akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#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 FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#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()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

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 main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin>>N;
    
    map<char,int> dic;
    rep(i,N){
        char c;cin>>c;
        dic[c]++;
    }
    
    int s=dic.size();
    string ans=(s==3?"Three":"Four");
    cout1(ans)
}

Measured memory_bytes: 256
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

void go()
{
    int n,m,sum=0;
    cin>>n;
    map<int,int> h;
    vector<int> a(n);
    for(int i=0;i<n-1;i++)
        cin>>a[i],h[a[i]]++;
    for(int i=1;i<=n;i++)
        cout<<h[i]<<endl;
}
int main()
{
    go();
    return 0;
}


Measured memory_bytes: 13564
use std::cmp::{max, min};
use std::io::{stdin, Read};
use std::str::FromStr;

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

#[allow(dead_code)]
fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let mut ans0 = 0;
    let mut ans1 = 0;

    for i in 0..s.len() {
        let ci0 = if i % 2 == 0 { '0' } else { '1' };
        if s[i] != ci0 {
            ans0 += 1
        }

        let ci1 = if i % 2 == 0 { '1' } else { '0' };
        if s[i] != ci1 {
            ans1 += 1
        }
    }
    println!("{}", min(ans0, ans1))
}


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

using namespace std;

#define ll long long
#define ini(arr, val) memset(arr, (val), sizeof(arr))
#define loop(i,n)  for(ll i=0; i<n; i++)
#define loop1(i,n)  for(ll i=1; i<=n; i++)

#define all(a)      (a).begin(),(a).end()
#define exist(s,e)  (s.find(e)!=s.end())
#define dbg(x)  cout << #x << " = " << x << endl
#define pt(x) cout<<x<<"\n"
#define pts(x) cout<<x<<" "

#define mp make_pair
#define pb push_back
#define F first
#define S second


#define inf (int)1e9
#define infll 1e18
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007


#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test   int t; cin>>t; while(t--)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef set<int> si;

typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
typedef map<ll,ll> mll;
typedef set<ll> sl;


int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };



//===========================DEBUG======================//
#define XOX 1
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

//================================================================//



//////////////////////////////////////////////////////////////////////////////////////////
//                      main starts
//////////////////////////////////////////////////////////////////////////////////////////
int const lmt=2e5+5;


int main(){
    #ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
    fast

    ll n; cin>>n;
    int a[n];
    loop(i,n) cin>>a[i];
    sort(a,a+n); reverse(a,a+n);

    int k=n-2;
    ll ans=0; 
    for(int i=1; k && i<n; i++){
    	if(k>1){ans+= 2*a[i]; k-=2;}
    	else {ans+=a[i]; k--;}
    }
    ans += a[0];
    pt(ans);
}


/*


*/





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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------


using pii = pair<string, int>;

int N;

vec<pair<pii, int>> v;

signed main() {
	cin >> N;
	rep (i, N) {
		string s;
		int p;
		cin >> s >> p;
		v.push_back(make_pair(make_pair(s, -p), i+1));
	}

	sort(all(v));

	rep (i, N) {
		cout << v[i].second << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline()[:-1]


N, C, K = map(int, input().split())
T = [0]*N
for i in range(N):
    T[i] = int(input())

T.sort()

ans = 0
bus_time = -1
bus_num = 0
for i in range(N):
    # 新しいバス
    if bus_time == -1:
        bus_time = T[i]
        bus_num = 1
        ans += 1
    elif T[i] <= bus_time+K and bus_num <= C:
        bus_num += 1
    else:
        bus_time = T[i]
        bus_num = 1
        ans += 1

    if bus_num == C:
        bus_time = -1
        bus_num = 0
print(ans)


Measured memory_bytes: 7472
#include<bits/stdc++.h>
using namespace std;
int n,a[200005],b[200005],m;
bool num[200005];
inline void in(int &k){
	int x=0;
	char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+c-48,c=getchar();
	k=x;
}
int main(){
	in(n);
	for(int i=1;i<=n;i++) in(a[i]);
	for(int i=n/2+1;i<=n;i++) 
		if(a[i]) b[++m]=i,num[i]=1;
	for(int i=n/2;i>0;i--){
		int tmp=0;
		for(int j=2;j*i<=n;j++)
			if(num[j*i]) tmp++;
		if(tmp%2!=a[i]) num[i]=1,b[++m]=i;
	}
	for(int i=1;i<=n;i++){
		int tmp=0;
		for(int j=1;j*i<=n;j++) tmp+=num[j*i];
		if(tmp%2!=a[i]){
			puts("-1");
			return 0;
		}
	} 
	sort(b+1,b+m+1);
	printf("%d\n",m);
	for(int i=1;i<=m;i++) printf("%d ",b[i]);
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int N=309;
string st[N];
int id=1,ans[N][N],n,m;
vector<int> arr[309];
void Fill(int cnt,int cl,int a,int b){

    for(int i=a;i<=b;i++){
        ans[i][cl]=id;
    }
    id++;
}
int main(){
    M();
    int k;
    cin>>n>>m>>k;
    for(int i=0;i<n;i++){
        cin>>st[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(st[i][j]=='#'){
                arr[j].pb(i);
            }
        }
    }
    int cnt=0,lst=-1;
    for(int i=0;i<m;i++){

        for(int j=0;j<sz(arr[i]);j++){
            if(j+1<sz(arr[i])){
            if(j==0){
                Fill(0,i,0,arr[i][j+1]-1);
                lst=arr[i][j+1]-1;
            }
            else{
                Fill(0,i,lst+1,arr[i][j+1]-1);
                lst=arr[i][j+1]-1;
            }
            }
            else{
                if(j==0){
                Fill(0,i,0,n-1);
              }
            else{
                Fill(0,i,lst+1,n-1);
            }
            }
        }

    }
    /*
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cout<<ans[i][j];
        }
        cout<<endl;
    }
    */
    lst=-1;
    for(int i=0;i<m;i++){
        bool ok=1;
        for(int j=0;j<n;j++){
            if(ans[j][i]==0) ok=0;
        }
        if(ok==1){
            break;
        }
        else{
            lst=i;
        }
    }
    if(lst!=-1){

     for(int i=lst;i>=0;i--){
        for(int j=0;j<n;j++){
            if(ans[j][i]==0)
            ans[j][i]=ans[j][i+1];
        }
     }

     for(int i=lst+2;i<m;i++){
        for(int j=0;j<n;j++){
            if(ans[j][i]==0)
            ans[j][i]=ans[j][i-1];
        }
     }


    }
    else{

        for(int i=1;i<m;i++){
        for(int j=0;j<n;j++){
            if(ans[j][i]==0)
            ans[j][i]=ans[j][i-1];
        }
     }
    }


    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cout<<ans[i][j]<<" ";
        }
        cout<<endl;
    }
}

/*
5 5 5
#####
#####
#####
#####
#####

3 6 2
.#.#..
......
.##.##

6 6 15
...##.
..##..
......
......
####.#
######



*/












Measured memory_bytes: 1920
(* q log(max a b) *)
let kInf = 20202020202
let a, b, q = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let ss = Array.init a @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let ts = Array.init b @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let ns = [|a; b|]
let sts = [|ss; ts|]
let xs = Array.init q @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let is_ok i key a = a.(i) >= key
let binary_search key a =
  let left, right = ref @@ -1, ref @@ Array.length a in
  while !right - !left > 1 do
    let mid = !left + (!right - !left) / 2 in
    if is_ok mid key a then right := mid
    else left := mid done;
  !right
let g x i =
  let ps = sts.(i) in
  let yi1 = binary_search x ps in
  if yi1 = 0 then ps.(yi1) - x
  else if yi1 = ns.(i) then x - ps.(yi1 - 1)
  else min (x - ps.(yi1 - 1)) @@ ps.(yi1) - x
let f x =
  let si1, ti1 = binary_search x ss, binary_search x ts in
  let s0, s1, t0, t1 =
    (if si1 = 0 then -kInf else ss.(si1 - 1)), (if si1 = a then kInf else ss.(si1)),
    (if ti1 = 0 then -kInf else ts.(ti1 - 1)), (if ti1 = b then kInf else ts.(ti1)) in
  let ans = ref kInf in
  ans := min !ans @@ if s0 < t0 then x - t0 + g t0 0 else x - s0 + g s0 1;
  ans := min !ans @@ if s1 < t1 then s1 - x + g s1 1 else t1 - x + g t1 0;
  Printf.printf "%d\n" !ans
let _ = Array.iter f xs

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
    int N;
cin >> N ;
  int A[N];
  for (int i=0 ; i<N ; i++){
    cin >> A[i];
  }
  int count=0;
  for (int c=1 ; c != 2  ;){
   c=A[c-1];
     count++;
   if (count == N){
     cout << -1 << endl;
     return 0;
   }
  }
  cout << count << endl ;
}
    


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

using ll = long long;

ll check(ll N, ll h, ll n){
  ll c = 4*h*n-N*(n+h);
  if(c == 0) return -1;
  ll p = N*h*n;
  if(p % c == 0){
    return p / c;
  }
  else return -1;
}

int main(){
	ll N;
  cin >> N;
  for(ll i = 1; i < 4000; i++){
    for(ll j = 1; j < 4000; j++){
      ll c = check(N, i, j);
      if(c > 0){
        cout << i << ' ' << j << ' ' << c << endl;
        return 0;
      }

    }
  }
}

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

ll dp[101][100001];
 
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
	ll n, W;
	cin >> n >> W;
	
	ll *wt = new ll[n];
	ll *val = new ll[n];
	
	for(ll i = 0; i < n; i++)
	{
	    cin >> wt[i] >> val[i];
	}
	
	memset(dp, 0, sizeof(dp));
	
	for(ll i = 1; i <= n; i++)
	{
	    for(ll j = 1; j <= W; j++)
	    {
	        if(wt[i-1] <= j)
	        {
	            dp[i][j] = max(val[i-1] + dp[i-1][j-wt[i-1]], dp[i-1][j]);
	        }
	        else
	        {
	            dp[i][j] = dp[i-1][j];
	        }
	    }
	}
	
	cout<<dp[n][W]<<"\n";
	
	return 0;
}



Measured memory_bytes: 82524
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
	ll a;
	cin>>a;
	ll ans=a+(a*a)+(a*a*a);
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

int main()
{
    ll n, k;
    cin >> n >> k;

    ll *h = new ll[n + 1];
    FOR(i, 1, n)
    {
        cin >> h[i];
    }

    ll *dp = new ll[n + 1];
    REP(i, n + 1)
    {
        dp[i] = INF;
    }
    dp[1] = 0;

    FOR(i, 2, n)
    {
        FOR(j, 1, k)
        {
            if (i - j <= 0)
                continue;

            int c = dp[i - j] + abs(h[i - j] - h[i]);
            if (c < dp[i])
                dp[i] = c;
        }
    }

    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 1792
N,M=map(int,input().split())
if M!=0:
  pS=[list(input().split()) for i in range(M)]
else:
  print(0,0)
  exit()

ac=[0]*N
wa=[0]*N
penalty=0

for i in range(M):
  n=int(pS[i][0])-1
  if pS[i][1]=="WA" and ac[n]==0:
    wa[n]+=1
  elif pS[i][1]=="AC" and ac[n]==0:
    ac[n]+=1
    penalty+=wa[n]

print(sum(ac),penalty)

Measured memory_bytes: 27452
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(true){
            int M = sc.nextInt();
            int T = sc.nextInt();
            int P = sc.nextInt();
            int R = sc.nextInt();
            if(M+T+P+R==0)break;
            int[][] pena = new int[T][P];
            int[][] score = new int[T][3];
            for (int i = 0; i < score.length; i++) {
                score[i][0]=i;
            }
            for (int i = 0; i < R; i++) {
                int m = sc.nextInt();
                int t = sc.nextInt()-1;
                int p = sc.nextInt()-1;
                int r = sc.nextInt();
                if(r==0){
                    score[t][1]++;
                    score[t][2]+=m+pena[t][p]*20;
                } else {
                    pena[t][p]++;
                }
            }
            Arrays.sort(score,new Comparator<int[]>(){
                @Override
                public int compare(int[] a, int[] b) {
                    if(a[1]==b[1]){
                        if(a[2]==b[2]){
                            return b[0]-a[0];
                        }
                        return a[2]-b[2];
                    }
                    return b[1]-a[1];
                }
            });
            StringBuilder ans=new StringBuilder();
            for (int i = 0; i < score.length; i++) {
                ans.append(score[i][0]+1);
                while(i+1<score.length && score[i][1]==score[i+1][1]&&score[i][2]==score[i+1][2]){
                    ans.append("=");
                    ans.append(score[i+1][0]+1);
                    i++;
                }
                ans.append(",");
            }
            System.out.println(ans.substring(0,ans.length()-1));
        }
    }

}

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

int arr[200000];
int n;

int main(){
	cin >> n;
	int sum = 0;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		sum ^= arr[i];
	}
	for(int i = 0; i < n; i++)
		cout << (sum ^ arr[i]) << ' ';
	return cout << endl, 0;
}

Measured memory_bytes: 4456
#include<bits/stdc++.h>
#define ll long long
#define N 100005
#define M 10000007
#define O 1000000009
#define vl vector<long>
#define vll vector<long long>
#define disp(n) cout<<n<<endl
#define fo(i,N) for(int i=0; i<N; ++i)
#define fos(i,b,N) for(int i=b; i<N; ++i)
#define forr(i,N) for(i=N; i>=0; --i)

using namespace std;
 
int main()
{
    long n, i, k;
    cin >> n >> k;
    vector<int> a(n);
    for(i = 0; i < n; ++i)
        cin >> a[i];
    
    vl dp(n + 1, 0);
    dp[2] = abs(a[1] - a[0]);

    for(i = 3; i <= n; ++i) {
        int j;
        dp[i] = INT_MAX;
        for(j = i - 1; j > 0 && j >= i - k; --j) {
            dp[i] = min(dp[i], dp[j] + abs(a[i - 1] - a[j - 1]));
        }
    }
    cout << dp[n] ;
    return 0;
}

Measured memory_bytes: 4564
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)

ll mod=998244353;


int32_t main() 
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	fastIO;
	ll n,a,b,q,c,y,x,i,j,k,arr[105];
	// cin>>t;
	// while(t--)
	// {
		string s,t;
		cin>>s;
		cin>>t;
		ll ans=t.size();
		// cout<<ans<<endl;
		for(i=0;i<=s.size()-t.size();i++)
		{
			ll cnt=0;
			k=i;
			for(j=0;j<t.size();j++)
			{
				// cout<<k<<" "<<j<<endl;
				// cout<<s[k]<<" "<<s[j]<<endl;
				if(s[k]!=t[j])
				{
					cnt++;
				}
				k++;
			}
			// cout<<cnt<<" ";
			ans=min(ans,cnt);
			// cout<<s[i]<<" "<<ans<<endl;
		}
		cout<<ans;
	//}
	return 0;
}

Measured memory_bytes: 3552
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let s=read::<String>().chars().map(|c|c.to_digit(10).unwrap()).collect::<Vec<u32>>();
    let mut ans=1000;
    for i in 0..s.len()-2{
        let now=(s[i]*100+s[i+1]*10+s[i+2])as i32;
        if (753i32-now).abs()<ans{ans=(753i32-now).abs()}
    }
    println!("{}",ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a,b,k;
    cin>>a>>b>>k;

    if(a>=k){
       a -=k;
    }
    else{
       k -=a;
       a =0;
       if(b>=k)
            b-=k;
       else
            b =0;
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}


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

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

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

    string ans = "-1 -1 -1";

    REPS(i, N) REPS(j, N-i) {
        if (i*10000 + j*5000 + (N-i-j)*1000 == Y) {
            printf("%d %d %d\n", i, j, N-i-j);
            return 0;
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
n, x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).map{|v| (v - x).abs}
ans = 0
n.times do |i|
    if i == 0
        ans = a[i]
    else
        ans = ans.gcd(a[i])
    end
end
p ans

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

int mod = 1000000007;
int64_t large = 9223372036854775807;

int main()
{
    int A, B;
    cin >> A >> B;
    if ((A + B) % 2 == 0)
        cout << (A + B) / 2;
    else
        cout << "IMPOSSIBLE";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    rep(i, 0, n) {
        int u, k;
        cin >> u >> k;
        u--;
        rep(j, 0, k) {
            int v;
            cin >> v;
            v--;
            g[u].push_back(v);
        }
    }

    int dist[n];
    rep(i, 0, n) dist[i] = -1;
    dist[0] = 0;
    queue<int> q;
    q.push(0);

    while (!q.empty()) {
        int x = q.front();
        q.pop();
        rep(i, 0, (int)g[x].size()) {
            int nx = g[x][i];
            if (dist[nx] != -1) continue;
            dist[nx] = dist[x] + 1;
            q.push(nx);
        }
    }

    rep(i, 0, n) {
        cout << i + 1 << " " << dist[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3160
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define N 310
#define ll long long
#define mod 1000000007
using namespace std;
ll f[N<<1][N][N];
int num[N<<1],p[N<<1],tot[N<<1],t;
int main()
{
	int n,cnt=0;
	ll ans=1;
	scanf("%d",&n);
	for(int i=1;i<=n<<1;i++) scanf("%d",&num[i]);
	for(int i=1;i<=n<<1;i+=2)
	if(num[i]!=-1 && num[i+1]!=-1) p[num[i]]=p[num[i+1]]=-1;
	else if(num[i]==-1 && num[i+1]==-1) (ans*=++cnt)%=mod;
	else p[num[i]+num[i+1]+1]=1;
	for(int i=1;i<=n<<1;i++)
	if(p[i]>=0) tot[++t]=p[i];
	f[t][0][0]=1;
	for(int i=t;i>=1;i--)
	{
		const int m=min(n,t);
		for(int j=0;j<=m;j++)
			for(int k=0;k<=m;k++)
			{
				if(k) f[i-1][j][k-1]=(f[i-1][j][k-1]+f[i][j][k])%mod;
				if(tot[i]==1) f[i-1][j+1][k]=(f[i-1][j+1][k]+f[i][j][k])%mod;
				else
				{
					f[i-1][j][k+1]=(f[i-1][j][k+1]+f[i][j][k])%mod;
					if(j)f[i-1][j-1][k]=(f[i-1][j-1][k]+f[i][j][k]*j)%mod;
				}
			}
	}
	ans*=f[0][0][0];
	printf("%lld",ans%mod);
	return 0;
}


Measured memory_bytes: 450816
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000000
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));

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

	int N,M;
	map<int,int>m;
	cin>>N>>M;
	VI A(N);
	REP(i,N)cin>>A[i];
	
	VI SUM(N+1);
	SUM[0]=0;
	
	REP(i,N){
		SUM[i+1]=(SUM[i]+A[i])%M;
	}
	ll ans=0;
	REP(i,N+1){
		ans+=m[SUM[i]];
		m[SUM[i]]++;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

signed main(){
	int n;
	cin>>n;
	int a[n];
	r(i,n)cin>>a[i];
	vector<P>v;
	r(i,n){
		v.push_back(P(a[i],i));
	}
	sort(v.begin(),v.end());
	int ans[n];
	r(i,n){
		int x=n/2;
		if(x>i){
			ans[v[i].second]=v[x].first;
		}
		else{
			ans[v[i].second]=v[x-1].first;
		}
	}
	r(i,n)cout<<ans[i]<<endl;
}

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

#define ll long long int 
ll mod=1e9+7;

// vector<int> g[200005];
// int vis[200005];
// queue<int> q;
// int level[200005];

// void dfs(int i)
// {
//     vis[i] = 1;
//     for(int j=0;j<g[i].size();j++)
//     {
//         int child = g[i][j];
//         if(vis[child] == 0)
//         {
//             dfs(child);
//         }
//     }
// }

// void bfs(int i)
// {
//     vis[i] = 1;
//     while(!q.empty())
//     {
//         int top = q.front();
//         int len_adj = g[top].size();
//         int j;
//         for(j=0;j<len_adj;j++)
//         {
//             int v = g[top][j];
//             if(vis[v]==0)
//             {
//                 vis[v]=1;
//                 q.push(v);
//                 level[v] = level[top] + 1;
//             }
//         }
//         q.pop();
// }

int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
    
    // int t;
    // cin >> t;
    // while(t--)
    // {        
    // }

    int n,i,j;
    cin >> n;
    int arr[n];

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

    for(i=1;i<n-1;i++)
    {
        int t1= arr[i-1];
        int t2 = arr[i];
        int t3 = arr[i+1];

        if(t2>t1 && t2 < t3)
        {
            ans++;
        }
        else if(t2<t1 && t2 > t3)
        {
            ans++;
        }

    }

    cout << ans << '\n';
    
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

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

    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args) {
		InputReader in = new InputReader(System.in);
	    int n = in.readInt();
	    int arr[] = new int[n]; 
	    for(int i = 0; i<n; i++) {
	    	arr[i] = in.readInt();
	    }
	    Arrays.sort(arr);
	    arr[arr.length-1] = arr[arr.length-1]/2;
	    int total = 0; 
	    for(int i = 0; i<n; i++) {
	    	total += arr[i]; 
	    }
	    System.out.println(total);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 21332
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#define rep(i, n) for(int i=0; i<n; i++)
#define rep_one(i, n) for(int i=1; i<n; i++)
using namespace std;
typedef long long ll;

int main(){
    int n; cin >> n;
    vector<ll> a;
    ll tmp;
    rep(i,n){ cin>>tmp; a.push_back(tmp);}
    sort(a.rbegin(), a.rend());
    ll ans=0;
    rep(i,n-1) ans += a[(i+1)/2];
    cout << ans << endl;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n;
  string s[40];
  int a[40];
  int check[5]={5,7,5,7,7};
  int cnt=0;
  bool b=false;
  while(1){
    cin>>n;
    if(n==0) break;
    b=false;
    rep(i,n){
      cin>>s[i];
      a[i]=s[i].size();
    }
    rep(i,n){
      cnt=0;
      int now=0;
      rep(j,5){
	cnt+=a[i+now];
	if(cnt<check[j]) j--;
	else if(cnt>check[j]) break;
	else cnt=0;
	if(j==4){cout<<i+1<<endl;b=true;break;}
	now++;
      }
      if(b) break;
    }
  }
    
  

  return 0;
}






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

using ll=long long;
const ll INF=1e18L + 5;

int bfs(vector<int> arr[], vector<bool> visited, vector<int> &dp, int i) {
	visited[i] = true;
	queue<int> q;
	q.push(i);
	while(!q.empty()) {
		i = q.front();
		q.pop();
		visited[i] = true;
		for(int x : arr[i]) {
			if(dp[x] == -1) {
				dp[x] = dp[i] + 1;
			}
			else if(dp[x] == dp[i]) {
				return -1;
			}
			if(visited[x] == false) {
				visited[x] = true;
				q.push(x);
			}
		}
	}
	return 0;
}

int main(){
	int n;
	scanf("%d", &n);
	vector<int> arr[n];
	for(int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		for(int j = 0; j < s.length(); ++j) {
			if(s[j] == '1') {
				arr[i].push_back(j);
			}
		}
	}
	int ans = -1;
	vector<bool> visited(n, false);
	for(int i = 0; i < n; ++i) {
		vector<int> dp(n, -1);
		dp[i] = 1;
		int res = bfs(arr, visited, dp, i);
		if(res == 0){
			int max1=-1;
			for(int x : dp) {
				max1 = max(max1, x);
			}
			ans = max(ans, max1);
		} 
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef vector< long long > vi;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define fr(n) for(ll i=0;i<n;i++)
#define tr(a) for(auto it=a.begin();it!=a.end();it++)
#define N 1000000007
#define PI 3.1415926535897932384
#define F first
#define S second
#define elasped_time    1.0 * clock() / CLOCKS_PER_SEC
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair


void solve(){ 

ll n;
cin>>n;
map <string,ll> m;
string s;
fr(n){
    cin>>s;
    m[s]++;
}
cout<<"AC"<<" x "<<m["AC"]<<endl;
cout<<"WA"<<" x "<<m["WA"]<<endl;
cout<<"TLE"<<" x "<<m["TLE"]<<endl;
cout<<"RE"<<" x "<<m["RE"];
}
int main()
{   FAST;
    
    ll test;
    test=1;
   
    //cin>>test;
    while(test--)
    {
        solve();
    }
     //cerr<<endl<<"maut : "<<elasped_time<<endl;
    return 0;
}
 
    



Measured memory_bytes: 3624
<?php
 fscanf(STDIN,"%d%d",$k,$s);
 $c=0;
 for($i=0;$i<=$k;$i++){
   for($j=0;$j<=$k;$j++){
     if(($s-($i+$j))<=$k && ($i+$j)<=$s){
      // echo "{$i} {$j} \n";
       $c++;
     }
   }
 }

echo $c;

Measured memory_bytes: 4604
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

struct UnionFind{
	vl p;
	vl rank;
	vl cnt;

	UnionFind(ll n){
		rank.resize(n,0);
		p.resize(n,0);
		cnt.resize(n,0);
		rep(i,n){
			p[i] = i;
			rank[i] = 0;
			cnt[i] = 1;
		}
	}

	ll find(ll x){
		if(x != p[x]) p[x] = find(p[x]);
		return p[x];
	}

	bool same(ll x, ll y){
		return find(x) == find(y);
	}

	void unite(ll x, ll y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rank[x] > rank[y]){
			p[y] = x;
			cnt[x] += cnt[y];
		}else{
			p[x] = y;
			cnt[y] += cnt[x];
			if(rank[x] == rank[y]) rank[y]++;
		}
	}

	ll size(ll x){
		return cnt[find(x)];
	}
};

int main(){
	int n,m; cin >> n >> m;
	UnionFind uf(n);
	rep(i,m){
		int a,b; cin >> a >> b; a--; b--;
		uf.unite(a,b);
	}
	int ans = 0;
	rep(i,n){
		chmax(ans, uf.size(i));
	}
	cout << ans << "\n";
}

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

void insertion_sort(std::vector<int>* A, int* cnt, int n, int g) {
  for (int i=g; i<n; i++) {
    int v = A->at(i);
    int j = i - g;
    while (j >= 0 && A->at(j) > v) {
      A->at(j+g) = A->at(j);
      j -= g;
      (*cnt)++;
    }
    A->at(j+g) = v;
  }
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> A(n);
  for (int i=0; i<n; i++) {
    std::cin >> A[i];
  }
  
  std::vector<int> intervals;
  int gap = 1;
  while (gap <= n) {
    intervals.push_back(gap);
    gap = 3 * gap + 1;
  }
  std::cout << intervals.size() << std::endl;
  for (int i=intervals.size()-1; i>0; i--) std::cout << intervals[i] << ' ';
  std::cout << intervals[0] << std::endl;
  
  int cnt = 0;
  for (int i=intervals.size()-1; i>=0; i--) {
    insertion_sort(&A, &cnt, n, intervals[i]);
  }
  std::cout << cnt << std::endl;
  for (int i=0; i<n; i++) std::cout << A[i] << std::endl;
  
  return 0;
}


Measured memory_bytes: 6788
#include <iostream>
#include <string>
#include <sstream>
#include <math.h>
using namespace std;
int main() {
int n, c = 1;
cin >> n;
for (int i = 0; i <= n/7; ++i) {
        if ((n - 7*i) % 4 == 0) {
                c = 0;
                cout << "Yes" << endl;
                break;
        }   
}
if (c) cout << "No" << endl;
}

Measured memory_bytes: 888
n = int(input())
x = list(map(int, input().split()))
INF = pow(10,10)
_min = INF

for p in range(min(x), max(x) + 1):
  total = 0
  for xi in x:    
    total += pow((xi-p),2)
  if total < _min:
    _min = total
print(_min)

Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
const int maxn=20+10,mo=1000000007;
int dp[2][maxn][(1<<21)+10],nxt[(1<<21)+10][maxn];
int bz[maxn][maxn];
int i,j,k,l,r,s,t,n,m,p,ans,now;
int main(){
	scanf("%d%d%d",&n,&m,&p);
	n--;
	fo(i,0,(1<<n)-1){
		t=-1;
		fd(j,n-1,0){
			if ((i&(1<<j))) t=j;
			nxt[i][j]=t;
		}
	}
	fo(i,1,m)
		fo(j,0,n-1)
			bz[i][j]=-1;
	fo(i,1,p){
		scanf("%d%d%d",&j,&k,&l);
		bz[j][k-1]=l;
	}
	dp[0][n][0]=1;
	now=1;
	fo(i,1,m){
		fo(s,0,(1<<n)-1) dp[now][0][s]=dp[1-now][n][s];
		fo(j,0,n)
			fo(s,0,(1<<n)-1)
				dp[1-now][j][s]=0;
		fo(j,0,n-1)
			fo(s,0,(1<<n)-1)
				if (dp[now][j][s]){
					fo(k,0,1){
						if (bz[i][j]!=-1&&bz[i][j]!=k) continue;
						t=(s&(1<<j));
						if (t) t=1;
						if (k==0&&t==1) continue;
						if (k==t) (dp[now][j+1][s]+=dp[now][j][s])%=mo;
						else{
							r=nxt[s][j];
							if (r==-1) (dp[now][j+1][s+(1<<j)]+=dp[now][j][s])%=mo;
							else (dp[now][j+1][s+(1<<j)-(1<<r)]+=dp[now][j][s])%=mo;
						}
					}
				}
		now=1-now;
	}
	fo(s,0,(1<<n)-1) (ans+=dp[1-now][n][s])%=mo;
	(ans+=mo)%=mo;
	printf("%d\n",ans);
}

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

template<typename T>
T gcd(T a, T b)
{
	return b ? gcd(b, a%b) : a;
}

int main()
{
	long long int n, k;
	cin >> n >> k;
	cout << min(n % k, k - (n % k)) << endl;
	return 0;
}

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

#define rep(i, n)  for (int i = 0; i < (n) ; ++i)
#define mod 1000000007

using namespace std;
using ll=long long;
const ll INF = 100000000;

int main() {
    int n;
    cin >> n;
    int res;
    if (n % 1000 == 0) {
        res = 0;
    } else {
        res = 1000 - (n % 1000);
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
#include <cfloat>
#include <set>

using namespace std;

int N;
int a[300000];
long long front_bests[100001];
long long back_bests[100001];

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

    priority_queue <int, vector<int>, greater<int> >pq;
    long long best_sum = 0;
    for(int i = 0; i < N; i++){
        pq.push(a[i]);
        best_sum += a[i];
    }

    front_bests[0] = best_sum;
    for(int i = N; i < 2 * N; i++){
        if(pq.top() < a[i]){
            best_sum -= pq.top();
            best_sum += a[i];
            pq.pop();
            pq.push(a[i]);
        }
        front_bests[i - N + 1] = best_sum;
    }

    priority_queue <int> pq_back;
    best_sum = 0;
    for(int i = 2 * N; i < 3 * N; i++){
        pq_back.push(a[i]);
        best_sum += a[i];
    }
    back_bests[N] = best_sum;
    for(int i = 2 * N - 1; i >= N; i--){
        if(pq_back.top() > a[i]){
            best_sum -= pq_back.top();
            best_sum += a[i];
            pq_back.pop();
            pq_back.push(a[i]);
        }
        back_bests[i - N] = best_sum;
    }
    long long ans = LLONG_MIN;
    for(int i = 0; i <= N; i++){
        ans = max(ans, front_bests[i] - back_bests[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3960
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long

ll gcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
  
   
// Function to return LCM of two numbers  
  ll lcm(ll a, ll b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
int main()
{
	ll n;cin>>n;
	map<string,ll> hash;
	string s;
	vector<string> vc;
	for(ll i=1;i<=n;i++)
	{
		cin>>s;
		sort(s.begin(),s.end());
		vc.push_back(s);
		hash[s]++;
	}
	ll count=0;
	for(ll i=0;i<vc.size();i++)
	{
		if(hash[vc[i]]){
		count=count+ ((hash[vc[i]]*(hash[vc[i]]-1))/2);
		hash[vc[i]]=hash[vc[i]]-hash[vc[i]];}
	}
	cout<<count<<endl;
	
	}

Measured memory_bytes: 16628
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto hw = readln.split.to!(int[]);
    auto H = hw[0];
    auto W = hw[1];
    int[][] ps;
    auto memo = new bool[][](H, W);
    foreach (i; 0..H) {
        foreach (j, c; readln.chomp) {
            if (c == '#') {
                ps ~= [j.to!int, i.to!int];
                memo[i][j] = true;
            }
        }
    }
    int c = -1;
    while (!ps.empty) {
        int[][] pps;
        foreach (p; ps) {
            foreach (d; [[1,0], [0,1], [-1,0], [0,-1]]) {
                auto x = p[0]+d[0];
                auto y = p[1]+d[1];
                if (x < 0 || x >= W || y < 0 || y >= H || memo[y][x]) continue;
                memo[y][x] = true;
                pps ~= [x, y];
            }
        }
        ps = pps;
        ++c;
    }
    writeln(c);
}

Measured memory_bytes: 80380
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov

int main(){
    ll a;
    cin >> a;
    ll b;
    cin >> b;
    ll c;
    cin >> c;
    ll d;
    cin >> d;
    while(true){
        c-=b;
        if(c<=0){
            cout<<"Yes"<<endl;
            return 0;
        }
        a-=d;
        if(a<=0){
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3624
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

def calc_sum(s):
    if s % 10 == 0:
        return 0
    else:
        return s

N = int(input())
S = [int(input()) for _ in range(N)]

ans = calc_sum(sum(S))
if ans > 0:
    print(ans)
    exit()

ans = 0
for i in range(N):
    s = S[0:i] + S[i+1:]
    ans = max(ans, calc_sum(sum(s)))

print(ans)

Measured memory_bytes: 3064
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
 
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
#include<iomanip>
 
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define pii pair<int,int>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp(a, b) make_pair(a, b)
#define mt(a,b,c) make_tuple(a,b,c)
#define rank qwertyuio
#define next dfghjk
#define plus fsghsf
#define minus ytryr
#define pb push_back
using namespace std;
 
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
 
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int mod = (int)1e9 + 7;
const int mod1 = (int)1e9 + 9;
const int mod2 = 998244353;
const int mod3 = (int)1e6+3;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

vector<vector<int>> adj(100007);
vector<bool> visiteda(100007,false);
vector<bool> visitedt(100007,false);
vector<int> aokimove(100007);
vector<int> takamove(100007);





int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);<<" "
    ll a,b,c;
    cin>>a>>b>>c;
    ll ans=0;
    if(c>b+1){
        ans+=2*b;
        c-=b;
    }
    else{
        ans+=b+c;
        cout<<ans;
        return 0;
    }
    if(c>a+1){
        ans+=a+1;
        cout<<ans;
    }
    else{
        ans+=c;
        cout<<ans;
    }
    return 0;
             
    
}

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

int N;

vector<int> twei = {1, 2, 4, 8, 16, 32, 64, 128};
int main(){
    scanf("%d", &N);
    printf("%d", *(upper_bound(twei.begin(), twei.end(), N)-1));
}


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

using namespace std;
 
int main() {
  double pi = 3.141592653589793238;
  double a,b, h, m;
  cin >> a >> b >> h >> m;
  double x, y;
  x = (360/12)*h;
  y = (360/60)*m;
  if (x == 0) x = 360;
  if (y == 0) y = 360;
  double plus = 0.5*m;
  x += plus;
  double diff = (double)(max(x,y) -  min(x,y));
  if (diff == 180) {
    cout << a + b << endl;
    return 0;
  } else if (180 < diff) {
    diff = 360 - diff;
  }
  double yogen = cos(diff / 180.0 * pi);
  double c = pow(a,2) + pow(b,2) - (2*a*b*yogen);
  double ans = sqrt(c);
  cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 4164
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int k,a,b;
    cin >> k >> a >> b;
    bool ok = 0;
    for(int i = a;i<=b;i++){
        if(i%k==0)ok=1;
    }
    if(ok)cout << "OK" << endl;
    else cout << "NG" << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int n, a[200];
int ta = 0, iwa = 0;

int main(){
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < 30; i++) {
		for (int j = 0; j < n; j++) {
			if (a[j] % 2 == 0) {
				ta++;
			}
		}
		if (ta == n) {
			iwa++;
			for (int j = 0; j < n; j++) {
				a[j] = a[j] / 2;
			}
		}
		else {
			break;
		}
		ta = 0;
	}
	cout << iwa << endl;
	return 0;
}

Measured memory_bytes: 256