akhauriyash/Code-Regression huggingface dataset:
/*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES

#include <iostream> // ?¨??????\??????
#include <fstream>  // ??????????????\??????
#include <string>   // ???????????¢???
#include <vector>   // ???????????????
#include <cmath>    // ??°??????
#include <iomanip>  // stream???????????¢???
#include <algorithm>// max??¢??°??????

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;        // ????´???°????????????????????????
using std::fixed;         // ???????????????????¨???????????????????????????????
using std::setprecision;  // ?????°????°???°?????\???????????°????????????????????¨????????\???

int main() {
	vector<int> height;	// ??\???????????????????´?????????????
	int h;				// ??\?????????????????????????´??????°

	// 10????????\?????????????????????
	for (size_t i = 0; i < 10; i++)
	{
		cin >> h;
		height.push_back(h);
	}
	// ????????????
	std::sort(height.begin(), height.end());

	// ??????
	cout << height[9] << endl;
	cout << height[8] << endl;
	cout << height[7] << endl;
	return 0;
}

Measured memory_bytes: 3072
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = nextInt();
        Integer[] a = new Integer[n];

        int Answer = 0;

        for(int i = 0; i < n; i++){
            a[i] = nextInt();
        }

        Arrays.sort(a, Comparator.reverseOrder());

        for (int i = 0; i < n - 2; i ++) {
        	for (int j = i + 1; j < n - 1; j++) {
        		for (int k = j + 1; k < n; k++) {
        			if (check(a[i], a[j], a[k])) {
        				Answer += 1;
        			} else {
        				break;
        			}
        		}
        	}
        }

        println(Answer);
    }

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

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

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

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static boolean check(int i, int j, int k) {
    	if (i + j <= k) {
    		return false;
    	}
    	if (j + k <= i) {
    		return false;
    	}
    	if (k + i <= j) {
    		return false;
    	}
    	return true;
    }

}

Measured memory_bytes: 25660
x,k,d=map(int,input().split())
mini=0
if abs(x)>=k*d:
 mini=abs(x)-k*d
 print(mini)
else:
 q=abs(x)//d
 s=abs(x)%d
 if (k-q)%2==0:
  print(s)
 else:
  print(abs(s-d))

Measured memory_bytes: 9160
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005
int table[NUM];

int main(){

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

	for(int i = 0; i < N; i++){

		scanf("%d",&table[i]);
	}

	int ans = 0;

	for(int i = 0; i <= N-2; i++){

		if(i+1 == table[i]){ //右に寄せる

			swap(table[i],table[i+1]);
			ans++;
		}
	}

	if(table[N-1] == N)ans++;

	printf("%d\n",ans);

	return 0;
}


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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    string s;
    cin >> n >> q >> s;
    VI ac_cnt(n, 0);
    FOR(i, 1, n - 1) {
        if(s.substr(i - 1, 2) == "AC") ac_cnt[i] = ac_cnt[i - 1] + 1;
        else ac_cnt[i] = ac_cnt[i - 1];
    }

    REP(i, q) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        cout << ac_cnt[r] - ac_cnt[l] << ln;
    }
    return 0;
}


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

int main()
{
    int n,j,a;
    cin>>a;
    if(a<10)
    {
        printf("%d\n",a%10); return 0;
    }
    if(a<100)
    {
        n=9;printf("%d\n",n);return 0;
    }
    if(a/100<10)
    {
        j=((a/100)-1)*100;n=j+(a%100)+10;printf("%d\n",n);return 0;
    }
    if(a/1000<10)
    {
        n=909;printf("%d\n",n);return 0;
    }
    if(a/10000<10)
    {
        j=((a/10000)-1)*10000;n=j+910+(a%10000);printf("%d\n",n);return 0;
    }
    if(a/100000<10)
    {
        n=90909;printf("%d\n",n);return 0;
    }
    if(a/1000000<10)
    {
        j=((a/1000000)-1)*1000000;n=j+90910+(a%1000000);printf("%d\n",n);return 0;
    }
    if(a/10000000<10)
    {
        n=9090909;printf("%d\n",n);return 0;
    }
    if(a/100000000<10)
    {
        j=((a/100000000)-1)*100000000;n=j+9090910+(a%100000000);printf("%d\n",n);return 0;
    }
    if(a/1000000000<10)
    {
        n=909090909;printf("%d\n",n);return 0;
    }

    return 0;
}


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

signed main() {
  int N, M;
  cin >> N >> M;
  
  vector<vector<bool>> G(N, vector<bool>(N));
  int A, B;
  for( int i = 0; i < M; i++ ){
    cin >> A >> B;
    G.at(A-1).at(B-1) = true;
    G.at(B-1).at(A-1) = true;
  }
  
  vector<int> zyun(N-1);
  for( int i = 0; i < N-1; i++ ) zyun.at(i) = i+1;
    
  
  int ans = 0;
  bool hantei;
  do{
    hantei = true;
    if( G.at(0).at(zyun.at(0)) == false ) hantei = false;
    for( int i = 0; i < N-2; i++ ){
      if( G.at(zyun.at(i)).at(zyun.at(i+1)) == false ){
        hantei = false;
      }
    }
    if( hantei == true ) ans++;
  }while( next_permutation(zyun.begin(), zyun.end()) );
  
  cout << ans << endl;
 
  
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans = 0
cnt_minus = 0
cnt_zero = 0
m = 10**9
for i in a:
    ans += abs(i)
    if i<0:
        cnt_minus += 1
    if i==0:
        cnt_zero +=1
    m = min(m,abs(i))

if cnt_minus % 2 == 0 or cnt_zero !=0:
    print(ans)
else:
    print(ans-2*m)


Measured memory_bytes: 20104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int S[211111];
int dp[211111];
int best[(1<<26)+2];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	int n=s.length();
	for(int i=1;i<(1<<26);i++) best[i]=int(1e9);
	dp[0] = 0;
	S[0] = 0;
	for(int i=0;i<n;i++)
	{
		S[i+1]=(1<<(s[i]-'a'));
		S[i+1]^=S[i];
	}
	for(int i=1;i<=n;i++)
	{
		int r=S[i];
		dp[i]=int(1e9);
		dp[i]=min(dp[i],best[r]+1);
		for(int j=0;j<26;j++)
		{
			dp[i]=min(dp[i],best[(1<<j)^r]+1);
		}
		best[r]=min(best[r],dp[i]);
	}
	cout<<dp[n]<<'\n';
}


Measured memory_bytes: 264340
#include <iostream>
#define rep(i, n) for (int i=0; i<n; i++)
#define ll long long
using namespace std;

void print(int *A, int N) {
    rep(i, N) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << "\n";
}

void selectionSort(int *A, int N) {
    int count = 0;
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (A[j] < A[minj])
                minj = j;
        }
        if (i != minj) {
            int tmp;
            tmp = A[i];
            A[i] = A[minj];
            A[minj] = tmp;
            count++;
        }
    }
    print(A, N);
    cout << count << endl;
}

int main() {
    int N;
    cin >> N;
    int A[N];
    rep(i, N) {
        cin >> A[i];
    }
    selectionSort(A, N);
}


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

bool isPrime(int);

int main()
{
    int n = 0;
    cin >> n;

    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        int tested;
        cin >> tested;
        if (isPrime(tested) == true)
        {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

bool isPrime(int n)
{
    bool res = false;
    if (n == 1 || (n % 2 == 0 && n != 2))
    {
        return res = false;
    }
    else if (n == 2)
    {
        return res = true;
    }
    else
    {
        for (int i = 2; i <= (int)sqrt(n); i++)
        {
            if (n % i == 0)
            {
                return res = false;
            }
        }
        return res = true;
    }

    return res;
}


Measured memory_bytes: 3108
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> a >> b >> d;
  rrep(i, a, b + 1) {
    if (i % d == 0) ans++;
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
typedef long long ll;
#define all(a)  (a).begin(), (a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i = 0; i < n; i++)
#define repR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m,n) for(int i = m; i < n; i++)
#define PB push_back
#define MP make_pair
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

struct town { ll p, y;};

int main(){
    int n,m;
    cin >> n >> m;
    struct town t[m+1];
    vector<int> P[n+1];

    rep(i,m+1)if(i){
        cin >> t[i].p >> t[i].y;
        P[t[i].p].PB(t[i].y);
    }
    rep(i,n+1)if(i){
        sort(all(P[i]));
    }

    rep(i,m+1)if(i){
        cout << setw(6) << setfill('0') << t[i].p;
        cout << setw(6) << setfill('0') << lower_bound(all(P[t[i].p]),t[i].y) - P[t[i].p].begin() + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <string.h>

using namespace std;


int main(){
    long long N,P;
    cin >> N >> P;
    double x = pow((double)P,1.0/(double)N);
    if(N==1){
        cout<<P;
        return 0;
    }
    if(x<1.9){
        cout<<1;
        return 0;
    }
    long long k = 1;
    for(long long i=2;i<x+1;i++){
        if(P<i){ break; }
        int count = 0;
        while(P%i==0){
            P/=i;
            count++;
        }
        for(long long j=0;j<(count/N);j++){
            k *= i;
        }
    }
    
    cout<<k;
    
    return 0;
}


Measured memory_bytes: 384
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n,m;
bool able[100005];
int cnt[100005];
int main(){
  cin>>n>>m;
  able[0]=1;
  REP(i,n) cnt[i]=1;
  REP(i,m){
    int x,y;scanf("%d%d",&x,&y);--x;--y;
    if(cnt[x]==1){
      able[y]|=able[x];
      able[x]=0;
      ++cnt[y];
      --cnt[x];
    }else{
      able[y]|=able[x];
      ++cnt[y];
      --cnt[x];
    }
  }
  int res=0;
  REP(i,n) if(able[i]) ++res;
  cout<<res<<endl;
  return 0;
}




Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>
#include<random>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
int d;
int c[30]={};
int s[370][30];
int num=100000;
int koho=5;
int calc(vector<int>const& t,vector<vector<int>>& last_list){
  int res=0;
  vector<int> last(30,0);
  rep1(i,d){
    res+=s[i][t[i]];
    last[t[i]]=i;
    last_list[i]=last;
    int buf=0;
    rep1(j,26){
      buf+=c[j]*(i-last[j]);
    }
    res-=buf;
    //cout<<res<<"\n";
  }
  return res;
}
int change(int nd,int nq,int& res,vector<int>& t,vector<vector<int>>& last_list){
  int flag_t=false;
  int flag_q=false;
  int x=t[nd];
  t[nd]=0;
  res+=s[nd][nq];res-=s[nd][x];
  for(int i=nd;i<=d;++i){
    if(flag_t&&flag_q)break;
    if(t[i]==x||flag_t)flag_t=true;
    else{
      res+=c[x]*(i-last_list[i][x]);
      last_list[i][x]=last_list[i-1][x];
      res-=c[x]*(i-last_list[i][x]);
    }
    if(t[i]==nq||flag_q)flag_q=true;
    else{
      res+=c[nq]*(i-last_list[i][nq]);
      last_list[i][nq]=nd;
      res-=c[nq]*(i-last_list[i][nq]);
    }
  }
  t[nd]=nq;
  return res;
}
vector<int> greedy(int d,vector<vector<int>>& t_koho){
  vector<int> res(d+1,0);
  vector<int> last(30,0);
  rep1(i,d){
    int mx=-inf;
    int mx_ind=0;
    vector<P> kouho(26);
    rep1(j,26){
      int tmp=s[i][j];
      rep1(k,26){
        if(k==j)continue;
        tmp-=c[k]*(i-last[k]);
      }
      if(mx<tmp){
        mx=tmp;
        mx_ind=j;
      }
      kouho[j-1]={tmp,j};
    }
    sort(kouho.begin(),kouho.end());
    reverse(ALL(kouho));
    rep(x,koho){
      t_koho[i][x]=kouho[x].second;
    }
    last[mx_ind]=i;
    res[i]=mx_ind;
  }
  return res;
}
signed main(){
  cin>>d;
  rep1(i,26)cin>>c[i];
  rep1(i,d){
    rep1(j,26)cin>>s[i][j];
  }
  vector<vector<int>> t_koho(d+5,vector<int>(koho+5,0));
  vector<int> t=greedy(d,t_koho);
  vector<vector<int>> last_list(d+1,vector<int>(30,0));
  int res=calc(t,last_list);
  //cout<<res<<"\n";
  int param=2;
  rep(xx,num){
    random_device rand;
    mt19937 mt(rand());
    vector<int> nd(param);rep(i,param)nd[i]=mt()%d+1;
    vector<int> nq(param);rep(i,param)nq[i]=t_koho[nd[i]][mt()%koho];
    vector<int> bq(param);rep(i,param)bq[i]=t[nd[i]];
    int bval=res;
    rep(i,param){
      change(nd[i],nq[i],res,t,last_list);
    }
    int yakinamasi=mt()%100;
    if(yakinamasi<5&&res+res/10000>bval)continue;
    if(bval>res){
      rep(i,param){
        change(nd[i],bq[i],res,t,last_list);
      }
    }
  }
  rep(xx,num){
    random_device rnd;
    mt19937 mt(rnd());
    int nd=mt()%d+1;
    int nq=mt()%26+1;
    int bq=t[nd];
    int bval=res;
    int hoge=change(nd,nq,res,t,last_list);
    if(hoge<bval){
      change(nd,bq,res,t,last_list);
    }
  }
  rep1(i,d){
    cout<<t[i]<<"\n";
  }
  //cout<<res<<"\n";
  return 0;
}

Measured memory_bytes: 3880
#include <stdio.h>

int main(void){
	int nyukyo[4][3][10]={0};
	int n;
	int building,floor,room;
	int people;
	int i,j,k;
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&building,&floor,&room,&people);
		nyukyo[building-1][floor-1][room-1]+=people;
	}
	for(i=0;i<4;i++){
		if(i)printf("####################\n");

		for(j=0;j<3;j++){
			for(k=0;k<10;k++) printf(" %d",nyukyo[i][j][k]);
			printf("\n");
		}
	}
		return 0;
}

Measured memory_bytes: 612
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
using namespace std;
#define ul unsigned long long

#define rep(a, b) for(int i = a; i < b; i++)

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

	int c = 0;
	vector<int> arr = vector<int>(9, 0);
	for (int i = 0; i < n; i++) {
		int r = a[i];
		if (r >= 3200) {
			c = 1;
		}
		else if (r >= 2800) {
			c = 2;
		}
		else if (r >= 2400) {
			c = 3;
		}
		else if (r >= 2000) {
			c = 4;
		}
		else if (r >= 1600) {
			c = 5;
		}
		else if (r >= 1200) {
			c = 6;
		}
		else if (r >= 800) {
			c = 7;
		}
		else if (r >= 400) {
			c = 8;
		}
		else if (r >= 1) {
			c = 9;
		}
		arr[c - 1]++;
	}

	int colors = 0;
	for (int i = 1; i < arr.size(); i++) {
		if (arr[i] != 0) colors++;
	}
	int minColors = colors;
	if (minColors == 0) {
		if (arr[0] != 0) minColors = 1;
	}
	int maxColors = colors + arr[0];
	/*if (maxColors >= arr.size() - 1) {
		maxColors = arr.size() - 1;
	}*/
	cout << minColors << " " << maxColors << endl;
	return 0;
}





Measured memory_bytes: 256
#include <utility>
#include <utility>
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int N, M;
    while(cin >> N >> M && N){
        int d, p;
        pair<int, int> PD[10010];
        for(int i=0; i<N; ++i){
            cin >> d >> p;
            PD[i] = make_pair(p, d);
        }
        sort(PD, PD+N);
        reverse(PD, PD+N);
        int ex = 0;
        for(int i=0;i<N;++i){
            if(M >= PD[i].second) M -= PD[i].second;
            else{
                ex += (PD[i].second - M) * PD[i].first;
                M = 0;
            }
        }
        cout << ex << endl;
    }
    return 0;
}

Measured memory_bytes: 1240
using System;
using System.Linq;

namespace ABC087
{
    class C
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] A2 = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int[] A1S = new int[N + 1];
            int[] A2S = new int[N + 1];

            int[] S = new int[N + 1];

            A1S[0] = 0;
            A2S[0] = 0;
            for (int i = 1; i < N + 1; i++)
            {
                A1S[i] = A1S[i - 1] + A1[i - 1];
                A2S[i] = A2S[i - 1] + A2[i - 1];
            }

            for (int i = 0; i < N; i++)
            {
                S[i] = A1S[i + 1] + A2S[N] - A2S[i];
            }

            Console.WriteLine(S.Max());
        }
    }
}


Measured memory_bytes: 13396
S=input()
N=len(S)
c=0
c2=0
#1010..
for i in range(N):
  if i % 2 == 0:
    if S[i] == "0":
      c += 1
  else:
    if S[i] == "1":
      c += 1
#0101..
for j in range(N):
  if j % 2 == 0:
    if S[j] == "1":
      c2 += 1
  else:
    if S[j] == "0":
      c2 += 1
print(c if c<=c2 else c2)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
	int ar[5];
	for(int i=0;i<5;i++){
		cin>>ar[i];
	}
	int k;
	cin>>k;
	sort(ar,ar+5);
	for(int i=0;i<5;i++){
		for(int j=i;j<5;j++){
			if(abs(ar[i]-ar[j])>k){
				cout<<":("<<endl;
				return 0;
			}
		}
	}
	cout<<"Yay!"<<endl;
}

Measured memory_bytes: 256
n,k = map(int, input().split())
a = list(map(int, input().split()))

#############

mod = 10**9 + 7
max = 10**5+10
fac, finv, inv = [0]*max, [0]*max, [0]*max

def comInit(max):
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,max):
      fac[i] = fac[i-1]* i% mod
      inv[i] = mod - inv[mod%i] * (mod // i) % mod
      finv[i] = finv[i-1] * inv[i] % mod

comInit(max)

# 二項係数の計算
def com(n,k):
    if(n < k):
        return 0
    if( n<0 | k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod

#############

a = sorted(a)

mul = [0]* n
mul[k-1] = 1
for i in range(k, n):
    mul[i] = com(i, k-1)

ans = 0
for i in range(n):
    ans += (a[i] * mul[i]) - (a[i] * mul[ -1*(i+1)]) % mod
    ans = ans % mod

print(ans)

Measured memory_bytes: 63472
n,m,c = map(int,input().split())
b = []
a = []
ans = 0
b = list(map(int,input().split()))
for i in range(n):
  a.append(list(map(int,input().split())))
for i in range(n):
  ad = 0
  for j in range(m):
    ad = ad + a[i][j]*b[j]
  ad = ad + c
  if ad > 0:
    ans += 1
print(ans)

Measured memory_bytes: 3064
import * as fs from 'fs'
const reader = (s: string) => s.split(' ').map(t => parseInt(t, 10))

function Main(input: string) {
  const [A, B] = reader(input)

  console.log(A - 2 * B >= 0 ? A - 2 * B : 0)
}

Main(fs.readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
    if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
    template <class C>
    static char test(typename C::const_iterator*);
    template <class C>
    static int test(...);
    static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
    static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o,
                                                             const C& c) {
    o << '[';
    for (auto it = c.begin(); it != c.end();)
        o << *it << (++it != c.end() ? ", " : "");
    return o << ']';
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
    return o << '(' << p.fi << ", " << p.se << ')';
}

using ld = long double;

void solve() {
    ld a, b;
    cin >> a >> b;
    a *= b;
    cout << (ll) a << endl;
}

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

    int tt = 1;
    FOR (t, 1, tt + 1) {
	// cout << "Case #" << t << ": ";
	solve();
    }

    return 0;
}


Measured memory_bytes: 3748
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	n, m := readInt(), readInt()

	s := make([][]int, m)
	for i := 0; i < m; i++ {
		k := readInt()
		s[i] = make([]int, k)
		for j := 0; j < k; j++ {
			s[i][j] = readInt()
		}
	}

	p := make([]int, m)
	for i := 0; i < m; i++ {
		p[i] = readInt()
	}

	count := 0
	l := int(math.Pow(2.0, float64(n)))
	for i := 0; i < l; i++ {
		format := "%0" + strconv.Itoa(n) + "b"
		bit := fmt.Sprintf(format, i)
		ok := true
		for j := 0; j < m; j++ {
			sum := 0
			for k := 0; k < len(s[j]); k++ {
				sum += int(bit[s[j][k]-1] - '0')
			}
			if sum%2 != p[j] {
				ok = false
			}
		}
		if ok {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)














int main(){
    ll n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    a--; b--; c--; d--;
    if(c < d){
        for(ll i = b; i < d; i++){
            if(s[i] == '#' && s[i + 1] == '#'){
                cout << "No" << endl;
                return 0;
            }
        }
        for(ll i = a; i < b; i++){
            if(s[i] == '#' && s[i + 1] == '#'){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    else{
        bool ok = true;
        for(ll i = a; i < c; i++){
            if(s[i] == '#' && s[i + 1] == '#'){
                cout << "No" << endl;
                return 0;
            }
            if(i == b){
                if(s[i + 1] == '#'){
                    b += 2;
                }
                else{
                    if(i < c - 1 && s[i + 2] != '#'){
                        b++;
                        i++;
                    }
                    else{
                        if(i > 0 && s[i - 1] != '#'){
                            
                        }
                        else{
                            b++;
                        }
                    }
                }
            }
        }
        if(b > d){
            cout << "No" << endl;
            return 0;
        }
        for(ll i = b; i < d; i++){
            if(s[i] == '#' && s[i + 1] == '#'){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 640
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
int main(){
    int x,y;
    cin >> x>> y;
    rep(i,x+1){
        int temp=2*i+4*(x-i);
        if(temp==y){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  long long h;
  cin >> h;
  long long count = 0;
  while(h > 1){
    h /= 2;
    count ++;
  }
  long long now = 1;
  long long ans = 0;
  for(int i = 0; i < count + 1; i++){
    ans += now;
    now *= 2;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3588
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = []
    ave = sum(A)/N
    this = max(A)
    count = 0
    for i in A:
        ans.append(abs(ave-i))
    for j in range(N):
        if this > ans[j]:
            count = j
            this = ans[j]
    print(count)
resolve()

Measured memory_bytes: 8968
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int n;
    std::cin>>n;
    std::vector<long long> x(n);
    for(int i = 0;i < n;i++){
        std::cin>>x[i];
    }

    std::vector<long long> y = x;
    std::sort(y.begin(), y.end());
    auto k = y.end() - (n / 2);
    for(int i = 0;i < n;i++){
        auto itr = std::lower_bound(y.begin(), y.end(),
                x[i]);
        if(itr < k){
            std::cout<<(*k)<<std::endl;
        }else{
            std::cout<<(*(k - 1))<<std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 5376
N=int(input())
p=list(map(float,input().split()))
dp=[[0]*(N+1) for _ in range(N+1)]

#dp[i][j]:=i枚コインの中から、j個表が出る確率
dp[0][0]=1

for i in range(1,N+1):
    dp[i][0]=dp[i-1][0]*(1-p[i-1])

for i in range(1,N+1):
    for j in range(1,N+1):
        dp[i][j]=dp[i-1][j]*(1-p[i-1])+dp[i-1][j-1]*p[i-1]

print(sum(dp[N][(N+1)//2:]))

Measured memory_bytes: 345992
import java.util.*;

public class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		
		String a = A.substring(A.length()-1,A.length());
		String b = B.substring(B.length()-1,B.length());

		if(a.equals(B.substring(0,1)) && b.equals(C.substring(0,1))){ 
				System.out.println("YES");
			} else{
				System.out.println("NO");
			}
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
using P= pair<int,int>;

int main(){
  int n; cin>>n;
  int num[n];
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  sort(num,num+n);
  vector<P> ans;
  int max=num[n-1],min=num[0];
  for(int i=1;i<n-1;i++){
    if(num[i]<0){
      ans.push_back(P(max,num[i]));
      max-=num[i];
    }else{
      ans.push_back(P(min,num[i]));
      min-=num[i];
    }
  }
  ans.push_back(P(max,min));
  cout<<max-min<<endl;
  for(int i=0;i<n-1;i++){
    cout<<ans[i].first<<' '<<ans[i].second<<endl;
  }
}

Measured memory_bytes: 3188
use proconio::input;

fn main() {
    input! {
        k: usize,
        a: usize,
        b: usize,
    }

    let r = if (b / k) - (a / k) >= 1 || a % k == 0 || b % k == 0 {
        "OK"
    } else {
        "NG"
    };

    println!("{}", r);
}


Measured memory_bytes: 2148
s = input()
counter = 0
for i in range(len(s)):
  if i == 0:
    if s[i] == "A":
      continue
    else:
      print("WA")
      exit()
  else:
    if 2<=i<=len(s)-1:
      if s[1] != s[1].lower():
        print("WA")
        exit()
      if s[i] == "C":
        counter += 1
      else:
        if s[i] != s[i].lower():
          print("WA")
          exit()
    if s[-1] != s[-1].lower():
      print("WA")
      exit()
if counter == 1:
  print("AC")
else:
  print("WA")
          
          

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

using namespace std;

typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll N, H;
	cin >> N >> H;
	vector<ll> a(N), b(N);
	for (int i = 0; i < N; i++){
		cin >> a[i] >> b[i];
	}
	ll a_max = *max_element(a.begin(), a.end());
	sort(b.rbegin(), b.rend());
	ll ans = 0;
	for (int i = 0; i < N; i++){
		if(a_max < b[i]){
			H -= b[i];
			ans++;
			if(H <= 0) break;
		}
	}
	
	if(H > 0){
		ans += (H + (a_max - 1)) / a_max;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){a%=mod;b%=mod;return a*b%mod;}
inline int power(int a,int b,int MOD){a%=mod;int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
    SPEED;
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(a+b+c>=22 ? "bust" : "win")<<endl;
    time();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin >> n >> m;
	string s;
	cin >> s;
	int a,b,f[n+1];
	f[0]=0;
	for(int i=1;i<n;i++)
	{
		f[i]=f[i-1];
		if(s[i]=='C'&&s[i-1]=='A') f[i]++;
	}
	for(int i=1;i<=m;i++)
	{
		cin >> a >> b;
		cout << f[b-1]-f[a-1] << endl;
	}
}


Measured memory_bytes: 1488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M=1000000007;
const ll N=200010;
ll n,k,ans,tmp;
ll in[N<<1],jc[N<<1],jcin[N<<1];
int main()
{
    scanf("%lld%lld",&n,&k);
    jc[1]=in[1]=jcin[1]=1;
    jc[0]=in[0]=jcin[0]=1;
    for(int i=2;i<=n<<1;++i){
    	jc[i]=jc[i-1]*i%M;
	}
	for(int i=2;i<=n<<1;++i){
		in[i]=(M-M/i*in[M%i]%M)%M;
	}
	for(int i=2;i<=n<<1;++i){
		jcin[i]=jcin[i-1]*in[i]%M;
	}
	if(k+1>=n) printf("%lld",jc[2*n-1]*jcin[n]%M*jcin[n-1]%M); 
    else{
    	ans=0;
    	for(ll q=0;q<=k;++q){
    		if(q) ans+=(M+jc[n]%M*jc[n-1]%M*jcin[q]%M*jcin[q]%M*jcin[n-q]%M*jcin[n-q-1]%M)%M;
    		else ans+=1;
    		ans%=M;
		}
		printf("%lld",ans);
	}
	return 0;
}

Measured memory_bytes: 9600
/* 

Author: Vishal Singh  
(singhvishal0304@gmail.com)

"The days that break you are the days that make you."

*/

#include <bits/stdc++.h>
using namespace std;

#define fastio() ios_base::sync_with_stdio(false);\
cin.tie(NULL);

#define md 1000000007


#define lli long long int
#define pb push_back
#define mp make_pair
#define vvi(r,c) vector<vector<lli>> v(r,vector<lli>(c));
#define fi first
#define se second
#define mem(arr,x) memset(arr,x,sizeof(arr))

lli power(lli a,lli b){
  if(b==0)
    return 1;
  if(b%2)
    return ((a%md)*(power(a,b-1)))%md;
  else
  {
    lli x=power(a,b/2);
    return (x*x)%md;
  }
}
int ans;
void bfs(vector<int>* adj,bool vis[],int s,int t){

  queue<int> q;
  q.push(s);
  q.push(-1);
  int ans=0;
  int flag=0;
  vis[s]=true;
  while(!q.empty()){
    int x=q.front();
    q.pop();
    if(x==t)
    {
      flag=1;
      break;
    }
    for(auto i:adj[x]){
      if(!vis[i]){
       q.push(i);
       vis[i]=true;
      }
    }
    int y=q.front();
    if(y==-1){
      q.pop();
      if(q.empty())
        break;
      q.push(-1);
      ans++;
    }
  }

  if(flag && !(ans%3))
    cout<<ans/3<<endl;
  else
    cout<<"-1"<<endl;
}

void solve(){
  int n,m;
  cin>>n>>m;
  int x=3*(n+1);
  vector<int> adj[x];
  for(int i=0;i<m;i++){
    int a0,b0;
    cin>>a0>>b0;
    int a1=n+a0,a2=2*n+a0;
    int b1=n+b0,b2=2*n+b0;
      adj[a0].pb(b1);
      adj[a1].pb(b2);
      adj[a2].pb(b0);
  }
  int s,t;
  cin>>s>>t;
  bool vis[x];
  mem(vis,false);
  bfs(adj,vis,s,t);
}


int main()
{  
    fastio();
  int t;
  t=1;
  while(t--){
    solve();
  }

  return 0;
}

Measured memory_bytes: 17024
N, K = map(int, input().split())

if N % K == 0:
    print(0)

else:
    while True:
        if N // K == 0:
            print(N % K) if N % K < abs(N - K) else print(abs(N - K))
            break;

        else:
            N = abs(N - K * (N//K))


Measured memory_bytes: 38256
n=int(input())

sosuu = [2]
A = 1000
for L in range(3, A, 2): # 2 以外の素数は奇数なので
    for L2 in sosuu:
        if L % L2 == 0:
            break # 素数でないことがわかったらそれ以上ループする必要はない
    else: # break で抜けることがなかったら L は素数（Python 特有の制御構文）
        sosuu.append(L)
ans=[]

for i in sosuu:
  ch=1
  x=i
  while x<=n:
    ch+=n//x
    x=x*i
    
  ans.append(ch)

ans1=1
mod=10**9+7
for j in ans:
  ans1=(ans1*j)%mod
  
print(ans1)

Measured memory_bytes: 9008
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int h,w,n;
vi a;

int main(){
	cin>>h>>w>>n;
	a=vi(h+1,w);
	a[h]=0;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		a[x-1]=min(a[x-1],y-1);
	}
	int t=0;
	for(int i=0;i<h;i++){
		int x=a[i+1];
		if(x<=t){
			cout<<i+1<<endl;
			break;
		}
		if(t+1<x) t++;
	}
}

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

int main(){
  int N,minsum=1000000;
  cin >> N;
  for(int i=1;i<N;i++){
    int A,B,sum=0;
    A=i,B=N-i;
    for(int j=0;j<8;j++){
      sum+=A%10;
      sum+=B%10;
      A/=10,B/=10;
    }
    minsum=min(minsum,sum);
  }
  cout << minsum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const llint INF = 100000000;

int main() {
	int n;
	cin >> n;
	hei(llint) a(n);
	rep(i, 0, n)cin >> a[i];
	int ans = 0;
	sort(a.begin(), a.end());
	rep(i, 0, n-2) {
		rep(j, i + 1, n - 1) {
			rep(k, j + 1, n) {
				if (a[i] == a[j] || a[i] == a[k] || a[k] == a[j])continue;
				if ((a[i] + a[j]) > a[k])ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);


vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i*i < n; ++i)
    if (primes[i])
      for (int j = i*i; j < n; j+=i)
        primes[j] = 0;
  return primes;
}
int main(){
	int m,a,b;
	vi e=sieve_of_eratosthenes(100000);
	sort(ALL(e));
	e.erase(unique(ALL(e)),e.end());
	e.erase(e.begin(),e.begin()+1);
	while(cin>>m>>a>>b,m|a|b){
		ll pp=0,qq=0;
		REP(i,e.size()){
			ll p=e[i];
			if(p>m)break;
			FOR(j,i,e.size()){
				ll q=e[j];
				if(p*q>m)break;
				if(a*q<=b*p){
					if(pp*qq<p*q){
						pp=p;
						qq=q;
					}
				}
			}
		}
		cout<<pp<<" "<<qq<<endl;
	}
}

Measured memory_bytes: 1536
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N, M, Q;
	List<Tuple> list;
	long result = 0L;

	static class Tuple {
		int a, b, c, d;

		Tuple(String line) {
			String[] tokens = line.split(" ");
			a = Integer.parseInt(tokens[0]) - 1;
			b = Integer.parseInt(tokens[1]) - 1;
			c = Integer.parseInt(tokens[2]);
			d = Integer.parseInt(tokens[3]);
		}
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		M = Integer.parseInt(tokens[1]);
		Q = Integer.parseInt(tokens[2]);
		list = new ArrayList<>(Q);
		for (int i = 0; i < Q; ++i) {
			list.add(new Tuple(in.readLine()));
		}
	}

	List<int[]> getValues(int prevVal, int remain) {
		if (remain == 0) {
			List<int[]> l = new ArrayList<>();
			for (int i = prevVal; i <= M; ++i) {
				int[] array = new int[N];
				array[N - 1] = i;
				l.add(array);
			}
			return l;
		} else {
			List<int[]> l = new ArrayList<>();
			for (int i = prevVal; i <= M; ++i) {
				List<int[]> nextL = getValues(i, remain - 1);
				for (int j = 0; j < nextL.size(); ++j) {
					nextL.get(j)[N - 1 - remain] = i;
					l.add(nextL.get(j));
				}
			}
			return l;
		}
	}

	long eval(int[] array, List<Tuple> list) {
		long sum = 0L;
		for (Tuple tuple : list) {
			if (array[tuple.b] - array[tuple.a] == tuple.c) {
				sum += tuple.d;
			}
		}
		return sum;

	}

	void calc() {
		List<int[]> arrays = getValues(1, N-1);
		for (int[] array : arrays) {
			result = Math.max(result, eval(array, list));
		}
		System.out.println(result);
	}

	void showResult() {
	}

}

Measured memory_bytes: 56324
def main():
    n, m = map(int, input().split())
    A, X = [], []
    for _ in range(n):
        A.append(list(map(int, input().split())))
    for _ in range(m):
        X.append(list(map(int, input().split())))
    for a, b in A:
        ans, dist = 0, 10e+10
        for i, (x, y) in enumerate(X):
            if (d := abs(x - a) + abs(y - b)) < dist:
                dist = d
                ans = i + 1
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9112
#define _CRT_SECURE_NO_WARNINGS
/*                   وتزودوا فإن خير الزاد التقوى                    */
/*       وما تدري نفس ماذا تکسب غدا وما تدري نفس باي ارض تموت      */
#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define endl '\n'
#define ll long long
#define PI acos(-1)
#define watch(x) cerr<<#x<<" = { "<<x<<" }\n"
#define sz(n) n.size()
#define MP(x,y) make_pair (x,y)
#define Mo7med_Sayed fast();
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define RT(v) return cout<<v,0;
#define mem(dp,n) memset(dp,n,sizeof dp)
const double EPS = (1e-7);
const ll OO = INT_MAX, mod = 1e9 + 7;
void run()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
#endif
}
void fast()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll n, m, k, x;
string s,p;

int dp[3003][3003];
int solve(int x, int y) {
    if (x == n || y == m)return 0;
    int &ret = dp[x][y];
    if (~ret)return ret;
    ret = 0;
    if (s[x] == p[y])
        ret = solve(x + 1, y + 1) + 1;
    ret = max(solve(x + 1, y), ret);
    ret = max(solve(x  , y+1), ret);
    return ret;
}
 void build(int x, int y) {
     if (x == n || y == m)return;
     if (s[x] == p[y]) {
         cout << s[x];
         build(x + 1, y + 1);
     }
     else  if (solve(x+1,y) >solve(x,y+1))
     {
         build(x + 1, y);
     }
     else  build(x, y + 1);
}

int main()
{
    //run();
    Mo7med_Sayed;
    cin >> s >> p;
    n = sz(s), m = sz(p);
    mem(dp, -1);
    solve(0, 0);
    build(0, 0);
}


Measured memory_bytes: 35840
import collections
N, K = map(int, input().split())
l = list(input().split())

c = collections.Counter(l)
c = c.most_common()
cnt = 0
if len(c) - K > 0:
    for i in range(1 , len(c) - K + 1):
        cnt += c[-i][1]

print(cnt)

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

int main(){
    int k;
    vector<int> p(5);
    for (int i = 0;i < 5;i++){
        cin >> p.at(i);
    }
    cin >> k;
    
    sort(p.begin(),p.end());
    if (p.back() - p.front() <= k){
        cout << "Yay!" << endl;
    }
    else {
        cout << ":(" << endl;
    }
}

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

int main() {
  int s;
  cin >> s;
  
  int i = 0;
  vector<int> a(1);
  a[0] = s;
  
  while(1) {
    if(a[i]%2 == 0) a.push_back(a[i]/2);
    else a.push_back(3*a[i]+1);
    i++;
    
    for(int j=0; j<i; j++) {
      if(a[j] == a[i]) {
        cout << i+1 << endl;
        return 0;
      }
    }
  }
      
  
}


Measured memory_bytes: 256
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[])
{
	LL n;
	cin >> n;
	vector<LL> a(n + 1);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	a[n] = (1 << 30) - 1;
	LL ans = 0;
	LL left = 0, x = 0;
	for (LL i = 0; i <= n; ++i) {
		while (left < i && (((x ^ a[i]) != (x | a[i])) || i == n)) {
			LL d = i - left;
			ans += d;
			x ^= a[left];
			++left;
		}
		x ^= a[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792