akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  int n;
  cin >> n;
  cout << n*800 - ((n/15)*200) << endl;
  ret 0;
}

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

using namespace std;


int main()
{
    int N;
    cin >> N;
    string s;
    cin >> s;
    vector<vector<int>> dp(N, vector<int>(N));
    int ans = 0;
    for(int i=N-1; 0<i; i--){
        for (int j=i-1; -1<j; j--) {
            if(s[i]==s[j]){
                if(i<N-1){
                    dp.at(i).at(j) = std::min(dp[i+1][j+1]+1, i-j);
                }else{
                    dp.at(i).at(j) = 1;
                }
            }else{
                dp.at(i).at(j) = 0;
            }
            if(dp[i][j]>ans){
                ans = dp.at(i).at(j);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 98176
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
int n,arr[N],dp[N];    

int calc(int idx){
    if(idx==n-1)return 0;
    if(idx==n)return 1e5;
    
    if(dp[idx] != -1)
    return dp[idx];
    
    return dp[idx] = min( abs(arr[idx]-arr[idx+1])+calc(idx+1) , abs(arr[idx]-arr[idx+2])+calc(idx+2));
}

int main(){
cin>>n;
for(int i=0;i<n;++i)
cin>>arr[i];

memset(dp,-1,sizeof(dp));

cout<<calc(0);
return 0;    
}

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

int main()
{
    map <int,int> m;

    for(int i=2;i<=13;i++)m[i] = i-1;

    m[1] = 13;

    int a,b; cin >> a >> b;

    if(a == b){
        cout << "Draw" << endl;
    }
    else if(m[a] > m[b]){
        cout << "Alice" << endl;
    }
    else{
        cout << "Bob" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public long[] A;
        public long MOD = 1000000007;

        public void Run()
        {
            N = Input.ReadInt();
            A = Input.ReadLongArray();

            long r = 0;
            while (true)
            {
                bool flg = true;
                for (int i = 0; i < N; i++)
                {
                    long a = A[i] / N;
                    if (a > 0)
                    {
                        flg = false;
                        r += a;
                        for (int j = 0; j < N; j++)
                        {
                            if (i == j) A[j] -= a * N;
                            else A[j] += a;
                        }
                    }
                }

                if(flg) break;
            }

            Console.WriteLine(r);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int n, A, B, p[2000];
int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    cin >> A >> B;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    int cnt0 = 0, cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; i++) {
        if (p[i] <= A) {
            cnt0++;
        }
        if (p[i] > A && p[i] <= B) {
            cnt1++;
        }
        if (p[i] >= B + 1) {
            cnt2++;
        }
    }
    cout << min({cnt0, cnt1, cnt2}) << "\n";
    return 0;
}

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

int main() {
    char b;cin >> b;
    if (b == 'A') cout << 'T' << endl;
    else if (b == 'T') cout << 'A' << endl;
    else if (b == 'C') cout << 'G' << endl;
    else if (b == 'G') cout << 'C' << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VVS = vector<VS>;
using VI = vector<int>;
using VVI = vector<VI>;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const ll MOD = 1e+9 + 7;
// --------------------------------------------------------


const int MAX_N = 3e+3;
VVI dp(MAX_N + 1, VI(MAX_N + 1, 0));

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);

    string S; cin >> S;
    string T; cin >> T;

    int N = SZ(S);
    int M = SZ(T);
    S = ' ' + S;
    T = ' ' + T;
    FOR(i, 1, N + 1) FOR(j, 1, M + 1) {
        if (S[i] == T[j]) {
            dp[i][j] = dp[i - 1][j - 1] + 1;
        } else {
            dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
        }
    }

    // LCS 復元
    int len = dp[N][M], i = N, j = M;
    string ans = string(len, ' ');
    while (len > 0) {
        if (S[i] == T[j]) {
            ans[--len] = S[i];
            i--; j--;
        } else if (dp[i][j] == dp[i - 1][j]) {
            i--;
        } else {
            j--;
        }
    }
    cout << ans << '\n';

    return 0;
}


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

template<class T> inline bool chmax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

char s[3100];
char t[3100];
char ans[3100];
long dp[3100][3100];

int main(){
	scanf("%s%s", s, t);
	int n = strlen(s);
	int m = strlen(t);
	for(int i=0; i < n; i++) {
		for(int j=0; j < m; j++) {
			if(s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j] + 1);
			chmax(dp[i+1][j+1], dp[i+1][j]);
			chmax(dp[i+1][j+1], dp[i][j+1]);
		}
	}

	int idx = dp[n][m] - 1;
	while(n > 0 && m > 0) {
		if(dp[n][m] == dp[n-1][m]) n--;
		else if(dp[n][m] == dp[n][m-1]) m--;
		else {ans[idx--] = s[n-1]; n--; m--;}
	}
	printf("%s\n", ans);
}


Measured memory_bytes: 73984
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll sx, sy, tx, ty;
    cin >> sx >> sy;
    cin >> tx >> ty;
    ll dx = tx - sx;
    ll dy = ty - sy;

    string ans; ans.reserve(max(dx, dy) * 4 + 4);
    
    REP(i, dy) ans.push_back('U');
    REP(i, dx) ans.push_back('R');
    REP(i, dy) ans.push_back('D');
    REP(i, dx) ans.push_back('L');

    ans += "LU";
    REP(i, dy) ans.push_back('U');
    REP(i, dx) ans.push_back('R');
    ans += "RDRD";
    REP(i, dy) ans.push_back('D');
    REP(i, dx) ans.push_back('L');
    ans += "LU";

    cout << ans << endl;
    
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    a, v = map(int, input().split())
    b, w = map(int, input().split())
    t = int(input())

    d = v - w

    if abs(a-b) <= t * d:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9180
#include<stdio.h>
int main()
{
	int i, n, temp, j, c=0;
	int a[100];
	int flag = 1;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	while (flag) {
		flag = 0;
		for (j = n - 1; j > 0; j--) {
			if (a[j] < a[j - 1]) {
				temp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = temp;
				c++;
				flag = 1;
			}
		}
	}
	for (i = 0; i < n; i++) {
		if (i == n - 1) {
			printf("%d\n", a[i]);
			break;
		}
		printf("%d ", a[i]);
	}
	printf("%d\n", c);

}

Measured memory_bytes: 2732
#include<stdio.h>
int main(void)
{
  int a, b, c, i;
  scanf("%d %d %d", &a, &b, &c);
  if(a > b)
    {
      i = a;
      a = b;
      b = i;
    }
  
  if(b > c)
    {
      i = b;
      b = c;
      c = i;
    }
  
  if(a > b)
    {
      i = a;
      a = b;
      b = i;
    }

  printf("%d %d %d\n", a, b, c);
  return 0;
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
#include <functional>
#include <iostream>
#define  pb push_back
#define  xx first
#define  yy second
//#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

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

int main()
{
    int n;
    cin >> n;
    ll a[n+1],sum = 0;
    for(int i = 1; i<=n; i++) {
            cin >> a[i];
    }
    ll res = 1000000001;
    for(int i = 1;i<=100; i++){
        ll ans = 0;
        for(int j = 1; j<=n; j++){
            ans +=(abs(i-a[j])*abs(i-a[j]));
        }
        res = min(res,ans);
    }

    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string o; readV(o);
  string e; readV(e);

  foreach (i; 0..e.length)
    write(o[i], e[i]);

  if (o.length > e.length)
    write(o[$-1]);

  writeln;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  char s[3];
  int t[3]={0};
  scanf("%s",s);
  int i,j=0;
    for(i=0;i<3;i++){
      if(s[i]=='a') t[0]=1;
        else if(s[i]=='b') t[1]=1;
               else t[2]=1;
    }  
    if(t[0]==1 && t[1]==1 && t[2]==1) printf("Yes");
      else printf("No");    
  return 0;
}


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

int main()
{
    //freopen("in.txt","r",stdin);
    int cnt = 1,n;
    string color;
    cin >> n >> color;
    for(int i=0;i<n-1;i++){
        if(color[i]!=color[i+1])    cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <map>
using namespace std;

map<int, int> t;

int main(void)
{
	int n, a, i;

	scanf("%d", &n);
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &a);

		if (t[a])
		{
			puts("NO");
			return 0;
		}

		t[a] = 1;
	}

	puts("YES");
	return 0;
}

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

using namespace std;

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

    vector<double> x(n), y(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }

    double ans = 0.0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            double dx = x[i] - x[j];
            double dy = y[i] - y[j];
            ans += pow(dx * dx + dy * dy, 0.5);
        }
    }

    cout << fixed << setprecision(10);
    cout << ans * 2 / n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
#define Ford(i, l, r) for (register int i = r, _l = l; i >= _l; --i)
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 20;
int n;
char s[]="aaaaaaaaaa";
inline int read()
{
	int x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){if (ch == '-')f = -1;ch = getchar();}
	while (ch >= '0' && ch <= '9'){x = (x << 3) + (x << 1) + ch - '0';ch = getchar();}
	return x * f;
}

inline void dfs(int now,int hst)
{
	if(now==n)
	{
		printf("%s\n",s);
		return;
	}
	For(i,1,hst)
		s[now]='a'+i-1,dfs(now+1,hst);
	if(hst<n) s[now]='a'+hst,dfs(now+1,hst+1);
}

int main()
{
	n=read();
	s[n]='\0';
	dfs(1,1);
	return 0;
}

Measured memory_bytes: 1536
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s=sc.next();
    String sub=s.substring(1,s.length()-1);
    String result=s.charAt(0) +"";
    result+=sub.length() + ""+s.charAt(s.length()-1);
    System.out.println(result);
  }
}

Measured memory_bytes: 22608
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	long long n;
	long long a;
	long long s=0;
	cin>>n;
	a=n;
	while(n!=0)
	{
		s+=n%10;
		n=n/10;
	}
	if(a%s==0)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	
}

Measured memory_bytes: 256
n=int(input())
h=list(map(int, input().split()))

ans=1
a=0

for i in range(1,n):
    for k in range(i):
        if h[k]>h[i]:
            a=1
    
    if a==0:
        ans+=1
    
    a=0
    
print(ans)

Measured memory_bytes: 9092
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
Tenka1-2018 C
"""

n = int(input())
m = -1
for i in range(1, 500):
    if i*(i-1)//2 == n:
        m = i
if m is -1:
    print('No')
    exit()

alili = [[] for i in range(m)]
for j in range(1, m):
    tmp = (2*m-j)*(j-1)//2
    for i in range(1, m-j+1):
        i2 = tmp+i
        alili[j-1].append(i2)
        alili[j-1+i].append(i2)


print('Yes')
print(m)
for j in range(m):
    print(m-1, " ".join(map(str, alili[j])))


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

using namespace std;

bool valid(char a){
 return a == 'A' || a == 'G' || a == 'T' || a == 'C';
}

int main(){
  string s;
  cin >> s;
  int ans = 0;
  int curr = 0;
  for(int i = 0; i < s.size(); i++){
  	if(valid(s[i])){
    	curr++;
        ans = max(ans, curr);
    }else{
    	curr = 0;
    }
  }
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	for i := 0; i < len(s); i++ {
		if s == t {
			fmt.Println("Yes")
			return
		}
		s = s[len(s)-1:] + s[:len(s)-1]
	}
	fmt.Println("No")
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
const int N=200005;
int flag,n,a[N],b[N],q[N],tot;
ll ans;
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read(); b[i]=read();
		if(a[i]!=b[i])flag=1;
	}
	if(flag){
		for(int i=1;i<=n;i++)if(a[i]<=b[i]){ans+=b[i]; }else q[++tot]=b[i];
		sort(&q[1],&q[tot+1]);
		for(int i=tot;i>1;i--)ans+=q[i];
		cout<<ans<<endl;
	}else puts("0");
}


Measured memory_bytes: 512
a,b = map(int, input().split())
 
 #最大公約数
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
#print(gcd(a,b))

 #最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)
print(lcm(a,b))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    long long n,a[300005],ans=0;
    cin>>n;
    for(int i=0;i<n*3;i++){
        cin>>a[i];
    }
    sort(a,a+n*3,greater<long long>());
    for(int i=1;i<2*n;i+=2){
        ans+=a[i];
    }
    cout<<ans<<endl;
	return(0);
}

Measured memory_bytes: 5864
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>

using namespace std;

#define Getsign(n) ((n > 0) - (n < 0))
#define QWERTYR(c) (c == 'y' || c == 'u' || (c >= 'h' && c <= 'p') ?	true : false)
map<string, int> roma_time = { { "I",1 },{ "II",2 },{ "III",3 },{ "IIII",4 },{ "V",5 },{ "VI",6 },{ "VII",7 },{ "VIII",8 },{ "IX",9 },{ "X",10 },{ "XI",11 },{ "XII",12 } };

typedef vector<int> Ivec;
typedef pair<int, int> pii;

int main() {
	int n, Max, Min;
	while (scanf("%d %d %d", &n, &Min, &Max)) {
		if (n == 0)
			return 0;

		vector<int> points;

		for (int i = 0; n > i; i++) {
			int p;
			scanf("%d", &p);
			points.push_back(p);
		}
		int num, Maxim = -1;
		for (int i = Min-1; Max-1 >= i; i++) {
			if (points[i] - points[i + 1] >= Maxim) {
				num = i;
				Maxim = points[i] - points[i + 1];
			}
		}
		printf("%d\n", num + 1);
	}
	return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
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; }

int main() {
  ll N, K;
  cin >> N >> K;
  ll ans = K;
  rep(i, 0, N - 1) ans *= (K - 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<stack>
#include<map>
#include<queue>
#include<unordered_map>
#include<cmath>
#include<utility>

using ULL = unsigned long long;
using LL = long long;
using String = std::string;
using Ints = std::vector<int>;
using Doubles = std::vector<double>;
using Bools = std::vector<bool>;
using Strings = std::vector<std::string>;
using ULLs = std::vector<ULL>;
using LLs = std::vector<LL>;

// pythonのdictionary相当
template <typename T1, typename T2>
using Dict = std::unordered_map<T1,T2>;



int main(void) {
    int N,K;
    LL res=0;
    Ints A;
    std::cin >> N >> K;

    for(int i=0;i<N;i++){
        int a;
        std::cin >> a;
        A.push_back(a);
    }
    std::sort(A.begin(),A.end());

    for(int i=0;i<K&&i<N;i++){
        res+=A[i];
    }

    std::cout << res << std::endl;
    return 0;
}

Measured memory_bytes: 3640
import heapq
def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

################################
n,w = map(int,input().split()) #n:頂点数　w:辺の数

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(w):
    x,y = map(int,input().split())
    edge[x-1].append([1,y-1])
    edge[y-1].append([1,x-1]) 
d = dijkstra_heap(0)

OK_flag = True

dic = {}
for i in range(n):
    if d[i] == float("inf"):
        OK_flag = False
    dic[d[i]] = i


if OK_flag == True:
    print("Yes")
    for i in range(1, n):
        print(dic[d[i]-1]+ 1)
else:
    print("No")




Measured memory_bytes: 72192
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=1;i<=b;i++){
		if((a*i)%b==c){
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
	return 0;
}

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

// using namespace std;
// using ll = long long;

// const int mod = 1000000007;
// struct mint {
//   ll x;
//   mint(ll x = 0) : x(x % mod) {}
//   mint operator-() const { return mint(-x); }
//   mint& operator+=(const mint a) {
//     if ((x += a.x) >= mod) {
//       x -= mod;
//     }
//     return *this;
//   }
//   mint& operator-=(const mint a) {
//     if ((x += mod - a.x) >= mod) {
//       x -= mod;
//     }
//     return *this;
//   }
//   mint& operator*=(const mint a) {
//     (x *= a.x) %= mod;
//     return *this;
//   }
//   mint operator+(const mint a) const {
//     mint res(*this);
//     return res += a;
//   }
//   mint operator-(const mint a) const {
//     mint res(*this);
//     return res -= a;
//   }
//   mint operator*(const mint a) const {
//     mint res(*this);
//     return res *= a;
//   }
//   mint pow(ll t) const {
//     if (!t) {
//       return 1;
//     }
//     mint a = pow(t >> 1);
//     a *= a;
//     if (t & 1) {
//       a *= *this;
//     }
//     return a;
//   }

//   mint inv() const { return pow(mod - 2); }
//   mint& operator/=(const mint a) { return (*this) *= a.inv(); }
//   mint operator/(const mint a) const {
//     mint res(*this);
//     return res /= a;
//   }
// };

// mint f(int n) {
//   if (n == 0) {
//     return 1;
//   }
//   mint x = f(n / 2);
//   x *= x;
//   if (n % 2 == 1) {
//     x *= 2;
//   }
//   return x;
// }
// mint choose(int n, int a) {
//   mint x = 1, y = 1;
//   rep(i, a) {
//     x *= n - i;
//     y *= i + 1;
//   }
//   return x / y;
// }
// int main() {
//   int n, a, b;
//   cin >> n >> a >> b;
//   mint ans = f(n);
//   ans -= 1;
//   ans -= choose(n, a);
//   ans -= choose(n, b);
//   cout << ans.x << endl;
//   return 0;
// }

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll MOD = 1000000007;

ll mod_pow(ll n, ll x) {
  if (x == 0) return 1;
  if (x == 1) return n;
  ll v = mod_pow(n, x/2);
  v *= v;
  v %= MOD;
  if (x%2 == 1) v *= n;
  return v % MOD;
}

ll mod_inv(ll a) {
  return mod_pow(a, MOD - 2) % MOD;
}

ll nck(ll n, ll k) { 
  ll x = 1, y = 1;
  for (ll i = 0; i < k; i++) {
    x *= n-i;
    x %= MOD;
    y *= mod_inv(i+1);
    y %= MOD;
  }
  return (x * y) % MOD;
}

int mod(ll n) {
  while (n < 0) n += MOD;

  return n % MOD;
}

int main()
{
  ll n, a, b;
  cin >> n >> a >> b;
  ll v = mod_pow(2, n) - nck(n, a) - nck(n, b) - (ll)1;
  cout << mod(v) << endl;
  
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 1e3+10;


int main() {
	int n = rd();
	map<int,int> s;
	REP(i,1,n) ++s[rd()];
	if (n<=2) return puts("Possible"),0;

	{
	int mi = s.begin()->x, ma = s.rbegin()->x;
//	if (mi!=(ma+1)/2) return puts("Impossible"),0;
//	REP(i,mi+1,ma) {
//		int cnt = 0;
//		if (!s.count(i)||s[i]==1) return puts("Impossible"),0;
//	}
	if (s.begin()->y!=(ma&1)+1) return puts("Impossible"),0;
	}
	int len = s.rbegin()->x, L = 1, R = len+1;
	if (s.rbegin()->y<2) return puts("Impossible"),0;
	s.erase(len);
	int mi = 1e9;
	REP(i,2,len) {
		int d = max(abs(i-L),abs(i-R));
		if (s.count(d)) { 
			if (!--s[d]) s.erase(d);
		}
		else return puts("Impossible"),0;
		mi = min(mi, d+1);
	}


	puts("Possible");	
}









Measured memory_bytes: 256
//98tarunkumar
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rlop(i,n) for(int i=n;i>0;i--)
#define lli long long int
#define sf ios::sync_with_stdio(false); cin.tie(NULL);
#define ainp(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define aout(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";
#define f(i, a, b) for(int i=a; i<b; i++)
#define lop(a,b) for(int i=a;i<b;i++)
#define ln cout<<"\n"
#define MOD 1e9+7

/*int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1};*/ // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction




int main(){
	sf;
	
	
	lli l,r,d;
	cin>>l>>r>>d;
	lli c=0;
	for(int i=l;i<=r;i++){
		if(i%d==0)
			c++;
	}
	cout<<c;

	


	
}








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

int main()
{
    int n, c;
    cin >> n >> c;
    
    int a[c][200010] = {{}};
    for(int i = 0; i < n; i++)
    {
        int s, t, ch;
        cin >> s >> t >> ch;
        a[ch-1][s*2-1]++;
        a[ch-1][t*2]--;
    }
    int ans = 0;
    for(int i = 0; i < 200005; i++)
    {
        int cnt = 0;
        for(int j = 0; j < c; j++)
        {
            a[j][i + 1] += a[j][i];
            if(a[j][i] > 0)
            {
                cnt++;
            }
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 23680
N, = [int(i) for i in input().split(' ')]
import sys
As = []
for line in sys.stdin:
    As.append(int(line.strip()))

As = sorted(As)
r = 0
r2 = 0
if N == 2:
    r = As[1] - As[0]
elif N == 3:
    r = max(2*As[2] - As[1] - As[0], As[2] + As[1] - 2 * As[0])
elif N % 2 == 1:
    r -= sum(As[:(N//2) - 1]) * 2
    r -= As[(N // 2)] + As[(N // 2) - 1]
    r += sum(As[(N // 2)+1:]) * 2
    #print(r)

    r2 -= sum(As[:(N//2)]) * 2
    r2 += As[(N // 2)+1] + As[(N // 2)]
    r2 += sum(As[(N // 2)+2:]) * 2
    #print(r2)
    r = max(r, r2)
else:
    #print(As[:(N//2) - 1])
    r -= sum(As[:(N//2) - 1]) * 2
    r += As[(N // 2)] - As[(N // 2) - 1]
    r += sum(As[(N // 2)+1:]) * 2
    #r2 -= sum(As[:(N//2)]) * 2
    #r2 += As[(N // 2)+1] + As[(N // 2)]
    #r2 += sum(As[(N // 2)+2:]) * 2
    #r = max(r, r2)
print(r)


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

using namespace std;

using lint = long long;
using ldouble = long double;

const int INF = 1 << 30;

int main() {
    int N, M, K;
    cin >> N >> M >> K;

    vector<int> D(M);
    map<int, int> rev;
    for (int i = 0; i < M; ++i) {
        cin >> D[i];
        rev[--D[i]] = i;
    }

    vector<vector<int>> path(N, vector<int>(K));
    for (auto& v : path) {
        for (auto& e : v) {
            cin >> e;
            --e;
        }
    }

    vector<vector<int>> graph(1 << M);
    for (int b = 0; b < (1 << M); ++b) {
        for (int a = 0; a < K; ++a) {
            int tob = 0;

            for (int i = 0; i < M; ++i) {
                if (!((b >> i) & 1)) continue;
                int to = path[D[i]][a];
                if (!rev.count(to)) continue;
                tob |= (1 << rev[to]);
            }

            graph[b].push_back(tob);
        }
    }

    vector<int> dist(1 << M, INF);
    dist[(1 << M) - 1] = 0;
    queue<int> que;
    que.push((1 << M) - 1);

    while (!que.empty()) {
        int v = que.front();
        que.pop();

        for (auto sv : graph[v]) {
            if (dist[sv] < INF) continue;
            dist[sv] = dist[v] + 1;
            que.push(sv);
        }
    }

    cout << dist[0] << endl;
    return 0;
}



Measured memory_bytes: 38808
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	Info(){
		x = y = mushi_count = time = 0;
	}
	Info(int arg_x,int arg_y,int arg_mushi_count,int arg_time){
		x = arg_x;
		y = arg_y;
		mushi_count = arg_mushi_count;
		time = arg_time;
	}
	bool operator<(const struct Info &arg) const{
		return mushi_count > arg.mushi_count;
	};

	int x,y,mushi_count,time;
};

int limit_x,limit_y;
int calc_X = 100,calc_Y = 100;

int diff_x_GU[7] = {0,1,1,0,-1,-1,0},diff_y_GU[7] = {1,0,-1,-1,-1,0,0};
int diff_x_KI[7] = {0,1,1,0,-1,-1,0},diff_y_KI[7] = {1,1,0,-1,0,1,0};

int min_Count[210][210][6];
bool check[210][210];

bool rangeCheck(int x,int y){
	if(abs(x) <= limit_x && abs(y) <= limit_y)return true;
	else{
		return false;
	}
}

int calc(int x,int y,int time){
	return abs(x*y*time)%6;
}

int main(){

	for(int i = 0; i < 210; i++){
		for(int k = 0; k < 210; k++){
			for(int p = 0; p < 6; p++)min_Count[i][k][p] = BIG_NUM;
			check[i][k] = true;
		}
	}

	int start_x,start_y,goal_x,goal_y;
	scanf("%d %d %d %d",&start_x,&start_y,&goal_x,&goal_y);

	int N,tmp_x,tmp_y;
	scanf("%d",&N);

	for(int loop = 0; loop < N; loop++){
		scanf("%d %d",&tmp_x,&tmp_y);
		check[tmp_x+calc_X][tmp_y+calc_Y] = false;
	}

	scanf("%d %d",&limit_x,&limit_y);

	Info first;
	first.x = start_x;
	first.y = start_y;
	first.mushi_count = 0;
	first.time = 0;

	min_Count[start_x+calc_X][start_y+calc_Y][0] = 0;

	priority_queue<Info> Q;
	Q.push(first);

	int ans = BIG_NUM,next_x,next_y;

	while(!Q.empty()){

		if(Q.top().x == goal_x && Q.top().y == goal_y){
			ans = Q.top().mushi_count;
			break;
		}else if(Q.top().mushi_count > min_Count[Q.top().x+calc_X][Q.top().y+calc_Y][Q.top().time%6]){
			Q.pop();
		}else{
			int op = calc(Q.top().x,Q.top().y,Q.top().time);

			for(int i = 0; i < 7; i++){
				if(Q.top().x%2 == 0){
					next_x = Q.top().x+diff_x_GU[i];
					next_y = Q.top().y+diff_y_GU[i];
				}else{
					next_x = Q.top().x+diff_x_KI[i];
					next_y = Q.top().y+diff_y_KI[i];
				}

				if(rangeCheck(next_x,next_y) == true && check[next_x+calc_X][next_y+calc_Y] == true){
					if(i == op){
						if(min_Count[next_x+calc_X][next_y+calc_Y][(Q.top().time+1)%6] > Q.top().mushi_count){
							min_Count[next_x+calc_X][next_y+calc_Y][(Q.top().time+1)%6] = Q.top().mushi_count;
							Q.push(Info(next_x,next_y,Q.top().mushi_count,Q.top().time+1));
						}
					}else{
						if(min_Count[next_x+calc_X][next_y+calc_Y][(Q.top().time+1)%6] > Q.top().mushi_count+1){
							min_Count[next_x+calc_X][next_y+calc_Y][(Q.top().time+1)%6] = Q.top().mushi_count+1;
							Q.push(Info(next_x,next_y,Q.top().mushi_count+1,Q.top().time+1));
						}
					}
				}
			}
			Q.pop();
		}
	}

	if(ans == BIG_NUM){
		printf("-1\n");
	}else{
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 4396
import sys
def input(): return sys.stdin.readline().rstrip()

def solve(l, m):
    if l < m:
        return l * 2 + m
    else:
        return l + m * 2

def main():
    N, K = map(int, input().split())
    x = tuple(map(int, input().split()))
    right_x = [i for i in x if i >= 0][:K]
    left_x = [-i for i in x if i < 0][-K:]

    left_len = len(left_x)
    right_len = len(right_x)
    if right_len < K:
        right_x += [10 ** 9 + 1] * (K - right_len)
    if left_len < K:
        left_x = [10 ** 9 + 1] * (K - left_len) + left_x

    right_x = [0] + right_x
    left_x += [0]

    ans = 10 ** 9
    for i in range(K + 1):
        tmp_ans = solve(left_x[i], right_x[i])
        if tmp_ans < ans:
            ans = tmp_ans
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15028
//    ? WHY YOU OPEN THIS ?    //
 
#include<bits/stdc++.h>
using namespace std;
#define int long long
 
#define PAIR    pair<int,int>
#define Vector  vector<int>
#define MAP     map<int,int>
#define pb      push_back
#define mk      make_pair
#define sz(x)   (int)(x).size()
#define MOD     1e9+7 
#define all(a)  begin(a),end(a)
#define F       first
#define S       second
 
#define FOR(i,a,b)     for(int i=a;i<b;i++)
#define ROF(i,a,b)     for(int i=a;i>=b;i--)
#define check(c)       cout<<#c<<" : "<<c<<endl;
#define check2(a,b)    cout<<#a<<" : "<<a<<" | "<<#b<<" : "<<b<<endl;
#define check3(a,b,c)  cout<<#a<<" : "<<a<<" | "<<#b<<" : "<<b<<" | "<<#c<<" : "<<c<<endl;
#define SWIFT          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// int gcd(int a, int b) 
// { 
//     if (b == 0) 
//         return a; 
//     return gcd(b, a % b);  
// } 

void testCase(){
    int n, ans = 0; cin >> n;
    int prev; cin >> prev;
    FOR(i, 1, n){
        int x; cin >> x;
        if(x < prev){
            //check(i)
            ans += prev - x;
        }
        prev = max(prev ,x);
            // check(prev)
        
    }
    cout << ans << '\n';
}
    
     
signed main(){
    SWIFT;
    
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    int t = 1;
    // int t; cin >> t;
    FOR(i, 0, t){
        testCase();
    }
    return 0;
}

Measured memory_bytes: 3664
#include<stdio.h>
#include<math.h>
#define M 10000

int Prime(int x);

main(){
  int n,c=0;
  int i;
  int A[M];

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);

  for(i=0;i<n;i++){
    if(Prime(A[i])==1)c++;
  }
 
  printf("%d\n",c);

  return 0;

}
 

int Prime(int x){
  int i=3;

  if(x==2)return 1;

  if(x<2||x%2==0)return 0;

  while(i<=sqrt(x)){
    if(x%i==0)return 0;
    i=i+2;
  }

  return 1;

}



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

int N;

int ans=0;

void dfs(long long n,int three,int five,int seven){
  if (n>N){
    return;
  }
  if (three&&five&&seven){
    ans++;
  }
  dfs(10*n+3,1,five,seven);
  dfs(10*n+5,three,1,seven);
  dfs(10*n+7,three,five,1);
  return;
}

int main() {
  cin >> N;
  dfs(0,0,0,0);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
typedef pair<double, double> doup;

ll modpow(ll x, ll n) {
    ll res=1;
    while(n>0) {
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

ll digitCnt(ll n) {
    ll res=0;
    while(n>0) {
        n/=10;
        res++;
    }
    
    return res;
}

int main(void) {
    ll N, i;
    cin >> N;
    ll ans=digitCnt(N);
    ll f;
    for(i=1; i*i<=N; i++) {
        if(N%i==0) {
            f=max(digitCnt(i), digitCnt(N/i));
            ans=min(ans, f);
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
INF = 10 ** 9

def main():
    H, N = map(int, input().split())
    dp = [INF] * (H+1)
    dp[0] = 0
    for _ in range(N):
        a, b = map(int, input().split())
        for j in range(H):
            nj = min(j+a, H)
            dp[nj] = min(dp[nj], dp[j]+b)

    print(dp[H])

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 41840
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
typedef long long int ll;

int main()
{
    int n;
    int a,b;

    while(scanf("%d",&n) != EOF)
    {
        a = n/100;
        b = n%10;
        if(a == b) printf("Yes\n");
        else printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
 
int W,H;
int POW[21],dp[1048576],next_dp[1048576];
int table[20][20];
vector<int> V;
int case_num = 1;
 
void recursive(int array[],int index){
 
    if(index == W){
        int code = 0;
        for(int i = 0; i < W; i++){
            if(array[i] == 1)code += POW[i];
        }
        V.push_back(code);
        return;
    }
 
    if(array[index-1] == 1){
        int next_array[W];
        for(int i = 0; i < index; i++)next_array[i] = array[i];
        next_array[index] = 0;
        recursive(next_array,index+1);
    }else{
 
        int next_array1[W];
        for(int i = 0; i < index; i++)next_array1[i] = array[i];
        next_array1[index] = 1;
        recursive(next_array1,index+1);
 
        int next_array2[W];
        for(int i = 0; i < index; i++)next_array2[i] = array[i];
        next_array2[index] = 0;
        recursive(next_array2,index+1);
    }
}
 
void func(){
 
    scanf("%d %d",&W,&H);
    if(W > H){
 
        for(int row = 0; row < H; row++){
            for(int col = 0; col < W; col++)scanf("%d",&table[col][row]);
        }
        swap(W,H);
    }else{
        for(int row = 0; row < H; row++){
            for(int col = 0; col < W; col++)scanf("%d",&table[row][col]);
        }
    }
 
    int first_array0[W],first_array1[W];
 
    V.clear();
 
    first_array0[0] = 0;
    recursive(first_array0,1);
    first_array1[0] = 1;
    recursive(first_array1,1);
 
 
    sort(V.begin(),V.end());
    V.erase(unique(V.begin(),V.end()),V.end());
 
 
    for(int i = 0; i < V.size(); i++){
        dp[V[i]] = 0;
        next_dp[V[i]] = 0;
    }
 
    int state,sum,maximum;
 
    for(int row = 0; row < H; row++){
 
        for(int i = 0; i < V.size(); i++){
            state = V[i];
            sum = 0;
            for(int loop = 0; loop < W; loop++){
                if(state & (1 << loop)){
                    sum += table[row][loop];
                }
            }
            next_dp[state] = sum;
 
            maximum = 0;
            for(int k = 0; k < V.size(); k++){
                if((state&V[k])==0){
                    maximum = max(maximum,dp[V[k]]);
                }
            }
            next_dp[state] += maximum;
        }
        for(int i = 0; i < V.size(); i++){
            dp[V[i]] = next_dp[V[i]];
        }
    }
 
    int ans = 0;
    for(int i = 0; i < V.size(); i++){
        ans = max(ans,dp[V[i]]);
    }
 
    printf("Case %d: %d\n",case_num++,ans);
 
}
 
int main(){
 
    for(int i = 0; i < 21; i++)POW[i] = pow(2,i);
 
    int data_set;
    scanf("%d",&data_set);
 
    for(int i = 0; i < data_set; i++)func();
 
    return 0;
}

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

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

    int x, y;
    cin >> x >> y;

    x = min(x, 4);
    y = min(y, 4);

    int ans = 100000 * (4 - x + 4 - y);

    if(x == 1 && y == 1)
        ans += 400000;

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 896
def resolve():
    k=int(input())
    list=[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]
    print(list[k-1])
resolve()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define maxN 200007
using namespace std;
int main() {
  fastio;
  ll n = 0, W = 0;
  cin >> n >> W;
  ll w[n], v[n];
  for (ll i = 0; i < n; ++i)
    cin >> w[i] >> v[i];
  ll dp[n + 1][W + 1];
  for (ll i = 0; i <= n; ++i) {
    for (ll j = 0; j <= W; ++j) {
      if (i == 0 or j == 0)
        dp[i][j] = 0;
      else if (j >= w[i - 1])
        dp[i][j] = max(v[i - 1] + dp[i - 1][j - w[i - 1]], dp[i - 1][j]);
      else
        dp[i][j] = dp[i - 1][j];
    }
  }
  cout << dp[n][W];
}

Measured memory_bytes: 82376
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll h,n,x,sum=0;
    cin>>h>>n;
    for(ll i=0;i<n;i++){
        cin>>x;
        sum+=x;
    }
    if(sum>=h){
        cout<<"Yes"<<endl;
    }else{cout<<"No"<<endl;}
    return 0;


}



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

using namespace std;

int main() {
    vector<int> c(3);
    for (int i = 0; i < 3; ++i) cin >> c.at(i);
    sort(c.begin(), c.end());
    cout << accumulate(c.begin(), c.end(), 0) - c.at(1) * 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll n,a[100050],b[100050],c[100050];
	cin >> n;
	for(int i=1; i<=n; i++)cin >> a[i];
	for(int i=1; i<=n; i++)cin >> b[i];
	for(int i=1; i<=n; i++)cin >> c[i];
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(c+1,c+n+1);
	ll jwb=0;
	for(int i=1; i<=n; i++){
		ll x=b[i];
		ll l=1,r=n,mid,jwb1=0,jwb2=n+1;
		while(l<=r){
			mid=(l+r)/2;
			if(a[mid]>=x){
				r=mid-1;
			}
			else{
				l=mid+1;
				jwb1=mid;
			}
		}
		l=1,r=n;
		while(l<=r){
			mid=(l+r)/2;
			if(c[mid]<=x){
				l=mid+1;
			}
			else{
				r=mid-1;
				jwb2=mid;
			}
		}
		//cout << jwb1 << " " << n-jwb2+1 << endl;
		jwb+=(jwb1)*(n-jwb2+1);
	}
	cout << jwb << endl;
}

Measured memory_bytes: 5884
inp = input ()

inplist = [char for char in inp]

playable = True

for i in range (0,len(inplist)):
    if i%2 == 0:
        if inplist[i] not in ('RUD'):
          playable = False
          break
    else:
        if inplist[i] not in ('LUD'):
          playable = False
          break

if playable:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
struct person{
  int num;
  int Num;
};
bool cmp(const person a, const person b){
  return a.num<b.num;
}
int main(){
  int N;
  cin >> N;
  struct person A[N];
  int ans=0;
  rep(i,N){
    cin >> A[i].num;
    A[i].Num = i+1;
  }
  sort(A,A+N,cmp);
  cout << A[0].Num;
  for(int i=1; i<N; i++) cout << " " << A[i].Num;
  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000000;
int dx[8]={0,0,1,1,1,-1,-1,-1};
int dy[8]={1,-1,1,-1,0,1,-1,0};
int main(){
    int n,m,l,k,a,h;
    while(cin>>n>>m>>l>>k>>a>>h,m+n+m+l+k+a+h){
        vector<int> v(l+2);
        bool f[110]={false};
        int d[110][110],d2[110][110];
        for(int i=0;i<n;i++)for(int j=0;j<n;j++)d[i][j]=d2[i][j]=INF;
        for(int i=0;i<n;i++)d[i][i]=d2[i][i]=0;
        for(int i=0;i<l;i++){
            cin>>v[i];
        }
        v[l]=h,v[l+1]=a;
        for(int i=0;i<k;i++){
            int x,y,t;cin>>x>>y>>t;
            d[x][y]=t;
            d[y][x]=t;
        }
        for(int k=0;k<n;k++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
                }
            }
        }
        for(int i=0;i<l+2;i++){
            for(int j=0;j<l+2;j++){
                if(d[v[i]][v[j]]<=m){
                    d2[i][j]=d[v[i]][v[j]];
                }
            }
        }
        for(int k=0;k<l+2;k++){
            for(int i=0;i<l+2;i++){
                for(int j=0;j<l+2;j++){
                    d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j]);
                }
            }
        }
        int ans=d2[l][l+1];
        if(ans==INF){
            cout<<"Help!"<<endl;
        }else{
            ans+=max(0,d2[l][l+1]-m);
            cout<<ans<<endl;
        }
    }
}


Measured memory_bytes: 3148
package main

import (
	"fmt"
	)

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	mx := max(max(a - b, a + b), a * b)
	fmt.Println(mx)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, ni;
    vector<int> sim;
    vector<int> sequence;
    cin >> n;
    for(int i  = 0; i < n; ++i)
    {
        cin >> ni;
        sim.push_back(ni);
    }
    
    if(n%2 == 0)
    {
        for(int i = n; i > 0; i -= 2) sequence.push_back(i-1);
        for(int i = 1; i < n; i += 2) sequence.push_back(i-1);
    }
    else
    {
        for(int i = n; i > 0; i -= 2) sequence.push_back(i-1);
        for(int i = 2; i < n; i += 2) sequence.push_back(i-1);         
    }




    // for(int i = 0; i < sequence.size(); ++i) cout << sequence[i] << " ";
    // cout << endl;


    for(int i  = 0; i < n-1; ++i)
    {
       cout << sim[sequence[i]] << " ";
    }
       cout << sim [sequence[n-1]] << endl;

    return 0;
}

Measured memory_bytes: 3828