akhauriyash/Code-Regression huggingface dataset:
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{ 
   static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter pw = new PrintWriter(System.out);
    static StringTokenizer st;
    
    static String next()
        {
            while(st==null || !st.hasMoreElements()) 
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch(IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
   static int gcd(int a,int b)
     {
       if(b==0)
        return a;
       else
        return gcd(b,a%b);
     }
  public static void main (String[] args) throws java.lang.Exception
   {
	try{
	   
		  int k=Integer.parseInt(next());
		  String s=next();
		  String td="...";
		  int len=s.length();
		  if(k>=len)
		    System.out.println(s);
		 else
		   System.out.println(s.substring(0,k)+td);
		 
	   }     
	catch(Exception e)
		 {}
	}
}


Measured memory_bytes: 37344
N = int(input())
T = list(map(int, input().split()))
M = int(input())

ans = []
for _ in range(M):
    p, x = map(int, input().split())
    a = 0
    for i in range(N):
        if i + 1 == p:
            a += x
        else:
            a += T[i]

    ans.append(a)

for a in ans:
    print(a)


Measured memory_bytes: 3060
def to_b(num):
    ans = "";
    while (num > 0):
        if (num % 2 == 0):
            ans += '0';
        else:
            ans += '1';
        num //= 2;
    return ans[::-1];


def check(s, t):
    for i in range(len(s)):
        if (s[len(s) - i - 1] == t[i] and t[i] == '1'):
            return False;
    return True;


n = int(input());

v = list(map(int, input().split()))
a = [""] * n;
for i in range(n):
    num = v[i];
    a[i] = to_b(num);

tmp = ['0'] * 100
l = 0;
r = 0;
ans = 0;
while (r < n):
    if (check(a[r], tmp)):
        #print(a[r])
        #print(tmp)
        for i in range(len(a[r])):
            if (a[r][len(a[r]) - i - 1] == '1'):
                tmp[i] = '1';
        r += 1;
        ans += r - l;
        #print("!!!!", l, r)
    else:
        for i in range(len(a[l])):
            if (a[l][len(a[l]) - i - 1] == '1'):
                tmp[i] = '0';
        l += 1;
print(ans);
        


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
string S,T;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	T="z";
	FORR(c,S) if(c!=T.back()) T.push_back(c);
	cout<<T.size()-1<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 592
import java.io.*;

import java.util.*;
import java.math.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.math.BigInteger.*;
import static java.lang.Character.*;

class AOJ1020 {
	int[] di = { +1, -1, +3, -3 };

	public void run() {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				return;
			int s = sc.next().charAt(0) - 'A';
			int t = sc.next().charAt(0) - 'A';
			int b = sc.next().charAt(0) - 'A';

			double[] prob = new double[9];
			double[][] move = new double[9][9];
			for (int i = 0; i < 9; i++)
				for (int d = 0; d < 4; d++) {
					int j = (!isValidMove(i, d) || i + di[d] == b) ? i : i + di[d];
					move[j][i] += .25;
				}

			prob[s] = 1.;
			for (int k = 0; k < n; k++) {
				double[] np = new double[9];
				for (int i = 0; i < 9; i++)
					for (int j = 0; j < 9; j++)
						np[i] += move[i][j] * prob[j];
				prob = np;
			}
			System.out.println(prob[t]);
		}
	}

	boolean isValidMove(int i, int d) {
		switch (d) {
		case 0:
			return i % 3 < 2;
		case 1:
			return i % 3 > 0;
		case 2:
			return i < 6;
		case 3:
			return i > 2;
		}
		return false;
	}
}

public class Main {
	public static void main(String... args) {
		new AOJ1020().run();
	}

	public static void debug(Object... os) {
		System.err.println(java.util.Arrays.deepToString(os));
	}
}

class Scanner {
	final java.util.Scanner sc;

	public double nextDouble() {
		return Double.parseDouble(sc.next());
	}

	public Scanner(java.io.InputStream is) {
		this.sc = new java.util.Scanner(is);
	}

	public boolean hasNext() {
		return sc.hasNext();
	}

	public String next() {
		return sc.next();
	}

	public int nextInt() {
		return Integer.parseInt(sc.next());
	}

	public String nextLine() {
		return sc.nextLine();
	}

	public long nextLong() {
		return Long.parseLong(sc.next());
	}
}

Measured memory_bytes: 12000
# -*- coding: utf-8 -*-
# problem B
player = {i:list(input()) for i in 'abc'}

t = 'a'
while True:
    if len(player[t]) == 0:
        break
    else:
        x = player[t][0]
        player[t].pop(0)
        t = x

print(t.upper())

Measured memory_bytes: 3068
from bisect import bisect_right
from itertools import accumulate

n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))

cnt = [0] * n
for i in range(n):
    cnt[i] = n - bisect_right(c, b[i])

cnt = [0] + list(accumulate(cnt[::-1]))
cnt.reverse()

ans = 0
for i in range(n):
    ans += cnt[bisect_right(b, a[i])]

print(ans)

Measured memory_bytes: 31640
#include <stdio.h>
 
int main(void){
	
	char a[4],b[4];
	
	scanf("%s\n%s",a,b);
	
	if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]){
	printf("YES\n");
	} else {
	printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
/* 

И пусть меня погубит, то к чему я
Бегу, не жалея ног.
И если мне суждено сгореть на восходе,
Я буду идти вперёд.

*/

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()

using namespace std;

const bool dbg_flg = 0;
#define debug(x) if (dbg_flg) cerr << #x << ' ' << x << '\n'
#define debug_pair(x) if (dbg_flg) cerr << #x << ' ' << x.F << ' ' << x.S << '\n' 

const int inf = 1e9 + 7;
const int MAXN = 2e5 + 5;

int n;
string s[MAXN];
unordered_map<string, int> ct;

void solve() {
	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> s[i];
	}

	for (int i = 1; i <= n; i++) {
		ct[s[i]]++;		
	}

	set<string> res;

	int mx = 0;

	for (int i = 1; i <= n; i++) {
		mx = max(mx, ct[s[i]]);				
	}

	for (int i = 1; i <= n; i++) {
		if (ct[s[i]] == mx) {
			res.insert(s[i]);		
		}
	}

	for (auto i : res) {
		cout << i << '\n';
	}

}

int main() {
	
	//~ freopen(".in", "r", stdin);
	//~ freopen(".out", "w", stdout);
	
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
	}

	return 0;
}

Measured memory_bytes: 33736
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	if a == b {
		fmt.Println("a", "==", "b")

	} else if a > b {
		fmt.Println("a", ">", "b")
	} else {
		fmt.Println("a", "<", "b")
	}
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}



Measured memory_bytes: 1088
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int a, b;
    cin >> a >> b;
    int ans = a;
    if(b < a) ans--;
    output(ans);
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if((i+j)%2 == 0) printf("#");
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2600
#include<iostream>
using namespace std;
#define maxn 100005
typedef long long LL;
int n,k;
LL t[maxn];
int check(LL p)
{
    int i=0;
    for(int j=0;j<k;++j)
    {
        LL s=0;
        while(s+t[i]<=p)
        {
            s+=t[i++];
            if(i==n) return n;
        }
    }
    return i;
}
int solve()
{
    LL left=0;
    LL right=100000*10000;
    LL mid;
    while(right-left>1)
    {
        mid=(left+right)>>1;
        int v=check(mid);
        if(v>=n) right=mid;
        else left=mid;
    }
    return right;
}
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;++i)
        cin>>t[i];
    LL ans=solve();
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3892
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
         Scanner sc = new Scanner(System.in);
//        Reader sc = new Reader();
        int N = sc.nextInt();
        int W = sc.nextInt();
        int[] ws = new int[N+1];
        int[] vs = new int[N+1];
        PrintWriter pw = new PrintWriter(System.out);

        for(int i=1; i<=N; ++i) {
            ws[i] = sc.nextInt();
            vs[i] = sc.nextInt();
        }

        long r = Knapsack2(N, W, ws, vs);

        pw.println(r);
        pw.close();
    }

    public static long Knapsack2(int N, int W, int[] ws, int[] vs) {
        int V = IntStream.of(vs).sum();
        long[][] dp = new long[N+1][V+1];

        for(int n=0; n<=N; ++n) {
            for(int v=0; v<=V; ++v) {
                dp[n][v] = Integer.MAX_VALUE - V;
            }
        }

        long value = 0;
        dp[0][0] = 0;
        for(int i=1; i<=N; ++i) {
            for(int v=0; v<=V; ++v) {
                dp[i][v] = Math.min(dp[i-1][v], dp[i][v]);
                if(v-vs[i]>=0)
                    dp[i][v] = Math.min(dp[i][v], dp[i-1][v-vs[i]] + ws[i]);
                if(dp[i][v] <= W) {
                    value = Math.max(value, v);
                }
            }
        }

//        d0(dp);

        return value;
    }

    public static void d0(int[][] dp) {
        System.out.print("    ");

        for(int j=0; j<dp[0].length; ++j){
            System.out.printf("%3d ", j);
        }
        System.out.println();

        for(int i=0; i<dp.length; ++i){
            System.out.printf("%3d|", i);
            for(int j=0; j<dp[0].length; ++j){
                System.out.printf("%3d ", dp[i][j]);
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 128328
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

const double PI = 2 * acos(0);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<double, double> pdd;
typedef pair<double, pdd> pddd;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

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

int main() {
    int n, w;
    scanf("%d%d", &n, &w);
    int r = 0;
    int large = 0;
    while(n--) {
        int t;
        scanf("%d", &t);
        large = max(large, t);
        r = gcd(r, t);
    }
    if(large >= w && w%r==0) printf("POSSIBLE\n");
    else printf("IMPOSSIBLE\n");
}


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

int main(){
  string s, ans;
  cin>>s;

  int i;
  for(i=0; i<s.length(); i++){
    if(s[i]=='B'){
            if(ans.length()==0)
                continue;
        else
            ans.erase(ans.length()-1);
    }
    else
        ans += s[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    long long int a, t, r;
    scanf("%lld %lld", &a, &t);
    if(a>t)
    {
        r = a-t;
        printf("%lld", r);
    }
    else
    {
        r = 0;
        printf("%lld", r);
    }
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 1e9
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

const int MAX = 100005;
struct edge {int to; ll cost;};
vector<edge> g[MAX];
ll ans[MAX];

void dfs(int v, int p, ll d) {
    ans[v] = d;
    for (auto &e : g[v]) {
        if (e.to == p) continue;
        dfs(e.to, v, d + e.cost);
    }
}
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    int n;
    cin >> n;
    rep(i, 0, n-1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        g[a].pb({b, c});
        g[b].pb({a, c});
    }
    int q, k;
    cin >> q >> k;
    k--;
    dfs(k, -1, 0);
    rep(i, 0, q) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        cout << ans[x] + ans[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 14336
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        x:usize,
    }
    let mut n = 1;
    while (n * (n + 1)) / 2 < x {
        n += 1;
    }
    println!("{}", n);
}

Measured memory_bytes: 4352
import java.util.*;
 
public class Main{
  static int gcd (int a, int b) {return b>0 ? gcd(b, a%b) : a;}
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    long ans = 0;
    for(int a = 1 ; a <= k ; a++){
      for(int b = 1; b <= k ; b++){
        for(int c = 1; c <= k; c++){
          ans += gcd(gcd(a,b),c);
        }
      }
    }
    System.out.println(ans);
  }
}

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

int main(){
    int n=0;

    cin >> n;

    int i[n];

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

    int homuzu;

    for(int x=0; x<n/2; x++){
        homuzu =  i[x];
        i[x] = i[n-(x+1)];
        i[n-(x+1)] = homuzu;
    }

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

    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
using namespace std;
int dist[10][10];
int fr[10];
int H,W;
int main()
{
    cin>>H>>W;
    for(int i=0;i<=9;i++)
    {
        for(int j=0;j<=9;j++)
        {
            cin>>dist[i][j];
        }
    }
    for(int k=0;k<=9;k++)
        for(int i=0;i<=9;i++)
            if(i!=k)
                for(int j=0;j<=9;j++)
                    if(i!=j&&j!=k)
                        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
    for(int i=1;i<=H;i++)
    {
        for(int j=1;j<=W;j++)
        {
            int val;
            cin>>val;
            if(val!=-1)fr[val]++;
        }
    }
    int rez=1<<30;
    for(int cf=1;cf<=1;cf++)
    {
        int tmp=0;
        for(int i=0;i<=9;i++)
            tmp+=dist[i][cf]*fr[i];
        rez=min(rez,tmp);
    }
    cout<<rez;
    return 0;
}


Measured memory_bytes: 256
n,m,k=map(int,input().split())
x='No'
for i in range(m+1):
  t=n*i
  if t==k:
    x='Yes'
    break
  for j in range(n):
    t+=m-2*i
    if t==k:
      x='Yes'
      break
print(x)

Measured memory_bytes: 2940
n,k,c=map(int,input().split())
s=input()
l=[0]*k
r=[0]*k
ld=0
rd=n-1
for i in range(k):
  j=k-1-i
  while s[ld]=='x':
    ld+=1
  while s[rd]=='x':
    rd-=1
  l[i]=ld
  ld+=1+c
  r[j]=rd
  rd-=1+c
for i in range(k):
  if l[i]==r[i]:
    print(l[i]+1)


Measured memory_bytes: 20628
#include <stdio.h>
#include <string.h>
int hit(int base[3]){
	int point = 0;
	if(base[2]){
		point = 1;
	}
	base[2] = base[1];
	base[1] = base[0];
	base[0] = 1;
	return point;
}
int main(void){
	char event[8];
	int n,i;
	int base[3];
	int point;
	int outCount;
	scanf("%d",&n);
	for(i = 0; i < n; i++){
		point = 0;
		outCount = 0;
		base[0] = 0;
		base[1] = 0;
		base[2] = 0;
		while(1){
			scanf("%s",event);
			if(!strcmp(event,"HIT")){
				if(hit(base)){
					point++;
				}
			}else if(!strcmp(event,"HOMERUN")){
				point += (base[0] + base[1] + base[2] + 1);
				base[0] = 0;
				base[1] = 0;
				base[2] = 0;
			}else if(!strcmp(event,"OUT")){
				outCount++;
				if(outCount >= 3){
					break;
				}
			}
		}
		printf("%d\n",point);
	}
	return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    int nt; cin >> nt;
    for (int tc = 0; tc < nt; ++tc) {
        int n, d; cin >> n >> d;
        cout << (n % 2 == 0 ? d ^ 127 : d) + (n - 1) * 127 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
using namespace std;
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<(a+1-b)*(a+1-c)<<endl;
	return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
constexpr int B = -2;

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

    std::cin >> N;

    if(N == 0){
        std::cout << "0" << std::endl;
    }

    std::vector<int> v;
        
    while(N != 0){
        int rem = N % B;
        N /= B;

        if(rem < 0){
            rem += -B;
            N += 1;
        }

        v.emplace_back(rem);
    }

    std::reverse(v.begin(), v.end());

    for(int r : v){
        std::cout << r;
    }
    std::cout << std::endl;
}


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

using namespace std;
using pii = pair<int, int>;

int main(int argc, char const *argv[]) {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  vector<vector<pii>> tbl(h, vector<pii>(w));

  for (int i = 0; i < h; i++) {
    int last = -1;
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        last = j;
      } else if (j == w - 1 || s[i][j + 1] == '#') {
        for (int jj = j; jj > last; jj--) {
          tbl[i][jj].first = j - last;
        }
      }
    }
  }

  for (int j = 0; j < w; j++) {
    int last = -1;
    for (int i = 0; i < h; i++) {
      if (s[i][j] == '#') {
        last = i;
      } else if (i == h - 1 || s[i + 1][j] == '#') {
        for (int ii = i; ii > last; ii--) {
          tbl[ii][j].second = i - last;
        }
      }
    }
  }
  int ret = 0;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ret = max(ret, tbl[i][j].first + tbl[i][j].second - 1);
    }
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 35712
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;




int main(){
    ll n;
    cin>>n;
    if(n==0){
        cout<<0<<endl;
        return 0;
    }
    if(n>0){
        vector<ll> a;
        a.push_back(n%2);
        n/=2;
        while(n>0){
            a.push_back(n%4);
            n/=4;
        }
        string s;
        s.push_back(a[0]+'0');
        a.push_back(0);
        a.push_back(0);
        for(int i=1;i<a.size();i++){
            if(a[i]==4){
                a[i+1]+=1;
                s.push_back('0');
                s.push_back('0');
            }
            if(a[i]==3){
                s.push_back('1');
                s.push_back('0');
                a[i+1]+=1;
            }
            if(a[i]==2){
                s.push_back('0');
                s.push_back('1');
            }
            if(a[i]==1){
                s.push_back('1');
                s.push_back('1');
            }
            if(a[i]==0){
                s.push_back('0');
                s.push_back('0');
            }
        }
        while(s[s.size()-1]=='0'){
            s.pop_back();
        }
        reverse(s.begin(),s.end());
        cout<<s<<endl;
        return 0;
    }
    else{
        n*=-1;
        vector<ll> a;
        while(n>0){
            a.push_back(n%4);
            n/=4;
        }
        string s;
        a.push_back(0);
        a.push_back(0);
        for(int i=0;i<a.size();i++){
            if(a[i]==4){
                a[i+1]+=1;
                s.push_back('0');
                s.push_back('0');
            }
            if(a[i]==3){
                s.push_back('1');
                s.push_back('0');
                a[i+1]+=1;
            }
            if(a[i]==2){
                s.push_back('0');
                s.push_back('1');
            }
            if(a[i]==1){
                s.push_back('1');
                s.push_back('1');
            }
            if(a[i]==0){
                s.push_back('0');
                s.push_back('0');
            }
        }
        while(s[s.size()-1]=='0'){
            s.pop_back();
        }
        reverse(s.begin(),s.end());
        cout<<s<<endl;
        return 0;
    }
    
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import heapq
T = int(input())
for _ in range(T):
    N = int(input())
    KLR = [tuple(map(int,input().split())) for i in range(N)]
    ans = 0
    LK = [[] for _ in range(N+1)]
    RK = [[] for _ in range(N+1)]
    for k,l,r in KLR:
        ans += min(l,r)
        if l >= r:
            LK[k].append(l-r)
        else:
            RK[k].append(r-l)
    lq = []
    for i in range(1,N+1):
        for v in LK[i]:
            heapq.heappush(lq, v)
        while len(lq) > i:
            heapq.heappop(lq)
    ans += sum(lq)
    rq = []
    for i in range(N,0,-1):
        for v in RK[i]:
            heapq.heappush(rq, v)
        while len(rq) >= N+1-i:
            heapq.heappop(rq)
    ans += sum(rq)
    print(ans)

Measured memory_bytes: 78540
N=int(input())
L=list(map(int,input().split()))
L.sort()
c=0
for i in range(N-2):
  k=i+2
  for j in range(i+1,N-1):
    s=L[i]+L[j]
    c=c+k-j-1
    while L[k]<s and k<=N-2:
      k=k+1
      c=c+1
    if k==j+1 and s<=L[k]:
      k=k+1
    if k==N-1 and L[k]<s:
      c=c+1
print(c)

Measured memory_bytes: 43740
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;

#define MOD 998244353

int main(){
    ll count=0,count2=0;
    string s;
    cin >> s;
    if (s[0]!='A'){
        cout << "WA" << endl;
        return 0;
    }
    for (ll i=1;i<s.size();i++){
        if (isupper(s[i]))count++;
        if (s[i]=='C' && i<s.size()-1 && i>1){
            count2++;
        }
    }
    if (count==1 && count2==1){
        cout << "AC" << endl;
        return 0;
    }
    cout << "WA" << endl;
    return 0;
}




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

int main(){
  int n,y,v=0,i,j;
  cin >> n >> y;
  for(i=0;i<n+1;i++){
    for(j=0;j<n-i+1;j++){
      if(i*10+j*5+(n-i-j)*1==y/1000){
        v++;
        break;
      }
    }
    if(v==1){
      break;
    }
  }
  if(v==1){
    cout << i << " " << j << " " << n-i-j << endl;
  }else{
    cout << "-1 -1 -1" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
	int n;
	int a[10005];

	cin >> n;

	int N = 0;

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

		int x = a[i];

		if (x != 0)
		{
			while (1)
			{
				if ((x & 1) == 0)
				{
					N++;

					x >>= 1;
				}
				else
				{
					break;
				}
			}
		}
	}

	cout << N << endl;

	return 0;
}


Measured memory_bytes: 256
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
c3 = list(map(int, input().split()))

c = c1 + c2 + c3

if sum(c) % 3 == 0 and c[0] + c[4] + c[8] == c[1] + c[3] + c[8]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll frac[200100];
ll fracinv[200100];

void gen_frac(){
  frac[0]=1;
  fracinv[0]=modinv(frac[0], MOD);
  rep(i, 200010){
    frac[i+1]=mod(frac[i]*(i+1), MOD);
    fracinv[i+1]=modinv(frac[i+1], MOD);
  }
}

ll comb(ll n,ll k){
  ll tmp = frac[n];
  tmp = mod(tmp * fracinv[k], MOD);
  tmp = mod(tmp * fracinv[n - k], MOD);
  return tmp;
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, K;
  cin >> N >> K;
  K = min(N, K);
  gen_frac();

  ll ans = 0;
  for(int i=N-K;i<=N;i++){
    ans = mod(ans + comb(N-1, i-1)*comb(N, i), MOD);
  }  
  cout << ans;
  
  
  return 0;
}


Measured memory_bytes: 3328
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val xs = readLine()!!.split(' ').map { it.toInt() }

    val f = { i: Int -> xs.filter { it % i == 0 }.count() >= n - 1 }

    val ans = xs.take(2).map { a ->
        generateSequence(1) { it + 1 }
                .takeWhile { it * it <= a }
                .filter { a % it == 0 }
                .map {
                    var r = 0
                    if (f(it)) r = Math.max(r, it)
                    if (f(a / it)) r = Math.max(r, a / it)
                    r
                }.max()?: 0
    }.max()

    println(ans)
}


Measured memory_bytes: 116844
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

int main(void)
{
    int n, m, x;

    scanf("%d %d", &n, &m);
    while(m --)
    {
        scanf("%d", &x);
        n -= x;
    }
    printf("%d\n", max(n, -1));

    return 0;
}


Measured memory_bytes: 3760
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	int n;
	cin>>n;
	int odd = n-n/2;
	float ans = 1.0*odd / n;
	cout<<setprecision(10)<<ans;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define f first
#define s second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define fast 
#define f first
#define s second
#define endl "\n"
#define pie 3.1415926535
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    int n;
    cin >>n;
    string s;
    cin >> s;
  
    long long sum = 0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            if(s[i]==s[j])
                continue;
            for(int k=j+1;k<n;k++){
                if((j-i)==(k-j) || s[j] == s[k] || s[i] == s[k])
                        continue;
                else 
                    sum++;
            }
        }
    }
    cout << sum<<endl;
    return 0;
    
}






Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003, M = N << 2;

int n, k, l;
int tot, head[N], headc[N], ver[M], nxt[M];
int in1[N], cnt1, in2[N], cnt2;
bool vis1[N], vis2[N];
map <PII, int> p;

inline void add(int h[], int u, int v)
{
	ver[++tot] = v, nxt[tot] = h[u], h[u] = tot;
}

void dfs1(int u, int id)
{
	in1[u] = id;
	vis1[u] = true;
	for (int i = head[u]; i; i = nxt[i])
	{
		int v = ver[i];
		if (!vis1[v]) dfs1(v, id);
	}
}

void dfs2(int u, int id)
{
	in2[u] = id;
	vis2[u] = true;
	for (int i = headc[u]; i; i = nxt[i])
	{
		int v = ver[i];
		if (!vis2[v]) dfs2(v, id);
	}
}

int main()
{
	//File("");
	n = gi <int> (), k = gi <int> (), l = gi <int> ();
	for (int i = 1; i <= k; i+=1)
	{
		int u = gi <int> (), v = gi <int> ();
		add(head, u, v), add(head, v, u);
	}
	for (int i = 1; i <= l; i+=1)
	{
		int u = gi <int> (), v = gi <int> ();
		add(headc, u, v), add(headc, v, u);
	}
	for (int i = 1; i <= n; i+=1)
		if (!vis1[i]) dfs1(i, ++cnt1);
	for (int i = 1; i <= n; i+=1)
		if (!vis2[i]) dfs2(i, ++cnt2);
	for (int i = 1; i <= n; i+=1) ++p[make_pair(in1[i], in2[i])];
	for (int i = 1; i <= n; i+=1)
		printf("%d ", p[make_pair(in1[i], in2[i])]);
	return 0;
}


Measured memory_bytes: 20508
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s1 = scan.next();
		String s2 = scan.next();
		String s3 = scan.next();
		
		String ans = s1.substring(0,1) + s2.substring(0,1)+ s3.substring(0,1);
		System.out.println(ans);
		
	}

}


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

int main(){
  int a,b;
  cin >> a >> b;
  if ( a >= 10 ) cout << b << endl;
  else cout << b+100*(10-a) <<endl;
 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int cnt = 0;
    rep(i, n) {
        int a;
        cin >> a;
        while (a % 2 == 0) { a /= 2; cnt++; }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    int n, m; cin>>n>>m;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    vector<vector<int>> G(n);
    for(int i=0; i<m; i++){
        int u, v; cin>>u>>v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    int sz = n - m;
    int need_edge = sz - 1;
    int need_node = 2 * need_edge;

    if(n < need_node){
        cout << "Impossible" << endl;
        return 0;
    }

    if(m == n - 1){
        cout << 0 << endl;
        return 0;
    }

    vector<bool> visited(n, false);
    vector<int> all_score;
    ll ans = 0;
    for(int i=0; i<n; i++){
        if(!visited[i]){
            vector<int> score;
            score.emplace_back(a[i]);
            visited[i] = true;
            queue<int> que;
            que.emplace(i);

            while(que.size()){
                int cv = que.front(); que.pop();
                for(auto nv : G[cv]){
                    if(!visited[nv]){
                        score.emplace_back(a[nv]);
                        visited[nv] = true;
                        que.emplace(nv);
                    }
                }
            }

            sort(score.begin(), score.end());
            for(int j=0; j<score.size(); j++){
                if(j == 0) ans += score[j], need_node--;
                else all_score.emplace_back(score[j]);
            }
        }
    }

    sort(all_score.begin(), all_score.end());
    for(int i=0; i<need_node; i++) ans += all_score[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7292
def main():
    n = int(input())
    xy = [list(map(int, input().split())) for _ in [0]*n]
    from scipy.optimize import fmin

    def calc(k):
        i, j = k
        ans = 0
        for x, y in xy:
            ans = max(ans, (x-i)**2+(y-j)**2)
        return ans

    x, y = fmin(calc, [500, 500], disp=0)
    print(calc((x, y))**0.5)


main()


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

ll mod(ll x) {
    x %= MOD;
    if (x < 0) { x += MOD; }
    return x;
}

ll mpow(ll x, ll p) {
    if (p == 0) { return 1; }
    if (p % 2 == 1) { return mod(x * mpow(x, p - 1)); }
    ll sub = mpow(x, p / 2);
    return mod(sub * sub);
}

ll mcombination(const vll& fac, const vll& inv, ll n, ll r) {
    if (r == 0 || r == n) { return 1; }
    return mod(mod(fac[n] * inv[n - r]) * inv[r]);
}

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

    ll n, k;
    cin >> n >> k;

    vll fac(n + 1), inv(n + 1);

    fac[0] = 1;
    rep(i, 1, n + 1) { fac[i] = mod(i * fac[i - 1]); }

    inv[n] = mpow(fac[n], MOD - 2);
    rrep(i, 0, n) { inv[i] = mod((i + 1) * inv[i + 1]); }

    ll r = n - k;
    rep(i, 1, k + 1) {
        if (r + 1 < i) {
            cout << 0 << endl;
            continue;
        }
        ll t1 = mcombination(fac, inv, r + 1, i);
        ll t2 = mcombination(fac, inv, k - 1, i - 1);
        cout << mod(t1 * t2) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
X,Y = map(int, input().split())
answer = []
for i in range(X):
    i += 1
    answer.append(i * 4 + (X - i) * 2)
    answer.append(i * 2 + (X - i) * 4)
if Y in answer:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9168
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N, X, T = NMI()
    print(math.ceil(N/X)*T)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9312
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
    ll ans=1;
    for(int i=1; i<=n; i++)
        ans*=a;
    return ans;
}

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

    ll n,f=0;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>A[i]>>B[i];
    }
    for(int i=1; i<=n-2; i++)
    {
        if(A[i]==B[i]&&A[i+1]==B[i+1]&&A[i+2]==B[i+2])
        {
            f=1;
        }
    }
    if(f)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>
#include <ios>
#include <iomanip>
#include <functional>
#include <queue>

#define int long long

int inf = (1LL <<  62);
using namespace std;

signed main(){
    int n,t;
    cin >> n >> t;
    int ans = n * t;
    vector<int> v;
    int sum = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        v.push_back(x);
        if(x == 0){
            continue;
        }
        if(x < v[i - 1] + t){
            sum += t - (x - v[i - 1]);
        }
    }
    cout << ans - sum;
}


Measured memory_bytes: 2420
//ABC055B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	long long int n, ans = 1;
	cin >> n;
	for(int i=1;i<=n;i++){
		ans *= i;
		ans %= 1000000007;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>
#define oo 987654321
#define INT long long
#define MOD 1000000007
#include <vector>
using namespace std;

INT n, m, vst[200020];
vector<INT> G[200020];
void dfs(int x, int y)
{
    if( y > 2 ) return;
    vst[x] = 1;
    for(int i = 0 ; i < G[x].size() ; i++ )
        if( !vst[G[x][i]] )
            dfs(G[x][i], y+1);
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>m;
    for(int i = 0, a, b ; i < m ; i++ )
    {
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(1, 0);
    cout<<(vst[n]?"POSSIBLE":"IMPOSSIBLE")<<endl;
    return 0;
}


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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int h, w, a, b;

int main() {
  cin >> h >> w >> a >> b;
  // a * x + (w - a) * (h - x) == b * y + (h - b) * (w - y)
  // x * (2 * a - w) + (w - a) * h == y * (2 * b - h) + (h - b) * w
  int x = -1, y = -1;
  range(i, 0, h) {
    range(j, 0, w) {
      if(a * i + (w - a) * (h - i) == b * j + (h - b) * (w - j)) {
        x = i;
        y = j;
        goto A;
      }
    }
  }
  A:;
  if(2 * a == w && 2 * b == h) {
    x = b; y = a;
  }
  if(x == -1) {
    cout << -1;
    return 0;
  }
  vector<vector<int>> grid(h, vector<int>(w));
  vector<int> cnt(w);
  range(i, 0, y) cnt[i] = -b;
  range(i, y, w) cnt[i] = -(h - b);
  range(i, 0, x) {
    vector<int> id(w);
    iota(id.begin(), id.end(), 0);
    sort(id.begin(), id.end(), [&](int u, int v){return cnt[u] < cnt[v];});
    range(j, 0, a) {
      grid[i][id[j]] = 1;
      cnt[id[j]]++;
    }
  }
  range(i, x, h) {
    vector<int> id(w);
    iota(id.begin(), id.end(), 0);
    sort(id.begin(), id.end(), [&](int u, int v){return cnt[u] < cnt[v];});
    range(j, 0, w - a) {
      grid[i][id[j]] = 1;
      cnt[id[j]]++;
    }
  }
  range(i, 0, h) {
    range(j, 0, w) cout << grid[i][j];
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 5120
# N, K = 5, 3
# ARR = [50, 100, 80, 120, 80]
#
#
# N,K = 1, 1
# ARR = [1000]

N,K = map(int,input().split())
ARR = list(map(int,input().split()))
arr = sorted(ARR)


result = 0
for i in range(K):
    result += arr[i]

print(result)

Measured memory_bytes: 9216