akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import java.math.*;
class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try {
	    String[] st;
	    while(true){
		int n = Integer.valueOf(sc.readLine());
		if(n==0)
		    break;
		int max=0, min=0, now=0;
		st = sc.readLine().split(" ");
		for(int j=0; j<5; j++)
		    now+=Integer.valueOf(st[j]);
		max = now; min = now;
		for(int i=1; i<n; i++){
		    now = 0;
		    st = sc.readLine().split(" ");
		    for(int j=0; j<5; j++)
			now+=Integer.valueOf(st[j]);
		    max = Math.max(max,now);
		    min = Math.min(min,now);
		}
		System.out.println(max+" "+min);
	    }
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 23392
import java.util.Scanner;
import java.util.Arrays;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = 0;
    int n = sc.nextInt();
    char[] letters = sc.next().toCharArray();
    for(int i = 0; i < n - 2; i++){
    if(letters[i] == 'A'){
      if(letters[i+1] == 'B'){
        if(letters[i+2] == 'C'){
          a++;
        }
        continue;
      }
      else{
        continue;
      }
    }else{
      continue;
    }
  }
  System.out.println(a);
    
  }
}

Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        a = a^b;
        b = a^b;
        a = a^b;
    }
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }
    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}


void solve(void){
    int s;
    cin >> s;
    int ans;
    vector<int> set;
    set.push_back(s);
    for(int i = 1;;i++){
        if(s % 2 == 0){
            s /= 2;
            set.push_back(s);
        }else{
            s = s*3+1;
            set.push_back(s);
        }
        rep(j,0,set.size()-1){
            if(set[j] == set[i]){
                cout << i+1 <<  endl;
                return;
            }
        }
    }
}

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

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
def is_stairs(h):
    
    if len(h) == 1:
        return('Yes')
    h[0] -= 1
    for i in range(1, len(h)):
        if h[i-1] - h[i] > 0:
            return('No')
        h[i] = max(h[i-1],h[i]-1)
        #print(h)
    return('Yes')
print(is_stairs(h))

Measured memory_bytes: 14396
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 

int main() {
  int n;
  cin >> n;
  int a,b,c,d;
  a = 0;
  b = 0;
  c = 0;
  d = 0;
  string tmp;
  for(int i = 0 ;i<n;i++){
    cin >> tmp;
    if(tmp == "AC"){a++; }
    else if(tmp == "WA"){b++; }
    else if(tmp == "TLE"){c++; }
    else{d++; }
  }
  
  cout << "AC x " << a << endl;
  cout << "WA x " << b << endl;
  cout << "TLE x " << c << endl;
  cout << "RE x " << d << endl;
  
  
 
}

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

int main() {
	int n, k;
	cin >> n >> k;
	int ans = 1;
	rep(i, n) {
		ans = min(ans + k, ans * 2);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [ list(map(int, input().split())) for _ in range(N) ]

totalcol = 0
for n in range(N):
    ex = sum([ A[n][m] * B[m] for m in range(M) ])
    ex += C
    totalcol += (ex > 0)

print(totalcol)

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

int main()
{
  int64_t N, s = 0, ans = (1LL << 62);
  cin >> N;
  vector<int64_t> A(N);
  for (int64_t i = 0; i < N; i++)
  {
    cin >> A.at(i);
    A.at(i) -= (i + 1);
    s += A.at(i);
  }
  sort(A.begin(), A.end());
  int64_t a1 = 0, a2 = 0;
  for (int i = 0; i < N; i++)
  {
    a1 += abs(A.at(max((int64_t)0, N / 2 - 1)) - A.at(i));
    a2 += abs(A.at(N / 2) - A.at(i));
  }
  cout << min(a1, a2) << endl;
}

Measured memory_bytes: 4784
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (a, b) = listOfInt()
    println(if (a <= 8 && b <= 8) "Yay!" else ":(")
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt()= listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37868
// I need some holiday
// But I don't wish that everyday is holiday
// Because I didn't bear the pain
// Because it wasn't a true freedom
//         ——『イヤホンと蝉時雨』·Orangestar

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned int UI;
typedef pair<int, int> pii;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define MP make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

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

namespace fastIO
{
	const int MAX_BUFFER_SIZE = 1 << 16;

	char buffer[MAX_BUFFER_SIZE], *cur = buffer, *ed = buffer;

	inline char getc() { return cur == ed && (ed = (cur = buffer) + fread(buffer, 1, MAX_BUFFER_SIZE, stdin), cur == ed) ? EOF : *cur++; }
}
using fastIO::getc;

template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getc());
	for(; !isdigit(ch); ch = getc()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getc()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

inline char *read_str(char *s)
{
	register char ch(getc());
	while(!isgraph(ch)) ch = getc();
	for(; isgraph(ch); ch = getc()) *s++ = ch;
	*s = '\0';
	return s;
}

// END tpl.

const int MOD = (int) 1e9 + 7;

inline int fpm(int x, int y)
{
	int res = 1;
	for(; y; y >>= 1, x = (LL) x * x % MOD) if(y & 1) res = (LL) res * x % MOD;
	return res;
}

inline int inv(int x) { assert(x); return fpm(x, MOD - 2); }

namespace MATH
{
	const int n = 50;

	int fac[n + 5], ifac[n + 5];

	inline void init()
	{
		fac[0] = 1;
		for(int i = 1; i <= n; ++i) fac[i] = (LL) fac[i - 1] * i % MOD;
		ifac[n] = inv(fac[n]);
		for(int i = n - 1; i >= 0; --i) ifac[i] = (LL) ifac[i + 1] * (i + 1) % MOD;
	}

	inline int C(int N, int M) { return N < 0 || M < 0 || N < M ? 0 : (LL) fac[N] * ifac[N - M] % MOD * ifac[M] % MOD; }
}
using MATH::C;

const int MAXN = 50;

int n;

inline void input()
{
	n = read<int>();
}

inline void solve()
{
	static int f[MAXN + 5][MAXN + 5];

	f[1][0] = f[1][1] = n;
	for(int i = 1; i < n; ++i)
		for(int j = 0; j <= n; ++j) if(f[i][j])
			for(int k = 1; i + k <= n; ++k) if(k >= j && (k - j) % 2 == 0)
			{
				int y = (k - j) / 2;
				for(int x = 0; x <= k; ++x) (f[i + k][abs(y - x)] += (LL) f[i][j] * C(n - i, k) % MOD * C(k, x) % MOD) %= MOD;
			}

	printf("%d\n", (f[n][0] + MOD) % MOD);
}

int main()
{
#ifdef K_ON
	freopen("F.in", "r", stdin);
	freopen("F.out", "w", stdout);
#endif

	MATH::init();
	input();
	solve();

	return 0;
}

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

int main()
{
  vector<bool> v(101);
  for (int x = 1; x <= 9; x++) {
    for (int y = 1; y <= 9; y++) {
      v.at(x * y) = true;
    }
  }
  int n;
  cin >> n;
  if (v.at(n)) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans*(b&1?a:1);
}
int main(){
    string s;
    cin>>s;
    int l=s.size();
    vector <int> S(l);
    rep(i,0,l){
        S[i]=stoi(s.substr(i,1));
    }
    int cnt1=0,cnt2=0;
    rep(i,0,l){
        if (S[i]==1) cnt1++;
        else cnt2++;
    }
    cout<<min(cnt1,cnt2)*2;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,m;
	
	cin>>n>>m;
	vector<int> h(n+1);
	vector<int> j(n+1);
	for(int i=1; i<=n; i++){
		cin>>h.at(i);
		j.at(i)=0;
	}
	for(int i=0; i<m; i++){
		int a,b;
		cin>>a>>b;
		j.at(a)= max(j.at(a),h.at(b));
		j.at(b)= max(j.at(b),h.at(a));
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(h.at(i)>j.at(i)){
			ans++;}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4056
#include <iostream>
#include <bits/stdc++.h>
#include<climits>
using namespace std;
int main()
{
   int n;
   cin>>n;
   long sum[n+1];
   long diff[n+1];
   for(int i =0;i<n;i++)
   {
       long a,b;
       cin>>a>>b;
       sum[i] = a+b;
       diff[i] = a-b;
    }
    long maxi = LONG_MIN;
    long mini = LONG_MAX;
    for(int i=0;i<n;i++)
    {
       maxi = max(maxi,sum[i]);
       mini = min(mini,sum[i]);
    }
     long ans1 = maxi - mini;
    maxi = LONG_MIN;
    mini = LONG_MAX;
   
    for(int i=0;i<n;i++)
    {
        maxi = max(diff[i],maxi);
        mini = min(diff[i], mini);
    }
    long ans2 = maxi - mini;
    ans1= max(ans1,ans2);
  cout<<ans1<<endl;
    return 0;
}


Measured memory_bytes: 6752
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

int x, y;

int read() {
  if (scanf("%d%d", &x, &y) < 2) {
    return false;
  }
  return true;
}

void solve() {
  if (!(x % y)) {
    printf("-1\n");
    return;
  }
  printf("%d\n", x);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
n = int(stdin.readline())
a = [int(stdin.readline()) for _ in range(n)]
b = a.copy()
m1 = max(b)
b.remove(m1)
m2 = max(b)
for i in range(n):
  if a[i] == m1:
    print(m2)
  else:
    print(m1)

Measured memory_bytes: 14076
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n; cin >> n;
    ll k; cin >> k;
    ll a[2001]; INITA(a, 0, 2000, 0);
    REP(i, n) {
        cin >> a[i];
    }
    //   x       y      z
    // 3 2 1 | 3 2 1 | ...
    // 元の整数列だとO(n^2)で確認可能
    // b[i]: i+1番目の数以降の転倒数
    // c[i]: 0番目の数以降の転倒数
    // 各セクションで値ごとにb, それより後のセクションに関してc
    int b[2001]; INITA(b, 0, 2000, 0);
    int c[2001]; INITA(c, 0, 2000, 0);
    FOR(i, 0, n-1) {
        int tmpb = 0;
        int tmpc = 0;
        FOR(j, 0, n-1) {
            if ((i != j) && (a[i] > a[j])) {
                if (i < j) {
                    tmpb++;
                }
                tmpc++;
            }
        }
        b[i] = tmpb;
        c[i] = tmpc;
    }

    ll res = 0;

    // a[i]ごとに回す
    REP(i, n) {
        // セクション内
        res += (b[i] * k) % MOD;
        res %= MOD;

        // セクション外
        // 3セクションだとすると、123,23。21... k(k-1)/2
        res += c[i] * ((k * (k-1) / 2) % MOD) % MOD;
        res %= MOD;
    }
    cout << res << endl;
    // REP(i, n) {
    //     cout << b[i] << endl;
    // }
    // cout << endl;
    // REP(i, n) {
    //     cout << c[i] << endl;
    // }
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int price = 0;
    if (A + B > 2 * C) {
        if (X > Y) {
            price += Y * 2 * C;
            if (A > 2 * C) {
                price += (X - Y) * 2 * C;
            }
            else {
                price += (X - Y) * A;
            }
        }
        else {
            price += X * 2 * C;
            if (B > 2 * C) {
                price += (Y - X) * 2 * C;
            }
            else {
                price += (Y - X) * B;
            } 
        }
    }
    else {
        price += X * A;
        price += Y * B;
    }
    cout << price;
    

    return 0;
}

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

c = [[int(s) for s in input().split()] for _ in range(3)]

flag = True
for i in range(3):
    for j in range(3):
        if c[i][j] - c[i][(j+1)%3] != c[(i+1)%3][j] - c[(i+1)%3][(j+1)%3]:
            flag = False

if flag:
    print("Yes")
else:
    print("No")

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

MAXN = 10 ** 5


def answer():
    minf = 10
    for a in range(1, MAXN + 1):
        if n % a == 0:
            b = n // a
            f = max(len(str(a)), len(str(b)))
            minf = min(minf, f)
    return minf


print(answer())


Measured memory_bytes: 9180
import java.util.Scanner;

public class Main {

	private int N = 0;
	private int A = 0;
	private int B = 0;

	public static void main(String[] args) {

		Main myself = new Main();
		myself.execute();

	}

	/**
	 * 実処理メソッド
	 */
	public void execute() {

		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		A = sc.nextInt();
		B = sc.nextInt();

		int costPlan1 = A * N;
		int costPlan2 = B;

		System.out.println(costPlan1 <= costPlan2 ? costPlan1 : costPlan2);

		sc.close();

	}

}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int r;
	cin >> r;

	cout << 3 * r * r << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <vector>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int c, n = 0;
	bool minus = false;
	if ((c = gcu()) == '-') minus = true;
	else ungetc(c, stdin);
	while ((c = gcu()) >= '0' && c <= '9') n = 10 * n + (c - '0');
	return minus ? -n : n; }
si void scan(char *s) {while (!isspace(*s++ = gcu()));}
#define pcu putchar_unlocked
#define svo si void out
svo(int n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
svo(const char *s){while(*s)pcu(*s++);}
//svo(char *s){while(*s)pcu(*s++);}
svo(char c){pcu(c);}
template <typename T>
svo(vector<T> v){for(T &x:v)out(' '),out(x);out('\n');}
//svo(vector<T> &v){for(int &x:v)out(&x == &v[0]?"":" ",x);out('\n');}
template <typename head, typename... tail>
svo(head&& h, tail&&... t){out(h);out(move(t)...);}

typedef vector<int> v;

struct bst
{
	struct node { int v, l = -1, r = -1; };
	int root = -1, i = 0;
	vector<node> nodes;

	bst(int n)
	{
		nodes.resize(n);
	}

	int insert (int r, int v)
	{
		if (r == -1) {
			nodes[i].v = v;
			return i++;
		}
		node &n = nodes[r];
		if (n.v < v)
			n.r = insert(n.r, v);
		else
			n.l = insert(n.l, v);
		return r;
	}
	void insert (int n)
	{
		root = insert(root, n);
	}
	bool find(int r, int v)
	{
		if (r == -1)
			return false;
		node &n = nodes[r];
		return n.v == v ? true : n.v < v ? find(n.r, v) : find(n.l, v);
	}
	bool find(int v)
	{
		return find(root, v);
	}
	int get_and_remove_next_idx(int &r) {
		node &n = nodes[r];
		if (n.l == -1) {
			int tmp = r;
			r = erace(r, n.v);
			return tmp;
		}
		return get_and_remove_next_idx(n.l);
	}
	int erace(int r, int v)
	{
		if (r == -1)
			return -1;
		node &n = nodes[r];
		if (n.v == v)
			if (n.l == -1 && n.r == -1)
				return -1;
			else if (n.l == -1) {
				r = n.r;
				n = nodes[r];
			} else if (n.r == -1) {
				r = n.l;
				n = nodes[r];
			} else
				n.v = nodes[get_and_remove_next_idx(n.r)].v;
		else if (n.v < v)
			n.r = erace(n.r, v);
		else
			n.l = erace(n.l, v);
		return r;
	}
	void erace(int v)
	{
		root = erace(root, v);
	}
	void print(int r, v &buf)
	{
		if (r == -1)
			return;
		node n = nodes[r];
		buf.push_back(n.v);
		print(n.l, buf);
		out(' ', n.v);
		print(n.r, buf);
	}
	void print()
	{
		v buf;
		print(root, buf);
		out('\n', buf);
	}
};

int main()
{
	int n = in();
	char s[20];
	bst b(n);

	while (n--) {
		scan(s);
		switch(*s) {
		case 'i':
			b.insert(in()); break;
		case 'f':
			out(b.find(in()) ? "yes\n": "no\n"); break;
		case 'd':
			b.erace(in()); break;
		default:
			b.print();
		}
	}
}



Measured memory_bytes: 10300
#include <bits/stdc++.h>
  #define endl "\n"
  #define ll long long int
  #define vi vector<int>
  #define vll vector<ll>
  #define vvi vector < vi >
  #define pii pair<int,int>
  #define pll pair<long long, long long>
  #define mod 1000000007
  #define inf 1000000000000000001;
  #define all(c) c.begin(),c.end()
  #define mp(x,y) make_pair(x,y)
  #define mem(a,val) memset(a,val,sizeof(a))
  #define pb push_back
  #define f first
  #define se second
  
  using namespace std;
  int main()
  {
    std::ios::sync_with_stdio(false);
    ll n=0,m=0,k=0,x=0,t1=0,t2=0,t3=0,f=0,sum=0,count=0;

    cin>>n;
    ll arr[n+1],dp[n+1];
    arr[0]=inf; dp[0]=inf;

    for (ll i = 1; i <= n; ++i){
      cin>>arr[i];
    }
    dp[1]=0;

    for (ll i = 2; i <= n; ++i)
    {
      dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
    }

    cout<<dp[n]<<endl;

    return 0;
  }

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

int main()
{
	int H, W;

	while (cin >> H >> W, H + W)
	{
		int h[1501] = {};
		int w[1501] = {};
		map<int, int> setH;
		map<int, int> setW;

		for (int i = 1; i <= H; i++) cin >> h[i];
		for (int i = 1; i <= W; i++) cin >> w[i];

		for (int i = 1; i <= H; i++) h[i] += h[i - 1];
		for (int i = 1; i <= W; i++) w[i] += w[i - 1];

		for (int i = 0; i < H; i++)
		{
			for (int j = i + 1; j <= H; j++)
			{
				int t = h[j] - h[i];
				if (setH.count(t)) setH[t]++;
				else setH[t] = 1;
			}
		}
		for (int i = 0; i < W; i++)
		{
			for (int j = i + 1; j <= W; j++)
			{
				int t = w[j] - w[i];
				if (setW.count(t)) setW[t]++;
				else setW[t] = 1;
			}
		}

		int cnt = 0;
		for (auto i : setH)
		{
			if (setW.count(i.first)) cnt += setW[i.first] * i.second;
		}

		cout << cnt << endl;
	}

	return 0;
}

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

int main() {
  int n, ans = 0;
  cin >> n;
  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) == a.at(i + 1)) {
      ans++;
    }
  }
  cout << n - ans << endl;
}

Measured memory_bytes: 9504
def solve(string):
    n, m, *ps = string.split()
    n = int(n)
    ac = [0] * n
    wa = [0] * n
    for p, s in zip(*[iter(ps)] * 2):
        p = int(p) - 1
        if s == "AC":
            ac[p] = 1
        elif not ac[p]:
            wa[p] += 1
    return "{} {}".format(sum(ac), sum([w * a for a, w in zip(ac, wa)]))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 18980
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int x, y;
	cin >> x >> y;
	rep(i, x + 1){
		int cur = 2 * i;
		if(cur > y) break;
		if((y - cur) % 4 == 0 && (y - cur) / 4 == (x - i)){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main(){
	int b[3][3];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>b[i][j];
		}
	}

	int n;	cin>>n;
	for(int i=0;i<n;i++){
		int tgt;	cin>>tgt;
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(b[j][k]==tgt)b[j][k]=0;
			}
		}
	}

	bool flag=false;
	for(int y=0;y<3;y++){
		if(b[y][0]==0&&b[y][1]==0&&b[y][2]==0)flag=true;
	}
	for(int x=0;x<3;x++){
		if(b[0][x]==0&&b[1][x]==0&&b[2][x]==0)flag=true;
	}

	if(b[0][0]==0&&b[1][1]==0&&b[2][2]==0)flag=true;
	if(b[0][2]==0&&b[1][1]==0&&b[2][0]==0)flag=true;
	

	if(flag)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();

		long ans = 1;
		int mod = 1000000007;
		for(int i = 1; i <= n; i++) {
			ans = ans % mod * i % mod;
		}

		System.out.println(ans);
	}
}



Measured memory_bytes: 35352
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::cmp;

#[allow(dead_code)]
fn getline() -> Vec<String> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok().unwrap();
    s.split(' ').map(|x| x.trim().to_string()).collect::<Vec<String>>()
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>(s: &String) -> T {
    s.parse().ok().unwrap()
}

fn main() {
    let abc = getline();
    let a: i32 = get(&abc[0]);
    let b: i32 = get(&abc[1]);
    let c: i32 = get(&abc[2]);
    if c - b == b - a {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
#!/usr/bin/env ruby

word = [];numbers = [];codes =[]
i = 0
sharp = "#";dot = "."
loop do 
    word = gets.split.map(&:to_i)
    if word[0] == 0 and word[1] == 0 then; break; end
    word.each do |key|
        numbers << key
    end
end

((numbers.count + 1) / 2).times do 
    numbers[i].times do |loopindex|
        case loopindex % 2 
        when 0 then
            numbers[i + 1].times do |count| 
                case count % 2
                when 0 then
                    codes << sharp
                when 1 then
                    codes << dot
                end
            end
        when 1 then
            numbers[i + 1].times do |count|
                case count % 2
                when 1 then
                    codes << sharp
                when 0 then
                    codes << dot
                end
            end
        end
        codes.each do |value|
            print value
        end
        codes.clear
        puts ""
    end
    i += 2
    puts ""
end


Measured memory_bytes: 6892
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int a, b, c;

int main() {
	cin >> a >> b >> c;
	vector<int> v = { a, b, c };
	sort(ALL(v));
	
	cout << (v[1] == c ? "Yes" : "No") << endl;
	
	return 0;
}


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

int main()
{
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1));
    for(int i = 0; i <= n ; i++)
    {
        for(int j = 0; j <= m ; j++)
        {
            if(i == 0||j==0)
                dp[i][j] = 0;
            else if(s[i - 1] == t[j - 1])
                dp[i][j] = 1 + dp[i - 1][j - 1];
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    string res;
    int len = dp[n][m];
    for(int i = n, j = m; i > 0 || j > 0; )
    {
        if(i > 0 && dp[i][j] == dp[i - 1][j])
            i--;
        else if(j > 0 && dp[i][j] == dp[i][j - 1])
            j--;
        else if(i > 0 && j > 0 && dp[i][j] == dp[i - 1][j - 1] + 1)
        {
            res.push_back(s[i - 1]);
            i--;j--;
        }
    }
    reverse(res.begin(), res.end());
    cout << res;
    return 0;
}

Measured memory_bytes: 35584
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long 


signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int s;
	cin >> s;
	int q = ceil(sqrt(s));
	s = q*q - s;
	cout << "0 0 " << q << " " << s << " " << 1 << " " << q;
	
	
	
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MOD = 998244353;
const Int MAX = 5050;
using BS = bitset<MAX>;

Int msb(BS a){
  for(Int i=MAX-1;i>=0;i--)
    if(a[i]) return i;
  return -1;
}

BS gcd(BS a,BS b){
  Int x=msb(a),y=msb(b);
  if(x<y) swap(a,b),swap(x,y);
  if(y<0) assert(x>=0);
  if(y<0) return a;
  Int d=x-y;
  return gcd(a^(b<<d),b);
}

signed main(){
  Int n;
  string x;
  cin>>n>>x;
  vector<string> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];

  BS g(a[0]);
  for(Int i=1;i<n;i++) g=gcd(g,BS(a[i]));
  
  BS z(x);  
  Int ans=0,m=msb(g);
  for(Int i=MAX-1;i>=m;i--){
    ans=ans*2+z[i];
    ans%=MOD;
  }
  
  BS t(0);
  for(Int i=MAX-1;i>=m;i--)
    if(t[i]^z[i]) t^=g<<(i-m);

  for(Int i=m;i>=0;i--){
    if(t[i]<z[i]) ans++;
    if(t[i]!=z[i]) break;
    if(i==0) ans++;
  }
  
  ans%=MOD;  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 15616
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        long ans;
        if(w%3==0||h%3==0) ans = 0;
        else{
            ans = Math.min(helper(h,w),helper(w,h));
        }
        System.out.println(ans);
    }
    static long helper(int height, int width){
        long h = (long) height;
        long w = (long) width;
        long len1 = w/3+w%3-1;
        long s1=h*len1;
        long s2=h*((w-len1)/2);
        long s3=h*w-s2-s1;
        long s4=(w-len1)*(h/2);
        long s5=h*w-s4-s1;
        long ans1 = Math.max(s1,Math.max(s2,s3))-Math.min(s1,Math.min(s2,s3));
        long ans2 = Math.max(s1,Math.max(s4,s5))-Math.min(s1,Math.min(s4,s5));
        return Math.min(ans1,ans2);
    }
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    for (int i=0;i<s.length();i++){
        if (s[i]=='1')
            s[i]='9';
        else
            s[i]='1';
    }
    cout<<s;
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 212345;
int A[MAX_N];
ll B[MAX_N];
ll S[MAX_N];

int main2() {
  int N = nextInt();
  int K = nextInt();
  REP(i, N) A[i] = nextInt();
  REP(i, N) B[i] = ((A[i] % K) + K-1) % K;
  S[0] = 0;
  REP(i, N) S[i+1] = (S[i] + B[i]) % K;

  map<ll, ll> counter;
  ll ans = 0;
  REP(i, N+1) {
    if (i - K >= 0) --counter[ S[i-K] ];
    ans += counter[ S[i] ];
    ++counter[ S[i] ];
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 16768
#include<iostream>
using namespace std;
int main()
{
    int N,i,j,k;
    cin>>N;
    i=N%10;
    N=N/10;
    j=N%10;
    N=N/10;
    k=N%10;
    if(i==7 || j==7 || k==7)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;

#define ll long long

int main()
{
    ll N, M;
    scanf("%lld %lld", &N, &M);

    ll s = 0;
    for (ll i = 0; i < M; i++)
    {
        ll A;
        scanf("%lld", &A);
        s += A;
    }

    if (N - s >= 0)
        printf("%lld", N - s);
    else
        printf("-1");
}


Measured memory_bytes: 3812
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=ja 
ALDS1_2_A:バブルソート
*/

#include <bits/stdc++.h>

using namespace std;

void disp(unsigned short int *n, unsigned short int N);

int main(void){

	unsigned short int N;
	scanf("%d", &N);

	unsigned short int n[N];

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

    int max = N-1;
    int flag;
    if(N >= 2){
        flag = 1; //ソート終了フラグ
    }else if(N<=1) flag = 0;
    int count=0; //交換回数
    while(flag == 1){
        for(int i=0; i<max; i++){
            if(n[i] > n[i+1]){
                count += 1;
                unsigned short int tmp = n[i];
                n[i] = n[i+1];
                n[i+1] = tmp;
            }
        }
        max = max-1;
        if(max == 0) flag = 0;
    }

    disp(n, N);
    printf("%d\n",count);

	return 0;
	
  
}

void disp(unsigned short int *n, unsigned short int N){
	//printf("disp: ");
	for(int i=0; i<N; i++) {
		printf("%d", n[i]);
		if( i != N-1) printf(" ");
	}
	printf("\n");
}




Measured memory_bytes: 3180
from collections import deque
K = int(input())
q = deque([i for i in range(1, 10)])
for _ in range(K - 1):
    # 13print(q)
    num = q.popleft()
    for i in range(-1,2):
        if 0 <= int(str(num)[-1]) + i <= 9:
            q.append(num * 10 + int(str(num)[-1]) + i)
print(q[0])


Measured memory_bytes: 18876
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}
func main() {
	var N int
	fmt.Scanf("%d\n", &N)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		var a int
		fmt.Scan(&a)
		A[i] = a
	}

	sum := 0.0
	for _, r := range A {
		sum += 1 / float64(r)
	}
	fmt.Println(1 / sum)
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


vector<int> v[100001];
int c[100000];
int y[100000];

int main(){
  int N,M;
  cin >> N >> M;
  rep(i,M){
    cin >> c[i] >> y[i];
    v[c[i]].push_back(y[i]);
  }
  rep(i,N){
    sort(v[i+1].begin(),v[i+1].end());
  }
  rep(i,M){
    printf("%012lld\n",ll(c[i])*1000000+int(lower_bound(v[c[i]].begin(),v[c[i]].end(),y[i])-v[c[i]].begin())+1);
  }
  return 0;
}



Measured memory_bytes: 7808
N = int(input())
A = list(map(int,input().split()))
c = sum(A)/2

S = [0] * (N+1)
S[0] = 0
for i in range(N):
  S[i+1] = A[i] + S[i]

m = float("INF")
j = -1
for i in range(1, N+1):
  if abs(c - S[i]) < m:
    m = abs(c - S[i])
    j = i

print(abs((S[N] - S[j]) - S[j]))

Measured memory_bytes: 26220
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;

const ll INF = 5e15;
const ll MOD = 1e9 + 7;

ll dp[3010][3010];

int main(){
    dp[0][0] = 1;
    ll N;
    string S;
    cin >> N >> S;
    for(ll i = 1; i < N; i++){
        ll sum[i + 1] = {};
        for(ll j = 0; j < i; j++) sum[j + 1] = (sum[j] + dp[i - 1][j]) % MOD;
        for(ll j = 0; j <= i; j++){
            if(S[i - 1] == '<') dp[i][j] = sum[j];
            else dp[i][j] = (sum[i] - sum[j] + MOD) % MOD;
        }
    }
    ll ans = 0;
    for(ll i = 0; i < N; i++) (ans += dp[N - 1][i]) %= MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 69120
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	string R = "yuiophjklnm";
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while (cin >> s&&s != "#") {
		int a=R.find(s[0]);
		int cnt = 0;
		FOR(i, 1, s.size()) {
			if (a!=R.find('a')) {
				if (R.find(s[i])==R.find('a')) {
					cnt++;
					a = R.find('a');
				}
			}
			else {
				if (R.find(s[i])!=R.find('a')) {
					cnt++;
					a = 1;
				}
			}
		}
		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 3196
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
static const int MAX_N = 40000;

int n;
int a[MAX_N], b[MAX_N];

int main(){
	for(;;){
		scanf("%d", &n);
		if(n == 0) break;
		for(int i = 0; i < n; i++) scanf("%d", &a[i]);
		for(int i = 0; i < n; i++) scanf("%d", &b[i]);
		sort(a, a + n, greater<int>());
		sort(b, b + n, greater<int>());
		int res = -1;
		int cnt = 0;
		int index = 0;
		for(int i = 0; i < n - 1; i++){
			if(a[i] <= b[index]) index++;
			else cnt++;
			if(cnt > (i + 1) / 2){
				res = i + 1;
				break;
			}
		}
		if(res == -1) printf("NA\n");
		else printf("%d\n", res);
	}
	return 0;
}



Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
int n;
char p[4] = {'+', '+', '+'};
int main() {
	while(~scanf("%d", &n)) {
		int a = n / 1000;//千位
		int b = (n % 1000) / 100;//百位
		int c = (n % 100) / 10;//十位
		int d = n % 10;//个位
		if(a + b + c + d == 7) p[0] = '+', p[1] = '+', p[2] = '+';
		else if(a + b + c - d == 7) p[0] = '+', p[1] = '+', p[2] = '-';
		else if(a + b - c + d == 7) p[0] = '+', p[1] = '-', p[2] = '+';
		else if(a + b - c - d == 7) p[0] = '+', p[1] = '-', p[2] = '-';
		else if(a - b + c + d == 7) p[0] = '-', p[1] = '+', p[2] = '+';
		else if(a - b + c - d == 7) p[0] = '-', p[1] = '+', p[2] = '-';
		else if(a - b - c + d == 7) p[0] = '-', p[1] = '-', p[2] = '+';
		else if(a - b - c - d == 7) p[0] = '-', p[1] = '-', p[2] = '-';
		printf("%d%c%d%c%d%c%d=7\n", a, p[0], b, p[1], c, p[2], d);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include <algorithm>
#include<cmath>
#include <iomanip>
#include<vector>

double distance(int i, int j, int x[], int y[]){
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return std::pow(dx*dx + dy*dy, 0.5);
}

int main(void){
    int n;
    std::cin >> n;

    int x[n+1];
    int y[n+1];
    std::vector<int> v(n);

    for(int i = 1; i < n+1; i++){
        std::cin >>x[i] >> y[i];
    }
    for(int i = 0; i < n; i++){
        v[i] = i + 1;
    }

    double sum = 0;

    do {
        for (int i = 0; i < n-1; i++) sum += distance(v[i],v[i+1], x, y);
    } while(std::next_permutation(v.begin(), v.end()));

    double Factorial = 1;
    for(int i = 2; i <= n; i++) Factorial *= i;

    std::cout << std::fixed << std::setprecision(15) << sum / Factorial << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
using  namespace std;
int main(){
    string str;
    cin>>str;
    str.erase(str.size()-1);
    if(str.size()%2!=0)str.erase(str.size()-1);
    while(true) {
        if(str.substr(0, str.size() / 2)==str.substr(str.size()/2))break;
        else str.erase(str.size()-2);
    }
    cout<<str.size()<<endl;
}

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

namespace DPL2_A
{
    class Program
    {
        const int INF = 1 << 30;
        const int MAX = 15;
        static int ans = INF;
        static int n;
        static int[,] d = new int[MAX, MAX];
        static int[,] dp = new int[1 << MAX, MAX];
        static void solve(int f)
        {
            for (int i = 0; i < 1 << n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    dp[i, j] = INF;
                }
            }
            //goal(f) = 0 
            dp[(1 << n) - 1, 0] = 0;

            for (int S = (1 << n) - 2; S >= 0; S--)
            {
                for (int v = 0; v < n; v++)
                {
                    for (int u = 0; u < n; u++)
                    {
                        if ((S >> u & 1) == 0 && d[v,u] != INF)
                        {
                            dp[S, v] = Math.Min(dp[S, v], dp[S | 1 << u, u] + d[v, u]);
                        }
                    }
                }
            }
            ans = ans > dp[0, 0] ? dp[0,0] : ans;
        }
        static void Main(string[] args)
        {
            var t = scan;
            n = t[0];
            int e = t[1];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    d[i, j] = INF;
                }
            }
            for (int i = 0; i < e; i++)
            {
                var k = scan;
                d[k[0], k[1]] = k[2];
            }


            for (int i = 0; i < n; i++)
            {
                solve(i);
            }
            

            Console.WriteLine(ans == INF ? -1 : ans);
        }


        static int[] scan
        {
            get { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
        }
    }
}

Measured memory_bytes: 11620
{-# OPTIONS_GHC -O #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

import Control.Monad
import Data.Function
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap as M

main = do
    [n,k] <- map read.words<$>getLine :: IO [Int]
    as <- sortOn snd.M.toList.
        -- 数値のリスト -> 数値をkeyとして出現回数のMAPに
        foldl' (\m k -> M.insertWith(+)k 1 m) M.empty.
        unfoldr (B.readInt.B.dropWhile(==' ')) <$> B.getLine :: IO [(Int,Int)]
    let a = (fix $ \loop c k n ((_,e):xs) -> if k >= n then c else loop (c+e) k (n-1) xs)  0 k (length as) as 
    print a


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

ll knapsack(ll wt[], ll val[], ll n, ll W)
{
	ll t[n+1][W+1];
	
	f(i, 0, n+1)
	{
		f(j, 0, W+1)
		{
			if(i == 0 || j == 0)
			{
				t[i][j] = 0;
			}
		}
	}
	f(i, 1, n+1)
	{
		f(j, 1, W+1)
		{
			if(wt[i-1] <= j)
			t[i][j] = max(val[i-1] + t[i-1][j-wt[i-1]], t[i-1][j]);
			else
			t[i][j] = t[i-1][j];
		}
	}
	return t[n][W];
}

int main()
{
	ll n, W;
	cin >> n >> W;
	ll wt[n], val[n];
	f(i, 0, n)
	{
		cin >> wt[i] >> val[i];
	}
	ll sum = knapsack(wt, val, n, W);
	cout << sum;
}

Measured memory_bytes: 79104
#define SUBMIT

#include <bits/stdc++.h>

using namespace std;

template <typename T>
void print_array(const vector<T>& a) {
    for (int i = 0; i < a.size(); ++i) {
        if (0 < i) cout << " ";
        cout << a[i];
    }
    cout << endl;
}

template <typename T>
void insertion_sort(vector<T>& a) {
    for (int i = 1; i < a.size(); ++i) {
        auto key = a[i];
        int j = i - 1;
        while (0 <= j && key < a[j]) {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = key;
        print_array(a);
    }
}

int main() {
#ifdef SUBMIT
    auto& in = cin;
#else
    stringstream in(R"(6
5 2 4 6 1 3
)");
#endif
    int n;
    in >> n;
    vector<int> a;
    for (int i = 0; i < n; ++i) {
        int temp;
        in >> temp;
        a.push_back(temp);
    }

    print_array(a);
    insertion_sort(a);
    return 0;
}


Measured memory_bytes: 3156
#include <stdio.h>

int aa[50];

int fib(int n){
  if(n == 0 || n == 1 ) return aa[n] = 1;
  if(aa[n] != -1) return aa[n];
  return aa[n] = fib(n -1) + fib(n -2);
}

int main(){
  int b,i;
  for(i = 0; i < 50; i++) aa[i]=-1;

  scanf("%d",&b);
  printf("%d\n",fib(b));

  return 0;
}



Measured memory_bytes: 2104
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N, K;
    cin >> N >> K;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    // 累積和
    vector<ll> Ac(N);
    Ac[0] = A[0];
    FOR(i, 1, N){
        Ac[i] = Ac[i-1] + A[i];
    }
    
    // 累積和
    vector<ll> B(N);
    FOR(i, 0, N){
        B[i] = max(A[i], 0LL);
    }
    FOR(i, 1, N){
        B[i] += B[i-1];
    }

    ll max_score = 0;

    // Kをiからi+K-1まで置く
    FOR(i, 0, N-K+1){        
        FOR(j, 0, 2){
            ll score = 0;

            // Kの範囲を黒
            if(j==0){
                if(i==0){
                    score += Ac[K-1];
                }
                else{
                    score += Ac[i+K-1] - Ac[i-1];
                }
            }
            // Kの範囲を白
            else{
                score = 0;
            }

            // 自由箇所
            if(i==0){
                // 右の自由
                score += B[N-1] - B[K-1];
            }else{
                // 右の自由
                score += B[N-1] - B[i+K-1];
                // 左の自由
                score += B[i-1];
            }

            // 得点が出た
            max_score = max(max_score, score);
        }
    }

    p(max_score);

    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h> 
main()
{
	long long z[100005],i,j,k=0,l=0,t=0,n;
	scanf("%lld",&n);
	for(i=0;i<n;i++)
	scanf("%lld",&z[i]);
	for(i=0;i<n-1;i++)
	{
		if(k==0)
		{
			for(j=i+1;j<n;j++)
			{
				if(z[i]!=z[j])
				{
					if(z[j]>z[i])
						k=1;
					else
						k=-1;
					i=j-1;
					break;
				}
			}
		}
		else
		{
			if(k==1&&z[i+1]<z[i])
				{l++;k=0;t=1;}
			if(k==-1&&z[i+1]>z[i])
			{	l++;k=0;t=1;}
		}
	}
	
	printf("%lld\n",l+1);
}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n){
    if(a[i]%2==0){
      if(a[i]%3!=0&&a[i]%5!=0){
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
}

Measured memory_bytes: 256