akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToArray();
            int N = input[0];
            int M = input[1];
            var AB = Enumerable.Repeat(new int[2], N).Select(ab => ab = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToArray());
            var sortedAB = AB.OrderBy(ab => ab[0]).ToArray();
            long ans = 0L;
            int idx = 0;
            int day = 1;
            PriorityQueue<int> pq = new PriorityQueue<int>((a, b) => b - a);
            while (day <= M)
            {
                if (idx < N && sortedAB[idx][0] <= day)
                {
                    while (idx < N && sortedAB[idx][0] <= day)
                    {
                        pq.Enqueue(sortedAB[idx][1]);
                        idx++;
                    }
                }
                if (pq.Any())
                {
                    ans += pq.Dequeue();
                }
                day++;
            }
            Console.WriteLine(ans);
        }
    }

    class PriorityQueue<T>
    {
        readonly List<T> heap;
        // Comparison<T>についてはhttps://docs.microsoft.com/ja-jp/dotnet/api/system.comparison-1?view=netframework-4.8を参照
        readonly Comparison<T> compare;
        private int size;

        public PriorityQueue(Comparison<T> compare)
        {
            heap = new List<T>();
            this.compare = compare;
        }

        /// <summary>
        /// 常に降順を保ったヒープにする
        /// </summary>
        /// <param name="val"></param>
        public void Enqueue(T val)
        {
            heap.Add(val);
            int i = size++;
            while (i > 0)
            {
                int p = (i - 1) >> 1;
                if (compare(heap[p], val) <= 0) break;
                heap[i] = heap[p];
                i = p;
            }
            heap[i] = val;
        }

        public T Dequeue()
        {
            T ret = heap[0];
            T x = heap[--size];
            int i = 0;
            while ((i << 1) + 1 < size)
            {
                int a = (i << 1) + 1;
                int b = (i << 1) + 2;
                if (b < size && compare(heap[b], heap[a]) < 0) a = b;
                if (compare(heap[a], x) >= 0) break;
                heap[i] = heap[a];
                i = a;
            }
            heap[i] = x;
            heap.RemoveAt(size);
            return ret;
        }

        public T Peek() { return heap[0]; }
        public int Count { get { return size; } }
        public bool Any() { return size > 0; }
    }
}


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

using namespace std;

int main()
{
  int n[] = {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 k;
  cin >> k;
  cout << n[k-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cstring>
#include <queue>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define MP make_pair
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> P;

struct state{
	int x, y;
	int foot; // 現在かけている足 0 => 左 1 => 右
	int time;
	state(int x, int y, int f, int t):x(x),y(y),foot(f),time(t){}
	bool operator<(const state &r)const{
		return time > r.time;
	}
};

int feet[30][60][2];

int dx[] = {1, 1, 1, 1, 1, 2, 2, 2, 3};		// 左足の時は*-1して使う
int dy[] = {2, 1, 0, -1, -2, 1, 0, -1, 0};

int main(){
	//freopen("test.txt", "r", stdin);
	int w, h;
	while(cin >> w >> h, w|h){
		vector<string> cliff(h);
		rep(i, h){
			rep(j, w){
				char c;
				cin >> c;
				cliff[i].push_back(c);
			}
		}

		memset(feet, -1, sizeof(feet));
		priority_queue<state> q;
		rep(i, h)rep(j, w){
			if(cliff[i][j] == 'S'){
				q.push(state(j, i, 0, 0));
				q.push(state(j, i, 1, 0));
				feet[j][i][0] = 0;
				feet[j][i][1] = 0;
			}
		}

		int ans = -1;
		while(!q.empty()){
			state s = q.top();
			q.pop();

			if(feet[s.x][s.y][s.foot] != s.time) continue;
			
			if(cliff[s.y][s.x] == 'T'){
				ans = s.time;
				break;
			}

			rep(i, 9){
				int x = s.x+dx[i]*(s.foot?-1:1); // 現在右足なら*-1
				int y = s.y+dy[i];
				if(x < 0 || x >= w || y < 0 || y >= h) continue;
				if(cliff[y][x] == 'X') continue;
				int t = (cliff[y][x]=='T'?0:cliff[y][x]-'0');
				state next = s;
				next.foot = !s.foot;
				next.time += t;
				if(feet[x][y][next.foot] != -1 && feet[x][y][next.foot] <= next.time) continue;
				feet[x][y][next.foot] = next.time;
				next.x = x;
				next.y = y;
				q.push(next);
			}
		} // end while
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1252
import java.util.Scanner;


public class Main {

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

		while (sc.hasNext()) {
			int d = sc.nextInt();
			int sum = 0;
			for (int x = 0 ; x < 600 ; x += d)  sum += x*x*d;
			System.out.println(sum);
		}

	}
}

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

int main()
{
  int n,m;
  cin >> n >> m;
  long *x=new long[n],*y=new long[n],*z=new long[n],*tmp=new long[n];
  for(int i=0;i<n;i++)
  {
    cin >> x[i] >> y[i] >> z[i];
  }
  long ans=0;
  for(int a=-1;a<2;a+=2)
  for(int b=-1;b<2;b+=2)
  for(int c=-1;c<2;c+=2)
  {
    for(int i=0;i<n;i++)
    {
      tmp[i]=a*x[i]+b*y[i]+c*z[i];
    }
    sort(tmp,tmp+n);
    long t=0;
    for(int i=0;i<m;i++)
    {
      t+=tmp[n-i-1];
    }
    if(t>ans)ans=t;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define TEST int t = 1;while(t--) solve()

void solve(){
    
    int n,k;
    cin>>n>>k;
    vector<vector<int> > v(n+1,vector<int>(64));
    for(int i=1;i<=n;i++)
    {  int t;
    	 cin>>t;
    	 v[i][0]=t;
    }
    for(int j=1;j<64;j++)
    {
    	 for(int i=1;i<=n;i++)
    	 {
    	 	 v[i][j]=v[v[i][j-1]][j-1];
    	 }
    }
    int mt=k;
    int a=1;
    vector<int> po;
    while(mt>0)
    {
    	 if(mt&1)
    	 { 
    	 	  po.push_back(a);
    	 	}
    	 a=2*a;
    	 mt=mt>>1;
    }

    reverse(po.begin(),po.end());
    int lt=1;
    for(auto x:po)
    {    int ft=log2(x);
    	 lt=v[lt][ft];
    	 //cout<<lt<<" ";
    }
    cout<<lt<<" ";
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); TEST; return 0;
}

Measured memory_bytes: 111160
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
int N,M;
struct node {
	int to,next,val;
}E[MAXN * 2];
int head[MAXN],sumE;
int fa[MAXN];
int64 sum[MAXN],x[MAXN];
bool vis[MAXN];
struct Enode {
	int u,v,c;
}s[MAXN];
void add(int u,int v,int c) {
	E[++sumE].to = v;
	E[sumE].next = head[u];
	E[sumE].val = c;
	head[u] = sumE;
}
int getfa(int u) {
	return fa[u] == u ? u : fa[u] = getfa(fa[u]);
}
void dfs(int u,int c) {
	int p = getfa(u);
	for(int i = head[u] ; i ; i = E[i].next) {
		if(E[i].val <= c) {
			int q = getfa(E[i].to);
			if(q != p) {
				fa[q] = p;
				dfs(E[i].to,c);
			}
		}
	}
}
void Solve() {
	read(N);read(M);
	for(int i = 1 ; i <= N ; ++i) read(x[i]);
	int u,v,c;
	for(int i = 1 ; i <= M ; ++i) {
		read(u);read(v);read(c);
		add(u,v,c);add(v,u,c);
		s[i] = (Enode){u,v,c};
	}
	sort(s + 1,s + M + 1,[](Enode a,Enode b){return a.c < b.c;});
	for(int i = 1 ; i <= N ; ++i) {
		fa[i] = i;sum[i] = x[i];
	}
	int t = 1;
	for(int i = 1 ; i <= M ; ++i) {
		int p = getfa(s[i].u),q = getfa(s[i].v);
		if(p != q) {
			fa[q] = p;
			sum[p] += sum[q];
		}
		if(i == N || s[i].c != s[i + 1].c) {
			for(int j = t; j <= i; ++j) {
				p = getfa(s[j].u);
				if(sum[p] >= s[j].c) vis[j] = 1;
			}
			t = i + 1;
		}
	}
	for(int i = 1 ; i <= N ; ++i) fa[i] = i;
	int ans = 0;
	for(int i = M ; i >= 1 ; --i) {
		if(getfa(s[i].u) == getfa(s[i].v)) continue;
		if(!vis[i]) {++ans;continue;}
		dfs(s[i].u,s[i].c);
	}
	out(ans);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


Measured memory_bytes: 9344
class NormalInput {
  input: string[];
  pointer: number;
  constructor(raw: string) {
    this.input = raw.split(/ |\n/);
    this.pointer = 0;
  }
  int = (): number => {
    const ret = parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  };
  str = (): string => {
    const ret = this.input[this.pointer];
    this.pointer++;
    return ret;
  };
  strs = (length: number): string[] => {
    let ret: string[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.str());
    }
    return ret;
  };
  ints = (length: number): number[] => {
    let ret: number[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.int());
    }
    return ret;
  };
}

function Main({ int, str, strs, ints }: NormalInput) {
  const [N,M ]= ints(2);
  console.log(N*(N-1)/2+M*(M-1)/2);
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 7500
"豪邸と宅配便"
N, M, T = map(int, input().split())  # 荷物の個数N, 片道の時間M, 終了時刻T

A = list(map(int, input().split()))

arraival_span = [A[0]]
for i in range(1, N):
    arraival_span.append(A[i] - A[i-1])
# print(arraival_span)

# 最後にT - A[-1]を加える
ans = arraival_span[0] - M
for i in range(1, len(arraival_span)):
    ans += max(arraival_span[i]-2*M, 0)

ans += max(T-A[-1]-M, 0)

print(ans)



Measured memory_bytes: 5600
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
  if a[i]>=b[i]:
    ans+=b[i]
  else:
    res=b[i]-a[i]
    if a[i+1]-res<0:
      ans+=a[i]+a[i+1]
      a[i+1]=0
    else:
      ans+=b[i]
      a[i+1]-=res
print(ans)

Measured memory_bytes: 97704
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
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 end

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

    ll n;
    in >> n;
    ll dp[n+1][3] = {};
    ll abc[n+1][3] = {};
    REP(i, n){
        in >> abc[i+1][0] >> abc[i+1][1] >> abc[i+1][2];
    }

    REP_AB(i, 1, n){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + abc[i][0];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + abc[i][1];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + abc[i][2];
    }

    out << max(max(dp[n][0], dp[n][1]), dp[n][2]) << endl;
}


Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<deque>
using namespace std;

int main() {

    vector<bool> is_prime (10001);
    for(int i = 0; i <= 10000; i++) {
        is_prime[i] = true;
    }
    is_prime[0] = false;
    is_prime[1] = false;
    for(int i = 2; i <= 100; i++) {
        if (is_prime[i]) {
            for(int j = 2 * i; j <= 10000; j += i) {
                is_prime[j] = false;
            }
        }
    }

    int n;
    while(cin >> n) {
        int res = 0;
        for(int i = 1; i <= n; i++) {
            if (is_prime[i] && is_prime[n-i+1])   res += 1; 
        }
        cout << res << endl;
    }
     
    return 0;
}

Measured memory_bytes: 0
X = int(input())
A = [1]
a = 2
while a**2 <= 1000:
    tmp = a**2
    while tmp <= 1000:
        A.append(tmp)
        tmp *= a
    a += 1
A = sorted(A)
A
for i in range(len(A)):
    if A[i] > X:
        break
if X == 1000:
    print(1000)
else:
    print(A[i-1])

Measured memory_bytes: 38256
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use std::mem::swap;

#[fastout]
fn main() {
    input! {
    h: usize,
    w: usize,
    k: usize,
    mut c: [Chars; h]
    }
    let tmp = c.clone();
    let mut ans = 0;
    for i in 0..1 << (h + w) {
        for j in 0..(h + w) {
            if i & 1 << j > 0 {
                if j >= h {
                    for k in 0..h {
                        c [k][j - h] = 'R';
                    }
                } else {
                    for k in 0..w {
                        c[j][k] = 'R';
                    }
                }
            }
        }
        if count_black(&c, h, w) == k {
            ans += 1;
        }
        c = tmp.clone();
    }
    println!("{}", ans);
}

fn count_black(c: &Vec<Vec<char>>, h: usize, w: usize) -> usize {
    let mut res = 0;
    for i in 0..h {
        for j in 0..w {
            if c[i][j] == '#' {
                res += 1;
            }
        }
    }
    res
}


Measured memory_bytes: 2160
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define _GLIBCXX_DEBUG
const int INF=1e15;

signed main(){
    int N,M;
    cin>>N>>M;
    priority_queue<int> pq;
    REP(i,N){
        int a;cin>>a;
        pq.push(a);
    }
    map<int,int>memo;
    REP(i,M){
        int a,b;cin>>a>>b;
        pq.push(b);
        memo[b]+=a-1;
    }
    int ans=0;
    REP(i,N){
        int d=pq.top();
      	ans+=d;
        if(memo[d]==0) pq.pop();
        else memo[d]--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 11120
# cook your dish here
h,w,m=map(int,input().split())
a=[0 for i in range(h+1)]
b=[0 for i in range(w+1)]

v={}
for i in range(m):
    x,y=map(int,input().split())
    # v.append([x,y])
    v[(x,y)]=1
    a[x]+=1
    b[y]+=1
    

maxx=max(a)
aa=[]
for i in range(1,len(a)):
    if a[i]==maxx:
        aa.append(i)

maxy=max(b)
bb=[]
for i in range(1,len(b)):
    if b[i]==maxy:
        bb.append(i)

ans=0
flag=0
for i in range(len(aa)):
    for j in range(len(bb)):
        if (aa[i],bb[j]) in v:
            ans=max(ans,a[aa[i]]+b[bb[j]]-1)
            
        else:
            ans=max(ans,a[aa[i]]+b[bb[j]])
            flag=1
            break
        
    if flag==1:
        break
            
print(ans)

Measured memory_bytes: 85620
s = input()

def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + "=7")
            exit()
    else:
        dfs(i+1, f + "+" + s[i+1], sum + int(s[i+1]))
        dfs(i+1, f + "-" + s[i+1], sum - int(s[i+1]))

dfs(0, s[0], int(s[0]))

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

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

int h, w;
int tov(int y, int x) {
    return (y * w + x);
}

const vi di = { -1, 0, 1, 0 }, dj = { 0, 1, 0, -1 };

int main(){
    cin >> h >> w;
    vs s(h);
    rep(i, h) cin >> s[i];
    vector<vi> dist(h*w, vi(h*w, INF));
    rep(i, h) rep(j, w) {
        if (s[i][j] == '#') continue;
        int val = tov(i, j);
        dist[val][val] = 0;
    }
    rep(pi, h) rep(pj, w) {
        if (s[pi][pj] == '#') continue;
        rep(j, 4) {
            int ni = pi + di[j], nj = pj + dj[j];
            if (ni<0 || ni>=h || nj<0 || nj>=w) continue;
            if (s[ni][nj] == '#') continue;
            int from = tov(pi, pj), to = tov(ni, nj);
            dist[from][to] = 1;
        }
    }
    rep(k, h*w) rep(i, h*w) rep(j, h*w) {
        dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
    }
    int ans = 0;
    rep(i, h*w) rep(j, h*w) {
        if (dist[i][j] == INF) continue;
        ans = max(ans, dist[i][j]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4196
#include <stdio.h>
#define MAX 100
#define INFTY (1<<21)
#define BLACK 2
#define GRAY 1
int n;
int a[MAX][MAX];
  
int omomi(){
    int u,minv,i,sum=0,v;
    int d[MAX],p[MAX],color[MAX];
 
    for(i=0;i<n;i++){
        d[i] = INFTY;
        p[i] = -1;
        color[i] = 0;
    }
 
    d[0] = 0;
 
    while(1){
        minv = INFTY;
        u = -1;
        for(i = 0;i<n;i++){
            if(minv > d[i] && color[i] != BLACK){
                u = i;
                minv = d[i];
            }
        }
        if(u == -1)break;
        color[u] = BLACK;
        for(v = 0;v<n;v++){
            if(color[v] != BLACK && a[u][v] != INFTY){
                if(d[v] > a[u][v]){
                    d[v] = a[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
        for(i = 0;i<n;i++){
            if(p[i] != -1)sum += a[i][p[i]];
        }
     
    return sum;
}
int main(){
int i,j,e;
 
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            scanf("%d",&e);
            if(e == -1)a[i][j] = INFTY;
            else a[i][j] = e;
        }
    }
 
    printf("%d\n",omomi());
    return 0;
}
 

Measured memory_bytes: 636
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <math.h>
using namespace std;

long gcd(long m,long n) {
    long m1 = m;
    long n1 = n;
    long r = m1 % n1;
    while (r > 0) {
        m1 = n1;
        n1 = r;
        r = m1 % n1;
    }
    return n1;
}

vector<long> divisors(long n) {
    vector<long> divs;
    long max = (long)sqrt(n);
    long tmp = n;
    divs.push_back(1);
    for (long num = 2; num <= max; num++)
    {
        if (tmp%num == 0) {
            divs.push_back(num);
            int cnt = 0;
            while(tmp%num == 0) {
                cnt += 1;
                tmp /= num;
                
            }
            /* if (pair != num) divs.push_back(pair); */
        }
    }

    if (tmp != 1) {
        divs.push_back(tmp);
    }
    if(n != 1 && divs.size() == 1) {
        divs.push_back(n);
    }

    return divs;
}

int main(int argc, char const *argv[]){
    long a,b;
    cin >> a >> b;

    long g = gcd(a,b);
    vector<long> vec = divisors(g);
    
    // for (int i = 0; i < vec.size(); i++)
    // {
    //     cout << vec[i] << endl;
    // }

    cout << vec.size() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 27;

int a[55][55];

bool b[55][55];
bool c[55][55];

int main(void){
	int H,W;
	cin >> H >> W;
	rep(i,H)rep(j,W) cin >> a[i][j];
	rep(i,H)rep(j,W) cin >> b[i][j];
	
	int h,w;
	cin >> h >> w;
	rep(i,h)rep(j,w) cin >> c[i][j];
	
	int ans=-inf;
	
	rep(i,H-h+1)rep(j,W-w+1){
		bool check=true;
		int rec=0;
		rep(k,h)rep(l,w){
			if(b[i+k][j+l]==c[k][l])
				rec+=a[i+k][j+l];
			else
				check=false;
		}
		if(check)
			ans=max(ans,rec);
	}
	
	if(ans==-inf)
		cout << "NA" << endl;
	else
		cout << ans << endl;
	return 0;
}


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

using namespace std;

void solve()
{
	string str;
	while(getline(cin, str))
	{
		int n = str.size();
		for(int i = 0; i < 26; ++i)
		{
			string Ans = str;
			for(int j = 0; j < n; ++j)
			{
				if('a' <= Ans[j] && Ans[j] <= 'z')
				{
					if(Ans[j] + i > 'z')
					{
						Ans[j] += i;
						Ans[j] -= 26;
					}
					else
					{
						Ans[j] += i;
					}
				}
			}
			if(Ans.find("this") != string::npos || Ans.find("that") != string::npos || Ans.find("the") != string::npos)
			{
				cout << Ans << endl;
				break;
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    string a="YES";
    cin >> s;
    vector<string> A(4);
    A={"dream","dreamer","erase","eraser"};
    reverse(s.begin(),s.end());
    for (int i = 0; i < A.size(); i++) {
        reverse(A.at(i).begin(),A.at(i).end());
    }

    for (int i = 0; i < s.size();){
        int b = 0;
        for (int j = 0; j < A.size(); j++){
            string d = A.at(j);
            if(s.substr(i, d.size())==d){
                b=1;
                i+=d.size();
            }
        }
        if(b!=1){
            a="NO";
            break;
        }
    }
    
    cout << a << endl;
}

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

using namespace std;
int h[100005];
int dp[100005];
int main(){
	int n;
    cin>>n;
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  cout << min(B / A, C) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
int n;
vector<vector<int>> graph;
vector<int> snuke, fennec;
vector<bool> used;

void dfs1(int cur, int d) {
  used[cur] = true;
  snuke[cur] = d;
  for (int v: graph[cur]) {
    if(used[v]) continue;
    dfs1(v, d + 1);
  }
}

void dfs2(int cur, int d) {
  used[cur] = true;
  fennec[cur] = d;
  for (int v: graph[cur]) {
    if(used[v]) continue;
    dfs2(v, d + 1);
  }
}

int main() {
  cin >> n;
  graph.resize(n);
  snuke.resize(n);
  fennec.resize(n);
  used.resize(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  
  dfs1(n - 1, 0);
  used = vector<bool>(n, false);
  dfs2(0, 0);
  int snukenum = 0;
  int fennecnum = 0;
  rep(i, n) if(fennec[i] <= snuke[i]) fennecnum++; else snukenum++;
  cout << (snukenum >= fennecnum ? "Snuke" : "Fennec") << endl;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

ll res;
vector<ll> h;

void ans(int l, int r){
  if (l == r)
    return;

  ll m = INF;
  for (int i = l; i < r; i++){
    m = min(m, h[i]);
  }

  res += m;

  for (int i = l; i < r; i++){
    h[i] -= m;
  }

  int a = l, b;
  while (true){
    while (a < r && h[a] == 0)
      a++;

    if (a == r)
      return;

    b = a + 1;
    while (b < r && h[b] != 0)
      b++;

    if (b == r){
      ans(a, b);
      return;
    }
    if (b == r || h[b] == 0){
      ans(a, b);
      a = b;
    }


    if (b == r)
      break;
    b++;
  }
}


int main(void){
  ll n;
  cin >> n;
  
  h = vector<ll>(n);
  for (int i = 0; i < n; i++){
    cin >> h[i];
  }

  ans(0, n);

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n+2];
        int sum =0;
        
        for(int i=1; i<n+1; i++){
            a[i] =sc.nextInt();
            sum += (int)(Math.abs(a[i] - a[i-1]));
        }
        //最後の目的地から0までの距離を足す。
        sum += (int)(Math.abs(a[n+1]-a[n]));

        for(int i=1; i<n+1; i++){
            int p = (int)(Math.abs(a[i+1]-a[i-1]));
            int m = (int)(Math.abs(a[i+1]-a[i])) + (int)(Math.abs(a[i]-a[i-1]));
            System.out.println(sum+p-m);
        }
        
    }
}


Measured memory_bytes: 69220
import numpy as np

N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))

e = (p + 1) / 2

# print(e)

cum_e = np.zeros(N + 1)
cum_e[1:] = np.cumsum(e)

# print(cum_e)

s = cum_e[K:] - cum_e[:-K]

print(max(s))


Measured memory_bytes: 33996
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100001

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}


LL C(LL n){
	if(n%2==0)return n^((n/2)%2);
	else return ((n+1)/2)%2;
}

int main(){
  LL A,B,ans=0;
  scanf("%lld%lld",&A,&B);

  printf("%lld\n",C(A-1)^C(B));
	return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

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

	int n, m;
	cin >> n >> m;
	bool al[200001] = {false};
	bool bl[200001] = {false};

	REP(i, m) {
		int a, b;
		cin >> a >> b;
		if(a == 1) {
			al[b] = true;
		}
		if(b == n) {
			bl[a] = true;
		}
	}

	for(int i=2;i<=n;i++) {
		if(al[i] && bl[i]) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}

	cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>

const int mod = 1e9 + 7;

int main()
{
    long long n, a, b;
    std::cin >> n >> a >> b;

    if (a > b || n == 1 && a != b) {
        std::cout << 0 << std::endl;
        return 0;
    }
    std::cout << (a + b * (n - 1)) - (a * (n - 1) + b) + 1 << std::endl;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    string teach = "keyence";
    REP(i, 0, S.size()) {
        REP(j, i, S.size()) {
            string sub = S.substr(0, i) + S.substr(j);
            if (sub == teach) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 22
#define inf 1<<29
#define linf (1e16)
#define eps (1e-8)
#define Eps (1e-15)
#define mod 1000000007
#define pi acos(-1.0)
#define phi (1.0+sqrt(5.0))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define pld(a) printf("%.10Lf\n",(ld)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define Unique(v) v.erase(unique(all(v)),v.end())
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

int h,w;
int mem[MAX][MAX][MAX][MAX];
string grid[MAX];

int rec(int a,int b,int c,int d){
  if(mem[a][b][c][d]!=-1)return mem[a][b][c][d];

  set<int> s;
  FOR(i,a,c){
    FOR(j,b,d){
      if(grid[i][j]=='X')continue;
      int g=0;
      if(i!=a && j!=b)g^=rec(a,b,i,j);
      if(i!=a && j!=d-1)g^=rec(a,j+1,i,d);
      if(i!=c-1 && j!=b)g^=rec(i+1,b,c,j);
      if(i!=c-1 && j!=d-1)g^=rec(i+1,j+1,c,d);
      s.insert(g);
    }
  }
  int res=0;
  while(s.count(res))res++;
  mem[a][b][c][d]=res;
  return res;
}

int main()
{
  cin>>h>>w;
  FOR(i,0,h)cin>>grid[i];
  memset(mem,-1,sizeof(mem));
  if(rec(0,0,h,w)!=0)cout<<"First"<<endl;
  else cout<<"Second"<<endl;

  return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define EPS             1e-9

void gogeta()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int MEX(int arr[], int n) {
    set<int> s;
    for (int i = 0; i <= n; i++)  s.insert(i);
    for (int i = 0; i < n; i++)  s.erase(arr[i]);
    return *(s.begin());
}

bool isinc(int arr[], int n) {
    for (int i = 0; i < n - 1; i++) {
        if (arr[i] > arr[i + 1]) return false;
    }
    return true;
}

int32_t main()
{
    gogeta();
    int n; cin >> n;
    int ans = 1000 - n % 1000;
    if (ans == 1000) ans = 0;
    cout << ans << endl;
}

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007

typedef long long ll;
int main() {
  int n;
  int count = 0;
  cin >> n;
  int taste[n];
  rep(i, n) {
    scanf("%d", &taste[i]);
  }
  for(int i = 0; i < n; i++) {
    for(int j = i; j < n; j++) {
      if(i == j) continue;
      count += taste[i] * taste[j];
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
//Kaori Miyazono, did I reach you ?
//"I can't die because... I'm the one who will protect you." -Asuna Yuuki

#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int n, d, x;
	cin >> n >> d >> x;
	int qnt = 0;
	for(int i = 0; i < n; i++) {
		int a;
		cin >> a;
		qnt += 1 + (d - 1) / a;
	}	
	cout << qnt + x;
   	return 0;
}

Measured memory_bytes: 256
from collections import deque
while True:
    n, k = map(int, input().split())
    if n==0:break
    a = deque(int(input()) for _ in range(k))
    ans=tmp=sum(a)
    for _ in range(n-k):
        x = a.popleft()
        y = int(input())
        a.append(y)
        tmp += y - x
        ans = max(ans, tmp)
    print(ans)

Measured memory_bytes: 9652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define INF 1000000000
ll i,j,k,p;
int main(){
    ll n,k;cin>>n>>k;
    vector<ll> h(n);
    for(i=0;i<n;i++){cin>>h[i];}

    sort(h.begin(),h.end(),greater<ll>());//降順

    ll ans=0;
    for(i=0;i<min(n,k);i++){//必殺を使うmonster
        h[i]=0;
    }

    for(i=0;i<n;i++){ans+=h[i];}

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

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int main()
{
	while(1) {
		int n, m;
		cin >> n >> m;
		if (!n && !m) break;
		Mii p;
		int len = 0;
		rep(i,0,n) {
			int a, b;
			cin >> a >> b;
			p[b] += a;
			len += a;
		}
		len -= m;
		int sum = 0;
		rep(i,0,11) {
			if (p[i]) {
				if (len > p[i]) {
					len -= p[i];
					sum += i * p[i];
					p[i] = 0;
				}
				else {
					sum += i * len;
					len = 0;
				}
			}
			if (!len) break;
		}
		if (sum > 0) cout << sum << endl;
		else cout << 0 << endl;
	}

	return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

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

  ll n; cin >> n;
  if(n == 1) {
    cout << 'a' << endl;
    return 0;
  }
  n--;
  string ans = "";
  while(n > 0) {
    ans.push_back(n % 26 + 'a');
    n /= 26;
    n--;
    if(n == 0) {
      ans.push_back('a');
      break;
    }
  }
  reverse(ALL(ans));
  cout << ans << endl;

}








Measured memory_bytes: 3668
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, c;
    cin >> a >> b >> c;
    if(c - (a - b) < 0)
    {
        cout << 0;
    }
    else
    {
        cout << c - (a - b);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n, k, s; cin >> n >> k >> s;
	int maxi = 1e9;
	if(s == maxi) maxi = 1;
	for(int i = 0; i < n; ++i) {
		if(i < k) {
			cout << s;
		} else {
			cout << maxi;
		}
		cout << (i == n - 1 ? "\n" : " ");
	}
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define LEN 100005
using namespace std;

int main(){
	int n,q;
	cin>>n>>q;
	queue<pair<string,int>>que;
	string s;
	for(int i=0,t;i<n;++i){
		cin>>s>>t;
		que.push(make_pair(s,t));
	}
	pair<string,int>qq;
	int ans=0;
	for(int tst;!que.empty();){
		qq=que.front();
		que.pop();
		tst=min(qq.second,q);
		ans+=tst;
		qq.second-=tst;
		if(qq.second==0){
			cout<<qq.first<<" "s<<ans<<"\n"s;
		}else{
			que.push(qq);
		}
	}
}


Measured memory_bytes: 6236
#include<stdio.h>

int main(){
    int i;
    double a, sum;

    while(scanf("%lf", &a) != EOF){
        sum = a;
        for(i = 2; i <= 10; i++){
            if(i % 2 == 0) a *= 2;
            else a /= 3;
            sum += a;
        }
        printf("%lf\n", sum);
    }
    return 0;
};

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine();

            for (char c = 'a'; c <= 'z'; c++)
            {
                var num = new List<int>();
                for (int i = 0; i < S.Length; i++) if (S[i] == c) num.Add(i);
                if (num.Count >= 2)
                {
                    var cha = T[num[0]];
                    for (int j = 1; j < num.Count; j++)
                    {
                        if (T[num[j]] != cha)
                        {
                            Console.WriteLine("No");
                            return;
                        }
                    }
                }
            }

            for (char c = 'a'; c <= 'z'; c++)
            {
                var num = new List<int>();
                for (int i = 0; i < T.Length; i++) if (T[i] == c) num.Add(i);
                if (num.Count >= 2)
                {
                    var cha = S[num[0]];
                    for (int j = 1; j < num.Count; j++)
                    {
                        if (S[num[j]] != cha)
                        {
                            Console.WriteLine("No");
                            return;
                        }
                    }
                }
            }

            Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 17888
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
score = [r,s,p]
def f():
    dp = [[0]*3 for j in range(len(win)+1)]
    for j in range(1,len(win)+1):
        w = win[j-1]
        
        for k in range(3):
            pl = 0
            if(k==0):
                if(w=='r'):
                    pl = r
                dp[j][k] = max(dp[j-1][1]+pl,dp[j-1][2]+pl) 
            if(k==1):
                if(w=='p'):
                    pl = p
                dp[j][k] = max(dp[j-1][0]+pl,dp[j-1][2]+pl)
            if(k==2):
                if(w=='s'):
                    pl = s
                dp[j][k] = max(dp[j-1][0]+pl,dp[j-1][1]+pl)
    return max(dp[-1])

ans = 0
for i in range(k):
    win = ''
    for j in range(i,n,k):
        enemy = t[j]
        if(enemy=='r'):
            win += 'p'
        if(enemy=='p'):
            win += 's'
        if(enemy=='s'):
            win += 'r'
    
    ans += f()

print(ans)  

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

#define ll long long
#define mx 100005
int ar[mx];
char ch[mx];
int n,m;
void solve()
{
    ll a,b;
    cin>>a>>b;
    ll re=abs(a-b);
    re=min(re,abs(abs(a-b)-b));
    if(a%b==0)re=0;
    a%=b;
    re=min(re,abs(a-b));
    re=min(re,abs(a-abs(a-b)));
    cout<<re<<endl;

}
int main()
{
    int t=1;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
  int N,cnt=0;
  cin>>N;
  int a[N];
  for(int i=0;i<N;i++) cin>>a[i];
  sort(a,a+N);
  for(int i=0;i<N;i++){
    if(a[i]==a[i+1]) continue;
    else cnt++;
  }  
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<cmath>
#include<map>
using namespace std;


int main(){
	int data[3];
	for(int i=0;i<3;++i){
		cin >> data[i];
	}
	sort(data,data+3);
	int a = data[2];
	int b = data[1];
	int c = data[0];
	
	int sa1 = a-b;
	int sa2 = a-c;
	int res = 0;
	int f = 0;
	
	if(sa1%2 ==0){
		res += sa1/2;
	}else{
		res +=(sa1-1)/2;
		f++;
	}
	
	if(sa2%2 ==0){
		res+=sa2/2;
	}else{
		f++;
		res+=(sa2-1)/2;
	}
	if(f==2) res+=1;
	if(f==1) res+=2;
	cout << res <<endl;
	
	return 0;
	
}



Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<u64>();
    let (n, wmax) = (v[0], v[1]);

    let mut items = vec![vec![]; 4]; // +0, +1, +2, +3
    let mut w0 = 0;
    for i in 0..n {
        let vv = read_vec::<u64>();
        let (w, v) = (vv[0], vv[1]);
        if i == 0 {
            w0 = w;
        }
        let idx = (w - w0) as usize;
        items[idx].push(v);
    }

    for i in 0..4 {
        items[i].sort_by(|a, b| b.partial_cmp(a).unwrap());
    }
    let mut options = vec![vec![]; 4];
    for i in 0..4 {
        options[i].push(0);
        for j in 0..items[i].len() {
            let prev = options[i][j];
            options[i].push(items[i][j] + prev);
        }
    }
    let mut ans = 0u64;
    for oi1 in 0..options[0].len() {
        for oi2 in 0..options[1].len() {
            for oi3 in 0..options[2].len() {
                for oi4 in 0..options[3].len() {
                    let mut weight = 0;
                    weight += oi1 as u64 * w0;
                    weight += oi2 as u64 * (w0 + 1);
                    weight += oi3 as u64 * (w0 + 2);
                    weight += oi4 as u64 * (w0 + 3);
                    if weight > wmax {
                        break;
                    }
                    let value =
                        options[0][oi1] + options[1][oi2] + options[2][oi3] + options[3][oi4];
                    ans = max(ans, value);
                }
            }
        }
    }
    println!("{:?}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
//rグー、sチョキ、pパー
int N,K,R,S,P;

int point(char t);
char win(char t);

int main(){
  string t;
  cin >> N >> K >> R >> S >> P >> t;
  int sum=0;
  char ans[N];
  for(int i=0; i<N; i++){
    ans[i]=win(t[i]);
    //cout << ans[i];
  }
  //cout << endl;
  for(int i=K; i<N; i++){
    if(ans[i]==ans[i-K]){
      ans[i]='n';
    }
  }
  for(int i=0; i<N; i++){
    sum+=point(ans[i]);
    //cout << sum << endl;
  }

  cout << sum << endl;
    
}

int point(char t){
  if(t=='p')return P;
  else if(t=='r')return R;
  else if(t=='s') return S;
  else return 0;
};

char win(char t){
  if(t=='r')return 'p';
  else if(t=='s')return 'r';
  else return 's';
};
  

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

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  vector<vector<int>> xss(H + 1);
  for (auto& xs : xss) xs = vector<int>(W + 1);
  int h = 1, w = 1, dw = 1, a;
  for (int i = 1; i <= N; ++i) {
    cin >> a;
    while (a--) {
      xss[h][w] = i;
      w += dw;
      if (w < 1 || W < w) {
        ++h;
        w -= dw;
        dw *= -1;
      }
    }
  }
  for (h = 1; h <= H; ++h) {
    for (w = 1; w <= W; ++w) {
      cout << xss[h][w];
      if (w != W) cout << " ";
    }
    cout << endl;
  }
}


Measured memory_bytes: 384
"""
AtCoder Grand Contest 039  B - Graph Partition / 


（１）ある集合V_iに含まれるノードから伸びる辺について、その先の集合がV_i-1かV_i+1になるように分ける
（２）その時の集合の個数の最大値を求める

（１）を言い換えると、あるノードが偶数番の集合に属しているとき、それと繋がっているノードが奇数番号の集合かつ差が１である
　→二部グラフ
（２）V_1とV_kがあるとき、少なくともそれらはk本の辺をたどらなければ繋がれないはずなので、最も距離の長い辺（直径）を探す
"""

from collections import deque

N = int(input())
es = [[] for _ in range(N)]

for i in range(N):
    S = input()
    for j in range(N):
        if S[j] == "1":
            es[i].append(j)


q = deque()
q.append(0)
checked = [0] * N
checked[0] = 1
while q:
    curr = q.popleft()
    for nxt in es[curr]:
        # 未探索なので、currと別の集合に設定
        if checked[nxt] == 0:
            checked[nxt] = checked[curr] * -1
            q.append(nxt)
        else:
            # 探索済みなので、別の集合に属しているか確認し、同じであれば条件を満たさない
            if checked[nxt] == checked[curr]:
                print(-1)
                exit()



# グラフの直径を求める。それぞれのノードをスタート地点として、全ノード間の距離を求めたときの最大距離が直径
ans = 0
for i in range(N):
    q = deque()
    q.append(i)
    dist = [0] * N
    # 距離＋１が答えなので、起点を１としておく
    dist[i] = 1
    while q:
        curr = q.popleft()
        for nxt in es[curr]:
            if dist[nxt] == 0:
                dist[nxt] = dist[curr] + 1
                q.append(nxt)

    ans = max(ans, max(dist))

print(ans)

Measured memory_bytes: 41708
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll a, b, c;
int main() {
    cin>>a>>b>>c;
    cout<<min(b/a, c)<<endl;
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
ok = true
x = 0
y = 0
t = 0
N.times do
  gt, gx, gy = gets.split.map(&:to_i)
  dist = (gx - x).abs + (gy - y).abs
  dt = (gt - t).abs
  if dist > dt || (dt - dist) % 2 != 0
    ok = false
    break
  end
  t, x, y = gt, gx, gy
end

puts ok ? "Yes" : "No"



Measured memory_bytes: 3836