akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int n;
char s[111];
int Min[666];
int Now[666];

int main(){
    memset(Min, 0x3f, sizeof(Min));
    scanf("%d", &n);
    while(n--){
        memset(Now, 0, sizeof(Now));
        scanf("%s", s + 1);
        int Length = strlen(s + 1);
        for(int i = 1; i <= Length; i++) Now[s[i]]++;
        for(int i = 'a'; i <= 'z'; i++) Min[i] = min(Min[i], Now[i]);
    }
    for(int i = 'a'; i <= 'z'; i++){
        for(int k = 1; k <= Min[i]; k++){
            printf("%c",(char)i);
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int A,B,k;
  scanf("%d %d",&A,&B);
  if(A>B)
    k=A+A-1;
  if(A<B)
    k=B+B-1;
  if(A==B)
    k=A+B;
  printf("%d \n",k);
  return 0;
}

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

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

    long long int X;

    cin>>X;

    long long int ans = 0, yen_500 = 0, yen_5 = 0;
    yen_500 = X/500;
    X %= 500;
    yen_5 = X/5;

    cout<<1000*yen_500+5*yen_5<<endl;

    return 0;
}


Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 50 + 7 ;

int T ;

int n ;
vector <int> g[2][N] ;

int par[2][N] , deg[N] ;
bool mark[2][N] ;
vector <int> child[2][N] ;

inline void init_get () {
	for (int i = 0 ; i < n ; i ++) {
		deg[i] = 0 ;
		for (int id : {0 , 1}) {
			par[id][i] = -1 ;
			mark[id][i] = 0 ;
			child[id][i].clear() ;
		}
	}
}

void pre_dfs (int v , int id) {
	for (int u : g[id][v]) {
		if (u == par[id][v]) continue ;
		par[id][u] = v ;
		child[id][v].push_back(u) ;
		pre_dfs(u , id) ;
	}
}

void dfs (int v) {
	mark[0][v] = mark[1][v] = 1 ;

	for (int u : child[0][v])
		if (v == par[1][u]) dfs(u) ;
}

inline int get (int root) {
	init_get() ;

	for (int id : {0 , 1}) {
		par[id][root] = -1 ;
		pre_dfs(root , id) ;
	}

	dfs(root) ;

	int ans = n ;

	for (int i = 0 ; i < n ; i ++) {
		if (mark[0][i] && mark[1][i]) {
			ans -- ;
			for (int j : child[1][i]) mark[1][j] = 1 ;
		}
	}

	int need = ans ;
	queue <int> que ;

	for (int i = 0 ; i < n ; i ++) {
		if (mark[0][i] && mark[1][i]) continue ;

		deg[i] = child[0][i].size() ;
		if (!deg[i]) {
			mark[0][i] = 1 ;
			if (mark[0][i] && mark[1][i]) que.push(i) ;
		}
	}

	while (_sz(que)) {
		int v = que.front() ;
		que.pop() ;
		need -- ;
	
		for (int u : child[1][v]) {
			mark[1][u] = 1 ;
			if (mark[0][u] && mark[1][u]) que.push(u) ;
		}

		{
			int u = par[0][v] ;
			if (!mark[0][u]) {
				deg[u] -- ;
				if (!deg[u]) mark[0][u] = 1 ;
				if (mark[0][u] && mark[1][u]) que.push(u) ;
			}
		}	
	}

	if (need) ans = n + 5 ;

	if (ans == n + 5 && g[0][root].size() == 1) {
		init_get() ;

		pre_dfs(root , 1) ;

		for (int i = 0 ; i < n ; i ++) {
			deg[i] = g[0][i].size() ;
			if (deg[i] == 1) mark[0][i] = 1 ;
		}
	
		mark[0][root] = mark[1][root] = 1 ;
		que.push(root) ;

		need = n ;
		while (_sz(que)) {
			int v = que.front() ;
			que.pop() ;
			need -- ;

			for (int u : child[1][v]) {
				mark[1][u] = 1 ;
				if (mark[0][u] && mark[1][u]) que.push(u) ;
			}

			{
				int u = -1 ;
				
				for (int x : g[0][v]) if (!mark[0][x]) u = x ;

				if (u != -1) {
					if (mark[0][u] && mark[1][u]) assert(0) ;
					deg[u] -- ;
					if (deg[u] == 1) mark[0][u] = 1 ;
					if (mark[0][u] && mark[1][u]) que.push(u) ;
				}
			}

			if (!need) ans = n ;
		}
	}

	return ans ;
}

inline void init_solve () {
	init_get() ;
	for (int i = 0 ; i < n ; i ++) g[0][i].clear() , g[1][i].clear() ;
	n = 0 ; // Just for fun 
}

inline void solve () {
	init_solve() ;

	cin >> n ;

	for (int id : {0 , 1}) {
		for (int i = 0 , u , v ; i < n - 1 ; i ++) {
			cin >> u >> v ;
			u -- , v -- ;
			g[id][u].push_back(v) ;
			g[id][v].push_back(u) ;
		}
	}


	int ans = n + 5 ;
	for (int i = 0 ; i < n ; i ++) ans = min(ans , get(i)) ;

	if (ans > n) ans = -1 ;

	cout << ans << '\n' ;
}

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

	cin >> T ;

	while (T --) solve() ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll tms[30],sz[30],ans=0,n,tree[N];
vector<ll> pc[30];
bool book[N];
ll ant_num(ll x)
{
	ll ant=0;
	while(x!=0)
	{
		ant+=tree[x];
		x=x&(x-1);
	}
	return ant;
}
void min_ant(ll x)
{
	while(x<=n)
	{
		tree[x]--;
		x+=x&(-x);
	}
	return;
}
int main(){
	ll i,t,p1,p2;
	string s;
	cin>>s;
	n=s.size();
	memset(sz,0,sizeof(sz));
	memset(tms,0,sizeof(tms));
	for(i=0;i<s.size();i++)
	{
		tree[i+1]=(i+1)&(-(i+1));
		pc[s[i]-'a'].push_back(i);
		tms[s[i]-'a']++;
		sz[s[i]-'a']++;
	}
	for(i=0;i<26;i++)
	{
		if(tms[i]%2==1)
		{
			ans++;
		}
	}
	if(ans>1)
	{
		cout<<-1<<endl;
		return 0;
	}
	memset(book,false,sizeof(book));
	ans=0;
	//树状数组维护逆序对的个数 
	for(i=0;i<n;i++)
	{
		if(book[i])
		{
			continue;
		}
		p1=pc[s[i]-'a'][sz[s[i]-'a']-1];
		sz[s[i]-'a']--;
		if(p1==i)
		{
			ans+=(ant_num(n)-ant_num(p1+1))/2;
		}
		else
		{
			ans+=ant_num(n)-ant_num(p1+1);
		}
		book[p1]=true;
		book[i]=true;
		min_ant(i+1);
		min_ant(p1+1);
	}
	cout<<ans<<endl;
	return 0;
} 

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

int main() {

  int N;
  cin >> N;

  map<int, int, greater<int>> A;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[a]++;
  }
  
  int sideA = 0;
  int sideB = 0;

  for (auto item: A) {
    if (4 <= item.second) {
      if (sideA == 0) {
        sideA = item.first;
      }
      if (sideB == 0) {
        sideB = item.first;
        break;
      }
    } else if (2 <= item.second) {
      if (sideA == 0) {
        sideA = item.first;
      } else if (sideB == 0) {
        sideB = item.first;
        break;
      }
    }
  }

  long long answer = (long long) sideA * sideB;
  
  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 4992
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a= sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        System.out.println(Math.min(b/a,c));
    }
}


Measured memory_bytes: 21716
N = int(input())
Alist = list(map(int, input().split()))
Alist = [Alist[i] - (i+1) for i in range(N)]
Alist.sort()

b = Alist[N//2]

ans = 0
for i in range(N):
    ans += abs(Alist[i] - b)
print(ans)

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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

// policy-based
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;	


using namespace std;


typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

/*
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
 
const ll MAX = 2e6+100;
const ll inf = 1e15;

ll a[MAX];
int main(){
	fastio;
	ll n,b = 0;
	cin >> n;
	f(i,1,n+1) cin >> a[i];
	ll ans = 0;
	f(i,1,n+1){
		b = max(b,a[i]);
		ans += b - a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 5116
N = int(input())
A = list(input().split())
flag = 0
for i in range(N):
    A[i] = int(A[i])
    if A[i] == 0:
        flag = -1
sum = 1

for i in range(N):
    if sum <= 10**18:
        sum = sum * A[i]
    else:
        break


if sum <= 10**18:
    print(sum)
else:
    if flag == -1:
        print(0)
    else:
        print(-1)

Measured memory_bytes: 19400
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  ll acc = A[0];
  ll ans = 1LL << 62;
  for(int i = 1; i < N; i++) {
    ans = min(ans, abs(acc - (sum - acc)));
    acc += A[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
from collections import Counter
N = int(input())
A = sorted(map(int, input().split()), reverse=False)
m = max(A)+1
c = Counter(A)
s = list(set(A))
dp = [True] * m
for x in list(set(A)):
    t = x * 2
    while t < m:
        dp[t] = False
        t += x
ans = 0
for a in A:
    if c[a] == 1 and dp[a]:
        ans += 1
print(ans)



Measured memory_bytes: 170024
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array

# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

# 再帰の制限設定
sys.setrecursionlimit(10000000)


def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
                    for _ in range(n)]


def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
                    for _ in range(n)]


def lcm(x, y): return (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    T = iss()

    ret = set()
    for i in range(len(S)-len(T)+1):
        for s, t in zip(S[i:i+len(T)], T):
            if s == t or s == '?': continue
            else: break
        else:
            tmp = ''
            if i != 0: tmp += S[:i]
            tmp += T
            if i+len(T) < len(S): tmp += S[i+len(T):]
            ret.add(tmp.replace('?', 'a'))

    if len(ret) == 0:
        print('UNRESTORABLE')
    else:
        print(sorted(list(ret))[0])


if __name__ == '__main__':
    main()


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

int main(){
	ll a=0,b=0,k=0;
	cin>>a>>b>>k;
	ll cnt=0;
	ll m = max(a,b);
	for(int i=1;i<m+1;i++){
		if(a%i==0&&b%i==0){
			cnt++;
			//cout<<"i:"<<i<<endl;
		}
	}
	ll cnt2 = 0;
	for(int i=1;i<m+1;i++){
		if(a%i==0&&b%i==0){
			cnt2++;
			//cout<<"i:"<<i<<endl;
		}
		if(cnt-cnt2+1==k){
			cout<<i<<endl;
			break;
		}
	}
}


Measured memory_bytes: 256
import sys,os,re
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations
sys.setrecursionlimit(10**6)

while 1:
    s=int(input())
    if s==0:
        break
    s=str(s)
    cnt=0
    for i in s:
        cnt+=int(i)
    print(cnt)


Measured memory_bytes: 6492
<?php
 
  $num=trim(fgets(STDIN));
  $nums = explode(' ',trim(fgets(STDIN)));

$kai = 0;
while(1){
  $newNum = [];
  foreach($nums as $num){
    if($num%2 == 1){
      echo $kai;
      return;
    }
    $newNum[] = $num/2;
  }
  $nums = $newNum;
    $kai++;
}

?>

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

int main()
{
    int n, x, t;
    cin >> n >> x >> t;
    if ((n % x) == 0) {
        cout << ((n / x)) * t << endl;
    }
    else {
        cout << ((n / x) + 1) * t << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  random_device rd;
  mt19937 mt(rd());
  uniform_int_distribution<ll> a(1,26);
  vector<ll> day(26);
  rep(i,365) {
    cout << 26 - i%26 << '\n';
  }
}

Measured memory_bytes: 3680
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, X, T = MAP()

    cnt = 0
    for i in range(1000):
        if (i + 1)*X >= N:
            print((cnt + 1)*T)
            exit()
        cnt += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 9980
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    int n;
    scanf("%d",&n);
    vector<int> p(n,0);
    for (int i = 0; i < n; i++) scanf("%d",&p[i]);
    bool ok = true;
    bool flag = true;
    for (int i = 0; i < n; i++) {
        if (p[i] != i+1 && flag) {
            if (p[p[i]-1] == i+1) {
                p[p[i]-1] = p[i];
                p[i] = i + 1;
                flag = false;
            } else {
                ok = false;
                break;
            }
        } else if (p[i] != i+1) {
            ok = false;
            break;
        }
    }
    if (ok) printf("YES\n");
    else printf("NO\n");
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int ans1=min(a,b);
    int ans2=max(0,a+b-n);
    cout<<ans1<<" "<<ans2<<endl;
}


Measured memory_bytes: 3576
#include <iostream>
#include <math.h>
using namespace std;
int main () {
  int n = 0;
  cin >> n;
  int dp[n+1] = {};

  for (int k = 1; k <= n; k++) {
    dp[k] = k;
    for (int i = 9; i <= k; i=i*9) {
      if (dp[k] > dp[k-i]+1) dp[k] = dp[k-i]+1;
    }
    for (int i = 6; i <= k; i=i*6) {
      if (dp[k] > dp[k-i]+1) dp[k] = dp[k-i]+1;
    }
  }
  cout << dp[n];
  return 0;
}


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

int main() {
	for( ;; ) {
		int m, f, r;
		cin >> m >> f >> r;

		if( m == -1 && f == -1 && r == -1 ) {
			break;
		}

		char result = 'F';

		if( m == -1 || f == -1 ) {
			result = 'F';
		}
		else if( m+f >= 80 ) {
			result = 'A';
		}
		else if( m+f >= 65 ) {
			result = 'B';
		}
		else if( m+f >= 50 ) {
			result = 'C';
		}
		else if( m+f >= 30 ) {
			result = (r >= 50 ? 'C' : 'D');
		}

		cout << result << endl;
	}
}



Measured memory_bytes: 3076
#include <iostream>
using namespace std; // consider removing this line in serious projects

int main() {
	int row, column;
	cin>>row;
	cin>>column;
	int out[row+1][column+1];
	
	for(int i=0; i<row+1; i++){
		for(int j=0; j<column+1; j++){
			out[i][j]=0;
		}
	}
	for(int i=0; i<row; i++){
		int sum=0;
		int num_in=0;
		for(int j=0; j<column; j++){
			cin >> num_in;
			out[i][j]=num_in;
			out[row][j]+=num_in;
			out[i][column]+=num_in;
			out[row][column]+=num_in;
		}
	}
	
	for(int i =0;i<row+1;i++){
		for(int j=0;j<column+1;j++){
			if(j != column)
				cout << out[i][j] << " ";
			else 
				cout << out[i][j];
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			long x = sc.nextLong();
			long t = sc.nextLong();

			if (x < t) {
				System.out.println(0);
			} else {
				System.out.println(x - t);
			}
		}
	}
}


Measured memory_bytes: 23636
n = gets.to_s.to_i

h = Array.new(n, 0)
ans = 0
d = $<.read.split.map{_1.to_i}.each_with_index do |e, i|
  ans      += h[i - e] if i - e >= 0
  h[i + e] += 1        if i + e < n
end

puts ans

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


int main(){
    long N;
    long ans = 0;
    cin >> N;
    for (int i = 1; i <= N; ++i){
        if ((i % 3 != 0) && (i % 5 != 0)) {
            ans += i;
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 3624
n=int(input())
a=[int(input())for i in range(n)]
a.sort()
memo=a[0]
ans=0
cnt=0
for i in range(n):
    if a[i]==memo:
        cnt+=1
        if i==n-1:
            if cnt%2!=0:
                ans+=1
    else:
        if cnt%2!=0:
            ans+=1
        if i==n-1:
            ans+=1
        cnt=1

    memo=a[i]
print(ans)



Measured memory_bytes: 7388
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;

namespace AtCoder.ABC
{
    class QuestionA
    {
        public static void Main(string[] args)
        {
            var a = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();

            var sx = a[0];
            var sy = a[1];
            var tx = a[2];
            var ty = a[3];

            var xDiff = tx - sx;
            var yDiff = ty - sy;

            var ans = "";

            for(int i = 0; i < yDiff; i++) {
                ans += "U";
            }

            for (int i = 0; i < xDiff; i++) {
                ans += "R";
            }

            for (int i = 0; i < yDiff; i++) {
                ans += "D";
            }

            for (int i = 0; i < xDiff; i++) {
                ans += "L";
            }

            ans += "L";

            for (int i = 0; i <= yDiff; i++) {
                ans += "U";
            }

            for (int i = 0; i <= xDiff; i++) {
                ans += "R";
            }

            ans += "D";
            ans += "R";

            for (int i = 0; i <= yDiff; i++) {
                ans += "D";
            }

            for (int i = 0; i <= xDiff; i++) {
                ans += "L";
            }

            ans += "U";

            Console.WriteLine(ans);
        }
    }
}



Measured memory_bytes: 46816
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

a,b=MI()
if 1<=a<=9 and 1<=b<=9:
    print(a*b)
else:
    print("-1")

Measured memory_bytes: 65532
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n;
  cin>>n;
  int p=0,w=0,g=0,y=0;
  rep(i,n){
    char c;
    cin>>c;
    if(c=='P') p++;
    if(c=='W') w++;
    if(c=='G') g++;
    if(c=='Y') y++;
  }
  if(p>0 && w>0 && g>0 && y>0)
    cout<<"Four"<<endl;
  else cout<<"Three"<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**5-10)

N = int(input())
h = list(map(int,input().split()))

memo = [-1]*N

def func(i):
  # メモのロード
  if memo[i]!=-1:
    return memo[i]
  # 初期値の部分
  if i==0:
    return 0
  elif i==1: 
    return abs(h[1]-h[0])
  # 二択の部分
  a = func(i-1)+abs(h[i]-h[i-1])
  b = func(i-2)+abs(h[i]-h[i-2])
  memo[i] = min(a,b) # メモのセーブ
  return memo[i]

print(func(N-1))


Measured memory_bytes: 119624
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
//ノート　isupperで大文字の判定　islowerで小文字の判定
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int a,b;
    std::cin >> a>>b;
    if(a>=9||b>=9)std::cout << ":(" << std::endl;
    else std::cout << "Yay!" << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
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;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n,c;
    cin>>n>>c;
    vvi vec(c,vi(c));
    REP(i,c){
        REP(j,c){
            cin>>vec[i][j];
        }
    }
    vvi d(n,vi(n));
    REP(i,n){
        REP(j,n){
            cin>>d[i][j];
            d[i][j]--;
        }
    }
    vvi mem(c,vi(3));
    REP(i,c){
        REP(j,3){
            REP(k,n){
                REP(l,n){
                    if((k+l)%3==j&&d[k][l]!=i){
                        mem[i][j]+=vec[d[k][l]][i];
                    }
                }
            }
        }
    }
    int ans=INF;
    REP(i,c){
        REP(j,c){
            if(i==j){
                continue;
            }
            REP(k,c){
                if(i==k||j==k){
                    continue;
                }
                chmin(ans,mem[i][0]+mem[j][1]+mem[k][2]);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(void){
    int n,d;
    cin >> n >> d;
    int x[n][d];
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin >> x[i][j];
        }
    }

    int ans=0;
    for(int i=0;i<n;i++){
        int sum;
        for(int j=i+1;j<n;j++){
            sum = 0;
            for(int k=0;k<d;k++){
                sum += pow(x[i][k]-x[j][k],2);
            }
            if(ceil(sqrt(sum)) == floor(sqrt(sum))) ans++;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

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

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
int dd[4] = {1,0,3,2}; // ???, ???, ???, ???

int W, H;
int maps[30][30];
bool wait[30][30][4]; // (i,j)???k??????????????????

int main() {
	while (cin >> W >> H, W || H) {
		queue<pii> que;
		
		REP(i, H) {
			string str; cin >> str;
			
			REP(j, W) {
				int num;
				switch (str[j]) {
					case '#': num = -1; break;
					case '.': num = -2; break;
					case 'X': num = -3; break;
					
					case 'E': num = 0; break;
					case 'S': num = 1; break;
					case 'W': num = 2; break;
					case 'N': num = 3; break;
				}
				maps[i][j] = num;
				if (num >= 0) que.push(pii(i, j));
			}
		}
		
		int turn = 0;
		
		while (turn <= 180 && !que.empty()) {
			//puts(""); REP(i, H) {REP(j, W) printf("%3d", maps[i][j]); puts("");}
			
			for (int i = que.size() - 1; i >= 0; i--) {
				pii now = que.front(); que.pop();
				int y = now.fi, x = now.se;
				int d = maps[y][x];
				
				int nextd = -1;
				
				REP(i, 4) {
					int nd = (d + dd[i]) % 4;
					int xx = x + dx[nd], yy = y + dy[nd];
					if (!(xx >= 0 && xx < W && yy >= 0 && yy < H)) continue;
					if (maps[yy][xx] < 0 && maps[yy][xx] != -1) {
						wait[yy][xx][(nd + 2) % 4] = true;
						nextd = nd;
						
						//printf("%d %d -> %d %d (%d)\n", y, x, yy, xx, nd);
						break;
					}
				}
				
				if (nextd == -1) que.push(pii(y, x));
			}
			
			REP(i, H) REP(j, W) {
				bool ok = false;
				REP(k, 4) {
					int d = dd[(k + 1) % 4];
					if (!wait[i][j][d]) continue;
					int y = i + dy[d], x = j + dx[d];
					maps[y][x] = (d + 2) % 4;
					
					if (ok) que.push(pii(y, x));
					else {
						if (maps[i][j] != -3) {
							swap(maps[y][x], maps[i][j]);
							que.push(pii(i, j));
						}
						else maps[y][x] = -2;
						ok = true;
					}
					wait[i][j][d] = false;
				}
				
			}
			
			turn++;
		}
		
		if (turn > 180) puts("NA");
		else cout << turn << endl;
	}
	return 0;
}

Measured memory_bytes: 3140
// abc136a.cpp :
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define dw(i,s,e,d) for(int i=(s);i>(e);i-=(d))
#define in(x) cin>>(x)
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl

void p1(vi v){
  for(auto a: v){ot(a);ot(",");}
}
void p2(vvi &x){
  for(auto v: x){ot("[");p1(v);ot("]\n");}
}

int main(){
  int a,b,c; cin>>a>>b>>c;
  // cout<<a<<","<<b<<","<<c<<"\n";
  int d = c-(a-b);
  ote((d<0? 0:d));


}

Measured memory_bytes: 256
use std::collections::VecDeque;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner {stdin: s.lock() };
    let n: usize = sc.read();
    let q: usize = sc.read();
    let mut tree = vec![vec![]; n];
    for _ in 1..n {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        tree[a].push(b);
        tree[b].push(a);
    }

    let mut add = vec![0; n];

    for _ in 0..q {
        let p = sc.read::<usize>() - 1;
        let x: u64 = sc.read();
        add[p] += x;
    }

    let mut ans = vec![0; n];
    let mut q = VecDeque::new();
    q.push_back((0, 0));
    ans[0] = add[0];
    while let Some((v, p)) = q.pop_front() {
        for &next in tree[v].iter() {
            if next == p {
                continue;
            }
            ans[next] = add[next] + ans[v];
            q.push_back((next, v));
        }
    }
    for i in 0..n {
        if i > 0 {
            print!(" ");
        }
        print!("{}", ans[i]);
    }
    println!();
}
pub struct Scanner<R> {
    stdin: R,
}


impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr> (&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe{ std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 29684
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int mass[101];
int main(){
    CIN(N);
    for(int a = 0;a < 100;a++){
        for(int b = 0;b < 100;b++){
            int ins = 7 * a+4 * b;
            if(ins <= 100){
                mass[ins]=1;
            }
        }
    }
    if(mass[N]==1){
        Yes(true);
    }else{
        Yes(false);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main() {
	string s; cin >> s;
	for (int i = 0; i < s.size() - 1; i++) {
		if (s.substr(i, 2) == "AC") {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n"; return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
int main(){
	int a,b;	//x??¨y????????°??§??´??°?????\????????°
	scanf("%d %d",&a,&b);
	int s,l;
	s=a*b;
	l=2*a+2*b;
	printf("%d %d\n",s,l);
	return 0;
}

Measured memory_bytes: 2760
#line 1 "test/yosupo_unionfind.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/unionfind"

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

#line 1 "datastructure/unionfind.cpp"
class UnionFind {
    int n;
    vector<int> uni;
    int forest_size;
public:
    explicit UnionFind(int n) : n(n), uni(static_cast<u32>(n), -1), forest_size(n) {};

    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        forest_size--;
        return true;
    }
    int size(){ return forest_size; }
    int size(int i){ return -uni[root(i)]; }
    bool same(int a, int b) { return root(a) == root(b); }
};

/**
 * @brief UnionFind(素集合データ構造)
 * @docs _md/unionfind.md
 */
#line 22 "test/yosupo_unionfind.test.cpp"

int main() {
    int n, q;
    cin >> n >> q;
    UnionFind uf(n);
    for (int i = 0; i < q; ++i) {
        int t, u, v;
        scanf("%d %d %d", &t, &u, &v);
        if(t) printf("%d\n", uf.same(u, v));
        else uf.unite(u, v);
    }
    return 0;
}



Measured memory_bytes: 4020
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace         std;
#define                 int long long
#define                 double long double
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<'\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector
#define die exit(0)
#define alln(arr) arr+1 , arr+1+n
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update> oset; 

int n,m,k,arr[N];

void solve()
{
    //int m,n;
	cin>>m>>n;
	cout<<ceil(1.0*m/n);
}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    forn(i,1,t)
    {
        solve();
        nl;
    }



    return 0;

}

//       clang++ c.cpp ; ./a.out < a.txt ;  

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

#define null                ""
#define all(dat)            dat.begin(), dat.end()
#define over(msg)           cout << msg << endl, exit(0);
#define loop(i, to)         for (int i = 0; i < to; ++i)
#define cont(i, to)         for (int i = 1; i <= to; ++i)
#define foreach(i, dat)     for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long           num;

using namespace std;

bool g[25][25];
int n, dp[(1 << 21) + 5], mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    loop (i, n) {
        loop (j, n) {
            cin >> g[i][j];
        }
    }
    dp[0] = 1;
    cont (S, (1 << n) - 1) {
        int i = __builtin_popcount(S) - 1;
        loop (j, n) {
            if (((S >> j) & 1) && g[i][j]) {
                dp[S] += dp[S ^ (1 << j)];
                dp[S] %= mod;
            }
        }
    }
    cout << dp[(1 << n) - 1] << endl;
}


Measured memory_bytes: 8448
#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() {
  int h, w, n;
  cin >> h >> w >> n;
  int p = max(h, w);
  int ans = (n + p - 1) / p;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3536
#include <bits/stdint-intn.h>
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

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>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int main(void) {
    int n, k; cin >> n >> k;
    vint sunuke(n, 0);
    rep(i, n) {
        int d;
        cin >> d;
        rep(j, d) {
            int a; cin >> a;
            sunuke[a-1]++;
        }
    }
    int ans = 0;
    rfor(x, sunuke) if(x == 0) ans++;
    println(ans);


    return 0;
}


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

// 基本テンプレート
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// 型
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// 定数
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int N;
    string s, t;
    cin >> N >> s >> t;

    int cnt = 0;
    while(true) {
        if(s==t) break;
        cnt++;
        s.erase(s.begin());
        t.erase(--t.end());

    }

    P(N+cnt);

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        
        int min = Integer.MAX_VALUE;
        
        for(int i = 1; i < n; i++){
            int a = n - i;
            int b = i;
            
            min = Math.min(min, sum(a) + sum(b));
        }
        
        System.out.println(min);
    }
    
    public static int sum(int a){
        String str = String.valueOf(a);
        int sum = 0;
        for(char c : str.toCharArray()){
            sum+=c-'0';
        }
        return sum;
    }
}


Measured memory_bytes: 35044
#include <bits/stdc++.h>
using namespace std;
#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++)

int main() {
  int n,t;
  cin >> n>>t;
  vector<int>a(t);
  rep(i,t){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  if(2*a.at(t-1)-n-1>0){
    cout<<2*a.at(t-1)-n-1<<endl;
  }
  else{
    cout<<0<<endl;
  }
}

Measured memory_bytes: 256
s=[s for s in input()]
alp=[chr(ord('a')+i) for i in range(26)]
n=len(s)
ans=10**9
for a in alp:
  t=s
  if not a in s:continue
  for i in range(n):
    if len(set(t))==1:break
    b=[]
    for j in range(n-i-1):
      if t[j]==a:b+=[t[j]]
      elif t[j+1]==a:b+=t[j+1]
      else:b+=t[j]
    t=b
  ans=min(ans,i)
print(ans)

Measured memory_bytes: 9124
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int k = Integer.parseInt(in.nextLine());
        String[] tmp = in.nextLine().trim().split("\\s");
        int a = Integer.parseInt(tmp[0]);
        int b = Integer.parseInt(tmp[1]);
        in.close();
        int res = 0;
        while(res < a){
            res += k;
        }
        if(res <= b){
            System.out.println("OK");
        }
        else{
            System.out.println("NG");
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int ans[50];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout<<setprecision(10)<<fixed;
	ll a, b;
	cin>>a>>b;
	if(a&1){
		ans[0]=((b-a)%4>=2 ? 0 : 1);
	}
	else{
		ll tmp=(b-a)%4;
		ans[0]=(tmp==0 || tmp==3 ? 0 : 1);
	}
	ll mask=2;
	FOR(i, 1, 40){
		mask<<=1;
		ll c=a%mask, d=b%mask;
		if(c<mask/2){
			ans[i]=(d<mask/2 || d&1 ? 0 : 1);
		}
		else{
			if(c&1){
				ans[i]=(d>=mask/2 && ~d&1 ? 0 : 1);
			}
			else{
				ans[i]=(d<mask/2 || d&1 ? 0 : 1);
			}
		}
	}
	ll res=0;
	FORR(i, 0, 40){
		res<<=1;
		res+=ans[i];
	}
	cout<<res<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);


map<ll,int> prime_factor(ll n) {
    map<ll,int> res;
    repr(i,2,sqrt(n)+1) {
        while (n%i==0) {
            ++res[i];
            n/=i;
        }
    }
    if(n!=1) ++res[n];
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);

    ll n;
    cin >> n; 
    map<ll,int> pf=prime_factor(n);
    ll ans=0;
    repitr(itr,pf) {
        int k=itr->second;
        double sk=sqrt(1+1.0*8*k)-1;
        double tans=sk/2;
        ans+=int(tans);
    }
    cout << ans << endl;

}


Measured memory_bytes: 3652
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100002

ll dp[101][N],pre[N];

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

    int n,k;
    cin>>n>>k;
    ll a[n];
    ifr(i,0,n) cin>>a[i];
    ifr(i,0,n) ifr(j,0,N) dp[i][j]=0;
    ifr(i,0,a[0]+1) dp[0][i]=1;
    ifr(i,1,n) {
        ifr(j,0,k+1) {
            pre[j]=dp[i-1][j]+((j-1>=0)?pre[j-1]:0); pre[j]%=mod;
            dp[i][j] = (pre[j]-((j-a[i]-1>=0)?pre[j-a[i]-1]:0))%mod;
            dp[i][j] = (dp[i][j]+mod)%mod;
        }
    }
    cout<<dp[n-1][k]<<endl;
    return 0;
}

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





int main() {


	long long int i, A,A_r, B,B_l, C, D, CD, count=0, count_C, count_D, count_CD, x, tmp, r;

	scanf("%lld %lld %lld %lld", &A, &B, &C, &D);

	A_r = A - (A % C);
	if (A % C != 0)
		A_r += C;
	B_l = B - (B % C);

	count_C = (B_l - A_r) / C;

	A_r = A - (A % D) + D;
	if (A % D != 0)
		A_r += D;
	B_l = B - (B % D);

	count_D = (B_l - A_r) / D;

	x = C * D;


	if (C < D) {
		tmp = C;
		C = D;
		D = tmp;
	}



	r = C % D;


	while (r != 0) {
		C = D;
		D = r;
		r = C % D;
	}

	CD = x / D;



	A_r = A - (A % CD) + CD;
	if (A % CD != 0)
		A_r += CD;
	B_l = B - (B % CD);

	count_CD = (B_l - A_r) / CD;

	count = B - A - count_C - count_D + count_CD;



	printf("%lld\n", count);


	return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

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

llint a, b, c, d;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> a >> b >> c >> d;
	cout << max(max(a*c, a*d), max(b*c, b*d)) << endl;
	
	return 0;
}

Measured memory_bytes: 3648