akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def warshall_floyd(g):
    d = defaultdict(dict)
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v))
    V = set(V)
    for i in V:
        for j in V:
            if i in g and j in g[i]:
                d[i][j] = g[i][j]
            else:
                d[i][j] = sys.maxsize
    for k in g:
        for i in g:
            for j in g:
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]

    return d


@mt
def slv(N, M, ABC):
    g = defaultdict(dict)
    for a, b, c in ABC:
        g[a][b] = c
        g[b][a] = c
    d = warshall_floyd(g)

    ans = 0
    for a, b, c in ABC:
        if d[a][b] < c:
            ans += 1
    return ans


def main():
    N, M = read_int_n()
    ABC = [read_int_n() for _ in range(M)]

    print(slv(N, M, ABC))


if __name__ == '__main__':
    main()


Measured memory_bytes: 64232
#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++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
const LL MOD = 1000000007LL;

int main() {
	LL X, Y;
	cin >> X >> Y;
	if (abs(X - Y) <= 1) {
		cout << "Brown" << endl;
	}
	else {
		cout << "Alice" << endl;
	}
}

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

int main()
{
	int n;
	cin >> n;
	long long int *b;
	int k = n / 2;
	int var = 0;
	var = n - 2 * k;
	b = new long long int[n];
	for (int i = 1; i <= n; i++) {
		cin >> b[k];
		if (var == 0) {
			k -= i;
			var++;
		}
		else {
			k += i;
			var--;
		}
	}
	cout << b[0];
	for (int i = 1; i < n; i++) {
		cout << " " << b[i];
	}
	return 0;
}



Measured memory_bytes: 3712
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VS s(n);
    REP(i,0,n) cin >> s[i];
    int a = 0,b = 0,c=0,d=0;
    REP(i,0,n) {
        if (s[i] == "AC") ++a;
        if (s[i] == "WA") ++b;
        if (s[i] == "TLE") ++c;
        if (s[i] == "RE") ++d;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 6420
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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() {
  int n,k; string s;
  cin >> n >> k >> s;
  s[k-1] -= 'A' -'a';
  cout << s << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <utility>    
using namespace std;
int N,A[100],ans=0;
int main(){
 cin>>N;
 for(int f=0;f<N;f++)cin>>A[f];
 for(int i=0;i<N-1;i++){
 
	int minj = i;
     for(int j=i+1;j<N;j++){
		 if (A[j] < A[minj]){
			 minj = j;}}
			 swap(A[i],A[minj]);
			 if(A[i]!=A[minj])ans++;}
 for(int i=0;i<N-1;i++)cout<<A[i]<<" ";
 cout<<A[N-1]<<endl<<ans<<endl;
return 0;
	}


Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int main()
{
	int N;
	scanf("%d", &N);
	printf("%d\n", (N - 1) / 2);
	return 0;
}


Measured memory_bytes: 760
#include <cstdio>

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if ((a*100 + b*10 + c) %4 == 0)
	{
		printf("YES");
	}
	else 
	{
		printf("NO");
	}
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
int sa[110],a,ans;
int main()
{
	cin>>a;
	for(int i=1;i<=2*a;i++)
	{
		cin>>sa[i];
	}
	sort(sa+1,sa+2*a+1,less<int>());
	for(int i=1;i<=2*a;i=i+2) 
	{
		ans+=sa[i];
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.awt.*;
import java.io.*;
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
//		new TestC().doIt();
		new TestD().doIt();
//		new TestE().doIt();
	}
	class TestE{
		void doIt(){
			int N = sc.nextInt();
			int K = sc.nextInt();
			int A[] = new int[N];
			for(int i = 0;i < N;i++){
				A[i] = sc.nextInt();
			}
			System.out.println(maxGCD(N,K,A));
		}
		int maxGCD(int N,int K,int A[]){
			int result = 0;
			for(int i = 1;i < 100;i++){
				int sum = 0;
				for(int j = 0;j < N;j++){
					if((A[j] % i) < i/2){
						sum = sum + A[j] % i;
					}else{
						sum = sum - i + (A[j] % i);
					}
				}
				System.out.println(i+" "+sum);
			}
			return 0;
		}
	}
	class TestD{
		void doIt(){
			String S = sc.next() + 'R';
			int length = S.length();
			char setRL[] = S.toCharArray();
			int children[] = new int[length];
			moveChildren(setRL,children,length);
			for(int i = 0;i < length-2;i++){
				System.out.print(children[i]+" ");
			}
			System.out.println(children[length - 2]);
		}
		void moveChildren(char RLSet[],int children[],int length){
			char c = 'R';
			int cnt = 1;
			for(int i = 1;i < length;i++) {
				if(RLSet[i] == c) {
					cnt++;
				}else {
					if(c == 'R') {
						children[i - 1] = children[i - 1] + (cnt / 2) + (cnt % 2);
						children[i] = children[i] + (cnt / 2);
						c = 'L';
						cnt = 1;
					}else {
						children[i - cnt - 1] = children[i - cnt - 1] + (cnt / 2);
						children[i - cnt] = children[i - cnt] + (cnt / 2) + (cnt % 2);
						c = 'R';
						cnt = 1;
					}
				}
			}
		}
	}
	class TestC{
		void doIt(){
			int N = sc.nextInt();
			int H[] = new int[N];
			for(int i = 0;i < N;i++){
				H[i] = Integer.parseInt(sc.next());
			}
			boolean result = canMonotonousDecrease(N,H);
			if(result){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
 		}
		boolean canMonotonousDecrease(int N,int H[]){
			for(int i = 1;i < N;i++){
				int diff = H[i] - H[i-1];
				if(diff > 0)H[i] = H[i] - 1;
				else if(diff < 0)return false;
			}
			return true;
		}
	}
}

Measured memory_bytes: 45976
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

main() {
    int64_t n;
    cin >> n;

    int64_t ans = numeric_limits<int64_t>::max();
    for (int64_t k = 1; k * k <= n; ++k) {
        if (n % k == 0) {
            auto l = n / k;

            ans = (k - 1) + (l - 1);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.Bool (bool)

main :: IO ()
main = do
  (_ : a : b : c : d : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  s <- T.getLine :: IO T.Text
  putStrLn . bool "No" "Yes" . solve a b c d $ s

solve a b c d s | c < d = check1 b d s && check1 a c s
                | otherwise = check1 b d s && check2 b d s && check1 a c s

check1 :: Int -> Int -> T.Text -> Bool
check1 a c s = fst . foldl step (True, False) . map T.length . T.group . T.take (c - (pred a)) . T.drop (pred a) $ s
  where
    step (True, False) _ = (True, True)
    step (True, True) l = (l <= 1, False)
    step p _ = p

check2 :: Int -> Int -> T.Text -> Bool
check2 b d s = fst . uncurry (foldl step . (,) False) . ((,) <$> (<= 1) . head <*> id) . map T.length . T.group . T.take (d - b + 3) . T.drop (pred $ pred b) $ s
  where
    step (False, True) _ = (False, False)
    step (False, False) l = (3 <= l, True)
    step p _ = p

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 2556
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
#define min(a,b) a > b ? b : a

int main(){
    int n;
    cin >> n;
    vector<ll> vec(n);
    int tmp;
    ll m = 2e9;
    int minus_cnt=0;
    ll ans = 0;
    rep(i,n) {
        cin >> tmp;
        if(tmp < 0) minus_cnt++;
        vec[i] = abs(tmp);
        ans += vec[i];
        m = min(vec[i],m);
    }
    
    if(minus_cnt % 2 == 0)
        cout << ans << endl;
    else
        cout << ans-2*m << endl;

    return 0;
}

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

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

    int n;
    cin >> n;
    int ans = -1e9;
    int minr;
    rep(i, n) {
        int R;
        cin >> R;
        if (!i) {
            minr = R;
            continue;
        }
        ans = max(ans, R - minr);
        minr = min(minr, R);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3188
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009
struct dice{
	int up;
	int down;
	int east;
	int west;
	int north;
	int south;
};
dice a;
char s[101];
int x;
void input(void){
	scanf("%d", &x);
	a.up = x;
	scanf("%d", &x);
	a.south = x;
	scanf("%d", &x);
	a.east = x;
	scanf("%d", &x);
	a.west = x;
	scanf("%d", &x);
	a.north = x;
	scanf("%d", &x);
	a.down = x;
}
void nr(void){
			x = a.north;
			a.north = a.up;
			a.up = a.south;
			a.south = a.down;
			a.down = x;
			return;
}
void sr(void){
			x = a.south;
			a.south = a.up;
			a.up = a.north;
			a.north = a.down;
			a.down = x;
			return;
}
void er(void){
	x = a.east;
	a.east = a.up;
	a.up = a.west;
	a.west = a.down;
	a.down = x;
	return;
}
void wr(void){
	x = a.west;
	a.west = a.up;
	a.up = a.east;
	a.east = a.down;
	a.down = x;
	return;
}
int main(void){
	int n;
	f(i, 101)s[i] = 0;
	input();
	scanf("%s", s);
	n = strlen(s);
	f(i, n){
		if (s[i] == 'N'){
			nr();
		}
		else if (s[i] == 'S'){
			sr();
		}
		else if (s[i] == 'E'){
			er();
		}
		else if (s[i] == 'W'){
			wr();
		}
	}
	printf("%d\n",a.up);
	return 0;
}

Measured memory_bytes: 2756
#include <stdio.h>

int main(){
  int i=0,j=0,n,m;
  char s[11],t[10];
  scanf("%d",&n);
  s[n]=0;
  for(i=0;i<n;i++){
    s[i]='a';
  }
  t[0]='b';
  i=0;
  while(s[0]=='a'){
    if(i==n-1){
      printf("%s\n",&s);
      s[i]++;
    }else{
      if(s[i]!=t[i]){
        i++;
        s[i]='a';
        m='a';
        for(j=0;j<i;j++){
          if(s[j]>m) m=s[j];
        }
        t[i]=m+2;
      }
    }
    if(s[i]==t[i]){
      i--;
      s[i]++;
    }
  }
  return(0);
}

Measured memory_bytes: 1408
import Data.Char
  ( digitToInt )

main :: IO ()
main = do
  n <- readLn
  putStrLn $ if isHarshad n then "Yes" else "No"

isHarshad
  :: Int -> Bool
isHarshad x 
  = let fx = sumDigits' x  
    in 0 == x `rem` fx

sumDigits, sumDigits'
  :: Int -> Int
sumDigits = sum . map digitToInt . show

sumDigits' = sum . int2lst
int2lst n
  | q == 0 = [r]
  | otherwise = r : int2lst q
  where
    (q,r) = divMod n 10

Measured memory_bytes: 508
import qualified Data.IntMap as M

main = do
 [n,w] <- map read . words <$> getLine
 wvs <- map (map read . words) . lines <$> getContents
 print (knap n w wvs)

knap n w wvs = maximum $ M.elems $ foldr dp (M.singleton 0 0) wvs
 where dp [w',v'] im = M.unionWith max im (M.filterWithKey (\k _ -> k<=w) $ M.mapKeys (+w') $ M.map (+v') im)

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

int main(){
	int n, m;
	int A[100][100], B[100], C[100]={0};
	int i, j;
	
	cin >> n >> m;
	
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			cin >> A[i][j];
		}
	}
		
	for(j = 0; j < m; j++){
		cin >> B[j];
	}
	
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			C[i] += A[i][j] * B[j];
		}
	}
	
	for(i = 0; i < n; i++){
		cout << C[i] << endl;
	}
	
	return 0;	
}

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

int main(){

	int i,j,H,W,N;
	int ans;
	int war;
	
	scanf("%d%d%d",&H,&W,&N);
	
	if(H>W){
	war = H;
	}
	else {
	war = W;
	}
	ans = (N%war==0 ? N/war: N/war+1);
	
	printf("%d\n",ans);	//printf("%ld %ld*(%ld - %ld)\n", cnt,edge,K,sa);
 return 0;
 }

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

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;

int main() {
#ifdef cute
	freopen("in", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);


	int a, b, c;
	cin >> a >> b >> c;
	cout << (((a+b+c) >= 22) ? "bust" : "win");


#ifdef cute
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms.\n";
#endif
}

// g++ o .cpp -O2 -std=c++11 -D cute -Wall -Wno-unused-result



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <float.h>
#include <iostream>
#include <map>
using namespace std;

int normalsort(const void* a, const void* b)
{
	long* pa = (long*)a;
	long* pb = (long*)b;
	return *pa - *pb;
}

int main()
{
	int nN,nK;
	cin >> nN >> nK;

	long lnHigh[100000];
	memset(lnHigh, 0, sizeof(lnHigh));
	for (int i = 0; i < nN; i++)
	{
		cin >> lnHigh[i];
	}
	qsort(lnHigh, nN, sizeof(long), normalsort);

	long lnMinDiff = 2147483647L;
	for (int i = 0; i < nN - nK+1; i++)
	{
		long lnDiff = lnHigh[i + nK - 1] - lnHigh[i];
		if (lnMinDiff > lnDiff)
			lnMinDiff = lnDiff;
	}

	cout << lnMinDiff;
	return 0;
}


Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
using namespace std;
int a,b,c;
int main()
{
    cin>>a>>b>>c;
    for(int i=1;i<=b;i++)
    {
        if((a*i)%b==c)
        {
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long int
#define P pair<ll, ll>
#define vii vector<P>
#define vvi vector<vector<ll>>
#define P_B push_back

#define MOD 1000000007
#define pi 3.141592653589793238


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

	// ll T; cin>>T; while(T--) 
	{
		
		ll n;
		cin>>n;

		vector<ll> v(n);
		for (int i = 0; i < n; i++) cin>>v[i];

		ll DP[n][n];

		for (ll l = n-1; l >= 0; l--) {

			for (int r = l; r < n; r++) {
				
				if(r == l) {
					DP[l][r] = 0;
					continue;
				}

				ll sum = 0;
				for (int i = l; i <= r; i++) sum += v[i];
				DP[l][r] = 1e18L;

				for (int p = l; p < r; p++) {
					DP[l][r] = min( DP[l][r] , DP[l][p] + DP[p+1][r] + sum);
				}
			}
			
		}

		cout<<DP[0][n-1];

	}	
	return 0;
}   

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

ll modiro(ll x,ll y){
    vector<ll> vec(30);
    rep(i,30){
        vec[i] = y;
        y = y * y % 1000000007;
    }
    ll c = x;
    c = c * vec[0] % 1000000007;
    c = c * vec[2] % 1000000007;
    c = c * vec[9] % 1000000007;
    c = c * vec[11] % 1000000007;
    c = c * vec[14] % 1000000007;
    c = c * vec[15] % 1000000007;
    c = c * vec[17] % 1000000007;
    c = c * vec[19] % 1000000007;
    c = c * vec[20] % 1000000007;
    c = c * vec[23] % 1000000007;
    c = c * vec[24] % 1000000007;
    c = c * vec[25] % 1000000007;
    c = c * vec[27] % 1000000007;
    c = c * vec[28] % 1000000007;
    c = c * vec[29] % 1000000007;
    return c;
}

vector<ll> binary(ll i, ll n, ll N){
    ll x = 1;
    rep(j,N){
        x *= n;
    }
    vector<ll> vec(N);
    rep(j,N){
        x /= n;
        vec[j] = i / x;
        i -= x * vec[j];
    }
    return vec;
}

int main(){
    ll N,a,b;
    cin >> N >> a >> b;
    ll keta;
    keta = 1;
    ll sub_N = N;
    while (sub_N / 2 != 0){
        sub_N /= 2;
        keta++;
    }
    vector<ll> vec(keta);
    vec = binary(N,2,keta);
    vector<ll> mojiro(keta);
    ll x = 2;
    for (ll i = 0; i < keta; i++){
        mojiro[i] = x;
        x = x * x % 1000000007;
    }
    ll ans = 1;
    for (ll i = 0; i < keta; i++){
        if (vec[keta - i - 1] == 1){
            ans = ans * mojiro[i] % 1000000007;
        }
    }
    ans--;
    ll a_sub = 1;
    for (ll i = 1; i <= a; i++){
        a_sub *= i;
        a_sub = a_sub % 1000000007;
    }
    ll na_sub = 1;
    for (ll i = (N - a + 1); i <= N; i++){
        na_sub *= i;
        na_sub = na_sub % 1000000007;
    }
    ll b_sub = 1;
    for (ll i = 1; i <= b; i++){
        b_sub *= i;
        b_sub = b_sub % 1000000007;
    }
    ll nb_sub = 1;
    for (ll i = (N - b + 1); i <= N; i++){
        nb_sub *= i;
        nb_sub = nb_sub % 1000000007;
    }
    ll asub = modiro(na_sub,a_sub) % 1000000007;
    ans = ans + 1000000007 - asub;
    ans = ans % 1000000007;
    ll bsub = modiro(nb_sub,b_sub) % 1000000007;
    ans = ans + 1000000007 - bsub;
    ans = ans % 1000000007;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N;
    cin >> N;
    vector<int> A = {105,135,165,189,195};
    cout << upper_bound(ALL(A),N) - A.begin() << "\n";
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n;

int main() {
	cin >> n;
	
	cout << n * (n + 1) / 2 << endl;
	
	return 0;
}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

class Parser {
public:
	using Iter = string::const_iterator;
	Iter it;
	Parser(Iter it) :it(it) {}
	void cmp(char expected) { if (*it != expected)cerr << *it << " is not " << expected << endl; assert(*it == expected); }
	/*
	EBNF
	???=???,{'+',???};
	???=integer,{'*',integer};
	*/
	int a() {
		int ret = b();
		while (true) {
			if (*it == '+') {
				it++;
				ret += b();
			}
			else break;
		}
		return ret;
	}
	int b() {
		int ret = integer();
		while (true) {
			if (*it == '*') {
				it++;
				ret *= integer();
			}
			else break;
		}
		return ret;
	}
	int integer() {
		int ret = 0;
		while (isdigit(*it)) {
			ret *= 10;
			ret += *it - '0';
			it++;
		}
		return ret;
	}
};

class Parser2 {
public:
	using Iter = string::const_iterator;
	Iter it;
	Parser2(Iter it) :it(it) {}
	void cmp(char expected) { if (*it != expected)cerr << *it << " is not " << expected << endl; assert(*it == expected); }
	/*
	EBNF
	???=integer,{('*'|'+'),integer};
	*/
	int a() {
		int ret = integer();
		while (true) {
			if (*it == '*') {
				it++;
				ret *= integer();
			}
			else if (*it == '+') {
				it++;
				ret += integer();
			}
			else break;
		}
		return ret;
	}
	int integer() {
		int ret = 0;
		while (isdigit(*it)) {
			ret *= 10;
			ret += *it - '0';
			it++;
		}
		return ret;
	}
};



signed main() {
	string s; getline(cin, s);
	s += "$";
	Parser P(s.begin());
	Parser2 P2(s.begin());
	int a; cin >> a;
	int a1 = P.a(), a2 = P2.a();
	if (a == a1&&a == a2)cout << "U" << endl;
	else if (a == a1)cout << "M" << endl;
	else if (a == a2)cout << "L" << endl;
	else cout << "I" << endl;
	return 0;
}

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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxn = 2e5 + 5;

int n, q;
ll ans;
int row[maxn], col[maxn];

class SegmentTree{
public:
	static const int siz = 262144;
	int dat[siz << 1];
	inline int size(){ return siz; }
	inline void build(int x, int l, int r){
		if(l == r){
			dat[x] = n - 1;
			return;
		}
		int md = l + r >> 1;
		build(x << 1, l, md);
		build(x << 1 | 1, md + 1, r);
		dat[x] = n - 1;
		return;
	}
	inline void update(int x, int l, int r, int s, int t, int k){
		if(l >= s && r <= t){
			dat[x] = min(dat[x], k);
			return;
		}
		int md = l + r >> 1;
		if(s <= md)
			update(x << 1, l, md, s, t, k);
		if(t > md)
			update(x << 1 | 1, md + 1, r, s, t, k);
		return;
	}
	inline int query(int x, int l, int r, int y){
		if(l == r)
			return dat[x];
		int md = l + r >> 1;
		if(y <= md)
			return min(dat[x], query(x << 1, l, md, y));
		return min(dat[x], query(x << 1 | 1, md + 1, r, y));
	}
}segc, segr;

int main(){
	scanf("%d%d", &n, &q);
	segc.build(1, 0, segc.size() - 1);
	segr.build(1, 0, segr.size() - 1);
	FOR(i, 0, q){
		int tp, x; scanf("%d%d", &tp, &x); --tp, --x;
		if(tp && !row[x]){
			int res = segc.query(1, 0, segc.size() - 1, x);
			--res;
			ans += max(0, res);
			segr.update(1, 0, segr.size() - 1, 1, res, x);
			row[x] = 1;
		}
		if(!tp && !col[x]){
			int res = segr.query(1, 0, segr.size() - 1, x);
			--res;
			ans += max(0, res);
			segc.update(1, 0, segc.size() - 1, 1, res, x);
			col[x] = 1;
		}
	}
	
	printf("%lld\n", 1ll * (n - 2) * (n - 2) - ans);
	return 0;
}


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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 1e6 + 7;
const int T = 1 << 17;

const int MX = 1e9 + 7;
const LL INF = 1LL * MX * MX;

int n, m;
LL dist[N];
bool vis[N];
vector <PII> G[N];

void addEdge(int from, int to, int id, int cost){
	from += T, to += T;
	while(from <= to){
		if(from & 1){
			G[from + n + m].push_back({id, 0});
			G[id].push_back({from + n + m + T + T, cost});
		}
		
		if(!(to & 1)){
			G[to + n + m].push_back({id, 0});
			G[id].push_back({to + n + m + T + T, cost});
		}
		
		from = (from + 1) >> 1;
		to = (to - 1) >> 1;
	}
}

void Dijkstra(){
	for(int i = 1; i <= n + m + 4 * T; ++i)
		dist[i] = INF;
	dist[1] = 0;

	priority_queue <PLL> Q;
	Q.push({0, 1});
	
	while(!Q.empty()){
		int u = Q.top().nd;
		Q.pop();
		
		if(vis[u])
			continue;
		vis[u] = true;
		
		for(auto v: G[u])
			if(dist[v.st] > dist[u] + v.nd){
				dist[v.st] = dist[u] + v.nd;
				Q.push({-dist[v.st], v.st});
			}
	}
}

int main(){
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= m; ++i){
		int l, r, c;
		scanf("%d %d %d", &l, &r, &c);
		addEdge(l, r, i + n, c);
	}
	
	for(int i = 1; i <= n; ++i){
		G[i].push_back({n + m + T + i, 0});
		G[n + m + 3 * T + i].push_back({i, 0});
	}
	
	for(int i = 2; i < T + T; ++i){
		G[i + n + m].push_back({i / 2 + n + m, 0});
		G[i / 2 + n + m + T + T].push_back({i + n + m + T + T, 0});
	}
	
	Dijkstra();
	if(dist[n] == INF)
		puts("-1");
	else
		printf("%lld\n", dist[n]);
	return 0;
}

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

using namespace std;

int main() {
  int N;

  cin >> N;
  vector<int> Ws(N);
  for (int i = 0; i < N; i++) {
    cin >> Ws[i];
  }

  vector<int> rsw(N);
  rsw[0] = Ws[0];
  for (int i = 1; i < N; i++) {
    rsw[i] = rsw[i-1] + Ws[i];
  }

  int mini = 100000000;
  int T = 0;

  for (int i = 0; i < N; i++) {
    if ((int)abs((rsw[N-1] - rsw[i]) - rsw[i]) < mini) {
      T = i;
      mini = (int)abs((rsw[N-1] - rsw[i]) - rsw[i]);
    } else {
      break;
    }
  }

  cout << mini << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
main(){int a,b,d=0,c;while(scanf("%d%d",&a,&b),a){if(d++)puts("");c=0;for(;a<=b;a++)if(a%4<1)if(a%25||a%16<1)c++,printf("%d\n",a);if(!c)puts("NA");}}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int co = 0;
	while (a >= b) {
		b *= 2;
		co++;
	}
	while (b >= c) {
		c *= 2;
		co++;
	}
	if (co <= k) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		String ans = "";
		for(int i = 0; i < 3; i++) {
			String str = n.substring(i,i+1);
			if("1".equals(str)) {
				ans += "9";
			} else {
				ans += "1";
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21588
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=200005;

int N,M;
int A[MAXN],cnt[MAXN];
int cov[MAXN];

int main()
{
	scanf("%d%d",&N,&M);
	for(int i=1;i<=N;i++)
	{
		scanf("%d",&A[i]);
		cnt[A[i]]++;
	}
	int ans=N;
	for(int i=1;i<=N;i++)
		for(int j=i-cnt[i]+1;j<=i;j++)
		{
			if(cov[max(1,j)]==0)
				ans--;
			cov[max(1,j)]++;
		}
	for(int i=1;i<=M;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		cov[max(1,A[x]-cnt[A[x]]+1)]--;
		if(cov[max(1,A[x]-cnt[A[x]]+1)]==0)
			ans++;
		cnt[A[x]]--;
		A[x]=y;
		cnt[y]++;
		if(cov[max(1,y-cnt[y]+1)]==0)
			ans--;
		cov[max(1,y-cnt[y]+1)]++;
		printf("%d\n",ans);
	}
		
	
	return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  bool a = false;
  int N;
  cin >> N;
  int B;
  for ( int i = 0 ; i < N ; i++ ) {
    cin >> B;
    if ( B % 2 == 0 ) {
      if (B % 3 == 0 || B % 5 == 0 ) {
      }
      else {
        a = true;
      }
    }
    B = 0;
  }
  if ( a ) {
    cout << "DENIED" << endl;
  }
  else { 
    cout << "APPROVED" << endl;
  }
}

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

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

Measured memory_bytes: 256
N = int(input())
X = list(map(int, input()))
# N = 2*10**5
# X = list(map(int, "10"*(N//2)))

Xp = sum(X)
        
# print(Xp)
a = 0
b = 0
# c = 0
# :N
for i, x in enumerate(X):
    i_reverse = N-i-1
    if Xp > 1:
        a = (a + x * pow(2, i_reverse, Xp-1)) % (Xp-1)
    b = (b + x * pow(2, i_reverse, Xp+1)) % (Xp+1)
    # c = (c + x * (1<<i_reverse))
    # print(bin(c))

# print(a, b)

# :N
for i in range(N):
    i_reverse = N-i-1
    if Xp > 1:
        m = ([a, b][X[i]==0] + [-1, 1][X[i]==0] * pow(2, i_reverse, [Xp-1, Xp+1][X[i]==0])) % [Xp-1, Xp+1][X[i]==0]
    else:
        if X[i]==0:
            m = (b + pow(2, i_reverse, Xp+1)) % (Xp+1)
        else:
            print(0)
            continue
    count = 1
    # print(i, ([a, b][X[i]==0], [-1, 1][X[i]==0]*(1<<i_reverse)), [Xp-1, Xp+1][X[i]==0], X[i]==0)
    # print(m)
    while m > 0:
        p = sum([int(c) for c in str(bin(m)[2:])])
        m = m % p
        count += 1
    print(count)


Measured memory_bytes: 86628
def main():
    n = int(input())
    h = list(map(int, input().split()))
    dp = [10**10]*n
    dp[0] = 0
    for i in range(n):
        if i + 1 < n and dp[i] + abs(h[i] - h[i+1]) < dp[i+1]:
            dp[i+1] = dp[i] + abs(h[i] - h[i+1])
        if i + 2 < n and dp[i] + abs(h[i] - h[i+2]) < dp[i+2]:
            dp[i+2] = dp[i] + abs(h[i] - h[i+2])
    print(dp[n-1])

if __name__ == "__main__":
    main()


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

int main(){
	string S,T;
	char ans[200]={};
	int N,i,count=0;

	cin>>N;
	cin>>S>>T;

	for(i=0;i<N*2;i+=2){
		ans[i]=S[count];
		ans[i+1]=T[count];
		count++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>

typedef long long ll;
using namespace std;
const int mod = 1000000007;

const int MAX = 1000;
int H, N;
vector<int> A(MAX), B(MAX);
vector<int> HP(10001, 100000000);
int f(int hp, int ind);

int main() {

    
    cin >> H >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }

    for (int hp = 1; hp <= H; hp++) {
        for (int ind = 0; ind < N; ind++) {
            HP[hp] = min(HP[hp], f(hp, ind));
        }
    }
    cout << HP[H] << '\n';

}

int f(int hp, int ind) {
    if (A[ind] >= hp)
        return B[ind];
    else
        return B[ind] + HP[hp - A[ind]];
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
int main()
{
    //int k,i,j,tep,x,a[170],m;
    int a,b,c,d,e,f,n;
   // long long int n;
    while(cin>>a>>b)
    {
        cout<<(int)log10(a+b)+1<<endl;
    }

    return 0;
}

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

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

	for(int m, n_min, n_max; cin >> m >> n_min >> n_max && m;) {
		vector<int> p(m);
		for(auto &e : p) cin >> e;

		int ans = -1;
		int mx = -1;
		for(int n = n_min; n <= n_max; ++n) {
			const int gap = p[n - 1] - p[n];
			if(mx <= gap) {
				ans = n;
				mx = gap;
			}
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

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

string s;
int ans = 0,cnt = 0;
int n;
int main(){
    cin >> n;
    if(!(n & 1)){
        cout << -1 << endl;
        return 0;
    }
    while(cnt <= 1e6){
        ans = ans * 10 + 7;
        cnt++;
        if(ans % n == 0){
            break;
        }
        ans %= n;
    }
    if(cnt <= 1e6) cout << cnt << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll n, mx;
ll d[105];

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        ll t;
        scanf("%lld", &t);
        d[t]++;
        mx = max(mx, t);
    }
    for(ll i = 0; i <= mx; i++)
    {
        ll t = max(i, mx - i);
        if(d[t] == 0)
        {
            printf("Impossible\n");
            return 0;
        }
        d[t]--;
    }
    for(ll i = 0; i <= (mx + 1) / 2; i++)
    {
        if(d[i] > 0)
        {
            printf("Impossible\n");
            return 0;
        }
    }
    printf("Possible\n");
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    private static final String YES = "Yes";
    private static final String NO  = "No";
    private static String REGIX = " ";


    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] numArray = br.readLine().split(REGIX);

        int a = Integer.parseInt(numArray[0]);
        int b = Integer.parseInt(numArray[1]);
        int c = Integer.parseInt(numArray[2]);

        System.out.println((isSmallNumber(a, b) && isSmallNumber(b, c)) ? YES : NO);

    }

    private static boolean isSmallNumber(int a, int b) {
        return a < b;
    }
}

Measured memory_bytes: 24340
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=5000+10;

int n;
string s;
int f[maxn][maxn];
int kq;

int main(){
  cin>>n>>s;s=" "+s;
  for(int i=1;i<=n-1;i++)
    if (s[i]==s[i+1]) f[i][i+1]=1;
    else f[i][i+1]=0;
  for(int i=1;i<=n;i++)
    for(int j=i+2;j<=n;j++)
      if (s[i]==s[j]) f[i][j]=f[i-1][j-1]+1;
      else f[i][j]=0;
  //for()
  kq=0;
  for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
      if (f[i][j]>=1){
        kq=max(kq,min(f[i][j],j-i));
      }
  cout<<kq;
}


Measured memory_bytes: 96896
#include <stdio.h>
int main(){
    char S[11];
    char T[12];
    int i,j;
    int k=0;
    scanf("%s",&S);
    scanf("%s",&T);
    for(j=0; S[j]!='\0'; ++j);
//    printf("入力した文字列は「%d」文字です。\n",j);
    
    for(i=0;i<j+1;i++){
        if(S[i]==T[i]){
//            printf("Yes");
//            printf("%c %c\n",S[i],T[i]);
            k++;
        }
        else{
//            printf("No");
//            printf("%c %c\n",S[i],T[i]);
            k=k;
        }
    }
//    printf("%d",k);
    if(k==j){
        printf("Yes");
    }
    else{
        printf("No");
    }
    
}

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

void trans(char *x, char *y, int v)
{
    while (v++ < 81) *x = '0', x++;
    strcat(x, y);
}
 
int main(void)
{
    int n;
    char a[128], b[128];
    char x[128], y[128];
    char *output;

    scanf("%d", &n);
    while (n--){

        output = "overflow";
        scanf("%81s %81s", a, b);
        if (fmax(strlen(a), strlen(b)) < 81){
            int carry, i;
 
            memset(x, 0, sizeof(x));
            memset(y, 0, sizeof(y));
 
            trans(x, a, strlen(a));
            trans(y, b, strlen(b));
             
            for (carry = i = 0; i < 81; i++){
                int v = x[80 - i] - '0' + y[80 - i] - '0' + carry;
                carry = v > 9;
                x[80 - i] = v % 10 + '0';
            }
            for (i = 0; i < 80 && x[i] == '0'; i++);
            if (i) output = x + i;
        }
        puts(output);
    }
    return (0);
}

Measured memory_bytes: 596
N, K = map(int, input().split())
h = list(map(int, input().split()))

cost = [0] + [float("inf")] * (N-1)

for i in range(1, N):
    for back in range(1, K+1):
        try:
            cost[i] = min(cost[i], cost[i-back] + abs(h[i] - h[i-back]))
        except IndexError:
            break

print(cost[-1])

Measured memory_bytes: 55648
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    cin>>N;
    vec a(N);
    rep(i,N) cin>>a[i];
    ll ans = INF;
    reps(i, 1, 101){
        ll temp = 0;
        rep(j,N) temp += (i - a[j]) * (i - a[j]);
        ans = min(temp, ans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,f,n) for(int i=f; i<(n); i++)
int main()
{

  string s="aa";
  char good[4] = {'A', 'C', 'G', 'T'};
  int ans = 0;
  cin >> s;
  s+="O";
  int size = s.length();
  REP(i,0,size){
    REP(j,0,4){
      if(s[i] == good[j]){
        int count=1;
        REP(i2,i+1,size){
          bool ok = false;
          REP(j2,0,4){
            if(s[i2] == good[j2]){
              count++;
              ok=true;
              break;
            }
          }
          if(ok==false || i2==size-1){
            if(ans<count){
              ans=count;
            }
            break;
          }
        }
      }
    }
  }

  cout << ans << endl;

  //--debug_end_stoper
  //string nanikayo; cin >> nanikayo;

  return 0;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        int w = sc.nextInt();
        int[][] arr = new int[n][2];

        for (int i=0; i<n; i++) {
            arr[i][0] = sc.nextInt();
            arr[i][1] = sc.nextInt();
        }

        int[][] dp = new int[n+1][n*1000+1];

        for (int i=0; i<n+1; i++) {
            for (int j=0; j<n*1000+1; j++) {
                dp[i][j] = (int)1e9 + 10;
            }
        }

        dp[0][0] = 0;

        for (int i=1; i<=n; i++) {
            for (int j=0; j<=n*1000; j++) {
                if (j < arr[i-1][1]) {
                    dp[i][j] = dp[i-1][j];
                } else {
                    dp[i][j] = Math.min(dp[i-1][j], dp[i-1][j-arr[i-1][1]] + arr[i-1][0]);
                }
            }
        }

        int ret = 0;

        for (int i=0; i<=n*1000; i++) {
            if (dp[n][i] <= w) ret = i;
//            System.out.println(dp[n][i]);
        }

        System.out.println(ret);

    }
}



Measured memory_bytes: 83520
def move(tiles, visited, i, j):
    visited[i][j] = True
    if tiles[i][j] == '.':
        return i, j
    elif tiles[i][j] == '>':
        if visited[i][j + 1]:
            return -1, -1
        return move(tiles, visited, i, j + 1)
    elif tiles[i][j] == '<':
        if visited[i][j - 1]:
            return -1, -1
        return move(tiles, visited, i, j - 1)
    elif tiles[i][j] == '^':
        if visited[i - 1][j]:
            return -1, -1
        return move(tiles, visited, i - 1, j)
    else:
        if visited[i + 1][j]:
            return -1, -1
        return move(tiles, visited, i + 1, j)

while True:
    y, x = map(int, raw_input().split())
    if x == 0 and y == 0:
        break

    tiles = []
    visited = [[0 for i in range(x)] for j in range(y)]
    for i in range(y):
        tiles.append(raw_input())
    y, x = move(tiles, visited, 0, 0)
    if x == -1: print "LOOP"
    else: print x, y

Measured memory_bytes: 4616
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;

long long int maxmin(long long int num,long long int l){
	long long int tmp[10]={},ma=0,mi=0;
	for(int i=0;i<l;i++){
		tmp[i]=num%10;
		num/=10;
	}	
	sort(tmp,tmp+l);
	for(int i=0;i<l;i++){
		mi=mi*10+tmp[i];
		ma=ma*10+tmp[l-i-1];	
	}
	return ma-mi;
}

int main() {
	cout << fixed << setprecision(5);
	long long int a,l;
	cin>>a>>l;
	while(l!=0){
		long long int tmp[50]={};
		bool key=false;
		tmp[0]=a;
		for(int i=1;i<=25;i++){
			tmp[i]=maxmin(tmp[i-1],l);
			for(int j=0;j<i;j++){
				if(tmp[i]==tmp[j]){cout<<j<<" "<<tmp[i]<<" "<<i-j<<endl;key=true;break;}	
			}	
			if(key){break;}
		}
		cin>>a>>l;
	}
}



Measured memory_bytes: 3120
#include<cstdio>
#include<algorithm>
using namespace std;
long long D[3010][3010], S[3010], Mod = 1000000007, res;
int n;
char p[3010];
int main() {
	int i, j;
	scanf("%d", &n);
	scanf("%s", p + 1);
	D[1][1] = 1;
	for (i = 2; i <= n; i++) {
		for (j = 0; j <= i; j++)S[j] = 0;
		if (p[i - 1] == '<') {
			for (j = 1; j < i; j++) {
				S[j + 1] = (S[j + 1] + D[i - 1][j]) % Mod;
			}
		}
		else {
			for (j = 1; j < i; j++) {
				S[j + 1] = (S[j + 1] + Mod - D[i - 1][j]) % Mod;
				S[1] = (S[1] + D[i - 1][j]) % Mod;
			}
		}
		for (j = 1; j <= i; j++) {
			S[j] = (S[j - 1] + S[j]) % Mod;
			D[i][j] = S[j];
		}
	}
	for (i = 1; i <= n; i++)res = (res + D[n][i]) % Mod;
	printf("%lld\n", res);
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

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 ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  string s;
  cin >> s;
  int ans=0;
  int cnt=0;
  REP(i,s.size()){
    if(s[i]=='A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C'){
      cnt++;
      chmax(ans, cnt);
    }else{
      cnt = 0;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
// 左から順番にみていくとして、i=1からスタートすると
// i-1よりもiを優先的に犠牲にしたほうがいい
// （i+1にも影響を与えてくれるので）
// 1. A[i] + A[i-1] <= x -> そのまま
// 2. 1以外:
//			2.1. A[i] >=x -> A[i]だけ必要なぶん犠牲にして減らす
//			2.2 2.1以外 -> A[i-1]も犠牲にする
package main

import "fmt"

func main() {
	var N, X int
	fmt.Scan(&N, &X)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		var V int
		fmt.Scan(&V)
		A[i] = V
	}
	ans := 0
	for i := 1; i < N; i++ {
		if A[i-1]+A[i] <= X {
			continue
		} else {
			hikubun := (A[i] + A[i-1]) - X
			ans += hikubun
			if A[i] >= hikubun {
				A[i] -= hikubun
			} else {
				// A[i-1]も減るけどどうせ今後登場しないので無視
				// と思ったらなんか答えが変なので一回みてみるために引く
				A[i-1] -= hikubun - A[i]
				A[i] = 0
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,1,0,-1,-1,-1,0,1}, dy[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

   int h, w;
   char c[50][50];
   cin >> h >> w;
   REP(i, h){
      REP(j, w) cin >> c[i][j];
   }

   REP(i, h){
      REP(j, w){
         if(c[i][j] == '.'){
            int a = 0;
            REP(k, 8){
               if(i+dx[k]>=0 && i+dx[k]<h && j+dy[k]>=0 && j+dy[k]<w && c[i+dx[k]][j+dy[k]] == '#') a++;
            }
            c[i][j] = a + 48;
         }
         cout << c[i][j];
      }
      cout << endl;
   }

   rtn 0;
}

Measured memory_bytes: 256
N, A, B =map(int,input().split())

al = []
for i in range(1, N + 1):
    checkno = 0

    for j in range(len(str(i))):
        str_i = str(i)
        checkno += int(str_i[j])
    if A <= checkno and checkno <= B:
        al.append(i)

print(sum(al))


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

#define endl '\n'

long long s[123456];

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  sort(a, a+n);
  int sum = 0;
  for(int i=0; i<k; i++) {
    sum += a[i];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
#define MAXN 100000000
int h,w,k,x,y;
long long memory[MAXN], ans[12];
int Sep,tot;
long long z;
int main() {
	scanf("%d%d%d",&h,&w,&k);
	z=1ll*(h-2)*(w-2);
	for(int p=1;p<=k;p++) {
		scanf("%d%d",&x,&y);
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				if(1<=x-i&&x-i<=h-2 && 1<=y-j&&y-j<=w-2)
					memory[++tot]=MAXN*(x-i)+(y-j);
	}
	sort(memory+1,memory+1+tot);
	int cnt=1;
	for(int i=1;i<=tot;i++) {
		if(memory[i]==memory[i+1])
			cnt++;
		else
			ans[cnt]++, cnt=1, z--;
	}
	printf("%lld\n",z);
	for(int i=1;i<=9;i++)
		printf("%lld\n",ans[i]);
}

Measured memory_bytes: 9080