akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"

	//	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

func stringToint(s string) int {
	i, _ := strconv.ParseInt(s, 10, 64)
	return int(i)
}

func noResult() {
	fmt.Println(0)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 10000)
	scanner.Buffer(buf, 1000000)
	line := make([]string, 0, 0)
	data := make([]int, 0, 0)

	for scanner.Scan() && scanner.Text() != "" {
		if scanner.Err() != nil && scanner.Err() == io.EOF {
			break
		}
		line = append(line, scanner.Text())
	}
	if len(line) < 2 {
		noResult()
		return
	}

	input := strings.Split(line[1], " ")

	for _, s := range input {
		data = append(data, stringToint(s))
	}

	if len(data) != stringToint(line[0]) {
		noResult()
		return
	}

	sort.Ints(data)
	totalNum := 0

	if len(data)%2 != 0 {
		if data[0] != 0 {
			noResult()
			return
		} else {
			for i := 0; i < (len(data)-1)/2; i++ {
				if !(data[i*2+1] == int((i+1)*2) && data[i*2+2] == int((i+1)*2)) {
					noResult()
					return
				}
			}
			totalNum = (len(data) - 1) / 2
		}
	} else {
		for i := 0; i < len(data)/2; i++ {
			if !(data[i*2] == int((i+1)*2)-1 && data[i*2+1] == int((i+1)*2)-1) {
				noResult()
				return
			}
		}
		totalNum = len(data) / 2
	}

	var remain int
	remain = 1
	for i := 0; i < totalNum; i++ {
		remain = (remain * 2) % 1000000007
	}
	fmt.Println(remain)
}


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

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    map<int,int> m;

    for(int i=0;i<n;i++){
        cin >> d.at(i);
        m[d.at(i)]++;
    }

    cout << m.size() << endl;
}

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

using namespace std;







int main()
{

	int n;
	vector<int> a;
	vector<int> b;
	vector<int> c;

	cin >> n;

	int wk;

	for (int i = 0; i < n; i++) {
		cin >> wk;
		a.push_back(wk);
	}

	for (int i = 0; i < n; i++) {
		cin >> wk;
		b.push_back(wk);
	}

	for (int i = 0; i < n-1; i++) {
		cin >> wk;
		c.push_back(wk);
	}



	int pre = -100;
	int ans = 0;
	for (int i = 0; i < a.size(); i++) {
		ans += b[a[i]-1];
		if (a[i] - 1 == pre)ans += c[a[i] - 2];
		pre = a[i];
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
li_a = [399, 799, 1199, 1599, 1999, 2399, 2799, 3199, 1000000]
li_b = ["a", "b", "c", "d", "e", "f", "g", "h", 1]

n = int(input())
people = list(map(int,input().split()))
ans = []
cnt = 0

s = 0
t = 0

for i in range(n):
    for j in range(9):
        if people[i] >= 3200:
            cnt += 1
            break
        elif people[i] <= li_a[j]:
            ans.append(li_b[j])
            break

ans = list(set(ans))
if cnt > 0:
    t = cnt
if len(ans) == 0:
    s = 1
print(len(ans)+s,len(ans)+t)


Measured memory_bytes: 3064
// #include<iostream>
// #include<vector>
// #include<algorithm>
// #include<map>
// #include<cstring>
// #include<math.h>
// #include<bitset>
// #include<queue>
// #include<set>
// #include<iomanip>
// #include<math.h>
// #include<assert.h>
// #include<string>
// #include<cstdlib>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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(){
  ll N;
  cin >> N;
  vector<ll> a(N);
  for(int i=0; i<N; i++){
    cin >> a[i];
  }
  map<ll,ll> mp;
  for(int i=0; i<N; i++){
    mp[a[i]]++;
  }
  ll h=0,w=0;
  for(auto m : mp){
    if(m.second >= 4){
      w = m.first;
      h = m.first;
    }else if(m.second>=2){
      w = h;
      h = m.first;
    }
  }
  cout << w*h << endl;
  return 0;
}


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

using namespace std;

	
struct Matrix{
  static const int maxn = 105;
  long long int A[maxn][maxn];
  int n;
 
  Matrix(int n_): n(n_) {
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j)
        A[i][j] = 0;
  }
 
  Matrix operator * (const Matrix& o) const {
    Matrix ret(n);
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j)
        for(int k = 0; k < n; ++k){
          long long int c = A[i][k] * o.A[k][j] % 1000000007;
          ret.A[i][j] = (ret.A[i][j] + c) % 1000000007;
        }
    return ret;
  }
 
  static Matrix identity(int n){
    Matrix ret(n);
    for(int i = 0; i < n; ++i)
      ret.A[i][i] = 1;
    return ret;
  }
 
  Matrix operator ^ (long long k) const {
    Matrix ret = identity(n);
    Matrix a = *this;
    while(k){
      if(k & 1)ret = ret * a;
      a = a * a;
      k /= 2;
    }
    return ret;
  }
 
};

int main(void) {
    long long int N, K;
    cin >> N >> K;
    Matrix matrix(N);
    for(int i=0; i<N; i++) {
        for(int j=0; j<N; j++) {
            cin >> matrix.A[i][j];
        }
    }
    // for(int k=0; k<K-1; k++) {
    //     Matrix matrix_tmp(N, vector<int>(N));
    //     for(int i=0; i<N; i++) {
    //         for(int j=0; j<N; j++) {
    //             for(int l=0; l<N; l++) {
    //                 matrix_tmp[i][j] += matrix[i][l] *matrix[l][j];
    //             }
    //         }
    //     }
    //     matrix = matrix_tmp;
    // }
    // for(int i=0; i<N; i++) {
    //     for(int j=0; j<N; j++) {
    //         cout << matrix[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    matrix = matrix^(K);
    int ans = 0;
    for(int i=0; i<N; i++) {
        for(int j=0; j<N; j++) {
            ans = (ans + matrix.A[i][j]) % 1000000007;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N,M;
    cin >> N >> M;

    vector<ll> d;
    for (ll i = 1; i*i <= M; i++) {
        if(M%i==0) {
            d.pb(i);
            if(i*i != M) d.pb(M/i); //Nが平方数である時の対策
        }
    }

    SORT(d);

    int ans = 0;
    REP(i, d.size()){
        if(d[i] <= (M/N)){
            ans = i;
        }
    }
    pr(d[ans]);
}

Measured memory_bytes: 256
n = gets.to_i
n.times do
  sum = 0
  eleven_num = 0
  k = 2
  gets.chomp.split.each do |c|
    if c =~ /[TJKQ]/
      sum += 10
    elsif c == ?A
      if eleven_num > 0
        sum += 1
      else
        sum += 11
        eleven_num += 1
      end
    else
      sum += c.to_i
    end
  end

  gets.chomp.split.each do |c|
    break if sum > 17
    break if sum == 17 && eleven_num == 0
    k += 1
    if c =~ /[TJKQ]/
      sum += 10
    elsif c == ?A
      if sum + 11 <= 21
        sum += 11
        eleven_num += 1
      else
        sum += 1
      end
    else
      sum += c.to_i
    end
    if sum > 21 && eleven_num > 0
      sum -= 10
      eleven_num -= 1
    end
  end

  if k == 2 && sum == 21
    puts 'blackjack'
  elsif sum > 21
    puts 'bust'
  else
    p sum
  end
end



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

int main() {
  int N; cin >> N;
  vector<string> s(N);
  vector<int> t(N);
  rep(i, N) cin >> s[i] >> t[i];
  string X; cin >> X;

  int ans = 0;
  bool check = false;
  rep(i, N) {
    if (check) ans += t[i];
    if (s[i] == X) check = true;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [long(input_raw[0])]
    coin_list = [1]
    for i in range(1, N):
        if N >= 6 ** i:
            coin_list.append(6 ** i)
        else:
            break

    for i in range(1, N):
        if N >= 9 ** i:
            coin_list.append(9 ** i)
        else:
            break

    dp = [[0 for i in range(N + 1)] for i in  range(len(coin_list) + 1)]
    for j in range(N + 1):
        dp[0][j] = j
    min_dpN = N
    for i in range(1, len(coin_list)):
        for j in range(N + 1):
            if j - coin_list[i] >= 0:
                dp[i][j] = min(dp[i - 1][j], dp[i][j - coin_list[i]] + 1)
            else:
                dp[i][j] = dp[i - 1][j]
        min_dpN = min(dp[i][N], min_dpN)
    print min_dpN

if __name__ == '__main__':
    main()


Measured memory_bytes: 42732
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	a := getNextInt(scanner)
	b := getNextInt(scanner)
	if (a+b)%2 != 0 {
		fmt.Fprintln(writer, "IMPOSSIBLE")
		writer.Flush()
		return
	}
	fmt.Fprintln(writer, (a+b)/2)
	writer.Flush()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 5010;
const int mod = 1e9 + 7;
int n;
char s[maxn];
int f[maxn][maxn];
LL Qpow(LL a, LL b) {
	LL ret = 1;
	for (; b; b >>= 1, a = (a * a) % mod) if(b & 1) ret = (ret * a) % mod;
	return ret;
}
int main() {
	scanf("%d%s", &n, s + 1);
	int len = strlen(s + 1);
	f[0][0] = 1;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= i; ++j) {
			f[i + 1][j + 1] = (f[i + 1][j + 1] + 2 * f[i][j] % mod) % mod;
			f[i + 1][max(j - 1, 0)] = (f[i + 1][max(j - 1, 0)] + f[i][j]) % mod;
		}
	}
	LL ans = (1ll * Qpow(Qpow(2, len), mod - 2) % mod * f[n][len] % mod) % mod;
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
    long long int size;
    std::string str;
    std::cin >> size >> str;
    if (str.size() <= size) {
        std::cout << str << "\n";
    }
    else {
        std::cout << str.substr(0, size) << "...\n";
    }

    return 0;
}

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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    FOREACH(x, v) { cout << x << " "; }                                        \
    cout << "\n";

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N, M;

int main() {
    cin >> N >> M;
    if(N == 1 && M == 1)
        cout << 1 << "\n";
    else if(N == 1 || M == 1)
        cout << max(N, M) - 2 << "\n";
    else
        cout << (N - 2) * (M - 2) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<cmath>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;

int main(){
    char c;
    cin >> c;
    char ans = c + 1;
    cout << ans << endl;
}


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

using namespace std;

#define LIMIT 100
typedef long long ll;
typedef pair<ll, ll> ii;
int gcd(ll a, ll b) { return (b==0)?a:gcd(b, a%b); }
int lcm(ll a, ll b) { ll i=(a/gcd(a,b))*b; assert(i>0); return i; }

//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n, k; cin >> n >> k;
  int a = 1;

  for (int i = 0; i < n; ++i) {
    if(k<a) a+=k;
    else a+=a;
  }

  std::cout << a << std::endl;

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int h, n, a[1010], b[1010], dp[20010];
int main() {
	scanf("%d %d", &h, &n);
	for (int i = 0; i < n; i++)
		scanf("%d %d", a + i, b + i);
	for (int i = 0; i < h; i++)
		dp[i] = 1e9;
	for (int i = 0; i < n; i++)
		for (int k = 20000; a[i] <= k; k--)
			dp[k - a[i]] = min(dp[k - a[i]], dp[k] + b[i]);
	printf("%d\n", dp[0]);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); i++)
#define rrep(i, s, n) for (int i = (s); i > (n); i--)

int m1,d1,m2,d2;
int main()
{
    cin >> m1 >> d1;
    cin >> m2 >> d2;
    int ans;
    ans = (m1==m2) ? 0:1; 
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int A[2000],q,n;

int solve(int a,int M){
  if(M==0){
    return 1;
  }else if(M<0 || a>n){
    return 0;
  }

  if(solve(a+1,M)){
    return 1;
  }
  if(solve(a+1,M-A[a])){
    return 1;
  }
}

int main(){
  int i,S[2000];

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&S[i]);
  }

  for(i=0; i<q; i++){
    if(solve(0,S[i])==1 ){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }
  return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	long double a,b,c,d,e,f;
	while(cin>>a>>b>>c>>d>>e>>f){
		long double x=(c*e-f*b)/(a*e-d*b);
		long double y=(c*d-f*a)/(b*d-e*a);
		cout<<fixed<<setprecision(3)<<(x==-0?0:x)<<" "s;
		cout<<fixed<<setprecision(3)<<(y==-0?0:y)<<"\n"s;
	}
}


Measured memory_bytes: 3284
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


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

    int n;
    cin >> n;
    print(n * n * n);

    return 0;
}



Measured memory_bytes: 256
n=int(input())
a=[int(i) for i in input().split()]
d={}
for i,j in enumerate(a):
    if i<2:
        k=1
        while 1:
            if k*k>j: break
            if j%k==0:
                if k in d:
                    d[k]+=1
                else:
                    d[k]=1
            if j%k==0 and k*k!=j:
                if j//k in d:
                    d[j//k]+=1
                else:
                    d[j//k]=1
            k+=1
    else:
        for k in d:
            if j%k==0:
                if k in d:
                    d[k]+=1
            elif j%k==0 and k*k!=j:
                if j//k in d:
                    d[j//k]+=1
#print(d)
ans=chk=0
for i in d:
    if d[i]>=n-1:
        ans=max(ans,i)
print(ans)


Measured memory_bytes: 84792
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		int minMap[][];
		int kTown;

		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}
			minMap = new int[10][10];
			kTown = 0;
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					if (i == j) {
						minMap[i][j] = 0;
					} else {
						minMap[i][j] = 1000;
					}
				}
			}
			for (int i = 0; i < n; i++) {
				int v1 = sc.nextInt();
				int v2 = sc.nextInt();
				int cost = sc.nextInt();
				minMap[v1][v2] = cost;
				minMap[v2][v1] = cost;
				if (kTown < Math.max(v1,  v2)) {
					kTown = Math.max(v1,  v2);
				}
			}

			for (int k = 0; k <= kTown; k++) {
				for (int i = 0; i <= kTown; i++) {
					for (int j = 0; j <= kTown; j++) {
						minMap[i][j] = Math.min(minMap[i][j], minMap[i][k] + minMap[k][j]);
					}
				}
			}

			int min, minIndex;
			min = Integer.MAX_VALUE;
			minIndex = 0;
			for (int i = 0; i <= kTown; i++) {
				int sum = 0;
				for (int j = 0; j <= kTown; j++) {
					sum += minMap[i][j];
				}
				if (sum < min) {
					min = sum;
					minIndex = i;
				}
			}
			System.out.println(minIndex + " " + min);
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    string X;
    ll N, i, t_count=0, ans=0;

    cin >> X;

    N = X.size();

    for(i=N-1; i>=0; i--){
        if(X[i]=='T'){
            t_count++;
        }
        else if(X[i]=='S'){
            if(t_count==0) ans++;
            else t_count--;
        }
    }

    cout << ans*2 << endl;

    return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import sys


def solve(N: int, x: "List[int]", y: "List[int]", h: "List[int]"):
    def is_match_to_samples(cx, cy):
        hmax = max(h)
        hmax_idx = h.index(hmax)
        ht = top_height(cx, cy, x[hmax_idx], y[hmax_idx], hmax)
        for xi, yi, hi in zip(x, y, h):
            if hi != height(cx, cy, xi, yi, ht):
                return False, -1
        return True, ht

    import itertools
    for cx, cy in itertools.product(range(101), range(101)):
        is_match, ht = is_match_to_samples(cx, cy)
        if is_match:
            print("{} {} {}".format(cx, cy, ht))
            break
    return

def height(cx, cy, xi, yi, ht):
    return max(0, ht - abs(cx - xi) - abs(cy - yi))

def top_height(cx, cy, xi, yi, hi):
    return hi + abs(cx - xi) + abs(cy - yi)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    h = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        h[i] = int(next(tokens))
    solve(N, x, y, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include "iostream"
#include "algorithm"
using namespace std;
void bubbleSort(int A[], int N);
void trace(int A[], int N);
int MAX = 100;

int main(int argc, char const *argv[]) {
    int A[100];
    int N;

    cin >> N;
    for(int i = 0; i < N; ++i) cin >> A[i];
    bubbleSort(A, N);
    return 0;
}

void bubbleSort(int A[], int N){
    int flag = 1;
    int i = 0;
    int count = 0;
    while(flag) {
        flag = 0;
        for (int j = N-1; j > i; j--) {
            if(A[j] < A[j-1]){
                swap(A[j], A[j-1]);
                count++;
                flag = 1;
            }
        }
        i++;
    }
    trace(A, N);
    cout << count << endl;
}

void trace(int A[], int N){
    for (int i = 0; i < N; i++){
        if(i > 0){
            cout << ' ';
        }
        cout << A[i];
    }
    cout << endl;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;
struct skew_heap {
  struct node {
    node *ch[2];
    int key;
  } *root;
	int size;
	
  skew_heap() : root(0), size(0) { }
  node *merge(node *a, node *b) {
    if (!a || !b) return a ? a : b;
    if (a->key > b->key) swap(a, b); // min heap
    a->ch[1] = merge(b, a->ch[1]);
    swap(a->ch[0], a->ch[1]);
    return a;
  }
  void push(int key) {
    node *n = new node();
    n->ch[0] = n->ch[1] = 0;
    n->key = key;
    root = merge(root, n);
  	size++;
  }
  void pop() {
    node *temp = root;
    root = merge(root->ch[0], root->ch[1]);
  	size--;
  }
  int top() {
    return root->key;
  }
  bool empty() { 
    return !root;
  }
  void merge(skew_heap x) { // destroy x
    root = merge(root, x.root);
  	size += x.size;
  }
};
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	deque<int> q;
	vector<skew_heap> v;
	{
		vi in, vs;
		rep(i, n){
			int a; cin >> a;
			vs.pb(a);
		}
		in = vs; sort(all(vs));
		rep(i, n){
			v.push_back(skew_heap());
			v.back().push(lower_bound(all(vs), in[i]) - vs.begin());
			q.push_back(i);
		}
	}
	
	ll ans = 0;
	for(int i = 0; ;){
		int fid = q[0];
		skew_heap &f = v[fid];
		q.pop_front();
		
		if(f.top() != i){
			v[q[0]].merge(f);
			continue;
		}
		
		int s = f.size;
		if(q.size() == 0){
			ans += s * (s - 1ll) / 2;
			break;
		}
		
		f.pop();
		ans += s - 1;
		if(s - 1) q.push_back(fid);
		i++;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 14716
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main() {
	int a, b; CI a>> b;
	if (a + b == 15)CO '+' EN;
	else if (a*b == 15) CO '*' EN;
	else CO 'x' EN;	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,k;
Vi h;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	std::cout<<std::fixed<<std::setprecision(30);
	cin>>n>>k;
	h.resize(n);
	rep(i,n){
		cin>>h[i];
	}
	sort(all(h));
	ll ans = 0;
	rep(i,n-k){
		ans += h[i];
	}
	print(ans);
	return 0;
}


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<pair<string, int>> vec(N);
    REP(i, N) {
        string s;
        int t;
        cin >> s >> t;
        vec[i] = make_pair(s, t);
    }
    string X;
    cin >> X; 

    int index;
    REP(i, N) {
        if (vec[i].first == X) {
            index = i;
            break;
        }
    }
    int ans = 0;
    for (int i = index+1; i < N; i++) {
        ans += vec[i].second;
    }
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pi pair<int,int>
#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b);i++)
#define repv(vec,v) for(v=(vec).begin(); v!=(vec).end();v++)
#define sz(vec) (int)(vec).size()
#define PB push_back
#define F first
#define S second

void solve(){
	
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	map<int,int> m;
	int a;
	rep(i,1,n-1){
		cin >> a;
		m[a]++;
	}
	for(int i=1;i<=n;i++)
		cout << m[i] << "\n";
	
	return 0;
}


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

int main()
{
  int S,W;
  
  cin>>S>>W;
  
  if(S<=W)
  {
    cout<<"unsafe"<<endl;
  }
  else
  {
    cout<<"safe"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>

using namespace std;

int main() {
	int A, B, iti, ju, hyaku, sen, man, kosuu = 0;

	cin >> A >> B;

	for (int i = A; i <= B; i++) {
		iti = i % 10;
		ju = i / 10 % 10;
		hyaku = i / 100 % 10;
		sen = i / 1000 % 10;
		man = i / 10000 % 10;
		if (iti == man && ju == sen) {
			kosuu++;
		}
	}
	cout << kosuu << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    rep(i,s.size()) s[i] = 'x';
    cout << s << endl;
}




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

#define int long long
//#define uint __int128_t

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int a[4];
bool ok[4];

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    //MOD同士の引き算に注意
    rep(i,0,4)cin>>a[i];
    rep(i,0,4)if(a[i]==1)ok[0]=true;
    rep(i,0,4)if(a[i]==7)ok[1]=true;
    rep(i,0,4)if(a[i]==9)ok[2]=true;
    rep(i,0,4)if(a[i]==4)ok[3]=true;
    
    bool used=true;
    rep(i,0,4)if(ok[i]==false)used=false;
    if(used)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll N;
int ans[1005][1005];

int Check(){
  ll sum = 0;
  for (ll i = 0; i <= N; i++){
    sum += i;
    if (N == sum) return i + 1;
  }
  return 0;
}

int main(){
  cin >> N;
  int Size = Check();
  if (Size == 0){
    No(); return 0;
  }

  Yes(); cout << Size << endl;

  int now = 1;
  for (int i = 0; i < Size-1; i++){
    for (int j = 0; i+j < Size - 1; j++){
      ans[i][j] = now;
      now++;
    }
  }
  
  now = 1;
  for (int j = Size - 2; j >= 0; j--){
    for (int i = Size - 1; i >= 0; i--){
      if (ans[i][j] != 0) continue;
      ans[i][j] = now; now++;
    }
  }

  for (int i = 0; i < Size; i++){
    cout << Size-1;
    for (int j = 0; j < Size - 1; j++){
      cout << " " << ans[i][j];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 5364
import java.util.Scanner;

class Main {
    
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] freq = new int[100001];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            int x = s.nextInt();
            sum += x;
            freq[x]++;
        }
        int q = s.nextInt();
        while (q-- > 0) {
            int b = s.nextInt();
            int c = s.nextInt();
            int count = freq[b];
            sum -= (1L*count*b);
            freq[c] += count;
            freq[b] = 0;
            sum += (1L*count * c);
            System.out.println(sum);
        }
    }
}

Measured memory_bytes: 57676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, D, A;
    cin >> N >> D >> A;
    vc<pair<ll, ll>> M(N);
    rep(i, N) cin >> M[i].first >> M[i].second;
    sort(all(M));
    ll ans = 0;
    ll cnt = 0;
    map<ll, ll> mp;

    rep(i,N){
        ll x, h;
        tie(x, h) = M[i];
        ll d = x + 2 * D;
        auto it = mp.begin();
        while(it!=mp.end()){
            if (it->first >= x){
                break;
            }
            cnt-=it->second;
            mp.erase(it++);
        }
        h -= A * cnt;
        if (h <= 0) continue;
        ll tmp;
        tmp = (h + A - 1) / A;
        mp[d] = tmp;
        cnt += tmp;
        ans += tmp;

        it = mp.begin();
        // cout << it->first<<" "<<x<<" "<<mp.size();
        if (it->first == x){
            cnt -= it->second;
            mp.erase(it);
        }

    }
    cout << ans << endl;
}


Measured memory_bytes: 9600
a = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
b = a.split(', ')
n = int(input())
print(b[n-1])

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

ans = []
tmp_A = A-1
tmp_B = B+1
for i in range(K):
    tmp_A += 1
    if tmp_A <= B and tmp_A not in ans:
        ans.append(tmp_A)
    tmp_B -= 1
    if tmp_B >= A and tmp_B not in ans:
        ans.append(tmp_B)

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

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll a, v; cin>>a>>v;
    ll b, w; cin>>b>>w;
    ll t; cin>>t;

    if (a < b) {
        if (a + t * v >= b + t * w) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    else {
        if (a - t * v <= b - t * w) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
//#define mod 998244353
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modinv(ll a){
	return powm(a,mod-2)%mod;
}

int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    t=1;
    //cin>>t;
    while(t--){
    	int h1,h2,s1,s2;
    	cin>>h1>>s1>>h2>>s2;
    	int x=h2/s1;
    	if(h2%s1!=0)
    	x++;
    	int y=h1/s2;
    	if(h1%s2!=0)
    	y++;
    	if(x>y)
    	cout<<"No";
    	else
    	cout<<"Yes";

    }

}

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

int main(){
  
  int n;
  while(cin >> n, n){
    int id[1001], p[1001], q[1001], r[1001];
    int P, Q, R, C;
    for(int i = 0; i < n; i++) cin >> id[i] >> p[i] >> q[i] >> r[i];
    cin >> P >> Q >> R >> C;
    
    bool judge = true;
    for(int i = 0; i < n; i++){
      if(p[i] <= P && q[i] <= Q && r[i] <= R && p[i]*4 + q[i]*9 + r[i]*4 <= C){
	cout << id[i] << endl;
	judge = false;
      }
    }
    if(judge) cout << "NA" << endl;
  }
  
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 200005;
int main()
{
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    string s;
    cin >> s;
    cout << (s[s.size() - 1] == 's' ? s + "es" : s + "s") << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int m;
vector<int>p;
vector<int>s;
int maxn,minn;


int main(){
  int i,j,now=0,ni=0;
  while(1){
  cin >> m >> minn >> maxn;
  now = 0;
  if(m==0&&maxn==0&&minn==0)break;
  for(i=0;i<m;i++){
    cin >> j;
    p.push_back(j);
  }
  sort(p.begin(),p.end());
  for(i=0;i<m-1;i++)  s.push_back(p[i+1]-p[i]);
  for(i=m-minn-1;i>=m-maxn-1;i--){
    // cout << " bbb"<<s[i];
    if(s[i]>=now){
      now = s[i];
      ni = i;
      //cout <<"aaa"<< now << " "<< ni << endl;
    }
  }
  //cout <<endl<< ni << endl;
  cout << m-1-ni << endl;
  while(p.size())p.pop_back();
  while(s.size())s.pop_back();
  }
  return 0;
}



Measured memory_bytes: 3104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace atcorder_Nikkei_2019
{
    class Program
    {
        struct sumData
        {
            public long sum;
            public long data1;
            public long data2;
        }
        static void Main(string[] args)
        {
            int cnt = int.Parse(Console.ReadLine());

            var dataList = new List<sumData>();

            for (int i = 0; i < cnt; i++)
            {
                long[] line = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
                sumData dataArr = new sumData { sum = line[0] + line[1], data1 = line[0], data2 = line[1] };
                dataList.Add(dataArr);
            }

            dataList.Sort((a, b) => a.sum.CompareTo(b.sum));

            long ret = 0;
            int idx = cnt - 1;
            while (0 <= idx)
            {

                ret += dataList[idx].data1;
                idx--;
                if (idx < 0) break;

                ret -= dataList[idx].data2;
                idx--;
                if (idx < 0) break;

            }

            Console.WriteLine(ret);

        }
    }
}

Measured memory_bytes: 21176
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    string str; cin >> str;

    int n = str.length();

    vector<char> usableChar;
    char allChar[26];
    string finalStr = "";
    rep(i, 26){
        allChar[i] = 97+i;
        finalStr.push_back(allChar[i]);
    }
    reverse(finalStr.begin(), finalStr.end());

    rep(i, 26){
        if(str.find(allChar[i]) == string::npos)
        usableChar.push_back(allChar[i]);
    }

    // rep(i, usableChar.size()){
    //     cout << usableChar[i] << endl;
    // }

    if(n != 26){
        str.push_back(usableChar[0]);
        cout << str << endl;
    }
    else if(str == finalStr){
        cout << -1 << endl;
    }
    else{
        vector<char> candChar;
        int index = 0;

        repr(i, n){
            candChar.push_back(str[i]);

            if(str[i-1] < str[i]){
                index = i;
                break;
            }
        }
        sort(candChar.begin(), candChar.end());

        rep(i, index-1){
            cout << str[i];
        }

        rep(i, candChar.size()){
            if(candChar[i] > str[index-1]){
                cout << candChar[i] << endl;
                break;
            }
        }
    }

    return 0;
}

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

int x,y;

struct grid{
  char c[11][11];
  int count;
  char bf;
  /*void operator=(grid& g2){
    this->count = g2.count;
    this->bf = g2.bf;
    for(int i=0;i<x;i++){
      for(int j=0;j<y;j++){
        this->c[i][j] = g2.c[i][j];
      }
    }
  }*/
};





void DFS(grid& g,char base,char change,int xp,int yp){

  if(xp<0 || yp<0 || xp >= x || yp >= y || g.c[xp][yp] != base){
    return;
  }

  g.c[xp][yp] = change;

  DFS(g,base,change,xp+1,yp);
  DFS(g,base,change,xp,yp+1);
  DFS(g,base,change,xp-1,yp);
  DFS(g,base,change,xp,yp-1);

}



int main(){

  while(1){

    cin >> x >> y;

    if(x==0&&y==0) break;

    grid g;

    for(int i=0;i<y;i++){
      for(int j=0;j<x;j++){
        cin >> g.c[j][i];
      }
    }

    g.count = 0;

    g.bf = g.c[0][0];

    queue<grid> q;

    q.push(g);

    while(!q.empty()){

      g = q.front();

      q.pop();

      bool flag = true;

      for(int i=0;i<y;i++){
        for(int j=0;j<x;j++){
          if(g.c[0][0] != g.c[j][i]){
            flag = false;
          }
        }
      }

      if(flag){
        cout << g.count << endl;
        break;
      }

      g.count++;

      grid tmp = g;

      if(tmp.bf != 'R'){
        DFS(tmp,tmp.c[0][0],'R',0,0);
        tmp.bf = 'R';
        q.push(tmp);
        tmp = g;
      }

      if(tmp.bf != 'G'){
        DFS(tmp,tmp.c[0][0],'G',0,0);
        tmp.bf = 'G';
        q.push(tmp);
        tmp = g;
      }

      if(tmp.bf != 'B'){
        DFS(tmp,tmp.c[0][0],'B',0,0);
        tmp.bf = 'B';
        q.push(tmp);
      }


    }

  }

}

Measured memory_bytes: 36620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const long long INF=1e18,MOD=1e9+7;
#define MAX_V 100010
int main(){
	ll n,m;
	cin>>n>>m;
	ll maxl=-1,minr=INF;
	vector<ll>l(m),r(m);
	for(int i=0;i<m;i++){
		cin>>l[i]>>r[i];
		maxl=max(maxl,l[i]);
		minr=min(minr,r[i]);
	}
	cout<<max((ll)0,min(n,minr)-maxl+1)<<endl;

}

Measured memory_bytes: 1792
import sys

def check(x_list, f, r, v):
    x_list[f][r] += v

def peo(x_list):
    for i in range(3):
        for j in range(10):
            sys.stdout.write(" %d" %(x_list[i][j]))
        print ("")

A_bill = [[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]
B_bill = [[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]
C_bill = [[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]
D_bill = [[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]

n = input()
for i in range(n):
    x = raw_input()
    b, f, r, v = x.split()
    b = int(b)
    f = int(f)
    r = int(r)
    v = int(v)
    
    if b == 1:
        check(A_bill, f-1,r-1,v)
    elif b == 2:
        check(B_bill, f-1,r-1,v)
    elif b == 3:
        check(C_bill, f-1,r-1,v)
    elif b == 4:
        check(D_bill, f-1,r-1,v)

peo(A_bill)
print("####################")
peo(B_bill)
print("####################")
peo(C_bill)
print("####################")
peo(D_bill)

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

int gcd(int a, int b) {
	int p = a, q = b, r = a % b;
	
	while (r > 0) {
		p = q;
		q = r;
		r = p % q;
	}

	return q;
}

int main()
{	
	int n, a, b, c;

	cin >> n;

	if (n == 2) {
		cin >> a >> b;

		int g = gcd(a, b);
		for (int i = 1; i <= g; i++) {
			if (g % i == 0)
				cout << i << endl;
		}
	}
	else if (n == 3) {
		cin >> a >> b >> c;

		int g = gcd(gcd(a, b), c);
		for (int i = 1; i <= g; i++) {
			if (g % i == 0)
				cout << i << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3084