akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
long long INF = 1e10;
/************************  DEFINE  ****************************/

/************************ FUNCTION ****************************/

/************************   MAIN   ****************************/
int main(void){
    
    ll n,k;cin>>n>>k;
    ll ans = 0;
    if(3*n<k){
        cout << 0 << endl;
        return 0;
    }
    if(k%2==0){
        ll s = 1+(n-k/2)/k,t = n/k;
        ans += s*(s-1)*(s-2) + 3*s*(s-1) + s;
        ans += t*(t-1)*(t-2) + 3*t*(t-1) + t;
    }else{
        ll t = n/k;
        ans += t*(t-1)*(t-2) + 3*t*(t-1) + t;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main(){
    ll D;
    cin>>A>>B>>C>>D;
    A += B; C += D;
    if(A > C) S = "Left";
    if(A == C) S = "Balanced";
    if(A < C) S = "Right";
    cout<<S<<endl;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List


data Dice = Dice{tp::Int, fr::Int, rt::Int, lt::Int, bk::Int, bm::Int} deriving (Show, Eq)

roll :: Dice -> Char -> Dice
roll (Dice tp fr rt lt bk bm) dir
  | dir == 'N' = Dice fr bm rt lt tp bk
  | dir == 'S' = Dice bk tp rt lt bm fr
  | dir == 'E' = Dice lt fr tp bm bk rt
  | dir == 'W' = Dice rt fr bm tp bk lt
  | otherwise = Dice tp fr rt lt bk bm

rolls :: Dice -> String -> Dice
rolls d s = foldl roll d s

initDice :: [Int] -> Dice
initDice [tp, fr, rt, lt, bk, bm] = Dice tp fr rt lt bk bm

main = do
  xs <- input (map read . words) :: IO [Int]
  s <- getLine
  print $ solve xs s

solve :: [Int] -> String -> Int
solve xs s = tp $ rolls (initDice xs) s

input :: (String -> a) -> IO a
input f = f <$> getLine

Measured memory_bytes: 3660
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
  		int A = sc.nextInt();
      	int B = sc.nextInt();
  		
      	System.out.println(Math.max(Math.max(A + B, A - B), A * B));
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    vector<int> B(n);
    vector<int> C(m);
    vector<int> D(m);
    rep(i, n)
    {
        cin >> A[i];
        cin >> B[i];
    }
    rep(i, m)
    {
        cin >> C[i];
        cin >> D[i];
    }
    for (int i = 0; i < n; i++)
    {
        int mindist = abs(A[i] - C[0]) + abs(B[i] - D[0]);
        int checkp = 1;
        for (int j = 0; j < m; j++)
        {
            int mindistk = abs(A[i] - C[j]) + abs(B[i] - D[j]);
            if (mindistk < mindist)
            {
                mindist = mindistk;
                checkp = j + 1;
            }
        }
        cout << checkp << endl;
    }
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split;
    auto N = s[0].to!int;
    auto K = s[1].to!long;
    auto A = N.iota.map!(_ => readln.split.map!(to!long).array).array;

    auto B = matpow(A, K);
    long ans = 0;
    foreach (i; 0..N) foreach (j; 0..N) (ans += B[i][j]) %= MOD;
    ans.writeln;
}


long[][] matmul(long[][] m1, long[][] m2) {
    int n = m1.length.to!int;
    long[][] ret = new long[][](n, n);

    foreach (i; 0..n) foreach (j; 0..n) foreach (k; 0..n) {
        (ret[i][j] += m1[i][k] * m2[k][j] % MOD) %= MOD;
    }

    return ret;
}

long[][] matpow(long[][] m, long x) {
    int n = m.length.to!int;
    long[][] ret = new long[][](n, n);
    foreach (i; 0..n) ret[i][i] = 1;

    while (x) {
        if (x % 2) ret = matmul(ret, m);
        m = matmul(m, m);
        x /= 2;
    }

    return ret;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string  a,b,c;
    cin>>a>>b>>c;
    int d,e,f;
    d =a.size();
    e =b.size();
    f =c.size();

    if(a[d-1]==b[0] && b[e-1]==c[0])
    {

        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }

    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・ev,ev -> ev or od,od -> ev
・奇数の個数 mod 2 が不変量
・1回以上操作をすると偶数が1つ以上残る
・N >= 2なので偶数が残る。よってodが奇数個ならむり
・奇数が偶数個なら、奇数を固めたあとつぶしていけばできる
"""

N,*A = map(int,read().split())

od = sum(x&1 for x in A)
answer = 'NO' if od & 1 else 'YES'
print(answer)

Measured memory_bytes: 12512
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

int a[100'009];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  int ans = -1;
  int best = 2'000'000'000;
  for (int i = 0; i < n - 1; ++i) {
    int cur = min(abs(a[i] - a[n - 1] / 2), abs(a[i] - (a[n - 1] + 1) / 2));
    if (cur < best) {
      ans = i;
      best = cur;
    }
  }
  printf("%d %d\n", a[n - 1], a[ans]);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

signed main() {
    int X, Y;
    cin >> X >> Y;
    if (Y == 1 || X % Y == 0) {
        cout << -1 << endl;
        return 0;
    }
    Y--;
    cout << X * Y << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main {

	public void run() {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();//猫の数
		int n = sc.nextInt();//部屋の数
		double[][] p = new double[m][n];
		for (int i = 0; i < m; ++i) {
			for (int j = 0; j < n; ++j) {
				p[i][j] = sc.nextDouble();
			}
		}
		double[][] prob = new double[n + 1][1 << m];
		Arrays.fill(prob[n], 1);
		for (int s = (1 << m) - 2; s >= 0; --s) {
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < m; ++j) {
					if ((s >> j) % 2 == 1)
						continue;
					double tmp = 0;
					double mul = 1;
					for (int k = i; k <= n; ++k) {
						tmp += prob[k][s | 1 << j] * mul * (1 - (k == n ? 0 : p[j][k]));
						if (k < n)
							mul *= p[j][k];
					}
					prob[i][s] = Math.max(prob[i][s], tmp);
				}
			}
		}
		System.out.println(String.format("%.40f", prob[0][0]));
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 40876
#include<bits/stdc++.h>
#pragma GCC optimize("trapv")
#define I inline void 
#define S struct 
#define vi vector<int> 

using namespace std ; 
using ll = long long ; 
using ld = long double ; 

const int N = 1e5 + 7 , mod = 1e9 + 7 ; 
int n ; 

// How interesting!

int main(){
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ;
	//freopen("in.in" , "r" , stdin) ; 
	int a  , b, c ; 
	cin >> a >> b >> c ; 
	if(b * c >= a){
		cout <<"Yes" ; 
	}
	else cout<<"No" ; 

	return 0 ; 
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    
    char a, b;
    cin >> a >> b;
    
    if(a == 'H'){
        cout << b << endl;
        return 0;   
    }else{
        if(b == 'H'){
            cout << "D\n";
            return 0;
        }else{
            cout << "H\n";
            return 0;
        }
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second  
#define endl '\n'
#define pb push_back
#define t_case ll tt; cin>>tt; while (tt--)
#define all(v) v.begin(),v.end()
#define ub(a,x) upper_bound(all(a),x)-a.begin()
#define lb(a,x) lower_bound(all(a),x)-a.begin()
#define fr(a,b,c) for (ll a=b;a<c;a++)
#define take(xx,n) for (int i=0;i<n;i++) cin>>xx[i];
#define take1(xx,n) for (int i=1;i<=n;i++) cin>>xx[i];
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

int main() 
{
	fastio
	//t_case
	{
		ll n,m,k,x,y,q,ans=0,f=1,sum=0  ;cin>>n ;
		ll a[n]; take (a,n);
		sort(a,a+n); m=n-2; sum+=a[n-1];
		for(int i=n-2;m>0;i--) {
			if (m==1) sum+=a[i],m--;
			else {
				m-=2;
				sum+=a[i]; sum+=a[i];
			}
		}
		cout<<sum;
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 5168
N,*a = map(int,open(0).read().split())
for i in range(N)[::-1]:
    part_rem = sum(a[i::i+1]) % 2
    if a[i] != part_rem:
        a[i] = abs(a[i] - 1) 

print(sum(a))
print(*[i+1 for i,v in enumerate(a) if v == 1])

Measured memory_bytes: 11644
#include<stdio.h>
int main(void)
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if ( a <= b && b <= c )
    printf("%d %d %d\n", a, b, c);
    else if ( a <= c && c <= b )
    printf("%d %d %d\n", a, c, b);
    else if ( b <= a && a <= c )
    printf("%d %d %d\n", b, a, c);
    else if ( b <= c && c <= a )
    printf("%d %d %d\n", b, c, a);
    else if ( c <= a && a <= b )
    printf("%d %d %d\n", c, a, b);
    else 
    printf("%d %d %d\n", c, b, a);

    return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <cstdio>
#include <vector>
#include <cassert>
#include <unordered_map>
#include <numeric>

using namespace std;


class Solution{

private:
    const int MOD = 1e9 + 7;
    int N, X, Y, Z;
    vector<vector<int>> dp;

public:
    int num(int N, int X, int Y, int Z){

        this->N = N, this->X = X, this->Y = Y, this->Z = Z;

        long long res = 1ll;
        for(int i = 0; i < N; i ++) res *= 10ll, res %= MOD;

        dp = vector<vector<int>>(N, vector<int>(1 << (X + Y + Z), -1));
        return (res - go(0, 0) + MOD) % MOD;
    }

private:
    int go(int index, int state){

        if(index == N) return 1;
        if(dp[index][state] != -1) return dp[index][state];

        int res = 0;
        for(int i = 1; i <= 10; i ++){
            int nextstate = ((state << i) + (1 << (i - 1))) & ((1 << (X + Y + Z)) - 1);
            if(!(nextstate & (1 << (Z - 1))) || !(nextstate & (1 << (Y + Z - 1))) || !(nextstate & (1 << (X + Y + Z - 1))))
                res += go(index + 1, nextstate), res %= MOD;
        }
        return dp[index][state] = res;
    }
};

int main() {

//    printf("%d\n", Solution().num(3, 5, 7, 5));
//    // 1
//
//    printf("%d\n", Solution().num(4, 5, 7, 5));
//    // 34
//
//    printf("%d\n", Solution().num(37, 4, 2, 3));
//    // 863912418
//
//    printf("%d\n", Solution().num(40, 5, 7, 5));
//    // 562805100

    int N, X, Y, Z;
    scanf("%d%d%d%d", &N, &X, &Y, &Z);
    printf("%d\n", Solution().num(N, X, Y, Z));

    return 0;
}


Measured memory_bytes: 23868
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,j,n=0,t,a,b,c=0,sum=0;
	string s,s1,s2;
	cin>>t;
	for(i=1;i<=t;i++)
    {
        if(t%i==0)
        {
            sum+=(t/i)-1;
        }
        else
        {
            sum+=(t/i);
        }
 
    }
    cout<<sum<<"\n";
	return 0;
}

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

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

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

using namespace std;

int cnt = 0;

void merge(vector<int>& A, int left, int mid, int right) {
	int length = right - left;
	int* temporary = new int[length];
	int l = left,
		r = mid,
		k = 0; // indexes for first half,second half,new array
	for (int i = 0; i < length; ++i) {
		
		if (l < mid&&r < right) {
			if (A[l] < A[r]) {
				cnt++;
				temporary[k] = A[l];
				l++;
				k++;
			}
			else {
				cnt++;
				temporary[k] = A[r];
				r++;
				k++;
			}
		}
		else if (l == mid) {
			cnt++;
			temporary[k] = A[r];
			r++;
			k++;
		}
		else {
			cnt++;
			temporary[k] = A[l];
			l++;
			k++;
		}

	}
	for (int i = 0; i < length; ++i) {
		A[left + i] = temporary[i];
	}
	delete[] temporary;
}

void mergeSort(vector<int>& A, int left, int right) { //call this as(v,0,n)
	if (right - left == 1) return;

	int mid = right - (right - left) / 2;
	mergeSort(A, left, mid);
	mergeSort(A, mid, right);
	merge(A, left, mid, right);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> v(n);
	REP(i, n) {
		cin >> v[i];
	}
	mergeSort(v, 0, n);
	REP(i, n) {
		cout << v[i];
		if (i == n - 1) cout << endl;
		else cout << " ";
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 7596
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int a, b, x;
	cin >> a >> b >> x;
	if(((a + b) >= x) && a <= x) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

void solve()
{
    ll n,x,m;
    cin>>n>>x>>m;
    vi v;
    v.pb(x);
    map<ll,ll>lol;
    lol[x]=0;
    ll ind=-1,p;
    for(int i=2;i<=n;i++)
    {
        p=v.back();
        p=p*p;
        p%=m;
        if(p==0)
        {
            ll ans=0;
            for(auto u:v)
                ans+=u;
            cout<<ans<<endl;
            return;
        }
        if(lol.find(p)!=lol.end())
        {
            ind=lol[p];
            break;
        }
        v.pb(p);
        lol[p]=i-1;
    }
    if(ind==-1)
    {
        ll ans=0;
        for(auto u:v)
            ans+=u;
        cout<<ans<<endl;
        return;
    }
    ll sz=v.size();
    ll rsz=sz-ind;
    ll c=(n-ind)/rsz;
    ll rem=(n-ind)%rsz;
    ll ans=0;
    rep(i,0,sz)
    {
        if(i<ind)
            ans+=v[i];
        else
        {
            if(i-ind+1<=rem)
            {
                ans+=v[i]*(c+1);
            }
            else
                ans+=v[i]*c;
        }
    }
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 6700
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}


using namespace std;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll mod = 1e9+7;

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n){
        cin >> a[i];
    }
    
    ll kC2 = nCr(k, 2);
    if(kC2 >= mod){
        kC2 %= mod;
    }
    
    ll result = 0;
    rep(i, n){
        ll befCount = 0;
        ll aftCount = 0;
        rep(j, i){
            if(a[i] > a[j]){
                befCount ++;
            }
        }
        
        For(j, i+1, n){
            if(a[i] > a[j]){
                aftCount ++;
            }
        }
        if(befCount >= mod){
            befCount %= mod;
        }
        if(aftCount >= mod){
            aftCount %= mod;
        }
        result += ((befCount * kC2) % mod) + (aftCount * (kC2+k)) % mod;
        if(result >= mod){
            result %= mod;
        }
    }
    
    cout << result << endl;
}


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

#define all(x) x.begin(),x.end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
    int n;
    vector<int> num;
    int res=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int temp;
        scanf("%d",&temp);
        num.push_back(temp);
        res ^=temp;
    }
    for(int i=0;i<n;i++){
        int temp = res ^ num[i];
        printf("%d",temp);
        if(i!=n-1){
            printf(" ");
        }else{
            printf("\n");
        }
    }
}


Measured memory_bytes: 4336
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> T keta(T num){ T k=0; while(num>0){ num/=10; k++; } return k; }
template<typename T> void vdebug(vector<T> v){ cout << "vdebug" << endl; for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ cout << "adebug" << endl; reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
template<typename T1, typename T2> void mdebug(map<T1, T2> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int n;
    string sin;
    int front_b = 0;
    int back_a = 0;
    int both = 0;
    int cnt = 0;

    cin >> n;
    rep(i, n){
        cin >> sin;
        reps(i, 1, sin.length()-1){
            if(sin[i-1] == 'A' && sin[i] == 'B') cnt++;
        }

        if(sin[0] == 'B' && sin[sin.length()-1] == 'A') both++;
        else{
            if(sin[0] == 'B') front_b++;
            if(sin[sin.length()-1] == 'A') back_a++;
        }
    }

    if(both > 0){
        if(both >= 1){
            if(front_b > 0){
                front_b--;
                cnt++;
            }
            if(back_a > 0){
                back_a--;
                cnt++;
            }
        }
        if(both > 1){
            cnt += both-1;
        }
    }

    if(front_b > 0 && back_a > 0){
        cnt += min(front_b, back_a);
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
<?php
$input = STDIN;

list($n, $m) = array_map('intval', explode(' ', trim(fgets($input))));

for ($i = 0; $i < $n; $i++) {
    $A[] = array_map('intval', explode(' ', trim(fgets($input))));
}

for ($j = 0; $j < $m; $j++) {
    $B_j = intval(trim(fgets($input)));
    for ($i = 0; $i < $n; $i++) {
        $A[$i][$j] *= $B_j;
    }
}

$C = array_map('array_sum', $A);
print implode("\n", $C) . "\n";


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

const int N = 1000 * 1000 + 5, LG = 20;

int a[N];
int cnt[5];

int get(int x, int y) {
	return (x >> y) & 1;
}

int chs(int x, int y) {
	for (int i = 0; i <= LG; i++) {
		if (!get(x, i) && get(y, i)) {
			return 0;
		}
	}
	return 1;
}
int main() {
	ios :: sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		char c;
		cin >> c;
		a[i] = c - '0';
		cnt[a[i]]++;
	}
	if (cnt[2] == 0) {
		int ans = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] == 3) {
				ans ^= chs(n - 1, i - 1);
			//	cout << n - 1 << " " << i - 1 << " " << chs(n - 1, i - 1) << endl;
			}
			
		}
		cout << ans * 2;
	}
	else {
		int ans = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] % 2) {
				ans ^= chs(n - 1, i - 1);
			}	
		}
		cout << ans;
	}
	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;

void solve(){
    int n;
    cin >> n;
    int a[n+10], b[n+10], c[n+10];
    rep(i,n){
        cin >> a[i] >> b[i] >> c[i];
    }
    int dpa[n+10], dpb[n+10], dpc[n+10];
    dpa[0]=a[0];
    dpb[0]=b[0];
    dpc[0]=c[0];
    for(int i=1; i<n; i++){
        dpa[i]=max(dpb[i-1]+a[i], dpc[i-1]+a[i]);
        dpb[i]=max(dpa[i-1]+b[i], dpc[i-1]+b[i]);
        dpc[i]=max(dpa[i-1]+c[i], dpb[i-1]+c[i]);
    }
    cout << max(dpa[n-1], max(dpb[n-1], dpc[n-1])) << endl;
}

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


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

void Bubble(char a[37][3], int n);
void Selection(char a[37][3], int n);
void Trace(char a[37][3], int n);

int main(void){
	int n;
	char card[37][3];
	char t1[37][3];
	char t2[37][3];
	cin >> n;

	for(int i=0; i<n; i++){
		scanf("%s", card[i]);
		strcpy(t1[i], card[i]);
		strcpy(t2[i], card[i]);
	}

	Bubble(t1, n);
	Selection(t2, n);
	Trace(t1, n);
	cout << "Stable\n";
	Trace(t2, n);
	int i;
	for(i=0; i<n; i++){
		if(strcmp(t1[i], t2[i]) != 0) break;
	}
	if(i == n) cout << "Stable\n";
	else cout << "Not stable\n";

	return 0;
}

void Bubble(char a[37][3], int n){
	for(int i=0; i<n; i++){
		for(int j=n-1; j>i; j--){
			if(a[j][1] < a[j-1][1]){
				char temp[3];
				strcpy(temp, a[j]);
				strcpy(a[j], a[j-1]);
				strcpy(a[j-1], temp);
			}
		}
	}
}

void Selection(char a[37][3], int n){
	for(int i=0; i<n; i++){
		int mini = i;
		for(int j=i; j<n; j++){
			if(a[j][1] < a[mini][1]){
				mini = j;
			}
		}
		if(i != mini){
			char temp[3];
			strcpy(temp, a[i]);
			strcpy(a[i], a[mini]);
			strcpy(a[mini], temp);
		}
	}
}

void Trace(char a[37][3], int n){
	for(int i=0; i<n; i++){
		if(i!=n-1)printf("%s ", a[i]);
		else printf("%s\n", a[i]);
	}
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;

int main() {
    int64_t A, B, N, ans, t;
    cin >> A >> B >> N;
    t = (N + 1) / B * B - 1;
    cout << max(A * t / B - A * (t / B), A * N / B - A * (N / B)) << endl;

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
int main()
{
	ll a,b,k,x,i,s=0,y,p,q;
	cin>>a>>b>>k;
	x=k-a;
	if(x>=0)
	{
		
		if(x-b>=0) cout<<0<<" "<<0;
		else cout<<0<<" "<<b-x;
	}
	else cout<<a-k<<" "<<b;

	
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < A.length; ++i) {
            A[i] = sc.nextInt();
        }

        System.out.println(solve(A));

        sc.close();
    }

    static String solve(int[] A) {
        int[] sorted = Arrays.stream(A).boxed().sorted(Collections.reverseOrder()).mapToInt(x -> x).toArray();

        return Arrays.stream(A).mapToObj(x -> String.valueOf((x == sorted[0]) ? sorted[1] : sorted[0]))
                .collect(Collectors.joining("\n"));
    }
}

Measured memory_bytes: 71588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

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

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
    
  int main(){
      lint N,W;
      cin>>N>>W;
        lint V[N];
        lint WW[N];
      rep(i,N){
          lint v,w;
          cin>>v>>w;
          V[i]=v;WW[i]=w;
      }
     lint dp[N+1][W+1];
      rep(i,W+1){
          dp[0][i]=0;
      }
      rep(i,N){
          rep(j,W+1){
            if(j>=WW[i])dp[i+1][j]=max(dp[i][j],dp[i][j-WW[i]]+V[i]);
            else dp[i+1][j]=dp[i][j];
          }
      }
      cout<<dp[N][W]<<endl;
    }
     
  



Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
 
struct Item{
    ll va,we;
};
 
int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    ll n,w;
    cin >> n >>w;
    Item items[n+1]={0};
    //vector<vector<int>> nw(n+1,vector<int>(2,0));
    ll vaMax=0;
    for(int i=1;i<n+1;i++){
        cin >> items[i].we >>items[i].va;
        vaMax+=items[i].va;
    }   
    vector<vector<ll>> dp(n+1,vector<ll>(vaMax+1,1000000000));
    for(int i=0;i<=n;i++)dp[i][0]=0;
    int vi=0,vj=0;
    for(int i=1;i<n+1;i++){
        for(int j=1;j<=vaMax;j++){
            dp[i][j]=dp[i-1][j];
            if(j-items[i].va<0) continue;
            dp[i][j]=min(dp[i-1][j],dp[i-1][j-items[i].va]+items[i].we);
            if(dp[i][j]>w) continue;
            //cout << "vmax"<<j<<" minwa"<<dp[i][j]<<endl;
            if(dp[i][j]<=w){
                vj=max(vj,j);
            }
        }
    }
    cout << vj;
    return 0;
}

Measured memory_bytes: 80256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<map>
#include<set>
#include<string>
#include<cctype>
#include<cmath>
#include<algorithm>
#define LL long long
#define ULL unsigned long long
#define debug(x) cerr << #x << " = " << x << endl
#define MAXN 500010
using namespace std;
int read(){
	int x = 0, f = 1; char ch = getchar(); for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
	for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return x * f;
}

int n, m;

struct CCM{int t, ne, l;} e[MAXN];
int num = -1, v[200010];

void add(int x, int y, int l){
	e[++num].t = y, e[num].l = l, e[num].ne = v[x], v[x] = num;
}

int q[MAXN], inq[200010];
int dis[200010];

int main(){
	memset(v, -1, sizeof v);
	n = read(), m = read();
	for(int i = 1, x, y; i <= m; i++){
		x = read(), y = read();add(x, y, 1);// add(y, x, 1);
	}
	inq[1] = 1; q[1] = 1;
	memset(dis, 127, sizeof dis);
	dis[1] = 0;
	int head = 0, tail = 1 ,x;
	while(head < tail){
		x = q[++head]; inq[x] = 0; //debug(x);
		for(int i = v[x]; i != -1; i = e[i].ne){
			if(dis[e[i].t] > dis[x] + e[i].l){
				dis[e[i].t] = dis[x] + e[i].l;
				if(!inq[e[i].t]){
					inq[e[i].t] = 1;
					q[++tail] = e[i].t;
				}
			}
		}
	}
	if(dis[n] <= 2) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

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


using namespace std;

int main()
{
    int a[4],i;
    for(i=0;i<3;i++)
        cin >> a[i];
    sort(a,a+3);
    int sum = 0 ;
    for(i=1;i<3;i++)
        sum += (a[i]-a[i-1]);
    cout << sum << '\n' ;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include<bits/stdc++.h>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>*/

#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define rep(a, b, c) for(int a = b; a <= c; ++a)
#define per(a, b, c) for(int a = b; a >= c; --a)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
//using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
/*typedef tree<pair<int, int>, 
null_type, less<pair<int, int>>, 
rb_tree_tag, tree_order_statistics_node_update>
ordered_set;*/
//find_by_order() order_of_key()

const double eps = 1e-7;
const int mod = 1e9+7, MXN = 5e5+17;
const int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};

template<typename T>inline bool updmin(T &a, const T &b) {return a > b ? a = b,1 : 0;}
template<typename T>inline bool updmax(T &a, const T &b) {return a < b ? a = b,1 : 0;}

string s;
ll res, pref[15], pw[15];

inline ll get(int l, int r) {
	if(!l) return pref[r];
	return pref[r]-pref[l-1]*pw[r-l+1];
}

int32_t main() { _
#ifdef DanQQQQQ
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	cin >> s;
	pw[0] = 1ll;
	rep(i,1,sz(s)-1) pw[i] = pw[i-1]*10ll;
	pref[0] = s[0]-'0';
	rep(i,1,sz(s)-1) pref[i] = pref[i-1]*10ll+s[i]-'0';
	rep(i,0,(1<<(sz(s)-1))-1) {
		int last = 0;
		rep(j,0,sz(s)-2) if((i>>j)&1)
			res += get(last,j), last = j+1;
		res += get(last,sz(s)-1);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 384
import math
def comb(n, r):
  if n - r < 0:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
MOD = 10**9 + 7
N, K = map(int, input().split(' '))
red = N - K
for i in range(K):
  res = comb(red + 1, i + 1) * comb(K - 1, i)
  res %= MOD
  print(res)

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */


int main(){
    int a[5];
    rep(i, 5) cin >> a[i];
    rep(i, 5){
        if(a[i] == 0) out(i+1);
    }
}

Measured memory_bytes: 3632
##解答を見た 手前でO(H^2W^2) ~O(10^9)くらいのことをしていた
H,W,D = map(int,input().split())
A = []
for i in range(H):
    A.append(list(map(int,input().split())))

pos = [[0 for i in range(2)] for j in range(H*W+1)]

for i in range(H):
    for j in range(W):
        pos[A[i][j]][0] = i+1
        pos[A[i][j]][1] = j+1

dist = []
for i in range(1,H*W+1):##O(HW)
    if i<=D:
        dist.append(0)
    else:
        dist.append(dist[i-D-1]+abs(pos[i][0]-pos[i-D][0])+abs(pos[i][1]-pos[i-D][1]))

LR = []
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
    LR.append([L,R])

for i in range(Q):
    print(dist[LR[i][1]-1]-dist[LR[i][0]-1])

Measured memory_bytes: 39136
Sa = " ".join(input()).split()
Sb = " ".join(input()).split()
Sc = " ".join(input()).split()
s='a'
while s:
    if s=='a':
        if len(Sa)==0:
            print("A")
            exit()
        s = Sa.pop(0)
    elif s=='b':
        if len(Sb)==0:
            print("B")
            exit()
        s = Sb.pop(0)
    else:
        if len(Sc)==0:
            print("C")
            exit()
        s = Sc.pop(0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vi a(n + 1), ans;
	rep(i, n) cin >> a[i+1];
	for(int i = n; i > 0; i--) if(a[i]){
		ans.pb(i);
		for(int j = 1; j * j <= i; j++) if(i % j == 0){
			a[j] ^= 1;
			if(j * j != i){
				a[i / j] ^= 1;
			}
		}
	}
	cout << ans.size() << endl;
	rep(i, ans.size()) cout << ans[i] << (i==ans.size()-1?"\n":" ");
	
	return 0;
}

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

int main() {
	string s;
	cin >> s;
	int a = (s[0] - '0') * 10 + s[1] - '0';
	int b = (s[2] - '0') * 10 + s[3] - '0';
	if (a >= 1 && a <= 12) {
		if (b >= 1 && b <= 12) {
			cout << "AMBIGUOUS" << endl;
		}
		else cout << "MMYY" << endl;
	}
	else if (b >= 1 && b <= 12) cout << "YYMM" << endl;
	else cout << "NA" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;


public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] d = new int[n];
        for(int i = 0; i < n; i++) d[i] = scan.nextInt();
        int out = 0;
        for(int i = 0; i < n - 1; i++){
            for(int j = i + 1; j < n; j++){
                out += d[i] * d[j];
            }
        }
        System.out.println(out);
        scan.close();
    }
}

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

namespace ABC088_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = new double[3][];
            var input = "";
            var arrayTemp = new string[3];
            for (int i = 0; i < 3; i++)
            {
                num[i] = new double[3];
                input = Console.ReadLine();
                arrayTemp = input.Split(' ');
                num[i] = arrayTemp.Select(double.Parse).ToArray();
            }

            double a1 = 0;
            double b1 = num[0][0] - a1;
            double a2 = num[1][0] - b1;
            double a3 = num[2][0] - b1;
            double b2 = num[0][1] - a1;
            double b3 = num[0][2] - a1;
            if (num[1][1] == a2 + b2 && num[1][2] == a2 + b3 && num[2][1] == a3 + b2 && num[2][2] == a3 + b3)
            {
                Console.WriteLine("Yes");
                return;
            }

            for (a1 = 1; a1 <= Math.Ceiling(num[0][0] / 2); a1++)
            {
                if (num[1][1] == a2 + b2 && num[1][2] == a2 + b3 && num[2][1] == a3 + b2 && num[2][2] == a3 + b3)
                {
                    Console.WriteLine("Yes");
                    return;
                }
                b1 = num[0][0] - a1;
                a2 = num[1][0] - b1;
                a3 = num[2][0] - b1;
                b2 = num[0][1] - a1;
                b3 = num[0][2] - a2;
            }
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13396
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>

#define MAX_LEN (3000)
// #define MAX_LEN (12)
#define SIZE_BUF (30)

using namespace std;

int dpss[MAX_LEN + 1][MAX_LEN + 1];

// self study
// time taken 55 min
// 2 WA
int main() {
  // read inputs
  char ss[MAX_LEN + 1], ts[MAX_LEN + 1], buf[SIZE_BUF];
  scanf("%s", ss);
  fgets(buf, SIZE_BUF, stdin);
  scanf("%s", ts);
  //   printf("%s\n", ss);
  //   printf("%s\n", ts);

  // get length of each string
  const int N = strlen(ss), M = strlen(ts);
  //   printf("N = %d, M = %d\n", N, M);

  // solve dp
  // initialize
  dpss[0][0] = 0;
  for (int i = 0; i < N; i++) {
    dpss[i + 1][0] = 0;
  }
  for (int j = 0; j < M; j++) {
    dpss[0][j + 1] = 0;
  }
  // update
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (ss[i] == ts[j]) {
        dpss[i + 1][j + 1] = dpss[i][j] + 1;
      } else {
        dpss[i + 1][j + 1] = max(dpss[i][j + 1], dpss[i + 1][j]);
      }
    }
  }

  // retrieve the LCS
  char cs[MAX_LEN + 1];
  cs[dpss[N][M]] = '\0';
  int i = N - 1, j = M - 1, k = dpss[N][M] - 1;
  while (k >= 0) {
    if (ss[i] == ts[j]) {
      cs[k--] = ss[i];
      i--;
      j--;
    } else {
      if (dpss[i + 1][j + 1] == dpss[i][j + 1]) {
        i--;
      } else {
        j--;
      }
    }
  }

  //   printf("%d\n", dpss[N][M]);
  printf("%s\n", cs);
}

Measured memory_bytes: 35328
public class Small_Large_or_Equal {
  static void Main(string[] args) {
    var line = System.Console.ReadLine().Trim().Split(' ');
    int a = int.Parse(line[0]);
    int b = int.Parse(line[1]);
    string str = "a ";

    if(a < b) {
      str += "< b";
    } else if(a == b) {
      str += "== b";
    } else {
      str += "> b";
    }

    System.Console.WriteLine(str);
  }
}

Measured memory_bytes: 8912
// In the name of ALlah //
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e5 * 5 + 10 , inf = 1e9;
int n , m;
void solve(){
    cout << max(0 , n - m);
}
void in (){
    cin >> n >> m;
    solve();
    
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    in();
}


Measured memory_bytes: 3612
#include <iostream>
#include<string>
using namespace std;
int main(void){
    string s;
    getline(cin,s);//一行読み込む
    for(int i=0;i<s.size();i++){
        char c=s[i];
        if('A'<=c && c<='Z'){
            //c=tolower(c);
            c=c+32;
        }
        else if('a'<=c && c<='z'){
            c=c-32;
        }
        cout << c;
    }
    cout << endl;
}


Measured memory_bytes: 3152
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int main(){
  string s,t;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'){
      t+='0';
    }
    if(s[i]=='1'){
      t+='1';
    }
    if(s[i]=='B'&&t.size()>0){
      t=t.substr(0,t.size()-1);
    }
  }
  cout<<t<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f(i,s,v) for(int i=(int)s;i<(int)v;++i)
#define rf(i,s,v) for(int i=(int)s-1;i>(int)v;--i)
#define pb push_back
#define all(v) ((v.begin()),(v.end()))
#define memset(c, value) memset(c, (int)value, sizeof(c))
using namespace std;
typedef long long ll;
const int oo = 1e9;
const ll MOD =1e9+7;
void fast(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int n, c;
int w[100005], v[100005];
bool valid (int r,int c){
    return (r < n && r >= 0 && c >= 0 && c < n);
}
int row[] = {0 , 1 , 0, -1};
int column[] = {1 , 0, -1, 0};
ll vis[101][100001];
ll dp(int i, int current){
    if(i == n)
        return 0;
    ll &ret = vis[i][current];
    if(ret != -1)
        return ret;

    ll ans = dp(i+1, current);
    if(current >= w[i])
        ans = max(ans, v[i] + dp(i+1, current - w[i]));

    return ret = ans;
}

int main()
{
    fast();
    memset(vis, -1);
    cin>>n>>c;
    f(i,0,n)
        cin>>w[i]>>v[i];
    cout<<dp(0, c)<<'\n';
    return 0;
}


Measured memory_bytes: 82500
#include <bits/stdc++.h>
using namespace std;
int main(){
    int64_t tate,yoko;
    int64_t ans=0;
    cin >> tate >> yoko;
    int64_t hantei = tate*yoko;

    if(tate ==1 || yoko ==1) ans=1;
    else if(hantei%2 ==0) ans = hantei/2;
    else if(hantei%2 ==1) ans= hantei/2+1;

    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 256
import math
N = int(input())
a_limit = math.ceil(math.sqrt(N))
ans = 0
for a in range(1,a_limit+1):
    b_limit = N//a
    for b in range(a,b_limit+1):
        c = N - a*b
        if c != 0:
            if a == b:
                ans += 1
            else:
                ans += 2
    
print(ans)

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<pair<long long,long long>> v;
  for(int i=0; i<n; i++){
    long long a, b;
    cin >> a >> b;
    v.push_back(make_pair(a,b));
  }
  sort(v.begin(), v.end());
  int id=0;
  long long num=0uLL, ans=0uLL;
  while(num<m){
      num+=v.at(id).second;
      ans+=v.at(id).first*v.at(id).second;
      id++;
  }
  ans-=v.at(id-1).first*(num-m);

  cout << ans << endl;
}


Measured memory_bytes: 2548
'use strict'

let cnt = 0
let num
let len
const chara = []

const rec = str => {
  if (str.length < len) {
    rec(str + '0')
    rec(str + '3')
    rec(str + '5')
    rec(str + '7')
  } else {
    // console.log(str)
    chara.push(str)
  }
}

const has753 = str => {
  let tmp = ~~str //数値化で先頭の0を削除
  tmp = tmp.toString() // stringに戻す

  return str.indexOf('3') >= 0 &&
    str.indexOf('5') >= 0 &&
    str.indexOf('7') >= 0 &&
    tmp.indexOf('0') < 0
    ? true
    : false
}

function main(input) {
  num = input.split('\n')[0]
  len = num.length
  num = ~~num

  rec('')

  for (let i in chara) {
    if (~~chara[i] <= num && has753(chara[i])) {
      // console.log(~~chara[i])
      cnt++
    }
  }
  console.log(cnt)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 57012
n = int(input())
ary = list(map(int, input().split()))

ext = [0] * n
ans = 0
for i in range(1,n):
    if ary[i] < (ary[i - 1] + ext[i - 1]):
        ext[i] = (ary[i - 1] + ext[i - 1]) - ary[i]
print(sum(ext))


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

using namespace std;

typedef long long ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll A, B, C, K; cin >> A >> B >> C >> K;
  if(K %2 == 0){
    cout << A - B << endl;
  }else{
    cout << B - A << endl;
  }
}

Measured memory_bytes: 256