akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

char tb[55][55];

int main() {

	int h, w; cin >> h >> w;

	for (int i = 0; i < h; i++) {
		string buf; cin >> buf;

		for (int j = 0; j < buf.size(); j++) {
			tb[i+1][j+1] = buf[j];
		}
	}

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

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			
			if (tb[i + 1][j + 1] == '#'){

				bool ok = false;

				for (int d = 0; d < 4; d++) {
					if (tb[i + 1 + dy[d]][j + 1 + dx[d]] == '#') {
						ok = true;
					}
				}


				if (!ok) {
					cout << "No" << endl;
					return 0;
				}
			}

			
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
     
    int a,b,i;
    char op;
    for(i=1;i>0;i++){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='+')
        {printf("%d\n",a+b);
        }
        else if(op=='-')
        {printf("%d\n",a-b);
        }
        else if(op=='*')
        {printf("%d\n",a*b);
        }
        else if(op=='/'){
            printf("%d\n",a/b);
        }else if(op=='?') {
            break;
        }
    }
    return 0;
}


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

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

    int x[N], y[N], c[N];
    //2K * 2Kの範囲に絞る
    for(int i = 0; i < N; ++i) {
        char sc;
        cin >> x[i] >> y[i] >> sc;
        x[i] %= K*2;
        y[i] %= K*2;
        c[i] = (sc == 'W');
    }

    int white[K][K];
    fill(white[0], white[K], 0);
    // white[x][y] = マス(x, y)を右上とした長方形に
    //                含まれている(白マス-黒マス)の総数

    int bnum = 0;
    // 黒マスを指定する条件の数

    // K * Kの範囲に絞る
    // 座標をKで割った値の偶奇で色が変わる
    for(int i = 0; i < N; ++i) {
        c[i] += x[i]/K + y[i]/K;
        c[i] %= 2;
        x[i] %= K;
        y[i] %= K;
        white[x[i]][y[i]] += (c[i] ? 1 : -1);
        if(c[i] == 0) ++bnum;
    }

    //2次元imosの要領で展開
    for(int x = 0; x < K; ++x) {
        for(int y = 1; y < K; ++y) {
            white[x][y] += white[x][y-1];
        }
    }

    for(int x = 1; x < K; ++x) {
        for(int y = 0; y < K; ++y) {
            white[x][y] += white[x-1][y];
        }
    }

    int ans = 0;
    for(int x = 0; x < K; ++x) {
        for(int y = 0; y < K; ++y) {
            // (x, y)を右上の頂点とした長方形を白く塗るパターン
            int w = white[K-1][K-1]
                    - white[x][K-1]
                    - white[K-1][y]
                    + 2*white[x][y]
                    + bnum;
            
            ans = max(ans, max(w, N-w));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 5376
#include<iostream>
#include<string>

using namespace std;

#define A 0
#define X 1
#define Y 2
#define Z 3
#define W 4
#define B 5

bool solve(int, int);

int map[10][2];
string s;

int main()
{

  for(int i = 0; i < 10; i++)
    map[i][0] = map[i][1] = -1;

  map[A][0] = X;
  map[A][1] = Y;
  map[X][1] = Z;
  map[Y][0] = X;
  map[Z][0] = W;
  map[Z][1] = B;
  map[W][0] = B;
  map[W][1] = Y;
  map[B][0] = Y;
  map[B][1] = X;
  while(1)
  {
    cin >> s;
    if(s[0] == '#')
      break;

    if(solve(0, A))
      cout << "Yes\n";
    else
      cout << "No\n";
  }
}

bool solve(int n, int city)
{
  if(city == -1)
    return false;
  if(n == s.length())
    return city == B;

  return solve(n + 1, map[city][s[n] - '0']);
}

Measured memory_bytes: 1160
using System;

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine();
            var DP = new long[N.Length + 1, 2];
            DP[N.Length, 1] = 10;
            for (int i = N.Length - 1; i >= 0; i--)
            {
                var d = int.Parse(N[i].ToString());
                DP[i, 0] = Math.Min(DP[i + 1, 0] + d, DP[i + 1, 1] + d + 1);
                DP[i, 1] = Math.Min(DP[i + 1, 0] + (10 - d), DP[i + 1, 1] + (10 - (d + 1)));
            }
            Console.WriteLine(Math.Min(DP[0, 0], DP[0, 1] + 1));
        }
    }
}


Measured memory_bytes: 32496
N, A, B = map(int, input().split())
nums = []
for i in range(1,N+1):
    I = str(i)
    s = 0
    for j in range(len(I)):
        s += int(I[j])
    if s >= A and s <= B:
        nums.append(i)
print(sum(nums))

Measured memory_bytes: 3292
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	double x[4],y[4];
	while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",x,y,x+1,y+1,x+2,y+2,x+3,y+3)){
		x[0]=max(x[0],x[2]);
		y[0]=max(y[0],y[2]);
		x[1]=min(x[1],x[3]);
		y[1]=min(y[1],y[3]);
		puts(x[0]>x[1] || y[0]>y[1]?"NO":"YES");
	}
	return 0;
}

Measured memory_bytes: 1196
a,b,c,d=map(int,input().split())
ans=0

for i in range(100):
  Alice=0
  Bob=0
  if(a<=i and i<b):
    Alice=1
  if(c<=i and i<d):
    Bob=1
  if(Alice==1 and Bob==1):
    ans+=1
    
print(ans)

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

int main() {
	int sx,sy,tx,ty;
	string r="";
	cin >> sx >> sy >> tx >> ty;

	rep(i,ty-sy)
		r += 'U';
	rep(i,tx-sx)
		r += 'R';
	rep(i,ty-sy)
		r += 'D';
	rep(i,tx-sx+1)
		r += 'L';
	rep(i,ty-sy+1)
		r += 'U';
	rep(i,tx-sx+1)
		r += 'R';
	r += "DR";
	rep(i,ty-sy+1)
		r += 'D';
	rep(i,tx-sx+1)
		r += 'L';
	
	cout << r + 'U' << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int i, j, n, p;
  scanf("%d", &n);
  int a[n], b[n];
  for(i = 1; i <= n; ++i) {
    scanf("%d", &p);
    a[--p] = p * n + i, b[p] = 8 * 1e8 - p * n + i;
  }
  for(i = 0; i < n; ++i) printf("%d ", a[i]);
  printf("\n");
  for(i = 0; i < n; ++i) printf("%d ", b[i]);
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
 int a,i,n;
 long min,max,sum;
 scanf("%d",&n);
 min=1000000;
 max=-1000000;
 sum=0;

 for(i=0;i<n;i++){
 scanf("%d",&a);
 if(min>a)min=a;
 if(max<a)max=a;
 sum=sum+a;
 }

 printf("%d %d %lld\n", min, max, sum);
 return 0;
 }



Measured memory_bytes: 2052
S=input()
T=input()

if S==T:
    ans="Yes"
else:
    ans="No"
    for _ in range(len(S)):
        rotated_S=S[len(S)-1:]+S[:len(S)-1]
        if rotated_S==T:
            ans="Yes"
            break
        else:
            S=rotated_S

print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		int[] h=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		long[] dp=new long[n];
		dp[1]=Math.Abs(h[0]-h[1]);
		for(int i=2;i<n;i++){
			dp[i]=Math.Min(Math.Abs(h[i]-h[i-1])+dp[i-1],Math.Abs(h[i]-h[i-2])+dp[i-2]);
		}
		Console.WriteLine("{0}",dp[n-1]);
	}
}

Measured memory_bytes: 17248
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        s:usize,
    }
    if s <= 2 {
        println!("{}", 0);
        return;
    }
    if s == 3 {
        println!("{}", 1);
        return;
    }
    let mut g = G {
        mem: vec![0; s + 1],
        ans: 0i64,
        s: s as usize,
    };
    g.rec(s as usize);
    println!("{}", g.mem[s]);
}
struct G {
    mem: Vec<i64>,
    ans: i64,
    s: usize,
}
impl G {
    fn rec(&mut self, x: usize) -> i64 {
        if x < 3 {
            return 0;
        }
        if x == 3 {
            self.ans += 1;
            self.ans %= MOD;
            return 1;
        }
        if self.mem[x] > 0 {
            self.ans += self.mem[x];
            self.ans %= MOD;
            return self.mem[x];
        }
        let mut ret = 1i64;
        for i in 3..=x {
            ret += self.rec(x - i);
            ret %= MOD;
        }
        self.mem[x] = ret;
        return ret;
    }
}

const MOD: i64 = 1000000007;
const MX: usize = 1010101;
/// x ^ n % m
pub fn mod_pow(x: i64, n: i64, m: i64) -> i64 {
    let mut res = 1;
    let mut x = x % m;
    let mut n = n;
    while n > 0 {
        if n & 1 == 1 {
            res = (res * x) % m;
        }
        x = (x * x) % m;
        n >>= 1;
    }
    res
}
struct ModComb {
    fact: Vec<i64>,
    fact_inv: Vec<i64>,
    n: usize,
    p: i64,
}
impl ModComb {
    fn initialize(&mut self) {
        let n = self.n;
        self.fact[0] = 1;
        for i in 1..n {
            self.fact[i] = (self.fact[i - 1] * i as i64) % self.p;
        }
        self.fact_inv[n - 1] = mod_pow(self.fact[n - 1], self.p - 2, self.p);
        for i in (0..n - 1).rev() {
            self.fact_inv[i] = (self.fact_inv[i + 1] * (i + 1) as i64) % self.p;
        }
    }
    fn new(max_n: usize, p: i64) -> ModComb {
        let mut ft = ModComb {
            fact: vec![0; max_n + 1],
            fact_inv: vec![0; max_n + 1],
            n: max_n + 1,
            p: p,
        };
        ModComb::initialize(&mut ft);
        ft
    }
    fn fact(&self, n: usize) -> i64 {
        self.fact[n]
    }
    fn comb(&self, n: i64, k: i64) -> i64 {
        if n < k {
            return 0;
        }
        (self.perm(n, k) * self.fact_inv[k as usize]) % self.p
    }
    fn perm(&self, n: i64, k: i64) -> i64 {
        if n < k {
            return 0;
        }
        self.fact[n as usize] * self.fact_inv[(n - k) as usize] % self.p
    }
    fn nsk(&self, n: i64, k: i64) -> i64 {
        if n < k {
            return 0;
        }
        let mut res = 0;
        for i in 0..k + 1 {
            let v = self.comb(k, i) * mod_pow(i, n, self.p) % self.p;
            if (k - i) % 2 == 1 {
                res = (res + self.p - v) % self.p;
            } else {
                res = (res + v) % self.p;
            }
        }
        return res * self.fact_inv[k as usize] % self.p;
    }
}


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

int main(){
   int a,b;
   cin>>a>>b;

 if(a < b) cout<<"a < b"<<endl;
 if(a > b) cout<<"a > b"<<endl;
 if(a == b) cout<<"a == b"<<endl;
   return 0;
}


Measured memory_bytes: 3000
a = [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]
k = int(input())

print(a[k-1])

Measured memory_bytes: 38704
#include <iostream>
using namespace std;
int main() {
	long long n, m, l, i, j, k, sum = 0;
	cin >> n >> m >> l;
    long long a[n][m], b[m][l];
	for (i = 0; i < n; i++) 
		for (j = 0; j < m; j++) 
			cin >> a[i][j];
	for (i = 0; i < m; i++) 
		for (j = 0; j < l; j++) 
			cin >> b[i][j];
	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			for (k = 0; k < m; k++) 
				sum += a[i][k] * b[k][j];
			cout << sum;
			if (j != l - 1) 
                cout << " ";
			sum = 0;
		}
		cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 3228
n = int(input())
a_list = [int(input()) for i in range(n)]

count = 1
now_button = 0
for i in range(1, len(a_list)+1):
    if a_list[now_button] == 2:
        print(count)
        exit()
    else:
        now_button = a_list[now_button]-1
        count += 1

print('-1')

Measured memory_bytes: 7084
#include<bits/stdc++.h>
#define pf printf
#define sf scanf
typedef long long LL;
using namespace std;
int main()
{
    int t,n;

    /*while(t--)
    {

    }*/
    sf("%d %d",&t,&n);
    pf("%d",t*t-n);



    return 0;
}


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

int main() {
    int W, H;
    int x, y, r;
    cin >> W >> H >> x >> y >> r;

    if ( ((x-r)<0) || ((x+r)>W) || ((y-r)<0) || ((y+r)>H) ) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define maxn 105
using namespace std;

bool st[maxn];

int main(){
    int n,k;
    cin>>n>>k;
    int cnt;
    for(int i=1;i<=k;i++)
    {
    	cin>>cnt;
    	for(int j=1;j<=cnt;j++)
    	{
    		int res;
    		cin>>res;
    		st[res] = 1;
		}
	}
	int ans =0;
	for(int i=1;i<=n;i++)
		if(st[i]==0) ans++;
	cout<<ans<<endl;
	return 0;
}

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


int main()
{
  string s, t;
  map<char, int> s_dic, t_dic;
  
  for ( int i='a'; i<'z'+1; i++ ) {
    s_dic[(char)i] = 0;
    t_dic[(char)i] = 0;
  }

  cin >> s;
  cin >> t;
  for ( int i=0; i<s.length(); i++ ) s_dic[s[i]] += 1;
  for ( int i=0; i<t.length(); i++ ) t_dic[t[i]] += 1;

  string ss="", tt="";
  for ( int i='a'; i<'z'+1; i++ ) {
    if ( s_dic[i] == 0 ) continue;
    for ( int j=0; j<s_dic[i]; j++ ) ss += (char)i;
  }
  for ( int i='z'; i>'a'-1; i-- ) {
    if ( t_dic[i] == 0 ) continue;
    for ( int j=0; j<t_dic[i]; j++ ) tt += (char)i;
  }

  if ( ss < tt ) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
# define ll long long
const ll INF=1e18L+5;
int main()
{
    int n,w;
    cin>>n>>w;
   vector<int>value(n),weight(n);
   int sum_index=0;
   for(int i=0;i<n;i++)
   {
       cin>>weight[i]>>value[i];
   }
   for(int x:value)
   {
       sum_index+=x;
   }
   vector<ll>dp(sum_index+1,INF);
   dp[0]=0;
    for(int item=0;item<n;item++){
            for( int value_already=sum_index-value[item];value_already>=0;value_already--)
            {
        dp[value_already+value[item]]=min(dp[value_already+value[item]],dp[value_already]+weight[item]);
            }

    }
    ll answer=0;
    for(int i=0;i<=sum_index;i++)
    {
        if(dp[i]<=w)
            answer=max(answer,(ll)i);
    }
    cout<<answer<<endl;
    return 0;
}



Measured memory_bytes: 1024
def main():
    n = int(input())
    a = list(map(int, input().split()))

    a.sort()
    idx, cnt, s = 0, 0, 0
    while idx < n:
        c = 1
        s += 1
        while idx < n-1 and a[idx] == a[idx+1]:
            idx += 1
            c += 1
        if c % 2 == 0:
            cnt += 1
        idx += 1

    if cnt % 2 == 1:
        print(s-1)
    else:
        print(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14388
s = input()

dp = [False]*(len(s)+1)

dp[0] = True

words = ['dream','dreamer','erase','eraser']
for i in range(len(s)+1):
    if dp[i]:
        for w in words:
            if s[i:i+len(w)]==w:
                dp[i+len(w)] = True
if dp[len(s)]:
    print('YES')
else:
    print('NO')



Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int n; cin >> n;
	vector<long long> a(n);
	vector<long long> b(n);
	vector<long long> c(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    long long ans = 0;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    for(int i = 0; i < n; i++) {
        auto it = upper_bound(c.begin(), c.end(), b[i]);
        long long diffbc;
        if(it == c.end())
            diffbc = 0;
        else
            diffbc = n - (it - c.begin());
        auto it2 = lower_bound(a.begin(), a.end(), b[i]);
        long long diffab;
        if(it2 == a.end())
            diffab = n;
        else
            diffab = it2 - a.begin();
        ans += diffbc * diffab;
        // cout << diffab << " " << diffbc << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2688
// C - Minimization

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int A[100000];

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

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

	int ans;
	if (N <= K) ans = 1;
	else ans = (N-2) / (K-1) + 1;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4004
#include<stdio.h>
int main(){
	int A, B, C, D, L, x, y;
	scanf("%d %d %d %d %d", &L, &A, &B, &C, &D);
	x = A / C;
	if(( A % C) != 0){
		x++;
	}
	y = B / D;
	if(( B % D) != 0){
		y++;
	}
	if( x > y){
		L= L - x;
	}else{
		L= L- y;
	}
	printf("%d\n",L);
	return 0;
}

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

using namespace std;

int main(){
    long a,b;
    cin>>a>>b;

    long ans=0l;
    for(int i=0;i<40;i++){
        const long period=(1l<<(i+1));
        const long half=period/2;
        const long arem=a%period;
        const long brem=b%period;
        long cnt=half*(b/period-a/period);
        cnt -= (arem >= half ? arem - half : 0) ;
        cnt+=  (brem >= half ?1+ brem - half : 0);
        if(cnt%2==1){
            ans|=half;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  vector<string> week={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string s;
  cin >> s;
  int cnt=7;
  for(int i=0;i<7;i++){
    if(s==week[i]){
      break;
    }
    cnt--;
  }
  cout << cnt << endl;
}


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

int main(){
    ll A,B;
    cin >> A >> B;
    ll a,b;
    a = A;
    b = B;
    ll mod = A % B;
    while(mod != 0){
        A = B;
        B = mod;
        mod = A % B;
    }
    cout << (a * b) / B;
    return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
  S = ns()
  n = len(S) - 1

  ans = 0
  for i in range(1 << n):
    tmp = S[0]
    for j in range(n):
      if (i >> j) & 1 == 1:
        tmp += "+"
      tmp += S[j+1]
    ans += eval(tmp)
  print(ans)

if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <ctype.h>

int main(void)
{
	char str[128];
	char *it;
	int sum = 0;

	while (fgets(str, sizeof(str), stdin)){
		for (it = str; *it != '\0'; it++){
			if (isdigit(*it)){
				sum += atoi(it);
				while (isdigit(*it)) it++;
			}
		}
	}
	printf("%d\n", sum);

	return (0);
}

Measured memory_bytes: 528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=4e5+5;
int a[N];
ll dp[N];
int main()
{
    int n,m;
    cin>>n>>m;
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<n;i++)
    {
        int l=a[i-1];
        int r=a[i];
        if(l>r)r+=m;
        sum+=r-l;
        if(r-l>1)
        {
            dp[l+2]++;
            dp[r+1]-=r-(l+2)+2;
            dp[r+2]+=r-(l+2)+1;
        }
    }
    ll ans=-1;
    for(int i=1;i<=2*m;i++)
    {
        dp[i]+=dp[i-1];
    }
    for(int i=1;i<=2*m;i++)
    {
        dp[i]+=dp[i-1];
    }
    for(int i=1;i<=m;i++)
    {
        ans=max(ans,dp[i]+dp[i+m]);
    }
    cout<<sum-ans<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vll> vvll;
typedef pair<ll, ll> pii;
typedef pair<string, ll> psi;
typedef pair<ll, string> pis;
typedef pair<ll, vll> plv;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define REP(i, a, b) for(ll i=ll(a);i<=ll(b);++i)
#define REPR(i, a, b) for(ll i=ll(a);i>=ll(b);--i)
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()

template<typename T>
T absolute(T a, T b) { return a >= 0 ? a : -a; }

template<typename T>
T sqr(T a) { return a * a; }

ll par[10000007];

ll find_set(ll v){
    if(par[v]==v)return v;
    return par[v]=find_set(par[v]);
}
void union_set(ll a,ll b){
    a=find_set(a);
    b=find_set(b);
    if(a!=b)par[a]=b;
}

int main() {
    REP(i,0,10000006)par[i]=i;
    fastio
    ll n,m;
    cin>>n>>m;
    REP(i,0,m-1){
        ll a,b,c;
        cin>>a>>b>>c;
        union_set(a,b);
    }
    set<ll>s;
    REP(i,1,n){
        s.insert(find_set(i));
    }
    cout<<s.size()<<endl;
}

Measured memory_bytes: 83072
import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Scanner;
     
    public class Main {
        public static void main(String[] args) throws Exception {    
          
        Date boundaryDate = ConvertDateFromString("2019/04/30");
        
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        
        int result = ConvertDateFromString(input).compareTo(boundaryDate);
     
        if ((result == -1) || (result == 0)) {
          System.out.println("Heisei");
        } else {
          System.out.println("TBD");
        }
     
        scanner.close();
     
    }
     
      public static Date ConvertDateFromString(String dateStr) throws Exception {
     
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
     
            // Date型変換
    	Date formatDate = sdf.parse(dateStr);
            return formatDate;
        }
    }

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 2e9+1;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

void printInfo(vector<int> &a, int id){
	int n = a.size();

	int key        = a[id];
	// int parent_key = INF;
	// int left_key   = INF;
	// int right_key  = INF;
	printf("node %d: ",id+1);
	printf("key = %d, ",key);
	if(id!=0) printf("parent key = %d, ",a[(id-1)/2]);
	if(id*2+1<n)printf("left key = %d, ",a[id*2+1]);
	if(id*2+2<n)printf("right key = %d, ",a[id*2+2]);
	printf("\n");
}

int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	rep(i,n)cin>>a[i];

	rep(i,n) printInfo(a,i);

	return 0;
}


Measured memory_bytes: 3232
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    while(1){
        int n;
        scanf("%d",&n);
        if(n==0)
            break;
        int fie[100100]={0},che=0,bef,start,ans=0;
        for(int i=1;i<=n;i++){
            int now;
            scanf("%d",&now);
            if(i==1)
                start=now,fie[che]++,bef=now;
            else if(i%2==1){
                if(bef!=now)
                    che++;
                fie[che]++;
            }
            else{
                if(bef!=now&&che!=0)
                    fie[che-1]+=fie[che]+1,fie[che]=0,che--;
                else
                    fie[che]++;
                if(bef!=now&&che==0)
                    start=now;

            }
            //printf("[%d][%d]\n",start,che);
            bef=now;
        }
        /*
        for(int i=0;i<10;i++)
            printf("[%d]",fie[i]);
        puts("");
        */
        for(int i=start;fie[i]!=0;i+=2)
            ans+=fie[i];
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1588
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)

int main(){
    ll k;
    cin>>k;
    ll sum=0;
    ll n=0;
   while(n<=k){
       if(n%3==0||n%5==0){
           n++;
           continue;
       }
     sum+=n;
     n++;
   }
   cout<<sum<<endl;
}



Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
const int MAX = 1000;
const int INF = 1e9;
struct edge{int from, to, cost;};
int n, m, d[MAX][MAX];
vector<edge> v;

void warshall_floyd(){
    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]);
        }
    }
}

int check(){
    int res = 0;
    bool shortest;
    for (int i = 0; i < m; i++){
        shortest = false;
        for (int j = 0; j < n; j++){
            if (d[j][v[i].from] == d[j][v[i].to] + v[i].cost) shortest = true;
        }
        if (shortest) res += 1;
    }
    return res;
}

int main(){
    int a, b, c;
    sc(n) sc(m)
    fill((int*)d, (int*)(d + n), INF);
    for (int i = 0; i < n; i++) d[i][i] = 0;
    for (int i = 0; i < m; i++){
        sc(a) sc(b) sc(c)
        a--; b--;
        d[a][b] = c;
        d[b][a] = c;
        v.push_back((edge){a, b, c});
    }
    warshall_floyd();
    cout << m - check() << endl;
    return 0;
}

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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < (int)k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int r, c;
int n[10][10000], ans = 0;
bool use[10];

void dfs(int now) {
    if(now == r) {
        int res = 0;
        rep(j, c) {
            int count = 0;
            rep(i, r) {
                if((use[i] && n[i][j]) || (!use[i] && !n[i][j])) ++count;
            }
            res += (r - count < count) ? count : r - count;
        }
        chmax(ans, res);
        return;
    }
    use[now] = true;
    dfs(now + 1);
    use[now] = false;
    dfs(now + 1);
}

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

    while((cin >> r >> c), r | c) {
        ans = 0;
        rep(i, r) rep(j, c) cin >> n[i][j];
        dfs(0);
        cout << ans << endl;
    }
    return 0;
}

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

typedef pair<long long, long long> P;
typedef pair<long long, P> PP;

#define MAX_N 100001

long long par[MAX_N]; // 親
long long rankuf[MAX_N]; // 木の深さ
// n要素で初期化
void init(long long n) {
	for (long long i = 0; i < n; i++) {
		par[i] = i;
    rankuf[i] = 0;
	}
}
// 木の根を求める
long long find(long long x) {
	if (par[x] == x) {
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}
// xとyの属する集合を併合
void unite(long long x, long long y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (rankuf[x] < rankuf[y]) {
		par[x] = y;
	} else {
		par[y] = x;
		if (rankuf[x] == rankuf[y]) rankuf[x]++;
	}
}
// xとyが同じ集合に属するか否か
bool same(long long x, long long y) {
	return find(x) == find(y);
}

int main(){
	long long N;
	scanf("%lld",&N);
	init(N);
	vector<long long> x(N-1+1);
	vector<long long> y(N-1+1);
	priority_queue<PP, vector<PP>, greater<PP> > quex, quey;
	for(long long i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&x[i]);
		scanf("%lld",&y[i]);
	}
	vector<P> px(N-1+1);
	vector<P> py(N-1+1);
	for(long long i = 0 ; i <= N-1 ; i++){
		px[i] = P(x[i],i);
		py[i] = P(y[i],i);
	}
	// printf("1\n");
	sort(px.begin(),px.end());
	sort(py.begin(),py.end());
	// printf("1\n");
	for(long long i = 0 ; i < N-1 ; i++){
		quex.push(PP(abs(px[i].first-px[i+1].first), P(px[i].second,px[i+1].second)));
		quey.push(PP(abs(py[i].first-py[i+1].first), P(py[i].second,py[i+1].second)));
	}

	long long res = 0;
// printf("%lld,%lu,%lu,%lld,%lld\n", res, quex.size(), quey.size(),quex.top().first,quey.top().first);
	while (!quex.empty() || !quey.empty()){
		if (quey.empty()) {
			// printf("%lld\n",quex.top().first);
			if (!same(quex.top().second.first,quex.top().second.second)) res += quex.top().first;
			unite(quex.top().second.first,quex.top().second.second);
			quex.pop();
			// printf("1\n");
			// for(long long i = 0 ; i <= N-1 ; i++){
			// 	printf("%lld:%d\n",i,used[i]);
			// }
		} else if (quex.empty()){
			if (!same(quey.top().second.first,quey.top().second.second)) res += quey.top().first;
			unite(quey.top().second.first,quey.top().second.second);
			quey.pop();
			// printf("2\n");
			// for(long long i = 0 ; i <= N-1 ; i++){
			// 	printf("%lld:%d\n",i,used[i]);
			// }
		} else {
			if (quex.top().first < quey.top().first) {
				if (!same(quex.top().second.first,quex.top().second.second)) res += quex.top().first;
				unite(quex.top().second.first,quex.top().second.second);
				quex.pop();
				// printf("3\n");
				// for(long long i = 0 ; i <= N-1 ; i++){
				// 	printf("%lld:%d\n",i,used[i]);
				// }
			} else {
				// printf("%lld,%lld,%lld\n",!used[quey.top().second.first],quey.top().second.first,quey.top().second.second);
				if (!same(quey.top().second.first,quey.top().second.second)) res += quey.top().first;
				unite(quey.top().second.first,quey.top().second.second);
				quey.pop();
				// printf("4\n");
				// for(long long i = 0 ; i <= N-1 ; i++){
				// 	printf("%lld:%d\n",i,used[i]);
				// }
			}
		}
		// printf("%lld,%lu,%lu,%lld,%lld\n", res, quex.size(), quey.size(),quex.top().first,quey.top().first);
	}
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 13608
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <cstring>
//#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define PI acos(-1.0)
typedef long long ll;
typedef unsigned long long ull;
#define gcd __gcd
const int INF=0x3f3f3f3f;
const ll LINF=1000000000000000000;
//priority_queue<int, vector<int>, greater<int> >p;
#define N 200005
//ll n,m,l,x,y,k,sum,g,mid,h,v;
//ll d[4][2]={1,0,-1,0,0,1,0,-1};
//ll a[N],b[N];
int main()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k&1)cout<<b-a<<endl;
    else cout<<a-b<<endl;
//    ios_base::sync_with_stdio(0);
//    cin>>n;
//    for(int i=1;i<=n;i++)
//        cin>>a[i],b[a[i]]=i;
//    x=1;
//    for(int i=2;i<=n;i++)
//        if(b[i]<b[i-1]){x=i-1;break;}
//    for(int i=n-1;i>=1;i--)
//        if(b[i]>b[i+1]){x=max(x,n-i);break;}
//    cout<<n-x<<endl;
    return 0;
}



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

int main()
{
    int n,k,q,x;
    cin>>n>>k>>q;
    int temp = q;
    vector<int> arr(n,k);
 
     while(temp--) {
               cin>>x;
        arr[x-1]++;}
  
   for(int i=0; i<n;i++) {
        arr[i] -= q;
        if(arr[i] <=0) cout<<"No\n";
        else cout<<"Yes\n";
    }
    
    //for(int i=0; i<n; i++) cout<<arr[i];
}

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

const ll INF = 1e+16;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n+1);
    a[0] = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++){
        a[i] += a[i-1];
    }
    ll ans = INF;
    for(int i = 1; i < n; i++){
        ll x = a[n] - a[i];
        ll y = a[i];
        ans = min(ans, abs(x - y));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4756
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int X;
int Y;
int N;
int A[10000];
int res[100][100];
int main(){
  int k;
  int i;
  int j;
  rd(X);
  rd(Y);
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  i = j = 0;
  for(k=(0);k<(N);k++){
    int KL2GvlyY;
    for(KL2GvlyY=(0);KL2GvlyY<(A[k]);KL2GvlyY++){
      if(i%2==0){
        res[i][j] = k + 1;
      }
      else{
        res[i][Y-1-j] = k + 1;
      }
      if(++j == Y){
        i++;
        j = 0;
      }
    }
  }
  for(i=(0);i<(X);i++){
    {
      int Q5VJL1cS;
      if(Y==0){
        putchar_unlocked('\n');
      }
      else{
        for(Q5VJL1cS=(0);Q5VJL1cS<(Y-1);Q5VJL1cS++){
          wt_L(res[i][Q5VJL1cS]);
          wt_L(' ');
        }
        wt_L(res[i][Q5VJL1cS]);
        wt_L('\n');
      }
    }
  }
  return 0;
}
// cLay varsion 20190921-1

// --- original code ---
// int X, Y, N, A[10000];
// int res[100][100];
// {
//   int i, j;
//   rd(X,Y,N,A(N));
//   i = j = 0;
//   rep(k,N) rep(A[k]){
//     res[i][if[i%2==0, j, Y-1-j]] = k + 1;
//     if(++j == Y) i++, j = 0;
//   }
//   rep(i,X) wt(res[i](Y));
// }


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

#define INF 1000000000

using namespace std;

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

    string str;
    cin >> str;

    str[K - 1] = str[K - 1] - 'A' + 'a';

    cout << str << endl;

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>

template<class T>
int partition(T &A, int first, int last){
    const int pivot = A[last-1].second;
    int bound = first-1;
    for(int i=first;i<last;++i)
        if(A[i].second<=pivot) std::swap(A[++bound], A[i]);
    return bound;
}
template<class T>
void quickSort(T &A, int first, int last){
    if(last-first<2) return;
    const int bound = partition(A,first,last);
    quickSort(A,first,bound);
    quickSort(A,bound,last);
}
#include<iostream>
#include<vector>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<pair<char,int>> A(N),B(N);
    for(int i=0;i<N;++i) cin>>A[i].first>>A[i].second;
    copy(A.begin(),A.end(),B.begin());
    quickSort(A,0,N);
    stable_sort(B.begin(),B.end(),[](pair<char,int>a,pair<char,int>b){return a.second<b.second;});
    cout<<(mismatch(A.begin(),A.end(),B.begin()).first==A.end()?"Stable":"Not stable")<<endl;
    for(auto &a:A) cout<<a.first<<' '<<a.second<<endl;
}

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

int main()
{
    int N;
    cin >> N;
    int fac2 = 0, fac4 = 0, fr = 0;
    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        if (tmp % 4 == 0)
            fac4++;
        else if (tmp % 2 == 0)
            fac2++;
        else
            fr++;
    }
    int mfac4 = N - fac4 * 2;
    if (fac2 == 0)
    {
        if (fac4 >= (fr - 1))
            cout << "Yes" << endl;
        else
        {
            cout << "No" << endl;
        }
    }
    else
    {
        if (fac4 >= fr)
            cout << "Yes" << endl;
        else
        {
            cout << "No" << endl;
        }
    }
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[100005];

int main()
{
    ll N;
    cin >> N;
    REP(i, N + 1)
    {
        cin >> A[i];
    }
    ll ans = 0;
    REP(i, N)
    {
        ll b;
        cin >> b;
        ll m = std::min(b, A[i]);
        b -= m;
        ll n = std::min(b, A[i + 1]);
        A[i + 1] -= n;
        ans += m + n;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> coin(N, 0);
    int tgt = K;
    int cnt = 0;
    while ((N << cnt) < K) {
        cnt++;
    }
    for (int i = N; i >= 1; i--) {
        if ((i << cnt) >= tgt) {
            coin[i-1] = (1 << cnt);
        } else {
            cnt++;;
            coin[i-1] = (1 << cnt);
        }
        // cout << coin[i-1] << " ";
    }
    double result = 0;
    for (int i = 0; i < N; i++) {
        result += 1.0 / (double)coin[i];
    }
    // cout << result << endl;
    result = result / (double)N;
    // cout << result << endl;
    printf("%.11f\n", result);
    return 0;
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, x=1;
  cin >> n;
  forll(i, 1, n+1)
	x = x * i % 1000000007;
  cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) \
    SORT(a);     \
    reverse(a.begin(), a.end())
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll N, K, S;

int main()
{
    cin >> N >> K >> S;

    vi ans = vi(N);
    REP(i, N)
    {
        if (i < K)
        {
            ans[i] = S;
        }
        else if (S < 1e9)
        {
            ans[i] = 1e9;
        }
        else
        {
            ans[i] = 1;
        }
    }

    OUTA(ans, N);
    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,k;
	cin>>n>>k;
	int a[1010];
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	int ans=0;
	for(int i=0;i<k;i++)ans+=a[i];
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N, M;
    while (cin >> N >> M, N|M) {
        int use[10001];
        int start[10001];
        fill_n((int *)use, 10001, 0);
        vector<pair<int, int>> vpii[10001];

        // data
        int r;
        cin >> r;
        for (int i = 0; i < r; i++) {
            int t, n, m, s;
            cin >> t >> n >> m >> s;
            if (s == 1) { // login
                if (use[m] == 0) {
                    start[m] = t;
                }
                use[m]++;
            } else { // logout
                use[m]--;
                if (use[m] == 0) {
                    vpii[m].push_back({start[m], t});
                }
            }
        }

        // query
        int q;
        cin >> q;
        for (int i = 0; i < q; i++) {
            int ts, te, m;
            cin >> ts >> te >> m;
            int total = 0;
            for (auto pii: vpii[m]) {
                if (te <= pii.first || ts >= pii.second)
                    continue;
                int left, right;
                left = pii.first > ts ? pii.first : ts;
                right = pii.second < te ? pii.second : te;
                total += right - left;
            }
            cout << total << endl;
        }
    }
    return 0;
}

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

int main (void){
 int a,b,k;
 cin >> a >> b >> k;

 if(b - a + 1 >= 2*k){
 for(int i = 0;i < k;i++){
 cout << a + i << '\n';
 }
 for(int i = 0;i < k;i++){
 cout << b - k + 1 + i << '\n';
 }
 }else if(b - a + 1 >= k){
 for(int i = 0;i < k;i++){
 cout << a + i << '\n';
 }
 for(int i = 0;i < b - a + 1 - k;i++){
 cout << a + k + i << '\n';
 }
 }else{
 for(int i = 0;i < b - a + 1;i++){
 cout << a + i << '\n';
 }
 }
 return 0;
 }

Measured memory_bytes: 3540
import math

def isPrime(n):  # 素数判定
    if n == 2:
        return True
    if n < 2 or n % 2 == 0:
        return False
    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            return False
        i += 2
    return True

n = int(input())
cnt = 0
for i in range(n):
    num = int(input())
    if isPrime(num):
        cnt += 1
print(cnt)



Measured memory_bytes: 5672
#include<iostream>
#include<vector>
#include<queue>
#include<map>
using namespace std;

#define N 3002
#define INF 100000000

struct Edge {
	int to, cost;
	Edge(int t, int c) : to(t), cost(c) {}
	Edge() {};
};

typedef vector<Edge> Graph;

int cost[N];
Graph g[N];
vector<int> sv;
typedef pair<int, int> P;

void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P> > q;
	cost[s] = 0; q.push(P(0,s));
	while(!q.empty()) {
		int p = q.top().first, v = q.top().second; q.pop();
		if(cost[v]<p) continue;
		for(int i=0; i<(signed)g[v].size(); ++i) {
			Edge e = g[v][i];
			if(cost[v]+e.cost<cost[e.to]) {
				cost[e.to] = cost[v]+e.cost;
				q.push(P(cost[e.to], e.to));
			}
		}
	}
}

#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)

int main() {
	int n, m, k, a, b, l, s;
	double ans = 0.0;
	cin >> n >> m >> k;
	for(int i=1; i<=n; ++i) cost[i] = INF;
	for(int i=0; i<m; ++i) {
		cin >> a >> b >> l;
		g[a].push_back(Edge(b,l));
		g[b].push_back(Edge(a,l));
	}
	for(int i=0; i<k; ++i) {
		cin >> s;
		dijkstra(s);
	}
	for(int i=1; i<=n; ++i) {
		for(int j=0; j<(signed)g[i].size(); ++j) {
			if(i<g[i][j].to) continue;
			a = cost[i]; b = cost[g[i][j].to]; l = g[i][j].cost;
			if(a>=b+l || b>=a+l) {
				ans = max(ans, (double)max(a,b));
			}else {
				ans = max(ans, (double)(a+b+l)/2.0);
			}
		}
	}
	cout << (int)(ans+0.5) << endl;
	return 0;
}

Measured memory_bytes: 4184
// #pragma GCC optimize("03")
#include <bits/stdc++.h>
#define ll long long 
#define fi first
#define se second

using namespace std;

int a[100100][3], n, k;
int dp[100100][3];

int main() {    
    // ifstream cin("tst.in");
    // ofstream cout("tst.out");
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= 3; j++)
            cin >> a[i][j];

    for (int i = 1; i <= 3; i++)
        dp[1][i] = a[1][i];

    for (int i = 2; i <= n; i++)
        for (int j = 1; j <= 3; j++)
            for (int k = 1; k <= 3; k++)
                if (k != j)
                    dp[i][k] = max(dp[i][k], dp[i - 1][j] + a[i][k]);

    int mn = 0;
    for (int i = 1; i <= 3; i++)
        mn = max(mn, dp[n][i]);

    cout << mn;

    return 0;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1LL<<60)

//0-index 抽象化半開区間遅延セグツリー
template<typename T, typename E>
class segment_tree{
    typedef function<T(T,T)> F; //要素に適用する演算
    typedef function<T(T,E)> G; //作用素の適用
    typedef function<E(E,E)> H; //作用素の合成
    typedef function<E(E,int)> P;
private:
    int num_of_elm_;
    vector<T> dat_, lazy_;
    F f_;
    G g_;
    H h_;
    P p_;
    T ident_;
    E op_ident_;
public:
    segment_tree(int n, F f, G g, H h, P p, T ident, E op_ident):f_(f), g_(g), h_(h), p_(p), ident_(ident), op_ident_(op_ident){
        num_of_elm_ = 1;
        while(num_of_elm_<n)num_of_elm_*=2;
        dat_ .resize(2*num_of_elm_,ident);
        lazy_.resize(2*num_of_elm_,op_ident);
    }
    
    void build(vector<T> vec){
        rep(i,vec.size()) dat_[num_of_elm_+i] = vec[i];
        for(int i=num_of_elm_-1;i>=1;i--)dat_[i] = f_(dat_[i*2],dat_[i*2+1]);
    }
    
    void eval(int k, int len){
        if(lazy_[k] == op_ident_)return ;
        
        if(k<num_of_elm_){
            lazy_[k*2]=h_(lazy_[k*2], lazy_[k]);
            lazy_[k*2+1]=h_(lazy_[k*2+1], lazy_[k]);
        }
        dat_[k] = g_(dat_[k],p_(lazy_[k], len));
        lazy_[k] = op_ident_;
    }
    
    T update(int L, int R, int val, int l=0, int r=0, int k=1){
        if(k==1)r = num_of_elm_;
        
        eval(k,r-l);
        if(r<=L || R<=l)return dat_[k];
        else if(L<=l && r<=R){
            lazy_[k] = h_(lazy_[k], val);
            return g_(dat_[k], p_(lazy_[k], r-l));
        }
        else{
            return dat_[k] = f_(update(L,R,val,l,(l+r)/2,k*2), update(L,R,val,(l+r)/2,r,k*2+1));
        }
        
    }
    
    T query(int L, int R,int l=0,int r=0, int k=1){
        if(k==1)r = num_of_elm_;
        
        eval(k,r-l);
        if(r<=L || R<=l)return ident_;
        else if(L<=l && r<=R){
            return dat_[k];
        }
        else{
            return f_(query(L,R,l,(l+r)/2,k*2), query(L,R,(l+r)/2,r,k*2+1));
        }
    }
};

signed main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    auto f = [](int a, int b){ return max(a,b); };
    auto g = f;
    auto h = [](int a, int b){ return b; };
    auto p = [](int a, int len){ return a; };

    segment_tree<int,int> dp(n+1,f,g,h,p,0,0);
    
    for(int i=1;i<=n;i++){
        dp.update(v[i-1], v[i-1]+1, dp.query( 0,v[i-1] )+v[i-1] );
    }
    cout<<n*(n+1)/2-dp.query(0,n+1)<<endl;
}



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

int main()
{
    int N,K;
    cin>>N>>K;
    priority_queue<int, vector<int>, greater<int> > pq;
    if(N==1)
    {
        int a;
        cin>>a;
        cout<<a;return 0;
    }
    for(int i=0;i<N;i++)
    {
        int a;
        cin>>a;
        pq.push(a);
    }
    int mina=0;
    for(int i=0;i<K;i++)
    {
        int a=pq.top();
        mina+=a;
        pq.pop();
    }
    cout<<mina;
    return 0;
}


Measured memory_bytes: 3612