akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力



		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int[] data = {a,b,c};
		Arrays.sort(data);
		System.out.print(a + b + c - data[2]);
	
		


	}


	static boolean checkswitch(int bit,int[] k,ArrayList<ArrayList<Integer>> list,int[] p,int m){
		
//		System.out.println("bit " + bit);
			
		for(int i = 0;i < m;i++){
			
			ArrayList<Integer> sub = list.get(i);
			int onnum = 0;						//onの数
			for(int j = 0;j < sub.size();j++){
//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
//					System.out.println("on  ");
				}
				
			}
			if(onnum % 2 != p[i]){				//一個でも電球がつかなかったらout
				return false;
			}
			
		}
		

		return true;

	}

	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}





}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return  otherpair.end - end;
	}
}




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

int main(){
	int A[7]={1,3,5,7,8,10,12};
	int B[4]={4,6,9,11};
	
	int x,y;
	bool ok=false;
	cin >> x >> y;
	if(x==y) ok=true;
	else{
		bool ok2=false,ok3=false;
		for(int i=0;i<7;i++){
			if(x==A[i]) ok2=true;
			if(y==A[i]) ok3=true;
		}
		if(ok2==ok3&&ok2==true) ok=true;
		ok2=false,ok3=false;
		for(int i=0;i<4;i++){
			if(x==B[i]) ok2=true;
			if(y==B[i]) ok3=true;
		}
		if(ok2==ok3&&ok2==true) ok=true;
	}
	
	cout << (ok?"Yes":"No") << endl;
	return 0;
}

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    while (cin >> n >> m, n + m) {
        vector<int> sum(n, 0);
        REP(i, 0, m) {
            REP(j, 0, n) {
                int p;
                cin >> p;
                sum[j] += p;
            }
        }
        int ans = 0;
        REP(i, 0, n) {
            ans = max(sum[i], ans);
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3076
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
    ll N;
    cin >> N;
    ll thirdDigit = N / 100;
    ll secondDigit = (N-thirdDigit*100) / 10;
    ll firstDigit = (N - thirdDigit * 100 - secondDigit * 10);
    if (firstDigit==2||
        firstDigit==4||
        firstDigit==5||
        firstDigit==7||
        firstDigit==9) {
        cout << "hon" << endl;
    }
    else if (firstDigit == 0 ||
        firstDigit == 1 ||
        firstDigit == 6 ||
        firstDigit == 8 ) {
        cout << "pon" << endl;
    }
    else{
        cout << "bon" << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    cout << max(0, int(c - a + b));
    return 0;
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){

	int n, k;
	cin >> n >> k;
	V<bool> canuse(10,true);
	rep(i,k) {
		int a;
		cin >> a;
		canuse[a] = false;
	}

	for(int x = n;; x++) {
		string s = to_string(x);
		bool ok = true;
		rep(i,sz(s)) {
			int c = s[i]-'0';
			ok &= canuse[c];
		}
		if(ok) {
			cout << x << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }
  sort(L.begin(),L.end());
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      int a = L[i];
      int b = L[j];
      ans += upper_bound(L.begin(),L.end(),a+b-1) - lower_bound(L.begin(),L.end(),b-a+1);
      ans--;
      if (b - a < a) {
        ans--;
      }
    }
  }
  cout << ans / 3 << endl;
  return 0;
}

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

#define int long long

signed main() {
  int N;
  string s;
  cin >> N;
  cin >> s;

  N *= 2;

  vector<int> id(N);
  {
    int a = 0, b = 0;
    for ( int i = 0; i < N; i++ ) {
      if ( s[i] == 'a' ) id[i] = a++;
      else id[i] = b++;      
    }
  }

  vector<string> vs;
  {
    string t = "";
    int sum = 0;  
    for ( int i = 0; i < N; i++ ) {
      sum += (s[i] == 'a' ? 1 : -1);
      t += s[i];
      if ( sum == 0 ) {
	vs.emplace_back(t);
	t = "";
      }
    }    
  }

  vector<string> maxs;
  int off = 0;
  for ( string t : vs ) {
    string u = "";
    if ( t[0] == 'a' ) {
      for ( int i = 0; i < (int)t.size(); i++ ) {
	if ( t[i] == 'a' ) {
	  u += "ab";
	  int j = i;	  
	  i++;	  
	  while ( id[off+j] != id[off+i] ) i++;	  
	}
      }
    } else {
      string ma = "";	
      for ( int i = 0; i < (int)t.size(); i++ ) {
	if ( t[i] == 'a' ) continue;	
	u = "";	
	for ( int j = i; j < (int)t.size(); j++ ) {
	  if ( id[off+i] <= id[off+j] ) u += t[j];	  
	}
	ma = max(ma, u);	
      }
      u = ma;
    }
    off += t.size();    
    maxs.emplace_back(u);    
  }

  string ans = "";
  for ( int i = (int)maxs.size()-1; i >= 0; i-- ) {
    // cout << maxs[i] << endl;
    if ( ans <= maxs[i]+ans ) ans = maxs[i]+ans;    
  }

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int a, b, t; cin >> a >> b >> t;
    int num = t/a;
    cout << b * num << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin>>H.at(i);
  }
  sort(H.begin(),H.end());
  long long count = 0;
  if(N>K){
  for(int i=0;i<N-K;i++){
      count+=H.at(i);
  }
  cout<<count<<endl;
  }
  else{
    cout<<0<<endl;
  }
  return 0;
}


Measured memory_bytes: 1024
from collections import Counter
from operator import itemgetter

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

for i in range(len(A)):
    A.append(A[i]+1)
    A.append(A[i]-1)

B = Counter(A)
B = list(B.items())
B1 = sorted(B,key=itemgetter(1),reverse = True)  
#print(B1)
print(B1[0][1])

Measured memory_bytes: 29020
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{

public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        StringBuilder sb=new StringBuilder();
       int n=s.nextInt(),k=s.nextInt();
       int[] arr=new int[n];
       for(int i=0;i<n;i++){arr[i]=s.nextInt();}
        int[] dp=new int[n];
      Arrays.fill(dp,1000000002);dp[0]=0;
      dp[1]=Math.abs(arr[1]-arr[0]);
      for(int i=2;i<n;i++){
        for(int j=i-1;j>=0&&j>=i-k;j--){
                  dp[i]=Math.min(Math.abs(arr[i]-arr[j])+dp[j],dp[i]);

        }
      }
      System.out.println(dp[n-1]);
    }
}
    
  












Measured memory_bytes: 50736
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    a,b,n = LI()
    ans = 0
    def f(a,b,x):
        ans = (a*x)//b - a*(x//b)
        return ans
    if b-1<=n:
        ans = f(a,b,b-1)
    else:
        ans = f(a,b,n)
    print(ans)
main()

Measured memory_bytes: 10048
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  S = input()

  st = N
  for i in range(N):
    if S[i] != '.':
      st = i
      break
  ed = 0
  for i in range(N):
    if S[N - 1 - i] != '#':
      ed = N - i
      break

  if ed <= st:
    print(0)
    return

  nWhite = 0
  for i in range(st, ed):
    if S[i] == '.':
      nWhite += 1

  countBlack = 0
  countWhite = 0
  ans = N
  for i in range(st, ed):
    w = nWhite - countWhite
    b = countBlack
    ans = min(ans, w + b)
    if S[i] == '#':
      countBlack += 1
    else:
      countWhite += 1
  ans = min(ans, countBlack)
  print(ans)

if __name__ == "__main__":
  main()


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

int main(){
int x,y;

cin >> x >> y;

if(x < y){
cout << "a < b"<< endl;
}else if(x > y){
cout << "a > b"<< endl;
}else{
cout << "a == b"<< endl;
}

return 0;

}

Measured memory_bytes: 1156
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;

int main()
{
	ll X, Y;
	cin >> X >> Y;
	int ans = 0;
	while (X<=Y)
	{
		X *= 2;
		ans++;
	}
	co(ans);
	return 0;
}

Measured memory_bytes: 256
A1=[int(i) for i in input().split()]
A2=[int(i) for i in input().split()]
A3=[int(i) for i in input().split()]
N=int(input())
b=[int(input()) for i in range (N)]
for t in b:
    if t in A1:
        A1[A1.index(t)]="#"
    elif t in A2:
        A2[A2.index(t)]="#"
    elif t in A3:
        A3[A3.index(t)]="#"
ans='No'
if len(set(A1))==1 or len(set(A2))==1 or len(set(A3))==1:
    ans='Yes'
if (A1[0]==A2[0]==A3[0]) or (A1[1]==A2[1]==A3[1]) or (A1[2]==A2[2]==A3[2]):
    ans='Yes'
if (A1[0]==A2[1]==A3[2]) or (A1[2]==A2[1]==A3[0]):
    ans='Yes'
print(ans)




Measured memory_bytes: 3064
def examA():
    N = DI()/dec(7)
    ans = N
    print(N)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    class combination():
        # 素数のmod取るときのみ　速い
        def __init__(self, n, mod):
            self.n = n
            self.mod = mod
            self.fac = [1] * (n + 1)
            self.inv = [1] * (n + 1)
            for j in range(1, n + 1):
                self.fac[j] = self.fac[j - 1] * j % mod

            self.inv[n] = pow(self.fac[n], mod - 2, mod)
            for j in range(n - 1, -1, -1):
                self.inv[j] = self.inv[j + 1] * (j + 1) % mod

        def comb(self, n, r):
            if r > n or n < 0 or r < 0:
                return 0
            return self.fac[n] * self.inv[n - r] * self.inv[r] % self.mod
    B, W = LI()
    N = B+W
    C = combination(N,mod)

    ans = [0]*N
    inv_2 = pow(2,mod-2,mod)
    now_W = 0
    now_B = 0
    for i in range(N):
        cur = inv_2
        if i>=W:
            #print(i)
            now_W = now_W*2 + C.comb(i-1, i-W)
            cur += pow(inv_2,i+1,mod)*now_W
        if i>=B:
            now_B = now_B * 2 + C.comb(i - 1, i - B)
            cur -= pow(inv_2, i + 1, mod) * now_B
        now_B %= mod
        now_W %= mod
        cur %= mod
        ans[i] = cur

    for v in ans:
        print(v)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 100948
N, K = gets.split.map(&:to_i)
hash = Hash.new(0)
N.times do
    s = gets.chomp
    hash[s[0]] += 1
end
nums = hash.values.sort.reverse
if nums.size < K
    puts 0
    exit
end

ans = 0
loop do
    break if nums[K-1] == 0
    K.times do |i|
        nums[i] -= 1
    end
    ans += 1
    nums = nums.sort.reverse
end
puts ans

Measured memory_bytes: 5884
/*                        
                            In the name of Almighty ALLAH

   code from :::::::::::::::::::::
   ******************************* R E S H A D ********************************
   
   
   
    FREE PALESTINE           FREE PALESTINE            FREE PALESTINE           FREE PALESTINE
   
                 FREE PALESTINE           FREE PALESTINE            FREE PALESTINE 
                 
    FREE PALESTINE           FREE PALESTINE            FREE PALESTINE           FREE PALESTINE
   
                 FREE PALESTINE           FREE PALESTINE            FREE PALESTINE
                 
    FREE PALESTINE           FREE PALESTINE            FREE PALESTINE           FREE PALESTINE
   
 
*/     

#include <bits/stdc++.h>

#define ll               long long
#define db               double
#define Pi               2*acos(0.0)
#define pb(a)            push_back(a)
#define VI               vector <int>
#define FASTIO           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ull              unsigned long long
#define all(a)           a.begin(),a.end()
#define loop(i,n)        for(int i=0;i<n;i++)
#define loop1(i,n)       for(int i=1;i<=n;i++)
#define TEST_CASE(t)     for(int z=1;z<=t;z++)
// 90 degree = acos(x)*180/acos(0.0)

using namespace std;

int main() {
    
    FASTIO;
    
    int n;
    cin >> n;
    int arr[n];
    for(int i=0; i<n; i++) cin >> arr[i];
    
    ll cnt=0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            for(int k=j+1; k<n; k++){
                if((arr[i]!=arr[j]) && (arr[j]!=arr[k]) && (arr[k]!=arr[i])){
                    //cout << arr[i] << " " << arr[j] << " " << arr[k] << endl;
                    int a[3];
                    a[0]=arr[i]; a[1]=arr[j]; a[2]=arr[k];
                    sort(a, a+3);
                    if(a[2]<(a[0]+a[1])) ++cnt;
                    
                }
            }
        }
    }
    
    cout << cnt << endl;
    
    
	return 0;
}

Measured memory_bytes: 3652
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

ll f(ll n) {
  if (n % 2 == 0) return n / 2;
  return 3 * n + 1;
}

void solve() {
  ll x; cin >> x;
  set<ll> s;
  ll ans = 1;
  while (s.count(x) == 0) {
    s.insert(x);
    x = f(x);
    ++ans;
  }
  cout << ans << endl;
}


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

#include<algorithm>
#define int long long
#define str(a) to_string(a)
#define pb push_back
#define mp make_pair
#define SORT(c) sort(c.begin(),c.end())
#define max_heap priority_queue<int>
#define min_heap priority_queue< int,vector<int>, greater<int> >
#define mod 1000000007
#define setbits(x) __builtin_popcount(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define start(t) int x;cin>>x;while(x--)
#define inf LLONG_MAX
#define sync ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define N 1000001


int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int a; cin >> a;
	cout << a + (a * a) + (a * a * a) << endl;
}


Measured memory_bytes: 3632
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int A = stdIn.nextInt();
		int B = stdIn.nextInt();
		int sum = A;
		int count = 1;
		
		if(B == 1) {
			System.out.println(0);
		}
		else if(A >= B) {
			System.out.println(count);
		}
		else {
			while(sum < B) {
				sum += A-1;
				count++;
			}
			System.out.println(count);
		}
	}

}

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

signed main(){
	int q;
	map<string,int>m;
	cin>>q;
	while(q--){
		int t,y;
		string x;
		cin>>t;
		if(t==0){
			cin>>x>>y;
			m[x]=y;
		}
		if(t==1){
			cin>>x;
			cout<<m[x]<<endl;
		}
		if(t==2){
			cin>>x;
			m.erase(x);
		}
	}
}


Measured memory_bytes: 27824
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
  static void Main(string[] args)
  {
        int[] arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var n = arr[0];
        var m = arr[1];
        var nodeArr = new Node[n];
        for(int i = 0; i < n; i++)
        {
            nodeArr[i] = new Node(i + 1);
        }
        for(int i = 0; i < m; i++)
        {
            int[] arrTwo = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int a = arrTwo[0];
            int b = arrTwo[1];
            nodeArr[a - 1].Children.Add(nodeArr[b - 1]);
            nodeArr[b - 1].Children.Add(nodeArr[a - 1]);
        }
        Search(nodeArr[0]);
        Console.WriteLine("Yes");
        for(int i = 1; i < n; i++)
        {
            nodeArr[i].writeAns();
        }


   }

    public static void Search(Node root)
    {
        var queue = new Queue<Node>();
        root.Visited = true;
        //Visit(root);
        queue.Enqueue(root);

        while (queue.Count != 0)
        {
            var current_node = queue.Dequeue();
            if (current_node.Children != null)
            {
                foreach (var node in current_node.Children)
                {
                    if (!node.Visited)
                    {
                        //Visit(node);
                        node.AnsNode = current_node;
                        node.Visited = true;
                        queue.Enqueue(node);
                    }
                }
            }
        }
    }


}

public class Node
{
    public int node;
    public Node(int i)
    {
        this.node = i;
    }

    public bool Visited { get; set; }
    public List<Node> Children = new List<Node>();

public Node AnsNode { get; set; }

    public void writeAns()
    {
        Console.WriteLine(AnsNode.node);
    }

}



Measured memory_bytes: 57948
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x


using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

int main() {
  
    string s;cin>>s;
    
    rep(k,s.size()){
        for(auto j = k; j<s.size();j++){
            string t;
            
            rep(i,k){
                t+=s[i];
            }
            repsg(i,j,s.size()){
                t+=s[i];
            }
            
            if(t=="keyence"){
                cout<<"YES"<<endl;
                return 0;
            }
            
        }
    }
    
    cout<<"NO"<<endl;
    
    
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long MOD=1e9+7;

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}
template<typename T> T extgcd(T a,T b,T &x,T &y){
    T d=a;
    if (b!=0){
        d=extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    } else x=1,y=0;
    return d;
}
template<typename T> int digit(T n){
    string cnt=to_string(n);
    return cnt.size();
}

template<typename T> bool is_prime(T n){
    for (T i=2;i*i<=n;++i)
        if (n%i==0) return false;
    return 1<n;
}
template<typename T> vector<T> divisor(T n){
    vector<T> res;
    for (T i=1;i*i<=n;++i) if (n%i==0){
        res.emplace_back(i);
        if (i!=n/i) res.emplace_back(n/i);
    }
    return res;
}
template<typename T> map<T,int> prime_factor(T n){
    map<T,int> res;
    for (T i=2;i*i<=n;++i){
        while (n%i==0){
            ++res[i]; n/=i;
        }
    }
    if (n!=1) res[n]=1;
    return res;
}
vector<bool> prime_table(int n){
    vector<bool> prime(n+1,true);
    prime[0]=prime[1]=false;
    for (int i=2;i<=n;++i) if (prime[i]){
        for (int j=i+i;j<=n;j+=i) prime[j]=false;
    }
    return prime;
}
vector<int> primes(int n){
    vector<int> res;
    vector<bool> pt=prime_table(n);
    for (int i=2;i<=n;++i) if (pt[i]){
        res.emplace_back(i);
    }
    return res;
}

long long modpow(long long x,long long n,long long mod){
    long long res=1;
    while (n>0){
        if (n&1LL) res=res*x%mod;
        x=x*x%mod; n>>=1LL;
    }
    return res;
}
long long modinv(long long x,long long p){
    return modpow(x,p-2,p);
}

template<typename T>
T eular_phi(T n){
    T res=n;
    for (T i=2;i*i<=n;++i) if (n%i==0){
        res-=res/i;
        while (n%i==0) n/=i;
    }
    if (n!=1) res-=res/n;
    return res;
}
vector<int> eular_phi_table(int n){
    vector<int> eular(n+1);
    iota(eular.begin(),eular.end(),0);
    for (int i=2;i<=n;++i) if (eular[i]==i){
        for (int j=i;j<=n;j+=i) eular[j]-=eular[j]/i;
    }
    return eular;
};


// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_A

void NTL_1_A(){
    int n; cin >> n;
    map<int,int> ans=prime_factor(n);
    cout << n << ':';
    for (auto p:ans){
        for (int i=0;i<p.second;++i){
            cout << ' ' << p.first;
        }
    }
    cout << '\n';
}

// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_B

void NTL_1_B(){
    ll m,n; cin >> m >> n;
    cout << modpow(m,n,MOD) << '\n';
}

// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_C

void NTL_1_C(){
    int n; cin >> n;
    ll ans=1;
    for (;n--;){
        ll a; cin >> a;
        ans=lcm(ans,a);
    }
    cout << ans << '\n';
}

// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_D

void NTL_1_D(){
    int n; cin >> n;
    cout << eular_phi(n) << '\n';
}

// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_E

void NTL_1_E(){
    int a,b,x,y; cin >> a >> b;
    extgcd(a,b,x,y);
    cout << x << ' ' << y << '\n';
}


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


Measured memory_bytes: 3172
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;


int main(){
  string A; cin >> A;
  ll n = A.size();
  ll cnt[26] = {};
  rep(i,n) cnt[A[i]-'a']++;
  ll ans = 1 + n*(n-1)/2;
  rep(i,26) ans -= cnt[i]*(cnt[i]-1)/2;
  cout << ans << endl;


  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3740
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sat Aug 24 21:16:12 2019
//
package main

import "fmt"

func main() {
	var m, d int
	fmt.Scan(&m)
	fmt.Scan(&d)
	count := 0

	for i := 1; i <= m; i++ {
		for j := 1; j <= d; j++ {
			d10 := j / 10
			d1 := j % 10
			if d10 >= 2 && d1 >= 2 {
				if i == d10*d1 {
					count++
				}
			}
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
import collections
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = [input().rstrip() for _ in range(N)]
    c = collections.Counter(S)
    for tc in ["AC", "WA", "TLE", "RE"]:
        if tc in c:
            print("{} x {}".format(tc, c[tc]))
        else:
            print("{} x 0".format(tc))


if __name__ == '__main__':
    main()


Measured memory_bytes: 80476
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String tmpStr = br.readLine();

			if(tmpStr == null){
				break;
			}

			int[] a = new int[4];
			int[] b = new int[4];
			boolean[] inA = new boolean[10];
			Arrays.fill(inA, false);

			String[] tmpArray1 = tmpStr.split(" ");
			String[] tmpArray2 = br.readLine().split(" ");

			for(int i = 0; i < 4 ; i++){
				a[i] = Integer.parseInt(tmpArray1[i]);
				b[i] = Integer.parseInt(tmpArray2[i]);
				inA[a[i]] = true;
			}

			//ヒット＆ブローチェック
			int hit = 0;
			int blow = 0;
			for(int i = 0; i < 4; i++){
				if(a[i] == b[i]){
					hit++;
				}

				else if(inA[b[i]]){
					blow++;
				}
			}
//			blow -= hit;

			System.out.println(hit + " "+ blow);
		}
	}

}



Measured memory_bytes: 24260
/* --- author: dxm --- */
#include<bits/stdc++.h>
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
#define DEBUG

int main(){
#ifndef DEBUG
	freopen("my.in","r",stdin);
	freopen("my.out","w",stdout);
#endif
	string s;
	cin>>s;
	int w;
	cin>>w;
	string ans="";
	for(int i=0;i<s.size();i+=w)ans+=s[i];
	cout<<ans;
	return 0;
}

/*
Input:
-----------------
Output:
*/

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

int main()
{
    string s, t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    int a = 0;

    if(s.back() > t.back()){
        a++;
        for(int i=s.size()-1;i>=0;i--){
            if(s[i] < t.back()){
                a = 2;
                break;
            }
        }
    }
    else if(s.back() == t.back()){
        for(int i=s.size()-1;i>=0;i--){
            if(s[i] < t.back()){
                a = 2;
                break;
            }
        }
    }
    else{
        a = 2;
    }
    if(a == 2) cout << "Yes" << endl;
    else if(a == 0 && s.size()<t.size()) cout << "Yes" << endl;
    else cout << "No" << endl; 
    
    return 0;
}

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

typedef long long ll;
    ll dp[50][500][500];

int main () {

    ll N, Ma,Mb;
    cin >> N >> Ma >> Mb;

    ll a[N],b[N],c[N];
    for(int i=0; i<N; i++) {
	cin >> a[i] >> b[i] >> c[i];
    }

    for(int k=0; k<50; k++) {
	for(int i=0; i<500; i++) {
	    for(int j=0; j<500; j++) {
		dp[k][i][j] = INT_MAX;
	    }
	}
    }
    
    dp[0][0][0] = 0;
    for(int k=0; k<N; k++) {
	for(int i=0; i<500; i++) {
	    for(int j=0; j<500; j++) {
		// 買わない
		dp[k+1][i][j] = min(dp[k+1][i][j],dp[k][i][j]); 
		// 買う
		dp[k+1][i+a[k]][j+b[k]] = min(dp[k+1][i+a[k]][j+b[k]], dp[k][i][j] + c[k]);
	    }
	}
    }
    ll ans = INT_MAX;
    for(int i=1; i<500; i++) {
	for(int j=1; j<500; j++) {
//	    cout << dp[N][i][j] << " ";
	    if( Ma*j == Mb*i )
		ans = min(dp[N][i][j],ans);
	}
    }
    cout << (ans==INT_MAX?-1:ans) << endl;
    
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  
  if (S=="Sunny"){
    cout << "Cloudy" << endl;
  }
  
  else if (S=="Cloudy"){
   cout << "Rainy" << endl; 
  }
  
  else{
   cout << "Sunny" << endl; 
  }
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String txt = sc.next().trim();
        
        if ('a' <= txt.charAt(0) && txt.charAt(0) <= 'z') {
            System.out.println('a');
        } else {
            System.out.println('A');
        }
    }
}

Measured memory_bytes: 26948
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){
  string S, T;
  cin >> S >> T;

  rep(i, S.size() ){
    if(S[i] != T[i]){
    cout << "No" << endl;
    return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 3624
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>

//macros
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define vecuni(a) (a).erase(unique((a).begin(),(a).end()),(a).end())

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvs = vector<vector<string>>;
template<class T>
using vec = vector<T>;

//frequent functions
int gcd(int a, int b){
  if (a == 0) 
    return b; 
  return gcd(b % a, a); 
}
int findGCD(vector<int> &arr, int n){
  int result = arr[0]; 
  for (int i = 1; i < n; i++) 
    result = gcd(arr[i], result); 
  return result; 
}
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<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}
//end
struct UnionFind{
  vector<int> par;
  UnionFind(int n) : par(n,-1) {}
  void init(int n) {par.assign(n,-1);}
  int root(int x){
    if(par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }
  bool issame(int x,int y){
    return root(x) == root(y);
  }
  bool merge(int x,int y){
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]){
      swap(x,y);
    }
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  int size(int x){
    return -par[root(x)];
  }
};


int N,M;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N >> M;
  vi P(N);
  rep(i,N){
    cin >> P[i];
  }
  UnionFind tree(N);
  rep(i,M){
    int x,y;
    cin >> x >> y;
    tree.merge(x-1,y-1);
  }
  int cnt = 0;
  rep(i,N){
    if(tree.issame(i,P[i]-1)){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))
flag = "a"
count = 0
for i in range(1,N):
    if A[i-1]<A[i] and flag == "a":
        flag = "up"
    elif A[i-1]>A[i] and flag == "a":
        flag = "down"
    elif A[i-1]==A[i] and flag == "a":
        continue
    if A[i-1]<=A[i] and flag == "up":
        continue
    elif A[i-1]>=A[i] and flag == "down":
        continue
    elif A[i-1]<A[i] and flag == "down":
        count += 1
        flag = "a"
    elif A[i-1]>A[i] and flag == "up":
        count += 1
        flag = "a"

print(count+1)

Measured memory_bytes: 14480
#include <stdio.h>

int fibonacci(int);

int F[44];

int main() {
  int n,i;

  scanf("%d",&n);

  for(i=0;i<=n;i++){
    F[i]=-1;
  }

  printf("%d\n",fibonacci(n));

  return 0;
}

int fibonacci(int n){
  if(n==0 || n==1) return F[n]=1;
  if(F[n]!=-1) return F[n];
  return F[n]=fibonacci(n-2)+fibonacci(n-1);
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int H, W, N;

int main()
{
	int i, j;

	scanf("%d%d%d", &H, &W, &N);
	printf("%d", (N+max(H, W)-1)/max(H, W));
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm> 
#include<cmath>
#include<cstring>
#define P 1000000007
#define LL long long
using namespace std;
int roadto[2001000],road[2001000],wz[2001000],f[2001000];
int n,K,num;


void conct(int x,int y)
{
  roadto[++num]=wz[x],road[num]=y,wz[x]=num;
  roadto[++num]=wz[y],road[num]=x,wz[y]=num;

}

void dfs(int x,int from)
{
  int t=wz[x],tt=K-2;
  if(x==1) tt++;
  f[x]=1;
  while(t)
    {
      if(road[t]!=from)
        {
		  dfs(road[t],x);
		  f[x]=(LL)f[x]*tt%P;
		  f[x]=(LL)f[road[t]]*f[x]%P;
		  tt--;
		}
	  t=roadto[t];
	}
   if(x==1)
     {
	   f[x]=(LL)f[x]*K%P;
	 }
}

int main()
{
  int i,x,y;
  scanf("%d%d",&n,&K);
  for(i=1;i<n;i++)
    {
	  scanf("%d%d",&x,&y);
	 conct(x,y);
	 	}
  dfs(1,0);
  printf("%d\n",f[1]);
} 

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair

#define debug(...) cerr << "[" << (#__VA_ARGS__) << "] : "; _debug(__VA_ARGS__);

template<class T, class S>
ostream& operator <<(ostream& out, pair<T, S> p) {
	out << "(" << p.first << ", " << p.second << ")" << endl;
	return out;
}

template<class T>
ostream& operator <<(ostream& out, vector<T>& v) {
	out << "[";
	if (v.size() > 0) out << v[0];
	for (auto it = next(v.begin()); it != v.end(); it++)
		cout << ", " << *it;
	out << "]";
	return out;
}
template<typename Arg, typename ...Args>
void _debug(Arg&& arg, Args && ...args) {
	using expander = int[];
	cerr << "{";
	cerr << arg; 
	(void)expander{0, ((void)(cerr << ", " << args), 0)...};
	cerr << "}" << endl;
}

#define HERE debug(__LINE__);

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;
const double PI = 3.141592653589793238;

const int N = 405;
int dp[N][N];
//dp[i][j] = the min total cost of combining interval [i, j] into one vertex

int32_t main() {
	FAST_IO;
	int n;
	cin >> n;
	vi a(n);
	for (int& x: a) cin >> x;
	
	auto sum = [&](int L, int R) {
		int s = 0;
		for (int i = L; i <= R; ++i) {
			s += a[i];
		}
		return s;
	};
	
	for (int L = n-1; L >= 0; --L) {
		for (int R = L; R < n; ++R) {
			if (L == R) {
				dp[L][R] = 0;
			} else {
				dp[L][R] = INF;
				int s = sum(L, R);
				for (int i = L; i <= R-1; ++i) {
					dp[L][R] = min(dp[L][R], dp[L][i] + dp[i+1][R] + s);
				}
			}
		}
	}
	
	cout << dp[0][n-1] << endl;
//	freopen("in.txt", "r", stdin);
	
	
	
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    string L;
    cin >> L;
    int n = L.size();
    vector<vector<ll>> dp(n+1,vector<ll>(2,0));
    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        int ld = L[i-1] - '0';
        if(ld == 1){
            dp[i][0] = (2*dp[i-1][0])%MOD;
            dp[i][1] = (3*dp[i-1][1] + dp[i-1][0])%MOD;
        }else{
            dp[i][0] = dp[i-1][0];
            dp[i][1] = (3*dp[i-1][1])%MOD;
        }
    }
    cout << (dp[n][0] + dp[n][1])%MOD << endl;
    return 0;
}

Measured memory_bytes: 5760
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var n=arr.shift()-0;
   if(n==0)break;
   var sum=(n!=1)?1:0;
   var sqrt=Math.sqrt(n);
   for(var i=2;i<sqrt;i++){
      if(n%i==0)sum+=i+n/i;
   }
   if(n%sqrt==0 && sqrt!=1)sum+=sqrt;
   var ans;
   if(n==sum)ans="perfect number";
   else if(n>sum)ans="deficient number";
   else if(n<sum)ans="abundant number";
   console.log(ans);
}

Measured memory_bytes: 15988
#include <bits/stdc++.h>
using namespace std;
vector<int> dp;
vector<vector<int> > g;
int dfs(int i){
  if(dp[i] != -1) return dp[i];
  
  int res = 0;
  for(int v: g[i]){
    res = max(res, dfs(v) + 1);
  }
  return dp[i] = res;   
}
int main(void){
  int N, M;
  cin >> N >> M;
  g.assign(N, vector<int>());
  for(int i=0; i<M; i++){
    int s, t;
    cin >> s >> t;
    s--; t--;
    g[s].push_back(t);
  }
  dp.assign(N, -1);
  int ans = 0;
  for(int i=0; i<N; i++) ans = max(ans, dfs(i)); 
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N, K, sum;
  sum = 0;
  cin >> N >> K;
  
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    
    if(x < K){
      if(x < (K-x) || x == (K-x)){
        sum += x*2;
      }
      else if(x > (K-x)){
        sum += (K-x)*2;
      }
    }
    
    else if(x > K){
      if(K < (x-K) || K == (x-K)){
        sum += K*2;
      }
      else if(K > (x-K)){
        sum += (x-K)*2;
      }
    }
  }
  cout << sum << endl;
}

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

int main() {
	int n;
	cin >> n;
	vector<int>a;
	for (int i = 0; i < n; i++) {
		int p;
		cin >> p;
		a.push_back(p);
	}
	int answer = a[1] - a[0];
	int min = a[0];
	int max = a[0];
	int p = 0;
	for (int i = 0; i < a.size() - 1; i++) {
		for (int j = i + 1; j <a.size(); j++) {
			if (min > a[j]) {
				min = a[j];
				max = min;
				i = j -1;
				break;
			}
			else if (max<= a[j]) {
				max = a[j];
				if (answer <max - min)answer = max - min;
			}
			else if(max > a[j]){
			    i = j;}
			if ( j == a.size() - 1) {
				max = a[j];
				if (answer <max - min)answer = max - min;
				i = j;
				break;
			}
			
		}
	}
	cout << answer << endl;
}





Measured memory_bytes: 3816
#include <iostream>
#include <numeric>
#include <vector>
#include <math.h>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
using namespace std; 

int main(){
    int a; cin >> a;
    map<string,int> A;
    for (int i=0;i<a;i++){
        string s;
        cin >> s;
        A[s]++;
    }
    int d=0;
    for (auto f : A){
        d=max(d,f.second);
    }
    for (auto f : A){
        if (f.second==d){
            cout << f.first << "\n";
        }
    }
}


Measured memory_bytes: 25216
#include<iostream>
#include<queue>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int INF = (1<<21);

int px[5][1000];
int py[5][1000];
int table[5][1000];
int p[5];
char m[1001];
int dist(int x,int y){
  if ( x < 0)x*=-1;
  if ( y <0)y*=-1;
  return x+y;
}
#define NEXT(i) ( (i+1)%5)
int solve(int ini,int sx,int sy,int gx,int gy){
  rep(i,5)rep(j,1000)table[i][j]=INF;
  ini=(ini+1)%5;
  rep(i,p[ini]){
    table[ini][i]=dist(sx-px[ini][i],sy-py[ini][i]);
  }
  

  rep(i,3){
    rep(j,p[(ini)]){
      rep(k,p[NEXT(ini)]){
	table[NEXT(ini)][k]=min(table[NEXT(ini)][k]
				,table[ini][j]+dist(px[ini][j]-px[NEXT(ini)][k],
						    py[ini][j]-py[NEXT(ini)][k]));
      }
    }
    ini=(ini+1)%5;
  }

  int ans = INF;
  rep(i,p[ini]){
    ans = min(ans,table[ini][i]+dist(gx-px[ini][i],gy-py[ini][i]));
  }
  return ans;
}

main(){
  int c,r;
  while(cin>>c>>r && c){
    int sx,sy,gx,gy;
    rep(i,5)p[i]=0;
    rep(i,r){
      cin>>m;
      rep(j,c){
	if ( m[j] == 'S')sx=j,sy=i;
	else if (m[j] == 'G')gx=j,gy=i;
	else if ( m[j] != '.'){
	  int now =m[j]-'0'-1;
	  py[now][p[now]]=i;
	  px[now][p[now]]=j;
	  p[now]++;
	}
      }
    }


    int ans=INF,ansindex =-1;
    rep(i,5){
      int tmp = solve(i,sx,sy,gx,gy);
      if ( tmp < ans)ans=tmp,ansindex=i;
    }

    if ( ansindex == -1)cout << "NA"<<endl;
    else cout << ansindex+1 <<" " << ans << endl;
  }
  return false;
}

Measured memory_bytes: 936
class UnionFind:
    def __init__(self, n):
        self.nodes = n
        self.parents = [i for i in range(n)]
        self.sizes = [1] * n
        self.rank = [0] * n

    def find(self, i):
        if self.parents[i] == i:
            return i
        else:
            self.parents[i] = self.find(self.parents[i]) # 経路圧縮
            return self.parents[i]

    def unite(self, i, j):
        pi = self.find(i)
        pj = self.find(j)
        if pi != pj:
            if self.rank[pi] < self.rank[pj]:
                self.sizes[pj] += self.sizes[pi]
                self.parents[pi] = pj
            else:
                self.sizes[pi] += self.sizes[pj]
                self.parents[pj] = pi
                if self.rank[pi] == self.rank[pj]:
                    self.rank[pi] += 1
    def same(self, i, j):
        return self.find(i)==self.find(j)

    def get_parents(self):
        for n in range(self.nodes): # findで経路圧縮する
            self.find(n)
        return self.parents

adj = []
N, M = map(int,input().split())
for m in range(M):
    a,b = map(int,input().split())
    adj.append([a-1,b-1])

ans = 0
for i in range(M):
    uf = UnionFind(N)
    for j in range(M):
        if (i==j):
            continue
        uf.unite(*adj[j])
    
    if len(set(uf.get_parents()))!=1: # 複数の集合にわかれているか確認
        ans += 1
print (ans)

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

int main()
{
    int n;cin>>n;
    for(int i=1;i<=9;i++)
    for(int j=1;j<=9;j++)
    {
        if(i*j==n){cout<<"Yes\n";return 0;}
    }
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		int n,i,j;
		int a[]= new int[1000];
		Scanner br = new Scanner(System.in);
		n=br.nextInt();
		for(i=0;i<n;i++){
			a[i]=br.nextInt();
		}
		for(j=n-1;j>=1;j--){
			System.out.print(a[j]+" ");
		}
		System.out.print(a[0]);
		System.out.println();
	}
}

Measured memory_bytes: 26320