akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法
#define JUUHATI 1000000000000000000 
#define JUUHATIPLUS 1000000000000000001 

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    ll N,K,ans1,ans2;
    cin >> N  >> K;

    if(N % K == 0 or N == K)
        ans1 = 0;
    else {
        ans1 = N % K;
        ans2 = ans1;
        if(K - ans1 < ans2)
            ans1 = K - ans2;
    }
    cout << ans1 << endl;

}

Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    int n,m;
    cin >> n >>m;
    vector<int> vec1(m);
    vector<int> vec2(m-1);
    for(int i=0;i<m;i++){
        int x;
        cin >> x;
        vec1[i]=x;
    }
    sort(vec1.begin(),vec1.end(),greater<int>());
    for(int i=0;i<m-1;i++){
        vec2[i]=vec1[i]-vec1[i+1];
    }
    sort(vec2.begin(),vec2.end(),greater<int>());
    if(n>=m){
        cout <<0<<endl;
    }else{
        int count=0;
        for(int i=0;i<n-1;i++){
            count += vec2[i];
         //   cout << vec2[i]<<endl;
        }
        cout << vec1[0]-vec1[m-1]-count<<endl;
       // cout <<vec1[m-1]<<" "<<vec1[0]<<endl;
    }
    
}


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

int main()
{
  int a, b;
  cin >> a >> b;

  string buf;

  if( a > b ) {
    buf = "a > b";
  }
  if( a < b ) {
    buf = "a < b";
  }
  if( a == b ) {
    buf = "a == b";
  }

  cout << buf << endl;

  return 0;
}

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

namespace Atc_0032
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            if (s.Substring(s.Length - 1, 1) == "s")
            {
                s += "es";
            }
            else
            {
                s += "s";
            }

            Console.WriteLine(s);

        
        }
    }
}


Measured memory_bytes: 25888
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
	cin>>a>>b;
	if (a>b) swap(a,b);
	if (a==1&&b==2) cout<<3<<endl;
	if (a==1&&b==3) cout<<2<<endl;
	if (a==2&&b==3) cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		for(int i = sc.nextInt(); i>0; i--){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			if(a*a == (b*b + c*c) || b*b == (a*a + c*c) || c*c == (a*a + b*b))
				System.out.println("YES");
			else
				System.out.println("NO");
		}
	}
}

Measured memory_bytes: 23368
import java.util.*;
import java.io.*;

public class Main {

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

			for(int i = 0; i < 3; i++)
			{
				String str = in.nextLine();
				for(int j = 0; j < 3; j++)
					matrix[i][j] = str.charAt(j);
			}
			for(int k = 0; k < 3; k++)
				System.out.print(matrix[k][k]);
	}
    
}

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

#define xin() main()
#define ru(a) if(a)
#define ruguo(a) else if(a)
#define baai(a) while(a)
#define sai(j,n) for(sei j=0;j<sei(n);++j)
#define gsai(j,n) for(sei j=sei(n)-1;j>=0;--j)
#define kan(j,m,n) for(sei j=m;j<sei(n);++j)
#define gkan(j,m,n) for(sei j=sei(n)-1;j>=sei(m);--j)
#define ta else
#define datu break
#define zi continue;
#define hen return
#define zen(h) (h).begin(),(h).end()
#define seiri(h) sort(zen(h))
#define yu(h) h.erase(unique(zen(h)), h.end())
#define gyaku(a) reverse(zen(a))
#define katu &&
#define mata ||
#define nyu(a) cin >> a
#define syutu(a) cout << a << endl
#define tuika(a,b) a.push(b)
#define huka(a,b) a.push_back(b)
#define tou(a) a.top()
#define kuu(a) a.empty()
#define xya(a) a.pop()
#define cyou(a) a.size()
#define tyou(a) a.length()
#define sen first
#define go second
#define kouzoutai struct
#define kigou operator
#define sin true
#define gi false
#define tei const
#define mugen 10000000111
#define yo 10000000711
#define kyou 1e-9

using namespace std;

typedef int seisu;
typedef void mu;
typedef long long sei;
typedef long double xyo;
typedef string moji;
typedef pair<sei, sei> so;
typedef pair<xyo, xyo> sox;
typedef vector<sox> hsox;
typedef vector<sei> hs;
typedef vector<hs> hhs;
typedef vector<xyo> hx;
typedef vector<hx> hhx;
typedef vector<moji> hm;
typedef vector<so> hso;
typedef vector<hso> hhso;
typedef bool singi;
typedef vector<singi>  hsi;
typedef vector<hsi> hhsi;
typedef priority_queue<sei> nibungi;

const seisu h1[8] = {1,1,0,-1,-1,-1,0,1};
const seisu h2[8] = {0,1,1,1,0,-1,-1,-1};

sei dai(sei a, sei b){return max(a,b);}
sei syou(sei a, sei b){return min(a,b);}

sei k;

sei kai(sei k){
    ru(k%2 == 0){
        hen(k*k/4);
    }
    ta{
        hen((k*k-1)/4);
    }
}

seisu xin(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    nyu(k);
    syutu(kai(k));
    hen 0;
}

Measured memory_bytes: 256
fn main() {
    let input = read_vec::<i32>();
    let res = input[0] * input[1];
    if res % 2 == 0 {
        println!("Even");
    } else {
        println!("Odd");
    }
}

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> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
n=int(input())
s=list(input())

flag=True

while flag:
    ans=[]
    for i in range(len(s)):
        if i==0:
            ans.append(s[i])
        else:
            if s[i-1]!=s[i]:
                ans.append(s[i])

    if ans==s:
        flag=False
    else:
        s=ans
print(len(ans))

Measured memory_bytes: 4652
class UnionFind
  attr_accessor :par

  def initialize(n)
    @par = Array.new(n) { |i| i }
  end

  def root(x)
    return x if @par[x] == x

    return @par[x] = root(@par[x])
  end

  def unite(x, y)
    rx = root(x)
    ry = root(y)

    return if rx == ry

    @par[rx] = ry
  end

  def same(x, y)
    root(x) == root(y)
  end

  def to_h
    @par.each.with_index.each_with_object({}) do |(_, i), sum|
      ri = root(i)
      sum[ri] = [] unless sum[ri]
      sum[ri].push(i)
    end
  end
end

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_int
  gets.chomp.to_i
end

N, M = get_ints
ps = get_ints.map { |x| x - 1 }

union_find = UnionFind.new(N)

M.times do
  x, y = get_ints
  x -= 1
  y -= 1
  union_find.unite(x, y)
end

hash = union_find.to_h

result = 0

hash.values.each do |group|
  p_group = group.map { |x| ps[x] }
  result += (group & p_group).length
end

puts result


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

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int res = a * x + b * y;
    res = min(res, (c * 2) * max(x, y));
    res = min(res, min(x, y) * 2 * c + a * (x - min(x,y)) + b * (y - min(x, y)));
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2510, INF = 0x3f3f3f3f;
int n, m, p, a, b, c, ans = 0;

struct Edge
{
    int from,to,dist;
    Edge(int u,int v,int w):from(u),to(v),dist(w){    }
};
struct SPFA
{
    int n,m;
    vector<Edge>edges;
    vector<int>G[MAXN];
    bool vis[MAXN];
    int d[MAXN];
    int p[MAXN];
    int cnt[MAXN];
    void init(int n)
    {
        this->n = n;
        edges.clear();
        for(int i=0;i<=n;i++)G[i].clear();
    }
    void AddEdge(int from,int to,int dist)
    {
        edges.push_back(Edge(from,to,dist));
        m = edges.size();
        G[from].push_back(m-1);
    }
    bool spfa(int s)
    {
        for(int i=0;i<=n;i++)d[i] = INF;
        memset(vis,0,sizeof(vis));
        memset(cnt,0,sizeof(cnt));
        d[s] = 0; vis[s] = true;
        queue<int>Q;
        Q.push(s);
        while(!Q.empty())
        {
            int u = Q.front();
            Q.pop();
            vis[u] = false;
            for(int i=0;i<G[u].size();i++)
            {
                Edge &e = edges[G[u][i]];
                if(d[u] < INF && d[e.to] > d[u] +e.dist)
                {
                    d[e.to] = d[u] + e.dist;
                    p[e.to] = G[u][i];
                    if(!vis[e.to])
                    {
                        Q.push(e.to);vis[e.to] = true;
                        if(++cnt[e.to] > n+2500) return false;
                    }
                 }
            }
        }
        return true;
    }
}bf;

int main() {
    cin >> n >> m >> p;
  	bf.init(n);
    for(int i = 0; i < m; i++) scanf("%d%d%d", &a, &b, &c), bf.AddEdge(--a, --b, -c+p);
    bf.spfa(0);
    if(bf.cnt[n-1] > n) cout << -1;
    else cout << max(-bf.d[n-1], 0);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main(){
	
	fastio;
	int n , X, T;
	cin >> n >> X >> T;
	int rem = n%X;
	int ans ;
	if(rem==0)
	ans = (n/X)*T;
	else
	ans = ((n/X)+1)*T;
	cout << ans << "\n";
	
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
using namespace std;
long long p[100010];
int n,m;
const long long md=1e9+7;
int mabs(int x)
{
	if(x<0)return -x;
	return x;
}
int main()
{
	scanf("%d%d",&n,&m);
	if(mabs(n-m)>1)
	{
		printf("0");
		return 0;
	}
	p[0]=1LL;
	for(int i=1;i<=max(n,m);i++)p[i]=p[i-1]*i%md;
	long long ans=p[n]*p[m]%md;
	if(n==m)ans=ans*2LL%md;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
 int x, y;
 char c;
 do {
  scanf("%d %s %d", &x, &c, &y);
  switch(c) {
   case '+':
    printf("%d\n", x + y);
    break;
   case '-':
    printf("%d\n", x - y);
    break;
   case '*':
    printf("%d\n", x * y);
    break;
   case '/':
    printf("%d\n", x / y);
    break;
  }
 } while (c != '?');
 return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cstring>

int main(void)
{
  char W[11],T[1001];
  int i,j,ans=0;

  scanf("%s", &W);
  
  for(i=0;W[i]!='\0';i++){
    if('A'<=W[i]&&W[i]<='Z') W[i]=W[i]-'A'+'a';
  }

  for(;;){
    scanf("%s", T);
    if(strcmp(T,"END_OF_TEXT")==0) break;
    
    for(j=0;T[j]!='\0';j++){
      if('A'<=T[j]&&T[j]<='Z') T[j]=T[j]-'A'+'a';
    }
    if(strcmp(T,W)==0) ans++;
  }

  printf("%d\n", ans);

  return 0;
}


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

#include <math.h>
#include <stdlib.h>


#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_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int X, A, B;
    cin >> X >> A >> B;
    int rest = X - A;
    cout << rest%B << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

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()
{
    char s;
    cin >> s;
    if(s == 'A'){
        cout << 'T' << endl;
    }else if(s == 'T'){
        cout << 'A' << endl;
    }else if(s == 'C'){
        cout << 'G' << endl;
    }else if(s == 'G'){
        cout << 'C' << endl;
    }
    return 0;
}

Measured memory_bytes: 3600
// atcoder/abc130/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli h, w, x, y;
  while (cin >> w >> h >> x >> y) {
    bool f = false;
    if (2 * x == w && 2 * y == h) f = true;
    printf("%.10lf %d\n", h * w / 2.0, f);
  }


  return 0;
}


Measured memory_bytes: 256
import math

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

a1 = math.pi*(60*h+m)/360
b1 = math.pi*m/30

print(math.sqrt( (a*math.cos(a1) - b*math.cos(b1))**2 + (a*math.sin(a1) - b*math.sin(b1))**2))



Measured memory_bytes: 9500
#include<stdio.h>
int main(){
	char x[1200] = { 0 };
	int i;
	gets(x);
	for (i = 0; i < 1200; i++){
		switch (x[i]){
		case 'a':x[i] = 'A';
				break;
		case 'b':x[i] = 'B';
			break;
		case 'c':x[i] = 'C';
			break;
		case 'd':x[i] = 'D';
			break;
		case 'e':x[i] = 'E';
			break;
		case 'f':x[i] = 'F';
			break;
		case 'g':x[i] = 'G';
			break;
		case 'h':x[i] = 'H';
			break;
		case 'i':x[i] = 'I';
			break;
		case 'j':x[i] = 'J';
			break;
		case 'k':x[i] = 'K';
			break;
		case 'l':x[i] = 'L';
			break;
		case 'm':x[i] = 'M';
			break;
		case 'n':x[i] = 'N';
			break;
		case 'o':x[i] = 'O';
			break;
		case 'p':x[i] = 'P';
			break;
		case 'q':x[i] = 'Q';
			break;
		case 'r':x[i] = 'R';
			break;
		case 's':x[i] = 'S';
			break;
		case 't':x[i] = 'T';
			break;
		case 'u':x[i] = 'U';
			break;
		case 'v':x[i] = 'V';
			break;
		case 'w':x[i] = 'W';
			break;
		case 'x':x[i] = 'X';
			break;
		case 'y':x[i] = 'Y';
			break;
		case 'z':x[i] = 'Z';
			break;
		case 'A':x[i] = 'a';
			break;
		case 'B':x[i] = 'b';
			break;
		case 'C':x[i] = 'c';
			break;
		case 'D':x[i] = 'd';
			break;
		case 'E':x[i] = 'e';
			break;
		case 'F':x[i] = 'f';
			break;
		case 'G':x[i] = 'g';
			break;
		case 'H':x[i] = 'h';
			break;
		case 'I':x[i] = 'i';
			break;
		case 'J':x[i] = 'j';
			break;
		case 'K':x[i] = 'k';
			break;
		case 'L':x[i] = 'l';
			break;
		case 'M':x[i] = 'm';
			break;
		case 'N':x[i] = 'n';
			break;
		case 'O':x[i] = 'o';
			break;
		case 'P':x[i] = 'p';
			break;
		case 'Q':x[i] = 'q';
			break;
		case 'R':x[i] = 'r';
			break;
		case 'S':x[i] = 's';
			break;
		case 'T':x[i] = 't';
			break;
		case 'U':x[i] = 'u';
			break;
		case 'V':x[i] = 'v';
			break;
		case 'W':x[i] = 'w';
			break;
		case 'X':x[i] = 'x';
			break;
		case 'Y':x[i] = 'y';
			break;
		case 'Z':x[i] = 'z';
			break;
		default:break;

		}
	}
	puts(x);
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>//author::@whohet-->Het Patel
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define test int T; cin>>T; while(T--)
#define endl "\n"
#define int long long
#define uint unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vvi vector<vector<int>>
#define mii map<int,int>
#define msi map<string,int>
#define mis map<int,string>
#define pb push_back
#define mod 1000000007
#define PI 3.141592653589793238

using namespace std;

//author::@whohet-->Het Patel

signed main()
{
	fasterthanlight;
	int n;
	cin>>n;
	int x=100,t=0;
	while(x<n)
	{
		int p=(x)/100;
		x=x+p;
		t++;

	}
	cout<<t;
}


Measured memory_bytes: 3636
# -*- coding: utf-8 -*-

# 終了後、重複処理を整理した版

from collections import deque

N = int(input())
aN = [int(input()) for i in range(N)]

# 受け取ったリストを前後から交互に並べていく
def changeList(_list):
    _list = deque(_list)
    res = [0] * N
    for i in range(N):
        if i % 2 == 0:
            res[i] = _list.popleft()
        else:
            res[i] = _list.pop()
    return res

# 受け取ったリストの隣り合う差の合計、最後だけ先頭とも比べて大きい方
def sumList(_list):
    ans = 0
    for i in range(1,N):
        if i == N-1:
            ans += max(abs(_list[i-1] - _list[i]), abs(_list[i] - _list[0]))
        else:
            ans += abs(_list[i-1] - _list[i])
    return ans

# 昇順と降順、両方試して良かった方を使う
aN2 = changeList(sorted(aN))
aN3 = changeList(sorted(aN, reverse=True))

print(max(sumList(aN2), sumList(aN3)))

Measured memory_bytes: 10656
a, b, c, x, y = map(int, input().split())
if a + b >= 2*c and x <= y and (2*c*x + b*(y-x)) >= 2*c*y:
    print(2*c*y)
elif a + b >= 2 * c and x <= y and (2 * c * x + b * (y - x)) < 2 * c * y:
    print(2 * c * x + b * (y - x))
elif a + b >= 2*c and x > y and (2*c*y + a*(x-y)) >= 2*c*x:
    print(2*c*x)
elif a + b >= 2 * c and x > y and (2 * c * y + a * (x - y)) < 2 * c * x:
    print(2*c*y + a*(x-y))
elif a + b < 2*c:
    print(a*x + b*y)

Measured memory_bytes: 3064
import sys
numbers = []
for line in sys.stdin:
	numbers.append(int(line))

k = []
k.append(1)
k.append(1)

def getFib(i, n):
    if i == n :
        print(k[-1])
        return
    k.append(int(k[i - 1]) + int(k[i - 2]))
    getFib(i + 1, n)

getFib(2, int(numbers[0])+1)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1005,M=1e9+7;
int n,A,B,C,D,fac[N],inv[N],dp[N][N];
int ksm(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=x*x%M)
		if (y&1)(ans*=x)%=M;
	return ans;	
}
signed main(){
	scanf("%lld%lld%lld%lld%lld",&n,&A,&B,&C,&D);
	dp[0][A-1]=1;
	fac[0]=inv[0]=1;
	for (int i=1;i<=n;i++)fac[i]=fac[i-1]*i%M,inv[i]=ksm(fac[i],M-2);
	for (int i=0;i<=n;i++)
		for (int j=A;j<=B;j++){
			dp[i][j]=dp[i][j-1];
			for (int k=C,p=ksm(inv[j],C);k<=D;k++,(p*=inv[j])%=M){
				if (i-j*k<0)break;
				(dp[i][j]+=dp[i-j*k][j-1]*p%M*inv[k])%=M;
			}
		}
	printf("%lld\n",dp[n][B]*fac[n]%M);
} 

Measured memory_bytes: 8064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final Scanner sc  = new Scanner(System.in);
    static final int     MOD = (int) 1E9 + 7;
    
    public static void main(String[] args) {
        int N = nint();
        int[] d = nints(N);
        long sum = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                sum += d[i] * d[j];
            }
        }
        System.out.println(sum);
    }
    
    private static int nint() {
        return sc.nextInt();
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }

    private static double ndouble() {
        return sc.nextDouble();
    }

    private static double[] ndoubles(int n) {
        return ndoubles(n, 0, 0);
    }

    private static double[] ndoubles(int n, int padL, int padR) {
        double[] d = new double[n + padL + padR];
        for (int i = 0; i < n; i++) {
            d[padL + i] = ndouble();
        }
        return d;
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static char[] nchars(int padL, int padR) {
        char[] temp = sc.next().toCharArray();
        char[] ret = new char[temp.length + padL + padR];
        System.arraycopy(temp, 0, ret, padL, temp.length);
        return ret;
    }

    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0, 0);
    }

    private static char[][] nchars2(int h, int w, int padLU, int padRD) {
        char[][] a2 = new char[h + padLU + padRD][w + padLU + padRD];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[padLU + i], padLU, w);
        return a2;
    }

    private static long min(long... ls) {
        return Arrays.stream(ls).min().getAsLong();
    }

    private static int min(int... is) {
        return Arrays.stream(is).min().getAsInt();
    }

    private static long max(long... ls) {
        return Arrays.stream(ls).max().getAsLong();
    }

    private static int max(int... is) {
        return Arrays.stream(is).max().getAsInt();
    }

    private static long abs(long a, long b) {
        return Math.abs(a - b);
    }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
 using namespace std;
int main(){
  int k, odd = 0, even = 0;
  cin >> k;
  for (int i = 1; i < k+ 1; i++) {
    if (i % 2 == 0) {
      even++;
    }else{
      odd++;
    }
  }

    cout << even * odd << "\n";
}


Measured memory_bytes: 256
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 全探索
N, M, X = lr()
CA = np.array([lr() for _ in range(N)])
INF = 10 ** 9
answer = INF
for pattern in range(1<<N):
    temp = 0
    algo = np.zeros(M+1, dtype=np.int32)
    for i in range(N):
        if (pattern>>i) & 1:
            algo += CA[i]
    if np.all(algo[1:] >= X) and algo[0] < answer:
        answer = algo[0]

print(answer if answer != INF else -1)


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

#define ll long long int
#define pb push_back
#define MP make_pair
#define PLL pair<ll,ll>
#define fastio ios::sync_with_stdio(0);cin.tie(0);

ll arr[1000009];

long double calcAngle(long double h, long double m)
{
    // validate the input

    if (h == 12) h = 0;
    if (m == 60) m = 0;

    long double hour_angle = 0.5 * (h * 60 + m);
    long double minute_angle = 6 * m;


    long double angle = abs(hour_angle - minute_angle);

    // Return the smaller angle of two possible angles
    angle = min(360 - angle, angle);

    return angle;
}

int main()
{
  long double a,b,h,m;
  cin >> a>>b>>h>>m;
  long double ans=calcAngle(h,m);
  //cout << ans;


    long double pi = 2 * acos(0.0);
     ans=ans * (pi/180);


  long double c;

 c=sqrt(a*a + b*b -2*a*b*cos(ans));
  cout << fixed << setprecision(10) << c <<endl;
}


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

int main()
{
	int input;
	scanf("%d", &input);

	int digit2 = input / 100;
	// cout << digit2 << '\n';
	int digit1 = (input - digit2 * 100) /10;
	// cout << digit1 << '\n';
	int digit0 = (input - digit2 * 100) % 10;
	// cout << digit0 << '\n';

	if (digit0 == digit1 && digit0 == digit2)
	{
		printf("%d\n", input);
	}
	else
	{
		int temp = 100*digit2 + 10*digit2 + digit2;
		if(input < temp)
		{
			printf("%d\n", temp);
		}
		else
		{
			printf("%d\n", temp + 111);
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
using vc=vector<char>;
int main(){
  vc alpha={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  char C; cin>>C;
  rep(i,25){
    if(alpha[i]==C) cout<<alpha[i+1];
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll unsigned long long
#define inf 1000000007 //10^9+7
#define sort(vec) sort(vec.begin(),vec.end());
#define rever(vec) reverse(vec.begin(),vec.end());
#define unsort(vec) sort(vec); rever(vec);
#define gcd __gcd
using namespace std;

int main() {
  string s;
  cin>>s;
  ll ans=0;
  for(ll i=0;i<3;i++) {
    if(s.at(i)-'0') {
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int w = sc.nextInt();
			int h = sc.nextInt();
			if( (w|h) == 0 ) break;
			int[][] dp = new int [h+1][w+1];
			int n = sc.nextInt();
			
			for(int i=0;i<n;i++) {
				int x = sc.nextInt();
				int y = sc.nextInt();
				dp[y][x] = -1;
			}
			dp[1][0] = 1;
//			for(int i=0;i<=w;i++) dp[1][i] = (dp[1][i] < 0)? -1:1; 
			for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) {
				if(dp[i][j] < 0 ) continue;
				dp[i][j] = max(0, dp[i-1][j]) + max(0, dp[i][j-1]);
//				for(int[] a: dp) debug(a);
//				debug();
			}
			System.out.println(dp[h][w]);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
	void debug(Object...os){
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9 + 7;
const int INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
   double x,y;
   int n;cin>>n;
   vector<P> t;
   vector<double> l;
   rep(i,n){
       cin>>x>>y;
       t.push_back(P(x,y));
   }
   rep(i,n){
       for(int k=i+1;k<n;k++){
           l.push_back(sqrt((t[i].first-t[k].first)*(t[i].first-t[k].first)+(t[i].second-t[k].second)*(t[i].second-t[k].second)));
       }
   }
   double ans=0;
   long long count=1,p=n-1;
   rep(i,n-1){
       count*=p;
       p--;
   }
   rep(i,l.size()){
       ans+=l[i]*count*2;
   }
   count*=n;
   printf("%.10lf\n",ans/count);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <complex>
#include <iomanip>
#include <cassert>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <cstring>
#include <climits>
using namespace std;
#define nl '\n'
#define sp ' '
#define f first
#define s second
#define boost() cin.tie(0); cout.tie(0); cin.sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5+2; // REMEMBER TO CHANGE
const int MOD = 1e9+7;
int N;
ll dp[2][MAXN];
vector<int>adj[MAXN];
void dfs(int cur, int pre){
	ll white = 1, black = 1;
	for(int i:adj[cur]){
		if(i==pre) continue;
		dfs(i, cur);
		white = (white*dp[0][i])%MOD+(white*dp[1][i])%MOD;
		black = (black*dp[0][i])%MOD;
	}
	dp[0][cur] = white, dp[1][cur] = black;
}
int main(){
	boost();
	cin >> N;
	for(int i = 1, x, y;i<=N-1;i++){
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs(1, 0);
	cout << (dp[1][1]+dp[0][1])%MOD << nl;
	return 0;
}

Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
struct state{
  int bit,p,cost;
  bool operator < (const state &p)const{
    return cost > p.cost;
  }
};
#define INF (1<<26)

int n;
string t[20];
int cost[20][20];
int id[20][20];

void calc(int a,int b){
  string A=t[a],B=t[b];
  int as=A.size(),bs=B.size();
  int i,j;
    
  for(i=0;i<as;i++){
    bool flg=true;
    for(j=0;j<bs&&i+j<as;j++){
      if(A[i+j]!=B[j]){
        flg=false;
        break;
      }
    }
    
    if(flg){
      cost[a][b]=bs-j;
      if(cost[a][b]==0)id[a][b]=a;
      else id[a][b]=b;
      return;
    }
  }
  
  cost[a][b]=bs;
  id[a][b]=b;
}

int d[(1<<14)][20];

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++)cin>>t[i];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(i!=j){
          calc(i,j);
          //cout<<t[i]<<' '<<t[j]<<endl;
          //cout<<cost[i][j]<<' '<<id[i][j]<<endl;
          //cout<<endl;
        }
      }
    }

    for(int i=0;i<(1<<14);i++)
      for(int j=0;j<20;j++)
        d[i][j]=INF;
    priority_queue<state> Q;
    for(int i=0;i<n;i++){
      state s;
      s.bit=(1<<i);
      s.cost=t[i].size();
      s.p=i;
      d[s.bit][s.p]=s.cost;
      Q.push(s);
    }
    while(!Q.empty()){
      state s=Q.top();Q.pop();
      if(s.cost>d[s.bit][s.p])continue;
      if(s.bit==(1<<n)-1){
        cout<<s.cost<<endl;
        break;
      }
      int S=s.bit;
      for(int i=0;i<n;i++){
        if(S>>i&1)continue;
        int nbit=S+(1<<i);
        int ncost=s.cost+cost[s.p][i];
        int to=id[s.p][i];
        if(ncost<d[nbit][to]){
          d[nbit][to]=ncost;
          Q.push((state){nbit,to,ncost});
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 4748
h, w = map(int, input().split())
lst = []
block = 0
for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == '#':
            block += 1
        lst.append(s[j])
queue = [(1, 0)]
visited = set()
flag = False
while queue:
    #print(queue)
    step, pos = queue.pop(0)
    if pos in visited:
        continue
    if pos == h * w - 1:
        flag = True
        ans = step
        break
    visited.add(pos)
    step += 1
    if pos > (pos // w) * w:
        if lst[pos - 1] == '.':
            queue.append((step, pos - 1))
    if pos < ((pos // w) + 1) * w - 1:
        if lst[pos + 1] == '.':
            queue.append((step, pos + 1))
    if pos >= w:
        if lst[pos - w] == '.':
            queue.append((step, pos - w))
    if pos < (h - 1) * w:
        if lst[pos + w] == '.':
            queue.append((step, pos + w))
if flag:
    print(h * w - block - ans)
else:
    print(-1)

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;
using namespace std;

signed main() {
  ll N,s=0;
  cin>>N;
  vector<ll> A(N);
  vector<ll> x(N);
  rep(i,0,N){
    cin>>A[i];
    if (i%2 ==0) {
      s+=A[i];
    } else {
      s-=A[i];
    }
  }

  x[0] = s;
  rep(i,1,N){
    x[i] = 2*A[i-1]-x[i-1];
  }

  rep(i,0,N){
    cout<<x[i];
    if (i==N-1)
      cout<<endl;
    else
      cout<<" ";
  }
  return 0;
}



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


int n;
int a[1000];



int main()
{
    cin >> n;
    for (int i = 0; i < 2*n; i++)
    {
        cin >> a[i];
    }
    sort(a,a+n*2);
    int ans = 0;
    for (int i = 0; i < 2*n; i+=2) ans += a[i];
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (c >= (a + b) && 4 * a * b < (c - a - b) * (c - a - b)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return (0 ^ _ ^ 0);
}



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

using namespace std;


vector<long long> a;
vector<long long> p;
long long f(long long n, long long x) {
    if (n == 0) {
        if (x <= 0) {
            return 0;
        } else {
            return 1;
        }
    } else if (x <= 1 + a[n - 1]) {
        return f(n - 1, x - 1);
    } else {
        return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1]);
    }
}

int main(){
  int n;
  long long x;
  cin >> n >> x;
  a.push_back(1);
  p.push_back(1);
  for(int i = 0; i < n;i++){
    a.push_back(a[i]*2 + 3);
    p.push_back(p[i]*2 + 1);
  }
  long long ans = f(n,x);

  cout << ans << endl;
}


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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x));
#define umin(m, x) (m = min(m, x));

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

using ll = long long int;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

inline void yn(bool f) { cout << (f ? "Yes" : "No") << endl; }


int main() {
    ll n, m;
    cin >> n >> m;

    vl h(n);
    rep(i, n) cin >> h[i];

    vl a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    vb f(n, true);
    rep(i, m) {
        if (h[a[i]] <= h[b[i]])
            f[a[i]] = false;
        if (h[a[i]] >= h[b[i]])
            f[b[i]] = false;
    }

    ll cnt = 0;
    rep(i, n) {
        if (f[i]) {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 5636
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    int target[M];
    for(int i = 0; i < M; ++i) cin >> target[i];
    vector<int> point(N,0);
    int b;
    for(int i = 0; i < M; ++i){
        int x = 0;
        for(int j = 0; j < N; ++j){
            cin >> b;
            if(b == target[i]) ++point[j];
            else ++x;
        }
        point[target[i]-1] += x;
    }
    for(int i = 0; i < N; ++i)
        cout << point[i] << endl;
    return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;


int main(void){

  int n;
  while( cin >> n , n){

    string s;
    while(n){
      int dgt = n % 10;
      if( dgt < 0 ) dgt += 10;
      s += ( dgt + '0' );
      n = ( n - dgt ) / (-10);
    }
    reverse( s.begin() , s.end() );
    cout << s << endl;

  }
  return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    int a[n+3];
    a[0]=0;
    a[n+1]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int tot=0;
    for(int i=1;i<=n+1;i++)
    {
        tot+=abs(a[i]-a[i-1]);
    }

    for(int i=1;i<=n;i++)
    {
        if(a[i]>=a[i-1]&&a[i]<=a[i+1])
            cout<<tot<<"\n";
        else if(a[i]<=a[i-1]&&a[i]>=a[i+1])
            cout<<tot<<"\n";
        else
        {
            int z=abs(a[i]-a[i-1])+abs(a[i]-a[i+1]);
            z-=abs(a[i+1]-a[i-1]);
            cout<<tot-z<<'\n';
        }
    }
}


Measured memory_bytes: 2048
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    int ans = 0;
    map<pair<int, int>, int> memo;
    for (int x = 1; x <= n; x++)
    {
        int b = x % 10, a = x;
        if (b == 0)
        {
            continue;
        }
        while (a > 9)
        {
            a /= 10;
        }
        memo[make_pair(b, a)]++;
    }

    for (int x = 1; x <= n; x++)
    {
        int b = x % 10, a = x;
        if (b == 0)
        {
            continue;
        }
        while (a > 9)
        {
            a /= 10;
        }
        ans += memo[make_pair(a, b)];
    }
    cout << ans << endl;
}

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


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

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, s, a) for (int i = s; i < a; i++)
#define llint long long int
using namespace std;

const int N_MAX = 505;
const llint INF = 999999999999999;

int n, m, q, ans[N_MAX][N_MAX], trn[N_MAX][N_MAX], sum[N_MAX][N_MAX];
queue<int> slv;


int ans_out(void) {
    rep(i, n) {
        rep(j, n) cout << ans[i][j] << ' ';
        cout << endl;
    }
    cout << endl;
    return 0;
}

int sum_out(void) {
    rep(i, n) {
        rep(j, n) cout << sum[i][j] << ' ';
        cout << endl;
    }
    cout << endl;
    return 0;
}



int main()
{
    cin >> n >> m >> q;
    rep(i, m) {
        int b, e;
        cin >> b >> e;
        --b;  --e;
        ++trn[b][e];
    }

    rep(i, n) ans[i][i] = trn[i][i];


    rep(j, n) {
        sum[0][j] = trn[0][j];
        reps(i, 1, n) {
            if (i <= j) sum[i][j] = sum[i - 1][j] + trn[i][j];
        }
    }


    rep(i, n) {
        ans[i][i] = trn[i][i];
        reps(j, 1, n) {
            if (i < j) {
                ans[i][j] = ans[i][j - 1] + sum[j][j];
                if (i > 0) ans[i][j] -= sum[i - 1][j];
            }
        }
    }

    
       
    //sum_out(); ans_out();

    
    rep(i, q) {
        int s, e;
        cin >> s >> e;
        --s; --e;
        slv.push(ans[s][e]);
    }
    while (!slv.empty()) {
        cout << slv.front() << endl;
        slv.pop();
    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

template <typename CLASS1, typename CLASS2>
bool operator==(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value == hoge2.value;
};

template <typename CLASS1, typename CLASS2>
bool operator<(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value < hoge2.value;
};

template <typename CLASS1, typename CLASS2>
bool operator>(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value > hoge2.value;
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vll d(N);
  REP(i,N) IN(d[i]);

  sort(ALL(d));

  OUT(d[N/2] - d[N/2-1]);

  return 0;
}


Measured memory_bytes: 1024
use std::cmp::min;

const INF: usize = 1 << 50;
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let h: usize = sc.read();
    let n: usize = sc.read();
    let ab = (0..n)
        .map(|_| (sc.read::<usize>(), sc.read::<usize>()))
        .collect::<Vec<_>>();
    let mut dp = vec![INF; h + 1];
    dp[0] = 0;
    for (a, b) in ab.into_iter() {
        for cur in 0..h {
            if dp[cur] == INF {
                continue;
            }
            let next = min(cur + a, h);
            dp[next] = min(dp[next], dp[cur] + b);
        }
    }
    println!("{}", dp[h]);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main()
{
    string N;
    while ( cin >> N, N != "0000" ) {
        int cnt = 0;
        set < string > st;

        while ( N != "6174" && st.find(N) == st.end() ) {
            string L = N, S = N;
            int val = 0;
            st.insert(N);
            sort(rbegin(L), rend(L));
            sort(begin(S), end(S));
            val = atoi(L.c_str()) - atoi(S.c_str());
            N = to_string(val);
            while ( N.size() < 4 ) {
                N = '0' + N;
            }
            cnt++;
        }

        if ( N == "6174" ) {
            cout << cnt << endl;
        } else {
            cout << "NA" << endl;
        }
    }

    return ( 0 );
}



Measured memory_bytes: 3220
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) int __VA_ARGS__; in(__VA_ARGS__)
//オーバーフロー対策
#define INL(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
#pragma endregion RegionDefs

void solve()
{
    INL(n, k);
    ll s = 0;
    if (k == 0)
    {
        cout << n * n << endl;
        return;
    }
    reps(i, k+1, n+1)
    {
        s += (i-k)*(n/i) + max(0LL, n%i-k+1);
    }
    cout << s << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn gcd(n: u64, m: u64) -> u64 {
    if n < m {
        gcd(m, n)
    } else if m == 0 {
        n
    } else {
        gcd(m, n % m)
    }
}

fn main() {
    input! {
        n: usize,
        k: u64,
        a: [u64; n],
    };
    let a_max = *a.iter().max().unwrap();
    let mut g = a[0];
    for &a_i in a.iter().skip(1) {
        g = gcd(g, a_i);
    }
    let ans = k <= a_max && k % g == 0;
    println!("{}", if ans { "POSSIBLE" } else { "IMPOSSIBLE" });
}


Measured memory_bytes: 3672
from sys import stdin

N = int(stdin.readline().rstrip())
lst = [[0, 0, 0]]
for _ in range(N):
    t, x, y = [int(a) for a in stdin.readline().strip().split()]
    lst.append([t, x, y])

ans = True
for i in range(len(lst) - 1):
    dt = abs(lst[i + 1][0] - lst[i][0])
    dx = abs(lst[i + 1][1] - lst[i][1])
    dy = abs(lst[i + 1][2] - lst[i][2])

    if dx + dy > dt or dt % 2 != (dx + dy) % 2:
        ans = False
        break

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 19572