akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize,
    }
    for k in 1..=n {
        let mut ans = 0usize;
        for x in 1..100 {
            if x * x > k {
                break;;
            }
            for y in x..100 {
                if x * x + y * y > k {
                    break;
                }
                for z in y..100 {
                    let v = d(x, y, z);
                    if v == k {
                        if x ==y && y == z {
                            ans += 1;
                        } else if x == y || y == z {
                            ans += 3;
                        } else {
                            ans += 6;
                        }
                        break;
                    } else if v > k {
                        break;
                    }
                }
            }
        }
        println!("{}", ans);
    }

}

fn d(x: usize, y: usize, z: usize) -> usize {
    x*x + y*y + z*z + x*y + y*z + z*x
}

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

using namespace std;

int main()
{
    string s;
    int nortesur=1,esteoeste=1;
	map<char,bool> m;
    cin>>s;

    for(int i=0; i<s.size(); i++)
    {
    	m[s[i]]=true;
	}
	
	if(m.size()==4)
		cout<<"Yes";
	else if(m.size()==2)
	{
		//cout<<"Dim 2"<<endl;
		map<char,bool>::iterator it=m.begin(), it2=it++;
		//cout<<it->first<<" "<<it2->first<<endl;
		if(it->first == 'S' && it2->first == 'N' )
			cout<<"Yes";
		else if(it->first == 'W' && it2->first == 'E')
			cout<<"Yes";
		else
			cout<<"No";
	}
	else
		cout<<"No";	
	cout<<endl;
    return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}

// ====================================================================

int main() {
  // 入力
  ll n, m;
  cin >> n >> m;
  vector<int> g[n + 1];
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    g[u].push_back(v);
  }
  int s, t;
  cin >> s >> t;

  ll d[n + 1][3];  // 3n,3n+1,3n+2の最短距離をもつ
  for (int i = 0; i <= n; i++)
    for (int j = 0; j < 3; j++)
      d[i][j] = -1;

  // 幅優先探索
  queue<int> q;
  q.push(s);
  d[s][0] = 0;
  while (!q.empty()) {
    int now = q.front();
    q.pop();

    for (auto x : g[now]) {
      for (int i = 0; i < 3; i++) {
        int nowd = d[now][i];
        if (nowd == -1) continue;  // -1だったら何もしない

        ll tar = d[x][(nowd + 1) % 3];
        if (tar > nowd + 1 || tar == -1) {  // もっと良いルートが分かっている
          d[x][(nowd + 1) % 3] = nowd + 1;
          q.push(x);
        }
      }
    }
  }

  if (d[t][0] == -1) {
    cout << -1 << endl;
  } else {
    cout << d[t][0] / 3 << endl;
  }

  // cout << endl;
  // for (int i = 1; i <= n; i++) {
  //   cout << d[i][0] << " " << d[i][1] << " " << d[i][2] << endl;
  // }
  //
  // for (int i = 1; i <= n; i++) {
  //   cout << g[i] << endl;
  // }
}


Measured memory_bytes: 8064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
using Graph = vector<vector<int>>;

int main(){
    string s,t;
    cin>>s>>t;
    ll ans = 0;
    for(ll i=0;i<s.length();i++){
        if(s[i] != t[i]) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3848
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
ll a[N], b[N];

int main() {
  int n; ll k; scanf("%d %lld", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%lld", a+i);
  sort(a, a+n);
  int m = 0;
  for (int i = 0; i < n; i++)
    if (a[i] > 0)
      b[m++] = a[i];
  int z = 0;
  for (int i = 0; i < n-m; i++) {
    if (a[i] == 0)
      z++;
    a[i] *= -1;
  }
  reverse(a, a+n-m);
  ll lo = -1e18, hi = 1e18;
  while (lo <= hi) {
    ll cnt = 0;
    ll mi = (lo+hi) / 2;
    mi++;
    for (int i = 0; i < n-m; i++) {
      if (a[i] == 0 && mi <= 0)
        cnt += n-m-i-1 + m;
      else if (a[i] != 0)
        cnt += n-m - (lower_bound(a+i+1, a+n-m, (max(0ll, mi)+a[i]-1) / a[i]) - a);
    }
    for (int i = 0; i < m; i++) {
      cnt += m - (lower_bound(b+i+1, b+m, (max(0ll, mi)+b[i]-1) / b[i]) - b);
      if (mi < 0) {
        cnt += upper_bound(a, a+n-m, (-mi) / b[i]) - a - z;
      }
    }
    mi--;
    if (cnt < (n*1ll*(n-1)) / 2 - k + 1)
      hi = mi - 1;
    else
      lo = mi + 1;
  }
  printf("%lld\n", lo);
  return 0;
}


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

#define fi first
#define se second
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const long long N = 100100;
const long long Q = 100000001;
const long long mod = 1e9 + 7;
const long long MAGIC = 30;

using namespace std;

int d[N];

void solve()
{
        for(int i = 1; i < N; i++){
                d[i] = i;
        }
        for(int i = 6; i < N; i *= 6){
                for(int j = i; j < N; j++){
                        d[j] = min(d[j], d[j - i] + 1);
                }
        }
        for(int i = 9; i < N; i *= 9){
                for(int j = i; j < N; j++){
                        d[j] = min(d[j], d[j - i] + 1);
                }
        }
        int n;
        cin >> n;
        cout << d[n] << "\n";
}

bool mtest = false; int main()
{
        //fin("input.txt");
        //fout("output.txt");
        //fin("maze.in");
        //fout("maze.out");
        ios_base::sync_with_stdio(0);
        int TE = 1;
        if(mtest)
                cin >> TE;
        while(TE--)
                solve();
        return 0;
}


Measured memory_bytes: 640
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		// 計算
		int result = a + b;
		if(result >= 10){
		    System.out.println("error");
		    return;
		}

		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 23892
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double s = r*r*Math.PI;
        double l = r*2*Math.PI;
        System.out.printf("%f %f", s, l);
    }
}


Measured memory_bytes: 28296
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <utility>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    Int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<Int> v(n);
    v[0] = 0;
    for (Int i = 1; i < n; ++i) {
        if (s[i - 1] == 'A' && s[i] == 'C') {
            v[i] = v[i - 1] + 1;
        } else {
            v[i] = v[i - 1];
        }
    }
    for (Int i = 0; i < q; ++i) {
        Int l, r;
        cin >> l >> r;
        cout << v[r - 1] - v[l - 1] << endl;
    }
    return 0;
}



Measured memory_bytes: 4208
#include<stdio.h>
using namespace std;

int main(){
	int n,k,b,s[101],i,j;
	
	for(;scanf("%d%d",&n,&k),n|k;){
		for(i=0;i<k;i++)
			scanf("%d",s+i);
		for(i=0;i<n;i++){
			for(j=0;j<k;j++){
				scanf("%d",&b);
				s[j]-=b;
			}
		}
		b=1;
		for(i=0;i<k;)
			if(s[i++]<0)
				b=0;
		puts(b?"Yes":"No");
	}
}

Measured memory_bytes: 736
var input = "";
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk){input += chunk});
process.stdin.on('end', function()
{
  input = input.split('\n');
  for(var i = 0; i < input.length - 1; i++)
  {
    a = Math.pow(input[i] / 9.8, 2)  * 4.9;
    for(var j = 1; ; j++)
    {
      if(j * 5 - 5 >= a)
      {
        console.log(j);
        break;
      }
    }
  }
});

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

int hu (int x,int y){
  if (y == 0)
    return 1;
  else
    return -1;
}
int main(){
  int p;
  int a, b, c, d;
  string op1, op2, op3,op4;
  cin >> p;
  d = p % 10;
  c = (p/10)%10;
  b = (p/100)%10;
  a = p/1000;
  int m= 0;
  for (int i = 0;  i < 2; i++){
    if (m == 1){
      break;
    }
    for (int j = 0 ; j < 2; j++){
      if(m ==1)
        break;
      for (int k = 0; k < 2; k++){
        if (a+hu(-1,i)*b+hu(-1,j)*c+hu(-1,k)*d == 7){
          
          if (i == 0)
            op1 = '+';
          else
            op1 = '-';
          if (j == 0)
            op2 = '+';
          else
            op2 = '-';
          if (k == 0)
            op3 = '+';
          else
            op3 = '-';
          cout << a << op1 << b << op2 << c << op3 << d << "=7"<<endl;
          m++;
          break;
        }
        else
          continue;
      }
    }
  }
}
           
      

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

import sys
import os


n, k = map(int, input().split())
#print(k, '??°??§????????????')

W = []
for i in range(n):
    W.append(int(input()))

def check(P):
    # ?????????P?????\?????¨??????????????????????????????????????????????????¢??°
    weight_index = 0
    for i in range(k):
        current_weight = 0
        while current_weight + W[weight_index] <= P:
            #print('i', i, W[weight_index], '?????????')
            current_weight += W[weight_index]
            weight_index += 1
            if weight_index == len(W):
                # ??¨??¨?????£???
                return len(W)
    return weight_index

P_min = 1
P_max = sum(W)
P_mid = None
while True:
    P_mid = (P_min + P_max) // 2
    loaded_num = check(P_mid)

    if loaded_num < n:
        # ????????????????????????
        P_min = P_mid + 1
    else:
        # ??????????????????????????§???P??????????????¢???
        P_max = P_mid

    if P_max == P_min:
        break

# ??????
print(P_max)

Measured memory_bytes: 11460
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
    int n;
    cin>>n;
    int ans = 0;
    for(int i= 1;i<=n;i++){
    	int occ = (n/i);
    	int val = (occ * (occ+1))/2;
    	ans += val*i;
    }
    cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
int32_t main()
{
   fastio
   int mod=1000000007;
   int n,m;
   cin>>n>>m;
   int arr[n+1];
   int arr2[m+1];
   repre(i,1,n)cin>>arr[i];
   repre(i,1,m)cin>>arr2[i];
   int dp[n+1][m+1];
   rep(i,n+1)rep(j,m+1)dp[i][j]=1;
   repre(i,1,n)
   {
     repre(j,1,m)
     {
       dp[i][j]=((dp[i-1][j]%mod)+(dp[i][j-1]%mod))%mod;
       if(arr[i]!=arr2[j])dp[i][j]=dp[i][j]-dp[i-1][j-1];
       if(dp[i][j]<0)dp[i][j]+=mod;
     }
   }
   cout<<dp[n][m]<<endl;
   return 0;
}


Measured memory_bytes: 31616
def main():
    x = int(input())

    while True:
        flag_prime = True
        x_ = int(x**0.5) + 1

        for i in range(2, x_):
            if x % i == 0:
                flag_prime = False
                break

        if flag_prime:
            break

        x += 1

    print(x)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  while(true){
    string s;

    //cin.ignore();
    getline(cin, s);

    if(s == ".") break;

    int len = s.length();
    int level1 = 0, level2 = 0;
    bool f = true;
    stack<int> stk;

    REP(i,len){
      if(s[i] == '('){
        level1++;
        stk.push(0);
      }else if(s[i] == '['){
        level2++;
        stk.push(1);;
      }else if(s[i] == ')'){
        if(stk.empty()){
          f = false;
          break;
        }
        int tp = stk.top();
        stk.pop();
        if(tp == 1){
          f = false;
          break;
        }
        level1--;
      }else if(s[i] == ']'){
        if(stk.empty()){
          f = false;
          break;
        }
        int tp = stk.top();
        stk.pop();
        if(tp == 0){
          f = false;
          break;
        }
        level2--;
      }
    }
    if(f && level1 == 0 && level2 == 0){
      cout << "yes\n";
    }else{
      cout << "no\n";
    }
  }
  return 0;
}




Measured memory_bytes: 3144
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b, c, d, x, y;
	cin >> a >> b >> c >> d;
	if (a >= b)
		x = b;
	else
		x = a;
	if (c >= d)
		y = d;
	else
		y = c;
	cout << x + y << "\n";
}

Measured memory_bytes: 3636
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
 
		int a = in.nextInt();
 
		if (a / 100 == a % 10) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

bool equalCharCaseInsensitiveFunction(const char& lhs, const char& rhs) {
  locale locale;
  return tolower(lhs, locale) == tolower(rhs, locale);
}

int main() {
  string w, t;
  cin >> w;
  int count = 0;
  while (cin >> t) {
    if (t == "END_OF_TEXT") break;
    bool equalchar =
        w.size() == t.size() && equal(t.begin(), t.end(), w.begin(),
                                      equalCharCaseInsensitiveFunction);
    if (equalchar) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
int n,a[100004];
bool ok=true;
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	if(n%2==0){
			for(int i=0;i<n-1;i+=2){
				if(a[i]!=i+1||a[i+1]!=i+1){ok=false;break;}
				
			
		}
	}else{
		if(a[0]!=0)ok=false;
		for(int i=1;i<n-1;i+=2){
				if(a[i]!=i+1||a[i]!=i+1){ok=false;break;}
		}
	}
	if(ok){
		long long ppap=1;
		for(int i=0;i<n/2;i++){ppap*=2;ppap%=1000000007;}
		cout<<ppap<<endl;
	}else{
		cout<<0<<endl;
	}
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define Max(x, y)(max(decltype(x)(0), max((x), (y))))
#define Min(x, y)(max(decltype(x)(0), min((x), (y))))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(x) (x).begin(),(x).end()
#define _end '\n'
#define Out(x) cout<<(x)<<_end
template<typename T> inline bool _max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool _min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int h, w;

    cin >> h >> w;

    V<string> grid(h);
    queue<V<pair<int, int> > > q;
    V<pair<int, int> > v, vv;
    pair<int, int> p;
    VV<int> table(h);
    int turn = 1;
    int white = 0;

    int i, j, len;

    rep(i, h) {
        cin >> grid[i];

        table[i] = V<int>(w);

        rep(j, w) {
            if (grid[i][j] == '#') {
                table[i][j] = -1;
            } else {
                white++;
                table[i][j] = INT_MAX;
            }
        }
    }

    table[0][0] = 1;
    v.pb(mp(0, 0));
    q.push(v);
    v.clear();

    while (!q.empty()) {
        vv = q.front();

        q.pop();

        len = vv.size();
        rep(i, len) {
            p = vv[i];

            if (0 <= p.first - 1 && turn + 1 < table[p.second][p.first - 1]) {
                v.pb(mp(p.first - 1, p.second));
                table[p.second][p.first - 1] = turn + 1;
            }
            if (p.first + 1 < w && turn + 1 < table[p.second][p.first + 1]) {
                v.pb(mp(p.first + 1, p.second));
                table[p.second][p.first + 1] = turn + 1;
            }
            if (0 <= p.second - 1 && turn + 1 < table[p.second - 1][p.first]) {
                v.pb(mp(p.first, p.second - 1));
                table[p.second - 1][p.first] = turn + 1;
            }
            if (p.second + 1 < h && turn + 1 < table[p.second + 1][p.first]) {
                v.pb(mp(p.first, p.second + 1));
                table[p.second + 1][p.first] = turn + 1;
            }
        }


        if (v.size() != 0) {
            q.push(v);
            v.clear();
        }

        turn++;
    }

    if (table[h - 1][w - 1] == INT_MAX) Out(-1);
    else Out(white - table[h - 1][w - 1]);

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
vector<int> v[N];
vector<LL> f[N];
LL dep[N];
void DFS(int u,int fa,LL dis) {
    dep[u]=dis;
    for(int i=0;i<v[u].size();i++) {
        int p=v[u][i];
        if(p==fa) continue;
        DFS(p,u,dis+f[u][i]);
    }
}
int main() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++) {
        int a,b;
        LL c;
        scanf("%d%d%lld",&a,&b,&c);
        v[a].push_back(b);
        v[b].push_back(a);
        f[a].push_back(c);
        f[b].push_back(c);
    }
    int q,k;
    scanf("%d%d",&q,&k);
    DFS(k,-1,0);
    while(q--) {
        int aa,bb;
        scanf("%d%d",&aa,&bb);
        printf("%lld\n",dep[aa]+dep[bb]);
    }
    return 0;
}

Measured memory_bytes: 21376
#include <iostream>
using namespace std;                                                                                   
int main () {
  int N;
  string S;
  cin >> N;
  cin >> S;

  if (N % 2 == 1) {
     cout << "No" << endl;
     return 0;
  } else {
    for (int i = 0; i< N/2; ++i) {
      if (S[i] != S[i + N/2]) {
        cout << "No" << endl;
        return 0;
      }   
    }   
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve(int v,const vector<vector<int>> &G,vector<bool> &seen,vector<long long> &cost){
    seen[v]=1;
    for(auto nv:G[v]){
        if(seen[nv])continue;
        cost[nv]+=cost[v];
        solve(nv,G,seen,cost);
    }
}
int main(){
    int N,Q;scanf("%d%d",&N,&Q);
    vector<vector<int>> G(N,vector<int>());
    for(int i=0;i<N-1;i++){
        int a,b;scanf("%d%d",&a,&b);
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<long long> cost(N);
    for(int i=0;i<Q;i++){
        int a;long long b;scanf("%d%lld",&a,&b);
        a--;
        cost[a]+=b;
    }
    vector<bool> seen(N);
    solve(0,G,seen,cost);
    for(int i=0;i<N;i++){
        if(i)printf(" ");
        printf("%lld",cost[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 30592
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD = 998244353;

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

signed main(){
	int n,t;
	cin >> n;
	t = n / 2;
	cout << t * (n - t) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
  int r, g, b;
  int k;
  scanf("%d %d %d", &r, &g, &b);
  k = 10*g + b;
  if (k % 4 == 0) {
    printf("YES");
  } else {
    printf("NO");
  }
  return 0;
}
  


Measured memory_bytes: 128
// https://atcoder.jp/contests/dp/tasks/dp_z

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%d%c", a[i][j], j + 1 == m ? '\n' : ' '); puts("")

//------------------------------------------------------------------------------
template<typename T> class ConvexHull {
public:
  struct line { T a, b; };
  deque<line> Ls;

  T f(line L, T x) {
    return L.a * x + L.b;
  }

  bool check(line L1, line L2, line L3) {
    return (L2.a - L1.a) * (L3.b - L2.b) >= (L3.a - L2.a) * (L2.b - L1.b);
  }

  void add(T a, T b) {
    line L = {a, b};
    int n;
    while ((n = Ls.size()) >= 2) {
      if (!check(Ls[n - 2], Ls[n - 1], L)) break;
      Ls.pop_back();
    }
    Ls.push_back(L);
  }

  T query(T x) {
    while (Ls.size() >= 2) {
      if (f(Ls[0], x) < f(Ls[1], x)) break;
      Ls.pop_front();
    }
    return f(Ls[0], x);
  }
};

//------------------------------------------------------------------------------

const int N_MAX = 2*1e5;
const int C_MAX = 1e12;
const int H_N_MAX = 1e6;
const ll INF = 1e18;

int N;
ll C;
ll h[N_MAX];

ConvexHull<ll> ch;
ll dp;

void solve() {
  ch.add(-2 * h[0], h[0] * h[0]);
  FOR(i, 1, N - 1) {
    dp = h[i] * h[i] + ch.query(h[i]) + C;
    ch.add(-2 * h[i], dp + h[i] * h[i]);
  }
  printf("%lld\n", dp);
}

void input() {
  scanf("%d%lld", &N, &C);
  REP(i, N) scanf("%lld", h + i);
}

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


Measured memory_bytes: 3968
// 2012/10/28 Tazoe

#include <iostream>
#include <string>
using namespace std;

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

	for(int i=0; i<N; i++){
		string S1, S2;
		cin >> S1;
		cin >> S2;

		if(S1.size()<S2.size()){
			string tmp = S1;
			S1 = S2;
			S2 = tmp;
		}

		if(S1.size()>80){
			cout << "overflow" << endl;
			continue;
		}

		int A[80];
		int C = 0;
		for(int j=0; j<S1.size(); j++){
			int tmp = (int)(S1[S1.size()-1-j]-'0')+C;
			if(j<S2.size()){
				tmp += (int)(S2[S2.size()-1-j]-'0');
			}

			A[j] = tmp%10;
			C = tmp/10;
		}

		if(S1.size()==80&&C==1){
			cout << "overflow" << endl;
		}
		else{
			if(C==1){
				cout << C;
			}
			for(int j=S1.size()-1; j>=0; j--){
				cout << A[j];
			}
			cout << endl;
		}
	}

	return 0;
}

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

int A, B;
int solve(int x, int y){
    int cnt = 0;
    for(int i=x; i<=y; i++){
        if((i/10000 == i%10) && ((i/1000)%10 == (i%100)/10)) cnt++;
    }
    return cnt;
}

int main(){
    scanf("%d%d", &A, &B);
    int res = solve(A, B);
    printf("%d", res);
    return 0;
}


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

using namespace std;


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

	vector<int> h(n), dp(n, 1 << 30);    

	for(int &x : h)
		cin >> x;

	dp[0] = 0;
	for(int i = 1; i < n; i++)
	{
		for(int j = 1; j <= min(i, k); j++)
			dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
	}

	cout << dp[n - 1] << endl;

}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;

class Progaram
{
    static void Main(String[] args)
    {
        var l = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var n = l[0];
        var m = l[1];

        var stores = new List<Store>();

        for (var i = 0; n > i; i++)
        {
            var li = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            stores.Add(new Store(li[0], li[1]));
        }

        stores = stores.OrderBy(x => x.Price).ToList();

        var now = 0L;
        var res = 0L;
        while (now < m)
        {
            long f;
            if (now + stores[0].Ko > m)
            {
                f = m - now;
            }
            else
            {
                f = stores[0].Ko;
            }
            now += f;
            res += f * stores[0].Price;
            stores.RemoveAt(0);
        }
        Console.WriteLine(res);
    }
}

class Store
{
    public long Price { get; set; }
    public long Ko { get; set; }

    public Store(long price, long ko)
    {
        this.Price = price;
        this.Ko = ko;
    }
}

Measured memory_bytes: 47416
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> cnt(26, 100);
    string S;
    for (int i = 0; i < N; i++) {
        vector<int> tmp(26, 0);
        cin >> S;
        for (int i = 0; i < S.size(); i++) tmp[S[i] - 'a']++;
        for (int i = 0; i < 26; i++) cnt[i] = min(cnt[i], tmp[i]);
    }
    for (int i = 0; i < 26; i++) {
        if (cnt[i] > 0) {
            for (int j = 0; j < cnt[i]; j++) cout << char(i + 'a');
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 4e5 + 44;
const int X[] = {1,0,-1,0,1,-1,1,-1};
const int Y[] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1e9 + 7;
const long long INF = 1e18;
const int inf = 1e9;

int pos[N];

int main () {
	boost;
	int n;
	cin >> n;
	for (int i = 0 ; i < n ; ++ i) {
		int a;
		cin >> a;
		pos[a] = i + 1;
	}
	for (int i = 1 ; i <= n ; ++ i)
		cout << pos[i] << " ";
}

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

string key[10] =
    {
    " ", "',.!?",  "abcABC", "defDEF", "ghiGHI",
    "jklJKL", "mnoMNO", "pqrsPQRS", "tuvTUV", "wxyzWXYZ"
    };

int main(){
    string seq;
    while( cin >> seq ){
        string res = "";
        string::iterator it = seq.begin();
        int num = *it - '0';
        int prev = num, count = 1;
        it++;
        for(; it != seq.end(); it++){
            num = *it - '0';
            if( prev-num ){
                if( prev ){
                    res.append(1, key[prev][(count-1)%key[prev].length()]);
                }else if(count >= 2){
                    res.append(count-1, ' ');
                }
                prev = num;
                count = 1;
            }else{
                count++;
            }
        }
        if( prev ){
            res.append(1, key[prev][(count-1)%key[prev].length()]);
        }else{
            res.append(count-1, ' ');
        }
        cout << res << endl;
    }
    return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> x(n), y(n);
    map<pair<int, int>, int> cnt;
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) if (i != j) {
            int dx = x[i] - x[j], dy = y[i] - y[j];
            cnt[{dx, dy}]++;
        }
    }
    int mi = n;
    for (auto &p: cnt) {
        mi = min(mi, n - p.second);
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") 
#include <bits/stdc++.h> 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define PI 3.1415926535897932384626 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd; 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
 
#define Rep(i, a, b) for (int i=a; i<(b); i++)
#define rep(i, a) for (int i=0; i<(a); i++)
#define Dep(i,a,b) for (int i = (b)-1; i >= a; i--)
#define dep(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for(auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // Random No.
 
const int MOD = 1000000007;
const char nl = '\n';

void sol() {
    int N ;
    cin >> N;
    int ar[N];
    ll sum =0;
    set<int> s;
    rep(i, N){
        cin >> ar[i] ;
        sum += ar[i];
        s.insert(ar[i]);
    }

    map <ll, ll> m;
    trav(x, s){
        int countt= count(ar , ar + N , x);
        m[x] = countt;
    }

    int Q;
    cin >> Q;
    while(Q--){
        int B , C;
        cin >> B >> C;
        sum += (C - B)*(m[B]);

        auto it = m.find(C);
        if(it != m.end()){
            m[C] = m[C] + m[B];
            m.erase(B);
        }
        else{
            m[C] = m[B];
            m.erase(B);
        }
        cout << sum << nl;

    }



}               

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

    #ifndef ONLINE_JUDGE
    	freopen("inputD.txt", "r", stdin);
	  #endif    
	
    int T=1;
    while(T--) {            
        sol();                
    }
	
	return 0;
}

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

using namespace std;

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

    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1,
               2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2,
               2, 5, 4, 1, 4, 1, 51};
    cout << a[N - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ff(i,n) for(i=0;i<n;i++)
ll bg=1000000007;
ll gcd(ll a,ll b)
{
if(b==0)
   return a;
else
   return gcd(b,a%b);   
}
ll power(ll x,ll y)
{
	if(y==0)
		return 1;
	ll h=power(x,y/2);	
	h=(h*h);
	if(y%2==1)
	  return (x*h);
	else
	  return h;  
}
ll isp(string str) 
{ 
    // Start from leftmost and rightmost corners of str 
    int l = 0; 
    int h = str.length() - 1;
    // Keep comparing characters while they are same 
    while (h > l) 
    { 
        if (str[l++] != str[h--]) 
        {  
            return -1; 
        } 
    } 
    return 1; 
} 
vector<vector<pair<ll,ll> > >adj(300000);
ll dis[300000],vis[300000],p[300000];

int main()
{
	ll t;
	t=1;
	while(t--)
	{	
	    ll i,j,n,x,y;
		cin>>n>>x>>y;
		ll dp[n]={0};
		for(i=1;i<=n;i++)
		{
		    for(j=i+1;j<=n;j++)	
			{
				if(i<=x)
				  dp[min(j-i,x-i+1+abs(y-j))]++;
				else if(i>x && i<y)
				  dp[min(j-i,i-x+1+abs(y-j))]++;
				else
				  dp[j-i]++;    
			}
		}
		for(i=1;i<n;i++)
		   cout<<dp[i]<<endl;   	  	   
	}
return 0;
}

Measured memory_bytes: 7296
N, M = map(int, input().split())
AB = [(a, b) for _ in range(N) for a, b in [map(int, input().split())] if M - a >= 0]

AB = sorted(sorted(AB, key=lambda x: x[0], reverse=False), key=lambda x: x[1], reverse=True)
x = [0] * M
p = [x for x in range(M)]

cnt = 0
cntIN = M
for a, b in AB:
    i = M-a

    s = []
    while i >= 0 and p[i] != i:
        s.append(i)
        i = p[i]
    for j in s:
        p[j] = i - 1

    if i >= 0:
        x[i] = b
        p[i] = i - 1
        cntIN -= 1            
        if cntIN <= 0:
            break

print(sum(x))


Measured memory_bytes: 21196
#include<stdio.h>
int main(void) {
	int x, y;
	int ans = 0;
	scanf("%d %d", &x, &y);
	if (x == 1 && y == 1) {
		printf("1000000\n");
		return 0;
	}
	else {
		
		if (x == 1) {
			ans += 300000;
		}
		else if (x == 2) {
			ans += 200000;
		}
		else if (x == 3) {
			ans += 100000;
		}
		if (y == 1) {
			ans += 300000;
		}
		else if (y == 2) {
			ans += 200000;
		}
		else if (y == 3) {
			ans += 100000;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int64_t a,b;
  cin >> a >> b;
  int64_t h = b-a;
  h = (h*(h+1))/2;
  cout << h - b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
	int n;
	cin >> n;
	vector <vector<int>> a(n+1, vector<int>(n+1, 0));
	for (int i = 0; i < n; i++) {
		int u, k; cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v; cin >> v;
			a[u][v]++;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cout << a[i][j];
			if (j != n) {
				cout << " ";
			}
		}
		cout << endl;
	}

}



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

int main() {
    int dp[100001];
    for(int i=0;i<100;i++) dp[i]=0;
    for(int i=100;i<=105;i++)dp[i]=1;
    int n;
    cin >> n;
    for(int i=106;i<=n;i++){
        dp[i]=max({dp[i-100],dp[i-101],dp[i-102],dp[i-103],dp[i-104],dp[i-105]});
    }
    if(dp[n]) cout << "1" << endl;
    else cout << "0" << endl;
}

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

bool is_sharp(int a, int b){
    if((a % 2 == 0 && b % 2 == 0) || (a%2 == 1 && b%2 == 1)){
        return true;
    }else{
        return false;
    }
}

int main(){
    int H, W, count = 0;
    vector<int> data_vector;
    while(1){
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        data_vector.push_back(H);
        data_vector.push_back(W);
        count+=2;
    }
    for (int i = 0; i < count; i+=2) {
        H = data_vector[i];
        W = data_vector[i+1];
        for (int j=0; j<H; j++) {
            for (int k=0; k<W; k++) {
                if (is_sharp(j, k)) {
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}




Measured memory_bytes: 3144
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
int main() {
    ll a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if (a == 0) {
        cout << 1 << endl;
    } else if (b == 0) {
        cout << 2 << endl;
    } else if (c == 0) {
        cout << 3 << endl;
    } else if (d == 0) {
        cout << 4 << endl;
    } else if (e == 0) {
        cout << 5 << endl;
    }
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main() {
	int a,b;
	scanf("%d%d",&a,&b);
	int c=a*pow(10,floor(log(b)/log(10)+1))+b;
	int s=sqrt(c);
	if (c==s*s) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    vector<int> d;
    rep(i, n){
        int x;
        cin >> x;
        d.push_back(x);
    }
    int sum=0;
    rep(i, n-1){
        rep2(j, i+1, n){
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    bool flag = true;
    if(N&1){
        pr("No");
        return 0;
    }
    for (int i = 0; i < N/2; i++) {
        if(S[i] != S[N/2+i])
            flag = false;
    }
    Yes(flag);
}

Measured memory_bytes: 256
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
typedef long long LL;
typedef unsigned long long ULL;

int a[105];

int main()
{
    int t,sum=0;
    bool flag=0;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    sort(a+1,a+t+1);
    if(sum%10==0)
    {
        for(int i=1;i<=t;i++)
            if(a[i]%10)
            {
                sum-=a[i];
                flag=1;
                break;
            }
        if(flag)cout<<sum<<endl;
        else cout<<0<<endl;
    }
    else cout<<sum<<endl;
    return 0;
}





















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

int main(){
    int N, ans = 0;
    cin >> N;

    for(int i = 0; i < N; i++){
        int math;
        cin >> math;
        if(math % 2 == 1 && (i+1) % 2 == 1){
            ans++;
        }
    }
    cout << ans << endl;
}


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

int main(){
	long int n,k;
	cin>>n>>k;
	vector<long int> a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	vector<long int> dp(n,1000000000);
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	if(n==1){
		cout<<0<<endl;
		return 0;
	}
	if(n==2){
		cout<<dp[1]<<endl;
		return 0;
	}
	if(k>=n-1)
		k=n;
	for(int i=2;i<=k;i++){
		for(int j=0;j<i;j++){
			dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
		}
	}
	for(int i=k+1;i<n;i++){
		for(int j=i-k;j<=i-1;j++){
			dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using Um = unordered_map<char,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;


#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> S(1LL<<N,0);
    for(ll i=0;i<(1LL<<N);++i)cin>>S[i];
    sort(S.rbegin(), S.rend());
    multiset<ll> selected;
    multiset<ll> notyet;
    selected.insert(S[0]);
    for(ll i=1;i<(1LL<<N);++i){
        notyet.insert(S[i]);
    }
    for(ll i=0;i<N;++i){
        multiset<ll> select;
        auto itr=selected.end();
        for(ll j=0;j<(1LL<<i);++j){
            --itr;
            auto x=notyet.lower_bound(*itr);
            if(x==notyet.begin()){
                prt("No");
                return 0;
            }
            --x;
            select.insert(*x);
            notyet.erase(x);
        }
        for(auto p: select){
            selected.insert(p);
        }
    }
    prt("Yes");

    return 0;
}



Measured memory_bytes: 23784
#include <stdio.h>
int main(){
    long N,K;
    scanf("%ld %ld",&N,&K);

    long total = 0;
    if (K == 0){
        total += N*N;
    }else{
        for (long b = K+1;b <= N;b++){
            long rn = N%b;
            long qn = (N-rn)/b;
            total += qn*(b-K);
            if (rn >= K) total += rn-K+1;
        }
    }

    printf("%ld\n",total);
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>

#pragma warning(disable : 4996)

using namespace std;

int main()
{
	int n, a, b, c, t, u, v;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a);
		scanf("%d", &b);
		scanf("%d", &c);

		t = min({ a, b, c });

		a -= t;
		b -= t;
		c -= t;

		u = min(a / 2, b);

		a -= u * 2;
		b -= u;

		v = a / 3;

		printf("%d\n", t + u + v);
	}
	
	return 0;
}

Measured memory_bytes: 2716