akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctype.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef long long Int;
Int mod = 1e9+7;
Int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
    Int n;
    cin >> n;
    vector<Int> a(n), b(n);
    Int asum, bsum;
    asum = bsum = 0;
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
        asum += a[i];
    }
    for (Int i = 0; i < n; i++) {
        cin >> b[i];
        bsum += b[i];
    }
    if (asum < bsum) {
        dump(-1);
        return 0;
    }
    vector<Int> c;
    Int x = 0;
    Int res = 0;
    for (Int i = 0; i < n; i++) {
        if (b[i] > a[i]) {
            x += a[i] - b[i];
            res++;
        }
        else if (a[i] > b[i]) c.push_back(a[i] - b[i]);
    }
    sort(c.begin(), c.end(), greater<Int>());
    for (Int i = 0; i < (Int)c.size() && x < 0; i++) {
        x += c[i];
        res++;
    }
    dump(res);
    return 0;  
}

Measured memory_bytes: 2556
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
long long rmax(long long a,long long b){
  if(a>b){
    return a;
  }
  else return b;
}

long long rmin(long long a,long long b){
  if(a>b){
    return b;
  }
  else return a;
}

using namespace std;
int main(void){

  int n;
  cin >> n;
  long long int a[n];

  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  long long int sumr,suml;
  long long int ans=1000000000000000;
  long long int sa;
  int i,j=0;
  do{
    sumr=suml=0;


    for(i=n/2+j;i>=0;i--){
      sumr=sumr+a[i];
    }
    for(i=n/2+1+j;i<n;i++){
      suml=suml+a[i];
    }
    sa=rmax(sumr,suml)-rmin(sumr,suml);
    if(ans>sa){
      ans=sa;
    }
    j++;

  }while(sumr<suml);

  do{
    sumr=suml=0;


    for(i=n/2-j;i>=0;i--){
      sumr=sumr+a[i];
    }
    for(i=n/2+1-j;i<n;i++){
      suml=suml+a[i];
    }
    sa=rmax(sumr,suml)-rmin(sumr,suml);
    if(ans>sa){
      ans=sa;
    }
    j++;

  }while(sumr>suml);

  printf("%lld",ans);

  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>


int main(void){
    int a[3][3], x[3][3];
    int i, j;
    for(i = 0 ; i < 3 ; i++){
        for(j = 0 ; j < 3 ; j++){
            x[i][j] = 0;
        }
    }
    for(i = 0 ; i < 3 ; i++){
        for(j = 0 ; j < 3 ; j++){
            scanf("%d", &a[i][j]);
        }
    }
    int n;
    scanf("%d", &n);
    int b, k;
    for(k = 0 ; k < n ; k++){
        scanf("%d", &b);
        for(i = 0 ; i < 3 ; i++){
            for(j = 0 ; j < 3 ; j++){
                if(a[i][j]==b){
                    x[i][j] = 1;
                }
            }
        }
    }
    int abe=0;
    int shinzo;
    for(i = 0 ; i < 3 ; i++){
        shinzo = 0;
        for(j = 0 ; j < 3 ; j++){
            if(x[i][j] == 1){
                shinzo++;
            }
        }
        if(shinzo == 3){
            abe = 1;
        }
    }
    for(j = 0 ; j < 3 ; j++){
        shinzo = 0;
        for(i = 0 ; i < 3 ; i++){
            if(x[i][j] == 1){
                shinzo++;
            }
        }
        if(shinzo == 3){
            abe = 1;
        }
    }
    if(x[0][0] == 1 && x[1][1] == 1 && x[2][2] == 1){
        abe = 1;
    }
    if(x[0][2] == 1 && x[1][1] == 1 && x[2][0] == 1){
        abe = 1;
    }
    if(abe == 1){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }


    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

ULL gcd(ULL a, ULL b) { return b ? gcd(b, a % b) : a; }

ULL dp[1001][1001] = {};
const ULL M = 1000000007;

int main() {
	string T, B; cin >> T >> B;
	dp[0][0] = 1;
	rep(i, T.size()) {
		rep(j, B.size()) {
			dp[i + 1][j] += dp[i][j];
			if (T[i] == B[j]) dp[i + 1][j + 1] += dp[i][j];
			dp[i + 1][j] %= M;
		}
		dp[i + 1][B.size()] += dp[i][B.size()];
		dp[i + 1][B.size()] %= M;
	}
	cout << dp[T.size()][B.size()] << endl;
	return 0;
}



Measured memory_bytes: 10992
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))


def solve(N, A):
    ma = max(A)
    mi = min(A)
    if ma == mi:
        # 全部違う色
        if ma == N - 1:
            return True
        # 全部誰かと被ってる
        return ma * 2 <= N
    if ma - mi == 1:
        A.sort()
        mi_count = bisect.bisect_left(A, ma)
        # mi_count の数だけ、誰とも被ってない人がいる
        return 0 < (ma - mi_count) * 2 <= N - mi_count
    return False


ok = solve(N, A)
if ok:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 24420
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))

int main(){
    int N;
    cin >> N;
    int nums[N];
    for(int i = 0; i < N; i++){
        cin >> nums[i];
    }
    int ans = 1e9;
    for(int i = -1000; i < 1000; i++){
        int this_ans = 0;
        for(int j = 0; j < N; j++){
            this_ans += (nums[j] - i) * (nums[j] - i);
        }
        ans = min(ans, this_ans);
    }
    cout << ans << endl;
}



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

int main(){
    int n,b,c=0,ans=0;
    cin>>n>>b;
    for(int i=1;i<n;i++){
        int a;
        cin>>a;
        if(b>=a) c++;
        else {
            ans = max(ans,c);
            c = 0;
        }
        b = a;
    }
    cout<<max(ans,c)<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int N;
    scanf("%d",&N);
    
    int K;
    scanf("%d",&K);
    
    int h[N];
    int counter = 0;
    for(int i=0;i<N;i++){
        scanf("%d",&h[i]);
        if(h[i] >= K){
            counter++;
        }
    }
    
    printf("%d\n",counter);
    
    return 0;
}

Measured memory_bytes: 512
/*
** Matrix Chain Multiplication
*/

# include <cstdio>
# include <algorithm>
using namespace std;

const int MAX = 100 + 5;

int n, m[MAX][MAX], p[MAX];

void matrixCM() {
    for (int i = 1; i <= n; i++) {
        m[i][i] = 0;
    }

    for (int l = 2; l <= n; l++) {
        for (int i = 1; i <= n - l + 1; i++) {
            int j = i + l - 1;
            m[i][j] = (1 << 21);
            for (int k = i; k < j; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }
}

void solve() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &p[i], &p[i + 1]);
    }
    matrixCM();
    printf("%d\n", m[1][n]);
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    solve();
    return 0;
}


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

using namespace std;
using ll = long long;

int n;
ll sum, ans;
map<ll, int> m;

int main(){
    scanf("%d", &n);
    m[0] = 1;
    for(int i = 0, a; i < n; i++){
        scanf("%d", &a);
        sum += a;
        ans += m[sum];
        m[sum]++;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 12800
#include<iostream>
using namespace std;
int main() {
  long N, M, A[100001], B[100001];
  cin >> N >> M;
  for (int i = M;i > 0;-- i) cin >> A[i] >> B[i];
  long ans[100001], uf[100001];
  ans[0] = N * (N - 1) / 2;
  for (int i = 1;i <= N;++ i) uf[i] = -1;
  for (int i = 1, l, r;i <= M;++ i) {
    for (l = A[i];uf[l] >= 0;l = uf[l]);
    for (r = B[i];uf[r] >= 0;r = uf[r]);
    ans[i] = ans[i - 1];
    if (l != r) {
      ans[i] -= uf[l] * uf[r];
      if(uf[l] < uf[r]) {
        uf[l] += uf[r];
        uf[r] = l;
      } else {
        uf[r] += uf[l];
        uf[l] = r;
      }
    }
  }
  for (int i = M - 1;i >= 0;-- i) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin>>n;
	long long res1,res2;
	for (int i=0;i<n;i++){
		long long a,b;
		cin>>a>>b;
		if (i==0){
			res1=a,res2=b;
			continue;
		}
		long long t1=(res1+a-1)/a;
		long long t2=(res2+b-1)/b;
		res1=a*max(t1,t2);
		res2=b*max(t1,t2);
	}
	cout<<res1+res2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	ll n;
	cin >> n;
	vector<ll> a(n);

	ll ma = 0;

	rep(i, n)
	{
		cin >> a[i];
		ma = max(ma, a[i]);
	}
	int count = 0;
	while (true)
	{
		if (ma == 0)
		{
			break;
		}
		ma = ma / 2;
		count++;
	}

	ll ans1 = 0;
	ll ans2 = 0;
	bool ans = true;

	for (int i = 0; i < count; i++)
	{
		for (int j = 0; j < n; j++)
		{
			ans1 += a[j] % 2;
			a[j] /= 2;
		}
		if ((ans1 != ans2 && ans2 != 0 && ans1!=0 || ans1 % 2 == 1) && i != 0)
		{
			ans = false;
		}
		ans2 = ans1;
		ans1 = 0;
	}

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

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

class UnionFind {
public:
	vector<int> par;//親の番号
    vector<int> rank;//木の深さ
 
	UnionFind(int n){//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
		rep(i,n){
            par.push_back(i);
            rank.push_back(0);
        }
	}
 
	int find(int x) {//木の根を求める
		if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
	}
 
	void unite(int x,int y){//xとyの属する集合を併合
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){//木の深さが小さい方を大きい方へ繋げる
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x,int y){//xとyが同じ集合に属するか否か
        return find(x)==find(y);
    }
};
//x以下の要素への最小index, ソートしてから使ってね
template <class T> 
int former(const vector<T> &v, T x){
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> 
int latter(const vector<T> &v, T x){
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
template <class T>
T comb(T n,T k){
    T ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
//素因数分解
template <class T>
map<T,T> prime_factor(T x){
    map<T,T> ans;
    for(T i=2;i*i<=x;i++){
        while(x%i==0){
            x/=i;
            ans[i]++;
        }
    }
    if (x!=1){
        ans[x]=1;
    }
    return ans;
}
//約数列挙
template <class T>
vector<T> divisor(T x){
    vector<T> res;
    for(T i=1;i*i<=x;i++){
        if(x%i==0){
            res.push_back(i);
            if(i!=x/i){
                res.push_back(x/i);
            }
        }
    }
    return res;
}
//素数判定
template <class T>
bool is_prime(T x){
    for(T i=2;i*i<=x;i++){
        if(x%i==0){
            return false;
        }
    }
    return x!=1;
}

const ll inf=1e9+7;

ll mult(ll n,ll m){//n^m%infを求める
    if(m==1){
        return n%inf;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%inf;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%inf;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    bool flag=false;
    vector<string> s(n);
    rep(i,n){
        cin>>s[i];
        if(s[i]=="Y"){
            flag=true;
        }  
    } 
    if (flag){
        cout<<"Four"<<endl;
    }else{
        cout<<"Three"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 10000000
#define LLINF 100000000000000
typedef long long ll;
typedef pair<long long, long long> P;
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define VSORT(v) sort(v.begin(), v.end());
#define fi first
#define se second
#define out(x) cout << x << endl;
int dx[] = {1, 0, -1, 0}, dy[] = { 0,1,0,-1 };
ll MOD = 1000000007;
struct edge {
	ll from, to, cost;
};

long long h,n;
vector<P>v;
long long dp[100005]={0};

int main() {
	cin>>h>>n;
    for(int i=0;i<n;i++){
        long long a,b;
        cin>>a>>b;
        v.pb(P(b,a));
    }
    for(int i=1;i<10005;i++){
        dp[i]=LLINF;
    }
    for(int i=0;i<10005;i++){
        for(int j=0;j<n;j++){
            dp[i+v[j].second]=min(dp[i]+v[j].first,dp[i+v[j].second]);
        }
    }
    //cout<<dp[h]<<endl;
    for(int i=10000;i>=0;i--){
        dp[i]=min(dp[i],dp[i+1]);
    }
    cout<<dp[h]<<endl;
	return 0;
}


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

int main()
{
	int n;
	int tmp;
	vector<int> vec;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> tmp;
		vec.push_back(tmp);
	}

	sort(vec.begin(), vec.end());

	cout << vec[n - 1] - vec[0] << endl;

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(a: int, b: int):
    if a<b:
        print(str(a)*b)
    else:
        print(str(b)*a)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.*;
class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int h = sc.nextInt();
        int a = sc.nextInt();
        
        int count = 0;
        
        do{
            count++;
            h-=a;
            if(h<=0){
                System.out.println(count);
            }
        }while(h>0);
    }
}

Measured memory_bytes: 23252
n = gets.to_i
s1,s2 = 2.times.map{gets.chomp}
a = []
f = false
c = 0
while c != n
  if c == 0
    if s1[c] == s2[c]
      c = 1
      f = true
      a << 3
    else
      c = 2
      a << 6
    end
  else
    if s1[c] == s2[c] && f == false
      c += 1
      a << 1
      f = true
    elsif s1[c] == s2[c] && f == true
      c += 1
      a << 2
    elsif s1[c] != s2[c] && f == false
      c += 2
      a << 3
    else
      c += 2
      a << 2
      f = false
    end
  end
end   
puts a.inject(:*)%(10**9+7)

Measured memory_bytes: 1788
#include<stdio.h>

int main(void){
int a,b;
  
  //do{
    scanf("%d %d",&a,&b);
  //}while(a>=1&&a<=20&&b>=1&&b<=20);
  
  if(b%a==0){
    printf("%d",a+b);
  }
  else{
  printf("%d",b-a);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

int main(void){
    int n,m;
    while(cin>>n>>m,n){
        vi v(n+1,0),h(m+1,0);
        rep(i,n)cin>>v[i+1];
        rep(i,m)cin>>h[i+1];
        partial_sum(all(v),v.begin());
        partial_sum(all(h),h.begin());
        map<int,int> v2,h2;
        rep(i,n+1)range(j,i+1,n+1) {
            if(v2.find(v[j]-v[i])==v2.end()) v2[v[j]-v[i]]=0;
            v2[v[j]-v[i]]++;
        }
        rep(i,m+1)range(j,i+1,m+1) {
            if(h2.find(h[j]-h[i])==h2.end()) h2[h[j]-h[i]]=0;
            h2[h[j]-h[i]]++;
        }
        ll ans=0;
        for(auto i:v2){
            if(h2.find(i.first)!=h2.end()){
                ans+=i.second*h2[i.first];
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 29880
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC033ATeacher2
{
    class Program
    {
            struct pos
        {
            public int x;
            public int y;
        }
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int H = int.Parse(str[0]);
            int W = int.Parse(str[1]);
            int[,] A = new int[H, W];
            var list = new List<pos>();
            pos p = new pos();
            for (var i = 0; i < H; i++)
            {
                string str2 = Console.ReadLine();
                for (var j = 0; j < W; j++)
                {
                    if (str2.Substring(j, 1) == "#")
                    {
                        A[i, j] = 1;
                        p.x = i;
                        p.y = j;
                        list.Add(p);
                    }
                }
            }
            int max = 0;
            while (list.Count > 0)
            {
                var list2 = new List<pos>(list);
                list.Clear();
                for (var i = 0; i < list2.Count; i++)
                {
                    int x = list2[i].x;
                    int y = list2[i].y;
                    int ct = A[x, y];
                    if (x > 0)
                    {
                        if (A[x - 1, y] == 0)
                        {
                            A[x - 1, y] = ct + 1;
                            max = Math.Max(max, ct);
                            p.x = x - 1;
                            p.y = y;
                            list.Add(p);
                        }
                    }
                    if (x < H - 1)
                    {
                        if (A[x + 1, y] == 0)
                        {
                            A[x + 1, y] = ct + 1;
                            max = Math.Max(max, ct);
                            p.x = x + 1;
                            p.y = y;
                            list.Add(p);
                        }
                    }
                    if (y > 0)
                    {
                        if (A[x, y - 1] == 0)
                        {
                            A[x, y - 1] = ct + 1;
                            max = Math.Max(max, ct);
                            p.x = x;
                            p.y = y - 1;
                            list.Add(p);
                        }
                    }
                    if (y < W - 1)
                    {
                        if (A[x, y + 1] == 0)
                        {
                            A[x, y + 1] = ct + 1;
                            max = Math.Max(max, ct);
                            p.x = x;
                            p.y = y + 1;
                            list.Add(p);
                        }
                    }
                }
            }
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 33352
#include <stdio.h>
#include <stdlib.h>
#define ll long long

int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

ll a[200010];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%lld",a+i);
	sortdown(a,n);
	ll ans=0;
	for(int i=k;i<n;i++)ans+=a[i];
	printf("%lld",ans);
}

Measured memory_bytes: 3324
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<iomanip>

using namespace std;
int n;
int main()
{
	cin>>n;
	if(n/10==9||n%10==9)cout<<"Yes\n";
	else cout<<"No\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int a[200010],cnt[1000010] = {};
vector<int> v[1000010];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,j,n; cin >> n;
    for(i=1;i<=1000000;i++){
        for(j=i;j<=1000000;j+=i){
            v[j].push_back(i);
        }
    }
    for(i=0;i<n;i++){
        cin >> a[i];
        cnt[a[i]]++;
    }
    int ans = 0;
    for(i=0;i<n;i++){
        int x = a[i];
        if(cnt[x]>=2) continue;
        bool flag = true;
        for(int num :v[x]){
            if(num==x) continue;
            if(cnt[num]>=1) flag = false;
        }
        if(flag) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 122492
S = input()

a = S[0]
b = 'b'
a_count = 0
b_count = 0

for i in S:
    if i==a:
        a_count += 1
    else:
        b = i
for i in S:
    if i==b:
        b_count +=1

if a_count == 2 and b_count == 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	int S;
	int h;
	int m;
	int s;
	cin >> S;
	h = S /3600;
	m = S / 60-S/3600*60;
	s = S % 60;
	cout << h << ":" << m << ":" << s << endl;
}



Measured memory_bytes: 3112
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

l = list(input())
k = s(l)
co = 0
a = 0
b = 0
if k[0][0] == "A":
	a = k[0][1]
for i in range(1,len(k)):
	if k[i][0] == "A":
		if b == 0:
			a += k[i][1]
		else:
			a = k[i][1]
			b = 0
	elif k[i][0] == "B":
		if k[i][1] == 1:
			b = 1
		else:
			b = 0
			a = 0
	else:
		if b == 1:
			if k[i][1] == 1:
				co += a
				b = 0
			else:
				co += a
				a = 0
				b = 0
		else:
			a = 0

print(co)


Measured memory_bytes: 74568
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#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()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
	int n;
	cin >> n;
	vi a(n);
	rep(i,n) cin >> a[i];
	
	int ans[100010];
	for(int i = 0; i < n; i++){
		if(i%2) ans[0] -= a[i];
		else ans[0] += a[i];
	}
	cout << ans[0];
	for(int i = 1; i < n; i++){
		cout << ' ';
		ans[i] = 2*a[i-1]-ans[i-1];
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 2048
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, r int
	fmt.Scan(&n)
	l := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&l[i])
	}
	sort.Sort(sort.IntSlice(l))
	for i := 0; i < n-2; i++ {
		for j := i + 1; j < n-1; j++ {
			t := l[j+1:]
			sum := l[i] + l[j]
			w := sort.Search(len(t), func(i int) bool { return t[i] >= sum })
			r += w
		}
	}
	fmt.Println(r)
}


Measured memory_bytes: 640
#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>
#include <iomanip>

using namespace std;

#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)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

const int MAX = 1000000000;
int main() {
    int n, m;
    cin >> n >> m;


    vector<int> a(m), b(m);
    vector<vector<int>> c(m);
    vector<int> bit(m);

    REP(i, m){
        cin >> a[i] >> b[i];
        c[i].resize(b[i]);
        REP(j, b[i]){
            cin >> c[i][j];
            c[i][j]--;
            bit[i] |= (1 << c[i][j]);
        }
    }

    vector<int> dp((1<<n), MAX);

    dp[0] = 0;

    IFOR(i, 1, m){
        IFOR(j, 0, (1<<n)-1){
            int target = j | bit[i-1];
            dp[target] = min(dp[target], dp[j] + a[i-1]);
        }
    }

    if(dp[(1<<n)-1] == MAX)
        cout << -1 << endl;
    else
        cout << dp[(1<<n)-1] << endl;





    return 0;
}

Measured memory_bytes: 384
def bingo():
    for i in a:
        if i[0] in b and i[1] in b and i[2] in b:
            return True
    for i in range(3):
        if a[0][i] in b and a[1][i] in b and a[2][i] in b:
            return True
    tmp=[(a[i][i] in b) for i in range(3)]
    if tmp.count(True)==3:
        return True
    tmp=[a[0][2] in b,a[1][1] in b,a[2][0] in b]
    if tmp.count(True)==3:
        return True
 
a=[[int(i)for i in input().split()]for j in range(3)]
n=int(input())
b=[int(input())for i in range(n)]
bingo=bingo()
print("Yes" if bingo else "No")

Measured memory_bytes: 9260
import sys
sys.setrecursionlimit(4100000)
N, M = map(int, input().split())
graph = [[] * N for _ in range(N)]
for _ in range(M):
    L, R, D = map(int, input().split())
    L -= 1
    R -= 1
    graph[L].append((R, D))
    graph[R].append((L, -D))


def dfs(node, dist):
    global visited
    global dists
    dists[node] = dist
    for next, d in graph[node]:
        if next in visited:
            if d + dist != dists[next]:
                print('No')
                sys.exit()
        else:
            visited.add(next)
            dfs(next, dist + d)


visited = set()
dists = [0] * N
for i in range(N):
    if i in visited:
        continue
    visited.add(i)
    dfs(i, 0)

print('Yes')


Measured memory_bytes: 133016
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

int main(){ cin.tie(0); ios::sync_with_stdio(false);
    int N = in, M = in;

    int ans = 1;
    for( int a=1; a*a <= M; a++ ) {
        if( M % a != 0 ) continue;
        int b = M / a;
        if( a >= N ) ans = max( ans, b );
        if( b >= N ) ans = max( ans, a );
    }

    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath> 
using namespace std;
int main() {
  int a, b, c, d, e, k;
  bool result = false;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
  cin >> k;
  int test[5] = {a, b, c, d, e};
  for(int i = 0;i < 4;i++) {
    for(int j = i;j < 4;j++){
    if (abs(test[i] - test[j+1]) > k) {
      cout << ":(" << endl;
      result = true;
      break;
    }
    }
    if (result == true) {
      break;
    }
    if (i == 3) {
      cout << "Yay!" << endl;
    }
  }
}

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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
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();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int N, K;
vec a;
bool dp[5010][5010];

bool C(const int &m) {
  m0(dp);
  dp[0][0] = true;
  vector<int> b;

  for (int i = 0; i < N; i++) {
    if (i != m) b.push_back(a[i]);
  }

  for (int i = 0; i < N - 1; i++) {
    for (int k = 0; k <= K; k++) {
      if (!dp[i][k]) continue;
      dp[i + 1][k] = true;
      if (k + b[i] <= K) dp[i + 1][k + b[i]] = true;
    }
  }

  int tmp = 0;
  for (int i = 0; i <= K; i++) {
    if (dp[N - 1][i]) {
      tmp = a[m] + i;
      if (tmp >= K) break;
    }
  }
  return (tmp < K) || (K <= tmp - a[m]);
}

signed main() {
  cin >> N >> K;
  a.resize(N);

  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    a[i] = min(tmp, K);
  }

  sort(ALL(a));

  int ok = -1, ng = N + 1;
  for (int i=0;i<13;i++) {
    int mid = (ok + ng) / 2;
    if (C(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  cout << min(ng, N) << endl;
  return 0;
}

Measured memory_bytes: 24960
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{

    class Program
    {
        static void Main(string[] args)
        {
            //???????????????
            long[] nml = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            long n = nml[0];
            long m = nml[1];
            long l = nml[2];
            long[][] graph1 = new long[n][];
            for(long i = 0; i < n; i++)
            {
                graph1[i] = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            }
            long[][] graph2 = new long[m][];
            for(long i = 0; i < m; i++)
            {
                graph2[i] = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            }

            long[,] graph3 = new long[n, l];

            //?¨??????????
            for(long i = 0; i < n; i++)
            {
                for(long k = 0; k < l; k++)
                {
                    for(long j = 0; j < m; j++)
                    {
                        graph3[i, k] += graph1[i][j] * graph2[j][k];
                    }
                }
            }

            //????????¨
            for(long i = 0; i < n; i++)
            {
                for(long j = 0; j < l; j++)
                {
                    if (j == l - 1)
                    {
                        Console.WriteLine(graph3[i, j]);
                    }
                    else
                    {
                        Console.Write("{0} ", graph3[i, j]);
                    }
                }
            }

        }
    }
}

Measured memory_bytes: 10320
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		long t = sc.nextLong();
        long time[] = new long[n];
        int i;
        long count = 0;
		for(i = 0;i < n; i++){
          time[i] = sc.nextLong();
	    }
        for(i = 1;i < n; i++){
          if(time[i] - time[i - 1] <= t){
            count += time[i] - time[i - 1];
          }else{
            count += t;
          }
          
        }
        count += t;
        System.out.println(count); 
  
    }
}

Measured memory_bytes: 60220
// atcoder/abc146/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  string s;
  while (cin >> n >> s) {
    each (c, s) {
      char d = (c - 'A' + n) % 26 + 'A';
      cout << d ;
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N = int(input())
s = []
for _ in range(N):
    s.append(int(input()))

tmp = sum(s)
if tmp % 10 == 0:
    for e in sorted(s):
        if e % 10 != 0:
            tmp -= e
            break
if tmp % 10 == 0:
    tmp = 0
print(tmp)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

int main() { 
	ll n;
	cin >> n;
	if (n == 1) {
		cout << 1;
	}else {
		ll l1 = 2;
		ll l2 = 1;
		for (ll i = 2; i <= n; ++i) {
			//l1 = l2;
			ll a = l2;
			l2 = l2 + l1;
			l1 = a;
		}
		cout << l2;
	}
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        m: usize,
        k: usize,
    }
    let a_max = 2usize.pow(m as u32);
    if k >= a_max || (m == 1 && k == 1) {
        println!("-1");
        return;
    }
    if k == 0 {
        for i in 0..a_max {
            print!("{} {} ", i, i);
        }
        println!("");
        return;
    }
    print!("0 {} 0 ", k);
    for i in 1..a_max {
        if i != k {
            print!("{} ", i);
        }
    }
    print!("{} ", k);
    for i in (1..a_max).rev() {
        if i != k {
            print!("{} ", i);
        }
    }

    println!("");
}


Measured memory_bytes: 5884
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

// region
class ModInt(x: Long) {

    companion object {
        const val MOD = 998244353L
    }

    val x = (x % MOD + MOD) % MOD

    operator fun plus(other: ModInt): ModInt {
        return ModInt(x + other.x)
    }

    operator fun minus(other: ModInt): ModInt {
        return ModInt(x - other.x)
    }

    operator fun times(other: ModInt): ModInt {
        return ModInt(x * other.x)
    }

    operator fun div(other: ModInt): ModInt {
        return this * other.inv()
    }

    fun pow(exp: Long): ModInt {
        if (exp == 0L) return ModInt(1L)
        var a = pow(exp shr 1)
        a *= a
        if (exp and 1L == 0L) return a
        return this * a
    }

    fun inv(): ModInt {
        return this.pow(MOD - 2)
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as ModInt

        if (x != other.x) return false

        return true
    }

    override fun hashCode(): Int {
        return x.hashCode()
    }

    override fun toString(): String {
        return "$x"
    }

}

val fac = mutableListOf<ModInt>()

fun fact(n: Long): ModInt {
    if (fac.count() == 0) fac.add(ModInt(1))
    while (fac.count() <= n) {
        fac.add(fac.last() * ModInt(fac.count().toLong()))
    }
    return fac[n.toInt()]
}

fun comb(n: Long, k: Long): ModInt {
    return fact(n) / fact(k) / fact(n - k)
}

fun comb2(n: Long, k: Long): ModInt {
    var ans = ModInt(1)
    for (i in 0 until k) {
        ans = ans * ModInt(n - i) / ModInt(k - i)
    }
    return ans
}
// endregion

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextLong()
    val m = sc.nextLong()
    val k = sc.nextLong()
    var ans = ModInt(0)
    for (i in 0..k) {
        val v =  ModInt(m) * ModInt(m - 1).pow(n - i - 1) * comb(n - 1, i)
        ans += v
    }
    println(ans)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 61888
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

// 二部グラフ判定
bool dfs(Graph &G, vector<int> &color, int v, int c)
{
    color[v] = c;
    for (auto u : G[v])
    {
        if (color[u] == c)
            return false;
        if (color[u] == 0 && !dfs(G, color, u, -c))
            return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, M;
    cin >> N >> M;
    Graph G(N);
    for (int i = 0; i < M; i++)
    {
        int A, B;
        cin >> A >> B;
        A--, B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    vector<int> color(N, 0);
    ll ans = 0;
    if (dfs(G, color, 0, 1))
    {
        // 二部グラフだった場合
        ll B = 0, W = 0;
        for (auto it : color)
        {
            if (it == 1)
                B++;
            else
                W++;
        }
        ans = B * W - M;
    }
    else
    {
        ans = N * (N - 1) / 2 - M;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9400
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static Scanner sc = new java.util.Scanner(System.in);

	public static void main(String[] args) {
		ArrayList<Double> height = new ArrayList<Double>();
		double max=0;
		double min =1000000;

		while (sc.hasNext()) {
			height.add(sc.nextDouble());
		}

		for(int i=0;i<height.size();i++){
			max=Math.max(max, height.get(i));

		}
		for(int i=0;i<height.size();i++){
			min=Math.min(min, height.get(i));
		}

		System.out.println(max-min);




	}

}

Measured memory_bytes: 27712
#include <stdio.h>

int main(){
    int n,i,out,point,rui1,rui2,rui3;
	char c[8];
	scanf("%d",&n);
	for(i=0; i<n; i++){
		out=0;
		point=0;
		rui1=0;
		rui2=0;
		rui3=0;
		while(out!=3){
			scanf(" %s",c);
			switch(c[1]){
			case 'U':
				out++;
				break;
			case 'O':
				if(rui1==1){
					point++;
					rui1=0;
				}
				if(rui2==1){
					point++;
					rui2=0;
				}
				if(rui3==1){
					point++;
					rui3=0;
				}
				point++;
				break;	
			case 'I':
				if(rui3==1){
					rui3=0;
					point++;
				}
				if(rui2==1){
					rui2=0;
					rui3=1;
				}
				if(rui1==1){
					rui2=1;
					rui1=0;
				}
				rui1=1;
				break;
			}
		}
		printf("%d\n",point);
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAX=50000;
ll mod=1e9+7;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define endl '\n'
#define pb push_back
#define se second
#define fi first
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

long long expo(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*expo((x*x)%M,(n-1)/2,M))%M;

}

bool prime[10000001];
void fin()
{

}


void solve()
{
    ll n,a,b;
    cin>>a>>b;
    ll ans=0;ll i;
   for(i=1;i<10000001;i++)
   {
       ll temp=(i*8)/100;
       ll temp2=(i*10)/100;
       if(temp==a && temp2==b)break;
   }
   if(i==(10000001))
    cout<<-1<<endl;
   else
    cout<<i<<endl;

}

int main(){
    boost;
  solve();
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();

            var r = 0L;
            var g = 0L;
            var b = 0L;
            foreach (var c in S)
            {
                switch (c)
                {
                    case 'R':
                        r++;
                        break;
                    case 'G':
                        g++;
                        break;
                    default:
                        b++;
                        break;
                }
            }

            var answer = r * g * b;
            foreach (var i in Enumerable.Range(0, N))
            {
                foreach (var j in Enumerable.Range(i + 1, N - i - 1))
                {
                    var k = j + j - i;
                    if (k >= S.Length)
                    {
                        continue;
                    }

                    if (S[i] != S[j] && S[i] != S[k] && S[j] != S[k])
                    {
                        answer--;
                    }
                }
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 28376
n, x = map(int, input().split())
# レベルごとの全体の枚数、パティの枚数を求める
a, p = [1], [1]
for i in range(n):
    a.append(2*a[i] + 3)
    p.append(2*p[i] + 1)
    
def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    # 3つの場合分け
    mid = (a[n]+1)/2
    if x == mid:
        return 1 + p[n-1]
    elif x < mid:
        return f(n-1, x-1)
    elif x > mid:
        return f(n-1, x-mid) + 1 + p[n-1]

print(f(n, x))

Measured memory_bytes: 3064