akhauriyash/Code-Regression huggingface dataset:
from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    n=II()
    print(n*(n-1)//2)

main()


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

using namespace std;

using u128 = __uint128_t;

#define int long long
#define mod 1000000007

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    map<int, int> data;
    for(int i = 1; i<=n;i++){
        int temp;
        temp = (int)log10(i);
        int f = i / (int)pow(10, temp) , l = i % 10;
        data[f*10 + l]++;
    }
    int count = 0;
    for(int i = 1; i<=n; i++){
        int temp;
        temp = (int)log10(i);
        int l = i / (int)pow(10, temp) , f = i % 10;
        count += data[f *10 + l];
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,l,r) for (ll i = (ll)l; i < (ll)(r); i++)

int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    map<ll,ll> mA;
    ll ma = 0;
    rep(i,0,N){
        cin >> A[i];
        mA[A[i]]++;
        ma = max(ma, A[i]);
    }
    sort(A.begin(),A.end());

    vector<bool> dp(10000100,true);   // dp[i] : iより小さいiの約数が存在しなかったらtrue
    for(auto &a : A){
        ll cur = a;
        int cnt = 2;
        while(cur <= ma){
            cur = a * cnt;
            dp[cur] = false;
            cnt++;
        }
    }

    ll ans = 0;
    for(auto &a : A){
        if(dp[a] && mA[a]<2){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 18472
// ConsoleApplication106.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<set>
#include<map>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;

int main()
{
	set<int>la;
	int *aa,*bb,m,a, b, c,x,y;
	cin >> a >> b >> m;
	aa = new int[a];
	bb = new int[b];
	for (int i = 0; i < a; i++)
	{
		cin >> aa[i];
	}
	for (int i = 0; i < b; i++)
	{
		cin >> bb[i];
	}
	for (int i = 0; i < m; i++)
	{
		cin >> x >> y>>c;
		la.insert(aa[x - 1] + bb[y - 1] - c);
	}
	sort(aa, aa + a);
	sort(bb, bb + b);
	la.insert(aa[0] + bb[0]);
	for (auto& x : la)
	{
		cout << x << endl;
		break;
	}
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(){
    int n,c;
    cin >> n >> c;
    int d[c+1][c+1];
    for (int i=1; i<=c; i++){
        for (int j=1; j<=c; j++){
            cin >> d[i][j];
        }
    }
    int init[n+1][n+1];
    for (int i=1; i<=n; i++){
        for (int j=1; j<=n; j++){
            cin >> init[i][j];
        }
    }
    long long x[3][c+1];
  	for (int i=0;i<3;i++){
      for (int j=1; j<=c; j++){
        x[i][j]=0;
      }
    }
    for (int k=1; k<=c; k++){
        for (int i=1; i<=n; i++){
            for (int j=1; j<=n; j++){
                x[(i+j)%3][k]+=d[init[i][j]][k];
            }
        }
    }
    long long ans=1e15;
    for (int i=1; i<=c; i++){
        for (int j=1; j<=c; j++){
            for (int k=1; k<=c; k++){
                if(i!=j && j!=k && k!=i){
                    ans=min(ans,x[0][i]+x[1][j]+x[2][k]);
                }
            }
        }
    }
    cout << ans <<endl;
}




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

int main()
{
	int N, K;
	cin >> N >> K;
	bool memberCheck[100] = {false};

	for (int i = 0; i < K; i++)
	{
		int d;
		cin >> d;
		for (int j = 0; j < d; j++)
		{
			int member;
			cin >> member;

			memberCheck[member-1] = true;
		}
	}
	
	int count = 0;
	for (int i = 0; i < N; i++)
	{
		if(memberCheck[i] == false){
			count++;
		}
	}
	
	std::cout << count << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<math.h>

typedef struct{
  double x,y;
}Point;

void koch(int,Point,Point);

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

  scanf("%d",&n);

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

  printf("%f %f\n",a.x,a.y);

  koch(n,a,b);

  printf("%f %f\n",b.x,b.y);
  return 0;
}

void koch(int n,Point a,Point b){
  Point s,t,u;
  double th = M_PI * 60.0 / 180.0;

  if(n==0)return;

  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) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x -s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n-1,a,s);
  printf("%f %f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%f %f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%f %f\n",t.x,t.y);
  koch(n-1,t,b);
}

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

int main() {
    int N;
    cin>>N;
    int v[60], c[60], ans=0;
    for(int i=0;i<N;i++) cin >> v[i];
    for(int i=0;i<N;i++) cin >> c[i];
    for(int i=0;i<N;i++) ans += max(0,v[i]-c[i]);
    cout << ans << endl;
}


Measured memory_bytes: 256
import random

class Dice:
    def __init__(self, labels):
        self.labels = labels

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def change(self, convert):
        result = []
        for i in range(6):
            result.append(self.labels[convert[i] - 1])

        self.labels = result


dice = Dice(list(map(int, input().split())))
for i in range(int(input())):
    up, front = map(int, input().split())

    while(True):
        direction = random.randint(0, 3)
        if direction == 0:
            dice.north()
        if direction == 1:
            dice.south()
        if direction == 2:
            dice.east()
        if direction == 3:
            dice.west()

        if dice.labels[0] == up and dice.labels[1] == front:
            print(dice.labels[2])
            break

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

int main() {
    long long N;
    cin >> N;
    N--;
    int num = 1;
    while (N >= pow(26, num)) {
        N -= pow(26, num);
        num++;
    }
    stack<int>st;
    for (int i = 0; i < num; i++) {
        st.push(N % 26);
        N /= 26;
    }
    while (!st.empty()) {
        cout << (char)(st.top()+97);
        st.pop();
    }
}

Measured memory_bytes: 4104
#include <bits/stdc++.h>
	#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
	#define ll long long int
	using namespace std;
	const long double pi = 3.14159265358979323;
	const double EPS = 1e-9;
	const int N = 1e6 + 5;
	const int MOD = 1e9 + 7;

	std::vector<ll> v[505];
	
	int main(){
		fast;
		ll n, m, k, x, y, ans = 0;
		cin >> n >> m >> k;
		for(int i = 0; i < m; i++){
			cin >> x >> y;
			v[x].push_back(y);
		}
		for (int i = 1; i < 501; i += 1){
			sort(v[i].begin(), v[i].end());
		}
		while(k--){
			cin >> x >> y;
			ans = 0;
			for(int i = x; i <= y; i++){
				ll t = upper_bound(v[i].begin(), v[i].end(), y) - v[i].begin();
				ans += t;
			}
			cout << ans << "\n";
		}
		return 0;
	}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;

int main(){
  int n, p; cin >> n >> p;
  string s; cin >> s;
  ll ans = 0;
  ll x = 1;
  vector<int> d(n+1, 0);
  vector<int> cnt(p, 0);
  
  if(p == 2 || p == 5){
    for(int i = 0; i < n; i++){
      if((s[i]-'0') % p == 0) ans += i+1;
    }
  }
  else{
    for(int i = n-1; i >= 0; i--){
      d[i] = (d[i+1]+(s[i]-'0') * x) % p;
      x = x * 10 % p;
    }
    for(int i = n; i >= 0; i--){
      ans += cnt[d[i]];
      cnt[d[i]]++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n; cin >> n;
  string s, t; cin >> s >> t;
  int sn = s.size(), tn = t.size();
  int ans = sn + tn, d = 0;
  rep(i,sn) {
    int j = 0;
    if (s[i] == t[j]) {
      int ni = i;
      int cnt = 0;
      while(ni < sn && s[ni] == t[j]) {
        cnt++;
        ni++; j++;
      }
      if (ni == sn) d = max(d, cnt);
    }
  }
  cout << ans - d << endl;
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,x;
	cin>>n>>x;
	vector<ll> a(n);
	rep(i,n){
		cin>>a[i];
	}
	ll ans=0;
	rep(i,n-1){
		ll now=a[i]+a[i+1];
		if(now<=x) continue;
		a[i+1]=max(0ll,a[i+1]-(now-x));
		ans+=now-x;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main(){
    ios;
    int a, b;
    cin >> a >> b;
    b *= 2;
    if(a - b <= 0) cout << 0;
    else cout << a - b;
    }



Measured memory_bytes: 256
import collections


if __name__ == '__main__':
    n = int(input())
    a_list = list(map(int,input().split()))

    c = collections.Counter(a_list)

    dic_cnt = dict(c.most_common())

    answer = -1
    for k in dic_cnt.keys():
        cnt = dic_cnt[k]
        if k-1 in dic_cnt.keys():
            cnt += dic_cnt[k-1]
        if k+1 in dic_cnt.keys():
            cnt += dic_cnt[k+1]
        answer = max(answer,cnt)
    print(answer)



Measured memory_bytes: 21088
while True:
    n,k = map(int, input().split())
    if n == k == 0:
        break
    s = list(map(int, input().split()))
    for _ in range(n):
        b = list(map(int, input().split()))
        for i in range(k):
            s[i] -= b[i]
    print("Yes" if min(s) >= 0 else "No")

Measured memory_bytes: 7632
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <vector>
#include <deque>
#include <cstdlib>
#include <numeric>
#include <cstring>
#include <ctime>
#include <climits>
#include <sstream>
#include <complex>
#define Mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define Rep(__i,__n) for(int __i = 0 ; __i < (__n);__i++)
#define Range(_ind,_a,_b) for(int _ind = (_a) ; _ind <(int)(_b);_ind++)
#define iRange(_i,_a,_b,_c) for(int _i = (_a) ; _i <(int)_b;_i+=_c)
#define All(__cont)  (__cont).begin(),(__cont).end()
#define ForEach(_itr,_cont) for(auto _itr  = _cont.begin();_itr !=  _cont.end();_itr++)


using namespace std;
typedef complex<double> P;
typedef long long ll;
typedef vector<int> vi ;
typedef vector<double> vd;
typedef vector<vector <int> > vvi;
typedef vector<vector<double> > vvd;
typedef pair<int,int> pii;
const int inf = INT_MAX / 3;
const double eps = 1e-9;

template <typename T >
void output(T a,string label = ""){
#ifdef DEBUG
  cout<<"[" <<(label==""?"":label + ":")<< a <<  "]"<< endl;
#endif
}
template <typename T>
void output(vector<T> &vec){
#ifdef DEBUG
  cout << "[";
  ForEach(itr,vec){
    if(itr != vec.begin())cout << ",";
    cout << *itr;
  }
  cout << "]"<<endl;;
#endif
}

int memo[301][301],cache[301][301];

#ifndef __NOT__MAIN

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> input(H);
  Rep(i,H){
    cin >> input[i];
  }
  int ans = 0;
  ll cnt2 = 0;

  Rep(i,W-1){    
    for(int a = H; a>=0;a-- ){
      for(int b = H ; b >= 0 ; b--){
	memo[a][b] = -1;
	cnt2 += 1;
	if(a == H || b ==H){
	  cache[a][b] = 0;
	  continue;
	} else if(input[H-a-1][i] == input[H-b-1][i+1]) {
	  cache[a][b] = cache[a+1][b+1] + 1;
 	} else {
	  cache[a][b] = cache[a+1][b+1] ;
	}
      }
    }
    for(int a = H ; a>= 0 ; a--){
      for(int b = H ; b >=0;b--){
	if(a == H || b == H) {
	  memo[a][b] = 0;
	  continue;
	}
	memo[a][b] = min(memo[a+1][b],memo[a][b+1])  + cache[a][b];
      }
    }
    ans += memo[0][0];
  }
  cout << ans << endl;
}
#endif


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

int main(){
 string S, T;
  cin >> S >> T;
  int ans = 0;
  
  rep(i, S.size()){
    if(S.at(i) != T.at(i)) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3864
from collections import Counter
from itertools import permutations
n=int(input())
if n==1:print(1);exit()
A=[list(map(int,input().split())) for i in range(n)]
B=[(a[0]-b[0],a[1]-b[1]) for a,b in permutations(A,2)]
most=max(Counter(B).values())
print(n-most)

Measured memory_bytes: 3828
package main

import "fmt"

func main(){
	var N, ans int;
	fmt.Scan(&N);

	if N < 10 {
		ans = N;
	}else if N < 100{
		ans = N % 10;
	}else {
		ans = N % 100;
		ans = ans % 10;
	}
	if ans == 3 {
		fmt.Println("bon");
	}else if ans == 0 || ans == 1 || ans == 6 || ans == 8{
		fmt.Println("pon");
	}else{
		fmt.Println("hon");
	}
	// fmt.Println(ans);
}

Measured memory_bytes: 1752
#include <stdio.h>

int main(){  
	int i, n;
	long long a[2000001], min, max, sum;
	scanf("%d\n", &n); 
	for (i = 1; i <= n; i++){
	scanf("%lld ", &a[i]);
	}
min = a[1];
max = a[1];
sum = a[1];

for (i = 2; i <= n; i++){
	if(a[i] > max) max = a[i];
        if(a[i] < min) min = a[i];
	sum += a[i];
}
printf("%lld %lld %lld\n", min, max, sum);

return 0;}



Measured memory_bytes: 2100
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        for(int i = 0; i <= 25; i++)
        {
            for(int j = 0; j <= 14; j++)
            {
                if(N == i * 4 + j * 7)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
        }
        Console.WriteLine("No");
    }
}


Measured memory_bytes: 13140
N = gets.to_i
H = gets.split.map(&:to_i)

ret = 'Yes'
heights = [0, 0, 0]

N.times do |i|
  if i == N - 1
    if heights[0] <= H[i]
      break
    else
      ret = 'No'
      break
    end
  end

  heights[1] = H[i]
  heights[2] = H[i + 1]
  
  if heights[0] <= heights[1] - 1 && heights[1] - 1 <= heights[2]
    heights[0] = heights[1] - 1
  elsif heights[0] <= heights[1] && heights[1] <= heights[2]
    heights[0] = heights[1]
  else
    ret = 'No'
    break
  end
end

puts ret

Measured memory_bytes: 8580
#include <iostream>
#include <stdio.h>
#include <string>

#define MAX_N 200'000

using namespace std;

string A[MAX_N];

int main() {
  string S;
  cin >> S;
  A[0] = S[0];
  string s = "";
  int cnt = 1;
  for (int i = 1; i < S.size(); ++i) {
    s += S[i];
    if (s != A[cnt - 1]) {
      A[cnt++] = s;
      s = "";
    }
  }
  printf("%d\n", cnt);
}

Measured memory_bytes: 8164
#include <bits/stdc++.h>
using namespace std;
int main() {
	// your code goes here
	//#ifndef ONLINE_JUDGE
	//#endif
	int n;
	cin>>n;
	int a[n];
	long long ans=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(i)
		{
			if(a[i]>a[i-1])	continue;
			ans+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4420
#include <iostream>

using namespace std;

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

  long long y = 0;
  int b = 0;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    int c = a + b - x;
    if (c > 0) {
      y += c;
      a -= c;
    }
    b = a;
  }
  cout << y << "\n";
  
  return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())

graph = []
for i in range(H):
    graph.append(input())

L = [[0 for _ in range(W)] for _ in range(H)]
U = [[0 for _ in range(W)] for _ in range(H)]
D = [[0 for _ in range(W)] for _ in range(H)]
R = [[0 for _ in range(W)] for _ in range(H)]


for y in range(H):
    for x in range(W):
        if graph[y][x] == "#":
            L[y][x] = 0
        elif x == 0:
            L[y][x] = 1
        else:
            L[y][x] = L[y][x-1] + 1

for x in range(W):
    for y in range(H):
        if graph[y][x] == "#":
            U[y][x] = 0
        elif y == 0:
            U[y][x] = 1
        else:
            U[y][x] = U[y-1][x] + 1

for x in range(W):
    for y in range(H-1, -1, -1):
        if graph[y][x] == "#":
            D[y][x] = 0
        elif y == H-1:
            D[y][x] = 1
        else:
            D[y][x] = D[y+1][x] + 1

for y in range(H):
    for x in range(W-1, -1, -1):
        if graph[y][x] == "#":
            R[y][x] = 0
        elif x == W-1:
            R[y][x] = 1
        else:
            R[y][x] = R[y][x+1] + 1

ans = -1
for y in range(H):
    for x in range(W):
        ans = max(ans, L[y][x] + R[y][x] + U[y][x] + D[y][x] - 3)

print(ans)


Measured memory_bytes: 211264
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>

using namespace std;
typedef pair<string, int> bug;
typedef map<string, int> closeMap;

int isOK(string str) {
    // cout << "str:" << str << " " << str.size() << endl;
    for ( int i = 0; i < str.size(); i++ ) {
        if ( str[0] != str[i] ) return 0;
    }
    return 1;
}

char cc(char a, char b) {
    // 並び替え
    if ( b < a ) {
        char tmp = a;
        a = b;
        b = tmp;
    }

    if ( a == 'b' && b == 'g' ) {
        return 'r';
    } else if ( a == 'b' && b == 'r' ) {
        return 'g';
    } else {
        return 'b';
    }
}

void wfs(string str) {
    int cnt = -1;
    string first = str;
    queue<bug> open;
    closeMap close;

    // 初期状態をプッシュ
    open.push( make_pair(str, 0) );

    close.insert( closeMap::value_type(str, 1) );
    // cout << str << " key:" << close[str] << endl;

    while(!open.empty()) {
        bug b = open.front(); open.pop();
        string cs = b.first;

        if ( isOK(cs) ) {
            cnt = b.second;
            break;
        }

        int c = 0;
        for ( int i = 1; i < cs.size(); i++ ) {
            if ( cs[i-1] != cs[i] ) {
                string tmp = cs;
                char nc = cc(cs[i-1], cs[i]);
                tmp[i-1] = nc;
                tmp[i] = nc;

                if ( close[tmp] )continue;
                open.push( make_pair(tmp, b.second+1) );
                close[tmp] = 1;
                c++;
            }
        }
    }

    if ( cnt == -1 ) {
        cout << "NA" << endl;
    } else {
        cout << cnt << endl;
    }


}

int main() {
    string n;

    while ( cin >> n, n != "0" ) {
        wfs(n);
    }

    return 0;
}

Measured memory_bytes: 2924
#include <bits/stdc++.h>
using namespace std;
int main () {
  int a,b,c;
  cin >>a>>b>>c;
  if (a+b==c || b+c==a || c+a==b) {
    cout <<"Yes"<<endl;
  }
  else {
    cout <<"No"<<endl;
  }
}

       

Measured memory_bytes: 256
#include <stdio.h>

int main( void )
{
	int a, b;
	
	scanf( "%d %d", &a, &b );
	
	if( a > b ){
		printf( "a > b\n" );
	}else if( b > a ){
		printf( "a < b\n" );
	}else{
		printf( "a == b\n" );
	}
	
	return 0;
}

Measured memory_bytes: 580
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int MOD =1000000007;

int main() {
  int n,m;
  cin>>n>>m;
  
  vector<ll> dp(n+1,0);
  
  int a=-1;
  rep(i,n+1){
    if(i>a) cin >> a;
    if(i==a){
      dp[i]=0;
      continue;
    }
    else if(i==0) dp[i]=1;
    else if(i==1) dp[i]=dp[i-1];
    else dp[i]=(dp[i-1]+dp[i-2])%MOD;
  }
  
  cout << dp[n] << endl;
  
  return 0;
}

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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A[] = new int[N];
        int B[] = new int[N];
        for(int i = 0; i < N; i++) {
        	A[i] = sc.nextInt();
        	B[i] = A[i];
        }
        sc.close();
        Arrays.sort(B);
        for(int i = 0; i < N; i++) {
        	if(B[N-1] != A[i]) {
        		System.out.println(B[N-1]);
        	}else {
        		System.out.println(B[N-2]);
        	}
        }
	}
}

Measured memory_bytes: 100152
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
#define check(n) reverse(all(n));rep(z,0,n.size())cout<<n[z];co("");reverse(all(n));
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll a,b,c=0,d=0,e;
  string s;
  cin>>s;
  if(s=="ABC") co("ARC");
  else co("ABC");
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main(){
    const int PRICES_LENGTH = 4;
    int prices[PRICES_LENGTH];
    float scales[4] = {.25f, .5f, 1.0f, 2.0f};
    
    for(int i=0;i<PRICES_LENGTH;i++){
        if(i>0){
            int eval;
            cin >> eval;
            
            prices[i] = min(prices[i-1]*2, eval);
        }else{
            cin >> prices[i];
        }
    }
    
    long quantity;
    long cost = 0;
    cin >> quantity;
    
    long count;
    
    count = floor(quantity/2);
    quantity-= count*2;
    cost+=prices[3]*count;
    
    count = floor(quantity);
    quantity-= count;
    cost+=prices[2]*count;
    
    cout << cost;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e4 + 1;
const int mod = 1e9 + 7;
int dp[maxn][100][3];

signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string k;
	cin >> k;
	int d;
	cin >> d;
	int n = k.size();
	for (int i = 1; i < (int)(k[0] - '0'); i++) {
		dp[1][i % d][0]++;
		dp[1][i % d][0] %= mod;
	}
	if (k[0] != '0') {
		dp[1][(k[0] - '0') % d][1]++;
		dp[1][(k[0] - '0') % d][1] %= mod;
	}
	for (int i = (int)(k[0] - '0') + 1; i <= 9; i++) {
		dp[1][i % d][2]++;
		dp[1][i % d][2] %= mod;
	}
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < d; j++) {
			int mx = k[i] - '0';
			for (int to = 0; to < mx; to++) {
				int kek = (j + to) % d;
				dp[i + 1][kek][0] += dp[i][j][0] + dp[i][j][1];
				dp[i + 1][kek][2] += dp[i][j][2];
				dp[i + 1][kek][0] %= mod;
				dp[i + 1][kek][2] %= mod;
			}
			dp[i + 1][(j + mx) % d][1] += dp[i][j][1];
			dp[i + 1][(j + mx) % d][1] %= mod;
			dp[i + 1][(j + mx) % d][0] += dp[i][j][0];
			dp[i + 1][(j + mx) % d][0] %= mod;
			dp[i + 1][(j + mx) % d][2] += dp[i][j][2];
			dp[i + 1][(j + mx) % d][2] %= mod;
			for (int to = mx + 1; to <= 9; to++) {
				int kek = (j + to) % d;
				dp[i + 1][kek][0] += dp[i][j][0];
				dp[i + 1][kek][2] += dp[i][j][1] + dp[i][j][2];
				dp[i + 1][kek][2] %= mod;
				dp[i + 1][kek][0] %= mod;
			}
		}
	}
	int ans = 0;
	for (int i = 1; i < n; i++) {
		ans += (dp[i][0][0] + dp[i][0][1] + dp[i][0][2]) % mod;
	}
	ans += (dp[n][0][0] + dp[n][0][1]) % mod;
	ans %= mod;
	cout << ans;
	return 0;
}

Measured memory_bytes: 23680
def Al(p):
   Alp = "abcdefghijklmnopqrstuvwxyz"
   for j in range(26):
      if p == Alp[j]:
         return j

def main():
   S = input()

   alpha = "abcdefghijklmnopqrstuvwxyz"

   if S == "zyxwvutsrqponmlkjihgfedcba":
      return -1

   elif len(S) != 26:
      for a in alpha:
         if (a in S)==False:
            return S + a
   
   else:
      A = ""
      for i in range(len(S)):
         s = S[-(i+1)]
         Snew = S[:-(i+1)]
         for a in A:
            if Al(s) < Al(a):
               return Snew + a
         A = A + s

if __name__ == "__main__":
   print(main())


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

def yakusuu(N):
    ret1 = []
    ret2 = []
    for i in range(1,int(N**0.5)+1):
        if N%i==0:
            ret1.append(i)
            ret2.append(N//i)
    return ret1,ret2

X,Y = yakusuu(N)

ans = 10**13
for i,x in enumerate(X):
    y = Y[i]
    ans = min(ans,abs(x-1)+abs(y-1))
print(ans)

Measured memory_bytes: 39664
#include <stdio.h>
#include <string.h>
#include <iostream>

using namespace std;

int main(void){
	int r, c, b, i, j, s[10][10000], t[10][10000], m, sum,mx;
	while(1){
		scanf("%d%d",&r,&c);
		if(r == 0 && c == 0) break;
		mx = 0;
		for(i = 0;i < r;i++){
			for(j = 0;j < c;j++)
				scanf("%d",&s[i][j]);
		}
		for(b = 0;b < (1 << r);b++){
			memcpy(t,s,sizeof(s));
			for(i = 0;i < r;i++){
				if(b & (1 << i)){
					for(j = 0;j < c;j++)
						t[i][j] = (t[i][j] + 1) % 2;
				}
			}
			sum = 0;
			for(i = 0;i < c;i++){
				m = 0;
				for(j = 0;j < r;j++)
					if(!t[j][i]) m++;
				sum += max(m,r - m);
			}
			mx = max(mx,sum);
		}
		printf("%d\n",mx);
	}
	return 0;
}

Measured memory_bytes: 1984
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}
	
	long dp[][];
	
	long[] fib;
	
	long mod = 1000000007;
			  

	public void solve() throws IOException {
		
		FastScanner fs = new FastScanner();
		int h = fs.nextInt();
		int w = fs.nextInt();
		int k = fs.nextInt();
		
		dp = new long[h+1][w];
		fib = new long[10];
		dp[0][0] = 1;
		for(int i = 1; i < w; i++) {
			dp[0][i] = 0;
		}
		
		for(int i = 1; i <= h; i++) {
			for(int j = 0; j < w-1; j++) {
				// j -> j+1(j+1 -> j)の個数を数える.
				int left = Math.max(0, j - 1);
				int right = Math.max(0, w- (j+1) - 2);
				
				long numOfEdge = fib(left+1) * fib(right+1);
//				System.out.println(numOfEdge);
				
				dp[i][j+1] = (dp[i][j+1] + (dp[i-1][j] * numOfEdge)) % mod;
				dp[i][j] = (dp[i][j] + (dp[i-1][j+1] * numOfEdge)) % mod;
			}
			for(int j = 0; j < w; j++) {
				// j->j+1, j -> j-1に棒がないパターン
				int left = Math.max(0, j-1);
				int right = Math.max(0, w-1-j-1);
				
				long numOfEdge = fib(left+1) * fib(right+1);
				dp[i][j] = (dp[i][j] + (dp[i-1][j]*numOfEdge)) % mod;
			}
		}
//		System.out.println(Arrays.toString(fib));
		System.out.println(dp[h][k-1]);
	}
	
	long fib(int n) {
		if(fib[n] > 0) {
			return fib[n];
		}
		if(n == 0) {
			fib[0] = 1;
			return 1;
		}
		
		if(n == 1) {
			fib[1] = 1;
			return 1;
		}
		
		fib[n] = fib(n-1)+fib(n-2);
		return fib[n];
	}
	
	

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}


}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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; }

int main() {
    int a, b; cin >> a >> b;
    cout << a*b << endl;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>

int main()
{

   int a,b,c,d;

    scanf("%d%d%d%d",&a,&b,&c,&d);


            if(abs(a-c)<=d){

                printf("Yes\n");



            }


    else if(abs(a-b)<=d && abs(b-c)<=d){

                printf("Yes\n");

            }


    else{

        printf("No\n");

    }




    return 0;
}




Measured memory_bytes: 1632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){

          int n;
           cin>>n;

         int arr[n];

           int freq[1000001]={0};

          for(int i=0;i<n;i++)
            {
               cin>>arr[i];
                freq[arr[i]]++;
            }
              int count=0;

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

                 int x = arr[i];
                   int c=0;

                    for(int j=1;j<=sqrt(x);j++){

                         if(x % j==0){

                              int p = x/j;

                              if(x!=j)
                              {
                                 if(freq[j] > 0)
                                    c++;
                              }
                              else{
                                if(freq[j] > 1)
                                  c++;
                              }
                              if(p!=x){
                                   if(freq[p] > 0)
                                    c++;
                              }
                              else{
                                 if(freq[p] > 1)
                                  c++;
                              }
                         }
                    }
                     if(c==0)
                      {
                        count++;
                      }
            }
             cout<<count;
}


Measured memory_bytes: 8152
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = 1e9;

void mark(int v, int from, int remain, vector<bool>& ok, vector<vector<int>>& rg)
{
	if(ok[v]) return;
	if(remain < 0) return;

	ok[v] = true;

	for(auto w : rg[v]) {
		if(w == from) continue;
		mark(w, v, remain - 1, ok, rg);
	}
}

vector<int> compute_depth(vector<vector<int>>& rg)
{
	vector<int> depth(rg.size(), -1);
	queue<pair<int,int>> q;

	q.push({0, 0});

	while(!q.empty()) {
		int v = q.front().first;
		int d = q.front().second;
		q.pop();
		depth[v] = d;
		for(auto w : rg[v]) {
			if(depth[w] != -1) continue;
			q.push({w, d + 1});
		}
	}

	return depth;
}

int main()
{
	int n, k;
	vector<int> as;

	scanf("%d%d", &n, &k);
	as.resize(n);
	for(int i = 0; i < n; ++i) {
		scanf("%d", &as[i]);
		as[i] -= 1;
	}

	vector<vector<int>> rg(n);

	for(int i = 1; i < n; ++i) {
		int to = as[i];
		rg[to].push_back(i);
	}

	vector<int> depth = compute_depth(rg);

	priority_queue<pair<int,int>> q;
	vector<bool> ok(n, false);
	int ans = (as[0] != 0);

	for(int i = 0; i < n; ++i) {
		if(depth[i] > k)
			q.push({depth[i], i});
	}

	while(!q.empty()) {

		int v = q.top().second;
		int p = v;
		q.pop();

		if(ok[v])
			continue;

		for(int i = 0; i < k - 1; ++i)
			p = as[p];

		mark(p, as[p], k - 1, ok, rg);
		ans += 1;
	}

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

	return 0;
}


Measured memory_bytes: 14336
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	long long int x;
	long long int ans = 0;
	cin >> x;
	ans = ans + x / 500 * 1000;
	x = x % 500;
	ans = ans + x / 5 * 5;
	cout << ans;

 }


Measured memory_bytes: 256
import itertools as it

N,M=map(int,input().split())
e=[[False for j in range(N+1)] for i in range(N+1)]
for i in range(M):
    a,b=map(int,input().split())
    e[a][b]=e[b][a]=True
# print(e) #DB

ans=0
l=list(range(2,N+1))
for p in it.permutations(l,N-1):
    q=(1,)+p    
    # print(q) #DB
    f=True
    for i in range(N-1):
        # print((q[i],q[i+1])) #DB
        if not e[q[i]][q[i+1]]:
            f=False
            break
    if f:
        ans+=1

print(ans)

Measured memory_bytes: 40048
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    ll M = N*(N+1)/2;
    ll S = accumulate(all(A),0LL);
    if (S%M != 0) {
        cout << "NO" << endl;
        return 0;
    }
    ll K = S/M;
    vector<ll> cnt(N);
    rep(i,N-1) {
        if ((A[i]+K-A[i+1])%N) {
            cout << "NO" << endl;
            return 0;
        }
        cnt[i+1] = (A[i]+K-A[i+1])/N;
        A[i+1] = A[i]+K;
        if (cnt[i+1] < cnt[i]) {
            cout << "NO" << endl;
            return 0;    
        }
    }
    ll z = K - cnt[N-1];
    if (z < 0) {
        cout << "NO" << endl;
        return 0;
    }
    for (int i = N-1; i > 0; i--) {
        cnt[i] -= cnt[i-1];
    }
    cnt[0] = z;
    ll c = 0;
    vector<ll> B(N);
    rep(i,N) B[i] = N+1-i;
    B[0] -= N;
    rep(i,N) {
        c += cnt[i]*B[i];
    }
    cout << (c == A[0] ? "YES" : "NO") << endl;
}


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

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a+n);
    int al = 0, bo= 0;
    for(int i = 0; i < n; i++)
    {
        if(i %2 == 0)
        {
            al += a[i];
        }
        else
        {
            bo += a[i];
        }
    }
    cout << abs(al - bo) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;

int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    VV dp(n,vector<ll>(n,0));
    rep(i,n){
        dp[n-1][i]=s[n-1]==s[i];
    }
    ll ans=0;
    for(ll i=n-2;i>=0;i--){
        for(ll j=0;j+1<n;j++){
            if(s[i]!=s[j])dp[i][j]=0;
            else dp[i][j]=dp[i+1][j+1]+1;
            ans=max(ans,min(dp[i][j],abs(i-j)));
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 195840
Ns = input()
N = int(Ns)
Nl = len(Ns)
ret = 0
def doit(t, f , s, now):
    global ret
    if t + f + s == 0:
        if int(now) <= N:
            ret += 1
        return
    if t > 0:
        doit(t - 1, f, s, now + str(3)) 
    if f > 0:
        doit(t, f - 1, s, now + str(5)) 
    if s > 0:
        doit(t, f, s - 1, now + str(7)) 
    
for seven in range(1, Nl - 1):
    for five in range(1, Nl - seven):
        least = Nl - seven - five
        for three in range(1, least + 1):
            doit(three, five, seven, '')

print(ret)


Measured memory_bytes: 3064
N=input()
K=int(input())
S="0"*(100-len(N))+N
DP=[[[0]*2 for _ in range(K+2)] for _ in range(101)]

DP[0][0][0] = 1
for i in range(100):
  for j in range(K+1):
    #SがN以下かわからないまま、「0」の文字をなぞるとき、0でない数字jはそのまま
    if S[i]=='0':
      DP[i+1][j][0]+=DP[i][j][0]
      
    #SがN以下かわからないまま、「0」以外の文字をなぞるとき、0でない数字jも+1
    else:
      DP[i+1][j+1][0]+=DP[i][j][0]
    
    #SがN以下が確定している　
    DP[i+1][j][1]+= DP[i][j][1]
    if int(S[i])>0:
      #0以外の文字がくると、
      DP[i+1][j][1]+=DP[i][j][0]
      
    #SがN以下が確定しているものは、1~9をくっつけたものと、同じ桁だけどより低い数字が来たとき
    DP[i+1][j+1][1] += DP[i][j][1]*9+DP[i][j][0]*(max(0, int(S[i])-1))
print(sum(DP[-1][K]))

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;
typedef long double ld;
ll mod=1e9+7;
int dp[6001][6001];

int main(){
    int n,t;cin>>n>>t;
    vector<pair<int,int> > v(n);
    for(int i=0;i<n;i++)cin>>v[i].first>>v[i].second;
    int ans=0;
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)for(int j=0;j<t;j++){
        dp[i+1][j+v[i].first]=max(dp[i][j]+v[i].second,dp[i+1][j+v[i].first]);
        dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
    }
    for(int i=0;i<n;i++)ans=max(ans,dp[i][t-1]+v[i].second);
    cout<<ans;
}

Measured memory_bytes: 71936
from itertools import accumulate
MOD = 10**9 + 7


N = int(input())
A = list(map(int, input().split()))
A_cumsum = list(accumulate(A))

ans = 0
for i in range(N-1):
    ans += A[i] * (A_cumsum[-1] - A_cumsum[i]) % MOD

print(ans % MOD)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[111111];

signed main(){
    cin>>N;
    rep(i,N)cin>>A[i];
    int cur=0;
    int ans=0;
    while(cur<N){
        ans++;
        int nex=cur;

        while(nex<N&&A[nex]==A[cur])nex++;
        if(nex==N)break;
        bool gre=false;
        if(A[nex]>A[nex-1])gre=true;

        while(nex<N){
            if(gre&&A[nex]<A[nex-1])break;
            if(!gre&&A[nex]>A[nex-1])break;
            nex++;
        }
        cur=nex;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;
#define vsort(v) sort(v.begin(), v.end());
#define vsort_reverse(v) sort(v.begin(), v.end(), greater<int>());
#define bsearch(v, n) binary_search(v.begin(), v.end(), n)
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, X;
	cin >> N >> X;
	vector<int> m;
	for(int i = 0; i < N; i++) {
		int x;
		cin >> x;
		m.push_back(x);
	}
	
	for(int i = 0; i < N; i++) {
		X -= m[i];
	}

	int rslt = N;

	vsort(m);
	rslt += X / m[0];	
	cout << rslt << endl;
}


Measured memory_bytes: 256
import java.util.Scanner


object Main {
  def read() = {
    val sc = new Scanner(System.in)
    val a, b, c, d = sc.nextInt()
    (a, b, c, d)
  }

  def dist(x: Int, y: Int): Int = Math.abs(x - y)

  def canTalk(a: Int, b: Int, c: Int, d: Int): Boolean = {
    // AさんとCさんが直接会話できる
    if (dist(a, c) <= d) {
      true
    } else {
      // AさんとBさんが直接会話できる && BさんとCさんが直接会話できる
      dist(a, b) <= d && dist(b, c) <= d
    }
  }

  def main(args: Array[String]): Unit = {
    val (a, b, c, d) = read()
    if (canTalk(a, b, c, d)) {
      println("Yes")
    } else {
      println("No")
    }
  }
}

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

int main(){
	string row;
	cin>>row;
	int f=0,cnt=0;
	//cout<<row.size();
	for(int i=0;i<row.size();i++){
		if(row[i]=='A')f=1;
		if(f==1&&row[i]=='Z'){
			cnt++;
			f=0;
		}
	}
	if(cnt!=0){
	for(int i=0;i<cnt;i++){
		cout<<"AZ";
	}
	cout<<endl;
	}
	else cout<<-1<<endl;
	
	return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int n;
int m[100], a[100], b[100];
int sum[200];

int main() {
	while (cin >> n, n) {
		REP(i, n) scanf("%d %d %d", m + i, a + i, b + i);
		
		vector<int> cx;
		REP(i, n) cx.push_back(a[i]);
		REP(i, n) cx.push_back(b[i]);
		
		sort(ALL(cx));
		cx.erase(unique(ALL(cx)), cx.end());
		
		REP(i, n) a[i] = lower_bound(ALL(cx), a[i]) - cx.begin();
		REP(i, n) b[i] = lower_bound(ALL(cx), b[i]) - cx.begin();
		
		memset(sum, 0, sizeof(sum));
		
		REP(i, n) {
			sum[a[i]] += m[i];
			sum[b[i]] -= m[i];
		}
		
		FOR(i, 1, 200) sum[i] += sum[i - 1];
		
		bool ans = true;
		REP(i, 200) if (sum[i] > 150) ans = false;
		puts(ans ? "OK" : "NG");
	}
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n;cin>>n;
  vector<int> count(n+1);

  rep1(i, n){
    int c = i;
    while(c<=n){
      count[c]++;
      c+=i;
    }
  }

  ll sum = 0;
  rep1(i, n)sum += i*count[i];

  cout<<sum;

  return 0;
}

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

using namespace std;

const int N = 21, mod = 1e9 + 7;
int n, dp[N][1 << N];
bool a[N][N];

bool checkBit (int _mask, int _k) { return (_mask >> _k) & 1; }

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
            if (!i && a[i][j]) dp[0][1 << j] = 1;
        }
    }

    for (int i = 0; i + 1 < n; ++i) {
        for (int mask = 0; mask < (1 << n); ++mask) if (dp[i][mask]) {
            for (int j = 0; j < n; ++j) if (!checkBit(mask, j) && a[i + 1][j]) {
                dp[i + 1][mask | (1 << j)] = (dp[i + 1][mask | (1 << j)] + dp[i][mask]) % mod;
            }
        }
    }

    cout << dp[n - 1][(1 << n) - 1];

    return 0;
}


Measured memory_bytes: 160000
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;

int N;
vector<vector<int>> v(1010);
vector<int> X(1010),mi(1010,0);

bool dfs(int n){
    bool ok = true;
    int s = v[n].size(),sum = 0;
    if(s==0) return true;
    vector<int> x(s,0),m(s,0);
    for(int i=0;i<s;i++){
        int a = v[n][i];
        ok = (ok & dfs(a));
        x[i] = X[a]; m[i] = mi[a];
        sum += X[a]+mi[a];
    }
    if(ok){
        vector<vector<int>> dp1(s,vector<int>(X[n]+1,0)),dp2(s,vector<int>(X[n]+1,0));
        if(x[0]<=X[n]) dp1[0][x[0]] = 1;
        if(m[0]<=X[n]) dp2[0][m[0]] = 1;
        for(int i=1;i<s;i++){
            for(int j=0;j<=X[n];j++){
                if(j+x[i]<=X[n]){
                    dp1[i][j+x[i]] = (dp1[i-1][j] | dp2[i-1][j]);
                }
                if(j+m[i]<=X[n]){
                    dp2[i][j+m[i]] = (dp1[i-1][j] | dp2[i-1][j]);
                }
            }
        }
        int res = -1;
        for(int j=0;j<=X[n];j++) if(dp1[s-1][j] || dp2[s-1][j]) res = j;
        if(res==-1) return false;
        else{
            mi[n] = sum-res;
            return true;
        }
    }else return false;
}

int main(){
    cin >> N;
    int p;
    for(int i=2;i<=N;i++){
        cin >> p;
        v[p].push_back(i);
    }
    for(int i=1;i<=N;i++) cin >> X[i];
    cout << (dfs(1)? "POSSIBLE":"IMPOSSIBLE") << endl;
}

Measured memory_bytes: 2320
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        int x = scanner.nextInt();
        for(int i = x-k+1; i <= x+k-1; i++){
            System.out.print(i + " ");
        }
        System.out.print("\n");
    }
}



Measured memory_bytes: 23252
n = int(input())
a = list(map(int, input().split()))

sunuke = 0
araiguma = sum(a)

min = 10000000000
for i in range(n-1):
    araiguma -= a[i]
    sunuke += a[i]
    if min > abs(sunuke - araiguma):
        min = abs(sunuke - araiguma)

print(min)


Measured memory_bytes: 24952