akhauriyash/Code-Regression huggingface dataset:
n = int(input())
ain = list(map(int, input().split()))
a = [0]
a.extend(ain)
a.append(0)
al = [abs(a[i]-a[i+1]) for i in range(n+1)]
mall = sum(al)
for i in range(1,n+1):
  dif = al[i-1] + al[i] - abs(a[i-1] - a[i+1])
  print(mall - dif)


Measured memory_bytes: 13920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define all(x) (x).begin(), (x).end()
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

struct mp {
  ll h, w, d;
  mp(ll d, ll h, ll w): d(d), h(h), w(w) {}
};

bool operator>(mp a, mp b) {
  return a.d > b.d;
}
bool operator<(mp a, mp b) {
  return a.d < b.d;
}
//bool operator==(mp a, mp b) return a.d == b.d;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15)

  ll h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--, cw--, dh--, dw--;
  vector<string> field(h);
  for (int i = 0; i < h; i++) cin >> field[i];

  vector<vector<ll>> dist(h, vector<ll>(w, LLINF));

  vector<ll> mx = {-1, 0, 0, 1}, my = {0, 1, -1, 0};
  priority_queue<mp, vector<mp>, greater<mp>> que;
  dist[ch][cw] = 0;
  que.push(mp(0, ch, cw));
  while(!que.empty()) {
    mp m = que.top(); que.pop();
    //cout << m.h << " " << m.w << " : " << m.d << endl; 
    if (m.d != dist[m.h][m.w]) continue;
    for (ll dx = -2; dx <= 2; dx++) {
      for (ll dy = -2; dy <= 2; dy++) {
        if ((dx == 0) && (dy == 0)) continue;
        if ((0 <= m.h + dy) && (m.h + dy < h) && (0 <= m.w + dx) && (m.w + dx < w) && (field[m.h+dy][m.w+dx] == '.')) {
          if (dist[m.h+dy][m.w+dx] > m.d + 1) que.push(mp(m.d+1, m.h+dy, m.w+dx));
          dist[m.h+dy][m.w+dx] = min(dist[m.h+dy][m.w+dx], m.d + 1);
          //if (dist[m.h+dy][m.w+dx] > m.d + 1) que.push(mp(m.d+1, m.h+dy, m.w+dx));
        }
        for (int i = 0; i < 4; i++) {
          ll dx = mx[i], dy = my[i];
          if ((0 <= m.h + dy) && (m.h + dy < h) && (0 <= m.w + dx) && (m.w + dx < w) && (field[m.h+dy][m.w+dx] == '.')) {
            if (dist[m.h+dy][m.w+dx] > m.d) que.push(mp(m.d, m.h+dy, m.w+dx));
            dist[m.h+dy][m.w+dx] = min(dist[m.h+dy][m.w+dx], m.d);
            //if (dist[m.h+dy][m.w+dx] > m.d) que.push(mp(m.d+1, m.h+dy, m.w+dx));
          }
        }
      }
    }
  }

  /*for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) cout << dist[i][j] << " ";
    cout << endl; 
  }*/
  cout << ((dist[dh][dw] == LLINF) ? -1 : dist[dh][dw]) << endl;

}


Measured memory_bytes: 12752
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<time.h>
#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
#include<stdint.h>
#include<stdarg.h>
#include<tgmath.h>
#include<assert.h>
#include<iso646.h>
#include<stdbool.h>

//fast(?) Input
#define buf_sz 1<<24
char buf[buf_sz];
unsigned int nextint(){
	static int idx = 0, sz;
	if(idx == 0)sz = read(0, buf, buf_sz);
	unsigned int res = 0;
	while(idx<sz && buf[idx]<'0' || '9'<buf[idx])idx++;
	while(idx<sz && '0'<=buf[idx] && buf[idx]<='9'){
		res *= 10;
		res += buf[idx++] - '0';
	}if(idx>=sz)exit(1);
	return res;
}

int d[] = {[0 ... 1<<17] -1};
int find(int x){
	if(d[x] < 0) return x;
	return d[x] = find(d[x]);
}
bool unite(int x, int y){
	x = find(x); y = find(y);
	if(x == y)return false;
	if(d[x] > d[y]){
		int tmp = x;
		x = y;
		y = tmp;
	}
	d[x] += d[y];
	d[y] = x;
	return true;
}
bool same(int x, int y){return find(x) == find(y);}
int size(int x){return -d[find(x)];}

int main(){
	int N = nextint() - 1;
	int M = nextint();
	for(int i=0;i<M;i++)N -= unite(nextint(), nextint());
	printf("%d\n", N);
	return 0;
}

Measured memory_bytes: 3188
#include <stdio.h>

int main(void)
{
	int a, b;
	char op;

	while (1)
	{
		scanf("%d %c %d", &a, &op, &b);
		if (op == '?')
			break;
		else if (op == '+')
			printf("%d\n", a + b);
		else if (op == '-')
			printf("%d\n", a - b);
		else if (op == '*')
			printf("%d\n", a * b);
		else if (op == '/')
			printf("%d\n", a / b);
	} 
	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long lli;
#define int long long

signed main(){
	ios_base::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;

	map <char, int> sctr, tctr;
	for(int i=0; i<s.size(); i++){
		sctr[s[i]]++;
	}
	for(int i=0; i<t.size(); i++){
		tctr[t[i]]++;
	}

	for(auto it=tctr.begin(); it!=tctr.end(); it++){
		if(!sctr[it->first]){
			cout << -1;
			return 0;
		}
	}

	map <char, vector <int>> pos;
	for(int i=0; i<s.size(); i++){
		pos[s[i]].pb(i);
	}

	int tekrar = 0;
	int ptr = -1;
	for(int i=0; i<t.size(); i++){
		auto it = upper_bound(ALL(pos[t[i]]), ptr);
		if(it == pos[t[i]].end()){
			ptr = pos[t[i]][0];
			tekrar++;
		}else{
			ptr = *it;
		}
	}

	int res = s.size() * tekrar + ptr + 1;
	cout << res;

	return 0;
}

Measured memory_bytes: 1736
#include <stdio.h>

int a,b;
int main(){
	scanf("%d %d", &a ,&b);
	if(a < b){
		printf("a < b\n");
	}else if (a > b){
		printf("a > b\n");
	}else 
		printf("a == b\n");
	return 0;
}



Measured memory_bytes: 2036
/*  6_2
    Y_Aizaki    */

#include <stdio.h>
#include <string.h>

#define SIZE 120

int main(void){
    char word[SIZE]; // 文字列
    int wordlen, mwordlen; // 文字列の長さ(null込み)、挟むべき文字列中身の長さ

    fgets(word, SIZE, stdin);
    wordlen = strlen(word);
    mwordlen = wordlen - 3;

    printf("%c", word[0]);

    while (mwordlen/10 >0)
    {
        printf("%c", '0'+ (mwordlen/10));
        mwordlen %= 10;
    }
    printf("%c", '0'+ mwordlen);
    
    printf("%c\n", word[wordlen-2]);

    return 0;
}

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

#define PI 4*atan(1)
#define INF 1e8

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

int main(){
  int N, W;
  cin >> N >> W;
  vector<string> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  for(int i = 0; i < W + 2; i++){
    cout << "#";
  }
  cout << endl;
  for(int i = 0; i < N; i++){
    cout << "#" << a[i] << "#" << endl;
  }
  for(int i = 0; i < W + 2; i++){
    cout << "#";
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<string>
#include<string.h>
#include<cmath>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#define E (2.71828182)
#define PI (3.1415926535898)
#define	mem(a,b)	memset(a,b,sizeof(a))
#define mod	1000000007
#include<set>
#define gc getchar
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<float, int> P;
const int N = 1000000;
const long long  MAX_V = 5005, INF = 2147483647, MOD = 998244353;
ll a[100005], n, m, b[100005], f, temp, ans, x;
ll gcd(ll a, ll b) 
{
	return b == 0 ? a : gcd(b, a % b);
}
int main()
{
	while (~scanf("%lld%lld", &n, &m))
	{
		ans = f = 1;
		for (int i = 0; i < n; i++)
		{
			scanf("%lld", &a[i]);
		}
		for (int i = 0; i < n; i++)
		{
			temp = 0;
			while (!(a[i] & 1))
			{
				temp++;
				a[i] >>= 1;
			}
			b[i] = temp;
			if (i && b[i] != b[i - 1])
				f = 0;
		}
		if (f)
		{
			x = pow(2, b[0] - 1);
			for (int i = 0; i < n; i++)
			{
				ans = ans / gcd(ans, a[i]) * a[i];
				if (ans * x > m)
				{
					f = 0;
					break;
				}
			}
			if (f)
			{
				ans *= x;
				m -= ans;
				printf("%lld\n", m / 2 / ans + 1);
			}
			else
				printf("0\n"); 
		}
		else
			printf("0\n");
	}
}

Measured memory_bytes: 1792
h,w,m=map(int,input().split())

bomb=set([])

zahyo_y=[0]*(h)
zahyo_x=[0]*(w)

#print(zahyo_y)
#print(zahyo_x)

maxy=0
maxy_index=[]
maxx=0
maxx_index=[]

for _ in range(m):
    y,x=map(int,input().split())
    bomb.add((y-1,x-1))
    zahyo_y[y-1]+=1
    zahyo_x[x-1]+=1

    if zahyo_y[y-1]==maxy:
        maxy_index.append(y-1)
    elif zahyo_y[y-1]>maxy:
        maxy_index=[y-1]
        maxy=zahyo_y[y-1]

    if zahyo_x[x-1]==maxx:
        maxx_index.append(x-1)
    elif zahyo_x[x-1]>maxx:
        maxx_index=[x-1]
        maxx=zahyo_x[x-1]

for x in maxx_index:
    for y in maxy_index:
        if (y,x) not in bomb:
            print(maxx+maxy)
            exit()

print(maxx+maxy-1)






Measured memory_bytes: 171088
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);

    auto pf = new long[](n + 1);
    foreach (i ; 1 .. n + 1) {
        pf[i] = pf[i-1] + a[i-1];
    }

    long ans = 10L^^18;

    foreach (i ; 0 .. n) {
        if (i < 2 || (n - i) < 2) {
            continue;
        }

        auto l = nibutan(n, pf, 0, i);
        auto r = nibutan(n, pf, i, n);

        long p1 = pf[l] - pf[0];
        long p2 = pf[i] - pf[l];
        long p3 = pf[r] - pf[i];
        long p4 = pf[n] - pf[r];
        long mx = max(p1, p2, p3, p4);
        long mn = min(p1, p2, p3, p4);
        ans = min(ans, mx - mn);
    }

    writeln(ans);
}


int nibutan(int n, long[] pf, int btm, int top) {
    long dif(int k) {
        return abs(pf[top] - pf[k] - (pf[k] - pf[btm]));
    }

    bool check(int k) {
        return dif(k) <= dif(k + 1);
    }

    int ok = top, ng = btm;

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (check(mid)) {
            ok = mid;
        }
        else {
            ng = mid;
        }
    }

    return ok;
}



































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

int main(){
  int N; cin >> N;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin >> P[i];
  }
  int ans=0;
  int now=N+1;
  for(int i=0;i<N;i++){
    if(P[i]<now){
      ans++;
      now=P[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Objects;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DMegalomania solver = new DMegalomania();
        solver.solve(1, in, out);
        out.close();
    }

    static class DMegalomania {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();

            // (time to do , time limit)
            ArrayList<Vec2i> job = new ArrayList<>();

            for (int i = 0; i < n; i++) {
                job.add(new Vec2i(in.nextInt(), in.nextInt()));
            }

            job.sort(Comparator.comparing(v -> v.y));

            int time = 0;
            for (int i = 0; i < n; i++) {
                if (time + job.get(i).x <= job.get(i).y) {
                    time += job.get(i).x;
                } else {
                    out.println("No");
                    return;
                }
            }
            out.println("Yes");

        }

    }

    static class Vec2i {
        public int x;
        public int y;

        public Vec2i(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public String toString() {
            return "Vec2i{" +
                    "x=" + x +
                    ", y=" + y +
                    '}';
        }

        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Vec2i vec2i = (Vec2i) o;
            return x == vec2i.x &&
                    y == vec2i.y;
        }

        public int hashCode() {
            return Objects.hash(x, y);
        }

    }
}



Measured memory_bytes: 67504
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define answer(x) cout<<endl<<"answer : "<<x<<endl<<endl;
#define op(x) cout<<x<<endl;
#define maxn 500005
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi lld t=1;//cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0,l=0,r=0,mid=0,lo=0,hi=0;string s;bool flag=false;
        cin>>n>>x>>m;
        ans = (n + x-1)/x;
        ans*=m;
        cout<<ans<<endl;

    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|

*/


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int K;
  cin >> K;
  K--;

  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
                   1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  int ans = a[K];
  cout << ans << endl;
}

Measured memory_bytes: 764
def main():
    S = input()
    T = input()

    top = -1
    for head in range(len(S) - len(T)+1):
        for i in range(len(T)):
            if T[i] == S[head + i] or S[head + i] == "?":
                continue
            else:
                break
        else:
            top = head

    if top == -1:
        print("UNRESTORABLE")
    else:
        password = S[:top] + T + S[top + len(T):]
        password = password.replace("?", "a")
        print(password)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
h, w = map(int, input().split())

ans = []
for i in range(h):
    temp = input()
    if '#' not in temp:
        continue
    ans.append(temp)

for i in reversed(range(w)):
    if ans[0][i] == '.':
        flag = True
        for j in range(len(ans)):
            if ans[j][i] != '.':
                flag = False
                break

        if flag:
            for j in range(len(ans)):
                ans[j] = ans[j][:i] + (ans[j][i+1:len(ans[j])] if i+1 < len(ans[j]) else '')

for i in range(len(ans)):
    print(ans[i])


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

int main() {
  int N, K, res = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    res += min(x, K - x) * 2;
  }
  cout << res;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> dp(n+1);
    dp[0] = 0;
    REP(i, n){
        dp[i] = dp[i-1]+1;
        int now = 6;
        while(i - now >= 0){
            dp[i] = min(dp[i], dp[i-now]+1);
            now *= 6;
        }
        now = 9;
        while(i - now >= 0){
            dp[i] = min(dp[i], dp[i-now]+1);
            now *= 9;
        }
    }
    cout << dp[n] << endl;
}


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

public class hello
{
    public static void Main()
    {
        var p = new bool[50000];
        GeneratePrime(p);
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var count = 0;
            for (int i = 2; i <= n / 2; i++)
                if (p[i] && p[n - i]) count++;
            Console.WriteLine(count);
        }
    }
    public static void GeneratePrime(bool[] p)
    {
        int prime;
        var m = p.Length;
        var sqrtMax = Math.Sqrt(m);
        var searchList = Enumerable.Range(2, m - 1).ToList();
        do
        {
            prime = searchList.First();
            p[prime] = true;
            searchList.RemoveAll(n => n % prime == 0);
        }
        while (prime < sqrtMax);
        foreach (var x in searchList)
            p[x] = true;
    }
}



Measured memory_bytes: 16412
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll n;
cin>>n;
ll k;
cin>>k;
ll h[n];
for(ll i=0;i<n;i++){
    cin>>h[i];
}
ll ans=infll;
sort(h,h+n);
for(ll i=0;i<n-k+1;i++){
    ll tmp=h[i+k-1]-h[i];
    chmin(ans,tmp);
}
cout<<ans<<endl;
}










Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <math.h>
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ull  unsigned long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 20000;
int dp1[N], dp2[N];
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt",  "r", stdin);
    //freopen("output.txt", "w", stdout);
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    dp1[0] = dp2[0] = 1;
    for (int i = 1; i <= 5000; i++){
        if (i >= c) dp1[i] = dp1[i - c];
        if (i >= d) dp1[i] = max(dp1[i], dp1[i - d]);
    }
    for (int i = 1; i <= 5000; i++){
        if (i >= 100 * a) dp2[i] = dp2[i - 100 * a];
        if (i >= 100 * b) dp2[i] = max(dp2[i], dp2[i - 100 * b]);
    }
    int ans1, ans2;
    double ans = -1;
    for (int i = 0; i <= f; i++){
        for (int j = 1; i + j <= f; j++){
            if (dp1[i] && dp2[j]){
                double x = (double) 100 * i / (i + j);
                //cout << x << endl;
                if (100 * i <= j * e){
                    if (ans < x){
                        ans = x;
                        ans1 = i + j;
                        ans2 = i;
                        //cout << x << " <- x" << endl;
                    }
                }
            }
        }
    }
    cout << ans1 << " " << ans2;
}


Measured memory_bytes: 384
# coding: utf-8

def greatest_common_devisor(x, y):
    if x > y:
        x, y = y, x
    
    amari = y % x

    while amari != 0:
        y = amari # 大きい方を消して，小さい方を残す
        if x > y:
            x, y = y, x
        amari = y % x
    print(x)

if __name__ == "__main__":
    x, y = map(int, input().split())
    greatest_common_devisor(x, y)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a; i<b; i++)

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main(){
    int n,m,ans;
    cin>>n>>m;
    ans=(n*(n-1)+m*(m-1))/2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val a = IntArray(n)
    for(i in 0 until n){
        a[i] = readLine()!!.toInt()
    }
    val b = a.sorted()
    var ans = StringBuilder()
    for(i in 0 until n){
        ans.append((if(a[i] == b[n - 1]) b[n - 2] else b[n - 1]).toString() + "\n")
    }
    println(ans.toString())
}

Measured memory_bytes: 61612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String before = sc.next();
		String after = sc.next();
		if (before.length() + 1 == after.length() && before.equals(after.substring(0, after.length() - 1))) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 35744
/**
 *    author:  [itmo] enot.1.10
 *    created: 10.10.2016 07:06:16       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int N = 1e5 + 10;

int a[N];
int b[N];


int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    int n, m;
    scanf("%d%d", &n, &m);
    forn(i, n) scanf("%d", &a[i]);
    forn(i, m) scanf("%d", &b[i]);
    sort(a, a + n);
    sort(b, b + m);
    ll res = 0;
    int i = 0, j = 0;
    while (i < n && j < m)
    {
        if (a[i] <= b[j])
        {
            res += a[i] * (ll)(m + 1 - j);
            i++;
        }
        else
        {
            res += b[j] * (ll)(n + 1 - i);
            j++;
        }
    }
    while (i < n)
    {
        res += a[i] * (ll)(m + 1 - j);
        ++i;
    }
    while (j < m)
    {
        res += b[j] * (ll)(n + 1 - i);
        ++j;
    }
    printf("%lld\n", res);
    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

int n,m;
vector<vector<int>> g(100000);

int dfs(int a,int b){
  if(g[b].size()==4)return b;
  if(g[b][0]==a)return dfs(b,g[b][1]);
  return dfs(b,g[b][0]);
}

int main(){
  cin>>n>>m;
  int a,b;
  REP(i,m){
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  bool flag=false;

  vector<int> cros;
  
  REP(i,n){
    if(g[i].size()%2==1){
      cout<<"No"<<endl;
      return 0;
    }
    if(g[i].size()>=6)flag=true;
    if(g[i].size()==4)cros.push_back(i);
  }
  if(flag || cros.size()>2){
    cout<<"Yes"<<endl;
    return 0;
  }

  if(cros.size()<2){
    cout<<"No"<<endl;
    return 0;
  }

  REP(i,4){
    if(dfs(cros[0],g[cros[0]][i])==cros[0]){
      cout<<"Yes"<<endl;
      return 0;
    }
  }

  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 5760
n = gets.chomp.to_i
abs = []
n.times{ abs << gets.split.map(&:to_i) }

abs.sort!{|a, b| a[1] <=> b[1] }
t = 0
e = false
abs.each do |ab|
  t += ab[0]
  if t > ab[1]
    e = true
    break
  end
end

puts e ? 'No' : 'Yes'


Measured memory_bytes: 18524
CITIES = 6
N = int(input())
# cap[i]は都市i-1からiに一度に移動できる人数, cap[0]はダミー
cap = [N] + [int(input()) for _ in range(CITIES - 1)]

def ceil(n, m):
    return -(-n // m)

dp = [0] * CITIES # 都市iまで全員が移動するのにかかる時間
mincap = N
for i in range(1, CITIES):
    if mincap <= cap[i]:
        dp[i] = dp[i - 1] + 1
    else:
        dp[i] = ceil(N, cap[i]) + i - 1
    mincap = min(mincap, cap[i])

print(dp[CITIES - 1])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long int
#define FILEIO  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 
#define maxn 1000000
 

using namespace std;

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

signed main() {
//FILEIO;
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
vector<int>arr(10001 , 0);
for(int i = 1; i*i <= 10000; i++)
{
	for(int j = 1; j *j <= 10000; j++)
	{
		for(int k = 1; k*k <= 10000; k++)
		{
			if(i*i + j*j + k*k + i*j + j *k + i*k <= 10000)
				arr[i*i + j*j + k*k + i*j + j*k + i*k]++;
		}
	}
}
int n;
cin>>n;
for(int i = 1; i <= n; i++)
{
	cout<<arr[i]<<endl;
}












    return 0;
}


Measured memory_bytes: 3708
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int f[100010][2];
char s[100010];
int main ()
{
	scanf("%s",s);
	int n,i;
	n=strlen(s);
	f[0][1]=1;f[0][0]=0;
	for(i=1;i<n;++i)
	{
		if(s[i]==s[i-1])
		{
			f[i][1]=f[i-1][0]+1;
			f[i][0]=f[i-1][1];
		}
		else
		{
			f[i][1]=f[i-1][1]+1;
			f[i][0]=f[i-1][0];
		}
	}
	printf("%d",min(f[n-1][1],f[n-1][0]));
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll ans = 0;
	for (ll i = 0; i < n; ++i) {
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,i,ans=1;
  
  cin>>n;
  vector<int> d(n);
  for(i=0;i<n;i++){	
    cin>>d.at(i);
  }
 sort(d.begin(),d.end());
  
  for(i=0;i<n-1;i++){
    
	if(d.at(i)!=d.at(i+1)){
		ans++;
    }
  }

  cout<<ans<<endl;
}



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

int main() {
  string s;
  while(getline(cin,s)) {
    while(true) {
      if( s.length() == 1 ) {
	cout<<s<<endl;
	break;
      }
      string l;
      for(int i=0; i<s.length()-1; i++)
	l += string( 1, ((s[i]-'0')+(s[i+1]-'0'))%10+'0');
      s = l;
    }
  }
}

Measured memory_bytes: 0
s = input().split()[0]
n = len(s)
l = s[:n//2]
r = s[n//2+1:]
cnt = 0
for i in range(n//2):
    if l[i] == l[n//2 - 1 - i]:
        cnt += 1
    if r[i] == r[n//2 - 1 - i]:
        cnt += 1
if l == r and cnt == n - 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
#include<stdio.h>
int main(){
  int i,j,k,l=1,a,b=1,c,e,f[3],n,r=0,d[]={3,5,7};
  scanf("%d",&n);
  for(i=1;i<10;i++){
    l*=3;
    for(j=0;j<l;j++){
      c=j;
      for(k=e=a=0;k<3;k++)f[k]=0;
      b=1;
      for(k=0;k<i;k++){
	a+=b*d[c%3];
	e+=1-f[c%3];
	f[c%3]=1;
	b*=10;
	c/=3;
      }
      if(e-3)continue;//printf("%d\n",a);
      if(n<a)goto END;
      r++;
    }
  }
 END:;
  printf("%d\n",r);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int ans;
	rep(i,1,6){
		int a; cin>>a;
		if(a==0) ans=i;
	}
	cout<<ans;
	
	return 0;
}

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

int main() {
	int q;
	cin >> q;
	deque<int> A;
	for (int i = 0; i < q; ++i) {
		int query;
		cin >> query;
		if (query == 0) {
			int d, x;
			cin >> d >> x;
			if (d == 0) A.push_front(x);
			else A.push_back(x);
		}
		else if (query == 1) {
			int p;
			cin >> p;
			cout << A[p] << endl;
		}
		else {
			int d;
			cin >> d;
			if (d == 0) A.pop_front();
			else A.pop_back();
		}
	}
}


Measured memory_bytes: 4604
//*INDENT-OFF*
#include<bits/stdc++.h>
using namespace std;
template<typename V>
bool tomin(V&x,V y){if(y<x){x=y;return true;}return false;}
template<typename V>
bool tomax(V&x,V y){if(x<y){x=y;return true;}return false;}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
#pragma GCC optimize(3)
#define lowbit(x) ((x)&-(x))
//*INDENT-ON*
const int M=1e5+5;
int n,A[M],B;
multiset<int>S;
multiset<int>::iterator it;
int main(){
    ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>A[i];
	int ans=0;
	for(int i=1;i<=n;i++){
		it=S.lower_bound(A[i]);
		if(S.size()&&it!=S.begin())
			S.erase(--it);
		else ans++;
		S.insert(A[i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5376
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {
    public static void main(String[] args) throws IOException {
        final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        final char[] line = reader.readLine().toCharArray();
        reader.close();

        final Deque<Integer> stack = new ArrayDeque<Integer>(line.length);
        final StringBuilder answer = new StringBuilder();

        int sum = 0;
        int count = 0;
        int indexLastZero = 0;
        final int[] process = new int[line.length + 1];
        final int[] graph = new int[line.length + 1];
        for (int i = 0; i < line.length; ++i) {
            if (stack.isEmpty()) indexLastZero = i;
            graph[i] = stack.size();
            process[i] = sum;
            switch (line[i]) {
                case '\\':
                    stack.push(i);
                    break;
                case '/':
                    if (!stack.isEmpty()) {
                        sum += i - stack.pop();
                        if (stack.isEmpty()) {
                            ++count;
                            answer.append(" ").append(sum - process[indexLastZero]);
                        }
                    }
                    break;
            }
        }
        if (stack.isEmpty()) indexLastZero = line.length;
        graph[line.length] = stack.size();
        process[line.length] = sum;

        for (int i = indexLastZero + 1, min; i < graph.length; ++i) {
            min = i;
            for (int j = i + 1; j < graph.length; ++j) {
                if (graph[i] == graph[j] && process[i] != process[j]) {
                    min = j;
                    break;
                }
            }
            if (min != i) {
                ++count;
                answer.append(" ").append(process[min] - process[i]);
                i = min - 1;
            }
        }
        System.out.println(sum);
        System.out.println(count + answer.toString());
    }
}

Measured memory_bytes: 25408
#include <stdio.h>
int main(){
  int n,m,a,b;
  scanf("%d%d",&n,&m);
  int boat[200010] = {};
  for(int i=0; i<m; i++){
    scanf("%d%d",&a,&b);
    if(a == 1){
      if(boat[b]>0){
	printf("POSSIBLE");
	return 0;
      }
      boat[b]++;
    }
    if(b == n){
      if(boat[a]>0){
	printf("POSSIBLE");
	return 0;
      }
      boat[a]++;
    }
  }
  printf("IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ll i,o,t,j,l,s,z;
    cin>>i>>o>>t>>j>>l>>s>>z;
    if(i&&j&&l) cout<<o+max(i/2*2+j/2*2+l/2*2,(i-1)/2*2+(j-1)/2*2+(l-1)/2*2+3);
    else cout<<o+i/2*2+j/2*2+l/2*2;
}

Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;
#pragma endregion

int gcd(int x, int y) {
  if (y == 0) {
    return x;
  }
  return gcd(y, x % y);
}

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

  int n;
  cin >> n;
  vector<int> A(n);
  REP(i, n) { cin >> A[i]; }
  int ans = A[0];
  FOR(i, 1, n) { ans = gcd(ans, A[i]); }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
S=list(input())

ans=0
n=len(S)

if n%2==0:
    for i in range(n//2):
        if S[i]!=S[n-1-i]:
            ans+=1
else:
    for i in range(n//2):
        if S[i]!=S[n-1-i]:
            ans+=1

print(ans)

Measured memory_bytes: 3060
N, K = map(int, input().split())
A = list(map(int, input().split()))
 
for i in range(N):
  A[i] -= 1

loop_lis = [0]
visited = [-1 for _ in range(N)]
visited[0] = 0
flag = 0
for i in range(K):
  if visited[A[loop_lis[-1]]] != -1:
    loop_time = i+1-visited[A[loop_lis[-1]]]
    start_loop = visited[A[loop_lis[-1]]]
    flag = 1
    break
  visited[A[loop_lis[-1]]] = i+1
  loop_lis.append(A[loop_lis[-1]])

if i == K-1 and flag == 0:
  print(loop_lis[-1]+1)
else:
  print(loop_lis[start_loop+(K-start_loop)%loop_time]+1)

Measured memory_bytes: 111072
from collections import deque
 
K = int(input())
que = deque(range(1, 10))
 
for _ in range(K - 1):
    x = que.popleft()
    if x % 10 != 0:
        que.append(10 * x + x % 10 - 1)
    que.append(10 * x + x % 10)
    if x % 10 != 9:
        que.append(10 * x + x % 10 + 1)
 
print(que.popleft())

Measured memory_bytes: 11912
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    s = input()
    t = s[:]
    a = [x for x in s.lower()]
    i = s.find('A')
    j = s.find('C')
    if i != -1 and j > 1 and j < len(s) - 1 and s.count('C') == 1:
        a[i] = 'A'
        a[j] = 'C'
        s = ''.join(a)
        if s == t:
            print("AC")
            exit()

    print("WA")


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()




"""

4
1 2
2 4
1 3
3
2 2 4
4 5 6

6
1 2
2 3
3 4
4 5
4 6
3
3 5 6
2 17 31 5 11

"""





Measured memory_bytes: 9404
from bisect import *

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

a_b=[0]
for i in range(1,n+1):
  a_b.append(a_b[i-1]+a[i-1])

b_b=[0]
for i in range(1,m+1):
  b_b.append(b_b[i-1]+b[i-1])

ans=0
for i in range(n+1):
  t_ans=i
  if a_b[i]>k:
    break
  t_ans+=bisect_right(b_b,k-a_b[i])-1
  ans=max(ans,t_ans)

print(ans)

Measured memory_bytes: 47512
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n; cin >> n;
	vector<int>a(n),Z; for (auto&& x : a)cin >> x;
	Z = a;
	sort(Z.rbegin(), Z.rend());
	int L = Z[n / 2 - 1], R = Z[n / 2];
	for (int i = 0; i < n; i++) {
		if (L > a[i])cout << L << endl;
		else cout << R << endl;
	}

	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007LL
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    rep(i, sz(v)) cout << v[i] << ",";
    cout << "]";
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N, M;
char board[1000][1001];
ll dp[1000][1000];

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> N >> M;
    rep(i, N) cin >> board[i];
    dp[0][0] = 1;
    rep(i, N) rep(j, M) if (board[i][j] == '.') {
        if (i > 0) dp[i][j] += dp[i-1][j];
        if (j > 0) dp[i][j] += dp[i][j-1];
        dp[i][j] %= MOD;
    }

    cout << dp[N-1][M-1] << endl;
}

Measured memory_bytes: 9088
#include <string>       // ヘッダファイルインクルード
#include <iostream>
#include <vector>  

int main()
{
    unsigned long long n, a,b;
//    std::vector<long> a,b;
	std::cin >> n;
	long long i=0,max=0, ten=0;
	
	for(i=0;i<n;i++){
		std::cin >> a; std::cin >> b;
		if(a>max){
			max=a;
			ten=b;
		}
     }
	
	std::cout << max+ten;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int ctoi(char c) {
	switch (c)
	{
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default:
		cout << "ERR_ctoi" << endl;
		return -1;
	}
}
int main() {
	
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	PRI(H*W-(H * w + W * h - w * h));
	return 0;
}

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

int n,b,bb;

int main()
{
	cin >> n;
	cin >> b;
	int ans = b;
	for (size_t i = 2; i < n; i++)
	{
		bb = b;
		cin >> b;
		ans += (b < bb ? b : bb);
	}
	cout << ans + b;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
struct point
{
	int x,y;
	double dis(point p1)
	{
		return sqrt((x-p1.x)*(x-p1.x)+(y-p1.y)*(y-p1.y));
	}
};
int jc(int n)
{
	int res=1;
	for (int i=2;i<=n;i++)
		res*=i;
	return res;
}
int main()
{
	int n;
	cin>>n;
	int jj=jc(n);
	point p[9];
	for (int i=1;i<=n;i++)
	{
		int x,y;
		cin>>x>>y;
		p[i].x=x;
		p[i].y=y;
	}
	double d[9][9]={0};
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
		{
//			if (i==j)
//				continue;
			d[i][j]=p[i].dis(p[j]);	
		}
	int a[n];
	for (int i=0;i<n;i++)
	{
		a[i]=i+1;
	}
	double sum=0;
	do
	{
		for (int i=0;i<n-1;i++)
			sum+=d[a[i]][a[i+1]]/jj;
	}
	while (next_permutation(a,a+n));
//	cout<<sum<<endl;
	printf("%.8lf",sum);		
	return 0;
}


Measured memory_bytes: 256
N, Q = map(int, input().split())
root = [[] for _ in range(N + 10)]
counter = [0 for _ in range(N + 10)]
for _ in range(N - 1):
  a, b = map(int, input().split())
  root[a].append(b)
  root[b].append(a)
for _ in range(Q):
  p, x = map(int, input().split())
  counter[p] += x
from collections import deque
d = deque([1])
while d:
  vertex = d.pop()
  for v in root[vertex]:
    counter[v] += counter[vertex]
    d.append(v)
    root[v].remove(vertex)
for i in range(1, N):
  print('{} '.format(counter[i]), end='')
print(counter[N])

Measured memory_bytes: 51452
def d_candy_distribution(N, M, A):
    import itertools
    import collections
    b = [0] + list(itertools.accumulate(A))

    # Aの累積和のうち、Mで割った余りが等しい要素の個数
    remainders = collections.defaultdict(int)
    for t in b:
        remainders[t % M] += 1

    ans = 0
    for k, v in remainders.items():
        if v >= 2:
            # 余りが等しい要素が2個以上あるなら、それから2つ選んで要望を満たせる
            ans += v * (v - 1) // 2
    return ans

N, M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(d_candy_distribution(N, M, A))

Measured memory_bytes: 16832
import sys
from heapq import heappush, heappop
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():
    n = ii()
    x = [0]*n
    y = [0]*n
    h = [0]*n
    for i in range(n):
        x[i], y[i], h[i] = mi()
    idx = h.index(max(h))
    for cx in range(101):
        for cy in range(101):
            flag = True
            H = abs(cx-x[idx])+abs(cy-y[idx])+h[idx]
            for i in range(n):
                tmp = abs(cx-x[i])+abs(cy-y[i])
                if h[i] == 0:
                    flag &= (tmp >= H)
                else:
                    tmp += h[i]
                    flag &= (tmp==H)
            if flag:
                print(cx, cy, H)
                return
            
            
        
        




if __name__ == '__main__':
    main()

Measured memory_bytes: 9208
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}

int main(){
  int n; cin >> n;
  vector<int> p(n), q(n);
  rep(i, n) {
    cin >> p[i];
    --p[i];
  }
  rep(i, n) {
    cin >> q[i];
    --q[i];
  }
  vector<int> vec(n);
  rep(i, n) vec[i] = i;

  int res_p = 0;
  int res_q = 0;
  int cnt = 0;
  do{
    cnt++;
    int cnt_p = 0;
    int cnt_q = 0;
    rep(i, n){
      if (vec[i] == p[i]) cnt_p++;
      if (vec[i] == q[i]) cnt_q++;
    }
    if (cnt_p == n) res_p = cnt;
    if (cnt_q == n) res_q = cnt;
  }while (next_permutation(vec.begin(), vec.end()));

  cout << abs(res_p - res_q) << endl;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double L;
    cin >> L;
    double ans = L*L*L/27;
//    cout << L*L*L/27 << endl;
    printf("%.10f",ans);
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a = Array.new(n, nil)
b = Array.new(n, nil)
n.times do |i|
  a[i], b[i] = gets.split.map(&:to_i)
end
count = 0
(n - 1).downto(0) do |i|
  r = (a[i] + count) % b[i]
  if r > 0
    count += b[i] - r
  end
end
puts count


Measured memory_bytes: 15896
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int A, B, K; std::cin >> A >> B >> K;
  std::vector<int> nums;
  for (int i = 1; i <= 100; ++i) {
    if (A % i == 0 && B % i == 0) {
      nums.push_back(i);
    }
  }

  std::cout << *(nums.rbegin() + K - 1) << std::endl;
}


Measured memory_bytes: 256