akhauriyash/Code-Regression huggingface dataset:
n=int(input())
p=list(map(int,input().split()))
moto=[]

for i in range(n):
  moto.append(i+1)

temp=0
for i in range(n):
  if moto[i]!=p[i]:
    temp+=1

print("YES" if temp==0 or temp==2 else "NO")

Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<queue>
#include<algorithm>
#include<cstring>
int main()
{
	int x,y,z;
	int i,n,j;
	scanf("%d%d%d",&x,&y,&z);
i=2*z;
j=i+y;
n=(x-j)/(z+y);
printf("%d\n",n+1);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>

using namespace std;

int main() {
	long long int N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;

	long long int diff = B - A;

	for (int m = 0; m < N; m++) {
		long long int s = C * (N - 1 - m) - D * m;
		long long int l = -1 * C * m + (N - 1 - m) * D;

		if (s <= diff && diff <= l) {
			cout << "YES" << endl;
			return 0;
		}
	}

	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, K;
    cin >> N >> K;

    if (N % K == 0) print(0);
    else print(1);

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	bool f[5]={false};
	char s;
	int n,i;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>s;
		if(s=='P' && f[1]==false)f[1]=true;
		if(s=='W' && f[2]==false)f[2]=true;
		if(s=='G' && f[3]==false)f[3]=true;
		if(s=='Y' && f[4]==false)f[4]=true;
	}
	int sum=0;
	for(i=1;i<5;i++)if(f[i])sum++;
	if(sum==3)cout<<"Three";
	else cout<<"Four";
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

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

int main(){
   int  X;
   cin >> X;
   int g = gcd(X,360);
   cout << 360*X/g/X << endl;
   return 0;
}


Measured memory_bytes: 3556
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        char op = sc.next().charAt(0);
        int b = sc.nextInt();
        
        //三項演算子
        int ans = (op == '+')? a + b : a - b ;
        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
import java.util.Scanner;
import java.util.stream.IntStream;

/**
  * 解説どおりに作成したソースコード<br/>
 * https://atcoder.jp/contests/abc087/submissions/5890910 にも参考
*/
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			UnionFind uf = new UnionFind(n);
			boolean result = true;
			for (int i = 0; i < m; i++) {
				int l = scanner.nextInt() - 1;
				int r = scanner.nextInt() - 1;
				int d = scanner.nextInt();
				if (uf.same(l, r)) {
					if (uf.diff(l, r) != d) {
						result = false;
						break;
					}
				} else {
					uf.unite(l, r, d);
				}
			}
			System.out.println(result ? "Yes" : "No");
		}
	}

	/**
	 * Union Findの実装<br/>
	 * https://atcoder.jp/contests/abc087/submissions/5890910 を参考に作成
	 */
	private static class UnionFind {
		int[] par;
		int[] rank;
		int[] diff_weight;

		UnionFind(int n) {
			par = new int[n];
			rank = new int[n];
			diff_weight = new int[n];
			IntStream.range(0, n).forEach(i -> {
				par[i] = i;
				rank[i] = 0;
				diff_weight[i] = 0;
			});
		}

		int find(int x) {
			if (par[x] == x) {
				return x;
			}
			int r = find(par[x]);
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = r;
		}

		int weight(int x) {
			find(x);
			return diff_weight[x];
		}

		boolean same(int x, int y) {
			return find(x) == find(y);
		}

		void unite(int x, int y, int w) {
			w += weight(x);
			w -= weight(y);
			x = find(x);
			y = find(y);
			if (x == y)
				return;
			if (rank[x] < rank[y]) {
				int tmp = x;
				x = y;
				y = tmp;
				w -= w;
			}
			par[y] = x;
			diff_weight[y] = w;
			return;
		}

		int diff(int x, int y) {
			return weight(y) - weight(x);
		}
	}
}


Measured memory_bytes: 157752
#include <bits/stdc++.h>
using namespace std;       //     ____   _   _  __   __
#define ll long long       //    / ___| | |_| |   / /
const ll INF = 0x3f3f3f3f; //   | |     |  _  |   V /
const ll N   = 1e5 + 5;    //   | |___  | | | |   | |
const ll MOD = 1e9 + 7;    //    ____| |_| |_|   |_|
ll read() {
  ll   x = 0, f = 1;
  char ch = getchar();

  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1; ch = getchar();
  }

  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0'; ch = getchar();
  }
  return x * f;
}

int n;

int main() {
  n = read();
  cout << n * n * n << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>

using namespace std;

int main()
{
	int n;
	while(true)
	{
		cin >> n;
		if(n==0)break;
		vector<string> code(n);
		for(int i=0;i<n;i++)
		{
			string s;
			cin >> s;
			code[i]=s[0];
			for(int j=0;j<s.size()-1;j++)
			{
				if(s[j]=='a' or s[j]=='i' or s[j]=='u' or s[j]=='e' or s[j]=='o')
					code[i]+=s[j+1];
			}
		}

		
		int ans=-1;
		for(int i=0;i<100;i++)
		{
			set<string> st;
			for(int j=0;j<n;j++)
			{
				st.insert(code[j].substr(0,i+1));
			}
			if(st.size()==n)
			{
				ans=i+1;
				break;
			}
		}

		cout << ans << endl;

	}



}



Measured memory_bytes: 3168
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using static System.Console;

namespace MergeSort
{
    internal class Program
    {
        private static int m_count = 0;
        public static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());
            var seq = ReadLine().Split(' ').Select(int.Parse).ToArray();

            MergeSort(seq, 0, n);
            var result = string.Join(" ", seq);
            WriteLine(result);
            WriteLine(m_count);
        }

        private static void Merge(int[] array, int left, int mid, int right)
        {
            var n1 = mid - left;
            var n2 = right - mid;
            var l_arr = new int[n1 + 1];
            var r_arr = new int[n2 + 1];
            for (var i = 0; i < n1; i++)
            {
                l_arr[i] = array[left + i];
            }

            for (var i = 0; i < n2; i++)
            {
                r_arr[i] = array[mid + i];
            }

            l_arr[n1] = int.MaxValue;
            r_arr[n2] = int.MaxValue;
            int j,k,l;
            for (j = 0, k = 0, l = left; l < right; l++)
            {
                m_count++;
                if (l_arr[j] <= r_arr[k])
                {
                    array[l] = l_arr[j];
                    j++;
                }
                else
                {
                    array[l] = r_arr[k];
                    k++;
                }
            }

        }

        private static void MergeSort(int[] seq, int left, int right)
        {
            if (left + 1 < right)
            {
                var mid = (left + right) / 2;
                MergeSort(seq, left, mid);
                MergeSort(seq, mid, right);
                Merge(seq, left, mid, right);

            }

        }
    }
}


Measured memory_bytes: 82660
#include<bits/stdc++.h>
using namespace std;
int p = 1e9+7;
int add(int a,int b){
    int s=(a+b);
    if(s>=p)s-=p;
    return s;
}
int sub(int a,int b){
    int s=(a+p-b);
    if(s>=p)s-=p;
    return s;
}
int mul(int a,int b){
    return (1LL*a*b)%p;
}
int po(int a,int deg){
    
    if(deg==0)return 1;
    int temp = po(a,deg/2);
    temp = mul(temp,temp);
    if(deg%2!=0)temp=mul(temp,a);
    return temp;
    
}
int inv(int n){
    return po(n,p-2);
}
int main(){
	int n,k;cin>>n>>k;
  vector<int >nos(n,0);
  for(int i=0;i<n;i++)cin>>nos[i];
  //for every number find the number of numbers less on both left and right side
  int right=0,left=0;
  for(int i=0;i<n;i++){
  	int count=0;
    for(int j=i-1;j>=0;j--)if(nos[j]<nos[i])count++;
    left=add(left,count);
    count=0;
    for(int j=i+1;j<n;j++)if(nos[j]<nos[i])count++;
    right=add(right,count);
  }
  //cout<<right<<' '<<left<<'\n';
  int invnos=0;
  invnos = add(invnos,mul(right,mul(mul(k,k+1),inv(2)   )  ) );
    invnos = add(invnos,mul(left,mul(mul(k-1,k),inv(2)   )  ) );
  cout<<invnos;
}
//take any number for instance
//which is in the nth iteration
//consider only right
//me  + 2*me + me3 + .. me*k
//now consider left
//me  + .. (k-1)*me;

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

int main(){
    int64_t N, K;
    cin >> N >> K;
    int64_t ok = 0, ng = K+1;
    while(ng-ok>1){
        int64_t mid = (ng+ok)/2;
        int64_t v = mid, s = 0, n = 0;
        while(v && n < N){
            s += v;
            v /= 2;
            n++;
        }
        (s <= K ? ok : ng) = mid;
    }
    cout << ok << endl;
    return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll N, K;
    sll(N);
    sll(K);
    vector<ll> hs(N);
    rep(i, N){
        sll(hs[i]);
    }
    sort(hs.begin(), hs.end());
    ll s = 0;
    rep(i, N-K){
        s += hs[i];
    }

    cout << s <<endl;
}

int main(){
    Main();
}

Measured memory_bytes: 4444
n, y = map(int, input().split())

y //= 1000

if 10 * n < y:
    print(-1, -1, -1)
    exit()

for i in range(n + 1):
    for j in range(n - i + 1):
        otoshidama = 10 * i + 5 * j
        otoshidama_1 = n - i - j if n - i - j > 0 else 0
        otoshidama += otoshidama_1
        if otoshidama == y and i + j + otoshidama_1:
            print(i, j, otoshidama_1)
            exit()
else:
    print(-1, -1, -1)


Measured memory_bytes: 3064
n = int(input())
h = list(map(int,input().split()))
ans = 0
for _ in range(max(h)):
  flag = 1
  for i in range(n):
    if h[i] > 0 and flag:
      h[i] -= 1
      flag = 0
      ans += 1
    elif h[i] > 0:
      h[i] -= 1
    else:
      flag = 1
print(ans)

Measured memory_bytes: 3064
import math
n=int(input())
x=list(map(int, input().split()))
y=list(map(int, input().split()))
print(sum([abs(a-b) for (a,b) in zip(x,y)]))
print(math.sqrt(sum([abs(a-b)**2 for (a,b) in zip(x,y)])))
print(math.pow(sum([abs(a-b)**3 for (a,b) in zip(x,y)]), 1/3))
print((max([abs(a-b) for (a,b) in zip(x,y)])))

Measured memory_bytes: 7820
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
 
ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}
int main(){
    ll n;
    cin>>n;
    ll ans=powmod(10,n)-powmod(9,n)-powmod(9,n)+powmod(8,n);
    ans%=mod;
    ans=(ans+mod)%mod;
    cout<<ans<<"\n";
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int n,m;
  cin  >> n >> m;
  cout << (n-1)*(m-1) << endl;
  return 0;
} 

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
#include<algorithm>

using namespace std;

long double fact(int x){
	long double r=1;
	while(x){
		r*=x--;
	}
	return r;
}

int main(){
	int n,m,l;
	cin>>n>>m>>l;
	double ap[100][51],acp[100][52]={{}};
	double at[100][51];
	for(int i=0;i<n;i++){
		double p,t,v;
		cin>>p>>t>>v;
		for(int j=0;j<=m;j++){
			at[i][j]=l/v+t*j;// time for athlete i to rest for j times
			ap[i][j]=pow(p/100,j)*pow(1-p/100,m-j)*fact(m)/fact(j)/fact(m-j);// probability to rest for j times
			acp[i][j+1]=acp[i][j]+ap[i][j];// sum of probability of less than j rests
		}
	}
	for(int i=0;i<n;i++){
		double a=0;
		for(int j=0;j<=m;j++){
			double c=ap[i][j];
			for(int k=0;k<n;k++){
				if(i!=k){
					int x=upper_bound(at[k],at[k]+m+1,at[i][j]+1e-9)-at[k];
					c*=1-acp[k][x];
				}
			}
			a+=c;
		}
		cout<<fixed<<a<<endl;   
	}
	return 0;
}

Measured memory_bytes: 1416
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>
#include <type_traits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//constexpr long long MOD = 1e9 + 7;
//constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
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; }

ll h, w;
vector<ll> dx = { -1, 0, 1, 0 };
vector<ll> dy = { 0, -1, 0, 1 };


bool isInField(ll x, ll y) {
    bool f = x >= 0 && x < w && y >= 0 && y < h;
    return f;
}

bool compare_first(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.first != y.first) {
        return x.first < y.first;
    }
    else {
        return x.second < y.second;
    }
}

bool compare_second(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.second != y.second) {
        return x.second < y.second;
    }
    else {
        return x.first < y.first;
    }
}

struct {
    bool operator()(pair<string, int> x, pair<string, int> y) const
    {
        return x.second <= y.second && x.first < y.first;
    }
} compare_map;

const ll MAX = 500000000;
const ll MOD = 1000000007;

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

    int a, b, m;
    cin >> a >> b >> m;

    vector<int> fvalue(a), mvalue(b);
    //vector<int> x(m), y(m), c(m);
    
    int minf = INF;
    int minm = INF;
    for (int i = 0; i < a; i++)
    {
        cin >> fvalue[i];
        if (minf > fvalue[i]) {
            minf = fvalue[i];
        }
    }

    for (int i = 0; i < b; i++)
    {
        cin >> mvalue[i];
        if (minm > mvalue[i]) {
            minm = mvalue[i];
        }
    }

    int min = INF;
    for (int i = 0; i < m; i++)
    {
        int x, y, c;
        //cin >> x[i] >> y[i] >> c[i];
        cin >> x >> y >> c;
        x--;
        y--;
        int candidate = fvalue[x] + mvalue[y] - c;
        if (min > candidate) {
            min = candidate;
        }
    }
    min = min > (minf + minm) ? minf + minm : min;

    cout << min << "\n";
    return 0;
}



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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

int n,a[100005][3],dp[100005][3];

int main(){
  cin >> n;
  for(int i=0;i<n;++i){
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }
  dp[0][0]=a[0][0];
  dp[0][1]=a[0][1];
  dp[0][2]=a[0][2];
  for(int i=1;i<n;++i){
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a[i][2];
  }
  cout << max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
  return 0;
}


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

typedef long long LL;
typedef unsigned long long ULL;

template<class T>
inline bool read(T &num) {
    char in;
    bool IsN = false;
    while(in = getchar(), in != '-' && (in < '0' || in > '9'))if(in == EOF)return false;
    in == '-' ? (IsN = true, num = 0) : num = in - '0';
    while(in = getchar(), in >= '0' && in <= '9')num = num * 10 + in - '0';
    return IsN ? num = -num : num, true;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define debug(m) cout<<"nico "<<m<<endl
#define __m  int mid=l+(r-l)/2

const int maxn   = 1e5 + 7;
const int inf    = 2e9 + 7;
const int mod    = 1e9 + 7;

int have[50];
int main() {
#ifdef LOCAL
    freopen("sample.in", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    string now;
    int need;
    for(int i=0;i<n;i++)
    {
        cin>>now;
        for(int j=0;j<now.length();j++)
            have[now[j]-'a']++;
    }
    bool yes=true;
    if(n==1||m==1)
    {
       int a=0,b=0;
       for(int i=0;i<26;i++)
       {
           b+=have[i]/2;
           a+=have[i]%2;
       }
       if(b==(n+m-1)/2&&a==(n+m-1)%2)
                ;
       else 
           yes=false;
    }
    else 
    {
        need=(n/2)*(m/2);
        for(int i=0;i<26&&need;)
        {
            if(have[i]>=4)
            {
                need--;
                have[i]-=4;
            }
            else i++;
        }
        if(need)
            yes=false;
        if(n%2&&m%2)
        {
           need=n/2+m/2;
           for(int i=0;i<26&&need;)
               if(have[i]>=2)
               {
                   have[i]-=2;
                   need--;
               }
                else i++;
           if(need)
               yes=false;
           int temp=0;
           for(int i=0;i<26;i++)
               temp+=have[i];
           if(temp!=1)
               yes=false;
        }
        else if(n%2)
        {
           need=m/2; 
           for(int i=0;i<26&&need;)
               if(have[i]>=2)
               {
                   have[i]-=2;
                   need--;
               }
               else i++;
           if(need)
               yes=false;
        }
        else if(m%2)
        {
            need=n/2;
            for(int i=0;i<26&&need;)
               if(have[i]>=2)
               {
                   have[i]-=2;
                   need--;
               }
               else i++;
           if(need)
               yes=false;
        }
    }
    if(yes)
        puts("Yes");
    else 
        puts("No");
    return 0;
}


Measured memory_bytes: 256
while (n = gets.to_i) > 0
  a = []
  max = false
  n.times{a << gets.to_i}
  n.times{|i|
    num = 0
    (n-i).times{|j|
      max ||= a[j+i]
      num += a[j+i]
      max = num if num > max
    }
  }
  puts max
end

Measured memory_bytes: 8732
#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 100000;
int w[MAX];
int n, k;

bool isOK(int p) {
  int ntrk = 1;
  int curweight = 0;
  for (int i = 0; i < n; i++) {
    if (p < w[i])
      return false;
    if (curweight + w[i] <= p) {
      curweight += w[i];
    } else {
      curweight = w[i];
      ntrk++;
      if (ntrk > k)
        return false;
    }
  }
  return true;
}

int main() {
  cin >> n;
  cin >> k;
  int sum = 0, wmax = 0;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
    if (w[i] > wmax)
      wmax = w[i];
    sum += w[i];
  }

  int left = wmax;
  int rigiht = sum;
  int mid;

  while (left < rigiht) {
    mid = (left + rigiht) / 2;
    if (isOK(mid)) {
      rigiht = mid;
    } else {
      left = mid + 1;
    }
  }

  cout << rigiht << endl;
}

Measured memory_bytes: 3464
/*
 * ----------------------------------------------------------------------------
 (: Bismillahir Rahmanir Rahim :) 
 * File: /root/Programming/Atcoder/A_Circle_Pond.cpp
 * Project: /root/Programming/Atcoder
 * Created Date: Sunday, April 19th 2020, 6:04:13 pm
 * Author: Grim Firefly :)
 * Author Mail : GrimFirefly1@gmail.com
 * -----
 * Last Modified: Sun Apr 19 2020
 * Modified By: Grim Firefly :)
 * -----
 * ----------------------------------------------------------------------------
 */

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

//constant
#define PI acos(-1.0)

//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned un;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef map<int, int> mii;
typedef map<char, char> mcc;
typedef map<char, int> mci;
typedef map<string, int> msi;
typedef map<ll, ll> mll;
typedef set<int> seti;
typedef set<ll> setl;
typedef queue<int> qui;
typedef deque<int> dqui;

//Debug Setting up
#define watch(x) cout << (#x) << " is " << x << endl
#define watchara(wow)  \
    for (auto x : wow) \
    cout << x << " "

//defining something
#define SZ 10000

//main function start

int main()
{
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);

    int x;
    scanf("%d", &x);
    double wow = 2.0 * x * PI;
    printf("%.3lf\n", wow);

    return 0;
}

Measured memory_bytes: 3820
#include<iostream>

using namespace std;

int main(){
    int N; 
    cin >> N;
    bool ok = false;
    for(int i = 1; i<10; i++){
        if(N % i == 0){
            int div = N / i;
            if(div < 10){
                ok = true;
                break;
            }
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        ABC073A s = new ABC073A();
        s.read();
        s.solve();
    }
}

class ABC073A
{
    String N;

    void read()
    {
        Scanner in = new Scanner(System.in);
        N = in.nextLine();
    }

    void solve()
    {
        if (N.contains("9"))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(9999)

n,m=map(int,input().split())

ps = [-1] * n
ps[0] = 0
tmps = {}
for _ in range(m):
    a,b=map(int,input().split())
    ai,bi=a-1,b-1
    if ai not in tmps:
        tmps[ai] = []
    tmps[ai].append(bi)
    if bi not in tmps:
        tmps[bi] = []
    tmps[bi].append(ai)

# print(tmps)

if 0 not in tmps:
    print("No")
    exit()


def puts(ks):
    nks = []
    for k in ks:
        _nks = tmps[k]
        for nk in _nks:
            if ps[nk] == -1:
                ps[nk] = k
                nks.append(nk)
    if nks == []:
        return None
    # puts(nks)
    return nks

ks = [0]
while True:
    nks = puts(ks)
    if nks is None:
        break
    else:
        ks = nks

#print(ps)

if -1 in ps:
    print("No")
    exit()

print("Yes")
for p in ps[1:]:
    print(p+1)

Measured memory_bytes: 39016
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -MOD * MOD;
const long double pi = 3.141592653589793;
int main() { // 問題文はしっかり読め!!!
	string s;
	cin >> s;
	int K;
	cin >> K;
	int n = s.size();
	VVV dp(n + 1, VV(2, V(n + 1, 0)));
	dp[0][0][0] = 1;
	rep(i, n) {
		rep(j, 2) {
			rep(k, n) {
				rep(num, 10) {
					int zero = (num != 0);
					int nj = j;
					if (nj == 0) {
						if (s[i] - '0' < num) continue;
						if (s[i] - '0' > num) nj = 1;
					}
					dp[i + 1][nj][k + zero] += dp[i][j][k];
				}
			}
		}
	}
	cout << dp[n][0][K] + dp[n][1][K] << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	long[] sosu = new long[N+1];
	for(int i = 0; i<=N; i++) {
	    int temp = i;
	    int cnt = 2;
	    while(temp > 1 && cnt<N) {
		while(temp%cnt == 0) {
		    sosu[cnt]++;
		    temp = temp/cnt;
		}
		cnt++;
	    }
	}
	//sosuに全ての個数が入ってる
	long ans = 0;
	HashMap<Integer,Long> map = new HashMap<Integer, Long>();

	long n74,n24,n14,n4,n2;
	for(int i=0; i<=N; i++) {
	    n74 = (map.get(74)==null)?0:map.get(74);
	    n24 = (map.get(24)==null)?0:map.get(24);
	    n14 = (map.get(14)==null)?0:map.get(14);
	    n4 = (map.get(4)==null)?0:map.get(4);
	    n2 = (map.get(2)==null)?0:map.get(2);
	    if(sosu[i] >= 74) map.put(74, n74+1);
	    if(sosu[i] >= 24) map.put(24, n24+1);
	    if(sosu[i] >= 14) map.put(14, n14+1);
	    if(sosu[i] >= 4) map.put(4, n4+1);
	    if(sosu[i] >= 2) map.put(2, n2+1);
	}

	n74 = (map.get(74)==null)?0:map.get(74);
	n24 = (map.get(24)==null)?0:map.get(24);
	n14 = (map.get(14)==null)?0:map.get(14);
	n4 = (map.get(4)==null)?0:map.get(4);
	n2 = (map.get(2)==null)?0:map.get(2);

	ans += n74;
	ans += n24*(n2-1);
	ans += n14*(n4-1);
	ans += (n4*(n4-1))/2 * (n2-2);
	System.out.println(ans);

    }
}

Measured memory_bytes: 21844
import collections


def main():
    N = int(input())
    S = input()
    cnt = collections.Counter(S)
    E_cnt = cnt['E']
    tmp = 0
    if S[0] == 'E':
        E_cnt -= 1
    ans = E_cnt
    for i in range(1, N):
        if S[i] == 'E':
            E_cnt -= 1
        if S[i - 1] == 'W':
            tmp += 1
        ans = min(ans, tmp + E_cnt)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9896
def calc_destination(start, edges, N):
    destination = [-1] * (N + 1)
    destination[start] = 0
    q = [start]
    while len(q) != 0:
        current = q.pop()
        for n in edges[current]:
            if destination[n] != -1:
                continue
            destination[n] = destination[current] + 1
            q.append(n)
    return destination

def main():
    N, u, v = map(int, input().split())

    if u == v:
        print(0)
        return

    edges = [[] for _ in range(N + 1)]
    for _ in range(N - 1):
        A, B = map(int, input().split())
        edges[A].append(B)
        edges[B].append(A)

    tak = calc_destination(u, edges, N)
    aok = calc_destination(v, edges, N)

    result = 0
    for i in range(1, N + 1):
        aoki = aok[i]
        if tak[i] >= aoki:
            continue
        if aoki > result:
            result = aoki
    print(result - 1)

main()


Measured memory_bytes: 29068
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

bool kaibun(string s){
  int n=s.size();
  rep(i,n/2){
    if(s[i]!=s[n-1-i]) return 0;
  }
  return 1;
}

int main(){
  string s; cin>>s;
  int n=s.size();
  string s2=s.substr(0,n/2);
  string s3=s.substr(n/2+1,n/2);
  bool a=kaibun(s);
  bool b=kaibun(s2);
  bool c=kaibun(s3);
  if(a&&b&&c)
  puts("Yes");
  else
  puts("No");

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
const int N=1e5+10;
const int INF=1e9+10;
int n,k,a[N],f[N];
int abs(int x){return x>0?x:-x;}
int min(int l,int r){return l>r?r:l;}
int dp(int pos){
  if(pos<=0)return INF;
  if(pos==1)return 0;
  if(f[pos]!=-1)return f[pos];
  int ans=INF;
  for(int i=1;i<=k;i++)if(pos-i>0)ans=min(ans,dp(pos-i)+abs(a[pos]-a[pos-i]));
  return f[pos]=ans;
}
int main(){
  scanf("%d%d",&n,&k);
  for(int i=1;i<=n;i++)scanf("%d",&a[i]);
  for(int i=1;i<=n;i++)f[i]=-1;
  printf("%d\n",dp(n));
}


Measured memory_bytes: 5632
from itertools import accumulate
import collections
import math

import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n=int(input())
a=list(map(int,input().split()))

acc=list(accumulate(a))
c=collections.Counter(acc)

ans=0
for i,m in c.items():
    if i==0:
        ans+=m
    if m>=2:
        ans+=comb(m,2)
print(ans)


Measured memory_bytes: 41728
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <utility>
#include <vector>

using namespace std;

int fact(int x) { return x == 0 ? 1 : x * fact(x - 1); }

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[i] = {x, y};
  }
  vector<int> p(n);
  iota(p.begin(), p.end(), 0);
  double total = 0;
  for (;;) {
    for (int i = 1; i < p.size(); i++) {
      int xi = v[p[i]].first;
      int yi = v[p[i]].second;
      int xj = v[p[i - 1]].first;
      int yj = v[p[i - 1]].second;
      total += sqrt((xi - xj) * (xi - xj) + (yi - yj) * (yi - yj));
    }
    if (!next_permutation(p.begin(), p.end())) break;
  }
  double avg = total / fact(n);
  printf("%f\n", avg);
  return 0;
}


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

int main(){
  int n,s[100],num,max,min,a;
  
  while(true){
    num =0;
   
  cin>>n;
  if(n == 0)break;

  cin>>s[0];
  max=s[0];
  min=s[0];
  num=s[0];

    
  for(int i=1;i<n;i++){
    cin>>s[i];
    
    if(max<s[i])max=s[i];
    if(min>s[i])min=s[i];
       
    num += s[i];
  }
  a = (num-max-min)/(n-2);

  cout<<a<<endl;
    
  }
  return 0;
}



Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll a[n],sum=0;
  rep(i,n) R a[i];
  rep(i,n) sum+=a[i];
  int cnt=0;
  rep(i,n) {
    if(a[i]>=(double)sum/(4*m)) cnt++; 
  }
  if(cnt>=m) pr("Yes");
  else pr("No");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n,m;
	cin>>n>>m;
	int x=n%m;
	cout<<min(x,m-x);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N, S;
int main() {
	while (cin >> N && N > 0) {
		int sum = 0;
		int largest = 0;
		int smallest = 1000;
		for (int i = 0; i < N; ++i) {
			cin >> S;
			if (largest < S) {
				largest = S;
			} if (smallest > S) {
				smallest = S;
			}
			sum += S;
		}
		cout << ((sum - largest - smallest) / (N - 2)) << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,a[105],b[105],c[105],d[105],ans,lk[105],vis[105];
vector<int> bi[105];
bool dfs(int x)
{
	if (vis[x]) return 0;
	vis[x]=1;
	int i;
	for (i=0;i<bi[x].size();i++)
	{
		if (!lk[bi[x][i]]||dfs(lk[bi[x][i]]))
		{
			//cerr<<bi[x][i]<<' ';
			lk[bi[x][i]]=x;
			return 1;
		}
	}
	return 0;
}
int main()
{
	cin>>n;
	for (i=1;i<=n;i++) cin>>a[i]>>b[i];
	for (i=1;i<=n;i++) cin>>c[i]>>d[i];
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
		{
			if (a[i]<=c[j]&&b[i]<=d[j]) bi[i].push_back(j);
		}
	}
	for (i=1;i<=n;i++)
	{
		memset(vis,0,sizeof(vis));
		if (dfs(i)) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
typedef struct list {
	int val, id;
	struct list *next;
} *list;

list cons (int v, int id, list next) {
	list cell = (list)malloc(sizeof(struct list));
	cell->val = v;
	cell->id = id;
	cell->next = next;
	return cell;
}

edge_color[100001], max_color;
list node_edges[100001];

void add_edge (int id, int a, int b) {
	node_edges[a] = cons(b, id, node_edges[a]);
	node_edges[b] = cons(a, id, node_edges[b]);
}

void solve (int node_id, int c) {
	list l = node_edges[node_id];
	int i = c == 1 ? 2 : 1;
	
	while (l) {
		if (!edge_color[l->id]) {
			edge_color[l->id] = i;
			if (max_color < i) max_color = i;
			solve(l->val, i);
			i = c == i + 1 ? i + 2 : i + 1;
		}
		l = l->next;
	}
}

int main (void) {
	int n, a, b, i;
	
	scanf("%d", &n);
	
	for (i = 0; i < n - 1; i++) {
		scanf("%d %d", &a, &b);
		add_edge(i, a - 1, b - 1);
	}
	
	solve(0, 0);
	
	printf("%d\n", max_color);
	for(i = 0; i < n - 1;i++) {
		printf("%d\n", edge_color[i]);
	}
}


Measured memory_bytes: 7808
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		String S = sc.next();
		long K = sc.nextLong() - 1;
		Pattern pattern = Pattern.compile("[2-9]");
		Matcher matcher = pattern.matcher(S);
		if (!matcher.find()) {
			System.out.println(1);
			return;
		}
		int first = matcher.start();
		if (K < first) {
			System.out.println(1);
		} else {
			System.out.println(S.charAt(first));
		}
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
const int mod=pow(10,9)+7;
int main() {
	// your code goes here
	int n,W;
	cin>>n>>W;
	vector<int> w(n),v(n);
	for(int i=0;i<n;i++)cin>>w[i]>>v[i];
	int totval=0;
	for(int x:v)totval+=x;
	vector<ll> dp(totval+1,1LL*pow(10,18));
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=totval-v[i];j>=0;j--)
		{
			dp[j+v[i]]=min(dp[j]+w[i],dp[j+v[i]] );
		}
	}
	ll ans=0;
	for(int i=totval;i>=0;i--)
	{
		if(dp[i]<=W)
		{
			ans=max(ans,1LL*i);
		}
	}
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 4064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
//#define fill(x,y) memset(x,y,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef pair<int, int>P;

int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


const int MAX = 500010;
const int MOD = (ll)1e9+7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;






signed main() {
	map<int, int>mp;
	int N; string S;
	cin >> N;
	cin >> S;
	REP(i, N) {
		mp[S[i] - 'a']++;
	}
	ll ans = 1;
	for (auto x : mp) {
		ans *= (x.second + 1)%MOD;
		ans%=MOD;
	}
	ans--;
	print(ans%MOD);
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int dsum, n, m, d[100001], to[10000];

int dist(int x, int y) { //x kara y
	if (x > y) swap(x, y);
	return min(y - x, x + dsum - y);
}

int main() {
	while (true) {
		cin >> dsum;
		if (dsum == 0) break;
		cin >> n >> m;
		d[0] = 0;
		FOR(i, 1, n) scanf("%d", &d[i]);
		d[n] = dsum;
		REP(i, m) scanf("%d", &to[i]);
		sort(d, d + n);
		sort(to, to + m);

		int pos = 0;
		long long ans = 0;
		REP(i, m) {
			while (!(d[pos] <= to[i] && d[pos + 1] >= to[i]))
				pos = (pos + 1) % n;

			int d1 = dist(d[pos], to[i]);
			int d2 = dist(d[(pos + 1) % n], to[i]);
			ans += min(d1, d2);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1684
#coding : utf-8

N, M = map(lambda x: int(x), input().split(" "))
A = list(map(lambda x: int(x), input().split(" ")))

total = 0

for a in A:
	total += a

m = 0

for a in A:
	if a * 4 * M >= total:
		m += 1

if m >= M:
	print("Yes")
else:
	print("No")



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<ext/numeric>

using namespace std;
using namespace __gnu_cxx;

const int MAX = 2e5 + 5, MOD = 1e9 + 7, oo = 1 << 30;

#define CLR(a,v) memset(a,v,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
typedef vector<int> vi;

char s[MAX];
int n, path[MAX], dp[MAX], memo[MAX];
vi occ[26];

int solve(int i) {
	if (i == n + 1)
		return memo[i] = 0;
	int &ret = memo[i];
	if (~ret)
		return ret;
	ret = oo;
	for (int j = 0; j < 26; ++j) {
		int reqIdx = i;
		if (s[i] == j + 'a')
			++reqIdx;
		int idx = lower_bound(all(occ[j]), reqIdx) - occ[j].begin();
		ret = min(ret, solve(occ[j][idx]) + 1);
	}
	return ret;
}

void buildPath(int i) {
	if (i == n + 1)
		return;
	int &mn = memo[i];
	for (int j = 0; j < 26; ++j) {
		int reqIdx = i;
		if (s[i] == j + 'a')
			++reqIdx;
		int idx = lower_bound(all(occ[j]), reqIdx) - occ[j].begin();
		if (memo[occ[j][idx]] + 1 == mn) {
			cout << char(j + 'a');
			buildPath(occ[j][idx]);
			break;
		}
	}
}

int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for (int i = 1; i <= n; ++i)
		occ[s[i] - 'a'].push_back(i);
	for (int i = 0; i < 26; ++i)
		occ[i].push_back(n + 1);
	CLR(memo, -1);
	solve(0);
	buildPath(0);
}


Measured memory_bytes: 2560
n,m = list(map(int, input().split()))
a = []
b = []
result = []
row_sum = 0

for i in range(n):
    l = list(map(int, input().split()))
    a.append(l)

for i in range(m):
    b.append(int(input()))

for row in a:
    for i,num in enumerate(row):
        row_sum += num * b[i]
    print(row_sum)
    row_sum = 0

Measured memory_bytes: 7912
import numpy as np

n, m, k = map(int, input().split())
a = np.array([0] + input().split(), dtype=int)
b = np.array([0] + input().split(), dtype=int)

cum_a = a.cumsum()
cum_b = b.cumsum()

maximum = 0
j = 0
for i in range(n, -1, -1):
  rest = k - cum_a[i]
  if rest < 0:
    continue
  while rest - cum_b[j] >= 0:
    j += 1
    if j > m:
      break
  j -= 1
  maximum = max(maximum, i + j)
print(maximum)

Measured memory_bytes: 56848
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define test        int t;cin>>t;while(t--)
#define REP(i,a,b)  for(int i=a,i<=b;i++)
#define MAXN        200001

int32_t main()
{
    
    int n;cin>>n;
    int arr[n],sum=0;

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

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

        temp+=arr[i];
        val+=((arr[i])*((sum-temp)%mod))%mod;
    }

    cout<<val%mod<<endl;

    return 0;
}

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

int main() {
  int N,A,B;
    cin>>N>>A>>B;
  if(A<B){
    cout<<A;
  }
  else{
    cout<<B;
  }
 int sum=A+B-N;
  if(sum<0){
    cout<<" "<<0<<endl;
  }
  else{
    cout<<" "<<sum<<endl;
  }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n;
  	cin >> n;
  	vector<int> vec(n);
  	
  	for(int i=0; i<n; i++){
      cin >> vec.at(i);
    }
  
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  int sum_a = 0;
  int sum_b = 0;
  
  for(int i=0;i<n;i+=2){
    sum_a += vec[i];
  }
  
  for(int i=1; i<n; i+=2){
   	sum_b += vec[i];
  }
  cout << sum_a -sum_b << endl;
}

Measured memory_bytes: 256
N, K = map(int,input().split())
l=list(range(1,N+1))
for i in range(K):
  d=int(input())
  s = input().split()
  for j in range(d):
    l[int(s[j])-1]=0
num=0
for i in range(N):
  if l[i]!=0:
    num=num+1
print(num)    

Measured memory_bytes: 9204
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  string ans = "No";
  int n, m; cin >> n >> m;
  if(n == m) ans = "Yes";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,w;
	cin>>h>>w;
	char a[h][w];
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		cin>>a[i][j];
	}
	for(int i=-1;i<=h;i++)
	{
		if(i==-1)
		{
			for(int j=0;j<=w+1;j++)
			cout<<'#';
			cout<<endl;
		}
		else if(i<h)
		{
			for(int j=-1;j<=w;j++)
			{
				if(j==-1)
				cout<<'#';
				else if(j<w)
				cout<<a[i][j];
				else if(j==w)
				{
					cout<<'#';
					break;
				}
			}
			cout<<endl;
		}
		else if(i==h)
		{
			for(int j=0;j<=w+1;j++)
			cout<<'#';
			break;
		}
	}
}

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

void insertionSort(vector<int> &a, int g, int &c) {
    for(int i=g;i<a.size();i++){
        int v=a[i],j=i-g;
        while(j>=0&&a[j]>v){
            a[j+g]=a[j];
            j=j-g;
            c++;
        }
        a[j+g]=v;
    }
}
void shellSort(vector<int> &a, vector<int> &g, int &c) {
    int h=1;
    for(;h*3+1<a.size();)h=h*3+1;
    for(;h>0;h=(h-1)/3){
        g.push_back(h);
        insertionSort(a,h,c);
    }
}
int main() {
    int i,m,n,c=0;
    cin>>n;
    vector<int> a(n),g;
    for(i=0;i<n;i++) cin>>a[i];

    shellSort(a,g,c);
    m=g.size();

    cout<<m<<endl;
    for(i=0;i<m-1;i++) cout<<g[i]<<" ";
    cout<<g[m-1]<<endl;
    cout<<c<<endl;
    for(i=0;i<n;i++) cout<<a[i]<<endl;
    return 0;
}


Measured memory_bytes: 6804
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] a) {
		int N = sc.nextInt();
		int[][] g = new int[N][N];
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				g[i][j] = sc.nextInt();
			}
		}
		long ans = 0;
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < i; ++j) {
				ans += Math.min(g[i][j], g[j][i]);
			}
		}
		System.out.println(ans);
	}

}

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

using namespace std;

typedef long long ll;

ll dp[51][2501];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a;
    cin >> n >> a;
    vector<ll> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = n; j > 0; j--) {
            for (int k = a * n; k >= x[i]; k--) {
                dp[j][k] += dp[j - 1][k - x[i]];
            }
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) ans += dp[i][a * i];
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1280
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

void inverse(ll n,vector<ll> &inv){
    //要素数:n+1 (0~n)
    inv[0]=1;
    inv[1]=1;
    for(ll i=2;i<=n;i++){
        inv[i]=(MOD-inv[MOD%i]*(MOD/i))%MOD;
    }
}

void inverse_u(ll n,vector<ll> &inv){
    //要素数:n+1 (0~n)
    for(ll i=2;i<=n;i++){
        inv[i]=(inv[i]*inv[i-1])%MOD;
    }
}

void factorial(ll n,vector<ll> &fac){
    //要素数:n+1 (0~n)
    fac[1]=1;
    for(ll i=2;i<=n;i++){
        fac[i]=(fac[i-1]*i)%MOD;
    }
}

ll nCr(ll n,ll r,vector<ll> &inv,vector<ll> &fac){
    return fac[n]*inv[r]%MOD*inv[n-r]%MOD;
}

int main(){
    ll n,m,M,ans=1; cin>>n>>m;
    vector<ll> inv(n+51,0),fac(n+51,0);
    inverse(n+50,inv); inverse_u(n+50,inv);
    factorial(n+50,fac);
    map<ll,ll> s;
    M=m;
    for(ll i=2;i*i<=M;i++){
        while(m%i==0){
            m/=i;
            if(s.count(i)) s[i]++;
            else s[i]=1;
        }
    }
    if(m>1) s[m]=1;
    for(auto q:s){
        ll a,p;
        tie(a,p)=q;
        ans=(ans*nCr(n-1+p,p,inv,fac))%MOD;
    }
    cout<<(MOD+ans)%MOD<<endl;
}

Measured memory_bytes: 1792
N = int(input())
S = []
for i in range(N):
    S.append(int(input()))
s = sum(S)
S1 = []
for i in range(N):
    if S[i]%10 != 0:
        S1.append(S[i])
if s % 10 != 0:
    print(s)
else:
    if S1:
        print(s-min(S1))
    else:
        print(0)

Measured memory_bytes: 3064