akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

const int N = 300;
string arr[N];
int res[N][N];

void fill(int ax, int ay, int bx, int by, int v) {
	for (int x = ax; x <= bx; ++x) {
		for (int y = ay; y <= by; ++y) {
			res[y][x] = v;
		}
	}
}

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

	int h, w, k;
	cin >> h >> w >> k;
	for (int y = 0; y < h; ++y) cin >> arr[y];

	int ay = 0;
	for (int y = 0; y < h; ++y) {
		vector<int> xs;
		for (int x = 0; x < w; ++x) {
			if (arr[y][x] == '#') xs.push_back(x);
		}
		if (! xs.empty()) {
			int by = (k <= xs.size() ? h-1 : y);

			int px = 0;
			for (int i = 0; i < xs.size(); ++i) {
				if (i+1 == xs.size()) {
					fill(px, ay, w-1, by, k);
				} else {
					fill(px, ay, xs[i], by, k);
				}
				px = xs[i] + 1;
				--k;
			}
			ay = by + 1;
		}
	}

	for (int y = 0; y < h; ++y) {
		for (int x = 0; x < w; ++x) {
			cout << res[y][x] << ' ';
		}
		cout << '\n';
	}
}


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

int main()
{
	int ans;
	for(int i = 1; i <= 5; i++)
	{
		int xi;
		scanf("%d", &xi);
		
		if(xi == 0)
			ans = i;
	}
	
	printf("%d", ans);
}


Measured memory_bytes: 3688
N = int(input())
K = int(input())

A = []

for n in range(N+1):
  ans = 1
  nm_A = n
  nm_B = N - n
  
  if nm_A > 0:
    for a in range(nm_A):
      ans *= 2
  
  if nm_B > 0:
    for b in range(nm_B):
      ans += K
  
  A.append(ans)

print(min(A))

Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)

func gets() string {
	sc.Scan()
	return sc.Text()
}

func toInt(value string) int {
	num, _ := strconv.Atoi(value)
	return num
}

func splitWithInt(value string) []int {
	vals := strings.Split(value, " ")
	nums := make([]int, len(vals))
	for index, elem := range vals {
		nums[index] = toInt(elem)
	}
	return nums
}

// B
func main() {
	var inputs []int
	inputs = splitWithInt(gets())
	N, M := inputs[0], inputs[1]
	countArray := make([]int, M)
	for i:= 0; i < N; i++ {
		inputs = splitWithInt(gets())[1:]
		for _, elem := range inputs {
			countArray[elem - 1]++
		}
	}

	countKinds := 0
	for _, elem := range countArray {
		if elem == N { countKinds++ }
	}

	fmt.Println(countKinds)
}


Measured memory_bytes: 640
using System;

namespace ABC089_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array = Console.ReadLine().Split(' ');
            int a = int.Parse(array[0]);
            
            
                Console.WriteLine(a / 3);
            

                 
            
          
        }
    }
}


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

int main(){
    int n, c[20], v[20];
    int i, X=0, Y=0;

    scanf("%d", &n);

    for(i=0; i<n; i++)
        scanf("%d", &v[i]);
    
    for(i=0; i<n; i++)
        scanf("%d", &c[i]);
    

    for(i=0; i<n; i++){
        if(v[i] > c[i]){
            X += v[i];
            Y += c[i];
        }
    }

    printf("%d\n", abs(X-Y));

    return 0;
}

Measured memory_bytes: 128
//name-afrin sultana
#include<stdio.h>
int main()
{
   int A,B,X,X1;
   scanf("%d%d",&A,&B);
   if (B%A==0)
   {
       X=(A+B);
       printf("%d",X);
   }
   else
    {
     X1=(B-A);
   printf("%d",X1);
    }
}
//name-afrin sultana


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

void EducationalDP_D()
{
	int N, W;
	cin >> N >> W;
	vector<int> w(N);
	vector<int> v(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> w[i] >> v[i];
	}
	vector<vector<ll> > value(N, vector<ll>(W + 1));
	value[0][w[0]] = v[0];
	for (int i = 1; i < N; ++i)
	{
		for (int j = 0; j <= W; ++j)
		{
			value[i][j] = max(j > w[i] ? value[i - 1][j - w[i]] + v[i] : 0, value[i - 1][j]);
		}
	}
	ll ret = 0;
	for (int j = 0; j <= W; ++j)
		ret = max(ret, value[N - 1][j]);
	cout << ret << endl;
}
int main()
{
	EducationalDP_D();
	return 0;
}

Measured memory_bytes: 79488
#include<stdio.h>
int main(void)
{
    char s[10];
    scanf("%s",s);

    int i, j, l = 0;
    for (i = 0; i < 10; ++i)
    for (j = i; j < 10; ++j){
        if (s[j] != 'A' && s[j] != 'T'
                && s[j] != 'C' && s[j] != 'G')
            break;
        const int len = j - i + 1;
        l = len > l ? len : l;
    }

    printf("%d", l);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int strAB(char[],int);
int main(void){
  int N,i,len,a=0,b=0,ab=0,c=0;
  char S[12];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s",S);
    len=strlen(S);
    c+=strAB(S,len);
    if(S[0]=='B' && S[len-1]=='A'){
      ab++;
      a++;
      b++;
    }else if(S[0]=='B' && S[len-1]!='A'){
      b++;
    }else if(S[0]!='B' && S[len-1]=='A'){
      a++;
    }else{
      continue;
    }
  }
  if(ab==b && b==a && a!=0){
    printf("%d\n",c+ab-1);
  }else if(a>b){
    printf("%d\n",c+b);
  }else{
    printf("%d\n",c+a);
  }
  return 0;
}
int strAB(char x[],int y){
  int t=0,j=0;
  while(j<y-1){
    if(x[j]=='A' && x[j+1]=='B'){
      t++;
    }
    j++;
  }
  return t;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <deque>

using namespace std;

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

    vector<int> A(N);
    for (auto& a: A) {
        cin >> a;
    }

    vector<int> M(N);
    for (int i=0;i<N;++i) {
        M[0] += (i%2==0 ? A[i] : -A[i]);
    }

    for (int i = N-1;i > 0;--i) {
        M[i] = 2 * A[i] - M[(i+1)%N];
    }

    for (int i=0;i<N;++i) {
        cout << M[i];
        if (i < N-1) cout << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2048
/*
Author : farhan132
*/
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef pair < ll , pair < ll , ll > > cm;

#define ff first
#define ss second
#define pb push_back
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)
#define clean cout.flush()

const ll mod = (ll)1e9+7;
const ll maxn = (ll)1e5+10;
const int nnn = 664579+500;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};

//ofstream wr ("txt.txt");
//ifstream rr ("input.txt");


void solve(){
	
	ll n , k;
	cin >> n >> k;
	ll a[n+5];
	f1(n) cin >> a[i];
	ll lo = 0, hg = 1e9;
	ll ans = hg;
	while(lo <= hg){
		ll mid = (lo+hg)/2;
		ll tot = 0;
		if(mid != 0){
		for(ll i = 1; i <= n; i++){
			if(a[i] <= mid) continue;
			tot += ((a[i]/mid) + (a[i]%mid != 0))-1 ; 
		}
     	}else{
     	  
		   for(ll i = 1; i <= n; i++){
		   	if(a[i]!=0) tot  = INF;
		   }	
     		
		}
     	
		if(tot <= k) ans = min(ans , mid) , hg = mid-1;
		else lo = mid+1;
	}
	cout << ans;
 	return;
}

int main() {
   
   ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
   //freopen("input.txt", "r", stdin);
   //freopen("output.txt", "w", stdout);
    ll T;
    T=1;
    //cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    
    //work();
    while(T--){
    	//cout << "Case #" << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
	
    return 0;
}
/*


*/

Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
int N, M;
void func()
{
    cin >> N;
    int ans = (N / 500) * 1000 + (N % 500) / 5 * 5;
    cout << ans << endl;
}
int main()
{
    func();
}

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

#define MAX_W 100000

int dp[MAX_W], N, W, v[10000], w[10000];

int main() {
	cin >> N >> W;
	for (int i = 0; i < N; i++) { cin >> v[i] >> w[i]; }
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < W; j++) {
			dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
		}
	}
	int maxn = 0;
	for (int i = 0; i <= W; i++) { maxn = max(maxn, dp[i]); }
	cout << maxn << endl;
	return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 1000000007;

int N, M;
ll p2[310];
bool e[16][16];
ll dp[1 << 15];

int main() {
	p2[0] = 1;
	for (int i = 1; i < 310; ++i) {
		p2[i] = p2[i-1] * 2 % MOD;
	}

	cin >> N >> M;

	rep(i, M) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		e[x][y] = 1;
	}

	dp[0] = 1;

	for (int i = 1; i < (1 << N); ++i) {
		for (int j = i; j >= 0; --j) {
			j &= i;

			int nx = j ^ i;
			if (dp[j] == 0 || ((nx & 1) && (nx & 2))) {
				continue;
			}

			int rem = ((1 << N) - 1) ^ i;

			ll way = 1;

			rep(k, N) {
				if ((rem >> k) & 1) {
					int cnt = 0;
					rep(t, N) if ((nx >> t) & 1) {
						if (e[k][t]) {
							++cnt;
						}
					}
					way = way * (p2[cnt] - 1) % MOD;
				} else if ((j >> k) & 1) {
					int cnt = 0;
					rep(t, N) if ((nx >> t) & 1) {
						if (e[k][t]) {
							++cnt;
						}
					}
					way = way * p2[cnt] % MOD;	
				}
			}

			dp[i] = (dp[i] + dp[j] * way) % MOD;
		}
	}


	cout << dp[(1 << N) - 1] << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  char ans,notone;
  long k,nagasa,basyo;
  cin>>str>>k;
  nagasa=str.size();
  basyo=0;
  for(int i=0; i<nagasa; i++){
    if(str.at(i)!='1'){
      basyo=i+1;
      notone=str.at(i);
      break;
    }
  }
  if(basyo==0||k<basyo){
    ans='1';
  }
  else {
    ans=notone;
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long n=1,k,num = 7;
	cin>>k;
	while(num%k!=0)
	{
		long a = num/k;
		num=num-a*k;		
		num = num*10+7;
		n++;				
		if(n>10000000)
		{
			n=-1;
			break;
		}
	}		
	cout<<n;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001




int main() {
    int A, B; cin >> A >> B;
    
    int sum = 1;
    int cnt = 0;
    while(sum<B){
        sum--;
        sum += A;
        cnt++;
    }
    
    cout << cnt << endl;
    return 0;
}



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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  cout << min(A, B) + min(C, D) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

K = int(input())
S = input()

len_S = len(S)

#MOD = 10 ** 9 + 7
SIZE = 2 * 10 ** 6 + 100
g1, g2, inv = [1, 1], [1, 1], [0, 1]
for i in range(2, SIZE + 1):
    g1.append((g1[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    g2.append((g2[-1] * inv[-1]) % MOD)
def nCr(n, r):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % MOD

answer = 0
for i in range(K + 1):
    answer += pow(25, i, MOD) * nCr(len_S - 1 + i, i) * pow(26, K - i, MOD)
    answer %= MOD

print(answer)

Measured memory_bytes: 186528
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
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; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    ll a,b,c,k;
    cin >> a >> b >> c >>k;
    ll ans = 0;
    ll x = min(a,k);
    k -= x;
    ans += x*1;
    ll y = min(b,k);
    k -= y;
    ll z= min(c,k);
    k -= z;
    ans += z*(-1);
    cout << ans << endl;

}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#define ll long long
#define MOD 1000000007
using namespace std;

int main(){
	int x,y,i;
	cin >> x >> y;
	for(i=0; i<=x; i++){
		int j=x-i;
		if(i*2+j*4 == y){
			cout << "Yes" << endl;
			break;
		}
	}
	if(i==x+1){
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<set>
#include<map>

using namespace std;

/*sqrt<3>(NMAX)==100*/

int Nkake[100+1];
int g[1000001]={0};
int k[1000001]={0};

int main(){

	int N;
	
	for(int i=1;i<=200;i++){
		Nkake[i]=i*(i+1)*(i+2)/6;
	}

	for(int i=0;i<=1000000;i++){
		for(int j=1;j<200;j++){
			if(i+Nkake[j]<=1000000){
				if(g[Nkake[j]+i]==0||g[Nkake[j]+i]>g[i]+1) g[Nkake[j]+i]=g[i]+1;
			}
		}
	}

	for(int i=0;i<=1000000;i++){
		for(int j=1;j<200;j++){
			if(Nkake[j]%2==1&&i+Nkake[j]<=1000000){
				if(k[Nkake[j]+i]==0||k[Nkake[j]+i]>k[i]+1) k[Nkake[j]+i]=k[i]+1;
			}
		}
	}

	while(1){
		cin>>N;
		if(N==0) break;

		cout<<g[N]<<" "<<k[N]<<endl;
	}
}

Measured memory_bytes: 8972
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n;
  cin>>n;
  cout<<n/3<<endl;


   return 0;
}


Measured memory_bytes: 768
#include<stdio.h>

int main(){
	int i,n,f=-1;
	long long l,a[100000];
	scanf("%d%d",&n,&l);
	for(i=0;i<n;i++)scanf("%lld",&a[i]);
	for(i=0;i<n-1;i++){
		if(l<=a[i]+a[i+1]){
			//puts("Possible");
			f=i;
			//break;
		}
	}
	if(f==-1){
		puts("Impossible");
		return 0;
	}else puts("Possible");
	for(i=0;i<f;i++)printf("%d\n",i+1);
	for(i=n-2;i>=f;i--)printf("%d\n",i+1);
	return 0;
}

Measured memory_bytes: 1536
#include <cstdio>

int main(){
	char x[1001];
	while(1){
		int U=0, i=0;
	
		scanf("%s", x);
		if(x[0]=='0') break;
	
		while(x[i]!='\0'){
			U += x[i]-'0';
			++i;
		}
		
		printf("%d\n", U);
	}
	
	return 0;
}



Measured memory_bytes: 2704
n = int(input())
s = ['']*n
ans='Yes'

for i in range(n):
    instr = str(input())
    if i!=0:
        if s[i-1][len(s[i-1])-1]!=instr[0]:
            ans = 'No'
        if instr in s:
            ans = 'No'
    s[i]=instr
print(ans)

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

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
	int n; cin >> n;
  	int a[n], b[n], c[n];
  	for(int i = 0; i < n; ++i) cin >> a[i] >> b[i] >> c[i];
 	int dp[3][n]; memset(dp, 0, sizeof dp);
  	dp[0][0] = a[0]; dp[1][0] = b[0]; dp[2][0] = c[0];
  	for(int i = 1; i < n; ++i) {
    	dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + a[i];
      	dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + b[i];
      	dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + c[i];
    }
  	cout << max(dp[0][n - 1], max(dp[1][n - 1], dp[2][n - 1]));
} //farewell, until we meet again..


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<unordered_map>
#include<string>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int N= 1e5 + 10;
inline void fastio()
{ 
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
 

int main()
{
    ll a, b, c, k, ans=0;
    cin >> a >> b >> c >> k;
    ans+=(k>=a)?a:k;
    ans -= (k - a - b >= 0) ? (k - a - b) : 0;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
def main():
    N = int(input())
    S = input()
    cumsum = [(0, 0)] * (N+1)
    for i in range(N):
        e, w = cumsum[i]
        if S[i] == 'E':
            e += 1
        else:
            w += 1
        cumsum[i+1] = (e, w)
    ans = float("inf")
    for i in range(N):
        cost = cumsum[i][1] + cumsum[N][0] - cumsum[i+1][0]
        ans = min(ans, cost)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 50140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static bool Solve(int N, int[] L)
        {
            Array.Sort(L);
            return L.Last() < L.Take(N - 1).Sum();
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            int[] L = ReadInts();
            Console.WriteLine(Solve(N, L) ? "Yes" : "No");
        }
    }
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> A[n+1];
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        A[a].push_back(b);
        A[b].push_back(a);
    }
    queue<int> nodes;
    vector<bool> visited(n+1,false);
    vector<int> sign(n+1,0);
    nodes.push(1);
    visited[1] = true;
    while (!nodes.empty()) {
        int node = nodes.front();
        nodes.pop();
        for (auto u : A[node]) {
            if (visited[u]) continue;
            visited[u] = true;
            sign[u] = node;
            nodes.push(u);
        }
    }
    cout << "Yes\n";
    for (int i = 2; i < n+1; i++) {
        cout << sign[i] << "\n";
    }
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll P, Q, R;
    cin >> P >> Q >> R;
    cout << min({P + Q, Q + R, R + P}) << endl;
    return 0;
}


Measured memory_bytes: 3544
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define boostIO                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, b, a) for (int i = b; i >= a; i--)
#define sz(v) (int)(v.size())
#define all(v) v.begin(), v.end()
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define trav(a, x) for (auto &a : x)
#define pb push_back
#define fi first
#define se second
#define int long long
#define mod 1000000007
#define rem 998244353
#define maxn 300005
const int INF = 1e18;
typedef pair<int, int> pii;


signed main() {
    boostIO;
    int n;
    cin >> n;
    int a[n], sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        sum -= a[i];
        ans += (((a[i] % mod) * (sum % mod)) % mod);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}
// XD ;;

Measured memory_bytes: 5200
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        long a = fs.nextLong();
        long b = fs.nextLong();
        long x = fs.nextLong();
        long small = (a+x-1)/x;
        long big = b/x;
        if(big>=small){
            System.out.println(big-small+1);
        }else{
            System.out.println(0);
        }
    }
    static class FastScanner {
            private final InputStream in = System.in;
            private final byte[] buffer = new byte[1024];
            private int ptr = 0;
            private int buflen = 0;
            private boolean hasNextByte() {
                if (ptr < buflen) {
                    return true;
                }else{
                    ptr = 0;
                    try {
                        buflen = in.read(buffer);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    if (buflen <= 0) {
                        return false;
                    }
                }
                return true;
            }
            private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
            private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
            public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
            public String next() {
                if (!hasNext()) throw new NoSuchElementException();
                StringBuilder sb = new StringBuilder();
                int b = readByte();
                while(isPrintableChar(b)) {
                    sb.appendCodePoint(b);
                    b = readByte();
                }
                return sb.toString();
            }
            public long nextLong() {
                if (!hasNext()) throw new NoSuchElementException();
                long n = 0;
                boolean minus = false;
                int b = readByte();
                if (b == '-') {
                    minus = true;
                    b = readByte();
                }
                if (b < '0' || '9' < b) {
                    throw new NumberFormatException();
                }
                while(true){
                    if ('0' <= b && b <= '9') {
                        n *= 10;
                        n += b - '0';
                    }else if(b == -1 || !isPrintableChar(b)){
                        return minus ? -n : n;
                    }else{
                        throw new NumberFormatException();
                    }
                    b = readByte();
                }
            }
            public int nextInt() {
                long nl = nextLong();
                if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
                return (int) nl;
            }
            public double nextDouble() { return Double.parseDouble(next());}
        }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};

int main()
{
    int n,sum=0;cin>>n;
    int a[n];REP(i,n)cin>>a[i];
    rep(i,1,n-1)if(max(a[i-1],a[i+1])>a[i]&&min(a[i-1],a[i+1])<a[i])sum++;
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef pair<int, int> P;
#define INF 1e9 + 7

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

    int n;
    cin >> n;
    int a[2][n];
    rep(i,2){
        rep(j,n){
            cin >> a[i][j];
        }
    }
    
    int ans = 0;
    rep(i,n){
        int now = 0;
        rep(j,i+1){
            now += a[0][j];
        }
        for(int j=i; j<n; j++){
            now += a[1][j];
        }
        // cout << now << endl;
        ans = max(ans, now);
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    vi64 b(7);
    forn(i, 7) cin >> b[i];
    i64 ans = 0;
    forn(k, 2) {
        vi64 a = b;
        i64 res = 0;
        if (k) {
            if (!a[3] || !a[4] || !a[0]) continue;
            --a[3]; --a[4]; --a[0];
            res += 3;
        }
        res += a[1];
        res += (a[3] / 2) * 2; a[3] %= 2;
        res += (a[4] / 2) * 2; a[4] %= 2;
        res += 2 * (a[0] / 2);
        uax(ans, res);
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

class DisjointSet
{
public:
  vector<int> rank, p;

  DisjointSet() {}
  DisjointSet(int size)
  {
    rank.resize(size, 0);
    p.resize(size, 0);
    for (int i = 0; i < size; i++)
      makeSet(i);
  }

  void makeSet(int x)
  {
    p[x] = x;
    rank[x] = 0;
  }

  bool same(int x, int y)
  {
    return findSet(x) == findSet(y);
  }

  void unite(int x, int y)
  {
    link(findSet(x), findSet(y));
  }

  void link(int x, int y)
  {
    if (rank[x] > rank[y])
    {
      p[y] = x;
      return;
    }
    p[x] = y;
    if (rank[x] == rank[y])
      rank[y]++;
  }

  int findSet(int x)
  {
    if (x != p[x])
      p[x] = findSet(p[x]);
    return p[x];
  }
};

class Edge
{
public:
  int source, target, cost;
  Edge(int source = 0, int target = 0, int cost = 0) : source(source), target(target), cost(cost) {}
  bool operator<(const Edge &e) const
  {
    return cost < e.cost;
  }
};

int kruskal(int N, vector<Edge> edges)
{
  int totalCost = 0;
  sort(edges.begin(), edges.end());
  DisjointSet ds = DisjointSet(N + 1);

  for (int i = 0; i < N; i++)
    ds.makeSet(i);

  int source, target;
  for (int i = 0; i < edges.size(); i++)
  {
    Edge e = edges[i];
    if (!ds.same(e.source, e.target))
    {
      totalCost += e.cost;
      ds.unite(e.source, e.target);
    }
  }
  return totalCost;
}

int main()
{
  int64_t N, x, y;
  cin >> N;
  vector<pair<int64_t, int64_t>> X(N), Y(N);
  for (int i = 0; i < N; i++)
  {
    cin >> x >> y;
    X.at(i) = {x, i};
    Y.at(i) = {y, i};
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());

  vector<Edge> edges;
  for (int i = 1; i < N; i++)
  {
    edges.push_back(Edge(X[i].second, X[i - 1].second, abs(X[i - 1].first - X[i].first)));
    edges.push_back(Edge(Y[i].second, Y[i - 1].second, abs(Y[i - 1].first - Y[i].first)));
  }
  cout << kruskal(N, edges) << endl;
}

Measured memory_bytes: 9456
#include <iostream>
#include <string.h>
using namespace std;

int main() {
  int n;
  int a[100000] = {0};
  int b[100000] = {0};
  cin >> n;
  for (int i=0; i < n; i++){
      cin >> a[i];
  }
  int now = 0, sum = 1;
  while(b[now]==0){
    b[now] = 1;
    now = a[now]-1;
    if(now == 1){
        cout << sum;
        break;
    }
    else if(b[now]==1){
        cout << -1;
        break;
    }
    else sum += 1; 
  }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  bool flag = true;
  while(flag){
      int a, b, c;
      cin >> a >> b >> c;
      if(a == -1 && b == -1 && c == -1) break;
      else if(a==-1 || b == -1)cout << 'F' << endl;
      else if(a+b>=80)cout << 'A' << endl;
      else if(a+b>=65 && a+b < 80)cout << 'B' << endl;
      else if(a+b>=50 && a+b < 65)cout << 'C' << endl;
      else if(a+b>=30 && a+b < 50){
          if(c >=50)cout << 'C' << endl;
          else cout << 'D' << endl;
      }
      else cout << 'F' << endl;
  }
}


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n+2);
	rep(i, n) cin >> a[i+1];
	a[0] = 0;
	a[n+1] = 0;

	int d[n+1];
	for (int i = 0; i < n+1; i++) {
		d[i] = abs(a[i+1] - a[i]);
	}

	int d2[n];
	rep(i, n) d2[i] = abs(a[i+2] - a[i]);

	int sum = 0;
	rep(i, n+1) sum += d[i];
	rep(i, n) cout << sum - d[i] - d[i+1] + d2[i] << endl;


	return 0;
}


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

int main() {
	int count = 0;
	string S, X = "CF";
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == X[count]) {
			count++;
		}
		if (count == 2) break;
	}
	if (count == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

typedef vector<ll> arr;
typedef vector<arr> mat;

mat eye(ll n){
	mat I(n, arr(n, 0));
	REP(i, n) I[i][i] = 1;
	return I;
}

mat mul(const mat &A, const mat &B){
	mat C(A.size(), arr(B[0].size(), 0));
	REP(i, C.size()){
		REP(j, C[0].size()){
			REP(k, A[0].size()){
				C[i][j] += (A[i][k]*B[k][j])%mod;
				C[i][j] %= mod;
			}
		}
	}
	return C;
}

mat matpow(const mat &A, ll k){
	mat res = eye(A.size());
	mat tmp = A;
	REP(i, 64){ // 64より大きい値にするとバグるので注意．long long が64バイトで表現されていることに依存する．65とかでも一見まともに動くがバグってる．
		if(k>>i&1) res = mul(res, tmp);
		tmp = mul(tmp, tmp);
	}
	return res;
}

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

    ll N, K;
    cin >> N >> K;
    mat a(N, arr(N, 0));
    REP(i, N){
    	REP(j, N){
    		cin >> a[i][j];
    	}
    }
    auto b = matpow(a, K);
    ll res = 0;
    REP(i, N){
    	REP(j, N){
    		res += b[i][j];
    		res %= mod;
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D
from functools import reduce as R
import heapq as H

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = I()
stones = S()
i, j = 0, len(stones)-1
ans = 0

if 'WR' not in stones:
  print('0')
else:
  stones = list(stones)
  while i < j:
    while stones[i] == 'R':
      i += 1
    while stones[j] == 'W':
      j -= 1
    if i < j:
      stones[i] = 'R'
      stones[j] = 'W'
      i += 1
      j -= 1
      ans += 1
  print(ans)

Measured memory_bytes: 28712
using System;
 
namespace Mysample{
  
  class multi1{
    
    static void Main(string[] args){
      
	  var line = System.Console.ReadLine();
      var l = line.Split(' ');
      
      var A =int.Parse(l[0]);
      var B =int.Parse(l[1]);
      
         Console.WriteLine(A*B);
    }
  }
}

Measured memory_bytes: 27444
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
const long long mod = 1e9+7;
int main(void)
{
    int n, m;
    cin >> n >> m;
    vector<bool> ok(n+1,true);
    rep(i,m){
        int a;
        cin >> a;
        ok[a] = false;
    }
    vector<long long> dp(n+1);
    dp[0] = dp[1] = 1;
    if(ok[1]==false) dp[1]--;
    REP(i,2,n+1){
        if(!ok[i]) dp[i] = 0;
        else dp[i] = ((dp[i-1]%mod)+(dp[i-2]%mod))%mod;
        dp[i] %= mod;
    }
    cout << dp[n] << endl;
    return 0;
}


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

bool prim(long long int x)
{
	long long int i=(long long int)sqrt(x);
	if(i%2==0)
	{
		i--;
	}
	for(i=i;i>2;i-=2)
	{
		if(x%i == 0)
		{
			return 0;
		}
	}
	return 1;
}

long long int prime(long long int x)
{
	if(x==2)
	{
		return 2;
	}
	if(x%2==0)
	{
		x++;
	}
	
	while(!prim(x))
	{
		x+=2;
	}
	return x;
}

int main()
{
	long long int x;
	cin>>x;
	cout<<prime(x);
	
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
A = list(map(int, input().split()))
mod = 10**9+7
A.sort()

"""
組み合わせ計算用のテーブルを用意
"""
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

"""
ここからメインの計算
ans = {¥Sum_S max(S)} - {¥Sum_S min(S)}より個別に導出
"""
maxS = 0
for i in range(k - 1, n):
    maxS += A[i] * cmb(i, k - 1, mod)
    maxS %= mod

minS = 0
for i in range(n - k + 1):
    minS += A[i] * cmb(n - i - 1, k - 1, mod)
    minS %= mod

print((maxS - minS) % mod)


Measured memory_bytes: 140236
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

struct edge { int to; edge(int to) : to(to) {} };

int scc(const VV<edge>& g, V<>& comp) {
  int n = g.size();
  VV<edge> rg(n); for (int i = 0; i < n; i++) for (auto&& e : g[i]) rg[e.to].push_back(i);
  V<> vs;
  V<bool> vis(n);
  comp.resize(n);

  function<void(int)> dfs = [&](int v) {
    vis[v] = true;
    for (auto&& e : g[v]) if (!vis[e.to]) dfs(e.to);
    vs.push_back(v);
  };

  function<void(int, int)> rdfs = [&](int v, int k) {
    vis[v] = true;
    comp[v] = k;
    for (auto&& e : rg[v]) if (!vis[e.to]) rdfs(e.to, k);
  };

  for (int v = 0; v < n; v++) if (!vis[v]) dfs(v);
  vis.assign(n, false);
  int k = 0;
  reverse(vs.begin(), vs.end());
  for (auto&& v : vs) if (!vis[v]) rdfs(v, k++);
  return k;
}

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  VV<edge> g(n);
  for (int i = 0; i < m; i++) {
    int a, b; cin >> a >> b;
    g[a].emplace_back(b);
  }
  V<> comp;
  scc(g, comp);
  V<> res(n);
  for (int i = 0; i < n; i++) res[comp[i]] = i;
  for (int i = 0; i < n; i++) cout << res[i] << '\n';
}


Measured memory_bytes: 4380
#define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

static const char a[] = {'r','g','b'};

bool checkColor(const string& str){

	bool res = false;
	for(int i=0;i<3;i++){
		if(count(str.begin(),str.end(),a[i]) == str.size()) res=true;
	}

	return res;
}

int changeColor(string str,int cost,map<string,int>& visited){

	if(checkColor(str)) return 0;

	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0,str));

	while(!que.empty()){
		int cost = que.top().first;
		string now = que.top().second;

		que.pop();
		for(int i=0;i+1<now.size();i++){
			string tmp = now;
			if(now[i] != now[i+1]){
				for(int j=0;j<3;j++){
					if(a[j] != now[i] && a[j] != now[i+1]){
						tmp[i] = a[j];
						tmp[i+1] = a[j];
						break;
					}
				}

				if(visited.find(tmp) != visited.end()) continue;

				visited[tmp] = cost + 1;
				if(checkColor(tmp)) return cost+1;
				que.push(P(cost+1,tmp));
			}
		}
	}

	return -1;

}

int main(){
	string str;

	while(cin>>str){
		if(str.size() == 1 && str[0] == '0') break;
		map<string,int> visited;
		visited[str] = 0;

		int res = changeColor(str,0,visited);

		if(res==-1) printf("%s\n","NA");
		else printf("%d\n",res);
	}
}

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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pnn=pair<int ,int>;

#define ft first
#define sd second
#define fn front
#define pb push_back
#define it insert
#define si(v) int((v).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sot(x) sort(x.begin(), x.end())
#define rese(x) reverse(x.begin(), x.end())
#define vnn(x,y,s,name) vector<vector<int>> name(x, vector<int>(y,s))
#define mse(x) memset(x, 0, sizeof(x))
#define mii(x,y,z) min(x,min(y,z))
#define maa(x,y,z) max(x,max(y,z))

string yes="Yes",no="No";

int main() {
  ll n,x,m;
  cin>>n>>x>>m;
  queue<ll> q;
  set<ll> s;
  ll now=x;
  ll cnt=0;
  ll ans=0;
  q.push(now);
  s.it(now);
  rep(i,100+m){
      now=now*now;
      now%=m;
      if(s.count(now)) break;
      q.push(now);
      s.it(now);
  }
  
  while(!q.empty()){
      ll j=q.front();
      if(j!=now){
          q.pop();
          cnt++;
          ans+=j;
          if(n==cnt){
              cout<<ans<<endl;
              return 0;
          }
          continue;
      }
      
      else {
          ll si=(n-cnt)%(q.size());
          ll roop=(n-cnt)/(q.size());
          int i=0;
          while(!q.empty()){
              if(i<si) ans+=q.front()*(roop+1);
              else ans+=q.front()*roop;
              q.pop();
              i++;
         
          }   
          cout<<ans<<endl;
          return 0;
      }
  }
}   
   



Measured memory_bytes: 6332
#include<stdio.h>
#include<math.h>
#define N 10000
int main(){
  int ary[N];
  int i,j,n,flag=0,scount=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&ary[i]);
  }
  for(i=0;i<n;i++){
    flag=0;
    for(j=2;j<=sqrt(ary[i]);j++){
      if(ary[i]%j==0){
	flag=1;
      }
    }
    if(flag==0)scount++;
  }
  printf("%d\n",scount);
  return 0;
}



Measured memory_bytes: 2084
#include <stdio.h>
int main(){

  int n,m,i,a[100000],b[50000],k,j,x,y,z;
  m=0;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d",&b[i]);
    x=n;
    y=0;
    while(x>y){
      z=(x+y)/2; 
      if(a[z]==b[i]){
	m++;
	break;
      }   
      if(a[z]>b[i]){
	x=z;
      }
      else if(a[z]<b[i]){
	y=z+1;
      }
      
    }
    
  }
  printf("%d\n",m);
  return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <vector>
#include <functional>

template <class T>
struct SegmentTree {
    using Merger = std::function<T(T, T)>;

    int length;
    std::vector<T> dat;
    T unit;
    Merger merge;

    SegmentTree() = default;

    SegmentTree(int n, const T& unit, const Merger& merge)
        : length(1), unit(unit), merge(merge) {
        while (length < n) length <<= 1;
        dat.assign(length * 2, unit);
    }

    template <class Container>
    SegmentTree(const Container& elems, const T& unit, const Merger& merge)
        : length(1), unit(unit), merge(merge) {
        int n = elems.size();
        while (length < n) length <<= 1;

        dat.assign(length * 2, unit);

        std::copy(elems.begin(), elems.end(), dat.begin() + length);

        for (int nidx = length - 1; nidx >= 1; --nidx) {
            T vl = dat[nidx * 2 + 0];
            T vr = dat[nidx * 2 + 1];
            dat[nidx] = merge(vl, vr);
        }
    }

    void update(int nidx, const T& elem) {
        nidx += length;
        dat[nidx] = elem;

        while (nidx > 0) {
            nidx >>= 1;
            T vl = dat[nidx * 2 + 0];
            T vr = dat[nidx * 2 + 1];
            dat[nidx] = merge(vl, vr);
        }
    }

    T fold(int ql, int qr) const {
        ql = std::max(ql, 0);
        qr = std::min(qr, length);
        ql += length, qr += length;

        T lacc = unit, racc = unit;
        while (ql < qr) {
            if (ql & 1) {
                lacc = merge(lacc, dat[ql]);
                ++ql;
            }
            if (qr & 1) {
                --qr;
                racc = merge(dat[qr], racc);
            }
            ql >>= 1, qr >>= 1;
        }

        return merge(lacc, racc);
    }

    T get(int idx) const { return dat[idx + length]; }
    T fold_all() const { return dat[1]; }
};

constexpr int X = 300001;

void solve() {
    int n, k;
    std::cin >> n >> k;

    SegmentTree<int>
        seg(X, 0, [](auto a, auto b) { return std::max(a, b); });

    while (n--) {
        int x;
        std::cin >> x;

        auto len = seg.fold(x - k, x + k + 1) + 1;
        seg.update(x, len);
    }

    std::cout << seg.fold_all() << "\n";
}

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

    solve();

    return 0;
}


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

int main(){
  int d,n,m;
  while(cin >> d, d){
    cin >> n >> m;

    vector<int> a(n+1,0);
    for(int i=1;i<n;i++)cin >> a[i];
    a[n] = d;
    sort(a.begin(),a.end());
    
    long long sum = 0;
    for(int i=0;i<m;i++){
      int k;
      cin >> k;
      int pos = upper_bound(a.begin(),a.end(),k) - a.begin();
      sum += min(a[pos]-k, k-a[pos-1]);
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1532
#始点1から全ノードを通る経路の総数
#解答：
#基本DFSだが、ゴールしたらゴールの訪問予定フラグを消す
#ゴールしたら分岐点からまたDFS


N,M=map(int,input().split())
#dc={}
lc=[[] for _ in range(N)]#インデは-1、要素はそのまま
for i in range(M):
    a,b=map(int,input().split())
    #if not a in
    lc[a-1].append(b)
    lc[b-1].append(a)
#st=[1]
#print(lc)
st=[[1,0]]
#df={1:1}
df={}
lp=[0]
ans=0
while st:
    #tmp=st.pop()
    tmptp=st.pop()
    #print("tmptp",tmptp)
    tmp=tmptp[0]
    ptmp=tmptp[1]
    p=lp.pop()
    while p!=ptmp:
        del df[p]
        p=lp.pop()
    lp.append(p)
    lp.append(tmp)
    df[tmp]=1
    if len(df)==N:
        ans+=1
        #del df[tmp]
        #print("lp",lp)
        #print("df",df)
    for c in lc[tmp-1]:
        if not c in df:
            #st.append(c)
            st.append([c,tmp])
            #df[c]=1
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
const long long mod = 1000000007;



const int MAX = 1000000000;

int search(int* d, int t, int n) {
	if (d[0] == t)return 0;
	int r = 0;
	for (int i = 20; i >= 0; i--) {
		int c = r | (1 << i);
		if (c >= n)continue;
		if (d[c] == t)return c;
		if (d[c] < t)r = c;
	}
	return -1;
}

int main() {
	long long S;
	scanf("%lld", &S);
	long long X2 = sqrt(S);
	long long Y1;
	if (X2 >= MAX) {
		X2 = MAX;
		Y1 = S / X2 + 1;
		if (Y1 >= MAX)Y1 = X2;
	}
	else {
		Y1 = S / X2 + 1;
		if (Y1 >= MAX) {
			X2 = MAX;
			Y1 = S / X2 + 1;
			if (Y1 >= MAX)Y1 = X2;
		}
	}
	long long X1 = Y1 * X2 - S;
	long long Y2 = 1;
	printf("0 0 ");
	printf("%d ",X1);
	printf("%d ",Y1);
	printf("%d ",X2);
	printf("%d ",Y2);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
    public static long gcd(long a, long b){
        if(b == 0)
            return a;
        else
            return gcd(b,a%b);
    }
    public static long lcm(long a, long b){
        if(a < b){
            long tmp = a;
            a = b;
            b = tmp;
        }
        return a * b / gcd(a,b);
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a[] = new long[n];
        for(int i = 0 ; i < n ;i++)
            a[i] = sc.nextLong();
        long ans = a[0];
        for(int i = 1 ; i < n ; i++)
            ans = lcm(ans,a[i]);
        System.out.println(ans);
    }
}


Measured memory_bytes: 26312