akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll n;
    cin >> n;
    cout << 3 * n * n;
    return 0;
}

Measured memory_bytes: 3624
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


K=int(input())
ans=0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            if i==j and j==k:
                ans=ans+gcd(i,j,k)
            elif i==j or j==k:
                ans=ans+3*gcd(i,j,k)
            else:
                ans=ans+6*gcd(i,j,k)
            
print(ans)

Measured memory_bytes: 9616
s = gets.chomp
len = s.size
ans = 0
(2 ** (len - 1)).times{|i|
    t = ""
    (len - 1).times{|j|
        t += s[j]
        if i[j] == 1
            t += ?+
        end
        }
    t += s[len - 1]
    ans += eval(t)
    }
p ans

Measured memory_bytes: 1916
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;
    static CF_Reader in;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new CF_Reader();

        String a = in.next(), b = in.next();
        int aLn = a.length(), bLn = b.length();
        out.println((bLn - aLn == 1 && a.equals(b.substring(0, aLn))) ? "Yes": "No");

        out.close();
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}


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

int main() {
  int k;
  string s;
  cin>>k>>s;
  if(s.size()<=k){
    cout<<s<< endl;
    return 0;
  }
  else{
    for(int i=0;i<k;i++){
      cout<<s.at(i);
    }
    cout<<"..."<< endl;
    return 0;
  }
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
 
typedef long long ll;

using namespace std;

const int mod=1e9+7;
const int INF=1<<25;

int main(){
  int N;
  ll A,B;
  cin >> N >> A >> B;
  ll temp,pre,ans=0;
  rep(i,N){
    if(i==0){
      cin >> pre ;
      continue;
    }
    cin >> temp ;
    ans+=min((temp-pre)*A,B);
    pre=temp;
  }
  cout << ans << endl;
  

  return 0;
}

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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	int n, m, o;
	cin >> n >> m >> o;
	vi a{abs(n- m), abs(m - o), abs(o - n)};
	sort(ALL(a));
	cout << a[0] + a[1] << "\n";
	return 0;
}


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

int n, m, p;
int d[10001];

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

	for (int i = 0; i < m; i++)
		cin >> d[i];

	sort(d, d + m);

	int s = n;

	for (int i = 0; i < m; i++) {
		if (d[i] <= p && d[i + 1] >= p)
			s = min(s, n - max(p - d[i], d[i + 1] - p));
		else if(p < d[i])
			s = min(s, n - d[i + 1] + d[i] + min(d[i] - p, p + n - d[i + 1]));
		else
			s = min(s, n - d[i + 1] + d[i] + min(d[i] + n - p, p - d[i + 1]));
	}

	if (d[m - 1] <= p)
		s = min(s, n - max(p - d[m - 1], d[0] + n - p));
	else if (p <= d[0])
		s = min(s, n - max(n - d[m - 1] + p, d[0] - p));
	else
		s = min(s, d[m - 1] - d[0] + min(d[m - 1] - p, p - d[0]));

	cout << s * 100 << endl;

	return 0;
}



Measured memory_bytes: 3196
local day = io.read("*n")
local c = {}
for i = 1, 26 do
  c[i] = io.read("*n")
end
local s = {}
for id = 1, day do
  s[id] = {}
  for i = 1, 26 do
    s[id][i] = io.read("*n")
  end
end

local function solve(t, debug)
  local cur = 0
  local lastday = {}
  for i = 1, 26 do lastday[i] = 0 end
  for id = 1, day do
    local pid = t[id]
    cur = cur + s[id][pid]
    lastday[pid] = id
    for i = 1, 26 do
      cur = cur - c[i] * (id - lastday[i])
    end
    if debug then print(cur) end
  end
  return cur
end
local t = {}
for id = 1, day do
  t[id] = io.read("*n")
  -- t[id] = 1 + (id % 26)
end
local m = io.read("*n")
for i = 1, m do
  local m, q = io.read("*n", "*n")
  t[m] = q
  print(solve(t))
end
-- local score = solve(t)
-- math.randomseed(1)
-- local iter = 1
-- local random = math.random
-- while os.clock() < 1.5 do
--   iter = iter + 1
--   local changeday = random(1, 365)
--   local changeto = random(1, 26)
--   local changefrom = t[changeday]
--   t[changeday] = changeto
--   local tmp = solve(t)
--   if score < tmp then
--     score = tmp
--   else
--     t[changeday] = changefrom
--   end
-- end
-- print(iter)
-- -- print(table.concat(t, "\n"))


Measured memory_bytes: 2944
#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 = 0;
    cin >> n;

    n = n % 10;

    if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9){
        cout << "hon" << endl;
    }else if(n == 0 || n == 1 || n == 6 || n ==8){
        cout << "pon" << endl;
    }else{
        cout << "bon" << endl;
    }
   
  
    
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
using namespace std;

const int INF = 1e9;

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int m,n;
  cin >> m >> n;
  vector<int> p(m),c(n),e(n);
  rep(i,m)cin >> p[i];
  sort(p.begin(),p.end(),greater<int>());
  rep(i,n)cin >> c[i] >> e[i];
  
  vector<int> dp(m+1,INF);
  dp[0] = 0;

  rep(i,n){
    for(int j=m;j>=0;j--){
      if(j<m)chmin(dp[j], dp[j+1]);
      chmin(dp[j], dp[max(0,j-c[i])] + e[i]);
    }
  }

  int ans = 0, sum = 0;
  rep(i,m){
    sum += p[i];
    chmax(ans, sum-dp[i+1]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1304
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int total = A * X + B * Y;
  int dif = A + B - 2 * C;
  if (dif > 0) {
    total -= dif * min(X, Y);
    if (X > Y) {
      int dif2 = A - 2 * C;
      if (dif2 > 0) {
        total -= dif2 * (X - Y);
      }
    }
    if (Y > X) {
      int dif2 = B - 2 * C;
      if (dif2 > 0) {
        total -= dif2 * (Y - X);
      }
    }
  }
  print(total);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    while(1){
        int n; cin>>n;
        if(n == -1) return 0;

        int ans = 1150;
        if(10 < n && n <= 20) ans += (n - 10) * 125;
        if(20 < n && n <= 30) ans += (n - 20) * 140 + 1250;
        if(30 < n) ans += (n - 30) * 160 + 1400 + 1250;

        cout << 4280 - ans << endl;
    }
}


Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

typedef long long ll;
bool debug = false;
const int NIL = -1;
const int INF = 100000;
const int NUM = 16;
clock_t START, END;
int G[NUM][NUM], dist[NUM][1 << 16];
int V;

int TSP(int k, int set) {
	if (set == 0)
		return dist[k][set] = G[k][0];
	if (dist[k][set] != -1)
		return dist[k][set];
	int i = 0, t, _min = INF;
	while (i < V - 1) {
		t = set & 1 << i;
		if (t) {
			_min = min(_min, G[k][i + 1] + TSP(i + 1, set & (~(1 << i))));
		}
		i++;
	}
	return dist[k][set] = _min;
}

int main(void)
{
	if (debug) {
		START = clock();
		freopen("in29.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	};
	int E, s, t, d;
	cin >> V >> E;
	for (int i = 0; i < V; i++)
		for (int j = 0; j < V; j++)
			G[i][j] = -1;
	for (int i = 0; i < E; i++) {
		cin >> s >> t >> d;
		G[s][t] = d;
	}
	for (int i = 0; i < V; i++) {
		for (int j = 0; j < V; j++) {
			if (G[i][j] == -1)
				G[i][j] = INF;
		}
	}
	for (int i = 0; i < V; i++)
		for (int j = 0; j < 1 << V; j++)
			dist[i][j] = -1;
	int ans = TSP(0, (1 << V - 1) - 1);
	if (ans == 100000)
		cout << "-1" << endl;
	else
		cout << ans << endl;
	if (debug) {
		END = clock();
		double endtime = (double)(END - START) / 1000;
		printf("total time = %lf s", endtime);
	}
	return 0;
}


Measured memory_bytes: 5100
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

vector<int> vec[SIZE];
int n,m;

bool f[SIZE][2];

void dfs1(int now, int b){

  if(f[now][b]) return;
  f[now][b] = 1;
  
  for(int i=0;i<vec[now].size();i++){
    dfs1(vec[now][i], 1-b);
  }

  return;
}

int main(){
  int a,b;

  
  scanf("%d%d",&n,&m);

  for(int i=0;i<m;i++){
    scanf("%d%d",&a,&b);
    a--; b--;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }

  dfs1(0, 0);
  
  ll only0 = 0, only1 = 0;
  
  for(int i=0;i<n;i++){
    if(f[i][0] && !f[i][1]) only0++;
    if(!f[i][0] && f[i][1]) only1++;
  }
  
  printf("%lld\n", (ll)n*(n-1)/2 - only0*(only0-1)/2 - only1*(only1-1)/2 - m);
  
  return 0;
}



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

int main(void){
    int n, l, cnt;
    vector<int> N;
    cin >> n;
    cnt = 0;
    
    for(int i = 0; i < n; i++){
        cin >> l;
        N.push_back(l);
    }
    
    sort(N.begin(), N.end());
    
    int i, j, k;
    for(i = 0; i < n; i++){
        j = i;
        while(N[i] == N[j]) j++;
        for(; j < n; j++){
            k = j;
            while(N[j] == N[k]) k++;
            for(; k < n; k++){
                if(N[i] + N[j] > N[k] && N[j] + N[k] > N[i] && N[k] + N[i] > N[j]) cnt++;
            }
        }
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 3620
N, M = map(int, input().strip().split())
L = [0] * M
R = [0] * M
for i in range(M):
    L[i], R[i] = map(int, input().strip().split())

diff = min(R) - max(L)
if diff >= 0:
    print(diff + 1)
else:
    print(0)


Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main() {
    int N; cin>>N;
    vector<ll> x(N),y(N);
    vector<pair<double,int>> angle(N);
    for (int i = 0; i < N; ++i) {
        cin>>x[i]>>y[i];
        angle[i].second=i;
        if(x[i]==0&&y[i]==0){
            angle[i].first=0.0;
            continue;
        }
        angle[i].first=atan2(y[i],x[i]);
        if(angle[i].first<0.0) angle[i].first=2.0*M_PI+angle[i].first;
    }

    sort(angle.begin(),angle.end());
/*
    for (int i = 0; i < N; ++i) {
        cout<<angle[i].first<<" "<<angle[i].second<<endl;
    }
    */

    double ans=0.0;


    for (int i = 0; i < N; ++i) {
        double xsum=0.0,ysum=0.0;
        double sangle=angle[i].first;
        for (int j = 0; j < N; ++j) { //選ぶ個数
            int target=i+j;
            if(target>=N) target-=N;
            xsum+=(double)x[angle[target].second]; ysum+=(double)y[angle[target].second];
            ans=max(ans,sqrt(pow(xsum,2.0)+pow(ysum,2.0)));
        }
    }

    printf("%.15f\n",ans);

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		char op = sc.next().charAt(0);
		int b = sc.nextInt();
		
		System.out.println(op == '+' ? a + b : a - b);
	}
}

Measured memory_bytes: 35504
#include <iostream>
#include <numeric>
#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
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	int A, B;
	cin >> A >> B;
	A = (A + 11) % 13;
	B = (B + 11) % 13;
	if (A > B) {
		cout << "Alice" << endl;
	}
	else if (A < B) {
		cout << "Bob" << endl;
	}
	else {
		cout << "Draw" << endl;
	}
	
}


Measured memory_bytes: 256
import java.util.*;
import java.text.*;

class Main{
public static void main(String[] args){
Scanner s = new Scanner(System.in);
	  int a = s.nextInt();
	  int b = s.nextInt();
	  int d = a / b;
	  int r = a % b;
	  double f = (double)a / (double)b;
	  
	  DecimalFormat fm = new DecimalFormat("#.######");
      System.out.println(d+" "+r+" "+fm.format(f));
	 }
	}

Measured memory_bytes: 17376
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
#include <boost/any.hpp>
using namespace::std;
namespace mp = boost::multiprecision;
typedef mp::number<mp::cpp_dec_float<32,int64_t>> cfloat;
typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define cout (cout<<fixed<<setprecision(15))
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<"\n";}while(0)
#define output2(v) for(auto i:v)output(i);
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define sum(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF 9223372036854775807
#define MOD 1000000007
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
vec bellmanFord(lint V,lint E,vec from,vec to,vec cost){
    vec diff(V,INF);
    diff[0]=0;
    rep(j,V-1)rep(i,E){
        if(diff[from[i]]!=INF)diff[to[i]]=min(diff[to[i]],diff[from[i]]+cost[i]);
    }
    rep(j,V)rep(i,E){
        if(diff[from[i]]!=INF && diff[from[i]]+cost[i]<diff[to[i]])diff[to[i]]=-INF;
    }
    return diff;
}
int main(){
    lint n,m,p;
    cin>>n>>m>>p;
    vec a(m),b(m),c(m);
    rep(i,m)cin>>a[i]>>b[i]>>c[i];
    rep(i,m){
        a[i]--;
        b[i]--;
        c[i]-=p;
        c[i]*=-1;
    }
    vec diff=bellmanFord(n,m,a,b,c);
    if(diff[n-1]==-INF)cout<<-1;
    else cout<<max(0LL,-diff[n-1]);
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    string s;
    char bc = ' ';
    vector<string>word1,word2;
    cin >> s;
    int cnt = 0, slen = s.size();
    word1.push_back(s.substr(0, 1));
    for (int i = 1; i < slen; i++) {
        if (slen - i == 2) {
            if (s[slen - 1] == s[slen - 2]) {
                if (word1[cnt] == s.substr(slen - 2, 2)) {
                    word1[cnt] = s.substr(slen - 4, 3);
                    word1.push_back(s.substr(slen - 1, 1));
                    break;
                }
                else {
                    word1.push_back(s.substr(slen - 2, 2));
                    break;
                }
            }
        }
        if (word1[cnt] != (s.substr(i, 1))) {
            word1.push_back(s.substr(i, 1));
            cnt++;
        }
        else if (slen - i >= 2) {
            word1.push_back(s.substr(i, 2));
            i++;
            cnt++;
        }
    }
    /*if (s.size() <= 2) {
        for (int i = 2; i < s.size(); i++) {
            if (word2[i - 1] != s[i] + "")word2.push_back(s[i] + "");
            else if (s.size() - i <= 2) {
                word2.push_back(s.substr(i, 2));
                i++;
            }
        }
    }
    rep(i, s.size()) {
        if (bc != s[i]) {
            bc = s[i];
            cnt++;
        }
        else {
            if ((s.size() - i) <= 2)i++, cnt++; bc = ' ';
        }
    }
    word2.push_back(s.substr(0, 2));*/
    cout << word1.size()<< endl;
    return 0;
}


Measured memory_bytes: 11852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

string s;

int main(void){
    
    cin >> s;
    if(s.size() == 2) cout << s << endl;
    else{
        reverse(s.begin(), s.end());
        cout << s << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int N;
string s, g;
int dp[1<<16][16];
int dfs(int S, int u){
  if(S == (1<<N) - 1) return 0;
  if(dp[S][u] != -1) return dp[S][u];
  int res = INF;
  REP(i, N)REP(j, N) if(i != j && (S >> i & 1) == 0 && (S >> j & 1) == 0 && g[i] != g[j]){
    res = min(res, abs(u - i) + abs(i - j) + dfs(S | 1 << i | 1 << j, j));
  }
  return dp[S][u] = res;
}
int main(){
  while(cin>>N && N){
    cin>>s>>g;
    REP(S, 1<<N) REP(p, N) dp[S][p] = -1;
    int S = 0;
    REP(i, N) if(s[i] == g[i]) S |= 1<<i;
    int ans = INF;
    REP(i, N) ans = min(ans, dfs(S, i));
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 5024
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
sum = 0
t = 0
for i in range(n):
  a = list(map(int,input().split()))
 # print(a)
  for x in range(m):
    t += a[x]*b[x]
  #print(t)
  if t+c >0:
    sum += 1
  t =0
print(sum)
  

Measured memory_bytes: 3060
import java.io.IOException;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Map<BigInteger, Integer> memo;
    static boolean[][] vis;
    static List<List<Integer>> adj;
    static List<Integer> vertices;

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

        int n = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < n; ++i) {
            int num =sc.nextInt();
            if (!set.add(num)) {
                System.out.println("NO");
                return;
            }

        }
            System.out.println("YES");
    }


    static int lowerBound(int[] arr, int element) {

        int low = 0, high = arr.length - 1, ans = 0;
        while (low <= high) {
            int mid = low + (high - low) / 2;
            if (arr[mid] <= element) {
                low = mid + 1;
                ans = mid;
            } else
                high = mid - 1;

        }

        return high;
    }

    static boolean isPalindrome(String word) {
        int i = 0, j = word.length() - 1;

        while (i <= j) {
            if (word.charAt(i++) != word.charAt(j--))
                return false;
        }

        return true;
    }

    static String longestPalindrome(String[] words, String word, int i) {
        if (i >= words.length) {
            if (isPalindrome(word))
                return word;

            return "";
        }

        if (word.length() > 0 && isPalindrome(word))
            return word;
        String left = longestPalindrome(words, word + words[i], i + 1);
        String right = longestPalindrome(words, word, i + 1);

        if (left.length() > 0)
            return left;
        return right;
    }


    static int solve(int[] arr, int i, int j, int k) {
        if (i == j && arr[i] <= k)
            return 1;

        int left = 0, right = 0;
        if (arr[i] <= k)
            left = solve(arr, i + 1, j, k) + 1;

        else if (arr[j] <= k)
            right = solve(arr, i, j - 1, k) + 1;

        return left + right;
    }

    static int minMove(BigInteger bg, int count) {
        if (bg.equals(BigInteger.ONE))
            return count;

        int first = Integer.MAX_VALUE, sec = Integer.MAX_VALUE, last = Integer.MAX_VALUE;
        if (bg.mod(BigInteger.valueOf(2)).compareTo(BigInteger.ZERO) == 0)
            first = minMove(bg.divide(BigInteger.valueOf(2)), count + 1);

        else if (bg.mod(BigInteger.valueOf(3)).compareTo(BigInteger.ZERO) == 0)
            sec = minMove(bg.multiply(BigInteger.valueOf(2)).divide(BigInteger.valueOf(3)), count + 1);

        else if (bg.mod(BigInteger.valueOf(5)).compareTo(BigInteger.ZERO) == 0)
            last = minMove(bg.multiply(BigInteger.valueOf(4)).divide(BigInteger.valueOf(5)), count + 1);

        if (memo.containsKey(bg))
            return memo.get(bg);

        memo.put(bg, Math.min(first, Math.min(sec, last)));

        return Math.min(first, Math.min(sec, last));
    }
}


Measured memory_bytes: 69936
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func init() {
	sc = bufio.NewScanner(os.Stdin)
	buffsize := 1000000
	buff := make([]byte, buffsize)
	sc.Buffer(buff, buffsize)
	sc.Split(bufio.ScanWords)
}

func loadint() (result int) {
	sc.Scan()
	result, _ = strconv.Atoi(sc.Text())
	return
}

func main() {
	n := loadint()
	result := 1110 - n
	fmt.Println(result)
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>

const int mod = 1e9 + 7;
int f[2][16];
char S1[233], S2[233];
int main()
{
	int n; scanf("%d", &n);
	scanf("%s%s", S1 + 1, S2 + 1);
	int x = 1;
	f[0][0] = 1;
	for (int i = 1; i <= n; ++i, x ^= 1)
	{
		memset(f[x], 0, sizeof (f[x]));
		if (S1[i] != S2[i])
		{
			++i;
			for (int j = 0; j < 16; ++j)
				if ((j >> 2) && (j & 3) && ((j >> 2) != (j & 3)))
					for (int k = 0; k < 16; ++k)
						if (((k >> 2) != (j >> 2)) && ((k & 3) != (j & 3)))
							(f[x][j] += f[x ^ 1][k]) %= mod;
		}
		else
		{
			for (int j = 5; j < 16; j += 5)
				for (int k = 0; k < 16; ++k)
					if (((k >> 2) != (j >> 2)) && ((k & 3) != (j & 3)))
						(f[x][j] += f[x ^ 1][k]) %= mod;
		}
	}
	int ans = 0;
	for (int i = 0; i < 16; ++i) (ans += f[x ^ 1][i]) %= mod;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b;
    d=b-a;
    rep(i,d)ans+=i;
    Cout(ans-a);
    return 0;
}


Measured memory_bytes: 768
n, m = map(int, input().split())
l = []
for i in range(n):
    l.append(list(map(int, input().split())))

if m == 0:
    print(0)
    exit()
    
ans = 0
tl = []
for x in l:
    tl.append(x[0] + x[1] + x[2])
tl.sort()
tmp = sum(tl[-m:])
if ans < tmp:
    ans = tmp

tl = []
for x in l:
    tl.append(x[0] + x[1] - x[2])
tl.sort()
tmp = sum(tl[-m:])
if ans < tmp:
    ans = tmp

tl = []
for x in l:
    tl.append(x[0] - x[1] + x[2])
tl.sort()
tmp = sum(tl[-m:])
if ans < tmp:
    ans = tmp

tl = []
for x in l:
    tl.append(x[0] - x[1] - x[2])
tl.sort()
tmp = sum(tl[-m:])
if ans < tmp:
    ans = tmp

tl = []
for x in l:
    tl.append(- x[0] + x[1] + x[2])
tl.sort()
tmp = sum(tl[-m:])
if ans < tmp:
    ans = tmp

tl = []
for x in l:
    tl.append(-x[0] + x[1] - x[2])
tl.sort()
tmp = sum(tl[-m:])
if ans < tmp:
    ans = tmp

tl = []
for x in l:
    tl.append(-x[0] - x[1] + x[2])
tl.sort()
tmp = sum(tl[-m:])
if ans < tmp:
    ans = tmp

tl = []
for x in l:
    tl.append(-x[0] - x[1] - x[2])
tl.sort()
tmp = sum(tl[-m:])
if ans < tmp:
    ans = tmp
print(ans)

Measured memory_bytes: 39536
#include<stdio.h>
int main(void)
{
  int m,f,r,j,sum;

  scanf("%d %d %d",&m,&f,&r);

  while(m!=-1 || f!=-1 || r!=-1){
    if(m == -1)sum=0;
    else if(f == -1)sum=0;
    else sum=f+m;
    if(sum >= 80)printf("A\n");
    else if(sum >= 65)printf("B\n");
    else if(sum >= 50)printf("C\n");
    else if(sum >= 30){
      if(r >= 50)printf("C\n");
      else printf("D\n");
    }
    else printf("F\n");
    scanf("%d %d %d",&m,&f,&r);
  }

  return 0;
}

Measured memory_bytes: 2680
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

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

    for (int i = 0; i < 2; ++i) {
        if (a > b) {
            cnt += a;
            a = a - 1;
        }
        else {
            cnt += b;
            b = b - 1;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int a;
    while(cin>>a){
        if(a==0){
            break;
        }
        int Z=0,Y=0,X=0,z=0,y=0,m=10000000;
        for(z=0;pow(z,3)<=a;z++){
            Z=pow(z,3);
            for(y=0;pow(y,2)<=a-Z;y++){
                Y=pow(y,2);
            }
            X=a-Y-Z;
            if(X+y+z-2<m){
                m=X+y+z-1;
            }
        }
        cout<<m<<endl;
    }
    return 0;
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f3f3f3f3f
#define PI acos(-1.0)
#define MOD 1000000007
#define R READ();
using namespace std;
typedef long long LL;
void READ()
{
    std::ios::sync_with_stdio(false);
#ifdef ONLINE_JUDGE
#else
    freopen("555input.txt","r",stdin);
    //freopen("555output.txt","w",stdout);
#endif
}
#define N 1005
char a,b;
int main()
{
    
    a=getchar();
    b=getchar();
    if(a=='9'||b=='9')cout<<"Yes";
    else cout<<"No";


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
const int N=300300;
int n,C[N],S[N],X[N],Y[N];
int Find(int u) {
	return u==C[u]?u:C[u]=Find(C[u]);
}
void Uni(int x,int y) {
	x=Find(x),y=Find(y);
	if(x!=y) C[x]=y,S[y]+=S[x],X[y]+=X[x],Y[y]+=Y[x];
}
int main() {
	scanf("%d",&n);
	For(i,1,300020) C[i]=i;
	For(i,1,100000) X[i+100010]=1;
	For(i,1,100000) Y[i+200020]=1;
	For(i,1,n) S[i]=1;
	For(i,1,n) {
		int x,y;
		scanf("%d%d",&x,&y);
		Uni(i,x+100010);
		Uni(i,y+200020);
	}
	long long ans=0;
	For(i,1,300020)
	if(i==Find(i)) {
		int x=X[i],y=Y[i],s=S[i];
		ans+=1LL*x*y-s;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define dalao main
#define inf 0x3f3f3f3f
#define M(x) memset(x,0,sizeof(x))
#define Mi(x) memset(x,0x3f,sizeof(x))
#define debug(x) {cerr<<#x<<" = "<<(x)<<endl;}
#define ll long long
using namespace std;
void read(int &x)
{
	int f=1;x=0;char s=getchar();
	while(s<'0'||s>'9'){if(f=='-') f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
	x*=f;
}
int dalao()
{
	char s[105];bool flag=false;
	scanf("%s",s);
	for(int i=0;i<=strlen(s)-1;i++)
	{
		if(s[i]=='C') flag=true;
		if(flag&&s[i]=='F')
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No");
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    vector<pair<ll, ll>> A(N);
    rep(i, N) {
        ll x, l;
        cin >> x >> l;
        A[i] = pair<ll, ll>{x + l, x - l};
    }
    ll cur = numeric_limits<ll>::min();
    ll ans = 0;
    sort(A.begin(), A.end());
    iter(i, A) {
        if(cur <= i.second) {
            ans++;
            cur = i.first;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4844
while s = gets
  @n = s.chop.to_i
  @r = 0
  @c = 0 

  def s(a, s)
    if a.length == 4
      @r += 1 if a.inject(:+) == @n
    else
      (0..9).each { |x| 
        a.push(x)
        s(a, s + x)
        a.pop
      }   
    end 
  end 

  s(Array.new, 0)
  puts @r
end

Measured memory_bytes: 2328
#include <bits/stdc++.h>
const int maxn=1e2+10,mod=1e9+7;
typedef long long ll;
using namespace std;
int n,m,k,t;
int dp[1<<18][18];
int a[18],b[18];
int main()
{
    int i,j;
    //freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
    memset(dp,-1,sizeof(dp));
    for(i=0;i<n;i++)
        dp[1<<i][i]=0;
    for(i=1;i<1<<n;i++)
    {
        int cur=__builtin_popcount(i);
        for(j=0;j<n;j++)
        {
            if(!~dp[i][j])continue;
            int x=(cur%2==j%2?b[j]:a[j]);
            int save=cur;
            for(k=0;k<n;k++)
            {
                if(i>>k&1)save--;
                else
                {
                    int y=(cur%2==k%2?a[k]:b[k]);
                    if(y>=x)
                    {
                        if(!~dp[i|(1<<k)][k]||dp[i|(1<<k)][k]>dp[i][j]+save)
                        {
                            dp[i|(1<<k)][k]=dp[i][j]+save;
                        }
                    }
                }
            }
        }
    }
    int ret=-1;
    for(i=0;i<n;i++)
    {
        if(~dp[(1<<n)-1][i])
        {
            if(ret==-1||ret>dp[(1<<n)-1][i])
            {
                ret=dp[(1<<n)-1][i];
            }
        }
    }
    printf("%d\n",ret);
    return 0;
}


Measured memory_bytes: 18688
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,M = LI()
    A = LI()
    a = sorted(A,reverse=True)

    high = a[0] * 2 + 1
    low = 0
    while high > low + 1:
        mid = (high + low) // 2

        cnt = 0
        j = N - 1
        for i in range(N):
            while a[i] + a[j] < mid:
                j -= 1
                if j < 0: break
            else:
                cnt += (j+1)
                continue
            break
        if cnt < M:
            high = mid
        else:
            low = mid

    s = [a[0]]
    for i in range(1,N):
        s.append(s[-1]+a[i])

    ans = 0
    cnt = 0
    j = N - 1
    for i in range(N):
        while a[i] + a[j] < low:
            j -= 1
            if j < 0: break
        else:
            ans += a[i] * (j+1) + s[j]
            cnt += j + 1
            continue
        break

    print(ans - (cnt-M) * low)


if __name__ == '__main__':
    main()

Measured memory_bytes: 93424
#include<stdio.h>


int main(){
	
	int R;
	
	scanf("%d",&R);
	
	if(R<1200){
		printf("ABC\n");
	}
	
	else if(R>=1200 && R<2800){
		printf("ARC\n");
	}
	
	else{
		printf("AGC\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main()
{
    int n, m;
    while(cin >> n >> m, n|m){
        vi taro;
        rep(i, n){
            int input;
            cin >> input;
            taro.pb(input);
        }
        vi hanako;
        rep(i, m){
            int input;
            cin >> input;
            hanako.pb(input);
        }
        int ans1 = 100, ans2 = 100;
        rep(i, n){
            rep(j, m){
                swap(taro[i], hanako[j]);
                // cout << ans1 << " " << ans2 << " " << taro[i] << " " << taro[j] << endl;
                if(accumulate(ALL(taro), 0) == accumulate(ALL(hanako), 0) && ans1+ans2 > taro[i]+hanako[j]){
                    ans2 = taro[i];
                    ans1 = hanako[j];
                }
                swap(taro[i], hanako[j]);
            }
        }
        if (ans1 == 100 && ans2 == 100) cout << -1 << endl;
        else cout << ans1 << " " << ans2 << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define tc(t)  int t; cin>>t; while(t--)
#define f(n)    for(int i=0;i<n;i++)
#define endl   "\n"
int sum(int n)
{
    if(n==0) return  0;

    return n%10+ sum((n/10));




}
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 int n;
 cin>>n;
 int answer=sum(n);

  n%answer==0? cout<<"Yes"<<endl:cout<<"No"<<endl;




}

Measured memory_bytes: 3652
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<vector>
#include<math.h>
#include<stack>
#include<map>
#include<queue>
#define ls(x) (x<<1)
#define rs(x) ((x<<1)|1)
#define eps 1e-9
using namespace std;
long long n;
long long a[100005],b[100005];
long long cnt[100005];
int main()
{
	scanf("%lld",&n);
	if(n==1)
	{
		printf("YES");
		return 0;
	}
	long long sum=0;
	for(long long i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	for(long long i=1;i<n;i++)
	{
		b[i]=a[i]-a[i+1];
	}
	b[n]=a[n]-a[1];
	long long num=n*(n+1)/2;
	if(sum%num)
	{
		printf("NO");
		return 0;
	}
	long long k=sum/num;
	sum=0;
	for(long long i=1;i<=n;i++)
	{
		if(b[i]+k<0||(b[i]+k)%n)
		{
			printf("NO");
			return 0;
		}
		cnt[i]=(b[i]+k)/n;
		sum+=cnt[i];
	}
	if(sum!=k)
	{
		printf("NO");
		return 0;
	}
	printf("YES");
}

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

#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

//{{{
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while
(getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}

const int N = 1e5 + 10;
int T;

LL dp[N];
int n, W;
const int INF = 0x3f3f3f3f;

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

    while (cin >> n >> W)
    {
        clr(dp, 0x3f);
        dp[0] = 0;

        int w, v;

        for (int i = 0; i < n; i++)
        {
            cin >> w >> v;

            // memcpy(dp[i + 1], dp[i], sizeof(dp[i]));
            for (int j = 100000; j >= 0; j--)
            {
                if (dp[j] == INF) continue;
                if (j + v > 100000) continue;
                dp[j + v] = min(dp[j + v], dp[j] + w);
            }
        }

        LL ans = 0;
        for (int i = 100000; i >= 0; i--)
        {
            if (dp[i] == INF) continue;
            if (dp[i] > W) continue;
            ans = i;
            break;
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 4396
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());
        long INF = 5_000_000_000_000_000_000L;
        ArrayList<int[]> point_x = new ArrayList<int[]>();
        Comparator<int[]> comparator_x = new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return Integer.compare(o1[0], o2[0]);
            }
        };
        Comparator<int[]> comparator_y = new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return Integer.compare(o1[1], o2[1]);
            }
        };
        for (int i=0;i<N;i++) {
            int x = Integer.parseInt(sc.next());
            int y = Integer.parseInt(sc.next());
            int[] add = {x, y, i};
            point_x.add(add);
        }
        ArrayList<int[]> point_y = new ArrayList<int[]>(point_x);
        Collections.sort(point_x, comparator_x);
        Collections.sort(point_y, comparator_y);
        // for (int[] array : point_x) {
        //     System.out.println("x " + Arrays.toString(array));
        // }
        // for (int[] array : point_y) {
        //     System.out.println("y " + Arrays.toString(array));
        // }
        long ans = INF;
        for (int wid=2;wid<=N;wid++) {
            for (int i=0;i+wid<=N;i++) {
                int[] flag = new int[N];
                for (int j=i;j<i+wid;j++) {
                    flag[point_x.get(j)[2]]=1;
                }
                for (int wid_2=2;wid_2<=N;wid_2++) {
                    for (int j=0;j+wid_2<=N;j++) {
                        int cnt=0;
                        for (int k=j;k<j+wid_2;k++) {
                            // System.out.println("k wid " + k + " " + wid);
                            if (flag[point_y.get(k)[2]]==1) {
                                cnt++;
                            }
                        }
                        if (cnt>=K) {
                            ans = Math.min(ans, (long)(point_x.get(i+wid-1)[0]-point_x.get(i)[0])*(point_y.get(j+wid_2-1)[1]-point_y.get(j)[1]));
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }
}


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

using namespace std;

void solve()
{
  deque< int > q;
  int N;
  cin >> N;

  for(int i = 0; i < N; i++) {
    int A;
    cin >> A;
    if(i & 1) {
      if(N & 1)q.emplace_back(A);
      else q.emplace_front(A);
    } else {
      if(N & 1)q.emplace_front(A);
      else q.emplace_back(A);
    }
  }

  for(auto &p : q) cout << p << " ";
  cout << endl;

}

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


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
 
typedef pair <int, int> ii;
 
const int Maxn = 105;
 
int n;
ii A[Maxn], B[Maxn];
bool tk[Maxn];
int res;
 
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d %d", &A[i].first, &A[i].second);
	for (int i = 0; i < n; i++)
		scanf("%d %d", &B[i].first, &B[i].second);
	sort(A, A + n);
	sort(B, B + n);
	for (int i = n - 1; i >= 0; i--) {
		int bj = -1;
		for (int j = 0; j < n; j++)
			if (A[i].first < B[j].first && A[i].second < B[j].second && !tk[j])
				if (bj == -1 || B[j].second < B[bj].second) bj = j;
		if (bj != -1) {
			res++;
			tk[bj] = true;
		}
	}
	printf("%d\n", res);
	return 0;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    string ans = "";
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '0')
            ans += "0";
        else if (s[i] == '1')
            ans += "1";
        else {
            if (ans.empty() == false)
                ans.erase(ans.begin() + ans.size() - 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
//#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define mii map<int,int>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi 3.14159265359
//#define INF 0x7fffffff
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long LL;
int main(){
	char c[10];
	scanf("%s",c);
	for(int i=0;c[i+1]!=0;i++){
		if(c[i]=='A'&&c[i+1]=='C')
			{
				printf("Yes\n");
				return 0;
			}
	}
	printf("No\n");
} 





Measured memory_bytes: 768