akhauriyash/Code-Regression huggingface dataset:
#include <complex>
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int main(){
  int in(q);
  rep(loop, q) {
    long long in(a, b);
    if(a == 1 and b == 1) {
      out(0);
      continue;
    }
    long long n = a * b;
    long long v = (long long) sqrt(n);
    long long result = 2 * v - 1;
    if(v * v == n) {
      if(v == a and v == b) result += 1;
      result -= 2;
      v -= 1;
    } else if(v * (n / v) == n and abs(n / v - v) == 1) {
      result -= 1;
    }

    if(n / v == v) {
      result -= 1;
    }
    out(result);
  }
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

maekara = []
atokara = []

temp = 0
for i in range(n):
    temp += a[i]
    maekara.append(temp)
temp = 0
for i in range(n):
    temp += a[n-1-i]
    atokara.append(temp)
atokara = atokara[::-1]

ans = 2020202020 * 200000
for i in range(n-1):
    ans = min(ans, abs(maekara[i]-atokara[i+1]))

print(ans)

Measured memory_bytes: 32424
sx, sy, tx, ty = map(int, input().split())
ans = ""
dx = tx-sx
dy = ty-sy

for i in range(dy):
    ans += "U"
for i in range(dx):
    ans += "R"
for i in range(dy):
    ans += "D"
for i in range(dx):
    ans += "L"
ans += "L"
for i in range(dy+1):
    ans += "U"
for i in range(dx+1):
    ans += "R"
ans += "D"
ans += "R"
for i in range(dy+1):
    ans += "D"
for i in range(dx+1):
    ans += "L"
ans += "U"

print(ans)

Measured memory_bytes: 3064
function main()
    N,M,X = parse.(Int,split(readline()))

    C = zeros(Int,N)
    A = zeros(Int,N,M)
    for i in 1:N
        tmp = parse.(Int,split(readline()))
        C[i] = tmp[1]
        A[i,:] = tmp[2:end]
    end

    min_cost = 1<<63-1
    for i in 1:1<<N-1
        d = digits(i,base=2,pad=N)
        if all(sum(A .* d,dims=1) .>= X)
            cost = sum(C .* d)
            min_cost = ifelse(cost < min_cost,cost,min_cost)
        end
    end
    if min_cost == 1<<63-1
        print(-1)
    else
        print(min_cost)
    end
end

main()

Measured memory_bytes: 233548
use proconio::input;

fn main() {
    input!{
        n: i32,
        d: i32,
    }
    let mut num = 0;
    for _ in 0..n {
        input! {
            x: f64,
            y: f64,
        }
        let dist = (x*x + y*y).sqrt();
        if dist <= d as f64 {
            num += 1;
        }
    }
    println!("{}", num);
}


Measured memory_bytes: 4972
while True:
    m, f, r = [int(i) for i in input().split()]

    if m == f == r == -1:
        break

    total = m + f
    if m == -1 or f == -1 or total < 30:
        print('F')

    elif total < 50 and r < 50:
        print('D')

    elif total < 65:
        print('C')

    elif total < 80:
        print('B')
        
    else:
        print('A')

Measured memory_bytes: 7724
N,P=map(int,input().split())
if N==1:
    print(P)
else:
    a=1
    for i in range(2,10**6+1):
        s=0
        while True:
            if P%i==0:
                P//=i
                s+=1
            else:
                if s>=N:
                    a*=i**(s//N)
                break
    print(a)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int ans = solve(A, B);

        System.out.println(ans);
    }

    private static int solve(int A, int B) {
        if (A <= 5) return 0;
        if (A <= 12) return B/2;

        return B;
    }
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<std::pair<int64_t, int64_t>> p(n);
  std::cin >> p;

  std::vector<double> theta(n);

  for (int64_t i = 0; i < n; i++) {
    theta[i] = std::atan2(static_cast<double>(p[i].second),
                          static_cast<double>(p[i].first));
  }

  int64_t ans = 0;

  for (int64_t i = 0; i < n; i++) {
    for (int64_t j = 0; j < n; j++) {
      const auto judge = [&](const auto t) {
        if (theta[i] < theta[j]) {
          if (theta[i] <= t && t <= theta[j]) {
            return true;
          } else {
            return false;
          }
        } else if (theta[j] < theta[i]) {
          if (theta[i] <= t || t <= theta[j]) {
            return true;
          } else {
            return false;
          }
        } else {
          if (theta[i] == t) {
            return true;
          } else {
            return false;
          }
        }
      };

      int64_t x = 0, y = 0;

      for (int64_t k = 0; k < n; k++) {
        if (judge(theta[k])) {
          x += p[k].first;
          y += p[k].second;
        }
      }
      const auto tmp = x * x + y * y;
      ans = std::max(tmp, ans);
    }
  }

  std::cout << std::fixed << std::setprecision(15)
            << std::sqrt(static_cast<double>(ans)) << std::endl;
  return 0;
}


Measured memory_bytes: 512
n,k= map(int, input().split())
xy=[list(map(int,input().split())) for i in range(n)]

def check(x1,y1,x2,y2):
    cnt=0
    for node in xy:
        x,y=node
        if x1<=x<=x2 and y1<=y<=y2:
            cnt+=1
    return cnt

xlis=[]
ylis=[]
for itm in xy:
    x,y=itm
    xlis.append(x)
    ylis.append(y)
xlis.sort()
ylis.sort()

ans=10**20
from itertools import *
for tmp1 in combinations(xlis,2):
    for tmp2 in combinations(ylis,2):
        x1,x2=tmp1
        y1,y2=tmp2
        ret = check(x1,y1,x2,y2)
        if ret==k:
            ans=min(ans,(x2-x1)*(y2-y1))

print(ans)

Measured memory_bytes: 51036
import java.util.*;
public class Main {
  public static void main(String args[]) {
    Scanner sc=new Scanner(System.in);
    String s1=sc.next();
    String s2=sc.next();
    int count=0;
    for(int i=0;i<s1.length();++i) {
      if(s1.charAt(i)!=s2.charAt(i))
        count++;
      
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 41196
# -*- coding: utf-8 -*-
"""
Created on Mon May 27 21:28:42 2019

@author: Yamazaki Kenichi
"""

N, M = map(int,input().split())
ks = [list(map(int,input().split())) for i in range(M)]
p = list(map(int,input().split()))

S = [0 for i in range(M)]
for i in range(M):
    for j in range(1,ks[i][0]+1):
        S[i] += 2**(ks[i][j]-1)

ans = 0
for i in range(2**N):
    flg = True
    for j in range(M):
        if ('{:010b}'.format(S[j]&i)).count('1') % 2 == p[j]:
            continue
        else:
            flg = False
            break
    if flg:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
	int n, m;
	ll ans = 0;
	cin >> n >> m;
	vector<pair<int, int> > part(n);
	for (int i = 0; i < n; i++){
		cin >> part[i].first >> part[i].second;
	}
	sort(part.begin(), part.end());
	priority_queue<int> que;
	int stop = 0;
	for (int i = 1; i <= m; i++){
		while(part[stop].first == i){
			que.push(part[stop].second);
			stop++;
		}
		if (!que.empty()){
			ans += que.top();
			que.pop();
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1660
#include <stdio.h>
#include <stack>

int main() {
	int space;
	std::stack<int> st;
	scanf("%d", &space);
	st.push(space);
	while(scanf("%d", &space ) != EOF) {
		if(space != 0) {
			st.push(space);
		} else {
			printf("%d\n", st.top());
			st.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 1036
MOD = 10**9+7
n,k = gets.split.map &:to_i
dp = [0] * (k+1)

1.upto(k) do |i|
  dp[i] = (k/i).pow(n,MOD)
end

k.downto(1) do |i|
  (2*i).step(k,i) do |j|
    dp[i] -= dp[j]
    dp[i] %= MOD
  end
end

ans = 0
1.upto(k) do |i|
  ans += dp[i] * i
  ans %= MOD
end

puts ans

Measured memory_bytes: 15072
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    ll A,B,N;
    cin >> A >> B >> N;

    ll ans = 0;
    if (B == 1) {
        ans = 0;
    } else {
        if (B > N) {
            ans = A * N / B;
        } else {
            ll x = B-1;
            ans = A * x / B - A * (x/B);
        }
    }

    cout << ans << '\n';


    return 0;
}

Measured memory_bytes: 3588
# import numpy as np


def main():
    N = map(int, input().split())
    As = list(map(int, input().split()))

    nums_dict = dict()
    for a in As:
        if a in nums_dict:
            nums_dict[a] += 1
        else:
            nums_dict[a] = 1

    combs = dict()
    total = 0
    for key, value in nums_dict.items():
        comb = (value * (value-1)) // 2
        combs[key] = comb
        total += comb

    for a in As:
        v = nums_dict[a]
        if v > 1:
            c = (v-1) * (v-2) // 2
            print(total - combs[a] + c)
        else:
            print(total)


if __name__ == "__main__":
    main()


Measured memory_bytes: 31828
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int prev = 0;
        boolean isDown = true;
        TreeMap<Integer, Integer> map = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            if (isDown && prev < x) {
                if (map.containsKey(prev)) {
                    map.put(prev, map.get(prev) + 1);
                } else {
                    map.put(prev, 1);
                }
                isDown = false;
            } else if (!isDown && prev > x) {
                if (map.containsKey(prev)) {
                    map.put(prev, map.get(prev) - 1);
                } else {
                    map.put(prev, -1);
                }
                isDown = true;
            }
            prev = x;
        }
        if (!isDown) {
            if (map.containsKey(prev)) {
                map.put(prev, map.get(prev) - 1);
            } else {
                map.put(prev, -1);
            }
        }
        int max = 0;
        int current = 0;
        for (int x : map.values()) {
            current += x;
            max = Math.max(max, current);
        }
       System.out.println(max);
     }
}


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

int main(){
  
  int n;
  cin>>n;
  set<string>s;
  for (int i = 0; i < n; i++){
  	string a;
    cin>>a;
    s.insert(a);
  }
	
  cout<<s.size()<<endl;

  return 0;
}

Measured memory_bytes: 19052
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def gcd(x, y):
    if x%y == 0:
        return y
    return gcd(y, x%y)

def lcm(x, y):
    return x*y//gcd(x, y)

def f(x):
    res = 0
    while x%2 == 0:
        x//=2
        res += 1
    return res

def main():
    N, M = map(int, readline().split())
    A = [int(i)//2 for i in readline().split()]

    t = f(A[0]) 
    for i in A:
        if f(i) != t:
            print(0)
            return

    A = [i//(2**t) for i in A] 
    M //= 2**t    

    l = 1
    for i in A:
        l = lcm(l, i)
        if l > M:
            print(0)
            return
    M //= l
    ans = (M+1)//2
    print(ans)
if __name__ == '__main__':
    main()

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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 3010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,m;

int f[maxn][maxn][2];

void Work(){
	REP(i,1,n)f[0][i][0]=1;f[0][0][1]=1;
	REP(i,1,m)
		REP(j,0,n)
			REP(k,0,1)if(f[i-1][j][k]){
				if(j)(f[i][j][k|(j==1)]+=f[i-1][j][k])%=mod;
				if(j)(f[i][j-1][k|(j==1)]+=f[i-1][j][k])%=mod;
				if(n-j)(f[i][j][k]+=f[i-1][j][k])%=mod;
				if(n-j)(f[i][j+1][k]+=f[i-1][j][k])%=mod;
			}
	int ans=0;
	REP(i,0,n)(ans+=f[m][i][1])%=mod;
	iout(ans);
}

void Init(){
	read(n,m);
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 70784
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();

    if ((A + B) < 10) {
      System.out.println(A + B);
    } else {
      System.out.println("error");
    }

  }
}

Measured memory_bytes: 21716
import java.util.Scanner;

//B - String Rotation
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        String T = sc.nextLine();
        solve(S, T);
        sc.close();
    }

    public static void solve(String s, String t) {
        StringBuilder sb = new StringBuilder(s);
        boolean can = false;
        for (int i = 0; i < s.length(); i++) {
            sb.append(sb.charAt(0)).deleteCharAt(0);
            if (sb.toString().equals(t)) {
                can = true;
                break;
            }
        }
        if (can)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 21844
import java.util.*;
import java.util.stream.Collectors;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
      
        int n = sc.nextInt();
        ArrayList<Integer> cards = new ArrayList<>();
        for(int i = 0;i < n; i++) {
        cards.add(sc.nextInt());
        }

        List<Integer> sortedCards = cards.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
        int alicePoints = 0;
        int bobPoints = 0;

        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                alicePoints += sortedCards.get(i);
            } else {
                bobPoints += sortedCards.get(i);
            }
        }
        System.out.println(alicePoints - bobPoints);
    }
}

Measured memory_bytes: 26704
#include<bits/stdc++.h>
#define R(n)for(L i=0;i<n;i++)
#define M make_pair
typedef long long L;
using namespace std;
int main(){
    L n,k,s,t,a[50];cin>>n>>k>>s>>t;
    R(n)cin>>a[i];
    map<pair<L,L>,L> p[50];
    R(n){
        for(L j=k-2;j+1;j--)for(const auto&l:p[j])p[j+1][M(l.first.first&a[i],l.first.second|a[i])]+=l.second;
        p[0][M(a[i],a[i])]=1;
    }
    n=0;
    R(k)n+=p[i][M(s,t)];
    cout<<n;
}

Measured memory_bytes: 153944
#include <stdio.h>
#include <string.h>
 
int main()
{
    char str[8];
 
    scanf("%s", str);
 
    if (strlen(str) == 2) {
        printf("%s\n", str);
    } else if (strlen(str) == 3) {
        putchar(str[2]); putchar(str[1]); putchar(str[0]);
        putchar('\n');
    }
 
    return 0;
}

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

int main()
{
  int n; cin>>n;
  vector<ll> dp(n+1, 0);
  dp[0] = 1;
  dp[1] = 1;
  for (int i=2; i<=n; i++) {
    dp[i] = dp[i-1]+dp[i-2];
  }
  cout << dp[n] << endl;

  return 0;
}



Measured memory_bytes: 3112
def issq(n):
    for i in range(2 * n):
        if i * i == n:
            return True
    return False
    

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]

count = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        sqdist = 0
        for k in range(d):
            sqdist = sqdist + ((x[i][k] - x[j][k]) ** 2)
        if issq(sqdist) == True:
            count = count + 1

print(count)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int vx[4] = { 0,1,0,-1 };
int vy[4] = { 1,0,-1,0 };


string a;

signed main() {

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	cin >> a;

	if (a.size() < 4) {
		cout << "No" << endl;
		return 0;
	}

	if (a[0] == 'Y'&&a[1] == 'A'&&a[2] == 'K'&&a[3] == 'I') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;

	}



	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9+7;
const ll INF = 1e18;
const int MAX = 1e6;

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

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

int n, m; // 変数
int sub[MAX];

int main() {
// input
    cin >> n;
    rep(i, n+1) {
        int boss;
        if (i > 1) {
            cin >> boss;
            sub[boss]++;
        }
    }
// solve
// output
    rep(i, n+1) {
        if (i > 0) cout << sub[i] << "\n";
    }
}

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

int main(){
    int n,d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    rep(i, n){
        rep(j, d){
            cin >> x.at(i).at(j);
        }
    }
    int ans=0;
    rep(i, n){
        for(int j=i+1;j<n;j++){
            int dist =0;
            for(int k=0;k<d;k++) dist+=pow(x.at(i).at(k)-x.at(j).at(k), 2);
            if(sqrt(dist) == floor(sqrt(dist))) ans+=1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
let () = Scanf.scanf "%d" (fun n -> 
 let a = let rec check_a a' = if 100 * a' - n > 0 then a' - 1 else  check_a (a' + 1) in check_a 2 in
 let b = let rec check_b b' = if 10 * b' - (n - a * 100) > 0 then b' - 1 else  check_b (b' + 1) in check_b 2 in
 let c = let rec check_c c' = if c' - (n - a * 100 - b * 10) > 0 then c' - 1 else  check_c (c' + 1) in check_c 2 in
let chenge m = if m = 1 then 9 else if m = 9 then 1 else m in
let (a', b', c') = (chenge a, chenge b, chenge c) in
let n' = a' * 100 + b' * 10 + c' in
      Printf.printf "%d" n')

Measured memory_bytes: 384
n, m = map(int, raw_input().split())
MOD = 10**9+7

F = [0 for _ in xrange(10**5+10)]
F[0] = 1
F[1] = 1
for i in xrange(2, 10**5+2):
    F[i] = F[i-1] * i % MOD

if abs(n - m) >= 2:
    print 0
elif abs(n - m) == 1:
    print F[n] * F[m] % MOD
else:
    print F[n] * F[m] * 2 % MOD


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

int main(){
  string s,t;
  cin>>s>>t;
  long cnt=0;
  for(long i=0;i<long(s.size());i++){
    if(s[i]!=t[i]){
      cnt++;
    }
  }
  cout<<cnt;
}
  

Measured memory_bytes: 3860
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void change(int *x, int *y);

int n;
int a[100000];
int max=0;
int rec;

int main(void){
	scanf("%d", &n);
	for(int i=0;i<n;i++)	scanf("%d", &a[i]);

	for(int i=0;i<n;i++){
		if(a[max]<a[i])	max=i;
	}
	
  	if(max==0)	rec=1;
  	else	rec=0;
  
	for(int i=0;i<n;i++){
		if(abs(a[max]/2-a[i]) < abs(a[max]/2-a[rec]) && i!=max)	rec=i;
	}

	printf("%d %d", a[max], a[rec]);

	return 0;
}

void change(int *x, int *y){
	int z;
	z = *x;
	*x = *y;
	*y = z;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> n;
  vlli d(n);
  vlli dp(n, INF);

  rep(i, 0, n)
  {
    cin >> d[i];
  }
  dp[0] = 0;
  dp[1] = abs(d[1] - d[0]);
  rep(i, 1, n)
  {
    chmin(dp[i], dp[i - 1] + abs(d[i] - d[i - 1]));
    if (i > 1)
      chmin(dp[i], dp[i - 2] + abs(d[i] - d[i - 2]));
  }
  cout << dp[n - 1] << endl;
}

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

using namespace std;

int main() {
    int n, c; cin >> n >> c;
    
    vector<long long> dp(c + 1, 0);
    for (int i = 0; i < n; ++i) {
        int w, v; cin >> w >> v;
        for (int j = c - w; j >= 0; --j) {
            dp[j + w] = max(dp[j + w], dp[j] + v);   
        } 
    }
    cout << dp[c] << endl;


    return 0;
}


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

const int INF = 999999999;
int main()
{
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int> vW(N+1, 0), vE(N+1, 0);
  for(int i=0;i<N;i++){
    vW[i+1] = vW[i];
    if(S[i] == 'W')vW[i+1]++;
    vE[i+1] = vE[i];
    if(S[i] == 'E')vE[i+1]++;
  }
  int ans = INF;
  for(int i=0;i<N;i++){
    int now = vW[i] + (vE[N]-vE[i+1]);
    if(ans > now)ans = now;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6132
solve (a1:a2:as) (b:bs)
  = let a2' = max 0 (a2 - max 0 (b - a1)) in 
    min (a1+a2) b + solve (a2':as) bs
solve _ _ = 0

main = do
  getLine
  a <- map read.words<$>getLine
  b <- map read.words<$>getLine
  print $ solve a b

Measured memory_bytes: 100732
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();

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

    int k, n;
    cin >> n >> k;
    VLD p(n);
    REP(i,n) cin >> p[i];

    VLD e(n);
    REP(i,n) {
        if (i==0) e[i] = ((p[i]*(p[i]+1.0)) / 2.0) / p[i];
        else e[i] = ((p[i]*(p[i]+1.0)) / 2.0) / p[i] + e[i-1];
    }

    VLD s(n+1, 0.0);
    REP(i,n) s[i+1] = e[i];

    LD ans = 0.0;
    for (int i=k; i<=n; i++) {
        ans = max(ans, s[i]-s[i-k]);
    }

    cout << fixed << setprecision(15) << ans << endl;
    
    return 0;
}

Measured memory_bytes: 12684
using System;

public class Hello
{
    public static void Main()
    {
        var a = new int[] { 63, 6, 91, 79, 102, 109, 125, 39, 127, 111, 0 };
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == -1) break;
            var pre = 10;
            for (int i = 0; i < n; i++)
            {
                var d = int.Parse(Console.ReadLine().Trim());
                var ret = Convert.ToString(a[pre] ^ a[d], 2);
                Console.WriteLine(ret.PadLeft(7, '0'));
                pre = d;
            }
        }
    }
}



Measured memory_bytes: 8892
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BSnakeToy {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int k, n;
	    in >> n >> k;
	    vector<int> l(n);
	    for(int i=0; i<n; i++){
	        in >> l[i];
	    }

	    sort(l.begin(), l.end(), greater<int>());

	    int res = 0;
	    for(int i=0; i<k; i++){
	        res += l[i];
	    }
	    out << res << endl;
	}
};


int main() {
	BSnakeToy solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vppll vector<pair<pll,pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll,ll>
#define fir first
#define sec second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define fo(i,b) for(i=0;i<b;i++)
#define repa(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18+1);
const long long int MIN = (ll)(-1e18-1);
const long long int mod = (ll)(1e9+7);
using namespace std;

ll max(ll a,ll b,ll c) {return max(max(a, b), c);}
ll min(ll a,ll b,ll c) { return min(min(a, b), c);}
ll max(ll a,ll b) {return (a>b) ? a : b;}
ll min(ll a,ll b) {return (a<b) ? a : b;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power_mod(ll a, ll n, ll mod_){ ll p=1; while(n){ if(n%2){ p=(p*a)%mod_;} n/=2; a=(a*a)%mod_;} return p%mod_;}
                                                 /*Code Begins*/


int main(){
    _cin;
    // cout << setprecision(15);
    ll mn = MAX, mx = MIN;
    ll n, t, m, k, i, j,  sum=0,  prev, flag=0, cnt=0;
    ll x=0, y=0, fx, diff, tot=0, l , r;
    int TC=1;
    // cin >> TC;
while(TC--){
    string s;
    cin >> s;
    n = s.length();
    string t1, t2;
    flag=0;
    fo(i,(n-1)/2) t1.pb(s[i]);
    repa(i,(n+3)/2-1, n) t2.pb(s[i]);
    // cout << t1 << endl << t2;
    fo(i,n){
        if(s[i]!=s[n-1-i]) flag=1;
    }
    fo(i,t1.length()){
        if(t1[i]!=t1[t1.length()-1-i]) flag=1;
    }
    fo(i,t2.length()){
        if(t2[i]!=t2[t2.length()-1-i]) flag=1;
    }
    flag ? cout << "No" : cout << "Yes";

}
    return 0;
}


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

using namespace std;

int main(void){
    int N;
    cin >> N;
    
    map<int, int> A;
    int a;
    for(int i=0; i<N; i++) {
        cin >> a;
        A.insert(make_pair(a, i));
    }
    
    for(int i=1; i<=N; i++) {
        cout <<  A.at(i) + 1 << " ";
    }
    
}


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

int main(){
    int c;
    int i=0;
    while (1){
        cin >> c;
        i++;
        if(c == 0){
            break;
        }
        else{
            cout << "Case" << ' ' << i << ':' << ' ' << c << endl; 
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
const int inf=1e9+7;
const int mod=1e9+7;
using namespace std;
//
int main(){
	string S;
	cin>>S;
	int N=S.size();
	if(S[0]!='1'||S[N-1]!='0'){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=0;i<N-1;i++){
		if(S[i]!=S[N-2-i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	int roo=1;
	for(int i=2;i<=N;i++){
		cout<<roo<<" "<<i<<endl;
		if(S[i-2]=='1'){
			roo=i;
		}
	}
	return 0;
}


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

using namespace std;

string s;

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

    cin >> s;

    if(s[5] == '0' && s[6] - '0' <= 4)
        cout << "Heisei";
    else
        cout << "TBD";

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		// int nnn=3*(3+1)*(3+2)/6;
		// System.out.println(nnn);
		long[] dp = new long[1000001];
		long[] dpki = new long[1000001];
		int min = 1000000;
		// int tate = n * (n + 1) * (n + 2);

		// tate++;
//		long[][] dp = new long[181][n+ 1];

		for (int i = 1; i <= 1000000; i++) {
			dp[i] = i;
//			dp[0][i] = 1000000;

			dpki[i] = i;
			//dpki[0][i] = 1000000;
		}

		for (int i = 2; i < 181; i++) {

		//	for (int j = 1; j <= n; j++)
		//		dp[i][j] = dp[i - 1][j];

			int sum = i * (i + 1) * (i + 2) / 6;

			for(int j=sum;j<=1000000;j++){
				dp[j]=Math.min(dp[j],dp[j-sum]+1);
			}
			
			/*
			if (sum <= n && dp[i - 1][sum] > 1)
				dp[i][sum] = 1;
			int count = 2;
			for (int j = sum * 2; j <= n; j += sum) {
				if (dp[i - 1][j] > count)
					dp[i][j] = count;
				count++;
			}

			// for (int k = 2; n / sum >= k; k++) {
			for (int j = 1; j <= n; j++) {
				if (n >= j + sum && dp[i - 1][j + sum] > dp[i - 1][j] + 1 && dp[i][j + sum] > dp[i - 1][j] + 1)
					dp[i][j + sum] = dp[i - 1][j] + 1;
			}
			// }
			*/

		}

		for (int i = 2; i < 181; i++) {
			//for (int j = 1; j <= n; j++)
			//	dpki[i][j] = dpki[i - 1][j];

			int sum2 = i * (i + 1) * (i + 2) / 6;

			if (sum2 % 2 == 0)
				continue;

//			if(dpki[i][sum2]>1)dp[i][sum2]=1;
			for(int j=sum2;j<=1000000;j++){
				dpki[j]=Math.min(dpki[j],dpki[j-sum2]+1);
			}
			
/*				if (sum2 <= n && dpki[i - 1][sum2] > 1)dpki[i][sum2] = 1;
			int count2 = 2;
			for (int j = sum2 * 2; j <= n; j += sum2) {
				if (dpki[i - 1][j] > count2)
					dpki[i][j] = count2;
				count2++;
			}

			for (int j = 1; j <= n; j++) {
				if (n >= j + sum2 && dpki[i][j + sum2] > dpki[i][j] + 1)dpki[i][j + sum2] = dpki[i][j] + 1;
			
			}

			
			for (int k = 1; n / sum2 >= k; k++) {
				int sss=sum2*k;
				for (int j = 1; j <= n; j++) {
					if (n >= j + sss && dpki[i][j + sss] > dpki[i][j] + 1)dpki[i][j + sss] = dpki[i][j] + 1;
				
				}
			 }
			 */
			
			
		}
/*		for (int i = 0; i < 181; i++) {
			for (int j = 0; j <= n; j++) {
				System.out.print(dpki[i][j] + " ");
			}
			System.out.println();
		}
*/
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;

	
			long result = dp[n];
			long result2 = dpki[n];
	/*		for (int i = 0; i < 181; i++) {
				// System.out.println(dp[i][n]);
				if (dp[i][n] == 0)
					continue;
				result = (int) Math.min(dp[i][n], result);

			}
			
			for (int i = 0; i < 181; i++) {
				// System.out.println(dp[i][n]);
				if (dpki[i][n] == 0)
					continue;
				result2 = (int) Math.min(dpki[i][n], result2);

			}
*/
			System.out.print(result+" ");
			System.out.println(result2);

		}
	}
}

Measured memory_bytes: 43164
def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P):
    P = sorted(P)
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        while(True):
            if isCLKWISE(phU) : break
            else :
                del phU[-2]
                if len(phU) == 2 : break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        while(True):
            if isCLKWISE(phL) : break
            else :
                del phL[-2]
                if len(phL) == 2 : break
    ph = phU + phL[1:-1]
    return ph
  
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R : print(r[0],r[1])

Measured memory_bytes: 33768
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
  string s;
  int flag=0;
  cin>>s;
  for(int i=0;i<s.length();i++)
  {
    if(s[i]=='7'){
      cout<<"Yes";
      flag=1;
      break;
    }
  }
  if(flag==0)
    cout<<"No";
  return 0;
}

  


Measured memory_bytes: 3588
using System;
using System.Linq;

class Problem {
    public static void Main() {
        var nml = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var a = new long[nml[0], nml[1]];
        for (var i = 0; i < nml[0]; i++) {
            var data = Console.ReadLine().Split().Select(long.Parse).ToArray();
            for (var j = 0; j < nml[1]; j++)
                a[i, j] = data[j];
        }
        var b = new long[nml[1], nml[2]];
        for (var i = 0; i < nml[1]; i++) {
            var data = Console.ReadLine().Split().Select(long.Parse).ToArray();
            for (var j = 0; j < nml[2]; j++)
                b[i, j] = data[j];
        }
        var c = new long[nml[0], nml[2]];
        for (var i = 0; i < nml[0]; i++)
            for (var k = 0; k < nml[1]; k++)
                for (var j = 0; j < nml[2]; j++)
                    c[i, j] += a[i, k] * b[k, j];
        for (var i = 0; i < nml[0]; i++)
            for (var j = 0; j < nml[2]; Console.Write(++j != nml[2] ? " " : "\n"))
                Console.Write(c[i, j]);
                
    }
}


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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}

int main() {
  int n,m,x,y,z;
  cin>>n>>m>>x>>y;
  vector<int> a(n),b(m);
  rep(i,n) cin>>a[i];
  rep(i,m) cin>>b[i];
  sort(b.begin(),b.end());
  z=b[0];
  if(!(x<z && z<=y)){
    cout<<"War"<<endl;
    return 0;
  }

  for(int i=0;i<n;i++){
    if(a[i]>=z){
      cout<<"War"<<endl;
      return 0;
    }
  }
  cout<<"No War"<<endl;
}


Measured memory_bytes: 256
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())
ans = 0

for i in range(1, K+1):
  for j in range(i, K+1):
    for k in range(j, K+1):
      if i == j and i == k and j == k:
        tmp = gcd(i, j, k)
      elif i == j or i == k or j == k:
        tmp = 3 * gcd(i, j, k)
      else:
        tmp = 6 * gcd(i, j, k)
      #print(i, j, k, tmp)
      ans += tmp
      
print(ans)

Measured memory_bytes: 9632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
struct CHT{
    //追加クエリの直線の傾きが単調のとき
    struct Line{
        int a,b;
        int y(int x){return a*x+b;}
    };
    deque<Line>q;
    bool noneed(Line a,Line b,Line c){
        return (b.b-c.b)*(b.a-a.a)<=(a.b-b.b)*(c.a-b.a);
    }
    void add(int a,int b){
        Line l={a,b};
        while(q.size()>1&&noneed(q[q.size()-2],q[q.size()-1],l)){
            q.pop_back();
        }
        q.push_back(l);
    }
    int query(int x){
        if(q.empty())return INF;
        while(q.size()>1&&q[0].y(x)>=q[1].y(x)){
            q.pop_front();
        }
        return q[0].y(x);
    }
};
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,c,h,dp;
    CHT cht;
    cin>>n>>c;
    cin>>h;
    cht.add(-2*h,h*h);
    rep(i,n-1){
        cin>>h;
        dp=cht.query(h)+h*h+c;
        cht.add(-2*h,dp+h*h);
    }
    cout<<dp<<endl;
    return 0;
}

Measured memory_bytes: 5532
#include<stdio.h>
int main(void)
{
	int b1,b2,b3;
	scanf("%d %d %d",&b1,&b2,&b3);

	if(b1==1 && b2==0 && b3==0){
	printf("Close\n");
	}
	else if(b1==0 && b2==1 && b3==0){
	printf("Close\n");
	}
	else if(b1==1 && b2==1 && b3==0){
	printf("Open\n");
	}
	else if(b1==0 && b2==0 && b3==1){
	printf("Open\n");
	}
	else if(b1==0 && b2==0 && b3==0){
	printf("Close\n");
	}
	return 0;
}

Measured memory_bytes: 1012
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	
	long long int a, b, k;
	cin >> a >> b >> k;
	if (a >= k) {
		a -= k;
		k = 0;
	}
	else {
		k -= a;
		a = 0;
	}
	if (b >= k) {
		b -= k;
		k = 0;
	}
	else {
		k -= b;
		b = 0;
	}

	
	cout << a << " " << b << endl;
}









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

using u64 = unsigned long long int;
using s64 = long long int;
using u32 = unsigned int;

constexpr u32 mod = 1000000007;

int n;

u32 pow2[200001];

void reduce(u64 *a, u64 *b){
  u64 s, t, u, v;
  s = v = 1;
  u = t = 0;
  
  while(*a){
    u64 q = *b / *a;
    u64 r = *b % *a;
    std::tie(s, t, u, v) = std::forward_as_tuple(u, v, s + q*u, t + q*v);
    *b = *a;
    *a = r;
  }
  *a = u;
  *b = v;
}

int main(){

  scanf("%d", &n);
  pow2[0] = 1;
  for(int i = 1; i <= n; i++){
    pow2[i] = 2 * pow2[i-1];
    if(pow2[i] >= mod) pow2[i] -= mod;
  }

  using quot = std::pair<u64, u64>;
  std::vector<quot> vp, vn;
  u32 zeroa = 0;
  u32 zerob = 0;
  u32 zero2 = 0;

  for(int i = 0; i < n; i++){
    s64 a, b;
    scanf("%lld%lld", &a, &b);
    if(a == 0 && b == 0) zero2++;
    else if(a == 0) zeroa++;
    else if(b == 0) zerob++;
    else if((a^b) >= 0){
      u64 ua = std::abs(a);
      u64 ub = std::abs(b);
      reduce(&ua, &ub);
      vp.emplace_back(ua, ub);
    }
    else {
      u64 ua = std::abs(a);
      u64 ub = std::abs(b);
      reduce(&ua, &ub);
      vn.emplace_back(ub, ua);
    }
  }

  std::sort(vp.begin(), vp.end());
  std::sort(vn.begin(), vn.end());

  std::vector<std::pair<quot, u32> > vpp, vnn;
  quot prev = {0, 0};
  for(auto const &x: vp){
    if(x == prev) vpp.back().second++;
    else{
      vpp.emplace_back(quot(x.first, x.second), 1);
      prev = x;
    }
  }
  prev = {0, 0};
  for(auto const &x: vn){
    if(x == prev) vnn.back().second++;
    else{
      vnn.emplace_back(quot(x.first, x.second), 1);
      prev = x;
    }
  }

  u64 ans = (pow2[zeroa] + pow2[zerob] + mod - 1) % mod;
  auto ip = vpp.begin(), in = vnn.begin();
  while(ip != vpp.end() && in != vnn.end()){
    if(ip->first == in->first){
      ans = ans * (pow2[ip->second] + pow2[in->second] + mod - 1) % mod;
      ++ip, ++in;
    }
    else if(ip->first < in->first){
      ans = ans * pow2[ip->second] % mod;
      ++ip;
    }
    else {
      ans = ans * pow2[in->second] % mod;
      ++in;
    }
  }
  while(in != vnn.end()){ ans = ans * pow2[in->second] % mod; ++in; }
  while(ip != vpp.end()){ ans = ans * pow2[ip->second] % mod; ++ip; }

  ans = (ans + zero2 + mod - 1) % mod;
  printf("%llu\n", ans);

  return 0;
}


Measured memory_bytes: 13516
using System;
using System.Text;

namespace ABC048B
{
    static class Program
    {
        static void Main()
        {
            long[] nbrs = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);

            StringBuilder res = new StringBuilder();
            for(int i = 0; i < nbrs[0]; i++)
            {
                string text = Console.ReadLine();
                res.Append(text + "\n");
                res.Append(text + "\n");
            }
            Console.WriteLine(res.ToString());
        }
    }
}

Measured memory_bytes: 11236
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
n,k = [int(i) for i in input().split()]
a = [int(i)-1 for i in input().split()]


acc = [0]
for ai in a:
    acc.append((acc[-1]+ai)%k)

#print(acc)
ans = 0
d = {}
for num,i in enumerate(acc):
    #print(d,num)
    if num >= k:
        d[acc[num-k]] -= 1
    #print(d,num)
    if i in d:
        ans += d[i]
        d[i] += 1
    else:
        d[i] = 1
    #print(ans)

print(ans)

Measured memory_bytes: 40616
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007



def main():
    h, w = LI()
    grid = SRL(h)
    cnt = 0
    for y in range(h):
        for x in range(w):
            if grid[y][x] == '.':
                cnt += 1
                grid[y][x] = INF



    que = deque([(0, 0)])
    grid[0][0] = 1
    while que:
        x, y = que.pop()
        cost = grid[y][x]
        for i, j in [(0,1),(1,0),(-1,0),(0,-1)]:
            nxt_x, nxt_y = x + i, y + j
            if not (0<=nxt_x<w and 0<=nxt_y<h):
                continue
            elif grid[nxt_y][nxt_x] != '#' and grid[nxt_y][nxt_x] > cost + 1:
                grid[nxt_y][nxt_x] = cost + 1
                que += [(nxt_x, nxt_y)]


    if grid[h-1][w-1] == INF:
        return -1


    return cnt - grid[h-1][w-1]







print(main())

Measured memory_bytes: 44764