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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - A to Z String
            var s = Console.ReadLine();
            int first = -1;
            int last = -1;

            for(int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'A' && first < 0)
                {
                    first = i;
                }
                else if (s[i] == 'Z' && first >= 0)
                {
                    last = i;
                }
            }

            Console.WriteLine(last - first + 1);
        }
    }
}

Measured memory_bytes: 11616
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
using namespace std;
 
 
 


int main() 
{ 
    int n;
    cin>>n;
    int odd=0;
    if(n%2==0) odd=n/2;
    else odd=n/2+1;
    double ans=(double)odd/(double)n;
    cout<<fixed<<setprecision(8)<<ans;
} 


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <string.h>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define ROF(i,n,m) for(int i=n; i>m; i--)
#define ri(a) scanf("%d",&a)
#define rii(a,b) ri(a),ri(b)
#define riii(a,b,c) rii(a,b),ri(c)
#define lri(a) scanf("%lld",&a)
#define lrii(a,b) lri(a),lri(b)
#define lriii(a,b,c) lrii(a,b),lri(c)
#define pb push_back
#define _1 first
#define _2 second
#define ALL(s) s.begin(),s.end()
#define SZ(x) int((x).size())

const int INF = 0x3f3f3f3f;
const ll INFLL = 1e18;
const int MOD = 1e9+7;
const int alphabet = 26;
const double PI = 3.1415926535;
const int MAXINT = 1e5+1;

int main(){
	int n, act[3][MAXINT];
	int dp[3][MAXINT];

	ri(n);
	FOR(i,0,n) riii(act[0][i], act[1][i], act[2][i]);
	FOR(i,0,3) dp[i][n] = 0;

	memset(dp,0,sizeof(dp));
	ROF(i,n-1,-1){
		FOR(j,0,3){
			FOR(k,0,3) if(k!=j){
				dp[j][i] = max(dp[j][i], dp[k][i+1] + act[k][i]);
			}
		}
	}
	printf("%d\n", max({dp[0][0],dp[1][0],dp[2][0]}) );
	return 0;
}
/*

*/  


Measured memory_bytes: 6140
#include<cstdio>
#include<algorithm>
using namespace std;

#define ll long long 
#define debug if (debug_message)

#define file_io 0
#define debug_message 0

int i,t,j;
int n,nt;

int main(){
	if (file_io){
		freopen(".in","r",stdin);
		freopen(".out","w",stdout);
	}
	
	scanf("%d",&n);
	
	printf("%d\n",n+n*n+n*n*n);
	
	
	return 0;
}
/*

*/

Measured memory_bytes: 1728
#include <stdio.h>
#include <string.h>
#include <math.h>
typedef long long ll;

int SquareNumber(int);

int main()
{
	int A, B, C, X, cnt = 0;
	scanf("%d %d %d %d", &A, &B, &C, &X);
	int answer = X;
	for (int i = 0; i <= A; ++i) {
		for (int j = 0; j <= B; ++j) {
			for (int k = 0; k <= C; ++k) {
				answer = i * 500 + j * 100 + k * 50;
				if(answer == X) cnt++;
			}
		}
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long k,h,a,p,i,n,s=0;
cin>>n;
a=n/2;i=1;
for(i;i<=a;i*=2)  
;
//i*=2;
for(i;i;i/=2)
s+=i;
//if(n==1)
//cout<<1;
//else
cout<<s<<endl;

	return 0;
}

/*
12                         
6 6
3 3 3 3
1 1 1 1 1 1 1 1 */

Measured memory_bytes: 256
const main = stdin => {
  const input = stdin.trim().split('\n')
  const [A, B, K] = input[0].split(' ').map(x => parseInt(x))

  for (let i = A; i <= B; i++) {
    if (i < A + K || i > B - K) {
      console.log(i);
    }
  }
}


// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 32776
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> A(M),B(M);
    vector<vector<int>> G(N);
    int a,b;
    rep(i,M){
        cin>>a>>b;
        G.at(a-1).push_back(b-1);
        G.at(b-1).push_back(a-1);
    }
    vector<int> load(N,-1);//頂点を-1で初期化
    queue<int> que;
    //初期条件（0を初期ノードとする）
    load[0]=0; 
    que.push(0);//0を橙にする
    //BFS開始（キューが空になるまで探索）
    int v=0;
    while(!que.empty()){
         v = que.front();//キューから一個取り出す
        que.pop();
     
        //vからたどれるちょうてんをすべて調べる
        for(int nv:G[v]){
            if(load[nv] != -1)continue;//すでに探索済みなら飛ばす
            load[nv]=v;//道しるべの部屋番号を入れる
            que.push(nv);
        }
    }
    cout << "Yes" << endl;
    for(int v=1;v<N;v++){
        cout << load[v]+1 << endl;
    }
       
  
    return 0;
}

Measured memory_bytes: 11572
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
typedef unsigned long long ll;

// 最大公約数求める関数
auto my_gcd(auto n , auto m){
  if(n < m){
    auto tmp = n;
    n = m;
    m = tmp;
  }
  auto l  = n % m;
  while(l != 0){
    n = m;
    m = l;
    l = n % m;
}
return m;
}

//char⇒int関数
 int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}



int main(){
int N,Y; cin >> N >> Y;
int x = -1,y = -1,z = -1;
for(int i = N; i >= 0;i--){
	for(int j = 0; j <= N - i; j++){
		if(10000 * i + 5000 * j + 1000 * (N - i - j) == Y){
			x = i; y = j; z = N - i - j;
		}
	}
}
	cout <<x << " " << y << " " << z << endl;
  }


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

typedef long long ll;
ll n;
ll x[20],y[20],p[20];
ll ret[20];
ll D[20];

int a[20];
int cnt;
void solve(int k){
	if(k==0){
		for(int i=0;i<n;i++)D[i]=min(abs(x[i]),abs(y[i]));
	}
	if(k==n-2){
		for(int i=0;i<n;i++){
			if(i<k&&a[i]!=0){
				D[i]=0;
			}
			else {
				D[i]=min(abs(x[i]),abs(y[i]));
				for(int j=0;j<k;j++){
					if(a[j]==1)D[i]=min(D[i],abs(x[i]-x[j]));
					if(a[j]==2)D[i]=min(D[i],abs(y[i]-y[j]));
				}
			}
		}
	}
	if(k==n){
		ll sum=0;
		for(int i=0;i<n;i++){
			if(a[i]!=0)continue;
			ll d=D[i];
			for(int j=max((int)n-2,0);j<n;j++){
				if(a[j]==1)d=min(d,abs(x[i]-x[j]));
				if(a[j]==2)d=min(d,abs(y[i]-y[j]));
			}
			sum+=d*p[i];
		}
		ret[cnt]=min(ret[cnt],sum);
		return;
	}
	for(int j=0;j<3;j++){
		a[k]=j;
		if(j>0)cnt++;
		solve(k+1);
		if(j>0)cnt--;
	}
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i]>>p[i];
	}
	for(int k=0;k<=n;k++){
		ret[k]=1000000000000000000;
	}
	solve(0);
	for(int k=0;k<=n;k++){
		cout<<ret[k]<<endl;
	}
}

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

int main()
{
    int n;
    cin >> n;

    int d1, d2;
    int check = 0;
    bool flag = false;
    rep(i, n){
        cin >> d1 >> d2;
        if(d1 == d2) check++;
        else check = 0;
        if(check==3) flag = true;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return  0;
}

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

int main(){
  string S;
  cin >> S;
  int ans=0;
  int cnt=0;
  for(int i=0; i<S.size(); i++){
    if(S.at(i)=='A' || S.at(i)=='T' || S.at(i)=='C' || S.at(i)=='G'){
      cnt++;
      ans=max(ans, cnt);
    }
    else{
      cnt=0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		StringBuilder sb = new StringBuilder(in.next());
		int ans = 0;
		for (int i = 0; i < sb.length() - 1; i++) {
			if (sb.charAt(i) == sb.charAt(i + 1)) {
				sb.replace(i + 1, i + 2, sb.charAt(i) == '0' ? "1" : "0");
				ans++;
			}
		}
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 26728
import sys

#sys.stdin = open('input1.txt', 'r')

H, W , N = map(int, raw_input().split())
squares = {}
results = [0 for _ in range(10)]
for _ in range(N):
	h, w = map(int, raw_input().split())
	for x in [(0, 0), (0, -1), (0, -2), (-1, 0), (-1, -1), (-1, -2), (-2, 0), (-2, -1), (-2, -2)]:
		nh, nw = h + x[0], w + x[1]
		if ((nh < 1) or (nw < 1) or (nh + 2 > H) or (nw + 2 > W)):
			pass
		else:
			if (nh, nw) in squares:
				squares[(nh, nw)] += 1
			else:
				squares[(nh, nw)] = 1

for v in squares.values():
	results[v] += 1

results[0] = (H - 2) * (W - 2) - sum(results[1:])

for x in range(10):
	print str(results[x])


Measured memory_bytes: 168604
#include<stdio.h>
int main(){
int a,b;
scanf("%d %d",&a,&b);
if(a<b){
printf("a < b\n");
}
else if(a>b){
printf("a > b\n");
}
else if(a==b){
printf("a == b\n");
}
return 0;
}


Measured memory_bytes: 2580
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

l = 0
now = 0
ans = 0
for i in range(N):
    var = As[i]
    if now+var==now^var:
        ans += (i-l+1)
        now += var
    else:
        while l<=i:
            lvar = As[l]
            l += 1
            now -= lvar
            if now+var==now^var:
                now += var
                ans += (i-l+1)
                break
print(ans)

Measured memory_bytes: 24840
N = int(input())
lis = [list(map(int, input().split())) for i in range(N)]
# 二点間の距離の計算
import math
def dist(x1,y1,x2,y2):
  x = (x1-x2)**2 + (y1-y2)**2
  return math.sqrt(x)

# 並び順のパターン
import itertools
rt_list = list(itertools.permutations(range(N)))

d = 0
for rts in rt_list:
  tmp_d = 0 #このルートでの総距離
  for rt in range(len(rts) - 1):
    tmp_d += dist(lis[rts[rt]][0],lis[rts[rt]][1], lis[rts[rt+1]][0],lis[rts[rt+1]][1])
  d += tmp_d
print(d/len(rt_list))

Measured memory_bytes: 8052
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int maxn=100000+10,mo=1000000007;
int fac[maxn*2],inv[maxn*2];
int i,j,k,l,t,n,m,a,b,ans;
int qsm(int x,int y){
	if (!y) return 1;
	int t=qsm(x,y/2);
	t=(ll)t*t%mo;
	if (y%2) t=(ll)t*x%mo;
	return t;
}
int C(int n,int m){
	if (n<m||m<0) return 0;
	return (ll)fac[n]*inv[m]%mo*inv[n-m]%mo;
}
int F(int n,int m){
	return C(n+m,n);
}
int main(){
	scanf("%d%d%d%d",&n,&m,&a,&b);
	fac[0]=1;
	fo(i,1,n+m) fac[i]=(ll)fac[i-1]*i%mo;
	inv[n+m]=qsm(fac[n+m],mo-2);
	fd(i,n+m-1,0) inv[i]=(ll)inv[i+1]*(i+1)%mo;
	fo(i,1,b)
		(ans+=(ll)F(n-a-1,i-1)*F(a-1,m-i)%mo)%=mo;
	ans=(F(n-1,m-1)-ans)%mo;
	(ans+=mo)%=mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

bool solve() {
  ll A, B; cin >> A >> B;
  string S; cin >> S;
  if ((ll)S.size() != A + B + 1) return false;
  for (ll i = 0; i < A+B+1; i++) {
    if (i == A) {
      if (S.at(i) != '-') return false;
    }else {
      if (! ('0' <= S.at(i) && S.at(i) <= '9')) return false;
    }
  }
  return true;
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);
  cout << (solve() ? "Yes\n" : "No\n");

  return 0;
}



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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



int main(){
    int n;
    cin >> n;
    int x = n/15;
    cout << n*800-x*200 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int a, b, c, x, ans;

int main()
{
    cin >> a >> b >> c >> x;
    for (int i = 0; i <= a; i++)
    {
        for (int j = 0; j <= b; j++)
        {
            for (int k = 0; k <= c; k++)
            {
                if (500 * i + 100 * j + 50 * k == x)
                    ans++;
            }
        }
    }
    cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n, m, q;
  cin >> n >> m >> q;
  vector<vi32> v(n);
  rep(i, m) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    v[l].emplace_back(r);
  }
  rep(i, n) {
    sort(all(v[i]));
  }
  rep(i, q) {
    int p, q;
    cin >> p >> q;
    p--, q--;
    int ans = 0;
    repic(l, p, q) {
      int x = upper_bound(all(v[l]), q) - v[l].begin();
      ans += x;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 2176
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main(){
    int A, B;
    cin >> A >> B;
    if(abs(A-B) % 2 == 0) cout << (A + B) / 2 << endl;
    else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include<cmath>
#define _GLIBCXX_DEBUG
using namespace std;

int main()
{
    long long X;
    cin>>X;
    int count=0;
    long long y=100;
    while(y<X){
        y*=1.01;
        count++;
    }
    
    cout<<count;
}

Measured memory_bytes: 3624
package main

import (
	"fmt"
)

func main() {
	var n int

	fmt.Scan(&n)

	weights := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&weights[i])
	}

	min := 99999

	for i := 0; i < n; i++ {
		abs := test(n, weights, i)
		if abs < min {
			min = abs
		}
	}

	fmt.Println(min)

}

func test(n int, weights []int, t int) int {
	s1 := 0
	s2 := 0

	for i := 0; i < n; i++ {
		if i <= t {
			s1 += weights[i]
		} else {
			s2 += weights[i]
		}
	}

	result := s1 - s2

	if result < 0 {
		result *= -1
	}

	return result

}


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

using ll=long long;


int main(){
    int tt=1;
    cin>>tt;
    map<string,int> mp;
    string s;
    while(tt--){
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<"\n";
    cout<<"WA x "<<mp["WA"]<<"\n";
    cout<<"TLE x "<<mp["TLE"]<<"\n";
    cout<<"RE x "<<mp["RE"]<<"\n";
    return 0;
}


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

int main()
{
  long N;
  std::cin >> N;
  
  std::string S, T;
  std::cin >> S >> T;
  
  long n = N;
  for(n=N; n>=0; --n)
  {
    if(S.substr(N-n, n) == T.substr(0, n))
    {
      break;
    }
  }
  
  std::cout << (S + T.substr(n)).size() << std::endl;
  
  return 0;
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    if(N==3||N==5||N==7){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;

lli get_abs(lli x);

int main(){
    lli n;
    cin >> n;
    vector<lli> a_vec;
    lli num_negative = 0, min_abs = 1e+09;
    for(lli i = 0; i != n; ++i){
        lli a;
        cin >> a;
        a_vec.push_back(a);

        if(a < 0){
            num_negative += 1;
        }

        min_abs = min(min_abs, get_abs(a));
    }

    lli ans = 0;
    bool found_min_abs = false;
    for(lli i = 0; i != n; ++i){
        if(num_negative % 2 == 0){
            ans += (a_vec[i] > 0)? a_vec[i] : -a_vec[i];
        }else{
            if(get_abs(a_vec[i]) == min_abs && !found_min_abs){
                ans += (a_vec[i] < 0)? a_vec[i] : -a_vec[i];
                found_min_abs = true;
            }else{
                ans += (a_vec[i] > 0)? a_vec[i] : -a_vec[i];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

lli get_abs(lli x){
    return (x > 0)? x : -x;
}

Measured memory_bytes: 1400
#include<iostream>
using namespace std;
int main()
{
    long long int x;
    cin>>x;
    int y=x%10;
    if(y==2 or y==4 or y==5 or y==7 or y==9) cout<<"hon";
    else if(y==0 or y==1 or y==6 or y==8) cout<<"pon";
    else cout<<"bon";
}


Measured memory_bytes: 3632
#include<stdio.h>

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

    if(a < b)
	printf("a < b\n");
    if(a == b)
	printf("a == b\n");
    if(a > b)
	printf("a > b\n");

    return 0;
}


Measured memory_bytes: 2132
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
using ll =double;
map <int ,int> mpa,mpb;

int main (void){
  int N;
  cin >> N;
  int ans=0;
  int ma=0;
  int mi=1000000;
  int o,p;
  int A[N]={0},B[N]={0};
  for(int i=1;i<=N;i++){
    cin >> A[i] >> B[i];
    if(A[i]>ma){
      ma=A[i];
      p=i;
    }
  }
  ans=ma+B[p];
  cout << ans;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
//#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){
    long long X,K,D;
    cin>>X>>K>>D;
    if (X<0) X=-X;
    long long n;
    n=X/D;
    if (n>=K){
        cout<<X-K*D<<endl;
        return 0;
    }
    K=K-n;
    X=X%D;
    if (D-X>X){
        K--;
        X=D-X;
    }
    if (K%2==0) cout<<X<<endl;
    else cout<<D-X<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<cmath>
using namespace std;
int ans=0;
int main()
{
	int n,m;scanf("%d%d",&n,&m);
	for(int i=sqrt(m);i>=1;--i) if(!(m%i)) {if(ans<i&&(m/i)>=n) ans=i;if(ans<m/i&&i>=n) ans=m/i;}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

G = [[] for _ in range(105)]
begin = [-1] * 105
end = [-1] * 105

t = 1
def dfs(v):
    global t
    begin[v] = t
    t += 1
    for e in G[v]:
        if begin[e] < 0:
            dfs(e)
    end[v] = t
    t += 1

def main():
    N = int(input())
    for i in range(N):
        A = list(map(int,input().split()))
        for a in A[2:]:
            G[i].append(a - 1)
    
    for i in range(N):
        if begin[i] < 0:
            dfs(i)
    for i in range(N):
        print(i + 1,begin[i],end[i])
if __name__ == '__main__':
    main()


Measured memory_bytes: 5664
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

struct FastIO
{
  FastIO() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(0); 
  }
} fastio;


signed main() {
	int n,m;
	std::cin >> n >> m;
	std::vector<std::pair<int,int> > bombs;
	bombs.reserve(n);
	rep(i,n) {
		int a,b;
		std::cin >> a >> b;
		bombs.emplace_back(a,b);
	}
	std::vector<std::pair<int,int> > codes;
	codes.reserve(m);
	rep(i,m) {
		int a,b;
		std::cin >> a >> b;
		codes.emplace_back(a,b);
	}
	std::sort(all(bombs));
	std::vector<int> xors(n+1);
	xors[0] = bombs[0].second; xors[n] = bombs[n-1].second;
	rep(i,n-1) {
		xors[i+1] = bombs[i].second^bombs[i+1].second;
	}
	std::map<std::pair<int,int>, int> map;
	std::vector<std::vector<int> > g(n+1,std::vector<int>());
	std::vector<int> bombsx(n);
	rep(i,n) {
		bombsx[i] = bombs[i].first;
	}
	rep(i,m) {
		int a = std::lower_bound(all(bombsx),codes[i].first)-bombsx.begin();
		int b = std::upper_bound(all(bombsx),codes[i].second)-bombsx.begin();
		map[std::make_pair(a,b)] = i;
		map[std::make_pair(b,a)] = i;
		if(a==b) continue;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	std::set<int> set;
	std::vector<int> went(n+1,false);
	auto dfs = [&] (auto f, int i, int par) -> int {
		int impossible = false;
		went[i]=true;
		for(int to: g[i]) {
			if(went[to]) continue;
			if(f(f,to,i)) impossible = true;
		}
		if(xors[i]) {
			if(par==-1) return 1;
			xors[par]^=1;
			set.emplace(map[std::make_pair(i,par)]);
		}
		return impossible;
	};
	rep(i,n+1) {
		if(went[i]) continue;
		if(dfs(dfs,i,-1)) {
			print(-1);
			return 0;
		}
	}
	print(set.size());
	for(auto x:set) {
		std::cout << x+1 << ' ';
	}
	std::cout << ENDL;
	return 0;
}


Measured memory_bytes: 49280
#include <bits/stdc++.h>
#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,b,a) for(int i=(b);i>=(a);i--)
#define len(a) int((a).size())
using namespace std;
using LL = long long;
using PII = pair<int, int>;


vector<int> sievePrime(int n) {
    vector<int> pl;
    vector<int> lo(n);
    vector<int> P(1e5 + 5);
    lo[1] = 1;
    for (int x = 2; x < n; x++) {
        if (!lo[x]) {
            pl.push_back(lo[x] = x);
            P[x] = 1;
        }
        for (auto p : pl) {
            if (x * p >= n)
                break;
            lo[x * p] = p;
            if (x % p == 0)
                break;
        }
    }
    return P;
}

vector<int> P;
vector<int> A;

int main() {
    int q;
    cin>>q;
    P = sievePrime(1e5 + 5);
    for (int i=3;i<=100000;i+=2) {
        if (P[i] && P[i+1>>1]) {
            A.push_back(i);
        }
    }
    while (q--) {
        int l, r;
        scanf("%d%d", &l, &r);
        int x = lower_bound(A.begin(), A.end(), l) - A.begin();
        int y = upper_bound(A.begin(), A.end(), r) - A.begin();
        printf("%d\n", y - x);
    }
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>

int main(int argc, char const *argv[]) {
  char w[101]={'\0'};
  int  count[24]={0};
  int i;

  scanf("%s", w);

  for(i=0;i < strlen(w);i++){
     count[ (int)(w[i]) - 97]++;
  }

  for(i=0;i<24;i++){
    if((count[i] % 2) != 0) {
      puts("No");
      return 0;
    }
  }

  puts("Yes");
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <stdio.h>

#define MAX_A 100'001

using namespace std;

int A[MAX_A]{};

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    ++A[a];
    if (a - 1 >= 0) {
      ++A[a - 1];
    }
    if (a + 1 < MAX_A) {
      ++A[a + 1];
    }
  }
  int res = 0;
  for (int i = 0; i < MAX_A; ++i) {
    res = max(res, A[i]);
  }
  printf("%d\n", res);
}

Measured memory_bytes: 3444
# -*- coding: utf-8 -*-
import math

class KochCurve(object):
	# public変数
	x = 0.0
	y = 0.0

	# private変数
	#__xy = 0.0

	# 解法
	def koch(self, n, a, b):
		if n == 0:
			return 

		s = KochCurve()
		t = KochCurve()
		u = KochCurve()
		th = math.pi * 60.0 / 180.0

		s.x = (2.0 * a.x + 1.0 * b.x) / 3.0
		s.y = (2.0 * a.y + 1.0 * b.y) / 3.0
		t.x = (1.0 * a.x + 2.0 * b.x) / 3.0
		t.y = (1.0 * a.y + 2.0 * b.y) / 3.0
		u.x = (t.x - s.x) * math.cos(th) - (t.y - s.y) * math.sin(th) + s.x
		u.y = (t.x - s.x) * math.sin(th) + (t.y - s.y) * math.cos(th) + s.y
		
		KochCurve().koch(n - 1, a, s)
		msg = "%.8f %.8f" % (s.x, s.y)
		print(msg)
		KochCurve().koch(n - 1, s, u)
		msg = "%.8f %.8f" % (u.x, u.y)
		print(msg)
		KochCurve().koch(n - 1, u, t)
		msg = "%.8f %.8f" % (t.x, t.y)
		print(msg)
		KochCurve().koch(n - 1, t, b)


if __name__ == '__main__':
	a = KochCurve()
	b = KochCurve()

	n = int(input())

	a.x = 0
	a.y = 0
	b.x = 100
	b.y = 0

	msg = "%.8f %.8f" % (a.x, a.y)
	print(msg)
	KochCurve().koch(n, a, b)
	msg = "%.8f %.8f" % (b.x, b.y)
	print(msg)


Measured memory_bytes: 5768
#include <stdio.h>

int main(void)
{
	int count;
	int a, b, c, d;
	int n;
	
	while (scanf("%d", &n) != EOF){
		count = 0;
		for (d = 0; d <= 9; d++){
			for (c = 0; c <= 9; c++){
				for (b = 0; b <= 9; b++){
					for (a = 0; a <= 9; a++){
						if (a + b + c + d == n){
							count++;
						}
					}
				}
			}
		}
		
		printf("%d\n", count);
	}
	
	return (0);
}

Measured memory_bytes: 596
#include <iostream> 
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <cstring>

#define mp make_pair
#define s second
#define f first
#define ll long long
using namespace std;
const ll mod = 10e8 + 7;
char mat[1003][1003];
ll dp[1003][1003];

int main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
	
	int n, m;
	cin >> n >> m;
	
	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			cin >> mat[i][j];
		}
	}
	
	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			if (mat[i][j] == '#') continue;
			
			if (i == 0 and j == 0) dp[i][j] = 1;
			else if (i == 0) dp[i][j] = dp[i][j-1];
			else if (j == 0) dp[i][j] = dp[i-1][j];
			else (dp[i][j] = dp[i-1][j] + dp[i][j-1]) %= mod;
		}
	}
	
	cout << dp[n-1][m-1];	
return 0;	
}




Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;
const int mod = 1000000007;

int main() {

  int N,M,ans=0;
  cin>>N>>M;
    unordered_map<int,int> map;
  vector<pair<int,int>> A(M);
  if(N==1&&M==0){cout<<0<<endl; goto end2;} 
  if(N==1){
    for(int i=0; i<M; i++){
    cin>>A[i].first>>A[i].second;
      if(!map.count(A[i].first))map[A[i].first]=A[i].second;
    else if(map[A[i].first]!=A[i].second){cout<<-1<<endl; goto end1;}
    if(A[i].second==0&&i==M-1){cout<<0<<endl;break;}
      if(i==M-1)cout<<A[i].second<<endl;
  }}
  else{
  for(int i=0; i<M; i++){
    cin>>A[i].first>>A[i].second;
  if(!map.count(A[i].first))map[A[i].first]=A[i].second;
    else if(map[A[i].first]!=A[i].second){cout<<-1<<endl; goto end1;}
    else {A[i].second=0;A[i].first=2;}
  //  else {cout<<-1<<endl; goto end;}
    if(A[i].first==1&&A[i].second==0){cout<<-1<<endl; goto end;}
    
  }
  if(!map.count(1))ans+=pow(10,N-1);
  for(int i=0; i<M; i++){
    ans+=pow(10,N-A[i].first)*A[i].second;}
  //vector<vector<int>> A(N,vector<int>(M));
  //for(int i=0; i<N; i++){for(int j=0; j<M; j++){cin>>A[i][j];}}
  //sort(A.begin(),A.end());
  //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
  //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
  cout << ans << endl;
  }
  end1: N=N;  end2: N=N;

  end : N=N;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;
 
int inf = 1e18;
const int N = 1e5+5;
 
int mod = 1e9+7;
/*
    int ncr(int n , int r ){
    	r = min(r,n-r);
    	int res = 1 ;
    	for(int i = 1 ; i <= r ; i++ ){
    		( res *= n-i+1 )%= mod;
    		res /= i ;
    	}
    	return res ;
    }
*/
//int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
//int arr[N];
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
      string s,t;
      cin>>s>>t;
      cout<<t+s;
 
     }
    return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


class RollingHash(object):
    def __init__(self, source: str, base=1000000007, mod=9007199254740997):
        self.source = source
        self.base = base
        self.mod = mod
        self.hash_from_zero_to = self._get_hash_from_zero_to()
        self.base_pow = self._get_base_pow()

    # 文字列sourceの区間 [0, right) のハッシュ値を前計算する
    def _get_hash_from_zero_to(self):
        hash_from_zero_to = [0]
        for si in self.source:
            hash_from_zero_to.append((hash_from_zero_to[-1] * self.base + ord(si)) % self.mod)

        return hash_from_zero_to

    # base値をi回掛けてmodをとった値を前計算する
    def _get_base_pow(self):
        base_pow = [1]
        for i in range(len(self.source)):
            base_pow.append(base_pow[-1] * self.base % self.mod)

        return base_pow

    # 文字列sourceの区間 [left, right) のハッシュを取得する
    def get_hash(self, left: int, right: int):
        return (self.hash_from_zero_to[right]
                - self.hash_from_zero_to[left] * self.base_pow[right - left]) % self.mod


# 題意を満たす文字列の最大長を二分探索する
def binsearch(func, rh: RollingHash, ok: int, ng: int):
    source_length = len(rh.source)
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if func(rh, mid, source_length):
            ok = mid
        else:
            ng = mid

    return ok


# 題意を満たす長さtarget_lengthの文字列があるか判定する
def judge(rh: RollingHash, target_length: int, source_length: int):
    memo = {}
    for start_idx in range(source_length - target_length + 1):
        cur_hash = rh.get_hash(start_idx, start_idx + target_length)
        if cur_hash in memo:
            if start_idx - memo[cur_hash] >= target_length:
                return True
        else:
            memo[cur_hash] = start_idx

    return False


n = ni()
s = ns()

rh = RollingHash(s)
print(binsearch(judge, rh, 0, n//2 + 2))

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int& i : a) cin >> i;
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int b, e;
		cin >> b >> e;
		reverse(a.begin() + b, a.begin() + e);
	}
	cout << a[0];
	for (int i = 1; i < n; ++i) cout << ' ' << a[i];
	cout << endl;
}


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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 100100;

int n, m;
vector<int> adj[maxn + 5];

int col[maxn + 5];

int cnt = 0;
int cntx = 0, cnty = 0;

bool dfs(int x, int c)
{
	if (~col[x])
	{
		return col[x] == c;
	}
	col[x] = c;
	++cnt;
	if (col[x] == 0) ++cntx;
	else ++cnty;
	bool ret = 1;
	for (auto y : adj[x])
		ret &= dfs(y, !c);
	return ret;
}

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d%d", &n, &m);
	REP(i, 0, m)
	{
		int u, v;
		scanf("%d%d", &u, &v), --u, --v;
		adj[u].pb(v), adj[v].pb(u);
	}
	memset(col, -1, sizeof col);
	LL ans = -m;
	REP(i, 0, n) if (!~col[i])
	{
		cnt = cntx = cnty = 0;
		if (!dfs(i, 0))
		{
			ans += (LL)cnt * (cnt - 1) >> 1;
		}
		else ans += (LL)cntx * cnty;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
#define f first
#define s second
#define MOD 1000000007
#define fast ios::sync_with_stdio(0),cout.tie(0),cin.tie(0)
#define pb push_back
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define mkt make_tuple
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"wait\n"
#define INF (ll)1e18+5
typedef long long ll;
typedef unsigned long long ull;


class solution{
public:
	void solve(){
		ll n,w;
		cin>>n>>w;
		vector<pair<ll,ll>> v(n);
		for(int i=0;i<n;i++){
			cin>>v[i].f>>v[i].s;
		}
		vector<ll> dp((int)(1e5+1),INF);
		vector<ll> newdp((int)(1e5+1),INF);
		ll poss = (int)(1e5+1);
		//deb(poss);
		dp[0] = 0;
		newdp[0] = 0;
		for(int i=0;i<n;i++){
			for(int value = 0;value<poss;value++){
				if(value+v[i].s<poss){
					ll a = dp[value]+v[i].f;
					ll val = dp[value+v[i].s];
					newdp[value+v[i].s] = min(val,a);
				}
				
			}
			dp = newdp;
		}
		ll ma = 0;
		for(int i=0;i<poss;i++){
			//deb(dp[i]);
			if(dp[i] <= w){
				ma = i;
			}
		}
		cout<<ma;
				
	}
};

int main()
{
    fast;
	ll i=0;
	solution s;
	s.solve();

 return 0;
}



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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,start,end) for(int i=(start);i<=(end);i++)
#define all(n) begin(n),end(n)

#define DEBUG

int main()
{
	int x;
	cin >> x;
	if(x == 3 || x == 5 || x == 7) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set> 
#include<cmath>
using namespace std;
long long p = 998244353;
//long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)
#define upper(h,val) upper_bound(h.begin(),h.end(),val)
#define mint modint<998244353>
#define end_s(a) cout <<a<<endl;return 0
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) { pa[x] = y; }
}
V<string> solve2(int a, int b) {
	if (a < 0 || b < 0) { return {}; }
	if (a == 0 && b == 0) {
		V<string> ans(1, "");
		return ans;
	}
	V<string> ans = solve2(a - 1, b);
	V<string> nans;
	for (auto x : ans) { nans.push_back(x+"A"); }
	V<string> ans2 = solve2(a, b - 1);
	for (auto x : ans2) { nans.push_back(x+"B"); }
	return nans;
}
signed main() {
	while (true) {
		int d, n; cin >> d >> n;
		if (d == 0) { break; }
		int inf = 100;
		vvel dp(d + 1, vel(101, 10000));
		vel a(n), e(n), r(n);
		rep(i, n) {
			cin >> a[i] >> e[i] >> r[i];
		}
		dp[0][0] = 0;
		rep(i, d + 1) {
			rep(j, 101) {
				rep(k, n) {
					if (r[k] <= j) {
						mmin(dp[min(i + a[k], d)][min(j + e[k], inf)], dp[i][j] + 1);
					}
				}
			}
		}
		int ans = 10000;
		rep(i, 101) { mmin(ans, dp[d][i]); }
		if (ans == 10000) { cout << "NA" << endl; }
		else { cout << ans << endl; }
	}
	return 0;
}


Measured memory_bytes: 3204
import math as m
a, b, h, min = map(int, input().split())

minutes = 60*h+min

degree_long = minutes*.5
degree_short = minutes*6 % 360


class P:
    def __init__(self, x, y):
        self.x, self.y = x, y

    def __sub__(self, q):
        return P(self.x-q.x, self.y-q.y)

    def length(self):
        return m.sqrt(self.x**2+self.y**2)


v1 = P(a*m.cos(m.radians(degree_long)), a*m.sin(m.radians(degree_long)))
v2 = P(b*m.cos(m.radians(degree_short)), b*m.sin(m.radians(degree_short)))

v3 = v1-v2
print(v3.length())


Measured memory_bytes: 9528
#include <bits/stdc++.h>
#define ll long long
#define p pair<int, int>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<p> a;
    for (int i = 0; i < n; i++) {
        int u;
        cin >> u;
        a.push_back(p(u, i + 1));
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        cout << a[i].second << " \n"[i == n - 1];
    }
    return 0;
}

Measured memory_bytes: 1780
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
 
using namespace std;
 
int h,w,sx,sy,gx,gy,tx,ty;
char house[505][505];   
bool isvisited[505][505]={false};
 
void search(int x,int y){
    if(isvisited[x][y]){
        return;
    }
    isvisited[x][y]=true;
 
    if(x<=0 || x>h || y<=0 || y>w){
        return;
    }
 
    if(house[x][y]=='#'){
        return;
    }
 
    search(x-1,y-1);
    search(x-1,y);
    search(x-1,y+1);
    search(x,y-1);
    search(x,y);
    search(x,y+1);
    search(x+1,y-1);
    search(x+1,y);
    search(x+1,y+1);
}
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    lol h,n,a,sum;
    cin>>h>>n;
    rep(i,n){
      cin>>a;
      sum+=a;
    }
    if(sum>=h){
      cout<<"Yes"<<'\n';
    }
    else{
      cout<<"No"<<'\n';
    }
    return 0;
}


Measured memory_bytes: 256
N,M,K = gets.split.map(&:to_i)

友達の輪と大きさ = [-1]*(N+1)
輪 = lambda{|a|
	next 友達の輪と大きさ[a]<0 ? a : 友達の輪と大きさ[a]=輪[友達の輪と大きさ[a]]
}
輪の大きさ = lambda{|a|
	next -友達の輪と大きさ[輪[a]]
}
友達です = lambda{|*ab|
	a,b = ab.map(&輪)
	next if a==b
	a,b = b,a if 友達の輪と大きさ[b]<友達の輪と大きさ[a]
	友達の輪と大きさ[a] += 友達の輪と大きさ[b]
	友達の輪と大きさ[b] = a
}

友達の数 = [0]*(N+1)

M.times{
	a,b = gets.split.map(&:to_i)
	友達です[a,b]
	友達の数[a] += 1
	友達の数[b] += 1
}

友達の輪の中の目障りなあいつ = [0]*(N+1)

K.times{
	a,b = gets.split.map(&:to_i)
	next if 輪[a]!=輪[b]
	友達の輪の中の目障りなあいつ[a] += 1
	友達の輪の中の目障りなあいつ[b] += 1
}

puts 1.upto(N).map{|n|
	輪の大きさ[n] - 1 - 友達の数[n] - 友達の輪の中の目障りなあいつ[n]
}


Measured memory_bytes: 17656
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n;
  ll a,b; cin>>n>>a>>b;
  if((b-a)%2 == 0) cout<< (b-a) / 2;
  else {
		cout<<min(a-1,n-b) + 1 + (b-a-1)/2;
  }
}

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

int main(){
	int n,k; cin >> n >> k;
	int cnt = 0;
	for(int i = 0;i < n;i++){
		int a;
		scanf("%d",&a);
		if(a >= k) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())
#define pb push_back
#define mp make_pair
#define MODP(A,B) A=(A+B)%mod
typedef pair<ll,ll> P;
typedef pair<double,double> Pd;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};


int main(){
    ll X,Y,Z; cin>>X>>Y>>Z;
    cout<<Z<<' '<<X<<' '<<Y<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a,b;
    cin >> a >> b;
    
    int m,n;
    m=a.size();
    n=b.size();
    
    
    int k=10000;
    for(int i=0;i<m-n+1;i++){
        int count = 0;
        for(int j=0;j<n;j++){
            if(a[i+j]!=b[j]){
                count++;
            }
        }
        k=min(k,count);
    }
    cout << k << endl;
}


Measured memory_bytes: 3624
NK = input()
NK = NK.split(" ")
N = int(NK[0])
K = int(NK[1])


h = []
for i in range(N):
  h.append(int(input()))
  
  
h.sort()
ans = h[-1] - h[0]

for i in range(N-K+1):
  ans = min(ans, h[i+K-1] - h[i])
print(ans)

Measured memory_bytes: 7488
//defalt
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
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; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;
int ans=0;

signed main(){
  string S;
  cin >> S;
  rep(i,S.size()/2){
    if(S[i]!=S[S.size()-1-i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
main()
{
	int a,b,c,d,s;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(b<=c)
	s=0;
	else
	{
	if(b>d)
	{
	         if(a>d)
	         s=0;
	        else
        	 {
		         if(a<c)
	         	s=d-c;
	             else
	             s=d-a;
	         }
	 }
	else
	{
		if(a>c)
		s=b-a;
		else
        s=b-c;
	}
	}
	printf("%d\n",s);
}

Measured memory_bytes: 128
n = int(input())
p_list = [int(input()) for i in range(n)]
maxval = -20000000000000
minval = p_list[0]
for i in range(n - 1):
  maxval = max(maxval, p_list[i + 1] - minval)
  minval = min(minval, p_list[i + 1])
print(maxval)



Measured memory_bytes: 13592
N = int(input())

def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  return divisors


divisors = make_divisors(N)
ans = 10**12
for i in divisors:
  ans = min(ans, i+N//i)
  
print(ans-2)

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

using namespace std;

int main(){
    int n;
    string s;
    int b = 0;
    int r = 0;
    cin >> n;
    cin >> s;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R') r++;
        else b++;
    }
    if(r > b) cout << "Yes" << "\n";
    else cout << "No" << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<float.h>
int main(void){
  long a,b,d,r;
  double A,B,f;
  scanf("%ld %ld",&a,&b);
  d = a / b;
  r = a % b;
  A = a;
  B = b;
  f = A / B;
  printf("%ld %ld %f\n",d,f,r);
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin>>x;
  for(int i=x;;i++){
    bool ok=true;
    for(int j=2;j*j<=x;j++){
      if(i%j==0)ok=false;
    }
    if(ok){
      cout<<i<<endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

#define BUFSIZE 101

int main(int argc, char const *argv[]) {
    int N, A[BUFSIZE], i;
    double ans= 0.0;
    scanf("%d", &N);
    for(i= 0; i < N; i++) {
        scanf("%d", &A[i]);
        ans+= 1.0 / A[i];
    }
    printf("%lf\n", 1 / ans);

    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int SURP = 1000000007;

int main(){
	int N,X;
	cin >> N >> X;

	int minm = 1000000;
	int ret  = N;
	FOR(i,0,N){
		int m;
		cin >> m;
		X -= m;
		if(minm > m) minm = m;
	}

	ret += (X / minm);
	cout << ret << endl;
	return 0;


}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long[] S = new long[n];
        for (int i = 0; i < n; i++) S[i] = Integer.parseInt(sc.next());

        int cnt = 0;

        int q = Integer.parseInt(sc.next());
        for (int i = 0; i < q; i++) {
            long T = Integer.parseInt(sc.next());
            if (search(S, n, T)) cnt++;
        }
        System.out.println(cnt);
    }

    private static boolean search(long[] A, int n, long key) {
//        return Arrays.binarySearch(A, key) >= 0;
        int l = 0;
        int r = n;
        while (l < r) {
            int m = (l + r) / 2;
            if (A[m] == key) {
                return true;
            } else if (key < A[m]) {
                r = m;
            } else {
                l = m + 1;
            }
        }
        return false;
    }
}



Measured memory_bytes: 71268
n=int(input())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

arr = make_divisors(n)
total=0
for m in arr:
    r = n//m

    if r<m-1:
        total +=m-1


print(total)


Measured memory_bytes: 9340