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

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

	while ( true )
	{
		int n, m;
		cin >> n >> m;

		if ( !( n | m ) )
		{
			break;
		}

		vector<PII> place( m );
		REP( i, 0, m )
		{
			place[i].snd = i + 1;
		}

		REP( i, 0, n )
		{
			REP( j, 0, m )
			{
				int tmp;
				cin >> tmp;
				place[j].fst -= tmp;
			}
		}

		sort( ALL( place ) );

		REP( i, 0, m )
		{
			if ( i )
			{
				cout << ' ';
			}
			cout << place[i].snd;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>
#include <string.h>

int main(void) {
  int n = 0, k = 0, d = 0;
  int i, j;
  int sunuke[100] = {0};
  scanf("%d %d", &n, &k);
  for(i = 0; i < k; i++) {
    scanf("%d", &d);
    for(j = 0; j < d; j++) {
      int x;
      scanf("%d ", &x);
      sunuke[x-1]++;
    }
  }
  
  int ans = 0;
  for(i = 0; i < n; i++) {
    if(sunuke[i] == 0) {
      ans++;
    }
  }
  
  printf("%d\n", ans);
  
  return 0;
}

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

int main()
{
  int n,k;
  cin>>n>>k;
  int x=1;

  for(int i=0;i<n;i++)
  {
    int a,b;
    a=x*2;
    b=x+k;
    if(a<=b)
    {
      x=a;
    }
    else
    {
      x=b;
    }
  }
  cout<<x<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void codeforces()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
string convert(int a) {
    string s;
    map<int, char> m;
    for(char c = 'a'; c<'z'; c++) m[c - 'a' + 1] = c;
    m[0] = 'z';
    while( a> 0){
        s+= m[a%26];
        if( a%26 == 0) a = a/26 - 1;
        else a = a/26;
    }
    reverse(s.begin(), s.end());
    return s;
}
int32_t main()
{
    
    // w(t)
    {
        int n;
        cin>>n;
        int a[n];
        int x = 0;
        for(int i=0; i<n; i++){ 
            cin>>a[i];
            x^= a[i];       
        }
        for(int i=0; i<n; i++) cout<<(x^a[i])<<" ";
        
    }
    return 0;
}

Measured memory_bytes: 5172
import sys
for i in sys.stdin.readlines(): 
    nums = list(map(int,i.split()))
    h = nums[0]
    w = nums[1]
    if h == 0 and w == 0:
        break
    for j in range(1,h+1):
        if h == 1 and w == 1:
            print("#")
        elif j % 2 == 1:
            if w % 2 == 1:
                x = int((w-1)/2)
                print("#."*x +"#")
            else:
                x = int(w/2)
                print("#."*x)
        elif j % 2 == 0:
            if w % 2 == 1:
                x = int((w-1)/2)
                print(".#"*x +".")
            else:
                x = int(w/2)
                print(".#"*x)
    print("")

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

#define REP(i,n) for(decltype(n) i=0; i<(n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define st first
#define nd second
#define pb push_back

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

void solve(){
    int h,w,d;
    cin>>h>>w>>d;
    const char colors[] {'R','G','B','Y'};
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            int a = j+i;
            int b = j-i;
            a %= 2*d;
            if(b<0) b=2*d-(-b)%(2*d);
            b %= 2*d;
            int color = 0;
            if(a >= d)
                color += 1;
            if(b >= d)
                color += 2;
            cout<<colors[color];
        }
        cout<<'\n';
    }
}

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


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] heights = new int[n];
        for (int i=0; i<n; i++) {
            heights[i] = sc.nextInt();
        }

        int[] dp = new int[n];
        for (int i=0; i<n; i++) {
            dp[i] = Integer.MAX_VALUE;
        }
        dp[0] = 0;

        for (int i=1; i<n; i++) {
            for (int j=Math.max(i - k, 0); j<i; j++) {
                dp[i] = Math.min(dp[i], dp[j] + Math.abs(heights[i] - heights[j]));
            }
        }
        System.out.println(dp[n - 1]);
    }
}


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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
    
    if((b-a)==(c-b)){
      cout<<"YES"<<endl;
    }
  
     if((b-a)!=(c-b)){
      cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

void a_swap(char C[][3], int i)
{
  char temp1;
  char temp2;

  temp1=C[i][0];
  C[i][0]=C[i-1][0];
  C[i-1][0]=temp1;

  temp2=C[i][1];
  C[i][1]=C[i-1][1];
  C[i-1][1]=temp2;
}

void b_swap(char C[][3], int j ,int minj)
{
  char temp1;
  char temp2;

  temp1=C[j][0];
  C[j][0]=C[minj][0];
  C[minj][0]=temp1;

  temp2=C[j][1];
  C[j][1]=C[minj][1];
  C[minj][1]=temp2;
}

void b_sort(char C[][3], int n)
{
  int i,j;

  for (i=0; i<n; i++) {
    for (j=n-1; j>i; j--) {
      if (C[j][1]<C[j-1][1]) {
        a_swap(C,j);
      }
    }
  }
}

void s_sort(char C[][3], int n)
{
  int i,j;
  int minj;

  for (i=0; i<n; i++) {
    minj=i;
    for (j=i; j<n; j++) {
      if (C[j][1]<C[minj][1]) {
        minj=j;
      }
    }
    b_swap(C,i,minj);
  }
}

int main(void)
{
  char card[53][3];
  char tcard[53][3];
  char *temp;
  int n;
  int i,j;
  int cnt[100];
  int l=0;
  int judge=0;

  scanf("%d",&n);
  
  for (i=0; i<n; i++) {
    scanf("%s",card[i]);
  }

  for (i=0; i<n; i++) {
    for (j=0; j<3; j++) {
      tcard[i][j]=card[i][j];
    }
  }
  
  b_sort(card,n);

  for (i=0; i<n; i++) {
    if (i!=n-1) printf("%s ",card[i]);
    else printf("%s\n",card[i]);
  }
  puts("Stable");

  s_sort(tcard,n);

  for (i=0; i<n; i++) {
    if (i!=n-1) printf("%s ",tcard[i]);
    else printf("%s\n",tcard[i]);
  }

  for (i=0; i<n; i++) {
    cnt[i]=strcmp(*(card+i),*(tcard+i));
    if (cnt[i]!=0) {
      judge=1;
      break;
    }
  }

  if (judge==1) printf("Not stable\n");
  else puts("Stable");

  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
 
using namespace std;
using LL = long long int; 

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.st <<","<<P.nd <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

bool isPalindrome(string str)
{
  // cout << str << endl;
  int low = 0;
  int high = str.length() - 1;
  
  while (low < high)
  {
    // if mismatch happens
    if (str[low] != str[high])
      return false;

    low++;
    high--;
  }
  
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  
  debug(((n - 1) / 2), (n + 3) / 2);
  if (isPalindrome(s) && isPalindrome(s.substr(0, (n - 1) / 2)) && isPalindrome(s.substr((n + 3) / 2 - 1))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int N = 5e2 + 7;
 
long long t[N][N];
long long n, m, h, w;
 
int main() {
	cin >> n >> m >> h >> w;
	long long ps = n * m * 500;
	for (int i = h; i <= n; i += h) {
		for (int j = w; j <= m; j += w) {
			t[i][j] = -1 * (h * w - 1) * 500 - 1;
			ps += t[i][j] - 500;
		}
	}
	if (ps > 0) {
		cout << "Yes" << endl;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				if (!t[i][j])
					t[i][j] = 500;
				cout << t[i][j] << " ";
			}
			cout << endl;
		}
	}
	else
		cout << "No";
	return 0;
}


Measured memory_bytes: 3328
import sys
N, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, sys.stdin.readline().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
X = [0] * N
for _ in range(Q):
    p, x = map(int, sys.stdin.readline().split())
    X[p-1] += x

ans = [0] * N
done = set()
todo = [(0, X[0])]
while todo:
    i, sumx = todo.pop()
    ans[i] = sumx
    done.add(i)
    for ni in G[i]:
        if ni in done:
            continue
        todo.append((ni, sumx + X[ni]))
print(" ".join(map(str, ans)))

Measured memory_bytes: 83100
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
using P = pair<int64, int64>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
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; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        os << "\n";
    }
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;

int N;
vector<string> ans;
void dfs(string& res, int remain, int turn){
    if(remain==0){
        ans.emplace_back(res);
        return;
    }
    int i=0;
    while(res[i]!='.'){
        i++;
    }
    res[i] = turn+'a';
    remain--;
    
    REP(mask,1<<remain){
        int i=0;
        string tmp = res;
        REP(j,remain){
            while(i<N and tmp[i]!='.'){i++;}
            if(mask>>j&1) tmp[i] = turn+'a';
            i++;
        }
        dfs(tmp, remain-__builtin_popcount(mask), turn+1);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    string s(N,'.');
    dfs(s, N, 0);
    sort(ALL(ans));
    cout << ans;
}

Measured memory_bytes: 7796
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main(void){
    char tmp[1000];
    //??\???
    fgets(tmp,sizeof(tmp),stdin);
    int num1=atoi(strtok(tmp," "));
    int num2=atoi(strtok(NULL," "));
    //?°???°?????????????????¨
    double fnum1=num1;
    double fnum2=num2;
    
    //????????¨??????
    printf("%d %d ",num1/num2,num1%num2); 
    printf("%f\n",fnum1/fnum2);

return 0;
}

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

int distance(int *x, int d) {
  int sum = 0;
  for (int i = 0; i < d; ++i) {
    sum += x[i] * x[i];
  }
  return (int)sqrt(sum);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  int n, d;
  cin >> n >> d;
  int x[10][10];
  rep(i, n) {
    rep(j, d) {
      cin >> x[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i+1; j < n; ++j) {
      int sum = 0;        
      for (int k = 0; k < d; ++k) {
        int d = (x[i][k] - x[j][k]);
        sum += d*d;
      }
      int d = sqrt(sum);
      if (sum == d * d) { ans++; }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  double a, b, n, d;
  int c;
  cin >> a >> b;
  c = (a + b) / 2;
  n = (a + b) / 2;
  d = (n - c) * 2;  
  cout << c + d << endl;
}


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

int main() {
  int n, m;
  long long p[1000];

  while(1) {
    cin >> n >> m;
    if (n == 0 && m == 0) break;

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

    sort(p, p+n, std::greater<long long>());

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

    cout << ans << endl;
  }

}

Measured memory_bytes: 3056
import Data.List
import Data.Char
import Control.Applicative

type Card = (Char, Int)

bubbleSort :: [Card] -> [Card]
bubbleSort xs = loop (1, xs)
  where
    loop (0, xs) = xs
    loop (1, xs) = loop $ foldr f (0, xs) [0 .. length xs - 2]
    f i (flag, xs)
      | (snd b) > (snd c) = (1, as ++ c : b : ds)
      | otherwise         = (flag, xs)
      where (as, b : c : ds) = splitAt i xs

findMinimumIndex :: [Card] -> Int
findMinimumIndex (x : xs) = (\(minj, _, _) -> minj) $ foldl f (0, 1, x) xs
  where f (minj, i, v) x = if (snd x) < (snd v) then (i, i + 1, x) else (minj, i + 1, v)

swapMinimum :: [Card] -> Int -> [Card]
swapMinimum xs i = if i > 0 then b : as ++ a : bs else xs
  where (a : as, b : bs) = splitAt i xs

selectionSort :: [Card] -> [Card]
selectionSort xs = foldl f xs [0 .. length xs - 2]
  where
    f xs i = as ++ ys
      where
        (as, bs) = splitAt i xs
        ys = swapMinimum bs $ findMinimumIndex bs

test :: [Card] -> [Card]
test xs = sortBy (\a b -> compare (snd a) (snd b)) xs

main :: IO ()
main = do
  _  <- getLine
  xs <- map (\[a, b] -> (a, digitToInt b)) . words <$> getLine
  let tl = test xs
  display (bubbleSort xs) tl
  display (selectionSort xs) tl
    where
      display xs ys = do
        putStrLn $ unwords $ map (\(a, b) -> (a : show b)) xs
        putStrLn $ if xs == ys
          then "Stable"
          else "Not stable"



Measured memory_bytes: 4064
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>

using namespace std;

int n, w[100];
int s1, s2, ans = 9999999;

int main(){


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


	for (int i = 0; i < n; i++){
		for (int j = 0; j < i; j++){
			s1 += w[j];
		}
		for (int k = 0; k < n; k++){
			s2 += w[k];
		}
		s2 = s2 - s1;

		int kari = abs(s2 - s1);

		if (kari < ans){
			ans = kari;
		}
		s1 = 0;
		s2 = 0;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdlib.h>

using LL = long long ;

void bad()
{
    puts("NO");
    exit(0);
}

int main()
{
    int n;
    scanf("%d", &n);
    std::vector<LL> a(n);
    for (int i = 0; i < n; ++ i) scanf("%lld", &a[i]);
    LL sum = std::accumulate(a.begin(), a.end(), 0ll);
    if (sum % (n * 1ll * (n + 1) / 2)) {
        bad();
    }
    LL step = sum / (n * 1ll * (n + 1) / 2);
    std::vector<LL> b(n);
    for (int i = 0; i < n; ++ i) {
        b[i] = a[i] - a[(i + n - 1) % n] - step;
        if (b[i] > 0 || -b[i] % n) {
            bad();
        }
    }
    puts("YES");
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

const int mod = 1000000007;

struct mint{
  ll x;
  mint(ll x = 0):x((x % mod + mod) % mod){};
  mint pow(ll y) const {
    mint res(1);
    mint a(x);
    while(y>0){
      if(y&1) res *= a;
      a *= a;
      y >>= 1;
    }
    return res;
  }
  mint inv() const{ return pow(mod-2); }
  mint& operator+= (const mint a) noexcept {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-= (const mint a) noexcept {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*= (const mint a) noexcept {
    (x *= a.x) %= mod;
    return *this;
  }
  mint& operator/= (const mint a) noexcept {
    return (*this) *= a.inv();
  }
  mint operator+ (const mint a) const noexcept {
    mint res(*this);
    return res += a;
  }
  mint operator- (const mint a) const noexcept {
    mint res(*this);
    return res -= a;
  }
  mint operator* (const mint a) const noexcept {
    mint res(*this);
    return res *= a;
  }
  mint operator/ (const mint a) const noexcept{
    mint res(*this);
    return res /= a;
  }
};

ostream& operator<<(ostream& stream, const mint& n){
  stream << n.x;
  return stream;
};

struct comb{
  vector<mint> fact, ifact;
  comb(int n): fact(n+1), ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i <= n; i++) fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k) const noexcept{
    if(k < 0 || n < k) return 0;
    return fact[n] * ifact[k] * ifact[n-k];
  }
};

int main(void){
  ll n;
  cin >> n;
  comb c(n+1);
  vector<ll> a(n+1);
  vector<vector<ll>> v(n);
  REP(i, n+1) cin >> a[i], v[--a[i]].emplace_back(i);
  ll l, r;
  REP(i, n){
    if(v[i].size() == 2){
      l = v[i][0];
      r = v[i][1];
    }
  }
  ll d = r-l+1;
  REP(i, n+1){
    ll k = i+1;
    cout << c(n+1, k) - c(n+1-d, k-1)  << endl;
  }
  return 0;
}

Measured memory_bytes: 9088
defmodule Main do
  def main do
    k=IO.gets("") |> String.trim |> String.to_integer
    [a,b]=IO.gets("") |> String.trim |> String.split(" ") |> Enum.map(&String.to_integer(&1))
    if(a<= div(b,k)*k) do
    IO.puts("OK")
    else
    IO.puts("NG")
    end    
  end
end


Measured memory_bytes: 30664
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
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;}
int N;
ll A[100100];
int l[100100];
int r[100100];
int sgn(int x){
	if(x>0)return 0;
	else return 1;
}
int main(){
	cin >> N;
	ll sum = 0ll;
	ll mi = INF;
	bool zero = false;
	for(int i=0;i<N;i++){
		cin >> A[i];
		if(A[i]==0)zero = true;
		sum += abs(A[i]);
		mi = min(mi,abs(A[i]));
	}
	if(zero){
		cout << sum << endl;
		return 0;
	}
	int pre = 0;
	for(int i=0;i<N-1;i++){
		if((pre+sgn(A[i]))%2==1){
			l[i]=1;
		}else{
			l[i]=0;
		}
		pre = l[i];
	}
	pre = 0;
	for(int i=N-1;i>0;i--){
		if((pre+sgn(A[i]))%2==1){
			r[i]=1;
		}else{
			r[i]=0;
		}
		pre = r[i];
	}
	/*for(int i=0;i<N;i++){
		cout << l[i] << ' ';
	}
	cout << endl;
	for(int i=0;i<N;i++){
		cout << r[i] << ' ';
	}
	cout << endl;*/
	bool flag = false;
	for(int i=1;i<N-1;i++){
		if((sgn(A[i])+l[i-1]+r[i+1])%2==0){
			flag = true;
			break;
		}
	}
	if((sgn(A[0])+r[1])%2==0)flag = true;
	if((sgn(A[N-1])+l[N-2])%2==0)flag = true;
	if(flag)cout << sum << endl;
	else cout << sum - mi*2 << endl;
	return 0;
}

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

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<ll> factorList(ll x) {
    vector<ll> res;
    for (int p : primes) {
      while (x%p == 0) {
        res.push_back(p);
        x /= p;
      }
    }
    if (x != 1) res.push_back(x);
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<ll> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<pair<ll,int>> res(1, P(fl[0], 0));
    for (ll p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  ll n;
  cin >> n;
  Sieve s(1000005);
  auto fs = s.factor(n);
  int ans = 0;
  for (auto p : fs) {
    int x = p.second;
    int b = 1;
    while (b <= x) {
      x -= b;
      b++;
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7836
import java.util.Scanner;
public class Main{


	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		
		int a,b;
		a=sc.nextInt();
		b=sc.nextInt();
		
		while(a!=0 || b!=0){
			
			System.out.println(b>a?a+" " +b:b+" "+a);
			a=sc.nextInt();
			b=sc.nextInt();
		}
		
	}

}

Measured memory_bytes: 27220
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;


int n, m;
vector<int> adj[(int)2e5];
int cnt[(int)2e5][2];
string s;

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

	cin >> n >> m >> s;
	/*
	n = (int)2e4;
	s = string(2, 'A') + string(n - 2, 'B');
	vector<pair<int, int>> edges = {
		{1, 2},
		{2, 3},
		{3, 3}
	};

	for (int i = 3; i <= n; ++i)
		edges.push_back({ 1, i });

	m = edges.size();
	*/

	for (int i = 0; i < m; ++i) {
		int a, b;
		// tie(a, b) = edges[i];
		cin >> a >> b;
		--a, --b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	queue<int> q;
	for (int i = 0; i < n; ++i) {
		for (char c = 'A'; c <= 'B'; ++c)
			cnt[i][c - 'A'] = count_if(adj[i].begin(), adj[i].end(), [&c](const int &x) { return s[x] == c; });
		if (any_of(cnt[i], cnt[i] + 2, [](const int &x) { return x == 0;  }))
			q.push(i);
	}

	auto removed = [](const int u) {
		assert(cnt[u][0] >= 0 && cnt[u][1] >= 0);
		return !cnt[u][0] || !cnt[u][1];
	};

	while (!q.empty()) {
		const int u = q.front();
		q.pop();
		assert(removed(u));
		for (const int &v : adj[u])
			if (!removed(v) && --cnt[v][s[u] - 'A'] == 0)
				q.push(v);
	}

	const bool ans = any_of(cnt, cnt + n, [](const int c[]) { return c[0] && c[1];  });
	cout << (ans ? "Yes" : "No") << '\n';
	return 0;
}

Measured memory_bytes: 12368
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int H, W;
  cin >> H >> W;
  char s[H][W];
  // bool visit[H][W];
  int dist[H][W];
  int black = 0;
  REP(i, H) REP(j, W) {
    cin >> s[i][j];
    dist[i][j] = 1e9;
    if (s[i][j] == '#') black++;
  }
  int dy[4] = {-1, 0, 1, 0};
  int dx[4] = {0, 1, 0, -1};
  queue<P> que;
  que.push(P(0, 0));
  dist[0][0] = 0;
  while (que.size()) {
    P p = que.front();
    que.pop();
    REP(i, 4) {
      int ny = p.first + dy[i];
      int nx = p.second + dx[i];
      if (0 <= ny && ny < H && 0 <= nx && nx < W && s[ny][nx] != '#' &&
          dist[ny][nx] == 1e9) {
        que.push(P(ny, nx));
        dist[ny][nx] = dist[p.first][p.second] + 1;
      }
    }
  }
  if (dist[H - 1][W - 1] == 1e9)
    cout << -1 << endl;
  else {
    int route = 0;
    cout << H * W - (black + dist[H - 1][W - 1] + 1) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
S = input()
ans = 0
cnt_a = 0
pc = "."
for c in S:
    #print(c, cnt_a)
    if pc=="B":
        if c=="C":
            ans += cnt_a
        elif c=="A":
            cnt_a = 1
        else:
            cnt_a = 0
    else:
        if c=="C":
            cnt_a = 0
        elif c=="B":
            pass
        else:
            cnt_a += 1
    pc = c

print(ans)


Measured memory_bytes: 3500
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void solve(long long A, long long B, long long C) {
  if (A % 2 != 0 || B % 2 != 0 || C % 2 != 0) {
    print(0);
    return;
  }

  ll cnt = 0;
  ll x1 = abs(A - B);
  ll x2 = abs(B - C);
  ll x3 = abs(C - A);
  while (x1 % 2 == 0 && x2 % 2 == 0 && x3 % 2 == 0) {
    cnt++;
    ll x1Tmp = x1 / 2;
    ll x2Tmp = x2 / 2;
    ll x3Tmp = x3 / 2;

    if (x1 == x1Tmp && x2 == x2Tmp && x3 == x3Tmp) {
      print(-1);
      return;
    }

    x1 = x1Tmp;
    x2 = x2Tmp;
    x3 = x3Tmp;
  }
  print(cnt);
}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  solve(A, B, C);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    string s;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        int ans = 0;
        sort(s.begin(),s.end());
        ans -= stoi(s);
        reverse(s.begin(),s.end());
        ans += stoi(s);
        cout << ans << "\n";
    }
    return 0;
}


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

#define mp make_pair
#define pb push_back

using namespace std;

int n;
pair<int, int> a[111111];
long long cnt[111111];

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d",&n);
	for(int i = 1; i <= n; ++i){
		scanf("%d",&a[i].first);
		a[i].first *= -1;
		a[i].second = i;
	}
	sort(a + 1, a + 1 + n);
	int pr = 1, i = 2;
	while (pr <= n){
		while (i <= n && a[i].second > a[pr].second) ++i;
		cnt[a[pr].second] = 1ll * pr * (-a[pr].first + a[i].first);
		for(int j = pr + 1; j < i; ++j) cnt[a[pr].second] += -a[j].first + a[i].first;
		pr = i;
		++i;
	}
	for(int i = 1; i <= n; ++i) printf("%lld\n",cnt[i]);
	return 0;
}

Measured memory_bytes: 2688
#106b
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
  
N = int(input())
ans = 0
for i in range(1,N+1):
  if i%2==1 and len(make_divisors(i))==8:
    ans += 1
print(ans)

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

using namespace std;

int a, b, c, d, e;

int main(){
	scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
	
	int res = 0;
	
	if(b <= 0)
	return 0 * printf("%d\n",(b - a) * c);
	else{
		if(a <= 0)
		return 0 * printf("%d\n", abs(a) * c + d + b * e);
		return 0 * printf("%d\n", (b - a) * e);
	}
}



Measured memory_bytes: 3232
#pragma region Macros
// ===========
// include
// ===========
#include <bits/stdc++.h>

using namespace std;

// ===========
// typedef
// ===========
typedef int64_t int64;
typedef vector<int64> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;

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

// ===========
// math
// ===========
template<class T> inline T sqr( T x ){ return x * x; }
inline int64 Factorial( int64 n ){ return n == 0 ? 0 : ( n == 1 ? 1 : Factorial( n - 1) * n  ); }

// ===========
// repetition
// ===========
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a), __length = int(b); i < __length; ++i)

void input(vector<int64> *vec, const int size){ vec->resize(size); rep(i, size) { cin >> vec->at(i); } }
void input(vector<string> *vec, const int size){ vec->resize(size); rep(i, size) { cin >> vec->at(i); } }

#pragma endregion //Macros

int main()
{
    int L, R, d;
    cin >> L >> R >> d;
    L -= 1;
    int ans = R / d - L / d;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
import java.lang.Math.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        int[] colors = new int[n];
        Arrays.fill(colors,-1);
        int idex =0;
        int next;int cur=0;
        for(int i=0;i<n;i++){
            cur = in.nextInt();
            int l=0;int r= idex;
            while (l!=r){
                next = (int)Math.floor((l+r)/2);
                if (colors[next]<cur)r=next;
                else l=next+1;
            }
            if (colors[r]<cur) colors[r]=cur;
            else {
                idex++;
                colors[idex]=cur;
            }
        }
        System.out.println(idex+1);

    }
}


Measured memory_bytes: 51392
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
using namespace std;
int main(){
  ll n;
  cin>>n;
  if(n%2==0){

   cout<<"0.5";
  }
  else {
    ld p=(n+1.0)/(2.0*n);
    cout<<fixed<<setprecision(6)<<p;


  }









}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
int main() {
	int n;
	int arr[100];
	int sum = 0, ave;
	cin >> n;
	REP(i, 0, n) {
		cin >> arr[i];
		sum += arr[i];
	}
	if ((sum + n * 1000) % n > n / 2) {
		ave = (sum + n * 1000) / n + 1 - 1000;
	} else {
		ave = (sum + n * 1000) / n - 1000;
	}
	int ans = 0;
	REP(i, 0, n) {
		ans += (arr[i] - ave) * (arr[i] - ave);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
long long int P=pow(10,9)+7;
//n^sを計算、mod m
long long int KurikaeshiJijou(long long int n,long long int s, long long int m){
	if(s==0) return 1;
	if(s%2==0){
		long long int t= (KurikaeshiJijou(n,s/2,m))%m;
		return ((t%m)*(t%m))%m;	
	}else{
		return (n * KurikaeshiJijou(n,s-1,m))%m;
	}
}


int main(void){
	long long int N,a,b;
	long long int ans=1;
	scanf("%lld %lld %lld",&N,&a,&b);
	ans=KurikaeshiJijou(2,N,P);
	ans--;
	//nCk=x/y=x*y^10^5-2
	long long int x=1;
	long long int y=1;
	for(int s=0;s<a;s++){
		x=(x*(N-s))%P;
		y=(y*(s+1))%P;
	}
	x=(x*(KurikaeshiJijou(y,P-2,P)))%P;
	ans-=x;
	x=1;
	y=1;
	for(int s=0;s<b;s++){
		x=(x*(N-s))%P;
		y=(y*(s+1))%P;
	}
	y=KurikaeshiJijou(y,P-2,P)%P;
	x=(x*y)%P;
	ans-=x;
	while(ans<0){
		ans+=P;
	}

	printf("%lld",ans);
}

Measured memory_bytes: 128
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<random>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int a[26]={},b[26]={};
  string s,t;
  cin >> s >> t;
  for(int i=0; i<s.size(); i++) {
    a[s[i]-'a']++;
  }
  for(int i=0; i<t.size(); i++) {
    b[t[i]-'a']++;
  }
  sort(a,a+26,greater<int>());
  sort(b,b+26,greater<int>());
  for(int i=0; i<26; i++) {
    if(a[i]!=b[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
 }

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

int N;
int ans;

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		int a; scanf("%d", &a);
		if (i % 2 == 1) {
			if (a % 2 == 1) ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3812
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//const int mod = 1e9+7;
int nums[6];

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main()
{
    quickread();
    cin >> nums[1] >> nums[2] >> nums[3] >> nums[4] >> nums[5];
    for(int i = 1; i <= 5; i ++) {
        if(nums[i] == 0) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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


signed main() {
    int m,k;
    cin>>m>>k;
    if(k>=(1<<m))cout<<-1;
    else{
        if(m!=1){
        for(int i=0;i<(1<<m);i++){
            if(i!=k)cout<<i<<' ';
        }
        cout <<k<<' ';
        for(int i=(1<<m)-1;i>=0;i--){
            if(i!=k)cout<<i<<' ';
        }
        cout <<k<<' ';
        }else{
            if(k==1)cout<<-1;
            else cout<< "0 0 1 1";
        }
    }



   


    return 0;


}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  double A,B;
  cin >> A >> B;
  for(int i = 0; i < 2000; i++){
    double tax_8 = i*0.08;
    if(floor(tax_8) == A){
      double tax_10 = i*0.1;
      if(floor(tax_10) == B){
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long ll;

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

	int N;
	cin >> N;
	ll rem = 0, ans = 0;
	for(int i = 0; i < N; i++) {
		ll A;
		cin >> A;
		ll sum = A + rem;
		ans += sum / 2;
		if(A == 0 && rem == 1) {
			rem = 0;
		}
		else {
			rem = sum % 2;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
B = int(input())
T, A = map(int, input().split())
N = map(int, input().split())
i = 9999
j = 1
for ids,k in enumerate(N):
  if abs(A - (T - k * 0.006)) < i : 
    i = abs(A - (T - k * 0.006))
    j = ids

print(j + 1)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
    int x=0,p=0;
};
bool cmp(node a,node b)
{
   return   a.x<b.x;
}
int main()
{   node a[100005];
    node b[100005];
    int l=1,n,i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i].x);
        a[i].p=i;
    }
    sort(a+1,a+n+1,cmp);
    int ans=0;
    for(i=1;i<=n;i++)
    {
        if(abs(a[i].p-i)%2!=0)
        {
            ans++;
        }
    }
    printf("%d\n",ans/2);
    return 0;
}

Measured memory_bytes: 896
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    long sum = 0;
    long[] a = new long[n];
    for (int i=0;i<n;i++){
      a[i] = scan.nextLong();
    }

    Arrays.sort(a);

    sum += a[n-1];
    int count = 1;
    int many = (int) (n-2)/2;

    for (int i=0;i<many;i++){
      sum += 2*a[n-2-i];
    }

    if (many*2 != n-2){
      sum += a[n-2-many];
    }

    System.out.println(sum);
  }
}


Measured memory_bytes: 61656
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(a) ll((a).size())
#define all(a) (a).begin(), (a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPD(i,n) for(int i=(n)-1;i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
const ll MOD = 1E9+7;
const ll INF = 1E18;
const double EPS = 1E-9;
const double PI = atan(1.0) * 4.0;
template<class T> T getbit(T s, int i) {return s>>i&1;}
template<class T> void flipbit(T& s, int i) {s^=(1LL<<i);}
constexpr int cntbit(ll x) {return __builtin_popcountll(x);}
constexpr int lg2(ll x) {return __lg(x);} // return int(log2(x))
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
ll fpow(ll a,ll p){ll res=1LL;while(p){if(p&1LL) res=res*a%MOD;a=a*a%MOD;p>>=1LL;} return res;}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	ll res=0;
	int n;cin>>n;
	ll best=INF;
	REP(i,n){
		ll a,b;
		cin>>a>>b;
		res+=a;
		if(a>b) best=min(best,b);
	}
	if(best==INF) exit(puts("0\n")*0);
	cout<<res-best<<'\n';
}



Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n;
    scanf("%d",&n);
    ll a[n+5];
    map < ll , ll > mp,fin;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        mp[a[i]]++;
    }
    long long tot=0;
    for(auto i : mp)
    {
        if(i.second>=2)
            tot+=(i.second*(i.second-1))/2;
    }
    for(int i=1;i<=n;i++)
    {
        long long x=mp[a[i]];
        long long temp=tot;
        temp-=(x*(x-1))/2;
        x--;
        temp+=(x*(x-1))/2;
        printf("%lld\n",temp);
    }
}


Measured memory_bytes: 11008
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
数値型から文字列に変換　to_string(number);これは簡単
文字列から数値型に変換　stoi(number)
文字列からllに変換　stoll(number)*/

//ここから書き始める
const int maxn=100000+10;
int a[maxn];
int b[maxn];
int N,Q;
bool search(int key){
	int left = 0;
	int right = N;
	while(left<=right){
		int mid=left+(right-left)/2;
		if(a[mid]==key)return true;
		else if(a[mid] < key) left = mid + 1;
		else if(a[mid] > key) right = mid - 1;
	}
	return false;
}
int main(){
	cin >> N;
	rep(i,N) cin>>a[i];
	cin >>Q;
	int cnt = 0;
	rep(i,Q) cin>>b[i];
	rep(i,Q){
		if(search(b[i])) cnt++;
	}
	cout<<cnt<<endl;
}



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

for i in range(n-1):
    a[i+1] += a[i]

left = 1
right = 3

ans = float('inf')

for mid in range(2, n-1):
    p = a[left - 1]
    q = a[mid - 1] - a[left - 1]
    p_next = a[left]
    q_next = a[mid - 1] - a[left]

    while abs(p_next - q_next) <= abs(p - q):
        left += 1
        p = a[left - 1]
        q = a[mid - 1] - a[left - 1]
        p_next = a[left]
        q_next = a[mid - 1] - a[left]

    r = a[right - 1] - a[mid - 1]
    s = a[n - 1] - a[right - 1]
    r_next = a[right] - a[mid - 1]
    s_next = a[n - 1] - a[right]

    while abs(r_next - s_next) <= abs(r - s):
        right += 1
        r = a[right - 1] - a[mid - 1]
        s = a[n - 1] - a[right - 1]
        r_next = a[right] - a[mid - 1]
        s_next = a[n - 1] - a[right]

    ans = min(ans, abs(min(p, q, r, s) - max(p, q, r, s)))

print(ans)

Measured memory_bytes: 25676
N=int(input())
s=False
for i in range(1,3501):
    for j in range(1,3501):
        if (4*i*j-N*i-N*j)>0:
            w=(N*i*j)/(4*i*j-N*i-N*j)
            if w%1==0:
                p=i
                q=j
                s=True
                break
    if s==True:
        break

print("{} {} {}".format(p,q,int(w)))

Measured memory_bytes: 3064
#include <cstdio>
#include <set>
typedef long long ll; 
namespace dsu
{
	int fa[200005]; 
	inline void init(int n)
	{
		for (int i = 0; i < n; i++)
			fa[i] = i; 
	}
	int getfa(int u)
	{
		if (u == fa[u])
			return u; 
		return fa[u] = getfa(fa[u]); 
	}
}
int one[200005], zero[200005], fa[200005]; 
struct comp
{
	inline bool operator ()(const int &a, const int &b) const
	{
		ll x = (ll)one[a] * zero[b], y = (ll)one[b] * zero[a]; 
		if (x == y)
			return a < b; 
		return x < y; 
	}
}; 
std::set<int, comp> se;
int main()
{
	// freopen("AGC023-F.in", "r", stdin); 
	int n; 
	scanf("%d", &n); 
	for (int i = 1; i < n; i++)
	{
		scanf("%d", fa + i);
		fa[i]--; 
	}
	dsu::init(n); 
	for (int i = 0; i < n; i++)
	{
		int x; 
		scanf("%d", &x); 
		(x ? one : zero)[i]++;
	}
	for (int i = 1; i < n; i++)
		se.insert(i);
	ll ans = 0; 
	while (!se.empty())
	{
		int u = *se.begin(); 
		se.erase(se.begin()); 
		int v = dsu::getfa(fa[u]);
		if (v)
			se.erase(v); 
		dsu::fa[u] = v; 
		ans += (ll)one[v] * zero[u]; 
		one[v] += one[u]; 
		zero[v] += zero[u]; 
		if (v)
			se.insert(v); 
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
//#include <iostream>
//#include <iomanip>
//#include <vector>
//#include <cmath>
//#include <algorithm>
using namespace std;


#define F first
#define PB push_back
#define MP make_pair

typedef unsigned long long ll;

ll p = pow(10, 9) + 7;





int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> a(N);
    vector<int> b(N);
    vector<int> c(N);
    for(int i = 0; i < N; i++)
    {
        cin >> a[i];
        cin >> b[i];
        cin >> c[i];
    }
    vector<int> dpA(N);
    vector<int> dpB(N);
    vector<int> dpC(N);
    dpA[0] = a[0];
    dpB[0] = b[0];
    dpC[0] = c[0];
    for(int i = 1; i < N; i++)
    {
        dpA[i] = max(dpB[i - 1] + a[i], dpC[i - 1] + a[i]);
        dpB[i] = max(dpA[i - 1] + b[i], dpC[i - 1] + b[i]);
        dpC[i] = max(dpA[i - 1] + c[i], dpB[i - 1] + c[i]);
    }
    cout << max(dpA[N - 1], max(dpC[N - 1], dpB[N - 1])) << endl;



}


Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>


int main(void){
	int a,b,c;
	int i,j,k;
	int m,n;
	char str[100];
	char d;
	scanf("%d",&a);
	scanf("%s",str);
	scanf("%d",&b);

	d = str[b-1];
	for(i=0;i<a;i++){
		if(str[i]!=d){
			printf("*");
		}else{
			printf("%c",d);
		}
	}
	printf("\n");

	return 0;
}


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


int main()
{
	int n, x,a;
	while (1) {
		a = 0;
		cin >> n >> x;
		if (n == 0 && x == 0)
			break;
		for (int i = 1;i <= n;i++) {
			for (int j = i+1;j <= n;j++) {
				for (int k = j + 1;k <= n;k++)
					if (i + j + k == x)
						a++;
			}
		}
		cout << a << endl;
	}
    return 0;
}


Measured memory_bytes: 3124
n = int(input())
a = sorted((int(x), k) for k, x in enumerate(input().split()))
opt = [[0 for j in range(n + 1)] for i in range(n + 1)]
for i in reversed(range(n)):
    for j in range(i, n):
        val, k = a[j - i]
        opt[i][j] = max(val * abs(k - i) + opt[i + 1][j], val * abs(k - j) + opt[i][j - 1])
print(opt[0][n - 1])


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

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

using ll = long long;
using graph = vector<vector<int>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;
ll dp[100050][2];
ll f(const graph &g, int x,int y){
  if(dp[x][y]!=-1) return dp[x][y];
  dp[x][y]=1LL;
  if(y==0){
    for(auto nx:g[x]){
      dp[x][y]*=(f(g,nx,1))%mod;
      dp[x][y]%=mod;
    }
  }
  if(y==1){
    for(auto nx:g[x]) {
      dp[x][y]*=(f(g,nx,0)+f(g,nx,1))%mod;
      dp[x][y]%=mod;
    }
  }
  return dp[x][y]%=mod;
}

int main() {
  int N;
  cin>>N;
  graph g(N);
  vector<int> cnt(N,0);
  for(int i = 0; i < 100050; i++) for(int j = 0; j < 2; j++) dp[i][j]=-1LL;
  for(int i = 0; i < N-1; i++){
    int x,y;
    cin>>x>>y;
    g[x-1].push_back(y-1);
    g[y-1].push_back(x-1);
  }
  queue<int> bfs;
  vector<bool> seen(N,false);
  bfs.push(0);
  seen[0]=true;
  graph h(N);
  while(!bfs.empty()){
    int x = bfs.front();
    bfs.pop();
    for(auto nx:g[x]){
      if(seen[nx])continue;
      seen[nx]=true;
      h[x].push_back(nx);
      bfs.push(nx);
    }
  }
  cout<<(f(h,0,0)+f(h,0,1))%mod<<endl;
}

Measured memory_bytes: 21504