akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

const double pi = 3.14159265358979323846;
const int mod = 1000000007;

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

  for(int i=0; i<S.size()-8; i++) cout << S[i];
  cout << endl;

  return 0;
}


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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

string s;

string tmp = "357";

int dfs(int idx, bool zero, string str){
	if(idx == s.size()){
		bool ans = !zero;
		ans = (ans && str <= s);
		ans = (ans && str.find('3') != string::npos);
		ans = (ans && str.find('5') != string::npos);
		ans = (ans && str.find('7') != string::npos);
		return ans == 1;
	}

	int ans = 0;
	str.push_back('0');
	if(zero) ans += dfs(idx+1, true, str);

	for(int i = 0;i < tmp.size();i++){
		str[idx] = tmp[i];
		ans += dfs(idx+1, false, str); 
	}

	return ans;
}

signed main(){

	cin >> s;

	cout << dfs(0, true, "") << endl;

	return 0;
}


Measured memory_bytes: 256
from itertools import accumulate 
n,q = map(int,input().split())
s = input()
l = [list(map(int,input().split())) for _ in range (q)]
flg =[]
for i in range(n-1):
  if s[i:i+2]=="AC":
    flg.append(1)
  else:
    flg.append(0)
flg2 = [0]+flg
flg2 = list(accumulate(flg2))
for i in l:
  print(flg2[i[1]-1]-flg2[i[0]-1])

Measured memory_bytes: 33160
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let n: i32 = read();

    let mut set: HashSet<String> = HashSet::new();
    for i in 0..n {
        set.insert(read());
    }
    println!("{}", set.len());
}


Measured memory_bytes: 15236
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;
#pragma endregion

#pragma region const
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#pragma endregion

#pragma region util
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}
#pragma endregion

#pragma region init
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

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


	REP(i, SIZE(S))
	{
		if (S == T)
		{
			cout << "Yes" << endl;
			return 0;
		}
		S = S.substr(SIZE(S) - 1, 1) + S.substr(0, SIZE(S) - 1);
	}
	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

const int maxn = 2e5 + 5;

struct X{
	int ans,pos;
}a[maxn];

bool cmp(X x,X y){
	if(x.ans == y.ans) return x.pos < y.pos;
	return x.ans < y.ans;
}

int k[maxn];

int main(){
	int n; scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&a[i].ans);
		a[i].pos = i;
	}
	sort(a + 1,a + 1 + n,cmp);
	for(int i = 1;i <= n;i++){
		int l = i - 1,r = n - i;
		int cnt = (n) / 2;
		if(cnt <= l){
			k[a[i].pos] = a[cnt].ans;
		}
		else{
			k[a[i].pos] = a[cnt + 1].ans;
		}
	}
	for(int i = 1;i <= n;i++){
		printf("%d\n",k[i]);
	}
}


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

int main(){
	int a[4],b[4],hit=0,brow=0;
		while(cin>>a[0]>>a[1]>>a[2]>>a[3]){
			hit=0;
			brow=0;
		for(int j=0;j<4;j++)cin>>b[j];
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				if(i==j&&a[i]==b[j])hit++;
				else if(a[i]==b[j])brow++;
			}
		}
		cout<<hit<<' '<<brow<<endl;
}
}

Measured memory_bytes: 1160
import java.util.Scanner;
import java.util.InputMismatchException;

class Main {
   public static void main(String args[]) {
      int x=0 ,y=0, z;
      Scanner scanner = new Scanner(System.in);
      x = scanner.nextInt();
      y = scanner.nextInt();
      z = scanner.nextInt();
      scanner.close();
      int temp;
      temp = z;
      for (int i=1; i<11; i++) {
         temp = x*temp-y;
         System.out.println(temp);
      }

   }
}


Measured memory_bytes: 21972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            String S = in.next();
            Set<Character> abc = new HashSet<>();
            for (char c : S.toCharArray()) {
                abc.add(c);
            }
            if (abc.size() == 3) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
    }
}

Measured memory_bytes: 21460
#include<iostream>
using namespace std;
int main(void)
{
  int n, k, m, l;
  while(cin >> n, n){
    m = l = 0;
    for(int i = 0;i < n; i++){
      cin >> k;
      if(k >= 2) m++;
      else if(k >= 1) l++;
    }
    if(m) cout << m + l + 1 << endl;
    else cout << "NA" << endl;
  }
}


Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    string s;
    vector<char> lft, rit;
    int q;
    bool flg = true;
    cin >> s >> q;
    while(q--){
        int f;
        cin >> f;
        if(f == 1){
            flg = !flg;
        }else{
            char c;
            cin >> f >> c;
            if((f==1&&flg) || (f==2&&!flg)){
                lft.push_back(c);
            }else{
                rit.push_back(c);
            }
        }
        
    }
    if(flg){
        for(int i=lft.size()-1;i>=0;i--){
            cout << lft[i];
        }
        cout << s;
        for(int i=0;i<rit.size();i++){
            cout << rit[i];
        }
    }else{
        for(int i=rit.size()-1;i>=0;i--){
            cout << rit[i];
        }
        for(int i=s.length()-1;i>=0;i--){
            cout << s[i];
        }
        for(int i=0;i<lft.size();i++){
            cout << lft[i];
        }
    }
    
    cout << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	ll a, b, n;
	cin >> a >> b >> n;
	ll x;
	if (n < b) x = n;
	else x = b-1;
	ll r = (a*x)/b - a*(x/b);
	cout << r<< endl;
	return 0;
}



Measured memory_bytes: 3620
using System;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Collections.Generic;
using System.Linq;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = myRead.readStr();
            var a = 0;
            for (int i = 0; i < n.Length; i++)
            {
                a += int.Parse(n[i].ToString());
            }
            var ans = a % 9 == 0 ? "Yes" : "No";
            WriteLine(ans);
        }
    }
    public static class myRead
    {
        public static int readInt() { return int.Parse(ReadLine()); }
        public static long readLong() { return long.Parse(ReadLine()); }
        public static string readStr() { return ReadLine(); }
        public static int[] readIntArray() { return ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        public static long[] readLongArray() { return ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        public static string[] readStrArray() { return ReadLine().Split(' '); }
    }


    public static class MyMath
    {
        public static long Factorical(long n)
        { return n <= 1 ? 1L : n * Factorical(n - 1); }
        public static long Permutation(long n, long m)
        { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); }
        public static long Combination(long n, long m)
        { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); }
        public static long Gcd(long n, long m)
        { return n % m == 0 ? m : Gcd(m, n % m); }
        public static long Lcm(long n, long m)
        { return n * m / Gcd(n, m); }
        public static long Pow(long n, long m)
        { return m == 0 ? 1L : m == 1 ? n : n * Pow(n, m - 1); }
    }


}

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

using namespace std;

using ll = long long;
template<class T> using v = vector<T>;

void bfs(ll node, ll N, const v<v<ll>> &edge, v<ll> &dist)
{
    v<bool> visit(N+1);
    queue<ll> q;
    q.push(node);
    dist.clear();
    dist.resize(N+1);
    
    dist[node] = 0;
    while(!q.empty()){
        node = q.front();
        q.pop();
        visit[node] = true;
        
        for(const auto n : edge[node]){
            if(visit[n]) continue;
            q.push(n);
            dist[n] = dist[node] + 1;
        }
    }
}

int main()
{
    ll N;
    cin >> N;
 
    if(N % 2 == 1){ cout << 0 << endl; return 0; }
    
    ll bunbo = 5;
    ll ans = 0;
    while(N >= bunbo * 2){
        ans += N / (bunbo * 2);
        bunbo *= 5;
    }
    cout << ans << endl;
}


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

using namespace std;
#define ll long long

int main()
{
  ll n;
  cin>>n;
  ll sum=0;
  for(ll i=1; i<=n; i++){
    if(i%3!=0 and i%5!=0)sum += i;
  }
  cout<<sum<<endl;
  
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define ll long long
#define INF 2000000000
#define INF2 2000000000000000000
 
using namespace std;

const int mod = 998244353;


int main() {
    
    IOS;

   	int n,k;
   	cin >> n >> k;
   	vector<pair<int,int>>arr;
   	int ans[n + 1];
   	memset(ans, 0, sizeof(ans));
   	for(int i = 1; i <= k; i++) {
   		pair<int,int>val;
   		cin >> val.first  >> val.second;
   		arr.push_back(val);
   	}
   	sort(arr.begin(), arr.end());

   	int ind = 0;
   	while(ind < arr.size()) {
   		if(ind && arr[ind].first == arr[ind - 1].second + 1) {
   			arr[ind - 1].second = arr[ind].second;
   			arr.erase(arr.begin() + ind);
   		} else
   			ind++;
   	}

   	ans[n] = 1; 
   	int sum = 0;
   	for(int i = n - 1; i >= 1; i--) {
   		for(auto range: arr) {
   			if(i + range.first <= n) {
   				sum += ans[i + range.first];
   				sum %= mod;
   			}
   			if(i + range.second + 1 <= n) {
   				sum -= ans[i + range.second + 1];
   				if(sum < 0)
   					sum += mod;
   			}
   		}
   		ans[i] = sum;
   	}
   	cout << ans[1];

}

Measured memory_bytes: 4424
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
  int N;
  cin >> N;
  map<int, int> A;
  rep(i, N)
  {
    int a;
    cin >> a;
    A[a] += 1;
  }

  for (const auto &x : A)
  {
    int v = x.second;
    if (v > 1)
    {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

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

int main() {
    char a;
    cin >> a;
    if (a >= 'a' && a <= 'z') {
        cout << "a" << endl;
    } else if (a >= 'A' && a <= 'Z') {
        cout << "A" << endl;
    }
}

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

int main(){
  int h,w;
  cin >>h>>w;
  char c[110][110];
for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
cin >>c[i][j];

for(int i=0;i<2*h;i++){
for(int j=0;j<w;j++){
  int k=(i/2);
  cout<<c[k][j];
}
cout<<endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const int INF = 0x3f3f3f3f;
ll max(ll a, ll b){return a > b ? a : b;}
ll min(ll a, ll b){return a < b ? a : b;}
 
int a[101];
int dp[100010];
int n, k;
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
    }
    for(int i=k; i>k-a[1]; i--)
    {
        dp[i]=1;
    }
    for(int i=k-a[1]; i>=0; i--)
    {
        bool ok=0;
        for(int j=1; j<=n; j++)
        {
            if(i+a[j]>k)
            {
                break;
            }
            else if(dp[i+a[j]]==1)
            {
                dp[i]=2;
                break;
            }
        }
        if(!dp[i]) dp[i]=1;
    }
    for(int i=1; i<=n; i++)
    {
        if(dp[a[i]]==1)
        {
            cout << "First";
            return 0;
        }
    }
    cout << "Second";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<sstream>

using namespace std;

#define open  freopen("input.txt","r",stdin)
#define close  freopen ("output.txt","w",stdout)
#define db double
#define ll long long
#define llu unsigned long long
#define loop(i,a,n) for(int i=a;i<=n;i++)
#define sf scanf
#define sf1(a) sf("%d",&a)
#define sf2(a,b) sf("%d %d",&a,&b)
#define sf3(a,b,c) sf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d) sf("%d %d %d %d",&a,&b,&c,&d)
#define sfd(a) sf("%lf",&a)
#define sfd2(a,b) sf("%lf %lf",&a,&b)
#define sfl1(a) sf("%lld",&a)
#define sfl2(a,b) sf("%lld %lld",&a,&b)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pf printf
#define pfi(x) pf("%d",x)
#define pfl(x) pf("%lld",x)
#define NL puts("")
#define bug pf("here is bug\n")
#define pft(tc) printf("Case %d:",tc++)
#define PI (2.0*acos(0.0))
//#define PI acos(-1.0)
#define mem(a,v) memset(a,v,sizeof a)
#define endl '\n'
#define pb push_back
#define xx first
#define yy second
#define mp make_pair
#define all(a) a.begin(),a.end()


template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T lcm(T a,T b)
{
    return (a/gcd(a,b))*b;
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}   // M is prime}
template <class T> inline T bpow(T p,T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}




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

#define linf 3000000000000000000ll
#define inf 999999999
#define MX 1000006
#define mod (ll) 1000000007
#define eps 1e-6
#define ub upper_bound // return the right most index of x<val
#define lb lower_bound // return the right most index of x<=val



struct data
{
    int ele1,ele2,ele3;
    data() {}
    data(int a,int b,int c)
    {
        ele1=a,ele2=b,ele3=c;
    }
    bool friend operator<(data a,data b)
    {
        return  a.ele1> b.ele1;// sort decreasingly but increasingly for priority_queue
    }
};


int n,m,k;
ll N,M,K;
int cnt[55][30];

int main()
{
    int t,tc=1;
	string a,b;
	sf1(n);
	for(int i=1;i<=n;i++){
		cin>>a;
		int l=a.length();
		for(int j=0;j<l;j++){
			int p=a[j]-'a';
			cnt[i][p]++;
		}
	}
	for(int i=0;i<26;i++){
		int mx=100;
		for(int j=1;j<=n;j++){
			mx=min(mx,cnt[j][i]);
		}
		for(int j=1;j<=mx;j++){
			pf("%c",i+'a');
		}
	}
	NL;
	

    return 0;
}

/*




*/


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll N, K;
int A[2005];

int main(){
  scanf("%lld%lld", &N, &K);
  for (int i = 0; i < N; i++) scanf("%d", A + i);

  ll ans = 0;
  for (int i = 0; i < N; i++){
    ll a = 0, b = 0;
    for (int j = 0; j < i; j++){
      if (A[j] < A[i]) a++;
    }
    for (int j = i + 1; j < N; j++){
      if (A[i] > A[j]) b++;
    }
    ans += K * b; ans %= MOD;

    ll now = K * (K - 1) / 2; now %= MOD;
    now *= a + b; now %= MOD;
    ans += now; ans %= MOD;
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 3832
def solve():
    N = int(input())
    f = lambda x,y,z:x*x+y*y+z*z+x*y+y*z+z*x
    MAX = 10000

    ans = [0]*(MAX+1)
    for x in range(1, 101):
        if f(x,0,0)>MAX:
            break
        for y in range(1, 101):
            if f(x,y,0)>MAX:
                break
            for z in range(1, 101):
                if f(x,y,z)>MAX:
                    break
                ans[f(x,y,z)]+=1
    for i in range(1, N+1):
        print(ans[i])

if __name__ == "__main__":
    solve()


Measured memory_bytes: 74360
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let s:String = read();
    let t:String = read();

    for i in 0..n {
        if s[i..] == t[..n-i] {
            println!("{}", i + n);
            return
        }
    }
    println!("{}", n*2);
}


Measured memory_bytes: 2092
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please



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


	ll N, K;
	cin >> N >> K;

	if (N >= K) {
		N -= (N - 1) / K * K;

		ce(N);
	}
	ll kotae = min(N, abs(N - K));

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int ans = 0;

	scanf("%d %d %d", &a, &b, &c);
	if (a == b || a == c) ans++;
	if (b == c) ans++;
	printf("%d\n", 3-ans);

	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

const int INF = 100000;
int L[3];
vector<int> len(8);
int n;

int compute(vector<int> B) {
  int res = 0;
  int sl[3] = {0, 0, 0};
  int cnt[3] = {0, 0, 0};
  rep(i, n) {
    if(B[i] == 3) continue;
    sl[B[i]] += len[i];
    cnt[B[i]]++;
  }

  bool ok = true;
  rep(bamboo, 3) if(cnt[bamboo] == 0) ok = false;
  if(!ok) return INF;

  rep(bamboo, 3) {
    res += abs(L[bamboo] - sl[bamboo]);
    res += 10 * (cnt[bamboo] - 1);
  }
  return res;
}

ll dfs(int depth, vector<int> B) {
  if(depth == n) return compute(B);
  ll res = INF;
  rep(i, 4) {
    B[depth] = i;
    res = min(res, dfs(depth + 1, B));
  }
  return res;
}

int main() {
  cin >> n >> L[0] >> L[1] >> L[2];
  len.resize(n);
  rep(i, n) cin >> len[i];
  vector<int> B(n);
  int ans = dfs(0, B);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define sp ' '
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

const long long int MOD = 1e9 + 7;
const long long int INF = 2e9 + 13;
const long long int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;

vector<vector<bool>> grid;
map<ll, bool> wall;
vvll AdjList;
ll H, W;

ll edgeno(ll r, ll c){ return r*W + c; }
void create_edge(void){
    for(ll i = 0; i < H; ++i){
        for(ll j = 0; j < W; ++j){
            if(!grid[i][j]) continue;
            if(i+1 < H){
                if(grid[i+1][j]){
                    AdjList[edgeno(i, j)].pb(edgeno(i+1, j));
                    AdjList[edgeno(i+1, j)].pb(edgeno(i, j));
                }
            }
            if(j+1 < W){
                if(grid[i][j+1]){
                    AdjList[edgeno(i, j)].pb(edgeno(i, j+1));
                    AdjList[edgeno(i, j+1)].pb(edgeno(i, j));
                }
            }
        }
    }
}

int main(int argc, char **argv){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    cin >> H >> W;
    grid.resize(H, vector<bool>(W, false));
    for(ll i = 0; i < H; ++i)
        for(ll j = 0; j < W; ++j){ char c; cin >> c; grid[i][j] = (c == '.'); }
    
    AdjList.resize(H*W);
    create_edge();

    vll dist(H*W, -1);
    queue<pll> bfs;

    ll ans = 0;
    for(ll i = 0; i < H; ++i){
        for(ll j = 0; j < W; ++j){
            if(!grid[i][j]) continue; 
            vector<bool> visited(H*W, false);
            bfs.push(mp(edgeno(i, j), 0));
            visited[edgeno(i, j)] = true;
            while(!bfs.empty()){
                pll tp = bfs.front(); bfs.pop();
                ans = max(ans, tp.nd);
                for(ll n = 0; n < AdjList[tp.st].size(); ++n){
                    ll v = AdjList[tp.st][n];
                    if(!visited[v]){
                        visited[v] = true;
                        bfs.push(mp(v, tp.nd+1));
                    }
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

//cikisir



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Data_Nerd ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define files freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
using ll = long long;

struct point {
	int x, y;
};

int main() {
	Data_Nerd
	point a, b; scanf("%d%d%d%d", &a.x, &a.y, &b.x, &b.y);

	point c, d;

	int deltaX = b.x - a.x;
	int deltaY = b.y - a.y;

	c.x = b.x - deltaY;
	c.y = b.y + deltaX;

	d.x = a.x - deltaY;
	d.y = a.y + deltaX;

	printf("%d %d %d %d", c.x, c.y, d.x, d.y);
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

class UnionFind{
private:
  vector<ll> Parent; 
 public:
  UnionFind(ll N){
    Parent = vector<ll>(N, -1);
  }
  
  ll root(ll A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  ll size(ll A){
    return -Parent[root(A)]; 
  }
  
  bool connect(ll A, ll B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
  
  bool isSame(ll A, ll B){
    return root(A) == root(B);
  }
};

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,m; cin>>n>>m;
  vpll ab(m);
  rep(i,m){
    ll a,b; cin>>a>>b; a--,b--;
    ab[i]={a,b};
  }
  
  ll ans=0;
  rep(i,m){
    UnionFind uf(n);
    rep(j,m){
      if(i==j) continue;
      uf.connect(ab[j].first,ab[j].second);
    }
    rep(j,n){
      if(!uf.isSame(0,j)){
        ans++;
        break;
      }
    }
  }
  cout<<ans<<endl;
  
}


Measured memory_bytes: 256
/* Priyansh Agarwal*/
#include<bits/stdc++.h>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define nline "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define debug(x) cout << #x << " " << x <<endl;
#define set_bits __builtin_popcount
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod)
{ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
bool revsort(ll a, ll b) {return a > b;}
void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
ll combination(ll n, ll r, ll m, ll* fact) {ll val1 = fact[n]; ll val2 = mminvprime(fact[r], m); ll val3 = mminvprime(fact[n - r], m); return ((val1 * val2) % m * val3) % m;}
void google(int t) {cout << "Case #" << t << ": ";}
/*--------------------------------------------------------------------------------------------------------------------------*/
int main()
{
	fastio();
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
	freopen("Error.txt", "w", stderr);
#endif
	int n;
	cin >> n;
	ll sum1 = 0;
	ll arr[n];
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if (i % 2 == 0)
			sum1 += arr[i];
		else
			sum1 -= arr[i];
	}
	ll x = sum1 / 2;
	ll ans[n];
	for (int i = 0; i < n; i++)
	{
		ans[i] = 2 * x;
		arr[i] -= x;
		arr[(i - 1 + n) % n] -= x;
		x = arr[i];
	}
	for (int i = 0; i < n; i++)
		cout << ans[i] << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 5228
program triangle
  implicit none
  integer(8) :: s, h, w, a, b, d
  integer(8) :: x1, y1, x2, y2, x3, y3, i
  read(*,*) s
  x1 = 0_8
  y1 = 0_8
  h = int(ceiling(sqrt(real(s,8))),8)
  w = h
  d = h*w-s
  a = 0_8
  b = 0_8
  if (d > 0_8) then
    a = int(floor(sqrt(real(d,8))),8)
    do while (a > 0_8)
      if (mod(d,a) == 0_8) exit
      a = a-1_8
    end do
    b = d/a
  end if
  x2 = a
  y2 = h
  x3 = w
  y3 = b
  write(*,'(i0,x,i0,x,i0,x,i0,x,i0,x,i0)') x1, y1, x2, y2, x3, y3
  stop
end program triangle

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
#include <stack>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;
static const ll INF = 1e18;

vector<ll> dx = {0, -1, 0, 1};
vector<ll> dy = {-1, 0, 1, 0};


void Main(){
    ll H, W, K;
    cin >> H >> W >> K;

    ll sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    -- sx;
    -- sy;
    -- tx;
    -- ty;

    
    vector<string> field(H);
    rep(i, H){
        cin >> field[i];
    }
    vector<ll> dist(H*W*4, INF);

    auto toid = [&](ll x, ll y, ll nd){
        return x * W * 4 + y * 4 + nd;
    };

    auto mod_ceil = [&](ll d){
        return (d + K - 1) / K * K;
    };

    queue<pll> Q;

    auto push = [&](int x, int y, int v, ll d){
        ll id = toid(x, y, v);
        if(d >= dist[id]) return;
        dist[id] = d;
        Q.emplace(d, id);
    };

    rep(v, 4){
        push(sx, sy, v, 0);
    }
    while(!Q.empty()){
        ll d = Q.front().first;
        ll id = Q.front().second;
        Q.pop();
        if(dist[id]!=d) continue;

        ll i = id / W / 4;
        ll j = id / 4 % W;
        ll v = id  % 4;
        rep(nv, 4){
            push(i, j, nv, d);
        }
        rep(nv, 4){
            for(ll nk=1;nk<=K;nk++){
                ll ni = i + dx[nv] * nk;
                ll nj = j + dy[nv] * nk;
                // cout << "ni,nj = " << ni << "," <<nj<<endl; 

                if(ni < 0 || ni >= H || nj < 0 || nj >= W || field[ni][nj]=='@'){
                    break;
                }
                ll nid = toid(ni, nj, nv);
                if(d+1>dist[nid]) break;
                if(field[ni][nj] == '.'){
                    push(ni, nj, nv, d+1);
                }
            }

        }

    }
    
    ll ans = INF;
    rep(v, 4){
        ans = min(ans, dist[toid(tx, ty, v)]);
    }
    if(ans == INF){
        cout << "-1" <<endl;
    }else{
        cout << ans << endl;
    }



}

int main(){
    Main();
}

Measured memory_bytes: 41028
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <iterator>
#include <random>
#include <fstream>
#include <chrono>
#include <math.h>
#include <cctype>
using namespace std;
#define int long long
#define forn(i, n) for (int i = 0; i < n; ++i)
const int mod = 1e9 + 7;

int32_t main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    if(n % 1000 == 0)
        cout << 0 << "\n";
    else
        cout << 1000 * (n/1000 + 1) - n << "\n";
    //cout << n % 1000 << "\n";
    return 0;
}

Measured memory_bytes: 3660
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N >= M:
    print(0)
    exit()
X.sort()
a = []
for i in range(M-1):
    a.append(abs(X[i]-X[i+1]))
a.sort()
ans = 0
for i in range(M-N):
    ans += a[i]
print(ans)

Measured memory_bytes: 20560
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

cnt = 2 ** n

arr = []
for i in range(1, 1 + cnt):
    
    arr.append(int(arr_data[i][0]))
    
while len(arr)>1:
    
    arr_temp = []

    for i in range(0, len(arr), 2):

        if(arr[i] < arr[i + 1]):

            arr_temp.append(arr[i+1]-arr[i])

        elif(arr[i] > arr[i + 1]):

            arr_temp.append(arr[i]-arr[i+1])
            
        else:
            
            arr_temp.append(arr[i])
            

    arr=arr_temp
    
print(arr[0])

Measured memory_bytes: 82676
using System;


namespace ConsoleApplication18
{
    class Program
    {
        static void Main(string[] args)
        { 
            
            int n = int.Parse(Console.ReadLine());
             
            String[] str = Console.ReadLine().Split(' ');
            long[] a = new long[n];
            long max=long.MinValue, min=long.MaxValue, sum=0;
 
            for(int i=0;i<n;i++){
                a[i] =long.Parse(str[i]);
                sum = sum + a[i];
            }
            for (int i=0; i < n; i++)
            {
                if (n == 1) {
                    min=a[0];
                    max=a[0];
                    sum=a[0];
 
                }
                if (max < a[i])
                    {
                     max = a[i];
                  }
                if (min > a[i])
                  {
                       min = a[i];
                  }
                 
            }
            Console.WriteLine(min+" "  + max+" " + sum);
 
            


            }


        }
    }

Measured memory_bytes: 10016
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
int A[4009], dp[2009][2009];
char C[4009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    rep(i,N*2) cin>>C[i]>>A[i], A[i]--;
    
    VV black(N,V(N+1,0));
    VV white(N,V(N+1,0));
    
    V bnum(N,0), wnum(N,0);
    rep(k,N*2){
        char c=C[k];
        int num=A[k];
        V wsum(N+1,0), bsum(N+1,0);
        for(int l=N;l>0;l--){
            bsum[l-1]=bsum[l]+bnum[l-1];
            wsum[l-1]=wsum[l]+wnum[l-1];
        }
        for(int l=N+1;l>0;l--){
            if(c=='B') black[num][l-1]=wsum[l-1]+bsum[num+1];
            if(c=='W') white[num][l-1]=wsum[num+1]+bsum[l-1];
        }
        if(c=='B') bnum[num]++;
        else wnum[num]++;
    }
    
    rep(i,2009)rep(j,2009) dp[i][j]=INF;
    dp[0][0]=0;
    rep(i,N+1)rep(j,N+1){
        if(i<N) dp[i+1][j]=min(dp[i+1][j],dp[i][j]+black[i][j]);
        if(j<N) dp[i][j+1]=min(dp[i][j+1],dp[i][j]+white[j][i]);
    }
    cout1(dp[N][N]);
}

Measured memory_bytes: 47488
#include<bits/stdc++.h>
using namespace std;
int main() {

	string s, t;
	cin >> s >> t;

	//s昇順　t降順

	/*vector<int> sa(s.length);
	vector<int> ta(t.length);

	for (int i = 0; i < s.length(); i++)
	{
		sa[i] = (int)s[i];
	}
	for (int i = 0; i < t.length(); i++)
	{
		ta[i] = (int)t[i];
	}
*/
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), std::greater<>());
	bool Yes = false;
	for (int i = 0; i < t.length(); i++)
	{
		if (s[i] < t[i]) {
			Yes = true;
			break;
		}
		else if(s[i] > t[i]) {
			Yes = false;
			break;
		}
	}

	if( Yes )cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
P = []
S = []
result = {}
num_result = {}

for i in range(M):
    p,s = map(str, input().split())
    P.append(int(p))
    S.append(s)

ac = 0
wa = 0

for i in range(M):
    if S[i] == 'AC':
        if P[i] in result:
            if result[P[i]] == 'WA':
                ac += 1
                result[P[i]] = 'AC'
        else:
            result[P[i]] = 'AC'
            ac += 1
    elif S[i] == 'WA':
        if P[i] in result:
            if result[P[i]] == 'WA':
                num_result[P[i]] += 1
        else:
            result[P[i]] = 'WA'
            num_result[P[i]] = 1

for item in num_result:
    if result[item] != 'WA':
        wa += num_result[item]

print('{} {}'.format(ac,wa))

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

long X[200010], Y[200010];

int main() {
  int N; cin >> N;
  for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];
  long max_a, min_a, max_b, min_b;
  max_a=min_a=X[0]+Y[0];
  max_b=min_b=Y[0]-X[0];
  for (int i = 0; i < N; i++) {
    max_a = max(max_a, X[i]+Y[i]);
    min_a = min(min_a, X[i]+Y[i]);
    max_b = max(max_b, Y[i]-X[i]);
    min_b = min(min_b, Y[i]-X[i]);
  }
  cout << max(max_a-min_a, max_b-min_b) << endl;
}

Measured memory_bytes: 6756
#include <stdio.h>

main ()

{
    int a,n,c,cc;
    scanf ("%d",&a);
    n=a/2;
    if (a%2==1)
    {
        c=n*(n+1);
        printf ("%d",c);
    }
    else if (a%2==0)
    {
        cc=n*n;
        printf ("%d",cc);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
 
const int INF = (int)(1e9);
 
void upd(int &x, int y) {
    x = min(x, y);
}
 
int main() {
 
 
    int n, m;
    while (cin >> n >> m) {
        vector<vector<int> > e(n, vector<int>(n, 0));
        for (int i = 0; i < m; i++) {
            int u, v, w;
            cin >> u >> v >> w;
            u--; v--;
            e[u][v] = e[v][u] = w;
        }
 
        int ans = INF;
        vector<vector<int> > dp(1 << n, vector<int>(n, INF));
        dp[1][0] = 0;
        for (int mask = 0; mask < (1 << n); mask++) {
            for (int last = 0; last < n; last++) {
                if (!(mask & (1 << last))) continue;
                if (dp[mask][last] == INF) continue;
                vector<int> cost(n);
                for (int nw = 0; nw < n; nw++) {
                    for (int i = 0; i < n; i++) if ((mask & (1 << i)) && i != last) cost[nw] += e[nw][i];
                }
                int rmask = ((1 << n) - 1) ^ mask;
                rmask ^= 1 << (n - 1);
                for (int x = rmask; x; x = (x - 1) & rmask) {
                    int cur = 0;
                    for (int i = 0; i < n; i++) if (x & (1 << i)) cur += cost[i];
                    upd(dp[mask | x][last], dp[mask][last] + cur);
                }
 
                if (last == n - 1) continue;
                for (int nw = 0; nw < n; nw++) {
                    if (mask & (1 << nw)) continue;
                    if (e[last][nw] == 0) continue;
                    int cost = 0;
                    for (int i = 0; i < n; i++) if ((mask & (1 << i)) && i != last) cost += e[nw][i];
                    upd(dp[mask | (1 << nw)][nw], dp[mask][last] + cost);
                }
            }
        }
        ans = dp[(1 << n) - 1][n - 1];
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3584
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

typedef long long LL;

const int N=105;
const int MOD=1000000007;

int n,f[N][N],h[N],w[N],m;

int ksm(int x,int y)
{
	if (y<0) return 1;
	int ans=1;
	while (y)
	{
		if (y&1) ans=(LL)ans*x%MOD;
		x=(LL)x*x%MOD;y>>=1;
	}
	return ans;
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&h[i]),w[++m]=h[i];
	std::sort(w+1,w+m+1);
	m=std::unique(w+1,w+m+1)-w-1;
	for (int i=1;i<=n;i++) h[i]=std::lower_bound(w+1,w+m+1,h[i])-w;
	f[0][0]=1;
	for (int i=1;i<=n;i++)
	{
		for (int j=h[i]+1;j<=h[i-1];j++) (f[i][0]+=f[i-1][j]*2%MOD)%=MOD;
		(f[i][0]+=f[i-1][0]*2%MOD)%=MOD;
		for (int j=1;j<=h[i];j++)
		{
			f[i][j]=(LL)f[i-1][j]*ksm(2,w[h[i]]-w[h[i-1]])%MOD;
			if (h[i-1]>=j) continue;
			if (j>1) (f[i][j]+=(LL)f[i-1][0]*(ksm(2,w[j]-w[j-1])-1)%MOD*2%MOD*ksm(2,w[h[i]]-w[j])%MOD)%=MOD;
			else (f[i][j]+=(LL)f[i-1][0]*(ksm(2,w[j])-2)%MOD*ksm(2,w[h[i]]-w[j])%MOD)%=MOD;
		}
	}
	int ans=0;
	for (int i=0;i<=m;i++) (ans+=f[n][i])%=MOD;
	printf("%d",ans);
	return 0;
	return 0;
}

Measured memory_bytes: 256
# ABC 143 D - Triangles
# https://atcoder.jp/contests/abc143/tasks/abc143_d

n = gets.chomp.to_i
l = gets.chomp.split(/ /).map(&:to_i).sort

class Stick
  def initialize(length, index)
    @length = length
    @index = index
  end

  attr_reader :length, :index
end

sticks = l.map.with_index(0) { |length, i| Stick.new(length, i) }

# puts sticks.inspect
# puts ""

count = 0
0.upto(n - 3) do |i|
  a = sticks[i]
  (i + 1).upto(n - 2) do |j|
    b = sticks[j]
    c_candidates = sticks[(j + 1)..(n - 1)]
    t = a.length + b.length
    c_over = c_candidates.bsearch { |stick| stick.length >= t }
    if c_over.nil?
      c_last_index = (n - 1)
    else
      c_last_index = c_over.index - 1
    end
    # puts "--------"
    # puts c_candidates.inspect
    # puts "a: #{a}, b: #{b}, a - b: #{t} -> #{c_last_index - j}"
    # puts ""
    count += c_last_index - j
  end
end

puts count


Measured memory_bytes: 2168
#include <iostream>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  if (n > k)
    cout << k * x + (n - k) * y << endl;
  else
    cout << n * x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  lint k; cin >> k;
  V<lint> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  V<lint> c0(40), c1(40);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 40; ++j) {
      if (a[i] & 1LL << j) ++c1[j];
      else ++c0[j];
    }
  }
  lint res = 0;
  for (int j = 0; j < 40; ++j) {
    if (k & 1LL << j) res += c0[j] << j;
    else res += c1[j] << j;
  }
  for (int j = 0; j <= 40; ++j) if (k & 1LL << j) {
    lint curr = 0;
    for (int i = 0; i < j; ++i) {
      curr += max(c0[i], c1[i]) << i;
    }
    curr += c1[j] << j;
    for (int i = j + 1; i < 40; ++i) {
      if (k & 1LL << i) curr += c0[i] << i;
      else curr += c1[i] << i;
    }
    res = max(res, curr);
  }
  cout << res << '\n';
}

Measured memory_bytes: 1024
import sys
readline = sys.stdin.readline

N, M, X = map(int, readline().split())
C, A = [], []
for i in range(N):
    t = list(map(int, readline().split()))
    C.append(t[0])
    A.append(t[1:])

a = [sum(l) for l in zip(*A)]
if any(X > x for x in a):
    print(-1)
    exit(0)


ans = 1e18
for i in range(2 ** N):
    c = 0
    a = [0] * M
    price = 0
    for j in range(N):
        if (i >> j) & 1:
            price += C[j]
            for k in range(M):
                a[k] += A[j][k]
    if all(v >= X for v in a):
        ans = min(ans, price)

print(ans)



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

using namespace std;

int main(int argc, const char *argv[]) {
  using ll = long long;
  int n;
  cin >> n;
  vector<ll> va(n);
  for (int i = 0; i < n; i++) {
    cin >> va[i];
  }

  auto calc_r = [](ll n, ll r) { return min(r, n - r); };
  auto n_it = max_element(va.begin(), va.end());
  auto r_it = va.begin();
  if (r_it == n_it) {
    r_it++;
  }

  for (auto it = va.begin(); it != va.end(); it++) {
    if (it != n_it && calc_r(*n_it, *it) > calc_r(*n_it, *r_it)) {
      r_it = it;
    }
  }

  cout << *n_it << ' ' << *r_it << '\n';
  return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[102],res;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]==a[i-1])
            res++,a[i]=0;
    }
    cout<<res;
}


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

int main(){
  string s, rvs;
  cin >> s;
  int q;
  cin >> q;
  bool isrv = false;
  for(int i=0; i<q; ++i){
    int q1, q2;
    string q3;
    cin >> q1;
    if(q1 == 1){
      if(isrv) isrv = false;
      else isrv = true;
    }else{
      cin >> q2 >> q3;
      if(isrv){
        if(q2 == 1) s += q3;
        else rvs += q3;
      }else{
        if(q2 == 1) rvs += q3;
        else s += q3;
      }
    }
  }
  if(isrv){
    reverse(s.begin(),s.end());
    cout << s+rvs << endl;
  }else{
    reverse(rvs.begin(),rvs.end());
    cout << rvs+s << endl;
  }
}

Measured memory_bytes: 1312