akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#include<vector>
#define mp make_pair
#define endl "\n"
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define forn(i,n) for(ll i=0 ; i<n ; i++)
#define arr(a,n) for(ll i=0;i<n;i++){ cin>>a[i]; }
#define ub upper_bound
#define pb push_back
#define mod 1000000007
using namespace std;


int main(){
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll sum=0;
	
	if(k-(min(a,k)+min(b,k))>0)
		sum=min(a,k)-min(c,k-(min(a,k)+min(b,k)));
else
sum=min(a,k);
	
	cout<<sum<<endl;
return 0;
}

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


void solve(){
    string a,b,temp;
    cin >> a >> b;
    temp+=a;
    int n=a.size();
    int m=b.size();
    int c=0,j=0,ans=0;
    for(int i=0;i<=n-m;i++){
        int k=i;
        c=0;
        for(int j=0;j<m;j++){
            if(a[k]==b[j]){
                c++;
            }
            k++;
        }
        ans=max(ans,c);
    }
    cout << m-ans << endl;
}
int main(){
	ios_base::sync_with_stdio(false); 
     	cin.tie(NULL);
	int t=1;
	while(t--)
	solve();	
	
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define forl(a,b,i) for(int i=a;i<=b;i++)
#define _fast_ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t;cin>>t;while(t--)
#define pb push_back
#define mp make_pair
using namespace std;

bool isPalin(string s){
    int i=0,j=s.length()-1;
    while(i<j){
        if(s[i]!=s[j])
            return 0;
        i++;j--;
    }
    return 1;
}

signed main(){
    _fast_;
    
    string s;
    cin>>s;
    int n=s.length();
    string s1="",s2="";
    for(int i=0;i<(n-1)/2;i++){
        s1+=s[i];
    }
    for(int i=(n+1)/2;i<n;i++){
        s2+=s[i];
    }
    if(isPalin(s)&&isPalin(s1)&&isPalin(s2)){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}



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

int	main(void)
{
  int K, A, B, copy_K;
  cin >> K >> A >> B;
  copy_K = K;
  
  while (K <= B)
  {
    if ((A <= K) && (K <= B))
    {
      cout << "OK" << endl;
      break;
    }
    else
      K += copy_K;
  }
  if (K > B)
    cout << "NG" << endl;
}

Measured memory_bytes: 3636
N = gets.to_i
Hs = gets.chomp.split.map(&:to_i)

counter = 0
max_count = 0

(Hs.length - 1).times { |n|
  if Hs[n] >= Hs[n + 1]
    counter += 1
    max_count = [max_count, counter].max
  else
    counter = 0
  end
}

puts max_count


Measured memory_bytes: 12292
n,m,x = map(int, input().split())
ca = []
for i in range(n):
    ca.append(list(map(int, input().split())))

c = []
a = []
for i in range(len(ca)):
    c.append(ca[i][0])
    a.append(ca[i])
    del a[i][0]

ans = 12345678
for i in range(2 ** n):
    cost = 0
    level = [0] * m
    for j in range(n):
        if((i>>j)&1):
            cost += c[j]
            for k in range(m):
                level[k] += a[j][k]
    flag = True
    for k in range(m):
        if(level[k] < x):
            flag = False
    if(flag):
        ans = min(ans,cost)
if(ans == 12345678):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9260
-- E - "Common Subsequence"
import Data.Array

main :: IO()
main = do
  [n, m] <- map read . words <$> getLine
  ns <- map read . words <$> getLine
  ms <- map read . words <$> getLine
  print $ solve n m ns ms

solve :: Int -> Int -> [Int] -> [Int] -> Int
solve n m ns ms = (dp!(n, m) + 1) `mod` (10^9 + 7)
  where
    na = listArray (1, n) ns
    ma = listArray (1, m) ms
    dp = array ((0, 0), (n, m)) $ map (\p->(p, f p)) [(x, y)| x <- [0..n], y <- [0..m]]
    f (x, y)
      | x == 0 || y == 0 = 0
      | na!x == ma!y = (1 + dp!(x-1, y) + dp!(x, y-1)) `mod` (10^9 + 7)
      | otherwise = (dp!(x-1, y) + dp!(x, y-1) - dp!(x-1, y-1)) `mod` (10^9 + 7)

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N; cin>>N;
	vector<ll> A(N+1,0);
	vector<ll> B(N);
	rep(i,N) cin>>A[i]>>B[i];

	ll cnt=0;

	for(int i=N-1;i>=0;i--){
		cnt+=B[i]*ceil((double)A[i]/B[i])-A[i];
		if(i>=1) A[i-1]+=cnt;
	}
	cout<<cnt;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	vector<long long> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	long long val = 0;
	for(int i = 0; i < n; i++){
		if(i&1) val -= a[i];
		else val += a[i];
	}
	cout << val;
	for(int i = 0; i < n - 1; i++){
		val = 2 * a[i] - val;;
		cout << " " << val;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 2048
#include<iostream>
using namespace std;
struct Cube{
    /**
    *   0
    * 3 1 2 4
    *   5
    * <:y ^:x <>:z
    **/
    Cube(){}
    int d[6];
    void roll(int i,int j,int k,int l){
        int t=d[i];d[i]=d[j];d[j]=d[k];d[k]=d[l];d[l]=t;
    }
    
    void z(){roll(1,2,4,3);}
    void y(){roll(0,2,5,3);}
    void x(){roll(0,1,5,4);}
    
    void n(){x();}
    void s(){x(),x(),x();}
    void e(){y(),y(),y();}
    void w(){y();}
    
    int getRight(int top,int front){
        int right;
        for(int i=0;i<6;++i){
            for(int j=0;j<4;++j){
                if(d[0]==top&&d[1]==front)right=d[2];
                z();
            }
            if(i&1)x();
            else y();
        }
        return right;
    }
    
    bool isSame(Cube c){
        auto chk=[&]{for(int i=0;i<6;++i)if(d[i]!=c.d[i])return false;return true;};
        bool res=false;
        for(int i=0;i<6;++i){
            for(int j=0;j<4;++j){
                if(!res&&chk())res=true;
                z();
            }
            if(i&1)x();
            else y();
        }
        return res;
    }
};
int main(){
  Cube c,d;
  int n;
  for(int i=0;i<6;++i)cin>>c.d[i];
  for(int i=0;i<6;++i)cin>>d.d[i];
  if(c.isSame(d))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

namespace AGC027A
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            long[] nx = Input.LongArray();
            long N = nx[0];
            long X = nx[1];

            long[] A = Input.LongArray();
            
            Array.Sort(A);
            long rest = X;
            int count = 0;
            for (int i = 0; i < N - 1; i++)
            {
                if (A[i] > rest)
                {
                    break;
                }

                count++;
                rest -= A[i];
            }

            if (A[N - 1] == rest)
            {
                count++;
            }
            Console.WriteLine(count);
        }
    }
    
    internal static class Input
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

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

#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define endl "\n" 
#define all(c) c.begin(),c.end()
#define present(c,element) (c.find(element)!=c.end())
#define cpresent(c,element) (find(c,element)!=c.end())
typedef vector<int> vi;
typedef vector<ll> vll;
ll mod=1e9+7;


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

int test=1;
//cin>>test;
while(test--)
{

	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int f=1;
	while(a>0&&c>0)
	{
		if(f)
			c-=b;
		else a-=d;
		if(c<=0)
		{
			cout<<"Yes";
			return 0;
		}
		if(a<=0)
		{
			cout<<"No";
			return 0;
		}
		f=1-f;
	}


	
}
return 0;
}









Measured memory_bytes: 3584
#include <stdio.h>

int main(){
    int n;
    int cnt;
    char e[ 1000001 ];
    int i, j;

    while ( 1 == scanf( "%d", &n ) ) {
        for ( i = 2; i <= n; i ++ ) {
            e[ i ] = 1;
        }
        for ( i = 2; i <= n; i ++ ) {
            if ( e[ i ] ) {
                for ( j = i + i; j <= n; j += i ) {
                    e[ j ] = 0;
                }
            }
        }
        cnt = 0;
        for ( i = 2; i <= n; i ++ ) {
            cnt += e[ i ];
        }
        printf( "%d\n", cnt );
    }

    return 0;
}

Measured memory_bytes: 1568
#include <iostream>
using namespace std;
int main(){
  const int NUM = 50000;
  bool prime[NUM];
  prime[0] = false;
  prime[1] = false;
  for(int i=2;i<NUM;i++)
    prime[i] = true;
  for(int i=2;i*i<NUM;i++)
    for(int k=2;i*k<NUM;k++)
      prime[i*k]=false;

  int n,c;
  while(true){
    cin>>n;
    if(!n)break;
    c = 0;
    for(int i=2;i<=n/2;i++)
      if(prime[i]&&prime[n-i])
	c++;
    cout << c << endl;
  }
  return 0;
}

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

int main() {
  vector<string> v;
  string s;

  while (getline(cin, s)) v.push_back(s);

  vector<vector<int>> a(v.size()), dp(v.size());
  for (int i = 0; i < v.size(); ++i) {
    int x = 0;
    v[i] += ',';
    for (int j = 0; j < v[i].size(); ++j) {
      if (v[i][j] == ',') {
        a[i].push_back(x);
        x = 0;
      } else {
        int t = v[i][j] - '0';
        x = 10 * x + t;
      }
    }

    dp[i].assign(a[i].size(), 0);
  }

  // for (int i = 0; i < a.size(); ++i) {
  //   for (int j = 0; j < a[i].size(); ++j) {
  //     cout << a[i][j] << (j + 1 == a[i].size() ? "\n" : " ");
  //   }
  // }

  dp[0][0] = a[0][0];
  for (int i = 1; i < a.size(); ++i) {
    for (int j = 0; j < a[i].size(); ++j) {
      if (dp[i].size() > dp[i - 1].size()) {
        if (j < dp[i - 1].size()) dp[i][j] = max(dp[i][j], dp[i - 1][j]);
        if (j - 1 < dp[i - 1].size()) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);
      } else {
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j + 1]);
      }
      dp[i][j] += a[i][j];
    }
  }

  // for (int i = 0; i < dp.size(); ++i) {
  //   for (int j = 0; j < dp[i].size(); ++j) {
  //     cout << dp[i][j] << (j + 1 == dp[i].size() ? "\n" : " ");
  //   }
  // }

  cout << dp.back().back() << endl;
}

Measured memory_bytes: 3012
import math 
import bisect
import heapq
from collections import deque

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

a.sort()
c.sort()
ans = 0
for i in range(n):

    idx1 = bisect.bisect_left(a, b[i])
    idx2 = n - bisect.bisect_right(c, b[i])
    ans += (idx1 * idx2)

print(ans)

Measured memory_bytes: 22792
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
string s,t;
int n,k,f[305][305][305],ans;
int main(){
	cin>>s;
	n=s.size();
	cin>>k;
	s=" "+s;
	for(int i=1;i<=n;++i){
		for(int j=0;j<=k;++j)f[j][i][i]=1;
	}
	for(int d=1;d<n;++d){
		for(int r=d+1;r<=n;++r){
			int l=r-d;
			f[0][l][r]=max(f[0][l+1][r],f[0][l][r-1]);
			if(s[l]==s[r])f[0][l][r]=max(f[0][l][r],f[0][l+1][r-1]+2);
		}
	}
	ans=f[0][1][n];
	for(int _=1;_<=k;++_){
		for(int d=1;d<n;++d){
			for(int r=d+1;r<=n;++r){
				int l=r-d;
				f[_][l][r]=max(f[_][l+1][r],f[_][l][r-1]);
				if(s[l]==s[r])f[_][l][r]=max(f[_][l][r],f[_][l+1][r-1]+2);
				else f[_][l][r]=max(f[_][l][r],f[_-1][l+1][r-1]+2);
			}
		}
		ans=max(ans,f[_][1][n]);
	}
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 112452
#!/usr/bin/env python

import collections

def parse_input():
    N = int(input())
    A = list(map(int, input().split()))
    return N, A

if __name__ == "__main__":
    N, A = parse_input()
    counts = collections.defaultdict(int)
    for i in range(N):
        counts[A[i]] += 1

    total = 0
    subtracts = collections.defaultdict(int)
    for a, c in counts.items():
        num_patterns = max((c * (c - 1)) // 2, 0)
        subtracts[a] = num_patterns - max(((c - 1) * (c - 2)) // 2, 0)
        total += num_patterns

    for i in range(N):
        print(total - subtracts[A[i]])


Measured memory_bytes: 32156
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
using namespace std;

int n,m;
int S[20];
vector<int> k[20];
int p[20];
int ans = 0;

bool judge(){
  bool flag = true;
  int count = 0;
  for(int i=0;i<m;i++){
    count = 0;
    
    for(int j=0;j<k[i].size();j++){
      if(S[k[i][j]] == 1) count += 1;
    }
    
    if(count%2 != p[i]){
      flag = false;
      break;
    }
  }
  return flag;
}

void rec(int j){
  if(j == n){
    if(judge()) ans += 1;
    return;
  }
  rec(j+1);
  S[j] = 1;
  rec(j+1);
  S[j] = 0;
}

int main(){
  cin >> n >> m;
  int num;
  int ki;
  for(int i=0;i<m;i++){
    cin >> num;
    for(int j=0;j<num;j++){
      cin >> ki;
      k[i].push_back(ki-1);
    }
  }

  for(int i=0;i<m;i++){
    cin >> p[i];
  }

  for(int i=0;i<n;i++){
    S[i] = 0;
  }
  
  rec(0);

  cout << ans << endl;

  return 0;
}

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

int main()
{
    int n, tmp;
    cin >> n;
    vector<int> a(n + 1);

    for(int i = 1; i <= n; ++i)
    {
        cin >> tmp;
        a[tmp] = i;
    }

    for(int i = 1; i <= n; ++i)
        cout << a[i] << " ";
    cout << "\n";
    return 0;
}

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

const int mnx = 1e6 + 9;
const int mod = 1e9 + 7;

ll n;
ll a[mnx];
ll mn, mx;

int main() {

cin >> n;

for(int i = 1; i <= n; i++){
    cin >> a[i];
}

mn = 2; mx = 2;

for(int i = n; i >= 1; i--){
    if(mn % a[i] != 0) mn = a[i] * (mn / a[i] + 1);
    mx = a[i] * (mx / a[i] + 1) - 1;
}

if(mn > mx) return cout << -1 << '\n', 0;
else cout << mn << ' ' << mx << '\n';

return 0;

}


Measured memory_bytes: 1024
import sys
import math


def deg(v1,v2):
    normv1 = math.sqrt(v1[0]**2+v1[1]**2)
    normv2 = math.sqrt(v2[0]**2+v2[1]**2)
    if normv1 == 0 or normv2 == 0:
        print "ERROR"; exit()
    return (v1[0]*v2[0]+v1[1]*v2[1])/(normv1*normv2)

def calc_hull_right(d):
    hull_right = [d[0]]
    first = d[0]
    p = d[0]
    while True:
        maxcos = -1.0
        for i in xrange(1,len(d)):
            if d[i][1] < p[1]  or d[i] == p: continue
            c = deg([d[i][0]-p[0],d[i][1]-p[1]],[1,0])
            if c >= maxcos:
                maxcos = c
                q = d[i]
        p = q
        hull_right.append(q)
        if q == d[-1]: break
    return hull_right


def calc_hull_left(d):
    hull_left = [d[0]]
    first = d[0]
    p = d[0]
    while True:
        maxcos = 1.0
        for i in xrange(1,len(d)):
            if d[i][1] < p[1]  or d[i] == p: continue
            c = deg([d[i][0]-p[0],d[i][1]-p[1]],[1,0])
            if c <= maxcos:
                maxcos = c
                q = d[i]
        p = q
        hull_left.append(q)
        if q == d[-1]: break
    return hull_left

while True:
    n = int(raw_input())
    if n == 0: break
    d = []
    for t in xrange(n):
        d.append(map(float,raw_input().split(",")))
    d.sort(key = lambda x:x[1])
    #print calc_hull_left(d) + calc_hull_right(d)
    print  - len( calc_hull_left(d) + calc_hull_right(d) ) + 2 + len(d)

Measured memory_bytes: 4524
lines = gets.to_i
ary = []
cake = 100/4
donat = 100/7
for i in 0..cake do 
    for t in 0..donat do
      if 4*i + 7*t == lines
          ary << 1
      end 
    end
end

if ary.count != 0
    puts "Yes"
else
    puts "No"
end


Measured memory_bytes: 1788
#include <stdio.h>

int main(){

  int H,W,i,j;

  while(scanf("%d %d",&H,&W),H!=0&&W!=0){

  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      if(i==0 || i==H-1 || j==0 || j==W-1){
          printf("#");
      }else{
          printf(".");
      }
    }
      printf("\n");
    }
      printf("\n");
    }
  return 0;
}


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

int main() {
  string S;
  cin >> S;
  
  if ( S.at(2) == S.at(3) && S.at(4) == S.at(5) ){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int in;
    int h,m,s;
    scanf("%d",&in);

    h = in / 3600;
    in %= 3600;

    m = in / 60;
    in %= 60;

    s = in;

    printf("%d:%d:%d\n",h,m,s);
}




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

int main(){
    string s;
    long long k;
    cin>>s>>k;

    if(s.size() == 1){
        cout<<s<<endl;
    }    

    else if(s[0] == '1' && s.size() != 1){
        int i=0;
        while(s[i] == '1'){
            i++;
        }

        if(i >= k)cout<<'1'<<endl;
        else cout<<s[i]<<endl;
    }

    else if(s[0] != '1') cout<<s[0]<<endl;

    return 0;
}

Measured memory_bytes: 256
s0 = list(input())
s = []
for i in s0:
    s.append(i)
A = s[:2]
B = s[2:]
a = "".join(A)
b = "".join(B)
a = int(a)
b = int(b)
if 0<a<=12 and 0<b<=12:
  print("AMBIGUOUS")
elif (a>12 or a == 0) and 0<b<=12:
  print("YYMM")
elif 0<a<=12 and (b>12 or b==0):
  print("MMYY")
else:
  print("NA")

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

int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  for (int i = 0; i < n; i ++) {
    cin >> a.at(i);
  }

  pair<int, int> b[26];
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < a.at(i).size(); j ++) {
      b[a.at(i).at(j) - 'a'].first ++;
    }
    for (int j = 0; j < 26; j ++) {
      if (i == 0) {
        b[j].second = b[j].first;
      } else {
        b[j].second = min(b[j].first, b[j].second);
      }
      b[j].first = 0;
    }
  }

  for (int i = 0; i < 26; i ++) {
    for (int j = 0; j < b[i].second; j ++) {
      cout << char(i + 'a');
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S; cin >> S;
    ll mi = INT32_MAX;
    for (char c = 'a'; c <= 'z'; c++) {
        char p[101];
        strcpy(p, S.c_str());

        int cnt = 0;
        bool others;
        while (1) {
            //if (c == 'r') printf("%s\n", p);
            char *i = p;
            others = false;
            while (*i != '\0') {
                if (*i != c) others = true;
                if (*(i+1) == c) *i = c;
                i++;
            }
            if (others == false) break;
            *(--i) = '\0';
            cnt++;
        }
        //printf("%c: %d\n", c, cnt);
        if (mi > cnt) mi = cnt;
    }
    cout << mi << endl;
}


Measured memory_bytes: 3632
import sys

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    BC = []
    for _ in range(M):
        b, c = map(int, input().split())
        BC.append((b, c))

    BC = sorted(BC, key=lambda x: -x[1])
    n = 0
    for b, c in BC:
        n += b
        A += [c] * b
        
        if n >= N:
            break

    A = sorted(A, key=lambda x: -x)
    return sum(A[:N])


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

Measured memory_bytes: 88984
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] s = new int[N];
    int sum = 0;
    for(int i = 0; i < N; i++) {
      s[i] = sc.nextInt();
      sum += s[i];
    }
    Arrays.sort(s);
    int ans = 0;
    if(sum % 10 != 0) {
      ans = sum;
    } else {
      int count = 0;
      for(int i = 0; i < N; i++) {
        if((sum - s[i]) % 10 != 0) {
          ans = sum - s[i];
          count++;
          break;
        }
      }
      if(count == 0 && (s[0] % 10 != 0)) {
        if(N > 1) ans = sum - s[0] - s[1];
      }
    }
    System.out.println(ans);
  }
}

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

using namespace std;

typedef long long ll;

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

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

	int k;
	cin >> k;

	string s;
	cin >> s;

	int n = s.size();

	if(n > k){
		cout << s.substr(0, k) << "..." << endl;
	}else{
		cout << s << endl;
	}
}


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

int main(void)
{
	int n,k,i,j,temp,sum=0;
	scanf("%d%d",&n,&k);
	int s[n];
	for(i=0;i<=n-1;i++)
		{scanf("%d",&s[i]);}
					for(i=0;i<=n-1;i++){fprintf(stderr,"%d ",s[i]);}

	for(i=0;i<=n-2;i++)
		{
		for(j=0;j<=n-2-i;j++)
			{
			if(s[j]<s[j+1])
				{
				temp=s[j];
				s[j]=s[j+1];
				s[j+1]=temp;
				}
			}
		}
					fprintf(stderr,"\n");
					for(i=0;i<=n-1;i++){fprintf(stderr,"%d ",s[i]);}

	for(i=0;i<=k-1;i++)
		{sum+=s[i];}
	printf("\n%d\n",sum);
	return 0;
}


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

int main(){
    string S, T;
    int A, B;
    string U;
    cin >> S >> T >> A >> B >> U;
    if (U==S){
        A--;
    }else{
        B--;
    }
    cout << A << " " <<  B << endl;
}

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

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

const int INF = 1000000007;

int main(void){
	int n,T; cin>>n>>T;
	ll t[220000]={0};
	for(int i=0;i<n;i++) cin>>t[i];
	t[n] = 5000000000;
	
	ll sum=0;
	ll start = t[0];
	for(int i=0;i<n;i++){
		if(t[i+1] - t[i] <= T) continue;
		else{
			sum += (t[i] + T) - start;
			start = t[i+1];
		}
	}

	printf("%ld\n", sum);

	return 0;
}

Measured memory_bytes: 1920
#include <iostream>

int main() {

    int n;

    std::cin >> n;

    int ans = 0;

    for(int i=0; i<n; i++){
        int l,r;
        std::cin >> l >> r;
        ans += r-l+1;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int n,m;cin>>n>>m;
  vector<pair<int,int>> pr(m);
  rep(i,m){
    int s,c;cin>>s>>c;
    s--;
    pr[i]=make_pair(s,c);
  }
  rep(i,1000){
    string s=to_string(i);
    if(s.size()==n){
      bool ans=true;
      rep(j,m){
        if((s[pr[j].first]-'0')!=pr[j].second)ans=false;
      }
      if(ans){
        cout<<i<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll l;
	cin >> n >> l;
	vector<ll> a(n);
	int id = -1;
	rep(i, n){
		cin >> a[i];
		if(i != 0){
			if(a[i]+a[i-1] >= l) id = i;
		}
	}
	if(id == -1){
		cout << "Impossible" << endl;
		return 0;
	}
	cout << "Possible" << endl;
	for(int i = 1; i < id; i++) cout << i << endl;
	for(int i = n-1; i >= id+1; i--) cout << i << endl;
	cout << id << endl;
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<(c<=a+b?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();

        long money = 100;
        long cou = 0;
        while(money<X){
        money = (long)(money*1.01);
            cou++;
        }
                System.out.println(cou); 
        }
}

Measured memory_bytes: 35796
import java.util.Scanner;

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

        while (true) {
            String s = sc.next();
            if (s.equals("-")) {
                break;
            }
            int m = sc.nextInt();
            for (int i=0; i<m; ++i) {
                int h = sc.nextInt();
                s = s.substring(h) + s.substring(0, h);
            }
            System.out.println(s);
        }
        sc.close();
    }
}



Measured memory_bytes: 26500
package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 100000000)

	_ = scanInt()
	s := scanText()

	ans := 0
	next := '0'
	for _, e := range s {
		if e != next {
			ans++
		}
		next = e
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
using ll = long long int;

#define rep(i, n) for (ll i = 0; i < (n); i++)

#define MOD 998244353

ll dp[3002] = {};

int main() {
  ll n, s;
  cin >> n >> s;
  vector<ll> a(n);

  rep(i, n) {
    cin >> a[i];
  }

  dp[0] = 1;
  rep(i, n) {
    for (ll j = s; j >= 0; j--) {
      if (j + a[i] <= s) {
        dp[j + a[i]] += dp[j];
        dp[j + a[i]] %= MOD;
      }
      dp[j] *= 2;
      dp[j] %= MOD;
    }
  }

  cout << dp[s] << endl;

  return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

//-----------------------------------------------

//------------------------------------------------
int main(){
  double ans,kouho,saisyo;
  int n,k;
  vector<double> a;
  cin>>n>>k;
  a.assign(n,0);
  rep(i,0,n) {
    double p;
    cin>>p;
    a.at(i)=(p+1)/2;
  }
rep(i,0,k) saisyo+=a.at(i);
ans=saisyo;
if(n-k>0){
rep(i,1,n-k+1){
  saisyo-=a.at(i-1);
  saisyo+=a.at(i+k-1);
  if(saisyo>ans) ans=saisyo;
}
}

cout<<fixed << setprecision(10) <<ans<<endl;
}


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

int main()
{
    int n, A[200];
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> A[i];
    int count = 0;
    for(int i=0; i<n; i++)//??????????°??????´??\?????´????´??????¢
    {
        int minj = i;
        for(int j=i+1; j<n; j++)
        {
            if(A[j]<A[minj])
            {
                minj = j;
            }
        }
        int temp = A[i];
        A[i] = A[minj];
        A[minj] = temp;
        if(i!=minj)
          count++;
    }
    for(int i=0; i<n-1; i++)
       cout << A[i] << " ";
    cout << A[n-1] << endl;
    cout << count << endl;
    return 0;
}

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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string n;cin>>n;
    int l = n.size();
    int K;cin>>K;
    vector<vector<vector<ll>>> dp=vector<vector<vector<ll>>>(l+1,vector<vector<ll>>(2,vector<ll>(K+2,0)));
    //dp[i][j][k]:上からi桁目、上位が小さいかどうか、0以外が出た回数+1
    dp[0][0][1]=1;

    for(int i=0; i<l; i++){
        //for(int j=0; j<2; j++){
            for(int k=1; k<=K+1; k++){
                if(n[i]=='0'){
                    dp[i+1][1][k]=dp[i][1][k-1]*9+dp[i][1][k];
                    dp[i+1][0][k]=dp[i][0][k];
                }
                else{
                    dp[i+1][1][k]=dp[i][1][k-1]*9+dp[i][1][k]+dp[i][0][k-1]*(n[i]-'0'-1)+dp[i][0][k];
                    dp[i+1][0][k]=dp[i][0][k-1];
                }

            }
        //}
    }
    cout<<dp[l][0][K+1]+dp[l][1][K+1];

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__

	int N, K;
	cin >> N >> K;
	VI A(200000, 0);
	REP(i, N) {int a; cin >> a; a--; A.at(a)++;}
	sort(ALL(A), greater<int>() );
	int ans = 0;
	FOR(i, K, N - 1)ans += A[i];
	cout << ans << endl;

	return 0;
}


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

vector<int> pre, in, post;
int n, pos;

void reconstruction(int left, int right) {
    if (left >= right) return;
    int root = pre[pos++];
    int idx = distance(in.begin(), find(in.begin(), in.end(), root));
    reconstruction(left, idx);
    reconstruction(idx + 1, right);
    post.push_back(root);
    return;
}

void solve() {
    pos = 0;
    reconstruction(0, n);
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << post[i];
    }
    cout << endl;
    return;
}

int main() {
    cin >> n;

    int node;
    for (int i = 0; i < n; i++) {
        cin >> node;
        pre.push_back(node);
    }

    for (int i = 0; i < n; i++) {
        cin >> node;
        in.push_back(node);
    }

    solve();

    return 0;
}


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

int main () {
  int N,x,ans;
  cin >> N;
  x = 1;
  ans = 0;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.at(i) = a;
  }
  while (true) {
    if (ans > N) {
      ans = -1;
      break;
    }
    else if (x != 2) {
      x = A.at(x-1);
      ans++;
    }
    else if (x == 2) {
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 768
#include<stdio.h>
int main()
{
  int a, b, i, c=0;
  scanf("%d %d", &a, &b);
  for(i = 1; i <= 12; i++){
    if(i < a){
       c++;
    }else if(i == a){
       break;
    }
  }
  if(i == a && i <= b){
           c++;
   }
  printf("%d\n", c);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int a[105];
int d[105];
int main(){
	int n,x;
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	d[1]=0;
	int ans=0;
	for(int i=2;i<=n+1;i++){
		d[i]=d[i-1]+a[i-1];
	}
	for(int i=1;i<=n+1;i++)
		if(d[i]<=x)
			ans++;
	//for(int i=1;i<=n;i++)
	//	printf("%d\n",d[i]);
	printf("%d\n",ans);	
}

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

int main() {
  string s; 
  cin>>s;
  if(s.at(5)=='1'){
    cout<<"TBD"<<endl;
  }
  else if(s.at(5)=='0'&&s.at(6)-'0'>4){
    cout<<"TBD"<<endl;
  }
  else{
    cout<<"Heisei"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i, a, b)  for(int i = a, _b = b; i <= _b; ++i)
#define Ford(i, a, b) for(int i = a, _b = b; i >= _b; --i)
#define FileName      "test"
#define ll            long long
#define ld            long double
#define ull           unsigned long long
#define Print(x)      cerr << #x << "is " << x << '\n';
#define pb            push_back
#define X             first
#define Y             second
//#define Karma

using namespace std;

template<typename T> inline void Cin(T &x)
{
    char c;
    T sign = 1;
    x = 0;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        if (c == '-') sign = -1;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
    x *= sign;
}
template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');}
template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);}
template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);}
template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);}

typedef pair<int, int> pii;
typedef pair<ll, int> plli;
const int N = 1 << 16;

int n, nState;
ll cost[N], f[N], a[20][20];
vector<int> v;

bool Get(int x, int i)
{
    return (x >> i) & 1;
}

void Enter()
{
     Cin(n);
     For(i, 0, n - 1)
     {
         For(j, 0, n - 1)
         Cin(a[i][j]);
     }
     nState = (1 << n) - 1;
     For(bit, 1, nState)
     {
        v.clear();
        For(i, 0, n - 1) if(Get(bit, i)) v.pb(i);
        cost[bit] = 0;
        int sz = v.size();
        for(int i = 0; i < sz; ++i)
        {
            for(int j = 0; j < i; ++j)
            cost[bit] += a[v[i]][v[j]];
        }
     }
}

void Solve()
{
     For(bit, 1, nState)
     {
         v.clear();
         For(i, 0, n - 1) if(Get(bit, i)) v.pb(i);
         int sz = v.size();
         int vState = (1 << sz);
         f[bit] = 0;
         For(vbit, 1, vState)
         {
             int mask = 0;
             for(int i = 0; i < sz; ++i) if(Get(vbit, i)) mask += (1 << v[i]);
             f[bit] = max(f[bit], f[bit - mask] + cost[mask]);
         }
     }
     cout << f[nState];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef Karma
    freopen(FileName".inp", "r", stdin);
    freopen(FileName".out", "w", stdout);
#endif // Karma

    Enter();
    Solve();

    return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<set>
using namespace std;
set<int> banned;
bool good(int n)
{
	while(n>0)
	{
		if(banned.count(n%10)==1)
			return false;
		n /= 10;
	}
	return true;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k; cin >> n >> k;
	for(int i = 0; i < k; i++)
	{
		int d; cin >> d;
		banned.insert(d);
	}
	
	for(; !good(n); n++);
	cout<<n<<endl;
	
	return 0;
}

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

#define MAX_N 20

int n, U;
int cs[MAX_N];
int rs[MAX_N];

inline bool check(int S) {
    // 履修に必要な単位をすべて取得しているか
    for (int i = 0; i < n; i++) {
        if (S & (1<<i)) {
            if ((S & rs[i]) != rs[i]) {
                return false;
            }
        }
    }

    // 総単位数がUを越えているか
    int unit = 0;
    for (int i = 0; i < n; i++) {
        if (S & (1<<i)) {
            unit += cs[i];
        }
    }
    if (unit < U) return false;

    return true;
}

bool checkAllPattern(int k) {
    int c = (1<<k)-1;
    while (c < (1<<n)) {
        if (check(c)) return true;
        int x = c & -c;
        int y = c + x;
        c = ((c & ~y) / x >> 1) | y;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    while (cin >> n >> U, n || U) {
        memset(cs, 0, sizeof(cs));
        memset(rs, 0, sizeof(rs));
        for (int i = 0; i < n; i++) {
            int c, k, r;
            cin >> c >> k; r = 0;
            for (int j = 0; j < k; j++) {
                int _r; cin >> _r;
                r |= (1<<_r);
            }
            cs[i] = c;
            rs[i] = r;
        }

        for (int i = 1; i <= n; i++) {
            if (checkAllPattern(i)) {
                cout << i << endl;
                break;
            }
        }

        //int ans = (1<<28);
        //for (int S = 1; S < (1<<n); S++) {
        //    if (check(S)) {
        //        ans = min(ans, __builtin_popcount(S));
        //    }
        //}

        //cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
#include <iostream>

using namespace std;

int main(void){
  
  while(1){
    int a,b;
    char str;

   cin >> a >> str >> b;

   if(str == '+')
     cout << a+b << endl;
   else if(str == '-')
     cout << a-b << endl;
   else if(str == '*')
     cout << a * b << endl;
   else if(str == '/')
     cout << a /b << endl;
   else 
     break;


 } 

  

  return 0;
}

Measured memory_bytes: 3100
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = 3;
        int[,] A = new int[N, N];
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                A[i, j] = cin.nextInt();
            }
        }

        int[] a = new int[N];
        int[] b = new int[N];
        for (int i = 0; i < N; i++)
        {
            b[i] = A[0, i];
        }
        a[1] = A[1, 0] - b[0];
        a[2] = A[2, 0] - b[0];

        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                if (a[i] + b[j] != A[i, j])
                {
                    Console.WriteLine("No");
                    return;
                }
            }
        }

        Console.WriteLine("Yes");
    }
}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}



Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
    int n;
    int blocks;
    int up = 0;
    int down = 0;

    cin >> n;

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

        cin >> blocks;
        vector<int> arr(blocks);

        for(int j = 0; j < blocks; j++){
            cin >> arr[j];
        }

        for(int k = 0; k < blocks-1; k++){
            //下がる
            if(arr[k] > arr[k+1]){
                if(down < abs(arr[k+1]-arr[k])){
                    down = abs(arr[k+1]-arr[k]);
                }
         //       cout <<"*" <<arr[k+1]-arr[k]  << endl;
            }
            if(arr[k] < arr[k+1]){
                if(up < abs(arr[k+1]-arr[k])){
                    up = abs(arr[k+1]-arr[k]);
                }
            }
        }

        cout << up << " " << down << endl;
        up = down = 0;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

const int INF = 2147483647;

//RMQ
struct SegTree {
    int N;
    vector<int> dat;
    SegTree() {}
    SegTree(int n) {
        N = 1;
        while(N < n) N *= 2;
        dat.resize(2 * N, INF);
        // for(int i = 0; i < 2*N-1; i++)
        //     dat[i] = INF;
    }
    // update k th element
    void update(int k, int a) {
        k += N-1; // leaf
        dat[k] = a; 
        while(k > 0) {
            k = (k - 1) / 2;
            dat[k] = min(dat[k*2+1], dat[k*2+2]);
        }
    }
    // min [a, b)
    int query(int a, int b) { return query(a, b, 0, 0, N); }
    int query(int a, int b, int k, int l, int r) {
        if(r <= a or b <= l) return INF;
        if(a <= l and r <= b) return dat[k];
        int m = (l + r) / 2;
        return min(query(a, b, k*2+1, l, m), query(a, b, k*2+2, m, r));
    }
};

signed main(){
    int n, q;
    cin >> n >> q;
    SegTree sg(n);
    rep(i, 0, q){
        int c, x, y;
        cin >> c >> x >> y;
        if(c == 0){
            sg.update(x, y);
        }else{
            cout << sg.query(x, y + 1) << endl;
        }
    }
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  ll a = n%k;
  ll ans = min(a, k-a);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstring>

using namespace std;

#define rep(i, a, n) for(int i = a; i < (n); ++i)
#define ll long long

int main(){
  char s[10];
  scanf("%s", s);

  int n = strlen(s);
  ll ans = 0;
  rep(bit, 0, 1 << (n-1)) {
    ll tmp = s[0] - '0';
    rep(j, 0, n-1) {
      if ((bit >> j) & 1) {
        ans += tmp;
        tmp = 0;
      }
      tmp = tmp * 10 + s[j+1] - '0';
    }
    ans += tmp;
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 256
import sys
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
l = []

def check(b) :
    r1 = [x % b for x in a]
    r1.sort()
    s1 = sum(r1)
    
    mn = 1e9
    s2 = 0
    for i in range(n):
        s2 += r1[i]
        mn = min(max(s2, (n-1-i)*b - (s1-s2)), mn)
        
    if mn <= k :
        print(int(b))
        sys.exit(0)
        

for p in range(1,int((s+1)**0.5+1)) :
    if s % p != 0:
        continue
    b = s // p
    l.append(p)
    check(b)
l.reverse()

for b in l:
    check(b)
        
    


Measured memory_bytes: 3192
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
typedef long long ll;
using namespace std;

int main() {
	int a,b; cin >> a >> b;
	int ans = 0;
	if (b >= a) ans = a;
	else ans = a - 1;
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   String YM = sc.next();
   
   boolean YYMM = false;
   boolean MMYY = false;
   
   
   if(YM.charAt(0)=='0'){
    if(YM.charAt(1)!='0'){
     MMYY = true;
    }
   }
     
   if(YM.charAt(0)=='1'){
    if(YM.charAt(1)=='0' || YM.charAt(1)=='1' || YM.charAt(1)=='2'){
     MMYY = true;
    }     
   }

     
      if(YM.charAt(2)=='0'){
    if(YM.charAt(3)!='0'){
     YYMM = true;
    }
   }
     
   if(YM.charAt(2)=='1'){
    if(YM.charAt(3)=='0' || YM.charAt(3)=='1' || YM.charAt(3)=='2'){
     YYMM = true;
    }     
   }
     if(YYMM && MMYY){
         System.out.println("AMBIGUOUS");
     }
      else if(YYMM && !(MMYY)){
         System.out.println("YYMM");
     }
      else if(!(YYMM) && MMYY){
         System.out.println("MMYY");
     }
      else{
         System.out.println("NA");
     }
   
 }
}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MOD=1e9+7;
static const ll MAX=101010;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/

ll dp[55][444][444];

int main(void) {
  ll i, j, k, l;
  ll N, Ma, Mb;
  cin >> N >> Ma >> Mb;
  ll a[44], b[44], c[44];
  
  for(i=0; i<N; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  
  for(i=0; i<44; i++)
    for(j=0; j<444; j++)
      for(k=0; k<444; k++)
        dp[i][j][k]=INF;
      
  dp[0][0][0]=0;
  ll t=0;
  for(i=0; i<N; i++) {
    for(j=0; j<404; j++) {
      for(k=0; k<404; k++) {
        chmin(dp[i+1][j][k], dp[i][j][k]);
        chmin(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i]);
      }
    }
  }
  
  ll ans=INF;
  for(ll p=1; p*max(Ma, Mb)<404; p++) {
    chmin(ans, dp[N][p*Ma][p*Mb]);
  }
  
  if(ans==INF) pt(-1);
  else pt(ans);
}




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

int main()
{
    int n;
    cin >> n;
    double sum = 0;
    rep(i, n)
    {
        int a;
        cin >> a;
        sum += 1.0 / a;
    }
    double ans = 1 / sum;
    printf("%.10f\n", ans);

    return 0;
}

Measured memory_bytes: 256