akhauriyash/Code-Regression huggingface dataset:
/***
 
            Bismillahir Rahmanir Rahim
            Rabbi Zidni Ilma
            Author : Saidur Rahman
            Department of CSE, City University, Bangladesh.
 
***/

#include<iostream>
using namespace std;

#define         sf                  scanf
#define         sff(a)              scanf("%d",&a)
#define         sfl(a)              scanf("%lld",&a)
#define         sfff(a,b)           scanf("%d%d",&a,&b)
#define         sfll(a,b)           scanf("%lld%lld",&a,&b)
#define         sffff(a,b,c)        scanf("%d%d%d",&a,&b,&c)
#define         sflll(a,b,c)        scanf("%lld%lld%lld",&a,&b,&c)
#define         pff(a)              printf("%d\n",a)
#define         pfl(a)              printf("%lld\n",a)
#define         pf                  printf
#define         pb                  push_back
#define         vi                  vector<int>
#define         newline             printf("\n")
#define         NO                  printf("NO\n")
#define         no                  printf("no\n")
#define         YES                 printf("YES\n")
#define         yes                 printf("yes\n")
#define         endl                "\n"
#define         kaj_shuru           int main()
#define         kaj_shesh           return 0

#define         PI                  acos(-1.0)
#define         f0(i,b)             for(int i=0;i<(b);i++)
#define         f1(i,b)             for(int i=1;i<=(b);i++)
#define         f2(i,a,b)           for(int i=(a);i<=(b);i++)
#define         TEST_CASE(t)        for(int Case=1 ; Case<=t ; Case++)
#define         input               freopen("input.txt", "r", stdin);
#define         output              freopen("output.txt", "w", stdout);

int         SetBit (int n, int X)       { return n | (1 << X); }
int         ClearBit (int n, int X)     { return n & ~(1 << X); }
int         ToggleBit (int n, int X)    { return n ^ (1 << X); }
bool        CheckBit (int n, int X)     { return (bool)(n & (1 << X)); }


/******************************** Code Started From Here **********************************/

const int MAX=1e8;
typedef long long ll;


kaj_shuru
{
   // std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
 #ifndef ONLINE_JUDGE 
    input;
    output;
#endif
    int n;
    sff(n);
    int a[n][n];
    for (int i = 0; i < n;i++)
    {
        for (int j = 0; j < 2;j++)
        {
            sff(a[i][j]);
        }
    }
    bool ok = 0;
    for (int i = 0; i < n;i++)
    {
        if(a[i][0]==a[i][1])
            {
                int cnt = 1;
                for (int j =i+1 ; j < n;j++)
                {
                    if(a[j][0]==a[j][1])
                    {
                        cnt++;
                    }
                    else
                        break;
                }
                if(cnt>=3)
                    ok = 1;
            }
            if(ok)
                break;
    }
    if(ok)
        pf("Yes\n");
    else
        pf("No\n");

        kaj_shesh;
}


Measured memory_bytes: 3200
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n, c[550], s[550], f[550];

int start(int x){
    int t = s[x] + c[x];
    for(int i = x + 1; i < n; ++i){
        if(t <= s[i]) t += s[i] - t;
        else{
            int w = (t - s[i]) % f[i];
            t += (w == 0 ? 0 : f[i] - w);
        }
        t += c[i];
    }
    return t;
}

void solve(){
    cin >> n;
    n--;
    for(int i = 0; i < n; ++i){
        cin >> c[i] >> s[i] >> f[i];
    }

    for(int i = 0; i < n; ++i){
        cout << start(i) << "\n";
    }
    cout << "0\n";
}

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

    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
	ll n,m,sum=0,ans=0;
	map<ll,int>mp;
	mp[0]++;
	cin >> n;
	rep(i,n){
		cin >> m;
		sum+=m;
		ans+=mp[sum];
		mp[sum]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
#define pb push_back
#define INF (ll)1e9
using namespace std;
using ll = long long;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,k,s;
	cin>>n>>k>>s;
	vector<ll> ans;
	ll left,right;
	if(k == n){
		while(k--){
			ans.pb(s);
		}
		for(ll i=0;i<n;i++){
			cout<<ans[i]<<" ";
		}
	}
	else if(s == 1){
		while(k--){
			ans.pb(1);
		}
		ll size = ans.size();
		while(size != n){
			ans.pb(INF);
			size++;
		}
		for(int i =0;i<n;i++){
			cout<<ans[i]<<" ";
		}
	}
	else if(k == 0){
		ll MI = INF;
		if(s == INF){
			MI--;
		}
		ans.resize(n,MI);
		for(auto it : ans){
			cout<<it<<" ";
		}
	}
	else{
		left = s/2;
		//cerr<<left;
		right = s - left;
		k--;
		ans.pb(left);
		ans.pb(right);
		ll i=0;
		while(k--){
			if(i&1){
				ans.pb(right);
			}
			else
				ans.pb(left);
			
			i++;
		}
		ll p= ans.size();
		ll MI = INF;
		if(s == INF){
			MI--;
		}
		if(p <n){
			//ll size = ans.size();
			//cerr<<"\n"<<INF-1<<"\n";
			while(p != n){
				//cerr<<"\n\n";
				ans.pb(MI);
				p++;
			}
		}
		
		for(i=0;i<n;i++){
			cout<<ans[i]<<" ";
		}
	}
	
}




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


int main(void) {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) {
    cin >> p.at(i);
  }
  int k = 0;
  rep(i, n) {
    if (p.at(i) != i + 1) {
      k++;
    }
    }
    if (k <= 2) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int[][] B = new int[M][];
		for(var i=0;i<M;i++){
			B[i] = new int[3];
			string[] str2 = Console.ReadLine().Split();
			B[i][0] = int.Parse(str2[0]);
			B[i][1] = int.Parse(str2[1]);
			B[i][2] = i;
		}
		Array.Sort(B,(x,y)=>x[1] - y[1]);
		int[,] C = new int[M,2];
		int[] D = new int[N];
		for(var i=0;i<M;i++){
			C[B[i][2],0] = B[i][0];
			C[B[i][2],1] = D[B[i][0]-1]+1;
			D[B[i][0]-1] += 1;
		}
		string[] E = new string[M];
		for(var i=0;i<M;i++){
			string a1 = "000000"+C[i,0].ToString();
			a1 = a1.Substring(a1.Length-6,6);
			string a2 = "000000"+C[i,1].ToString();
			a2 = a2.Substring(a2.Length-6,6);
			E[i] = a1+a2;
		}		
		for(var i=0;i<M;i++){
			Console.WriteLine(E[i]);
		}
	}
}

Measured memory_bytes: 32676
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
using namespace std;
double solve(ll num, double d1, double dif){
	if(num == 1) return d1;
	else{
		ll nnum = num-1;
		double nd1 = (num+1) * d1 / num + 3 * dif / (2 * num);
		double ndif = (num+2) * dif / num;
		double ex = d1 + (num-1) * dif / 2.0;
		return ex + solve(nnum, nd1,ndif);
	}
}
int main(){
	ll n,d,x;
	cin>>n>>d>>x;
	double nd = (d + d + x) / 2.0;
	double nx = x * 2.0;
	cout<<fixed;
	cout<<setprecision(12)<<solve(n,nd,nx)<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

int c[1000], t[1000];

int main() {
    int N, T;
    cin >> N >> T;
    rep(i, N)cin >> c[i] >> t[i];

    int mi = INF;
    rep(i, N) {
        if (t[i] <= T) {
            mi = min(c[i], mi);
        }
    }
    if (mi == INF) {
        cout << "TLE" << endl;
    }
    else cout << mi << endl;

}


Measured memory_bytes: 256
N = int(input())
dp = [True] * 10**6
count = 0
if N % 2 == 0:
    times = 0
    while(N % 2 == 0):
        times += 1
        N //= 2
    i = 1
    while(times-i >= 0):
        times -= i
        i += 1
        count += 1
f = 3
while f**2 < N:
    if N % f == 0:
        times = 0
        while(N % f == 0):
            times += 1
            N //= f
        i = 1
        while(times-i >= 0):
            times -= i
            i += 1
            count += 1
    else:
        f += 2
if N != 1:
    count += 1
print(count)

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

int	main() {
	int N;
	cin >>N;
	int a=0;
	int b=0;
	int ab=0;
	int ab1=0;
	for (int i=0; i<N; i++) {
		string S;
		cin >>S;
		for (int j=1; j<S.size(); j++)
			if (('A'==S.at(j-1))&&('B'==S.at(j)))
				ab++;
		if ('B'==S.front()) {
			b++;
			if ('A'==S.back())
				ab1++;
		}
		if ('A'==S.back())
			a++;
	}
	if ((a>0)&&(a==b)&&(a==ab1))
		a--;
	a=min(a, b);
	a=min(a, N-1);
	cout <<a+ab <<endl;
	return 0;
};


Measured memory_bytes: 256
import math
n=int(input())
a=[0]*5
a[0]=int(input())
a[1]=int(input())
a[2]=int(input())
a[3]=int(input())
a[4]=int(input())
min_a=min(a)
min_index=a.index(min(a))
print(math.ceil(n/a[min_index])+4)

Measured memory_bytes: 3064
#include<iostream>
 
using namespace std;
 
int main(){
  int lot[31];
  for(int i=1;i<=30;i++){
    lot[i]=i;
  }
  int w,n;
  cin>>w>>n;
  for(int i=0;i<n;i++){
    int a,b;
    (cin>>a).ignore()>>b;
    swap(lot[a],lot[b]);
  }
  for(int i=1;i<=w;i++){
    cout<<lot[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

use std::cmp::max;
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"4 7 9 3
" => r"Yes",

r"100 10 1 2
" => r"No",

r"10 10 10 1
" => r"Yes",

r"1 100 2 10
" => r"Yes"
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: i32,
        b: i32,
        c: i32,
        d: i32
    }

    if (a - c).abs() <= d || ((a - b).abs() <= d && (b - c).abs() <= d) {
        "Yes".to_string()
    } else {
        "No".to_string()
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    ll n,a,b;
    cin >> n >> a >> b;

    if(a>=n){
        cout << n << endl;
        return 0;
    }

    ll ab=a+b;
    if(ab>=n){
        cout << a << endl;
        return 0;
    }

    ll asum=a*(n/ab);
    if(n-ab*(n/ab)>a)asum+=a;
    else asum+=(n-ab*(n/ab));

    cout << asum << endl;

    return 0;
}


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

import numpy as np

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

#2次元配列を作る
#[j][0]で数字の個数を、[j][1]で数字自体を取り出す
BC = []
for _ in range(M):
  BC.append(list(map(int, input().split())))

BC = np.array(BC)
BC = BC[BC[:,1].argsort()[::-1],:]


ans = 0
nowaindex = 0
for i, bc in enumerate(BC):
  #continueflagが0のままならループ全体を抜ける
  continueflag = 0
  b = bc[0]
  c = bc[1]
  for j in range(b):
    if A[nowaindex]<c:
      ans += c
      nowaindex += 1
      continueflag += 1
      if nowaindex > N-1:
        continueflag = 0
        break
    else: break
  if continueflag == 0: break
    
print(ans + sum(A[nowaindex:]))

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

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

  int ans = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      for (int k = j + 1; k < n; k++) {
        if (l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) continue;

        if (l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j])
          ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long ans = 0;
  for (int i = 0; i < n - k; ++i) {
    ans += a[i];
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,a,b,i,j,x,y,sum;

    while(scanf("%d",&n)==1)
    {
        m = 7;
        sum = 0;
        if(n%2==0||n%5==0)printf("-1\n");
        else
        {
            while(m%n!=0)
            {
                sum++;
                m = m*10+7;
                m = m%n;
            }
            printf("%d\n",sum+1);



        }
    }







return 0;
}


Measured memory_bytes: 3828
#include<cstdio>
#include<algorithm>
using namespace std;

int a[10005];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d", &a[i]);
    sort(a, a+n);
    int q, key, cnt=0;
    scanf("%d", &q);
    for(int i=0; i<q; i++)
    {
        scanf("%d", &key);
        if(binary_search(a, a+n, key)) cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 2808
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int n,m;
	cin>>n>>m;
	int ans=0;
	if(n>=2){
		ans+=n*(n-1)/2;
	}
	if(m>=2){
		ans+=m*(m-1)/2;
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#ifndef ONLINE_JUDGE
#define OJ \
    freopen("input.txt", "r", stdin); \
    //freopen("output.txt", "w", stdout);
#else
#define OJ ;
#endif
void solve()
{
    int e=0,ans=0;
    string s;
    cin>>s;

    if(s[1]=='R')
    {
        ans++;
        if(s[0]=='R')
        {
            ans++;
        }
        if(s[2]=='R')
        {
            ans++;
        }
    }
    else
    {
        if(s[0]=='R')
        {
            ans=1;
        }
        if(s[2]=='R')
        {
            ans=1;
        }
    }
    cout<<ans<<"\n";
    
}
signed main()
{
    OJ
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //int _t;cin>>_t;while(_t--)
    solve();
    return 0;
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int h, w;
vvi d;
vector<string> g;
typedef tuple<int, int, int> tup;

int dijk(int i, int j){
    priority_queue<tup, vector<tup>, greater<tup>> pq;
    pq.push(make_tuple(0,0,0));
    d[0][0] = 0;
    while(!pq.empty()){
        auto t = pq.top(); pq.pop();
        int c = get<0>(t), i = get<1>(t), j = get<2>(t);
        if(j+1 < w){
            int nc = (g[i][j] == g[i][j+1]) ? c : c+1;
            if(d[i][j+1] > nc){
                d[i][j+1] = nc;
                pq.push(make_tuple(nc, i, j+1));
            }
        }
        if(i+1 < h){
            int nc = (g[i][j] == g[i+1][j]) ? c : c+1;
            if(d[i+1][j] > nc){
                d[i+1][j] = nc;
                pq.push(make_tuple(nc, i+1, j));
            }
        }
    }
    return d[h-1][w-1];
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    cin >> h >> w;
    g = vector<string>(h);
    rep(i,h) cin >> g[i];
    d = vvi(h, vi(w, INF));

    int ans = dijk(0,0);
    if(g[0][0] == '#') ans++;
    if(g[h-1][w-1] == '#') ans++;
    cout << (ans + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 384
<?php
list($n, $m) = array_map("intval", explode(" ", trim(fgets(STDIN))));
for($i = 0; $i < $m; $i++){
    list($l, $r, $d) = array_map("intval", explode(" ", trim(fgets(STDIN))));
    $link[$l][$r] =  $d;
    $link[$r][$l] = -$d;
}

for($i = 1; $i <= $n; $i++){
    if(!isset($pos[$i]))dfs($i, 0);
}
echo "Yes\n";

function dfs($i, $p){
    global $pos;
    global $link;
    if(isset($pos[$i])){
        if($pos[$i] != $p){
            echo "No\n";exit;
        }
    }else{
        $pos[$i] = $p;
        foreach($link[$i]??[] as $to => $d){
            dfs($to, $p + $d);
        }
    }
}


Measured memory_bytes: 88568
def findNumberOfTriangles(arr, n): 
      
    # Count of triangles 
    count = 0
      
    # The three loops select three 
    # different values from array 
    for i in range(n): 
        for j in range(i + 1, n): 
              
            # The innermost loop checks for 
            # the triangle property 
            for k in range(j + 1, n): 
                if(arr[i]!=arr[j] and arr[j]!=arr[k] and arr[i]!=arr[k]):
                    
                # Sum of two sides is greater 
                # than the third 
                    if (arr[i] + arr[j] > arr[k] and 
                        arr[i] + arr[k] > arr[j] and 
                        arr[k] + arr[j] > arr[i]): 
                            count += 1
    return count 
  
# Driver code 

n=int(input())
arr = list(map(int,input().split()))
size = len(arr) 
  
print(findNumberOfTriangles(arr, size)) 
  

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

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

  if (S == "SUN") {
    cout << '7' << endl;
  }

  if (S == "MON") {
    cout << '6' << endl;
  }

  if (S == "TUE") {
    cout  << '5' << endl;
  }

  if (S == "WED") {
    cout << '4' << endl;
  }

  if (S == "THU") {
    cout << '3' << endl;
  }

  if (S == "FRI") {
    cout << '2' << endl;
  }
  if (S == "SAT") {
    cout << '1' << endl;
  }

  return 0;
}


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

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

Measured memory_bytes: 3096
N = int(input())
A = [int(x) for x in input().split()]
res = list()
count = 0
for n in range(N-1):
  if A[n] >= A[n+1]:
    count += 1
  else:
    res.append(count)
    count = 0
res.append(count)
print(max(res))

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int n,k,dp[100009][3],a[100009][3],mx=1e9+8;
int bt(int x,int al)
{
    if(x==0)return a[x][al];
    if(dp[x][al]!=-1)return dp[x][al];
    for(int i=0;i<3;i++)
    {
        if(i==al)continue;
        dp[x][al]=max(dp[x][al],bt(x-1,i));
    }
    dp[x][al]+=a[x][al];
    return dp[x][al];
}
int main()
{
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)cin>>a[i][j];
    }
    int mx=0;
    for(int i=0;i<3;i++)
    {
        mx=max(mx,bt(n-1,i));
    }
    cout<<mx;
}


Measured memory_bytes: 8832
#include<stdio.h>
#include<math.h>
#define ll long long
#define MOD 1000000007

long long mypow(long long k, long long n) {
	long long temp = 1;
 
	k = k % MOD;
	while (n) {
		if (n & 1) temp = temp * k % MOD;
		k = k * k % MOD;
		n = n >> 1;
	}
	return temp % MOD;
}

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

long long combi(long long n, long long r) {
	long long x = 1, y = 1, y_inv;
	long long min;
 
	if (n - r > r) min = r;
	else min = n - r;
	for (long long i = 0; i < min; i++) {
		x = x * (n - i) % MOD;
		y = y * (i + 1) % MOD;
	}
	y_inv = mypow(y, MOD - 2);
	return x * y_inv % MOD;
}

int main(){
  ll n, a, b, i;
  scanf("%lld%lld%lld",&n, &a, &b);
  ll ans = (mypow(2,n)-1-combi(n,a));
  if (ans < 0)ans = (ans + MOD);
  ans = (ans-combi(n,b));
  if (ans < 0)ans = (ans + MOD);
  printf("%lld",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
double dist(double x, double y){
	return sqrt(x * x + y * y);
}
double fact(double n){
	double res = 1;
	for(int i = 2; i <= n; ++i){
		res *= i;
	}
	return res;
}
void solve()
{
	int n;
	cin >> n;
	vector<pair<double, double> > v;
	vector<double> k;
	for(int i = 0 ;i < n; ++i){
		double x, y;
		cin >> x >> y;
		v.pb({x, y});
		k.pb(i);
	}
	double res = 0;
	do{		
		for(int i = 1; i < sz(k); ++i){
			res += dist(v[k[i]].F - v[k[i - 1]].F, v[k[i]].S - v[k[i - 1]].S);
		}
	}		
	while(next_permutation(all(k)));
	// cout << res << endl;
	res = res / fact(n);
	cout << fixed << setprecision(7) << res;
}
 
int main()
{
    Red;
    solve();
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		int x = cin.nextInt();
		int y = cin.nextInt();
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i <= 12; i++)
			map.put(i, 1);
		map.put(2, 2);
		map.put(4, 3);
		map.put(6, 3);
		map.put(9, 3);
		map.put(11, 3);
		if (map.get(x) == map.get(y))
			cout.println("Yes");
		else
			cout.println("No");
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new IllegalStateException(e);
				}
			return st.nextToken();
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
			return str;
		}

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

}


Measured memory_bytes: 21204
//This code was made by Chinese_zjc_.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
int n,cnt[16],x[16][16],y[16][16],w[16][16],ans;
bool yes;
void dfs(int now,int g)
{
	if(now>n)
	{
		ans=max(g,ans);
	}
	if(g+n-now<ans)
	{
		return;
	}
	for(int i=1;i<=n;++i)
	{
		w[now][i]=w[now-1][i];
	}
	//false
	if(w[now][now]!=1)
	{
		int tmp=w[now][now];
		w[now][now]=-1;
		dfs(now+1,g);
		w[now][now]=tmp;
	}
	//true
	if(w[now][now]!=-1)
	{
		yes=true;
		w[now][now]=1;
		for(int i=1;i<=cnt[now];++i)
		{
			if(w[now][x[now][i]]*-1==y[now][i])
			{
				yes=false;
				break;
			}
		}
		if(yes)
		{
			for(int i=1;i<=cnt[now];++i)
			{
				w[now][x[now][i]]=y[now][i];
			}
			dfs(now+1,g+1);
		}
	}
}
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>cnt[i];
		for(int j=1;j<=cnt[i];++j)
		{
			cin>>x[i][j]>>y[i][j];
			if(!y[i][j])
			{
				--y[i][j];
			}
		}
	}
	dfs(1,0);
	cout<<ans;
	return 0;
}


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

typedef long long int ll;
typedef string str;

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t=0,n,m,k,i,a,b,j;
	cin >> n >> m >> k;
	for(i=n;i<=m;i++)
	{
		if(i%k==0)
			t++;
	}
	cout << t << "\n";
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#define sz(x) ((ll)(x).size());
#define pb push_back;
#define all(x) (x).begin(),(x).end()
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N; cin >> N;
    if(N%10 == 3){
        cout << "bon";
    }else if(N%10 == 0||N%10 == 1||N%10 == 6||N%10 == 8){
        cout << "pon";
    }else{
        cout << "hon";
    }
}

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

public class Main {
	private static int n;

	public static void main(String args[]) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		n = Integer.parseInt(br.readLine());
		String line;
		for (int i = 0; i < n; i++) {
			line = br.readLine();
			char[] s = line.toCharArray();
			char[] rev = new char[s.length];
			Arrays.sort(s);
			for (int j = 0; j < s.length; j++) {
				rev[j] = s[s.length - j - 1];
			}

			int a = Integer.parseInt(String.valueOf(s));
			int b = Integer.parseInt(String.valueOf(rev));
			System.out.println(b - a);
		}

	}
}

Measured memory_bytes: 16868
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,Q,A,B,*X = map(int,read().split())

class MinSegTree():
    def __init__(self,N):
        self.Nelem = N
        self.size = 1<<(N.bit_length()) # 葉の要素数
        
    def build(self,raw_data):
        # raw_data は 0-indexed
        INF = 10**18
        self.data = [INF] * (2*self.size)
        for i,x in enumerate(raw_data):
            self.data[self.size+i] = x
        for i in range(self.size-1,0,-1):
            x = self.data[i+i]; y = self.data[i+i+1]
            self.data[i] = x if x<y else y
    
    def update(self,i,x):
        i += self.size
        self.data[i] = x
        i >>= 1
        while i:
            x = self.data[i+i]; y = self.data[i+i+1]
            self.data[i] = x if x<y else y
            i >>= 1
    
    def get_value(self,L,R):
        # [L,R] に対する値を返す
        L += self.size
        R += self.size + 1
        # [L,R) に変更
        x = 10**18
        while L < R:
            if L&1:
                y = self.data[L]
                if x > y: x = y
                L += 1
                
            if R&1:
                R -= 1
                y = self.data[R]
                if x > y: x = y
            L >>= 1; R >>= 1
        return x

INF = 10**18
dpL = MinSegTree(N+10); dpL.build([INF] * (N+10))
dpR = MinSegTree(N+10); dpR.build([INF] * (N+10))
dpL.update(A,0-A)
dpR.update(A,0+A)

prev_x = B
add = 0
for x in X:
    from_left = dpL.get_value(0,x) + x
    from_right = dpR.get_value(x,N+10) - x
    dist = x-prev_x if x>prev_x else prev_x-x
    y = from_left if from_left < from_right else from_right
    y -= dist
    dpL.update(prev_x,y-prev_x)
    dpR.update(prev_x,y+prev_x)
    add += dist
    prev_x = x

dp = [(x+y)//2 for x,y in zip(dpL.data[dpL.size:],dpR.data[dpR.size:])]
answer = min(dp) + add
print(answer)

Measured memory_bytes: 119824
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int martix[105][105];

int main()
{
	int n, id, d,v;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> id >> d;
		while (d--)
		{
			cin >> v;
			martix[id][v] = 1;
		}
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (j ==1)	cout << martix[i][j];
			else cout << ' ' << martix[i][j];
		}
		putchar('\n');
	}
    return 0;
}




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

int main() {
  string S;
  cin >> S;
  ll ans = 0;
  int w_count = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'W') {
      ans += (i - w_count);
      w_count++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+10;
vector<int>G[maxn];
priority_queue<int>P;
int main()
{
    int n,m,ans=0;scanf("%d%d",&n,&m);
    for(int i=1,x,y;i<=n;i++)
    {
        scanf("%d%d",&x,&y);
        G[x].push_back(y);
    }
    for(int i=1;i<=m;i++)
    {
        for(int j=G[i].size()-1;j>=0;j--)
        {
            P.push(G[i][j]);
        }
        if(!P.empty())
        {
            ans+=P.top();
            P.pop();
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 5632
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D: 2017-like Number
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_P = 100000;

/* typedef */

/* global variables */

bool primes[MAX_P + 1];
int cs[MAX_P + 1];

/* subroutines */

void gen_primes(int maxp) {
  memset(primes, true, sizeof(primes));
  primes[0] = primes[1] = false;

  int p;
  for (p = 2; p * p <= maxp; p++)
    if (primes[p])
      for (int q = p * p; q <= maxp; q += p) primes[q] = false;
}

/* main */

int main() {
  gen_primes(MAX_P);

  for (int i = 1; i <= MAX_P; i++)
    cs[i] = cs[i - 1] + ((primes[i] && primes[(i + 1) / 2]) ? 1 : 0);

  int q;
  scanf("%d", &q);

  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", cs[r] - cs[l - 1]);
  }
  return 0;
}


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

#define sz(s) (ll)(s.size())
#define all(x) (x.begin(), x.end())

#define pb push_back
#define pf push_front
#define F first
#define S second
#define ort1 exit(0);
#define nl endl
#define db double

#define TL clock() / (double)CLOCKS_PER_SEC
#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;


const double pi = acos(-1.0);
const double eps = 1e-9;
const int mod = 1e9 + 7;
const ll INF = 1e12 + 1;
const int N = 1e2 + 9;

int n;
int a[N];

int main()
{
    for(int i = 1; i <= 3; ++i){
        cin >> a[i];
    }

    sort(a + 1, a + 4);
    for(int i = 1; i <= 3; ++i){
        n += abs(a[i] - a[2]);
    }

    cout << n;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String str = sc.next();
		// スペース区切りの整数の入力
		
		String aa = str.substring(0,1);
		String cc = str.substring(2);
		cc =cc.substring(0, cc.length() -1);
		int indA = str.indexOf("A");
		int indC = str.indexOf("C");
		int lastIndA = str.lastIndexOf("A");
		int lastIndC = str.lastIndexOf("C");

		// System.out.println(indA);
		// System.out.println(indC);
		// System.out.println(lastIndA);
		// System.out.println(lastIndC);
		// 		System.out.println(indA==1);
		// System.out.println(cc.contains("C"));
		// System.out.println(lastIndA==indA);
		// System.out.println(lastIndC==indC);
		if(indA==0&&cc.contains("C")&&(lastIndA==indA)&&lastIndC==indC){
			boolean flag =false;
			String lowerStr=str.replace("A","a");
			lowerStr= lowerStr.replace("C","c");
			flag = isLower(lowerStr);
			// System.out.println(lowerStr);
			if(flag){
				System.out.println("AC");
			}else{
				System.out.println("WA");
			}
		}else{
			System.out.println("WA");
		}
	}

	public static boolean isLower(String str) {
		return str.equals(str.toLowerCase());
	}

}

Measured memory_bytes: 21972
n,m = map(int,input().split())
ans = [1] + [1]*n
if n == 1:
    print(1)
    exit()
for i in range(m):
    ans[int(input())] = 0
for i in range(n-2,-1,-1):
    if ans[i] == 0:
        continue
    ans[i] = (ans[i+1] + ans[i+2])%1000000007
print(ans[0])

Measured memory_bytes: 12480
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
int main()
{
fast;
    ll n,m;
    cin>>n>>m;
    if(m%2==1)
        cout<<"No";
    else
    {
        ll x=2*n-(m/2);
        if(x>=0 && x<=n)
            cout<<"Yes";
        else
            cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3656
/* atcoder */
#include "bits/stdc++.h"
using namespace std;

/* typedef */
/* long系 */
typedef long long ll;   // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vi;                    // intのvector
typedef vector<double> vd;                 // doubleのvector
typedef vector<ll> vll;                    // llのvector
typedef vector<ld> vld;                    // ldのvector
typedef vector<vector<int>> vvi;           // intの2次元vector
typedef vector<vector<double>> vvd;        // doubleの2次元vector
typedef vector<vector<ll>> vvll;           // llの2次元vector
typedef vector<vector<ld>> vvld;           // ldの2次元vector
typedef vector<pair<int, int>> vi_i;       // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l;         // l_lのvector
typedef vector<pair<ld, ld>> vld_ld;       // ld_ldのvector
typedef vector<string> vs;                 // stringのvector
/* pair系 */
typedef pair<int, int> i_i;       // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l;         // ll同士のpair
typedef pair<ld, ld> ld_ld;       // ld同士のpair

/* define */
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1))             // 円周率pi

/* stringstream */
stringstream ss;
stringstream init_ss; // save default formatting

/* upper, lower */
struct ToUpper
{
    char operator()(char c)
    {
        return toupper(c);
    }
};
struct ToLower
{
    char operator()(char c)
    {
        return tolower(c);
    }
};

/* next combination */
int next_combination(int sub)
{
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}

/* main */
void Main(void)
{
    int n, k;
    cin >> n >> k;
    vi p;
    p.resize(n);
    for (int rv = 0; rv < n; rv++)
    {
        cin >> p[rv];
    }
    sort(all(p));
    ll ans = accumulate(p.begin(), p.begin() + k, 0);
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();

    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(void){

    int H, W;
    vector<string> S;
    vector<vector<int>> lenLightV(2000, vector<int>(2000));
    vector<vector<int>> lenLightH(2000, vector<int>(2000));
    string strbuf;
    
    cin >> H >> W;

    for(int i=0; i<H; i++){
        cin >> strbuf;
        S.push_back(strbuf);
    }

    int startW = -1;
    int endW = -1;

    for(int i=0; i<H; i++){
        for(int j=0; j<=W; j++){
            if(j == W){
                if(startW != -1){
                    endW = j;
                    for(int k=startW; k<endW; k++){
                        lenLightH[i][k] = endW-startW;
                    }
                    startW = -1;
                }
                continue;
            }
            if((startW == -1)&&(S[i][j] == '.')){
                startW = j;
            }else if ((startW != -1)&&S[i][j] != '.'){
                endW = j;
                for(int k=startW; k<endW; k++){
                    lenLightH[i][k] = endW-startW;
                }
                startW = -1;
            }
            if (S[i][j] != '.'){
                lenLightH[i][j] = 0;
            }
        }
    }

    int startH = -1;
    int endH = -1;

    for(int i=0; i<W; i++){
        for(int j=0; j<=H; j++){
            if(j == H){
                if(startH != -1){
                    endH = j;
                    for(int k=startH; k<endH; k++){
                        lenLightV[k][i] = endH-startH;
                    }
                    startH = -1;
                }
                continue;
            }
            if((startH == -1)&&(S[j][i] == '.')){
                startH = j;
            }else if ((startH != -1)&&S[j][i] != '.'){
                endH = j;
                for(int k=startH; k<endH; k++){
                    lenLightV[k][i] = endH-startH;
                }
                startH = -1;
            }
            if (S[j][i] != '.'){
                lenLightV[j][i] = 0;
            }
        }
    }

    int res = 0;

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            res = max(res, lenLightH[i][j]+lenLightV[i][j]-1);
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 35712
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
	char a[101];
	int s,cn=0,i,f;
	while (cin >> a) {
     s=strlen(a); f=0;
     for (i=0;i<(s+1)/2;i++) if (a[i]!=a[s-1-i]) f=1;
	 if (f==0) cn++;
	}
	cout << cn << endl;
	return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl;
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define MOD 1000000007
#define FOR(i, n) for(ll i = 0; i < n; i++)
using namespace std;
const long long INF = 3*1e18;

int main() {
    ios::sync_with_stdio(0);    
    cin.tie(0);
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(ll i = 0; i < N; i++) cin >> A[i];
    ll cost1 = abs(A[1] - A[0]);
    ll cost2 = min(abs(A[2] - A[1]) + cost1, abs(A[2] - A[0]));
    if(N == 2) {
        cout << cost1 << "\n";
        return 0;
    }
    if(N == 3){
        cout << cost2 << "\n";
        return 0;
    }
    for(ll i = 3; i < N; i++){
        ll cost = min(abs(A[i] - A[i-1]) + cost2, abs(A[i] - A[i-2]) + cost1);
        cost1 = cost2;
        cost2 = cost;
    }
    cout << cost2 << "\n";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll cap[105][105]; int par[105];
vector<int>adj[105];
const ll inf=1e12;
ll bfs(){
	memset(par, -1, sizeof(par));
	par[0]=-2;
	queue<pair<int, ll> >q;
	q.push({0, inf});
	for(;!q.empty();q.pop()){
		int nw=q.front().first; ll flow=q.front().second;
	//	cout<<nw<<" "<<flow<<" "<<par[nw]<<endl;
		for(int nx:adj[nw]) if(par[nx]==-1 && cap[nw][nx]>0){
			par[nx]=nw;
			ll nflw=min(flow, cap[nw][nx]);
		//	for(int i=1; i<=6; i++) cout<<par[i]<<" "; cout<<endl;
			if(nx==101) return nflw;
			q.push({nx, nflw});
		}
	}
	return 0;
}
ll maxflow(){
	ll flow=0, nflw;
	for(nflw=bfs();nflw;nflw=bfs()){
		flow+=nflw;
		int nw=101;
		while(nw!=0){
			int bf=par[nw];
			cap[bf][nw]-=nflw;
			cap[nw][bf]+=nflw;
			nw=bf;
		//	cout<<nw<<" "<<par[nw]<<endl;
		}
	}
	return flow;
}
void addedge(int u, int v, ll cp){
	cap[u][v]=cp;
	adj[u].push_back(v);
	adj[v].push_back(u);
}
int n, a[105];
int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	ll optimal=0ll;
	for(int i=1; i<=n; i++){
		if(a[i]>0){
			optimal+=a[i];
			addedge(i, 101, 1ll*a[i]);
		}else{
			addedge(0, i, -1ll*a[i]);
		}
		for(int j=2*i; j<=n; j+=i)
			addedge(i, j, inf);
	}
	/*for(int i=0; i<=101; i++) if(adj[i].size()){
		for(int j:adj[i]){
			if(cap[i][j]){
				printf("%d %d %lld\n", i, j, cap[i][j]);
			}
		}
	}*/
	ll mincut=maxflow();
	printf("%lld\n", optimal-mincut);
	return 0;
}//

Measured memory_bytes: 3888