akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

ll H, W, K;
char mp[888][888];
ll flg[888][888];
ll sx, sy;
ll dy[4] = {0, 1, 0, -1};
ll dx[4] = {1, 0, -1, 0};

int main(){
    cin >> H >> W >> K;
    rep1(y, H)rep1(x, W){
        cin >> mp[y][x];
        flg[y][x] = INF;
        if(mp[y][x] == 'S'){
            sx = x;
            sy = y;
        }
    }
    flg[sy][sx] = 0;
    queue<P>Q;
    Q.push(P(sx, sy));
    while(!Q.empty()){
        ll x = Q.front().first;
        ll y = Q.front().second;
        Q.pop();
        rep(i, 4){
            ll nx = x + dx[i];
            ll ny = y + dy[i];
            if(flg[ny][nx] < INF)continue;
            if(mp[ny][nx] == '#')continue;
            flg[ny][nx] = flg[y][x] + 1;
            Q.push(P(nx, ny));
        }
    }
    ll ans = INF;
    rep1(y, H)rep1(x, W)if(flg[y][x] <= K){
        chmin(ans, 1 + (H - y + K - 1) / K);
        chmin(ans, 1 + (y - 1 + K - 1) / K);
        chmin(ans, 1 + (W - x + K - 1) / K);
        chmin(ans, 1 + (x - 1 + K - 1) / K);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7040
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>

using std::cin;
using std::cout;



int main(int argc, char* argv[])
{
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;

  std::string A, B, C;
  cin >> A >> B >> C;

  std::array<char, 3> chr;
  int res = 0;
  for (int i = 0; i < n; ++i)
  {
    chr = {A[i], B[i], C[i]};
    std::sort(chr.begin(), chr.end());
    if (chr[0] == chr[2]) continue;
    if (chr[0] == chr[1] || chr[1] == chr[2]) ++res;
    else res += 2;
  }
  cout << res << "\n";

  return 0;
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

void solve(){
   int a,b,c,k;
   cin >> a >> b >> c >> k;

   int ans = 0;
   ans += min(a , k);
   k -= min(a,k);
   k -= min(b,k);
   ans -= min(c,k);
   cout << ans;
}

int32_t main(){
   fast;
   int t = 1;
//   cin >> t;
   while(t--)  solve();   

}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };
// struct edge{ll to; ll cost;};



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// struct UnionFind {
//     vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
//
//     UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
//         for(int i = 0; i < N; i++) par[i] = i;
//     }
//
//     int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
//         if (par[x] == x) return x;
//         return par[x] = root(par[x]);
//     }
//
//     void unite(int x, int y) { // xとyの木を併合
//         int rx = root(x); //xの根をrx
//         int ry = root(y); //yの根をry
//         if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
//         par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
//     }
//
//     bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };
//
// vint divisor(ll n){ // nの約数
//   vint ret;
//   for(ll i=1;i*i<=n;i++){
//     if(n%i == 0){
//       ret.pb(i);
//       if(i*i!=n) ret.pb(n/i);
//     }
//   }
//   vsort(ret);
//   return ret;
// }
//
// ll get_digits_num(ll n){
//   ll ret=0;
//   while(n){
//     n/=10;
//     ret++;
//   }
//   return ret;
// }


ll f(ll n){
  ll rtn;
  ll m = n%8;

  rtn = 0;
  for(ll i=n-m;i<=n;i++){
    rtn = rtn^i;
  }

  return rtn;
}


int main() {
  cout<<fixed<<setprecision(10);


  ll N;cin>>N;
  vint W(N);
  rep(i,N) cin>>W[i];

  ll ans = LLONG_MAX;
  ll s1,s2;
  for(ll i=0;i<N;i++){
    s1 = 0; s2=0;
    for(ll j=0;j<i;j++){
      s1+=W[j];
    }
    for(ll j=i;j<N;j++){
      s2+=W[j];
    }
    ans = min(ans, abs(s1-s2));
  }
  // cout << s1 << s2<<endl;
  cout << ans<<endl;


}




//


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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, clock()*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

int main() {
#ifdef LOCAL
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
#endif

  char s[20];
  while (scanf("%s", s) == 1) {
    int ans = 0;
    int pref = 0;
    int l = strlen(s);
    for (int i = 0; i < l; i++) {
      if (s[i] != '0') {
        ans = max(ans, pref + (s[i] - '0' - 1) + (l - i - 1) * 9);
      }
      pref += s[i] - '0';
    }
    ans = max(ans, pref);
    printf("%d\n", ans);
  }

  return 0;
}


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

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define debugaar(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define BIGINT 0x7FFFFFFF
#define E107 1000000007ll
void printbit(int u){if(u==0)cout<<0;else{int s=0,k=0;for(;0<u;u>>=1,k++)s=(s<<1)|(u&1);for(;0<k--;s>>=1)cout<<(s&1);}}

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())

namespace{
    std::chrono::system_clock::time_point t;
    void tic(){t=TIME;}
    void toc(){fprintf(stderr,"TIME : %lldms\n",MILLISEC(TIME-t));}
}

template<typename T1,typename T2>
ostream& operator <<(ostream &o,const pair<T1,T2> p){o<<"("<<p.first<<":"<<p.second<<")";return o;}

int width,height;
int m,n;

int hako[100010];

int main(){
    int i,j,k;
    int x,y,a,b;
    
    cin >> n;
    
    for (i=0;i<n;i++){
        scanf("%d",&k);
        hako[k]++;
    }
    a=0;b=0;
    for (i=0;i<100010;i++){
        if (hako[i]){
            a+=hako[i]-1;
            b++;
        }
    }
    
    cout << (b-(a%2)) << endl;
    

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int m,d,cnt;
int main()
{
	scanf("%d%d",&m,&d);
	for(int i=1;i<=m;i++)
		for(int j=2;j<=9;j++)
			for(int k=2;k<=9;k++)
				if(10*j+k<=d&&j*k==i) cnt++;
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 256
package main
import (
    "fmt"
    "bufio"
    "os"
    "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main(){
    // Your code here!
    sc.Split(bufio.ScanWords)
    sc.Scan()
    N,e1:=strconv.Atoi(sc.Text())
    if e1!=nil{
        panic(e1)
    }
    sc.Scan()
    A,e2:=strconv.Atoi(sc.Text())
    if e1!=nil{
        panic(e2)
    }
    sc.Scan()
    B,e3:=strconv.Atoi(sc.Text())
    if e3!=nil{
        panic(e3)
    }
    if B>A*N{
        fmt.Println(A*N)
    }else{
        fmt.Println(B)
    }
}

Measured memory_bytes: 640
import sys
import bisect
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    a.sort()

    cor_v = -1
    inc_v = 10 ** 11
    while - cor_v + inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for v in a:
            cost += n - bisect.bisect_left(a, bin_v - v)
            if cost > m:
                break
        #costが制約を満たすか
        if cost >= m:
            cor_v = bin_v
        else:
            inc_v = bin_v
    acm = [0] + list(itertools.accumulate(a))
    c = 0
    t = 0
    for v in a:
        p = bisect.bisect_left(a, cor_v - v)
        c += n - p
        t += acm[-1] - acm[p] + v * (n - p)
    print(t - (c - m) * cor_v)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 54324
def examA():
    N, M = LI()
    if N==M:
        print("Yes")
    else:
        print("No")
    return

def examB():
    A, B = LI()
    if A>B:
        ans = str(B)*A
    else:
        ans = str(A)*B
    print(ans)
    return

def examC():
    N = I()
    P = LI()
    minP = N+1
    ans = 0
    for i in range(N):
        if minP>P[i]:
            minP=P[i]
            ans +=1
    print(ans)
    return

def examD():
    N = I()
    ans = 0
    keep = [[0]*10 for _ in range(10)]
    for i in range(1,N+1):
        l = int(str(i)[0]); r = int(str(i)[-1])
        keep[l][r]+=1

    for i in range(1,N+1):
        l = int(str(i)[0])
        r = int(str(i)[-1])
        ans += keep[r][l]

    print(ans)
    return

def examE():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    def lcm(x, y):
        return x * y // gcd(x, y)
    N = I()
    A = LI()


    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

"""

"""

Measured memory_bytes: 3824
#include<cstdio>

inline int read() {
	int n=0; char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') n=(n<<3)+(n<<1)+(c^48),c=getchar();
	return n;
}
template<typename T>
void write(const T& n) {
	if(n>=10) write(n/10);
	putchar(n%10+48);
}

int N, K, x, ans;

int main() {
	N = read(), K = read();
	while(N--) {
		x = read();
		if(x > (K>>1)) x = K - x;
		ans += x<<1;
	}
	return write(ans), putchar(10), 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[100000];
map<int, int> m;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        m[a[i]]++;
    }
    auto it = m.find(0);
    if (it != m.end())
    {
        if (m.size() == 1)
            return cout << "Yes", 0;
        if (m.size() == 2 && it->second == (n / 3 + (n % 3 == 2)))
            return cout << "Yes", 0;
        return cout << "No", 0;
    }
    if (n % 3 != 0 || m.size() != 3)
        return cout << "No", 0;

    int x = 0;
    for (pair<int, int> p : m)
    {
        x ^= p.first;
        if (p.second != n / 3)
            return cout << "No", 0;
    }
    if (x != 0)
        return cout << "No", 0;
    cout << "Yes";
}


Measured memory_bytes: 4224
N = int(input())
AA = input().split()
BB = input().split()
CC = input().split()
total = 0
for i in range(len(AA)-1):
  if int(AA[i+1]) - int(AA[i]) == 1:
    
    total += int(CC[int(AA[i])-1])
    
for i in BB:
  total += int(i)
print(total)

Measured memory_bytes: 9120
n,l =map(int,input().split())
if l+n-1 <0:
    print((n-1)*(l-1)+n*(n-1)//2)
elif l > 0:
    print(n*(l-1)+n*(n+1)//2-l)
else:
    print(n*(l-1)+n*(n+1)//2)

Measured memory_bytes: 9112
import java.util.Scanner;

class Main{

	public static void main(String[] args){

		Scanner sc =new Scanner(System.in);

		while(true){
			String W =sc.next();
			if(W.equals("-")) break;
			int m=sc.nextInt();
			int count=0;
			for(int i=0;i<m;i++)
				count+=sc.nextInt();
			for(int i=0;i<W.length();i++)
				System.out.print(W.charAt((count+i)%W.length()));
			System.out.println();
		}
	}

}


Measured memory_bytes: 26452
#ifndef ___Rank_Union_Find
#define ___Rank_Union_Find

// ------ Required ------ //
#include <vector>

// ------ Class ------ //
class RankUnionFind {
private:
	std::size_t size_; std::vector<std::size_t> par, rank;
public:
	RankUnionFind() : size_(0), par(std::vector<std::size_t>()), rank(std::vector<std::size_t>()) {};
	RankUnionFind(std::size_t size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (std::size_t i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	std::size_t size() { return size_; }
	std::size_t root(std::size_t x) { return par[x] == x ? x : par[x] = root(par[x]); }
	bool same(std::size_t x, std::size_t y) { return root(x) == root(y); }
	void unite(std::size_t x, std::size_t y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const RankUnionFind &u) { return par == u.par; }
	bool operator!=(const RankUnionFind &u) { return par != u.par; }
};

#endif

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct edge{ int src, dst, cost; };
bool operator<(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
int n, m;
int main() {
	scanf("%d%d", &n, &m);
	vector<edge> z(m);
	for(int i = 0; i < m; i++) scanf("%d%d%d", &z[i].src, &z[i].dst, &z[i].cost);
	sort(z.begin(), z.end());
	RankUnionFind uf(n);
	int ret = 0;
	for(int i = 0; i < z.size(); i++) {
		int a = z[i].src, b = z[i].dst;
		if(!uf.same(a, b)) uf.unite(a, b), ret += z[i].cost;
	}
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 3872
n,k,c = map(int, input().split())
s = str(input())
t = []
u = []
i,x,y,j = 0,0,0,n-1
while i < n and x < k:
    if s[i] == "o":
        t.append(i)
        x += 1
        i += c
    i += 1
 
while j >= 0 and y < k:
    if s[j] == "o":
        u.append(j)
        y += 1
        j += -c
    j += -1
 
for i in range(0,k):
    if t[i] == u[k-1-i]:
        print(t[i]+1)

Measured memory_bytes: 20620
def solve_slow(X):
    for n in range(1000000):
        # print((n * (n - 1) // 2))
        if (n * (n - 1) // 2) >= X:
            break
    return n - 1


def solve_fast(X):
    # n^2 - n - 2X <= 0
    # n = (1 + sqrt(1 + 8X)) // 2
    n = max(int((1 + (1 + 8 * X) ** 0.5) / 2) - 1, 0)
    while True:
        if (n * (n - 1) // 2) >= X:
            break
        n += 1
    return n - 1


X = int(input())
print(solve_fast(X))

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, D, A;
    cin >> N >> D >> A;
    ll X[N], H[N];
    plglg data[N];
    REP(i, 0, N) {
        cin >> X[i] >> H[i];
        data[i] = plglg(X[i], H[i]);
    }
    queue<plglg> que;
    ll ans = 0;
    ll now = 0;
    sort(data, data + N);
    REP(i, 0, N) {
        plglg d = data[i];
        ll x = d.first;
        ll h = d.second;
        while(!que.empty()) {
            plglg p = que.front();
            if (p.second < x) {
                que.pop();
                now -= p.first;
                // cout << now << endl;
            } else {
                break;
            }
        }
        ll tmp = (h + A - 1) / A;
        // cout << tmp << " " << now << " aaa" << endl;
        if (tmp <= now) {
            continue;
        } else {
            ans += tmp - now;
            que.push(plglg(tmp - now, x + 2 * D));
            // cout << tmp - now << " " << x + 2 * D << " " << i << endl;
            now = tmp;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
int n;
int a[110];
int A,B;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a,a+n);
  for (int i = 0; i < n; i++) {
    if (i & 1) B += a[(n-1-i)];
    else A += a[(n-1-i)];
  }
  cout << A - B << endl;
}

/*　【提出前に確認すること】
・コンパイルできるか
・テストケース試したか
・オーバーフローあるか
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  //  vector<int> a(n);
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (((i + 1) % 2 == 1) and (a % 2 == 1)) ++ret;
  }

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int ans=0;
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        if((i&1)&&(x&1)) ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 3656
while True:
    m,f,r = map(int,input().split())
    if m == -1 and f == -1 and r == -1:
        break
    if m == -1 or f == -1:
        print("F")
    elif m + f >= 80:
        print("A")
    elif m + f >= 65:
        print("B")
    elif m + f >= 50:
        print("C")
    elif m + f >= 30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")
    



Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    deque<int>q;
    rep(i,n){
        cin>>a[i];
        if(n%2==i%2){
            q.push_back(a[i]);
        }
        else{
            q.push_front(a[i]);
        }
    }
    for(int x:q){
        cout<<x<<" ";
    }
}

Measured memory_bytes: 3840
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = pow(10,15);
int k; ll m, n, h, w, v, q; string s;
const ll MOD= 1000000007;
const ld PI = acos(-1);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
} vector<bool> visit;
ll d[100100];
struct edge {
    ll to;
    ll cost;
};
vector<vector<edge>> G(200);
using p = pair<ll, ll>;
void dijkstra(int s) {
    priority_queue<p, vector<p>, greater<p>> q;
    Fill(d, INF);
    d[s] = 0;
    q.push(p(0, s));
    while (!q.empty()) {
        p now = q.top(); q.pop();
        ll v = now.second;
        if (d[v] < now.first) continue;
        rep(i, G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                q.push(p(d[e.to], e.to));
            }
        }
    }
}
int main() {
    cin >> n; G.resize(n+1); int Q;
    rep(i, n - 1) {
        cin >> h >> w >> v; h--; w--;
        edge e = { w,v };
        G[h].push_back(e);
        e = { h,v };
        G[w].push_back(e);
    }cin >> Q >> k; k--;
    dijkstra(k);
    rep(i, Q) {
        cin >> h >> w; h--; w--;
        cout << d[h] + d[w] << endl;
    }
}

Measured memory_bytes: 11120
using System;
using System.Linq;
using System.Collections.Generic;

class Bmondai
{
    static void Main()
    {
        var abk = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var list=new List<int>();
        var count = abk[0] < abk[1] ? abk[0] : abk[1];
        var ans = 0;
        var counter = 0;
        for (int i=count;0<i;--i)
        {
            if (abk[0] % i == 0 && abk[1] % i == 0)
            {
                counter++;
                if (counter == abk[2])
                {
                    ans = i;
                    break;
                }
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
import numpy as np
import math

N, K = map(int, input().split())


prob = []
if N >= K:
    p_e = (1 / N) * (N - K + 1)
    for i in range(1, K):
        p_i = (1 / N) * ((1 / 2) ** (math.ceil(np.log2(K / i))))
        prob.append(p_i)

else:
    p_e = 0
    for i in range(1, N+1):
        p_i = (1 / N) * ((1 / 2) ** (math.ceil(np.log2(K / i))))
        prob.append(p_i)


s = sum(prob) + p_e
print("{:.12f}".format(s))

Measured memory_bytes: 12508
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
struct fzy
{
	int x;int y;
};
bool my(fzy a,fzy b)
{
	return (a.y==b.y?a.x<b.x:a.y<b.y);
}
int main()
{
	for(int n;cin>>n && n;)
	{
		vector<fzy> v;fzy f;
		for(int i=0;i<n;i++)
		{
			cin>>f.x>>f.y;
			v.push_back(f);
		}
		sort(v.begin(),v.end(),my);
		int sum=0;int flag=1;
		for(int i=0;i<n;i++)
		{
			sum+=v[i].x;
			if(sum>v[i].y)
			{
				flag=0;break;
			}
		}
		cout<<(flag?"Yes":"No")<<endl;
	}
}

Measured memory_bytes: 1212
#!/usr/bin/env python3

import numpy as np


def solv(a):
    idx = np.argsort(a)
    top_index = idx[-1]
    top = a[top_index]
    second = a[idx[-2]]
    for i in range(n):
        if i != top_index:
            print(top)
        else:
            print(second)


if __name__ == '__main__':

    n = int(input())
    a = np.empty(n, dtype=np.int)

    for i in range(n):
        a[i] = int(input())

    solv(a)


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

int main(void){

    // #ifndef ONLINE_JUDGE 
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif 


   int n,m,sum=0,c=0;
   cin>>n>>m;
   int arr[n];
   for(int i=0;i<n;i++){
    cin>>arr[i];
    sum+=arr[i];
}
   for(int i=0;i<n;i++){
    if(4*m*arr[i]>=sum)
        c++;
   }
   if(c>=m)
    cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 256
MOD = 10**9+7
n = int(input())
S = input()
dp = [[0]*(n+1) for _ in range(n+1)]
for j in range(n):
  dp[1][j] = 1
for i, s in enumerate(S, 1):
  if s == "<":
    dp[i+1][n-(i+1)] = dp[i][n-i]
    for j in range(n-i-2, -1, -1):
      dp[i+1][j] = dp[i+1][j+1] + dp[i][j+1]
      dp[i+1][j] %= MOD
  else:
    dp[i+1][0] = dp[i][0]
    for j in range(1, n-i):
      dp[i+1][j] = dp[i+1][j-1] + dp[i][j]
      dp[i+1][j] %= MOD
ans = dp[n][0]
print(ans)

Measured memory_bytes: 112732
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        if(a == b && b == c && c == a){
            System.out.println("No");
        }else if(a != b && b != c && c != a){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 24916
d,g = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]

ans = g // 100

for i in range(2 ** d):
    total = 0
    correct = 0
    for j in range(d):
        if (i >> j) & 1:
            correct += S[j][0] 
            total += S[j][0] * (j+1) * 100 + S[j][1]
        else:
            biggest = j

    if total >= g:
        ans = min(correct,ans)
    elif total + (S[biggest][0] - 1) * (biggest+1) * 100 < g:
        continue
    else:
        while total < g:
            total += (biggest+1) * 100
            correct += 1
        ans = min(correct,ans)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
#define MAX 50

int main(int argc, char const *argv[])
{
    int n, p;
    int candidate[MAX];

    while (cin>>n>>p, n&&p){
        int remains = p;
        int turn = 0;
        int winner = -1;
        for (int i = 0; i < MAX; i++){
            candidate[i] = 0;
        }
        while (1){
            if (remains > 0){
                candidate[turn]++;
                remains--;
            }
            else{
                remains += candidate[turn];
                candidate[turn] = 0;
            }

            if (candidate[turn] == p){
                winner = turn;
                break;
            }
            turn++;
            turn%=n;
        }
        cout<<winner<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 2980
#include <iostream>
#include <string>
#include <numeric>
#include <algorithm>

int main(){
    int a = 0, b = 0;
    std::cin >> a >> b;

    auto const n = std::min(a, b);

    auto const m = std::max(a, b);

    for( int i = 0; i < m; ++i){
        std::cout << n;
    }

    std::cout << std::endl;

    return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
hwl = []
for _ in range(h):
  l = list(input())
  hwl.append(l)
  
for i in range(h):
  for j in range(w):
    if hwl[i][j] == ".":
      cnt = 0
      if i != 0 and j !=0 and hwl[i-1][j-1] == "#":
        cnt +=1
      
      if i != 0 and hwl[i-1][j] == "#":
        cnt +=1
      
      if i != 0 and j < w-1 and  hwl[i-1][j+1] == "#":
        cnt +=1
        
      if j !=0 and hwl[i][j-1] == "#":
        cnt +=1
      
      if j < w-1 and hwl[i][j+1] == "#":
        cnt +=1
        
      if i < h-1 and j != 0 and hwl[i+1][j-1] == "#":
        cnt +=1
      
      if i <h-1 and hwl[i+1][j] == "#":
        cnt +=1
        
      if i < h-1 and j < w-1 and hwl[i+1][j+1] == "#":
        cnt +=1
        
      hwl[i][j] = str(cnt)

  print("".join(hwl[i]))
      
   



Measured memory_bytes: 3188
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
 
        if(y >= r && y <= H-r && x >=r && x <= W-r){
            System.out.printf("Yes\n");
        }else{
            System.out.printf("No\n");
        }
    }
}


Measured memory_bytes: 26456
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math

sets = [
    set([1,3,5,7,8,10,12]),
    set([4,6,9,11]),
    set([2])
]

def find_group(i):
    for index, group in enumerate(sets):
        if i in group:
            return index


x,y = map(int, sys.stdin.readline().rstrip().split())

if (find_group(x) == find_group(y)):
    print("Yes")
else:
    print("No")

exit(0)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
int main(void) {
    int r, g, b; cin >> r >> g >> b;
    int ans = 100*r + 10*g + b;
    if(ans%4==0) cout <<"YES";
    else cout << "NO";
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

template <typename T>
bool MinPlace(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool MaxPlace(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename Container>
int SZ(const Container& S) { return S.size(); }

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg_var(x) clog << #x  << ": " << x << endl;
    #define dbg_array(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg_var(x)
    #define dbg_array(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

const int MAXN = -1; 

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!

    string S;
    cin >> S;
    int a = 0, b = 0, c = 0;
    for (char x : S) {
        if (x == 'a') a++;
        if (x == 'b') b++;
        if (x == 'c') c++;
    }
    int mx = min(min(a, b), c);
    int MX = max(max(a, b), c);
    cout << ((MX <= 1 + mx)?"YES":"NO") << "\n";
}



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

res = []
low, up = a[0], a[-1]
for i in range(1, n-1):
    if a[i] < 0:
        res.append([up, low])
        up = up - low
        low = a[i]
    else:
        res.append([low, up])
        low = low - up
        up = a[i]

print(up-low)
res.append([up, low])

for v in res:
    print(*v)


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

int main(){

    string s;
    cin >> s;

    if(s.size()==2&&s[0]==s[1]){
        cout << "1 2";
        return 0;
    }
    for(int i = 0;i < s.size() - 2;i++){
        int j = i;
        if(s[j]==s[j+1]||s[j]==s[j+2]||s[j+1]==s[j+2]){
            cout << j+1 << " " << j+3;
            return 0;
        }
    }
    cout << "-1 -1";
}


Measured memory_bytes: 512
// Tested On: http://arc076.contest.atcoder.jp/tasks/arc076_a
#include <iostream>
#include <cassert>
#include <vector>
using namespace std;
template<typename T> T expo(T base, T e, T mod) { T res = 1;
  while(e > 0) { if(e&1) res = res * base % mod; base = base * base % mod; e >>= 1; }
  return res;
}

//Begin
template<typename T>
vector<T> PreprocessFactorial(int size, T mod) {
  size++;
  vector<T> res(size, 0);
  res[0] = 1;
  for(T i = 1; i < size; i++) {
    res[i] = res[i - 1] * i % mod;
  }
  return res;
}
// Provide modular Inverse of fact.back()
template<typename T>
vector<T> PreprocessInverseFactorial(vector<T> fact, T mod, T inverse) {
  int size = fact.size();
  vector<T> res(size, 0);
  res[size - 1] = inverse;
  for(T i = size - 1; i > 0; i--) {
    res[i - 1] = res[i] * i % mod;
  }
  return res;
}
template<typename T>
T nCr(const vector<T> &fact, const vector<T> &ifact, T n, T r, T mod) {
  return ((fact[n] * ifact[n - r]) % mod) * ifact[r] % mod;
}
//End

#define LL long long
int main() {
  ios_base::sync_with_stdio(false);
  const LL mod = 1e9 + 7;
  const int MAXN = 1e6;
  vector<LL> fact = PreprocessFactorial<LL>(MAXN, mod);
  vector<LL> ifact = PreprocessInverseFactorial<LL>(fact, mod, expo(fact.back(), mod - 2, mod));
	LL n, m;
	cin >> n >> m;
	LL res = 0;
	if(abs(n - m) > 1) {
		res = 0;
	} else {
		if(n == m) {
			res = fact[n] * fact[m] % mod;
			res += fact[n] * fact[m] % mod;
		} else {
			res = fact[n] * fact[m] % mod;
		}
		res %= mod;
	}
	cout << res << '\n';
  return 0;
}


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



N,A,B,C,D = map(int, input().split())
As = [A-1,C-1]
Bs = [B-1,D-1]
S = "#"+str(input())+"#"

ans = True
if "##" in S[Bs[0]+1:Bs[1]+2] or "##" in S[As[0]+1:As[1]+2]:
  ans = False
elif As[1] > Bs[1]:
  if "..." not in S[Bs[0]:Bs[1]+3]:
    ans = False

if ans:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3636
S = list(input())
N = len(S)
output = "Yes"
for i in range(N):
    if (i%2==1)and(S[i] not in ["L","U","D"]):
        output="No"
    if (i%2==0)and(S[i] not in ["R","U","D"]):
        output="No"
print(output)


Measured memory_bytes: 38256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)

int main()
{
        string S;
        cin >> S;
        int ans = 0;
        char moji[] = {'A', 'C', 'G', 'T'};
        int cnt = 0;

        for (int i = 0; i < S.size(); i++)
        {
                bool ok = false;
                rep(j, 4)
                {

                        if (S[i] == moji[j])
                        {
                                ok = true;
                        }
                }
                if (ok)
                {
                        cnt++;
                        ans = max(ans, cnt);
                }
                else
                {
                        cnt = 0;
                        ok = false;
                }
        }
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define loop(i,a,b) for(ll i=a; i<b; i++)
#define revloop(i,a,b) for(ll i=a; i>=b; i--)
#define pb push_back
#define vl vector<ll>
#define vvl vector<vl>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define all(c) (c).begin(), (c).end()
#define sz(a) ((a).size())
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i!=(c).end(); i++))
#define mp make_pair
#define ss second
#define ff first
#define ld long double
const ll INF = 1e13;
const ll N = 100002;
ll mod= 1000000007;
/*bool prime(ll x)
{
	if(x<2) return false;
	for(ll i=2; i*i<=x; i++) if(x%i==0) return false;
	return true;
}
vl fac(N);
void fact()
{
	fac[0]=1;
	loop(i,1,N) fac[i]=(fac[i-1]*i)%mod;
}
*/
ll dpw[100005], dpb[100005];
vl adj[100005];
void dfs(ll n, ll p)
{
	dpw[n]=1;
	dpb[n]=1;
	for(auto i:adj[n])
	 if(i!=p)
	 {
	 	dfs(i,n);
	 	dpw[n]=dpw[n]*(dpw[i]+dpb[i])%mod;
	 	dpb[n]=dpb[n]*dpw[i]%mod;
	 }
}
void solve()
{
 ll n;
 cin>>n;
 loop(i,1,n)
 {
 	ll u,v;
 	cin>>u>>v;
 	adj[u].pb(v);
 	adj[v].pb(u);
 }
 dfs(1,0);
 cout<<(dpw[1]+dpb[1])%mod;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--) solve();
 return 0;
}

Measured memory_bytes: 11520
#include <iostream>
using namespace std;
int main()
{
  int t,n;
  for(int i=0;i<4;i++){
    cin>>t>>n;
    switch(t){
    case 1:
      cout<<n*6000<<endl;
      break;
    case 2:
      cout<<n*4000<<endl;
      break;
    case 3:
      cout<<n*3000<<endl;
      break;
    case 4:
      cout<<n*2000<<endl;
      break;
    }
  }
  return 0;
}



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

using std::pair;
using std::make_pair;
typedef pair<int, int> Pair;

#define update_max(a, b) if ((a) < (b)) (a) = (b)
#define update_min(a, b) if ((a) > (b)) (a) = (b)

const int N = 1000 + 10;

bool visited[N], busy[N][N];
int a[N][N], pivot[N];
int n;

std::queue<Pair> candidates[2];

void add(std::queue<Pair>& queue, int x, int y) {
  if (x > y) std::swap(x, y);
  queue.push(make_pair(x, y));
}

void run(int case_id = 0) {
  std::cin >> n;
  for (int i = 1; i <= n; ++ i) {
    pivot[i] = 1;
    for (int j = 1; j < n; ++ j) {
      std::cin >> a[i][j];
    }
  }

  for (int i = 1; i <= n; ++ i) {
    int x = a[i][1];
    if (x > i && a[x][1] == i) {
      add(candidates[1], i, x);
    }
  }

  int day = 0;
  int done = 0;
  while (done < n * (n - 1) / 2) {
    day ++;
    int now = day & 1;
    if (candidates[now].empty()) {
      day = -1;
      break;
    }
    while (!candidates[now].empty()) {
      int x = candidates[now].front().first;
      int y = candidates[now].front().second;
      candidates[now].pop();
      pivot[x] ++;
      pivot[y] ++;
      done ++;
      if (pivot[x] <= n - 1) {
        int x2 = a[x][pivot[x]];
        if (a[x2][pivot[x2]] == x) {
          add(candidates[now ^ 1], x, x2);
        }
      }
      if (pivot[y] <= n - 1) {
        int y2 = a[y][pivot[y]];
        if (a[y2][pivot[y2]] == y) {
          add(candidates[now ^ 1], y, y2);
        }
      }
    }
  }
  std::cout << day << std::endl;
}

void multi_cases_main() {
  int num_tests;
  std::cin >> num_tests;
  for (int t = 1; t <= num_tests; ++ t) {
    run(t);
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  run();
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<vector<long long>> a(n, vector<long long>(2, 0));
    for (int i=0; i<n; i++){
        long long tmp;
        cin >> tmp;
        a[i] = {tmp, i+1};
    }
    stable_sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    
    vector<vector<long long>> dp(n+1, vector<long long>(n+1, 0));
    long long ans = 0;
    
    for (int i=1; i<n+1; i++){
        for (int x=0; x<i+1; x++){
            int y = i-x;
            long long activity = a[i-1][0];
            int ind = a[i-1][1];
            long long val1 = 0;
            long long val2 = 0;
            if (y-1 >= 0){
                val1 = dp[x][y-1] + activity*(abs(n-(y-1)-ind));
            }
            if (x-1 >= 0){
                val2 = dp[x-1][y] + activity*(abs(ind-x));
            }
            dp[x][y] = max(val1, val2);
            if (i == n && dp[x][y] > ans){
                ans = dp[x][y];
            }
        }
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 34688
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define sett(a,b) memset(a,b,sizeof(a))
#define cpy(a,b) memcpy(a,b,sizeof(a))
#define prq priority_queue
using namespace std;
string s;
int nxt[101010],lst[101010];
int main(){
	cin>>s;
	int n=s.size();
	fo(i,0,n){
		if(i<n-1)nxt[i]=i+1;
		else nxt[i]=-1;
		if(i>0)lst[i]=i-1;
		else lst[i]=-1;
	}
	int i=0,ans=0;
	while(i>=0&&i<n){
		if(nxt[i]!=-1) if(s[i]!=s[nxt[i]]){
			ans+=2;
			if(lst[i]!=-1)nxt[lst[i]]=nxt[nxt[i]];
			if(nxt[nxt[i]]!=-1)lst[nxt[nxt[i]]]=lst[i];
			if(lst[i]!=-1)i=lst[i];
			else if(nxt[nxt[i]]!=-1)i=nxt[nxt[i]];
			else break;
			continue;
		}
		i=nxt[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int a,b,c,d;
    IN(a,b,c,d);
    while(a > 0&&c > 0){
        c-=b;
        a-=d;
        debug(a,c);
    }
    if(c<=0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3640
# ノートに考察メモあり。
from collections import Counter, deque  # https://note.nkmk.me/python-scipy-connected-components/
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        gg = Counter([])
        H, W = map(int, input().split())
        grid = [[_ for _ in input()] for _ in range(H)]
        for g in grid:
            gg.update(Counter(g))

        if H % 2 == 0 and W % 2 == 0:
            for i in gg.values():
                if i % 4 != 0:
                    return 'No'
            return 'Yes'

        elif H % 2 == 0 and W % 2 == 1:
            cnt = 0
            for i in gg.values():
                if i % 4 == 2:
                    cnt += 2
                elif i % 4 == 1 or i % 4 == 3:
                    return 'No'

            if cnt <= H:
                return 'Yes'
            else:
                return 'No'

        elif H % 2 == 1 and W % 2 == 0:
            cnt = 0
            for i in gg.values():
                if i % 4 == 2:
                    cnt += 2
                elif i % 4 == 1 or i % 4 == 3:
                    return 'No'

            if cnt <= W:
                return 'Yes'
            else:
                return 'No'

        else:
            cnt1 = 0
            cnt2 = 0
            for i in gg.values():
                if i % 4 == 1:
                    cnt1 += 1
                elif i % 4 == 2:
                    cnt2 += 2
                elif i % 4 == 3:
                    cnt2 += 2
                    cnt1 += 1
            if cnt1 == 1 and cnt2 <= (H + W - 2):
                return 'Yes'
            else:
                return 'No'

    print(main())


resolve()

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

using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b + c)
    cout << "Yes" << endl;
  else if (b == a + c)
    cout << "Yes" << endl;
  else if (c == a + b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256