akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
// const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 1e6+1;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

long long modpow(long long res,long long a, long long n, long long mod) {
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
// ここから開始
int main(){
  ll a,b,k;
  cin>>a>>b>>k;
  if(a>=k){
    a-=k;
  }
  else if(a+b>=k){
    b-=(k-a);
    a=0;
  }
  else{
    a=0;
    b=0;
  }
  cout<<a<<" "<<b<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

#define WMAX 1000
#define NMAX 1000
int main(void)
{
    int W, n;
    int cyc = 0;
    while (cin >> W && W && cin >> n) {
        cyc++;
        int dp[WMAX+1][NMAX+1] = {};
        for (int i = 0; i < n; i++) {
            int v, w;
            scanf("%d,%d", &v, &w);
            for (int j = 0; j < W+1; j++) 
                dp[j][i+1] = max(dp[j][i], (j-w >= 0 ? dp[j-w][i] + v : 0));
        }
        cout << "Case " << cyc << ":" << endl;
        for (int j = 0; j < W+1; j++) {
            if (dp[j][n] == dp[W][n]) {
                cout << dp[j][n] << endl << j << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 5164
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    k = int(input())
    x = int(input())
    y = int(input())

    res = min(n, k) * x + max(0, (n - k) * y)
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <iomanip>
#include <map>
#include <bits/stl_numeric.h>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


int main(){

    string s[3];
    REP(i,3)cin >> s[i];

    vector <int> num(3, 0);

    //ターン:0(Aさん),1(Bさん),2(Cさん)
    int turn = 0;
    bool flg = true;
    string res;

    while(flg)
    {

        for(int i = 0; i < 3; ++i)
        {
            if(turn == i)
            {
                turn = (int)s[i][num[i]] - (int)'a';
                ++num[i];
                if(num[i] > s[i].size())
                {
                    res = 'A' + i;
                    flg = false;
                    break;
                }
            }
        }
    }


    cout << res << endl;

    return 0;
}



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

int main(void){
  int m, h;
  int i, k, len;
  char card[201];

  scanf(" %s", card);
  while(strcmp(card, "-")){
    scanf("%d", &m);
    len = (int)strlen(card);
    k = 0;
    for(i = 0; i < m; i++){
      scanf("%d", &h);
      k = (k + h) % len;
    }
    for(i = 0; i < len; i++){
      printf("%c", card[(i+k)%len]);
    }
    printf("\n");
    scanf(" %s", card);
  }
  return 0;
}

Measured memory_bytes: 568
import math
  
a,b,c = [ float(s) for s in input().split() ]

height = b * math.sin(math.radians(c))
area = a * height /2
l = math.sqrt(height**2 + (a - b * math.cos(math.radians(c)))**2)
length = a + b +  l
print(area)
print(length)
print(height)


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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main() {

    long long int k;
    cin >> k;
    string s;
    cin >> s;

    if ( s.size() <= k ) {
        cout << s << endl;
    } else {
        for ( long long int i = 0; i < k; i++ ) {
            cout << s[i];
        }
        cout << "..." << endl;
    }

    return 0;

}


Measured memory_bytes: 3624
import java.util.Scanner

object Main {
  val sc = new Scanner(System.in)
  def main(args: Array[String]): Unit = {
    val n = sc.nextInt
    val qn = sc.nextInt
    val s = sc.next
    val ql = List.fill(qn){(sc.nextInt, sc.nextInt)}

    val sl = buildSum(s)

    ql.foreach{q =>
      println(sl(q._2 - 1) - sl(q._1 - 1))
    }
  }

  def buildSum(str: String): Vector[Int] ={
    str.split("(?<=.)").foldLeft((Vector.empty[Int], false)){ case ((l,flgA), s) =>
      if (l.isEmpty) (Vector(0), s == "A")
      else
        s match{
          case x if "ATG".contains(x) => (l :+ l.last, s == "A")
          case "C" => if (flgA) (l :+ (l.last + 1), false) else (l :+ l.last, false)
        }
    }._1
  }
}

Measured memory_bytes: 100520
val = gets.to_i
ans = {
  hour: 0,
  minute: 0,
  second: 0
}

while true do
  if 3599 < val #????????? 60 * 60
    val -= 3600
    ans[:hour] += 1
  elsif 59 < val #??????
    val -= 60
    ans[:minute] += 1
  else
    ans[:second] = val
    break
  end
end

puts "#{ans[:hour]}:#{ans[:minute]}:#{ans[:second]}"

Measured memory_bytes: 8680
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>

int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i < n;i++) cin >> a[i];
    int max =0;
    for(int i=0;i < n-1;i++){

        for(int j = i + 1;j < n;j++){

            if(max < abs(a[i] - a[j])){
                max = abs(a[i] - a[j]);
            }
        }



    }

    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define mp(a, b) make_pair((a),(b))
#define bs(n) ((ull)1<<((ull)n))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;
constexpr double eps = 0.000000001;

int main() {
    int a, b, c, x, y, p[100000], q[100000], r[100000];
    cin >> x >> y >> a >> b >> c;
    rep(i, a)cin >> p[i];
    rep(i, b)cin >> q[i];
    rep(i, c)cin >> r[i];
    sort(p, p + a, greater<>());
    sort(q, q + b, greater<>());
    vector<int> s(x + y + c);
    rep(i, x)s[i] = p[i];
    rep(i, y)s[i + x] = q[i];
    rep(i, c)s[i + x + y] = r[i];
    sort(s.begin(), s.end(), greater<>());
    ll d = 0;
    rep(i, x + y)d += s[i];
    cout << d << endl;
}



Measured memory_bytes: 2560
import java.util.*;

public class Main{

    static int mod = (int) 1e9 + 7;
    static int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
    static int INF = Integer.MAX_VALUE/2;

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);

        //Queue<int[]> q = new ArrayDeque<int[]>();
        Integer N = new Integer(scan.nextInt());
        ArrayList<Integer> a = new ArrayList<Integer>();

        for(int i=0;i<N;i++) a.add(scan.nextInt());

        boolean flag = true;
        for(int i=0;i<N;i++){
            int t = a.get(i);
            if(t%2==0){
                if(!((t%3==0)||(t%5==0))) flag = false;
            }
        }

        if(flag)
            System.out.println("APPROVED");
        else
        System.out.println("DENIED");
    }

    static int factorial(int n){
        if(n == 0){
          return 1;
        }
        return n * factorial(n-1);
    }


}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a != b && b != c && c != a){
        cout << 3;
    } else if(a == b && b == c && c == a){
        cout << 1;
    } else {
        cout << 2;
    }
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define ss(x) (int) x.size()
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl;
#define ios cin.tie(0); ios_base::sync_with_stdio(0)
 
using namespace std;
using namespace __gnu_pbds;
 
// order_of_key
// find_by_order
// tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ja;

string s;
int ile[3];

int main() {				 
	ios;
	cin >> s;
	FOR(i, 0, ss(s) - 1) {
		ile[s[i] - 'a'] += 1;
	}
	
	int mini = ss(s) + 1;
	int maxi = -1;
	FOR(i, 0, 2) {
		mini = min(mini, ile[i]);
		maxi = max(maxi, ile[i]);
	}
	
	if(maxi - mini <= 1) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
	
	
	
	return 0;
}
		


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int gcd(int x,int y){
    if(y==0){
        return x;
    }else{
        return gcd(y,x%y);
    }
}
int main(){
    int k;
    cin >> k;
    int ans = 0;
    for(int a=1;a<=k;a++){
        for(int b=1;b<=k;b++){
            for(int c=1;c<=k;c++){
                //cout << "gcd(" << a << ", " << b << ", " << c << ")=" << gcd(gcd(a,b),c)<< endl;
                ans += gcd(gcd(a,b),c);
            }
        }
    }
    cout << ans << endl;    
}

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

int main(){
  int64_t N,K;
  cin >> N >> K;

  int64_t over= N+K- K*(N/K);
  int64_t under= over- K;
  int64_t ans= (over- K < K- under) ? over- K
                                : K- under;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define P(s) cout<<s<<endl
 
int main() {
    int n;
    cin >> n;
    
    vector<int> r(n);
    for (auto&& ri: r) {
        cin >> ri;
    }
    
    int cnt = 0;
    for (auto i=0; i<n; ++i) {
        if (i+1 == r[r[i]-1]) {
            ++cnt;
        }
    }
    P(cnt/2);
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    VVI dp(n,VI(2));
    dp[0][s[0]-'0'] = 0;
    dp[0][1-(s[0]-'0')] = 1;
    REP(i,1,n) {
        if (s[i] == '1') {
            dp[i][1] = dp[i-1][0];
            dp[i][0] = dp[i-1][1] + 1;
        } else {
            dp[i][1] = dp[i-1][0] + 1;
            dp[i][0] = dp[i-1][1];            
        }
    }
    cout << min(dp[n-1][0], dp[n-1][1]) << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 5760
from bisect import bisect_right, bisect_left
N = int(input())
A = sorted([int(i) for i in input().split()])
B = sorted([int(i) for i in input().split()])
C = sorted([int(i) for i in input().split()])

count = 0

for b in B:
    i = bisect_left(A, b)
    k = bisect_right(C, b)
    count += i * (N-k)

print(count)

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

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int r = Integer.parseInt(in.readLine());

		System.out.println((r * r * 3));
	}
}


Measured memory_bytes: 21076
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	int N;
	cin >> N;

	switch (N % 10) {
	case 3:
		printf("bon\n"); break;
	case 0:
	case 1:
	case 6:
	case 8:
		printf("pon\n");
		break;
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		printf("hon\n");
		break;
	}


EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}




Measured memory_bytes: 3164
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j;
  int A[N+1];
  int tmp;
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);

  for(i = 2;i <= n;i++){
    tmp = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > tmp){
      A[j+1] = A[j];
      j--;
      A[j+1] = tmp;
    }
    trace(A,n);
  }




  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

int main() {
    long a, b, x, ans = 1;
    cin >> x;
    if (x == 1) {
        cout << 0 << endl;
    }
    // vector<long> prime{2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31,  37,  41,  43, 47,
    //                    53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109};
    // for (int i = 0; i < 100000; i++) {
    //     ans *= prime[i];
    //     if (ans + 1 > x) {
    //         a = i;
    //         break;
    //     }
    // }
    for (int i = x; i <= 200000; i++) {
        b = 0;
        for (int j = 2; j * j <= i; j++) {
            if (i % j == 0) {
                b++;
            }
        }
        if (b == 0) {
            cout << i << endl;
            return 0;
        }
    }
}

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

signed main() {
	string S;
	int K;
	cin >> S >> K;
	int N = (int)S.size();
	// Ai以下を見て, Sと等しいか, 以下か
	vector<vector<ll>> dp_equal(N+1, vector<ll>(4, 0));
	vector<vector<ll>> dp_less(N+1, vector<ll>(4, 0));
	// 0個見て, 0でない数字が0個 つまり0
	dp_equal[0][0] = 1;

	for(int i=1;i<=N;i++) {
		int now = (int)(S[i-1] - '0');
		// i桁目まで全部0
		dp_less[i][0] = 1;
		for(int j=1;j<=K;j++) {
			// equal -> equalについて
			if(now > 0) dp_equal[i][j] = dp_equal[i-1][j-1];
			else dp_equal[i][j] = dp_equal[i-1][j];

			// less -> lessについて
			// 1~9のどれかを置ける
			dp_less[i][j] += dp_less[i-1][j-1] * 9;
			// 0を置く
			dp_less[i][j] += dp_less[i-1][j];

			// now == 0のときはequal -> lessにならない
			if(now > 0) {
				// 0を置く
				dp_less[i][j] += dp_equal[i-1][j];
				// equalからlessになる, 1以上now-1以下
				dp_less[i][j] += dp_equal[i-1][j-1] * (now - 1);
			}
		}
	}
	cout << dp_equal[N][K] + dp_less[N][K] << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007LL;
class ModCombination
{
public:
    ModCombination(const int n, const ll mod = MOD) : mod{mod}, fact(n + 1, 1), inv(n + 1, 1), inv_fact(n + 1, 1)  // mod should be prime
    {
        for (ll i = 2; i <= n; i++) {
            fact[i] = (fact[i - 1] * i) % mod;
            inv[i] = ((mod - (mod / i)) * inv[mod % i]) % mod;
            inv_fact[i] = (inv_fact[i - 1] * inv[i]) % mod;
        }
    }
    ll factorial(const int n) const { return fact[n]; }
    ll permutation(const int n, const int k) const { return (fact[n] * inv_fact[n - k]) % mod; }

private:
    const ll mod;
    vector<ll> fact;
    vector<ll> inv;
    vector<ll> inv_fact;
};
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    for (int i = 0; i < M; i++) { cin >> A[i]; }
    reverse(A.begin(), A.end());
    const int maximum = 1 << N;
    ModCombination mod(maximum);
    vector<ll> dp(maximum, 0LL);
    dp[0] = 1;
    for (int i = 0; i < M; i++) {
        auto tmp = dp;
        for (int j = 0; j < maximum; j++) {
            if (dp[j] == 0) { continue; }
            const int rest = maximum - A[i] - j;
            for (int k = 0; k < N; k++) {
                if (j & (1 << k)) { continue; }
                const int need = (1 << k) - 1;
                if (rest < need) { continue; }
                const ll way = mod.permutation(rest, need) * (1 << k) % MOD;
                (tmp[j | 1 << k] += dp[j] * way % MOD) %= MOD;
            }
        }
        dp = tmp;
    }
    ll ans = 0;
    for (int i = 0; i < maximum; i++) {
        const ll num = dp[i] *= mod.factorial(maximum - i - 1) % MOD;
        (ans += (__builtin_popcount(i) % 2 == 0 ? num : MOD - num)) %= MOD;
    }
    cout << (ans * maximum % MOD) << endl;
    return 0;
}


Measured memory_bytes: 2816
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
priority_queue<ll,vector<ll>,greater<ll>> pq[100005];
class UF{
public:
	vector<int> par,num;
	int find(int v){
		return (par[v]==v)? v: (par[v]=find(par[v]));
	}
	explicit UF(int N):par(N),num(N,1){
		iota(all(par),0);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return;
		if(num[u]<num[v])swap(u,v);
		num[u]+=num[v];
		par[v]=u;
	}
	bool same(int u,int v){
		return find(u)==find(v);
	}
	bool ispar(int v){
		return v=find(v);
	}
	int size(int v){
		return num[find(v)];
	}
};
int main(){
 int n,m;
 cin>>n>>m;
 V<ll> a(n);
 for(int i=0;i<n;i++)cin>>a[i];
 UF uf(n);
 for(int i=0;i<m;i++){
   int a,b;cin>>a>>b;
   uf.unite(a,b);
 }
 for(int i=0;i<n;i++){
   pq[uf.find(i)].emplace(a[i]);
 }
 ll ans=0;
 V<P> d; 
 for(int i=0;i<n;i++){
   if(uf.find(i)==i)d.emplace_back(uf.size(i),i);
 }
 sort(all(d),greater<P>());
 int now=d[0].se;
 for(int i=1;i<d.size();i++){
   if(pq[now].size()==0){
     cout<<"Impossible"<<"\n";
     return 0;
   }
   ans+=pq[now].top();pq[now].pop();
   ans+=pq[d[i].se].top();pq[d[i].se].pop();
   while(pq[d[i].se].size()){
      pq[now].emplace(pq[d[i].se].top());
      pq[d[i].se].pop();
   }
 }
 cout<<ans<<"\n";
}


Measured memory_bytes: 9212
param_x, param_k, param_d = map(int, input().split())

param_x_tmp = param_x

if param_x > 0:
  int_times_nega_posi = -1
else:
  int_times_nega_posi =  1
  
if (param_x*int_times_nega_posi*-1) - (param_k*param_d) > 0:
  print((param_x*int_times_nega_posi*-1) - (param_k*param_d))
  
else:
  int_time_before_cross_0 = int((param_x*int_times_nega_posi*-1) / param_d)
  # print(int_time_before_cross_0)
  
  param_x_tmp = param_x + int_time_before_cross_0*param_d*int_times_nega_posi
  # print(param_x_tmp)
  
  int_move = param_k - int_time_before_cross_0 #move left
  int_move_devide_2_no_amari = int_move % 2
  print(abs(param_x_tmp + param_d*int_move_devide_2_no_amari*int_times_nega_posi))
  
  #count = 0
  #while param_x_tmp*param_x > 0:
  #  
  #  param_x_tmp = param_x_tmp + param_d*int_times_nega_posi
  #  
  #  count = count + 1
  #  
  #  if param_k - count == 0:
  #    print(abs(param_x_tmp))
  #
  #if count < param_k:
  #  int_move = param_k - count #move left
  #  int_move_devide_2_no_amari = int_move % 2
  #  print(abs(param_x_tmp + param_d*int_move_devide_2_no_amari*int_times_nega_posi*-1))

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  int a;
  cin >> a;
  
  if(a<1000){
    cout << "ABC";
    
  }else{
    cout << "ABD" ;
    
  }
  
   return 0;
}


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

using namespace std;

int sum_elements(int n) 
{
    int sum = 0, m;

    while(n > 0)
    {    
        m = n % 10;    
        sum = sum + m;    
        n = n / 10;    
    }
    return sum;
}

int main(void)
{

    int N; cin >> N;
    int menor = INT_MAX;

    for(int i = 1, j = N - 1; i <= N / 2 and j >= N / 2; ++i and --j)
    {
        int soma_a = sum_elements(i);
        int soma_b = sum_elements(j);
        int ab = soma_a + soma_b;

        if(ab < menor)
            menor = ab;
    }

    cout << menor << endl;

    return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll H, W, M;
  scanf("%lld %lld %lld", &H, &W, &M);

  vll h_list = vll(300005);
  vll w_list = vll(300005);

  mll points;

  ll h_max = -1;
  ll w_max = -1;
  // vector<l_l> list;
  for (ll i = 0; i < M; i++) {
    ll h, w;
    scanf("%lld %lld", &h, &w);
    // list.emplace_back(make_pair(h, w));

    h_list[h]++;
    w_list[w]++;

    h_max = max(h_max, h_list[h]);
    w_max = max(w_max, w_list[w]);

    points[h + w * 1000000LL] = 1;
  }

  vll y_list;
  vll x_list;

  for (ll i = 0; i < 300005; i++) {
    if (h_list[i] == h_max) {
      y_list.emplace_back(i);
    }
  }
  for (ll i = 0; i < 300005; i++) {
    if (w_list[i] == w_max) {
      x_list.emplace_back(i);
    }
  }

  ll ans = h_max + w_max - 1;

  for (auto y : y_list) {
    for (auto x : x_list) {
      if (!points[y + x * 1000000LL]) {
        cout << ans + 1 << endl;
        return 0;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 29804
#include <bits/stdc++.h>
using namespace std;
#define patrat(x) (x * x)
ifstream fin("cmap.in");
ofstream fout("cmap.out");
const int MAXN = 105;
const int MAXW = 1e5 + 4;
int w[MAXN], v[MAXN];
long long dp[MAXN][MAXW];
int main(){
    ios::sync_with_stdio(false);
    fin.tie(0);fout.tie(0);
    int n ,k ; cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> w[i] >> v[i];
    }
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= k; ++j){
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if(j + w[i + 1] <= k)
                dp[i + 1][j + w[i + 1]] = max(dp[i + 1][j + w[i + 1]], dp[i][j] + v[i + 1]);
        }
    }
    long long maxim = 0;
    for(int i = 1; i <= k; ++i){
        maxim = max(maxim, dp[n][i]);
    }
    cout << maxim;
    return 0;
}


Measured memory_bytes: 79360
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

int n;
int s;

int main(){
	ri2(n,s);
	int ans = 0;
	for(int X = 0; X <= n; X++){
		for(int Y = 0; X + Y <= s and Y <= n; Y++){
			int Z = s - X - Y;
			if(Z <= n) ans += 1;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define REP(i, m, n) for(long long i = m; i < n; ++i)
#define CO(n) cout << n << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//二部グラフであれば，二部グラフを保ったまま辺の数を最大化
//B*(N-B)-M
//そうでなければ全ての頂点を結ぶ
//N*(N-1)/2

//V頂点数，E辺数
ll N, M;
//辺
vector<int> G[100000];
//二部グラフ用
int color[100000];
//1の個数
int B=0;

//二部グラフ判定
bool dfs(int v, int c) {
    color[v] = c;
    if (c == 1) ++B;
    REP(i,0,G[v].size()){
        if (color[G[v][i]] == c) return false;
        if (color[G[v][i]] == 0 && !dfs(G[v][i], -c)) return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> N >> M;
    REP(i,0,M){
        int from, to;
        cin >> from >> to;
        --from; --to; //0〜N-1にする
        G[from].push_back(to);
        G[to].push_back(from);
    }
    if (dfs(0,1)) {
        // CO("yes");
        CO(B*(N-B)-M);
    } else {
        // CO("no");
        CO(N*(N-1)/2 - M);
    }
    // REP(i,0,N) cout << color[i] << ' ';
    // cout << endl;
    return 0;
}


Measured memory_bytes: 6528
n = int(input())
a = list(map(int, input().split()))
ret = [0]*(n+1)
ret2 = []

for i in reversed(list(range(n))): 
  if sum(ret[::i+1][1:])%2 != a[i]:
    ret[i+1] = 1
    ret2.append(i+1)

print(sum(ret[1:]))
print(" ".join(list(map(str, ret2[::-1]))))

Measured memory_bytes: 21260
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e5 + 5;
ll n,p;
string s;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>s;
    if(n % 2 == 0){
        p = 1;
        for(int i = 0;i < n / 2;i += 1) if(s[i] != s[i + n / 2]) p = 0;
    }
    cout<<(p == 0 ? "No" : "Yes");
    return 0;
} 

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import os
import pprint

#fd = os.open('CGL_2_A.txt', os.O_RDONLY)
#os.dup2(fd, sys.stdin.fileno())

def judge(lst):
    x0, y0, x1, y1, x2, y2, x3, y3 = lst
    v0 = (x1 - x0, y1 - y0)
    v1 = (x3 - x2, y3 - y2)

    dot = v0[0] * v1[0] + v0[1] * v1[1]
    cross = v0[0] * v1[1] - v0[1] * v1[0]

    if dot == 0:
        print(1)
    elif cross == 0:
        print(2)
    else:
        print(0)


N = int(input())
for i in range(N):
    lst = list(map(int, input().split()))
    judge(lst)

Measured memory_bytes: 8316
/*
Author : N_o_o_B
Created : April 11 2020 15:01:46 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    int n,m;
    cin >> n >> m;
    int tot = 0;
    vi a(n);
    fori(i,n){
        cin >> a[i];
        tot += a[i];
    }
    int cnt = 0;
    fori(i,n){
        if(a[i]*4*m >= tot){
            cnt++;
        }
    }

    if(cnt >= m){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;

    time_taken();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int n;
    cin >> n;
    int r = n % 10;
    if (r == 3) {
        cout << "bon" << endl;
    } else if (r == 0 || r == 1 || r == 6 || r == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include<algorithm>
#include <set>
#include <stack>
#include <stdlib.h>

using namespace std;

int main()
{
    int n=0;
    string arr,arr1;
    cin>>arr>>arr1;
    for(int i=0;i<arr.size();i++)
    {
        if(arr[i]!=arr1[i])
            n++;
    }
    cout<<n;
    return 0;
}

Measured memory_bytes: 3892
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

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

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			double t = in.nextDouble();
			double a = in.nextDouble();
			double[] h = in.nextDoubleArray(n);
			double[] ave = new double[n];
			int ans = 0;
			double ret = LINF;
			for (int i = 0; i < n; i++) {
				ave[i] = - h[i] * 0.006 + t;
				if (Math.abs(ave[i] - a) < ret) {
					ret = Math.abs(ave[i] - a);
					ans = i;
				}
			}
			out.println(ans + 1);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21844
#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>;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v.at(i);
    sort(v.begin(), v.end());
    cout << v[n/2]-v[n/2-1] << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,i,j; cin>>n;
    vector <vector<int>> a(2, vector <int>(n));
    for(j=0;j<2;j++){
       for(i=0;i<n;i++){
          cin>> a[j][i];
       }
    }
    int max=0;
    for(i=0;i<n;i++){
        int count =0;
        for(j=0;j<n;j++){
            if(j<=i) count += a[0][j];
            if(j>=i) count+=a[1][j];
        }
        if(count>=max) max=count;
    }
    cout<<max<<endl;
}

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

using namespace std;

typedef long long ll;
const int N=5e5+9;

ll to[N<<1],nxt[N<<1],beg[N],tot;
ll n,m,c[N],w[N<<1];
ll ans,f[4],flag;

inline void add(int u,int v,int c)
{
    to[++tot]=v;
    nxt[tot]=beg[u];
    w[tot]=c;
    beg[u]=tot;
}

inline void dfs(int u)
{
    f[c[u]]++;
    for(int i=beg[u];i;i=nxt[i])
    {
        if(w[i]==1)f[3]++;
        if(!(~c[to[i]]))
        {
            c[to[i]]=(c[u]+w[i])%3;
            dfs(to[i]);
        }
        else if (c[to[i]]!=(c[u]+w[i])%3)
            flag=1;
    }
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1,u,v;i<=m;i++)
    {
        scanf("%d%d",&u,&v);
        add(u,v,1);add(v,u,2);
    }

    memset(c,-1,sizeof(c));
    for(int i=1;i<=n;i++)
        if(!(~c[i]))
        {
            f[c[i]=0]=f[1]=f[2]=f[3]=flag=0;
            dfs(i);
            if(flag)
            {
                ll cnt=f[0]+f[1]+f[2];
                ans+=cnt*cnt;
                goto nxt;
            }
            else if((!f[0]) || (!f[1]) || (!f[2]))
            {
                ans+=f[3];
            }
            else 
            {
                ans+=f[0]*f[1];
                ans+=f[1]*f[2];
                ans+=f[2]*f[0];
            }

            nxt:;
        }

    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 20096
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            boolean[] can = new boolean[110];
            can[0] = true;
            for (int i = 0; i < n; i++) {
                if (can[i]) {
                    can[i + 4] = true;
                    can[i + 7] = true;
                }
            }

            out.println(can[n] ? "Yes" : "No");
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 21460
l = list(map(str, input().split()))

m = [0]

n = len(l)

for i in range(n):
  if l[i].isdigit() == True:
    m.append(l[i])
  else:
    a = int(m.pop())
    b = int(m.pop())
    if l[i] == "+":
      c = a+b
      m.append(c)
    elif l[i] == "-":
      c = b-a
      m.append(c)
    else:
      c = a*b
      m.append(c)
print(m[1])


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n, k;
  cin >> n >> k;
  if (n % k == 0) cout << 0 << endl;
  else cout << 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    cout << ((a.back() == b.front() && b.back() == c.front()) ? "YES" : "NO") << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int input[5];

    for (int i = 0; i < 5; i++)
        cin >> input[i];

    sort(input, input + 5, greater<int>());

    cout << input[0] << " " << input[1] << " " << input[2] << " " << input[3];
    cout << " " << input[4] << endl;


    return 0;
}

Measured memory_bytes: 1180
N = int(input())

if N%2==1:
    print(0)
else:
    count2=0
    count5=0
    n=N

    while(n//2>0):
        count2 += n//2
        n //= 2

    m=N//2

    while(m//5>0):
        count5 += m//5
        m //= 5

    print(min(count2,count5))

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

ll powMod(ll x, ll n)
{
    ll res = 1;
    for(ll i = 0; i < n; i++)
    {
        res = res * x % mod;
    }
    return res;
}

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

    ll res = powMod(10, n) - powMod(9, n) * 2 + powMod(8, n);
    res = (res % mod + mod) % mod;

    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <map>
using namespace std;
int main(void){
    int n;
    int m;
    
    while (cin >> n && n != 0) {
        map<char, char> table;
    
        for (int i = 0; i < n; i++) {
            char convert_from, convert_to;
            cin >> convert_from >> convert_to;
            table[convert_from] = convert_to;
        }
        
        cin >> m;
        for (int i = 0; i < m; i++) {
            char comp;
            cin >> comp;
            
            if (table.count(comp)) {
                comp = table[comp];
            }
            cout << comp;
        }
        
        cout << endl;
    }
    
    return 0;
}



Measured memory_bytes: 2996
import sys
input=sys.stdin.readline
n=int(input())
A=[int(input()) for _ in range(n)]
if A[0]!=0:
    print(-1)
    exit()
for i in range(n-1):
    if A[i]+1<A[i+1]:
        print(-1)
        exit()
ans=0
prev=A[0]
for i,a in enumerate(A,1):
    if a==prev+1:
        ans+=1
    else:
        ans+=a
    prev=a
print(ans)

Measured memory_bytes: 50268
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)

using namespace std;
typedef long long ll;
ll x;
ll a[6]={100,101,102,103,104,105};
set<ll> s;
void dfs(ll now)
{
    if(now>100000) return;
    s.insert(now);
    rep(i,6)
    {
        if(!s.count(now+a[i])) dfs(now+a[i]);
    }
}
int main()
{
    dfs(0);
    while(cin>>x)
    {
        if(s.count(x)) cout<<"1\n";
        else cout<<"0\n";
    }

}


Measured memory_bytes: 4864
use std::io::Read;
fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();

    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();

    let mut a: i32 = iter.next().unwrap().parse().unwrap();
    let mut b: i32 = iter.next().unwrap().parse().unwrap();
    if a < b {
        let t = a;
        a = b;
        b = t;
    }
    let d = a - b;
    if d % 2 == 0 {
        let v: i32 = d/2 as i32;
        let ans: i32 = v - a;
        println!("{}", -ans)
    } else {
        println!("IMPOSSIBLE")
    }

}



Measured memory_bytes: 4352