akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

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

    ll A, B ;
    cin >> A >> B ;

    cout << max(A+B, max(A-B, A*B)) << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = []
for _ in range(n):
  a.append(input())
print("AC x " + str(a.count("AC")))
print("WA x " + str(a.count("WA")))
print("TLE x " + str(a.count("TLE")))
print("RE x " + str(a.count("RE")))

Measured memory_bytes: 16268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

string mx(string s, string t) {
  if(s.size() > t.size())
    return s;
  else if(s.size() < t.size())
    return t;
  else if(s >= t)
    return s;
  else
    return t;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vl a(m);
  rep(i, m) cin >> a[i];
  vl v = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  vs dp(n + 10, "");
  rep(i, n) {
    if(i > 0 && dp[i] == "") continue;
    for(ll k : a) dp[i + v[k]] = mx(dp[i + v[k]], dp[i] + char(k + '0'));
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 61624
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    int q;
    cin >> q;
    multimap<string, int> map;
    while (q--)
    {
        int c;
        cin >> c;
        if (c == 0)
        {
            string key;
            int x;
            cin >> key >> x;
            map.insert(pair<string,int>(key,x));
        } else if (c == 1)
        {
            string key;
            cin >> key;
            auto it = map.find(key);
            auto its=map.lower_bound(key);
            auto ise=map.upper_bound(key);
            if (its!=ise)
            {
                for (auto i = its; i !=ise ; ++i)
                {
                    cout << i->second << endl;
                }
            }
        } else if (c == 2)
        {
            string key;
            cin >> key;
            map.erase(key);
        } else
        {
            string L, R;
            cin >> L >> R;
            auto its = map.lower_bound(L);
            auto ite = map.upper_bound(R);
            for (auto i = its; i != ite; ++i)
            {
                cout << i->first << " " << i->second << endl;
            }
        }

    }

}


Measured memory_bytes: 24768
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	s := make([]string, n)
	m := make(map[string]int)
	f := 1
	for i := range s {
		fmt.Scan(&s[i])
		k := s[i]
		_, ok := m[k]
		if !ok {
			m[k] = 1
		} else {
			m[k] = m[k] + 1
			if f < m[k] {
				f = m[k]
			}
		}
	}

	r := make([]string, 0, len(m))
	for key, val := range m {
		if val == f {
			r = append(r, key)
		}
	}
	sort.Strings(r)
	for _, p := range r {
		fmt.Println(p)
	}
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string s[7];
    s[0] = "SUN", s[1] = "MON", s[2] = "TUE", s[3] = "WED", s[4] = "THU", s[5] = "FRI", s[6] = "SAT";

    string t;
    cin >> t;
    rep(i, 7)
    {
        if (s[i] == t)
        {
            OP(7 - i);
        }
    }

    return 0;
}

Measured memory_bytes: 256
while True:
  ans = 0
  n, x = [int(n) for n in input().split()]
  if n == x == 0:
    break
  for i in range(1, n+1):
    for j in range(i+1, n+1):
      for k in range(j+1, n+1):
        if i+j+k == x:
          ans += 1
  print(ans)



Measured memory_bytes: 5600
#include <iostream>
using namespace std;
#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
const int MOD = 1000000007;

char a[1000][1000];
int dp[1000][1000];
int main() {
  int in(H); int in(W);

  rep(i, H) rep(j, W) {
    dp[i][j] = 0;
    cin >> a[i][j];
  }
  dp[0][0] = 1;

  rep(i, H) rep(j, W) {
    if (i+1 < H && a[i+1][j] != '#') (dp[i+1][j] += dp[i][j]) %= MOD;
    if (j+1 < W && a[i][j+1] != '#') (dp[i][j+1] += dp[i][j]) %= MOD;
  }
  cout << dp[H-1][W-1] << endl;

  return 0;
}


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

long long gcd(long long number1, long long number2)
{ //最大公約数
  long long m = number1;
  long long n = number2;

  if (number2 > number1)
  {
    m = number2;
    n = number1;
  }
  long long r = n % m;
  while (r != 0)
  {
    n = m;
    m = r;
    r = n % m;
  }

  return m;
}

long long lcm(long long number1, long long number2)
{ //最小公倍数
  return number1 / gcd(number1, number2) * number2;
}

int main()
{
  int N;
  cin >> N;
  long long ans = 1;
  rep(i, N)
  {
    long long T;
    cin >> T;
    ans = lcm(ans, T);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input()) 
c=list(map(int, input().split())) 
ans = 0
 
if n == 1:
    print('Yes')
    exit()
if n == 2:
    if c[0] > c[1] + 1:
        print('No')
        exit()
if n >= 3:
    for i in range(n-1):
        if c[i] > c[i+1] +1:
            print('No')
            exit()
        if c[i] == c[i+1] +1:
            ans = max(ans,c[i])
            if c[i+1] + 1 < ans:
                print('No')
                exit()


print('Yes')

Measured memory_bytes: 20800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int N,M;
vector<tuple<int,int,int> >V;
bool pro(int X,int Y,int H)
{
    for(auto&I:V)
        if(get<2>(I)!=max(0,H-abs(X-get<0>(I))-abs(Y-get<1>(I))))
            return 0;
    return 1;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>N;
    V.resize(N);
    int miH=0;
    for(auto&I:V)
    {
        int T,O,P;
        cin>>T>>O>>P;miH=max(miH,P);
        I=tie(T,O,P);
    }
    for(int i=0;i<=100;i++)
        for(int j=0;j<=100;j++)
            for(int h=0;h<=200;h++)
                if(pro(i,j,miH+h))
                {
                    cout<<i<<' '<<j<<' '<<miH+h;
                    return 0;
                }
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
using namespace std;
using ll = long long;

const ll M=1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}


int main(){
  fac[0] = 1;
  ifac[0] = 1;
  for(ll i = 0; i<300000; i++){
    fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
    ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
  }
  int S;
  cin >> S;
  int N=S/3;
  ll ans=0;
  for(int i=1;i<=N;i++){
    int r=S-i*3;
    ans=(ans+comb(r+i-1,r))%M;
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
    string o, e;

    cin >> o >> e;

    for (int i = 0; i < e.length(); i++) {
        cout << o[i] << e[i];
    }

    if (o.length() > e.length()) {
        cout << o[o.length()-1] << endl;
    } else {
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define pi  acos(-1)
const int w=5e5+5;
const ll mod=1e9+7;
int a[]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
    int i,j;
    int x;
    cin>>x;
    cout<<a[x]<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    
    Scanner input = new Scanner(System.in);
    String[] s = new String[]{"MON","TUE","WED","THU","FRI","SAT","SUN"};
    String a = input.next();
    
    int g = 0;
    for(int i=0;i<s.length;i++)
      if(a.equals(s[i]))
        g=i;
    if(g==6)
      System.out.println(7);
    else
      System.out.println(6-g);
    
  }
}

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

using namespace std;

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define per(i,n) for ((i)=n;(i)>=(1);(i)--)
using namespace std;
int n,i,j,a[100005],cnt[100005];
int main()
{
	cin>>n;int mx=0,mi=n+1;
	rep(i,n){cin>>a[i];mx=max(mx,a[i]);mi=min(mi,a[i]);cnt[a[i]]++;}
	if(mx-mi>1){puts("No");return 0;}
	if(mx==mi)
	{
		if(mi==n-1||mi*2<=n)
		{
			puts("Yes");
		}
		else
		{
			puts("No");
		}
	}
	else
	{
		if(cnt[mi]>mi)
		{
			puts("No");
		}
		else if(n-cnt[mi]<2*(mx-cnt[mi]))
		{
			puts("No");
		}
		else puts("Yes");
	}
	return 0;
}

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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


auto solve() {
    int n, a, b;
    cin >> n >> a >> b;
    int q1 = 0, q2 = 0, q3 = 0;
    vi p(n);
    for (auto &&e:p) {
        cin >> e;
        if (e <= a) q1++;
        else if (a < e && e <= b) q2++;
        else q3++;
    }

    return min(q1, min(q2, q3));
}


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

    cout << solve() << endl;
//    solve();

    return 0;
}


Measured memory_bytes: 256
n,C,*H=map(int,open(0).read().split());
dp=[0];
P=[0];
def f(I,h):
    return dp[I]+H[I]*(H[I]-2*h)
for i in range(1,n):
    h=H[i]
    while len(P)>1 and f(P[0],h)>f(P[1],h):P.pop(0)
    dp+=[f(P[0],h)+h**2+C]
    while len(P)>1 and (H[P[-1]]-H[P[-2]])*(f(P[-1],0)-f(i,0))>(h-H[P[-1]])*(f(P[-2],0)-f(P[-1],0)):P.pop()
    P+=[i]
print(dp[-1])

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

int main(){
  int a, b;
  cin >> a >> b;
  if (a <= 5) {
    cout << 0 <<endl;
  }
  else if (a <= 12 && a >= 6) {
    cout << b / 2 <<endl;
  }
  else {
    cout << b <<endl;
  }
}


Measured memory_bytes: 256
/*
	我	好	弱	啊
	连指针也不会用
	我	好	弱	啊
	诸位大佬太强啦
		 --[伏地mod]InterestingLSY 
*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#define pb push_back
#define mp make_pair
#define INF 9999999
#define LINF 9999999999999999
#define uint unsigned int
#define msn(a,v) memset(a,v,sizeof(a))
#define ms(a) msn(a,0)
#define NONE -1
#define ll long long
#define ull unsigned ll
#define uchar unsigned char
#define sint short int
#define usint unsigned sint
#define lb lower_bound
#define ub upper_bound
using namespace std;
#define MAXN 400

int m,n;
int data[MAXN][MAXN];
bool ban[MAXN];
int pos[MAXN];

int main(){
	//freopen("B.txt","r",stdin);
	ms(ban);
	
	cin >> n >> m;
	for(int i = 1;i <= n;i++){
		pos[i] = 1;
		for(int j = 1;j <= m;j++)
			cin >> data[i][j];
	}
	
	int ans = INF;
	for(int i = 1;i <= m;i++){
		int app[MAXN]; ms(app);
		for(int j = 1;j <= n;j++)
			app[  data[ j ][ pos[j] ]  ]++;
		int maxval = -1,maxid;
		for(int j = 1;j <= m;j++){
			if(app[j] > maxval  &&  !ban[j]){
				maxval = app[j];
				maxid = j;
			}
		}
		ban[maxid] = 1;
		for(int j = 1;j <= n;j++)
			if( data[j][pos[j]] == maxid )
				while( ban[ data[j][ pos[j] ] ] )
					pos[j]++;
		ans = min( ans , maxval );
		
		//for(int i = 1;i <= n;i++)
		//	cout << pos[i] << " "; cout << endl;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 768
while 1:
    a , op, b = raw_input().split()
    a = int(a)
    op = str(op)
    b = int(b)

    if op == '+':
         print a+b
    elif op == '-':
         print a-b
    elif op == '*':
        print a*b
    elif op == '/':
        print a/b
    elif op == '?':
        break

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

signed main() {

    int n;
    string s;
    cin >> n >> s;

    int ans = 0;
    REP(j, 1, n-1){
        int a = 0, b = 0;
        char c = s[j];

        map<char, int> mp1;
        for(int i=j-1; i>=0; --i){
            if(s[i] != c){
                mp1[s[i]]++;
            }
        }

        map<char, int> mp2;
        REP(k, j+1, n){
            if(s[k] != c){
                mp2[s[k]]++;
            }
        }

        int res = 0;
        if(c == 'B'){
            res = mp1['R'] * mp2['G'] + mp1['G'] * mp2['R'];
        }
        else if(c == 'R'){
            res = mp1['B'] * mp2['G'] + mp1['G'] * mp2['B'];
        }
        else{
            res = mp1['R'] * mp2['B'] + mp1['B'] * mp2['R'];
        }

        REP(l, 1, n){
            if(j - l < 0 || j + l >= n){
                break;
            }
            if(s[j-l] != c && s[j+l] != c){
                if(s[j-l] != s[j+l]){
                    res--;
                }
            }
        }
        ans += res;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextInt();
		long b = sc.nextInt();
		long c = sc.nextInt();
		int d = 0;
		while(c-- != 0)
		{
		    if(d == 0)
		    {
		    if(a % 2 != 0)
		    {
		        a--;
		    }
		    a /= 2;
		    b += a;
		    d = 1;
		    }
		    else if(d == 1)
		    {
		        if(b % 2 != 0)
		        {
		            b--;
		        }
		        b /= 2;
		        a += b;
		        d = 0;
		    }
		}
		System.out.print(a + " " + b);
	}
}

Measured memory_bytes: 23764
# coding: utf-8
# Your code here!

from collections import deque
from pprint import pprint
moves=[(0,1),(1,0),(0,-1),(-1,0)]
pp=pprint
INF=float("inf")

h,w,k=map(int,input().split())
x1,y1,x2,y2=map(lambda x:int(x)-1,input().split())
maze=[list(input()) for _ in range(h)]
cost=[[INF]*w for _ in range(h)]

todo=deque()
todo.append((x1,y1))
cost[x1][y1]=0

while todo:
    x,y=todo.popleft()
    for vx,vy in moves:
        for kk in range(1,k+1):
            nx=x+vx*kk
            ny=y+vy*kk
            if not(0<=nx<h) or not(0<=ny<w):
                break
                # 更に伸ばす必要はない
            if maze[nx][ny]=="@":
                break
                # 蓮の向こうにはいけない
            if cost[nx][ny]<=cost[x][y]:
                break
                # 更新を1回以上受けていて、更に良くならない場合はbreak
            if cost[nx][ny]==INF:
                cost[nx][ny]=cost[x][y]+1
                todo.append((nx,ny))


# pp(cost)
ans=cost[x2][y2]
if ans==INF:ans=-1
print(ans)

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

int main() {
    int n, k;
    cin >> n >> k;

    int ans = 0;
    while (1) {
        ans++;
        if (n/k != 0) n /= k;
        else break;
    }

    cout << ans << endl;
    
}

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

#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,a,b)  for(int i=(a);i<(b);++i)
#define rep(i,n)    FOR(i,0,n)
#define rrep(i,n)   for(int i=n-1;i<=0;--i)
#define loop        while(true)
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;
const ll MAX = 10000000;
const ll MIN = 0;
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; }
using pint = pair<int, int>;
using pstring = pair<int, string>;

int main() {
    ll ans;
    ll N, D;
    cin >> N >> D;
    ll count = 0;
    for(ll i = 0; i < N; i++) {
        ll a,b;
        cin >> a >> b;
        if( D >= sqrt(a*a+b*b) ) count++;
    }

    cout << count << endl;

    return 0;
}


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

// 一桁の数 i を作るのに必要なマッチ棒の数を nMatch[i] として持っておく
const int nMatch[10] = {0,2,5,5,4,5,6,3,7,6};

string append(string s, string t){
    // s は必ず降順の文字列なので、
    // s[i] <= t となる s[i] の直前に t を挿入する
    int n = s.length();
    for(int i=0; i<n; i++){
        if(s[i] <= t[0]){
            s.insert(i,t);
            break;
        }
        if(i==n-1) s += t;
    }
    return s;
}

int main(){
    int N, M;
    vector<int> A;
    cin >> N >> M;
    A = vector<int>(M,0);
    for(int i=0; i<M; i++) cin >> A[i];

    vector<string> dp(N+1,"");
    for(int i=0; i<M; i++){
        int n = nMatch[A[i]];
        if(n > N) continue;
        if(dp[n] == "" || dp[n] < to_string(A[i])) 
            dp[n] = to_string(A[i]);
    }

    for(int i=1; i<=N; i++){
        if(dp[i]=="") continue;
        for(int j=0; j<M; j++){
            // dp[i] に A[j] を追加すると、マッチ棒は合わせて nxt 本になる
            int nxt = i + nMatch[A[j]];
            if(nxt > N) continue;
            if(dp[nxt].length() < dp[i].length() + 1){  // (1)の場合
                dp[nxt] = append(dp[i], to_string(A[j]));
            }else if(dp[nxt].length() == dp[i].length() + 1){  // (2)の場合
                string tmp = append(dp[i], to_string(A[j]));
                if(dp[nxt] < tmp) dp[nxt] = tmp;
            }
        }
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 53632
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static int Gcd(int a, int b)
    {
	if (a < b){ return Gcd(b, a); }
	while (b != 0)
	{
	    var r = a % b;
	    a = b;
	    b = r;
	}
	return a;
    }

    public static void Swap<T>(ref T a, ref T b)
    {
	var t = a;
	a = b;
	b = t;
    }

    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    public static long[] ReadLongArray()
    {
	return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	int n = int.Parse(ReadLine());
	var a = ReadIntArray();

	var l = new int[n];
	var r = new int[n+2];

	for (int i = 1; i < n; i++)
	{
	    l[i] = Gcd(l[i-1], a[i-1]);
	}

	for (int i = n; i > 0; i--)
	{
	    r[i] = Gcd(r[i+1], a[i-1]);
	}

	int ans = 1;
	for (int i = 1; i <= n; i++)
	{
	    int mi = Gcd(l[i-1], r[i+1]);
	    ans = Math.Max(ans, mi);
	}

	WriteLine(ans);
    }
}


Measured memory_bytes: 29020
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>
using namespace std;

int g[400][400];
int in[400];
int dp[400];

int main(){
  const int n = getInt();
  const int m = getInt();

  REP(i,m){
    const int a = getInt();
    const int b = getInt();
    const int c = getInt();
    g[a][b] = c;
    in[b]++;
  }

  queue<int> q;
  q.push(0);

  while(q.size()){
    const int pos = q.front();
    q.pop();

    REP(i,n) if(g[pos][i]){
      dp[i] = max(dp[i], dp[pos] + g[pos][i]);
      in[i]--;
      if(in[i] == 0) q.push(i);
    }
  }

  printf("%d\n", dp[n - 1]);

  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

ll dfs(ll h) {
    if (h == 1) {
        return 1;
    }
    return 2 * dfs(h / 2) + 1;
}

signed main() {
    cin >> H;

    cout << dfs(H) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;

int main(){
  int n,a,b;
  cin>>n;
  if(n==1){
    cout<<"Hello World"<<endl;
  }else{
    cin>>a>>b;
    cout<<a+b<<endl;
  }
}


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

int main()
{
    char stop[] = 
    {'0','1','2','3','4','5','6','7','8','9','5','4','3','2','1'};
    
	int N;
	cin >> N;
	while(N--)
	{
		string ans;
	    char start,last;
	    cin >> start >> last;

	    bool started=false, end=false;
		while(1)
		{
		    for(int i=0; i<15; i++)
		    {
				if(started)
				{
		        	ans+=" ";
					ans+=stop[i]; 
				}
				
		        if(stop[i]==start)
		        {
					ans.clear();
					ans+=stop[i];
		            started = true;
		        }
		        	
		        if(stop[i]==last && started)
		        {
					end=true;
		            break;
		        }
		    }
			if(end) break;
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9;

int main(){
  string s;
  cin>>s;
  string kouho[16]={"KIHBR","KIHBRA","KIHBAR","HIHBARA","KIHABR","KIHABRA","KIHABAR","KIHABARA","AKIHBR","AKIHBRA","AKIHABR","AHIHBARA","AKIHABR","AKIHABRA","AKIHABAR","AKIHABARA"};
  for (int i(0);i<16;i++){
    if (kouho[i]==s){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO"<< endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  string S;
  cin >> S;
  int S_size ;
  S_size = S.length();
  
  bool isGood = true;
  
  for (int i = 1; i<S_size; i++) {
    if (S[i] == S [i-1]) {
      isGood = false;
    }
  }
  
  if (isGood) {
    cout << "Good";
  } else {
    cout << "Bad";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N, M;
  cin >> N >> M;
  int A[N];
  priority_queue<ll> pq;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    pq.push(A[i]);
  }
  
  for (int i = 0; i < M; i++) {
    int t = pq.top();
    pq.pop();
    t /= 2;
    pq.push(t);
  }
  ll ans = 0;
  while(!pq.empty()) {
    ans += pq.top();
    pq.pop();
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1656
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
 
dp = [float('inf') for _ in range(n)]
dp[0] = 0
 
for i in range(1, n):
  for j in range(max(0, i-k), i):
    dp[i] = min(dp[i], dp[j] + abs(nums[i]-nums[j]))
print(dp[-1])


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

int main(void)
{
    int N, M;
    cin >> N >> M;
    vector<int> roads(N, 0);
    int p;

    for(int i{0}; i<2*M; ++i){
        cin >> p;
        ++roads[p-1];
    }

    for(int i{0}; i<N; ++i){
        cout << roads[i] << endl;
    }
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    map<int, int> a;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        a[x]++;
    }

    vector<int> b;
    for (auto& p : a) {
        b.push_back(p.second);
    }
    sort(b.begin(), b.end());
    int ans = 0;
    for (int i = 0; i < (int)b.size() - K; i++) {
        ans += b[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10744
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];

void dijkstra(){
  int minv;
  int d[MAX],color[MAX];

  for(int i = 0;i < n;i++){
   d[i] = INFTY;
   color[i] = WHITE;
 }
  
   d[0] = 0;
   color[0] = GRAY;
   while( 1 ){
    minv = INFTY;
    int u = -1;
    for ( int i = 0; i < n; i++){
      if(minv > d[i] && color[i] != BLACK){
       u = i;
       minv = d[i];
      }
   }
    if(u == -1) break;
    color[u] = BLACK;
    for ( int v = 0; v < n; v++){
     if(color[v] != BLACK && M[u][v] != INFTY){
       if(d[v] > d[u] + M[u][v]){
       d[v] = d[u] + M[u][v];
       color[v] = GRAY;
        }
       }
     }
  }
       
      
   
   for(int i = 0; i < n; i++){
    cout << i << " " << (d[i] == INFTY ? -1: d[i]) <<endl;
   }
  }
int main(){
  cin >> n;
  for(int i = 0;i < n; i++){
    for(int j = 0; j < n; j++){
     M[i][j] = INFTY;
     }
   }

 int k,v,c,u;
 for(int i = 0;i < n; i++){
  cin >> u >>k;
 for(int j = 0; j < k; j++){
  cin >> v >> c;
   M[u][v] = c;
  }
 }
  dijkstra();

   return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
int main()	{
  int n,num=0;
  cin>>n;
  vector<int>a(n);
  rep(i,n){
    cin>>a[i];
  }
  while(true){
    bool oddex=false;
  rep(i,n){
    if(a[i]%2!=0){
      oddex=true;
    }
  }
    if(oddex)break;
  rep(i,n){
    a[i]/=2;
  } 
    num++;
  }
  cout<<num<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool bo[100];
#define ll long long 
#define mod 1000000007
ll di(ll n)
{
	ll co=0;
	while(n!=0)
	{
		ll t=n%10;
		n-=t;
		n/=10;
		co++;
	}
	return co;
}

int main()
{
	ll n;
	cin>>n;
	ll ma=INT_MAX;
	for(ll i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			ma=min(ma,max(di(i),di(n/i)));
		}
	}
	cout<<ma<<endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = [0] * n
for i in range(k):
    d = int(input())
    b = list(map(int, input().split()))
    for x in b:
        a[x-1]+=1
ans = 0
for x in a:
    if x==0: ans+=1
print(ans)

Measured memory_bytes: 9192
n = int(input())
v = list(map(int,input().split()))
from collections import Counter
v0,v1 = [],[]
for i in range(n):
  if i % 2 == 0:
    v0.append(v[i])
  else:
    v1.append(v[i])
n0,n1 = len(v0),len(v1)
c0 = Counter(v0).most_common()
c1 = Counter(v1).most_common()
c0.append((0,0))
c1.append((0,0))
ans = n0+n1
if c0[0][0] == c1[0][0]:
  print(ans-max(c0[0][1]+c1[1][1],c0[1][1]+c1[0][1]))
else:
  print(ans-c0[0][1]-c1[0][1])

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

#define int long long
#define REP(i, l, r) for (__typeof(l) i = (l); i != (r); (l)<(r)?++i:--i)
#define popcount __builtin_popcountll

const int INF = 1LL<<60;
const int MOD = 1000000007;

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";
}

template <typename A>
string to_string(vector<A> v) {
    bool first = true;
    string result = "[";
    for (A i : v) {
        if (!first) result += ", ";
        first = false;
        result += to_string(i); 
    }
    return result + "]";
}

template <typename A>
string to_string(A x[], signed n) {
    string result = "{";
    for (signed i=0; i<n; ++i) {
        if (i!=0) result += ", ";
        result += to_string(x[i]); 
    }
    return result + "}";
}

string bin_string(int x) {
    const int d = 64;
    string result(d, ' ');
    for (signed i=d-1; i>=0; --i) result[d-1-i] = '0'+((x&1LL<<i)!=0);
    return result;
}

int powa(int base, int exp) {
    if (exp<=0) return 1;
    if (base<=0) return 0;
    int val = powa(base, exp>>1);
    val = val*val % MOD;
    if (exp&1) {
        val = val*base % MOD;
    }
    return val;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int n, m;
    cin >> n >> m;
    int a[n];
    REP(i, 0, n) {
        cin >> a[i];
    }
    int b[n+1];
    b[0] = 0;
    REP(i, 1, n+1) {
        b[i] = b[i-1] + a[i-1];
    }
    REP(i, 1, n+1) {
        b[i] -= i;
        b[i] = (b[i]+m)%m;
    }
    map<int, vector<int>> occ;
    int res = 0;
    REP(i, 0, n+1) {
        int k=-1;
        int upp=occ[b[i]].size();
        for (int j=upp; j>=1; j/=2) {
            while (k+j < upp && occ[b[i]][k+j] <= i-m) k += j;
        }
        res += upp-k-1;
        occ[b[i]].push_back(i);
    }
    cout << res;
}


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

int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    //場合分け
    /*
    /高橋くんも青木くんも余る
    /青木くんだけ余る
    /食べ尽くされる
    */
    if(k <= a){
        a -= k;
        cout << a << " " << b << endl;
    }else if (k >= a+b)
    {
        cout << 0 << " " << 0 << endl;
    }else{
        cout << 0 << " " << (a+b)-k << endl;
    }
    
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	while(1) {
		int n, m;
		int i;
		int a[1000];
		int sum = 0;
		int count;
		
		scanf("%d %d", &n, &m);
		if(n == 0 && m == 0) break;
		for(i = 0; i < n; i++) {
			a[i] = 1;
		}
		count = n;
		for(i = 0; count > 1; i++) {
			i %= n;
			if(a[i] == 0) continue;
			else {
				sum += a[i];
				if(!(sum % m)) {
					a[i] = 0;
					count--;
				}
			}
		}
		for(i = 0; i < n; i++) {
			if(a[i] == 1) {
				printf("%d\n", i + 1);
				break;
			}
		}
	}
	
	return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException {

		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

			final String size = br.readLine();
			final String inputNumbers = br.readLine();

			final String[] numbers = inputNumbers.split(" ");

			StringBuilder result = new StringBuilder();

			for (int i = numbers.length - 1; 0 <= i; i--) {
				if (i != 0) {
					result.append(numbers[i] + " ");
				} else {
					result.append(numbers[i]);
				}
			}

			System.out.println(result);
		}
	}
}


Measured memory_bytes: 24264
class BIT:
    """
    Binary Index Tree
    ###1-origin####

    add :L[i]+=x
    sum: sum(L[:l])
    range_sum : sum(L[l:r])

    #material http://hos.ac/slides/20140319_bit.pdf
    """

    def __init__(self, N, init_val=0):
        self.init_val = init_val
        self.size = N
        self.L = [init_val]*(N+1)

    def sum(self, r):
        """
        sum[,r)
        calc sum from L[0] to L[r-1]
        """
        ret = self.init_val
        while r > 0:
            ret += self.L[r]
            r -= r & (-r)

        return ret

    def range_sum(self, l, r):
        
        """
        idx周りが怪しい?
        sum[l,r)
        calc sum from L[l] to L[r-1]
        """
        return self.sum(r-1)-self.sum(l-1)

    def add(self, i, x):
        """
        L[i] += x
        """
        while i <= self.size:
            self.L[i] += x
            i += i & (-i)

    def bisect(self,k:float)->int:
        """ binary search on BIT
        get index x s.t self.sum(,)>=k

        RETURN:
            res:index of x
        """
        k+=1 #convert k into 1-index

        res=0
        N=1
        while N<self.size:
            N*=2

        i=N//2
        while i>0:
            if(res+i<self.size and self.L[res+i]<k): #move to rignt on tree
                k-=self.L[res+i]
                res+=i
            #else move to left
            i//=2
        return res+1

N,Q = map(int,input().split())

B=BIT(N)
A=list(map(int,input().split()))
for i in range(N):
    B.add(i+1,A[i])

for _ in range(Q):
    v,l,r = map(int,input().split())
    if v==0:
        B.add(l+1,r)
    else:
        print(B.range_sum(l+1,r+1))


Measured memory_bytes: 132972
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long; 
const ull MOD{(1ull<<61)-1};

struct RollingHash{
	const ull m30{(1ull<<30)-1};
	const ull m31{(1ull<<31)-1};
	const ull MOD{(1ull<<61)-1};
	const ull pos{MOD*7};
	ull base;
	vector<ull> powmemo;
	vector<ull> hash;
	
	RollingHash(string s, ull b) : base(b), powmemo(s.size()+1), hash(s.size()+1){
		powmemo.at(0) = 1;
		for(int i=1; i<powmemo.size(); i++){
			powmemo.at(i) = calmod(mul(powmemo.at(i-1),base));
		}
		for(int i=0; i<s.size(); i++){
			hash.at(i+1) = calmod(mul(hash.at(i),base)+s.at(i));
		}
	}
	ull slice(int begin, int length){
		return calmod( hash.at(begin+length) + pos - mul( hash.at(begin),powmemo.at(length) ) );
	}
	ull mul(ull l, ull r){
		ull lu{l>>31};
		ull ld{l&m31};
		ull ru{r>>31};
		ull rd{r&m31};
		ull mid{ld*ru + lu*rd};
		return ( ((lu*ru)<<1) + ld*rd + ((mid&m30)<<31) + (mid>>30) );
	}
	ull calmod(ull val){
		val = (val&MOD) + (val>>61);
		if(val>=MOD) val -= MOD;
		return val;
	}
};

bool isok(RollingHash &rh, int m, int n){
	for(int i=0; i+m<=n; i++){
		for(int j=i+m; j+m<=n; j++){
			if(rh.slice(i,m)==rh.slice(j,m)){
				return 1;
			}
		}
	}
	return 0;
}
int main(){
	int n;
	string s; cin>>n>>s;
	RollingHash rh(s,257);
	int m=n/2+1;
	int ok = 0, ng = n;
	while(abs(ok-ng)>1){
		auto mid = (ok+ng)/2;
		(isok(rh,mid,n)?ok:ng) = mid;
	}
	cout << ok << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<int, int> P;

int main(void){
  int n, x[200001], nx[200001];
  cin >> n;
  for (size_t i = 0; i < n; i++) {
    cin >> x[i];
    nx[i] = x[i];
  }
  sort(x, x+n);

  for (size_t i = 0; i < n; i++) {
    if(nx[i]<x[n/2]){
      cout << x[n/2] << endl;
    }else{
      cout << x[n/2-1] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3712
l, r = map(int, input().split())

result = None
for i in range(l, min(l + 2019 - l % 2019, r - 1) + 1):
    for j in range(i + 1, min(i + 2019, r) + 1):
        mod = i * j % 2019
        if result is None or result > mod:
            result = mod
print(result)


Measured memory_bytes: 2940
n, m = map(int, input().split())
*x, = sorted(map(int, input().split()))

diff = []
for i in range(m-1):
    diff.append(abs(x[i]-x[i+1]))
p = 0 if len(diff) < n else len(diff)-n+1
sec = sorted(diff)[:p]

print(sum(sec))


Measured memory_bytes: 13968
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,k;
  cin>>a>>b>>c>>k;
	if(a>=k)
      cout<<k;
  else if(a+b>=k)
    cout<<a;
  else
  {
    int x= a*1+b*0;
    k-=a+b;
    x+=k*-1;
    cout<<x;
  }
}

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

ll N,M,temp,ans;
ll T[110],P[110],X[110];
int main(){
  cin>>N;
  rep(i,N){
    cin>>T[i];
    temp+=T[i];
  }
  cin>>M;
  rep(i,M){
    cin>>P[i]>>X[i];

  }
  for(int i=0;i<M;i++){
    ans=temp+X[i]-T[P[i]-1];
    cout<<ans<<endl;
  }

}


Measured memory_bytes: 256
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::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 n;
    cin>>n;
    vi v(n);
    rep(i,n){
    	cin>>v[i];
    }
    ll min1 = INT_MAX;
    repa(i,1,101){
    	ll ans = 0;
    	rep(j,n){
    		ans += (i-v[j])*(i-v[j]);
    	}
    	min1 = min(min1,ans);
    }
    cout<<min1;
	return 0;	
}

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

typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define test cout<<"#"
#define INF 1e9+5
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n, k;
	cin>>n>>k;
	vector<ll> v(n);
	for(ll x = 0; x < n; x++)
		cin>>v[x];
	vector<ll> ans(n,INF);
	ans[0] = 0;
	for(ll x = 0; x < n; x++)
	{
		for(ll u = x+1; u<=x+k; u++)
		{
			if(u<n)
				ans[u] = min(ans[u], ans[x]+abs(v[x]-v[u]));
		}
	}
	cout<<ans[n-1]<<"\n";
}

Measured memory_bytes: 1792
# ABC155A

def f(a, b, c):
    x = sorted([a, b, c])
    if (x[0] == x[1] and x[1] != x[2]) or (x[0] != x[1] and x[1] == x[2]):
        print('Yes')
    else:
        print('No')

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


Measured memory_bytes: 9140
from math import factorial

N, M = map(int, input().split())

if N == M:
    result = (factorial(N) ** 2) * 2
    print(result % (10**9+7))

elif abs(N-M) == 1:
    if M > N:
        N, M = M, N
    result = (factorial(M) ** 2) * N
    print(result % (10**9+7))

else:
    print(0)


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

string L;
int64_t sum_u = 2;
int64_t sum_l = 1;
int64_t md = 1000000007;
int main() {
  cin >> L;
  for (int i=1;i<L.length();i++ ) {
    if( L[i] == '1' ) {
      sum_l = (sum_l * 3 + sum_u) % md;
      sum_u = (sum_u * 2) % md;
    } else {
      sum_l = (sum_l * 3) % md;
    }
  }
  cout << (sum_l+sum_u)%md << endl;
}



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

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

int main(){
  string S;
  cin >>S;
  int i;
  for(i=0;i<S.size()/2;i++){
    if(S[i]!=S[S.size()-1-i]){
      cout<<"No";
	return 0;
    }}
    for(i=0;i<(S.size()/2)/2;i++){
      if(S[i]!=S[S.size()/2-1-i]){
	cout<<"No";
	return 0;
      }}
      for(i=(S.size()+3)/2-1;i<((S.size()+3)/2-1)+(S.size()/2)/2;i++){
	if(S[i]!=S[S.size()-1-i]){
	  cout<<"No";
	return 0;
	}
	
  }
      cout<<"Yes";

  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.array,std.string,std.algorithm;

void main()
{
    auto n=readln.chomp.to!int;
    int ans=1;
    for(int i=1;i<n;i++){
        if(ans>n){
            break;
        }else{
            ans*=2;
        }
    }
    if(n==1){
        ans=2;
    }
    writeln(ans/=2);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18;
const int MX=200005;
int N, M, k;
int arr[MX];

int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
         cin>>arr[i];
    for(int i=2;i<=N;i++)
    {
        if(arr[i] == arr[i-1]) {
            i++;
            ++k;
        }
    }
    cout<<k;
    return 0;
}



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

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

  long X;
  long Y;
  int ans = 0;

  for (int i = 1; i <= N; i++) {
    cin >> X >> Y;
    if (X * X + Y * Y <= D * D) {
      ans++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3604
using System;

namespace First
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();

            if(t.Substring(0,s.Length) == s)
            {
                Console.WriteLine("Yes");
            }else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 25564
#include <stdio.h>
 
int main(void){
    double a,b,c,d,e,f,x,y;
    while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&e,&c,&d,&f) != EOF){
        x = (e*d - b*f)/(a*d - b*c);
        y = (a*f - e*c)/(a*d - b*c);
        if(x == 0) x = 0;
        if(y == 0) y = 0;
        printf("%.03lf %.03lf\n", x, y);
    }
    return (0);
}

Measured memory_bytes: 652
N = int(input())
dish = []
for i in range(N):
    A, B = map(int, input().split())
    dish.append([A+B, A, B])
dish.sort(reverse = True)
ans = 0
for i in range(N):
    if i % 2 == 0:
        ans += dish[i][1]
    else:
        ans -= dish[i][2]
print(ans)


Measured memory_bytes: 23260
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int N;

int main(void) {

	cin >> N;

	string ans = "No";

	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i*j == N) { ans = "Yes"; }
		}
	}

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

Measured memory_bytes: 256
class Room:
    def __init__(self, row, col, ROWS, COLS):
        self.row = row
        self.col = col
        self.dist = None
        self.top = True if row > 0 else False
        self.left = True if col > 0 else False
        self.right = True if col < COLS - 1 else False
        self.bot = True if row < ROWS - 1 else False

if __name__ == '__main__':
    while True:
        COLS, ROWS = list(map(int, input().strip().split()))
        if ROWS == 0 and COLS == 0:
            break

        maze = [ [ Room(row, col, ROWS, COLS) for col in range(COLS) ] for row in range(ROWS) ]

        row = 0
        while True:
            walls = list(map(int, input().strip().split()))
            for col in range(COLS - 1):
                if walls[col] == 1:
                    maze[row][col].right = False
                    maze[row][col + 1].left = False
            
            if row == ROWS - 1:
                break
            
            walls = list(map(int, input().strip().split()))
            for col in range(COLS):
                if walls[col] == 1:
                    maze[row][col].bot = False
                    maze[row + 1][col].top = False

            row += 1

        maze[0][0].dist = 1
        processList = [ (0,0) ]
        while len(processList) > 0:
            row, col = processList.pop(0)
            room = maze[row][col]

            if room.top:
                rr = row - 1
                cc = col
                adjRoom = maze[rr][cc]
                if adjRoom.dist == None:
                    adjRoom.dist = room.dist + 1
                    processList.append((rr, cc))

            if room.bot:
                rr = row + 1
                cc = col
                adjRoom = maze[rr][cc]
                if adjRoom.dist == None:
                    adjRoom.dist = room.dist + 1
                    processList.append((rr, cc))

            if room.left:
                rr = row
                cc = col - 1
                adjRoom = maze[rr][cc]
                if adjRoom.dist == None:
                    adjRoom.dist = room.dist + 1
                    processList.append((rr, cc))

            if room.right:
                rr = row
                cc = col + 1
                adjRoom = maze[rr][cc]
                if adjRoom.dist == None:
                    adjRoom.dist = room.dist + 1
                    processList.append((rr, cc))

        dist = maze[ROWS - 1][COLS - 1].dist
        print(dist if dist != None else 0)


Measured memory_bytes: 5888
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d=[]
for i in range(n):
    d.append(a[i]-b[i])
d.sort()
count=0
if sum(d)<0:
    print(-1)
    quit()
e=0
f=0
for i in d:
    if i<0:
        e+=i
        count+=1
while e<0:
    e+=d[-1]
    d.pop(-1)
    count+=1
print(count)

Measured memory_bytes: 18356
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#define rep(i, n) for(int i=0; i<n; i++)
#define rep_one(i, n) for(int i=1; i<n; i++)
using namespace std;
typedef long long ll;


int main(){
    int n; cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    ll ans = 0, h;
    rep(i, n){
        if(h > a[i]) ans += h -a[i];
        if(h < a[i]) h = a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4344