akhauriyash/Code-Regression huggingface dataset:
/* Header {{{ */
#include <bits/stdc++.h>
using namespace std;

typedef long long readtype;
typedef long long var;
typedef long double let;

readtype read() {
  readtype a = 0, c = getchar(), s = 0;
  while (!isdigit(c)) s |= c == '-', c = getchar();
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
  return s ? -a : a;
}

#ifdef LOCAL_LOGGER
#define logger(...) fprintf(stderr, __VA_ARGS__)
#define abortif(v, ...) if (v) {logger("Error in Line %d, Function '%s()'.\nInfo: ", __LINE__, __FUNCTION__); logger(__VA_ARGS__); exit(0);}
#else
#define logger(...);
#define abortif(v, ...);
#endif
/* }}} */

const let EPS = 1e-8;

int sign(let x) { return (x < -EPS) ? -1 : (x > EPS ? 1 : 0); }

struct Point {
  let x, y;

  friend Point operator + (Point a, Point b) {
    return (Point) {a.x + b.x, a.y + b.y};
  }
  friend Point operator - (Point a, Point b) {
    return (Point) {a.x - b.x, a.y - b.y};
  }
  let Dist() {
    return sqrt(x * x + y * y);
  }
  Point Rotate(let sink, let cosk) {
    return (Point) {x * cosk - y * sink, x * sink + y * cosk};
  }
  Point Rotate(Point k) {
    let z = k.Dist();
    return Rotate(k.y / z, k.x / z);
  }
  Point operator ~ () {
    return (Point) {x, -y};
  }
};

typedef Point Vec;

struct Line {
  Point p;
  Vec v;
  Line() {}
  Line(Point a, Point b) {
    p = a, v = b - a;
  }
  friend int CheckRelate(Line a, Line b) {
    Vec res = b.v.Rotate(~a.v);
    if (!sign(res.y)) return 2;
    if (!sign(res.x)) return 1;
    return 0;
  }

  // friend bool CheckParallel(Line a, Line b) {
  // }
  // friend bool CheckOrthogonal(Line a, Line b) {
  // }
};

Point ReadPoint() {
  let x, y;
  scanf("%Lf%Lf", &x, &y);
  return (Point) {x, y};
}

int main() {
// #ifndef ONLINE_JUDGE
//   freopen("CGL_2_A.in", "r", stdin);
//   freopen("CGL_2_A.out", "w", stdout);
// #endif
// #ifdef LOCAL_LOGGER
//   freopen("CGL_2_A.log", "w", stderr);
// #endif
  int q = read();
  while (q--) {
    Line l1 = (Line) {ReadPoint(), ReadPoint()},
         l2 = (Line) {ReadPoint(), ReadPoint()};
    printf("%d\n", CheckRelate(l1, l2));
  }
  return 0;
}

/* ==== Makefile ==== {{{
CompileAndRun:
	make Compile
	make Run

Compile:
	g++ -o CGL_2_A CGL_2_A.cpp -g -Wall -DLOCAL_LOGGER

CompileUF:
	g++ -o CGL_2_A CGL_2_A.cpp -g -Wall -DLOCAL_LOGGER -fsanitize=undefined

Run:
	./CGL_2_A < CGL_2_A.in > CGL_2_A.out
==================
}}} */



Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

vec<int> mult(vec<int>& A,vec<int>& B){
    vec<int> C(A.size());
    for(int i=0;i<A.size();i++) C[i] = B[A[i]];
    return C;
}

vec<int> pow(vec<int>& A,ll n){
    if(n==1) return A;
    vec<int> R = pow(A,n>>1);
    R = mult(R,R);
    if(n&1) R = mult(A,R);
    return R;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> X(N);
    vec<int> D(N-1);
    for(int i=0;i<N;i++){
        cin >> X[i];
        if(i) D[i-1] = X[i]-X[i-1];
    }
    vec<int> perm(N-1);
    iota(perm.begin(),perm.end(),0);
    int M;
    ll K;
    cin >> M >> K;
    for(int i=0;i<M;i++){
        int a;
        cin >> a;
        a -= 2;
        swap(perm[a],perm[a+1]);
    }
    auto res = pow(perm,K);
    ll s = X[0];
    for(int i=0;i<N;i++){
        cout << s << "\n";
        if(i!=N-1) s += D[res[i]];
    }
}

Measured memory_bytes: 5204
#include<iostream>
#include<string>

using namespace std;

int main(){
	string s, ans = "";
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'B'){
			if(ans.size()){
				ans.pop_back();
			}
		}else{
			ans += s[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n;
    cin >> n;
    if(n%1000) print(1000-n%1000);
    else print(0);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

void Cont(){
    int N;
    cin >> N;
    vector<int> di(N);
    int p_differ = 0;
    for(auto& v : di)
        cin >> v;
    sort(di.begin(),di.end());//1 3 5..
    
    int temp=0, X=0;
    for(auto& v :di)
        if(temp <v){
            X++;
            temp = v;
        }
    cout << X << "\n";
}

int main()
{
	std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Cont();
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))

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

	int res = 0;
	REP(i, 1, N + 1)res += to_string(i).size() % 2;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

string S;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> S;
    int ans = 0;
    REP(i, S.size()) {
        char f = i & 1 ? 'p' : 'g';
        char s = S[i];
        if (f != s) f == 'p' ? ans++ : ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include <climits>
#include<vector>
#include<list>
#include<numeric>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;



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

	int n, k;
	cin >> n >> k;
	vector<int> w(n);
	vector<int> sum(n + 1, 0);
	REP(i, n) {
		cin >> w[i];
		sum[i + 1] += sum[i] + w[i];
	}
	int left = 0, right = 1e9;
	
	while (left + 1 != right) {
		int mid = (left + right) / 2;
		int l = 0, r = 0;
		REP(i, k) {
			while (r < n && sum[r + 1] - sum[l] <= mid) {
				r++;
			}
			if (r == n) break;
			l = r;
		}
		if (r == n) right = mid;
		else left = mid;
	}
	cout << right << "\n";

	return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong K;
  string S;
  cin >> K >> S;

  for (int i = 0; i < min((llong)S.size(), K); ++i) {
    cout << S[i];
  }

  if (S.size() > K) {
    cout << "...";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main(){
int N;
cin >> N;
int num[110];
int count=0;
int ans=0;
int i;
int a;
for(i=0;i<100;i++){
        num[i]=0;
} 
for(i=0;i<N;i++){
       cin>>a;
       num[a]+=1;
} 
i=100;
while(i>0){
      while(num[i]>0){
            if (count==0) {
            ans+=i;
            }else{
            ans-=i;
            }
            count=(count+1)%2;
            num[i]-=1;
      }
i-=1;
}
cout<<ans;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define ct(string) cout << string

int main() {
    string s;
    cin >> s;
    int n1= (int) s.at(0)-48, n2= (int) s.at(1)-48, n3= (int) s.at(2)-48, n4= (int) s.at(3)-48, op;
    rep(i,8) {
        int value = n1;
        if (i & (1<<0)) value += n4;
        else value -= n4;
        if (i & (1<<1)) value += n3;
        else value -= n3;
        if (i & (1<<2)) value += n2;
        else value -= n2;
        if (value == 7) {op = i; break;}
    }
    ct(n1);
    if (op & (1<<2)) ct("+");
    else ct("-");
    ct(n2);
    if (op & (1<<1)) ct("+");
    else ct("-");
    ct(n3);
    if (op & (1<<0)) ct("+");
    else ct("-");
    ct(n4);
    ct("=7");
    ct(endl);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int n; cin >> n;
	vi a(n);
	REP(i,n) cin >> a[i];
	reverse(ALL(a));
	REP(i, n) {
		if (i == n - 1) cout << a[i] << endl;
		else cout << a[i] << " ";
	}
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  string a,s,c;
  cin>>a>>s>>c;
  
  string ans="";
  ans += a[0];
  ans += s[0];
  ans += c[0];
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
n,m=gets.split.map &:to_i
h=gets.split.map(&:to_i)
ab=m.times.map { gets.split.map &:to_i }
res=Hash.new{|h,k| h[k] = [] }
ab.each do |i|
  res[i[0]]<<i[1]
  res[i[1]]<<i[0]
end
ans=Hash.new{|h,k| h[k] = [] }
res.each do |k,v|
  v.each do |i|
    ans[k] = h[k-1] > h[i-1] ? true : false
    break if ans[k] == false
  end
end
puts n - ans.values.select{ |i| i==false }.size


Measured memory_bytes: 36376
import java.util.*;

public class Main {
    private static int[][] c;
    private static int count;

    public static void main(String[] args) {
        int h, w;

        Scanner sc = new Scanner(System.in);

        while (true) {
            w = sc.nextInt();
            h = sc.nextInt();
            if (w == 0 && h == 0) break;

            c = new int[h+2][w+2];

            for (int i=1; i<=h; i++) {
                for (int j=1; j<=w; j++) {
                    c[i][j] = sc.nextInt();
                }
            }
            for (int i=0; i<h+2; i++) c[i][0] = c[i][w+1] = 0;
            for (int j=0; j<w+2; j++) c[0][j] = c[h+1][j] = 0;

            count = 1;
            for (int i=1; i<=h; i++) {
                for (int j=1; j<=w; j++) {
                    if (c[i][j] == 1) {
                        count++;
                        bfs(i, j);
                    }
                }
            }
            
            System.out.println(count-1);
            c = null;
        }
    }

    private static void bfs(int row, int column) {
        c[row][column] = count;
        for(int i=-1; i<=1; i++) {
            for (int j=-1; j<=1; j++) {
                if (c[row+i][column+j] == 1) bfs(row+i, column+j);
            }
        }
    }
}

Measured memory_bytes: 45628
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  ll N;
  cin >> N;
  Vll A(N), B(N), C(N);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];
  REP(i, N) cin >> C[i];
  SORT(A); SORT(B); SORT(C);
  Vll B_possible(N);
  REP(i, N)
  {
    if (i != 0 && B[i] == B[i-1])
    {
      B_possible[i] = B_possible[i-1];
      continue;
    }
    ll x = B[i];
    B_possible[i] = bisect_left(A, x);
  }
  REP(i, N-1) B_possible[i+1] += B_possible[i];
  ll tmp1, tmp2;
  ll ans = 0;
  REP(i, N)
  {
    if (i != 0 && C[i] == tmp1)
    {
      ans += tmp2;
      continue;
    }
    ll x = C[i];
    ll count = bisect_left(B, x);
    tmp1 = C[i];
    if (count == 0) tmp2 = 0;
    else tmp2 = B_possible[count-1];
    ans += tmp2;
  }
  cout << ans << endl;

  return 0;
}

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

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

int main(){
    int H,W;cin >> H >> W;
    vector<string> field;
    for(int i = 0;i < H;i++){
        string s;cin >> s;
        field.push_back(s);
    }
    auto calc = [&](int x,int y){
        vector<vector<int>> dist(H, vector<int>(W, 1e9));
        queue<pair<int, int>> que;
        que.push(make_pair(x, y));
        dist[x][y] = 0;
        while(!que.empty()){
            auto q = que.front();
            que.pop();

            for(int i = 0;i < 4;i++){
                if(0 <= q.first + dx[i] && q.first + dx[i] < H && 0 <= q.second + dy[i] && q.second + dy[i] < W){
                    if(field[q.first+dx[i]][q.second+dy[i]] != '#' && dist[q.first+dx[i]][q.second+dy[i]] == 1e9){
                        que.push(make_pair(q.first+dx[i], q.second+dy[i]));
                        dist[q.first+dx[i]][q.second+dy[i]] = dist[q.first][q.second] + 1;
                    }
                }
            }
        }
        int ans = 0;
        for(int i = 0;i < H;i++){
            for(int j = 0;j < W;j++){
                if(field[i][j] == '.'){
                    ans = max(dist[i][j], ans);
                }
            }
        }
        return ans;
    };
    int ans = 0;
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            if(field[i][j] != '#')ans = max(calc(i, j), ans);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

    int n = s.nextInt();
    int[] a = new int[n];
    int[] sorted = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = s.nextInt();
      sorted[i] = a[i];
    }
    Arrays.sort(sorted);
    for (int i = 0; i < n; i++) {
      if (a[i] < sorted[n/2]) {
        System.out.println(sorted[n/2]);
      } else {
        System.out.println(sorted[n/2 - 1]);
      }
    }
  }
}


Measured memory_bytes: 90944
#ifdef Rahul
# include "RAHUL.h"
#else
# include <bits/stdc++.h>
  using namespace std;
# define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int n; cin >> n;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int x; cin >> x;
    if (i % 2 == 0 && x % 2) ++ans;
  }
  kek(ans);
}


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

struct Node{
    Node *left;
    Node *right;
    Node() { left = NULL, right = NULL; }
};

int findcc(string s) {
    int dd = 0;
    for(int i=0; i<s.length(); ++i) {
        if(s[i] == '(') dd++;
        else if(s[i] == ')') dd--;
        else if(s[i] == ',' && dd == 1) return i;
    }
    return -1;
}

Node* parse(string s) {
    Node *r = new Node();
    int ff = findcc(s);
    if(ff != 1) r->left = parse(s.substr(1,ff-1));
    if(ff != s.length()-2) {
        string tmp = s.substr(ff+1);
        r->right = parse(tmp.substr(0,tmp.length()-1));
    }
    return r;
}

Node *intersect(Node *r1,Node *r2) {
    Node *ret = new Node();
    if(r1->left != NULL && r2->left != NULL)
        ret->left = intersect(r1->left,r2->left);

    if(r1->right != NULL && r2->right != NULL)
        ret->right = intersect(r1->right,r2->right);

    return ret;
}

Node* uni(Node *r1,Node *r2) {
    if(r1 == NULL && r2 == NULL) return NULL;

    Node *ret = new Node();
    ret->left = uni(((r1 == NULL)?NULL:r1->left),(r2 == NULL)?NULL:r2->left);
    ret->right = uni(((r1 == NULL)?NULL:r1->right),(r2 == NULL)?NULL:r2->right);
    return ret;
}

string toStr(Node *tree) {
    string res = "(";
    if(tree->left != NULL) res += toStr(tree->left);
    res += ",";
    if(tree->right != NULL) res += toStr(tree->right);
    res += ")";
    return res;
}

void treedel(Node *node) {
    if(node->left != NULL) treedel(node->left);
    if(node->right != NULL) treedel(node->right);
    delete node;
    return;
}

int main() {
    string op,t1,t2;
    while(cin>>op>>t1>>t2) {
        Node *r1 = parse(t1);
        Node *r2 = parse(t2);
        Node *ans;
        if(op == "i") ans = intersect(r1,r2);
        else if(op == "u") ans = uni(r1,r2);

        cout<<toStr(ans)<<endl;
        treedel(r1); treedel(r2); treedel(ans);
    }
}

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

int main()
{
    int n,k,i,sum=0;
    cin>>n>>k;
    int price[n];
    for(i=0;i<n;i++)
        cin>>price[i];
    sort(price,price+n);
    for(i=0;i<k;i++)
        sum+=price[i];
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
#define mod (long)(1e9 + 7)
using namespace std;

long dp[3000][3000];

// long solve(int curr, int howManyLessLeft, string &s) {
// 	if(curr == s.size()) {
// 		return 1;
// 	}
// 	if(dp[curr][howManyLessLeft] != -1) return dp[curr][howManyLessLeft];
// 	long res = 0;
// 	if(s[curr] == '<') {
// 		int howManyHighLeft = (int)s.size() + 1 - (curr + 1 + howManyLessLeft);
		
// 		for(int i = 1; i <= howManyHighLeft; ++i) {
// 			res = (res + solve(curr + 1, howManyLessLeft + i - 1, s)) % mod;
// 		}
// 	}
// 	else {
// 		for(int i = 1; i <= howManyLessLeft; ++i) {
// 			res = (res + solve(curr + 1, i - 1, s)) % mod;
// 		}
// 	}
// 	return dp[curr][howManyLessLeft] = res;

// }

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	
	int n;
	cin >> n;
	if(n == 1) {
		cout << 1;
		return 0;
	}
	string s;
	cin >> s;
	long res = 0;
	memset(dp, 0, sizeof dp);
	for(int i = 0; i <= n - 1; ++i) {
		dp[n - 1][i] = i + 1;
	}
	for(int i = n - 2; i >= 0; --i) {		// curr
		for(int j = 0; j <= n - 1; ++j) {	// lessCount
			if(s[i] == '<') {
				// cerr << "j:" <<j<<endl;
				int howManyHighLeft = n - (i + 1 + j);
				// cerr << i <<" " <<j << ":" << howManyHighLeft << endl;
				if(howManyHighLeft > 0) {
					dp[i][j] = (dp[i + 1][j + howManyHighLeft - 1] - 
						(j - 1 >= 0 ? dp[i + 1][j - 1] : 0) + mod) % mod;
				}
				// cerr<<"new j:" << j << endl;
			}
			else {
				if(j == 0) continue;
				dp[i][j] = dp[i + 1][j - 1];
			}
		}
		for(int j = 1; j <= n - 1; ++j) {
			dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
		}
	}
	cout << dp[0][n - 1];

	return 0;
}

Measured memory_bytes: 73936
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n,a[100010];
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    sort(a,a+n);
    ll result = 0;
    ll now = 0;
    ll c = 0;
    for (int i = 0; i < n; i++) {
        if(now == a[i]){
            c++;
        }else{
            if(now < c){
                result += c-now;
            }else if(now > c){
                result += c;
            }
            c = 0;
            now = a[i];
            c++;
        }
    }
    if(now < c){
        result += c-now;
    }else if(now > c){
        result += c;
    }
    std::cout << result << std::endl;
}


Measured memory_bytes: 1024
import static java.lang.System.*;
import java.util.*;

public class Main {
	public static final int MOD = 1000000007;
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(in);

        int n = sc.nextInt();
		
		long[][][][] dp = new long[4][4][4][n-3+1];
		for(int i=0; i<4; i++) 
			for(int j=0; j<4; j++) 
				for(int k=0; k<4; k++) {
					Arrays.fill(dp[i][j][k], 0L);
					dp[i][j][k][0] = 1L;
				}
		dp[0][1][2][0] = 0L;
		dp[0][2][1][0] = 0L;
		dp[1][0][2][0] = 0L;
		
		for(int m=0; m<n-3; m++) 
			for(int i=0; i<4; i++) 
				for(int j=0; j<4; j++) 
					for(int k=0; k<4; k++)
						for(int l=0; l<4; l++) {
							dp[j][k][l][m+1] += dp[i][j][k][m];
							dp[j][k][l][m+1] %= MOD;
							
							dp[0][1][2][m+1] = 0L;
							dp[0][2][1][m+1] = 0L;
							dp[1][0][2][m+1] = 0L;
							if(i==0) {
								for(int o=0; o<4; o++) {
									dp[o][1][2][m+1] = 0L;
									dp[1][o][2][m+1] = 0L;
								}
							}
						}
		
		long sum = 0L;
		for(int i=0; i<4; i++) 
			for(int j=0; j<4; j++) 
				for(int k=0; k<4; k++) {
					sum += dp[i][j][k][n-3];
					sum %= MOD;
				}
		
		out.println(sum);
	}
}

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

using namespace std;

typedef long long LL;

struct Graph
{
	vector<int>e[200010];
	vector<LL>d[200010];
	void add(int u,int v,LL w)
	{
		e[u].push_back(v);
		d[u].push_back(w);
	}
	void add2(int u,int v,LL w)
	{
		add(u,v,w);
		add(v,u,w);
	}
}G1,G2,G3;
int S,T,N,M;
int p[200010];

const int MOD = 1000000007;
LL dis[200010];
LL f1[200010],f2[200010];
bool inq[200010];
const LL INF = 1e17;
bool cmp(int a,int b)
{
	return dis[a] < dis[b];
}
queue<int>q;

void upd(LL &x){
	if (x < 0) x += MOD;
	if (x >= MOD) x -= MOD;
}
int main()
{
	//freopen("E.in","r",stdin);
	scanf("%d%d",&N,&M);
	scanf("%d%d",&S,&T);
	for (int i=1;i<=M;i++)
	{
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		G1.add2(u,v,w);
	}
	q.push(S);
	for (int i=1;i<=N;i++)dis[i] = INF,inq[i] = false;
	inq[S] = true;
	dis[S] = 0;
	while(!q.empty())
	{
		int now = q.front();
		for (int i=0;i<G1.e[now].size();i++)
		if (dis[now] + G1.d[now][i] < dis[G1.e[now][i]])
		{
			dis[G1.e[now][i]] = dis[now] + G1.d[now][i];
			if (!inq[G1.e[now][i]])
			{
				q.push(G1.e[now][i]);
				inq[G1.e[now][i]] = true;
			}
		}
		inq[now] = false;
		q.pop();
	}
	//for (int i=1;i<=N;i++)printf("%d %lld\n",i,dis[i]);
	for (int i=1;i<=N;i++)
		for (int j=0;j<G1.e[i].size();j++)
			if (dis[i] + G1.d[i][j] == dis[G1.e[i][j]])
			{
				//printf("add %d %d %d\n",i,G1.e[i][j],G1.d[i][j]);
				G2.add(i,G1.e[i][j],G1.d[i][j]);
				G3.add(G1.e[i][j],i,G1.d[i][j]);
			}
	for (int i=1;i<=N;i++)p[i] = i;
	sort(p+1,p+N+1,cmp);
	assert(p[1] == S);
	memset(f1,0,sizeof(f1));
	memset(f2,0,sizeof(f2));
	f1[S] = 1;
	f2[T] = 1;
	
	for (int i=1;i<=N;i++)
	{
		int P = p[i];
		for (int j=0;j<G2.e[P].size();j++)
			upd(f1[G2.e[P][j]] += f1[P]);
	}
	for (int i=N;i>=1;i--)
	{
		int P = p[i];
		for (int j=0;j<G3.e[P].size();j++)
			upd(f2[G3.e[P][j]] += f2[P]);
	}
	
	//for (int i=1;i<=N;i++)printf("%d %d\n",f1[i],f2[i]);
	LL ans = 1LL * f1[T] * f1[T] % MOD;
	//printf("%d\n",ans);
	for (int i=1;i<=N;i++)
		if (dis[i] * 2LL == dis[T])
			upd(ans -= (1LL * f1[i] * f2[i] % MOD * f1[i] % MOD * f2[i] % MOD));
	for (int i=1;i<=N;i++)
	if (2LL * dis[i] < dis[T])
		for (int j=0;j<G2.e[i].size();j++)
		{
			int P = G2.e[i][j];
			if (2LL * dis[P] > dis[T])
			{
				upd(ans -= (1LL * f1[i] * f1[i] % MOD * f2[P] % MOD * f2[P] % MOD));
			}
		}
	ans %= MOD;
	if (ans < 0) ans += MOD;
	printf("%lld\n",ans);
}

Measured memory_bytes: 56960
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<math.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define N (1000000000+7)
#define INF (ll)1e16
typedef long long ll;

int main(void){
   int a;
   string s;
   cin>>a>>s;
   if(a>=3200)cout<<s<<endl;
   else cout<<"red"<<endl;
    return 0;
}

Measured memory_bytes: 256
//Suplex
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	if(a>b) printf("%d\n",a-1);else printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
     
     
public class Main {
	static int month[] = new int[]{31,29,31,30,31,30,31,31,30,31,30,31};
	static int day[]   = new int[13];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		boolean[][] bunny = new boolean[k][n];
		for(int i = 0; i < k; i++) {
			int m = sc.nextInt();
			for(int j = 0; j < m; j++) {
				bunny[i][sc.nextInt()-1] = true;
			}
		}
		int r = sc.nextInt();
		boolean[] check = new boolean[n];
		for(int i = 0; i < r; i++) {
			int p = sc.nextInt()-1;
			int q = sc.nextInt()-1;
			for(int j = 0; j < k; j++) {
				if(bunny[j][p] && bunny[j][q]) {
					check[p] = true;
					check[q] = true;
				}
			}
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			if(check[i]) count++;
		}
		System.out.println(count);
	}
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main() {
 int n,k;
 cin>>n>>k;
 double p[n];
 rep(i,n){
     cin>>p[i];
 }
 double cnt=0;
 rep(i,k){
cnt+=(p[i]+1)/2;
 }
 double ans=cnt;
for(int i=k;i<n;i++){
    cnt-=(p[i-k]+1)/2;
    cnt+=(p[i]+1)/2;
    ans=max(ans,cnt);
}
cout<<fixed<<setprecision(12)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
using namespace std;

int main(){
    string str;
    cin>>str;
    rep(i,3){
        if(str[i]==str[i+1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
}


Measured memory_bytes: 256
sx,sy,tx,ty = map(int,input().split())
a = tx-sx
b = ty-sy
r1 = "R"*a+"U"*b
r2 = "L"*a+"D"*b
r3 = "D"+"R"*(a+1)+"U"*(b+1)+"L"
r4 = "U"+"L"*(a+1)+"D"*(b+1)+"R"
print(r1+r2+r3+r4)

Measured memory_bytes: 3060
/*
                  友利奈緒の力でACしてくれ！！！！！！！！！！！！
                  Charlotteまだ見てない人は見ような！！！！！！！

                  ／　 /:／　　　　　　　　　　　 　 ＼:ヽ　＼
  　　　　　　　 /　　／　　　　　　 　 　 　 　 　 　 　 ＼　　ヽ
  　　　　　＼__L 彡　　　　　　　　　　　　　　　　　　　 ヽ　　',
  　　　　　　　ﾌ /　　　/　　/　 /　　　,　　 　 　 　 ヽ　　', 　ｊ
  　　　　　　　ﾚ　　　 /　　/ 　/　 　 　 　 　 　 　 　 ', 　ヽ　j
  　　　 　 　 // 　 　 !　/_l＿/__ノ 　　{ ＼}　　　　 　 ',　　',/
  　　　　　　i ﾊ 　 　 {　从j　ﾊ　i　　　 ',　 ト-､}　 i i　 }　　jj
  　　　　　　( ﾊ　　　(　 川　ハ ﾊ　 !　 '　ﾊ　 ﾊ　j j　,' 　 八
  　　　 ＜＿,ｨ∧　　　斗芹ﾃミxハ ﾊ　 ﾚ　} /__ﾚﾚ　/ 　 ∧ ＼　ﾉ
  　　　 　 　 ∨　＼ 　ゝ　辷:ソ　　 　)　芹ﾚ心ヾレ′　/ ト--　´
  　　　＼ｰ‐'　ﾉ　　 ＼ゝ　　　　　　 　 　 ゞ:_ソ "/ 　／ 　ヽ
  　　　　 　 フ　　　　i八 " "　　　,　　　　　　　ム彡　　　　＼
  　　　　 　/　　/　　j　 ト　　　　　　 　 　 " "イト＜　 　 　 ＼＼
  　　　　 /　　/　　　j　/／ヽ､ 　 ∩　　 　 イ　{ {　　￣ フフへ ＼＼
  　　　　(　／　　　 ,/ / 　　i　＞――＜ニニニﾆ┐　 〃／: : ヽ　ヽヽ
  　　　　／　　ィT´/ /┌―　￣￣ /::: , ,)　 　 　 〃／／: : : : : :}　ヽヽ)
  　　　/ /　 ∧ヾi┌― { {￣　　　 ﾉ:::トﾟ<　 　 　 ∥//: : : : : : : : i　 ﾉ ﾉ
  . 　　( 人　 {:ヽヾi∨　∧V　　　 /:::/　､ヽ　　　 ∥/: : : : : : : : : :}　/
  　　　V　( ∧: :＼'∨　∧V　　 ﾉ:::/　 ∧ 〉＿__∥: : : : : :／: : : :ﾚ
  　　 　 　 /∧: : : : ∨　∧V┬ｲ:::ﾉ　 〈 TT　|　|{{: : : : ／: : : : : ∧　　 ﾉ
  　　　 　 (　ハ: : : : :∨'T∧Vi　i (　 　 V　!　!　{{: : ／ : : : : : : /　ｰ　ノ
  　　　　　V　ハ: : : : :∨ﾍ∧V　i ゝゝ　 i／⌒＼{／ : : : : : : : /ｰ― ´
  　　　　　 ∨　ヽ: : : : :∨ﾍ∧∨i　〉 〉 /　/二　 ): : : : : : : : :/

          (https://seesaawiki.jp/asciiart/d/Charlotteより)
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) REP(i,n+1)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define RREPS(i,n) RREP(i,n+1)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define PERM(c) sort(ALL(c)); for(bool cp = true;cp;cp = next_permutation(ALL(c)))
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1E9+7;
int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1};
template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> istream& operator>>(istream &is,vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i){
    if(i==st.size()-1) os << st[i];
    else os << st[i] << " ";
  }
  return os;
}
template<class T> ostream& operator<<(ostream &os, const vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i){
    os << st[i];
    if(i!=st.size()-1) os << endl;
  }
  return os;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(n*a,b) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0; i<n; i++)

int pan1[5000];
int pan2[5000];
int pan3[5000];
int pan4[5000];

int main() {
  int N;
  cin >> N;
  rep (i, N) {
    cin >> pan1[i];
    pan2[i] = pan1[i];
    pan3[i] = pan1[i];
    pan4[i] = pan1[i];
  }

  int cnt1 = 0;
  for (int i=0; i<N-1; i++) {
    if (pan1[i] <= 0) continue;
    cnt1 += pan1[i]*2;
    pan1[i+1] -= pan1[i];
  }
  cnt1 += max(0, pan1[N-1]);

  int cnt2 = 1;
  pan2[0] -= 1;
  for (int i=0; i<N-1; i++) {
    if (pan2[i] <= 0) continue;
    cnt2 += pan2[i]*2;
    pan2[i+1] -= pan2[i];
  }
  cnt2 += max(0, pan2[N-1]);

  int cnt3 = 2;
  pan3[0] -= 2;
  for (int i=0; i<N-1; i++) {
    if (pan3[i] <= 0) continue;
    cnt3 += pan3[i]*2;
    pan3[i+1] -= pan3[i];
  }
  cnt3 += max(0, pan3[N-1]);

  int cnt4 = 3;
  pan4[0] -= 3;
  for (int i=0; i<N-1; i++) {
    if (pan4[i] <= 0) continue;
    cnt4 += pan4[i]*2;
    pan4[i+1] -= pan4[i];
  }
  cnt4 += max(0, pan4[N-1]);

  cout << min(cnt1, min(cnt2, min(cnt3, cnt4))) << endl;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
int n,m,cnt,ans=0, k[20],x[20][20][2],s[11][11],sw[20] = {0};
bool judge(){
    for(int i = 1; i <= n; i++){
        if(sw[i]){
            for(int j = 1; j <= k[i]; j++){
                if(sw[x[i][j][0]] != x[i][j][1])
                return 0;
            }
        }
    }
    return 1;
}
void dfs(int num){
    if(num > n){
        if(judge()){
            cnt = 0;
            for(int j = 1; j <= n; j++){
                if(sw[j])
                    cnt++;
            }
            ans = max(ans,cnt);
        } 
       return ; 
    }
    for(int j = 0; j <= 1; j++){
        sw[num] = j;
        dfs(num+1);
        sw[num] = 0;
    }    
}
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> k[i];
        for(int j = 1; j <= k[i]; j++){
            cin >> x[i][j][0] >> x[i][j][1];
        }
    }
    dfs(1); 
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            int M = in.nextInt();
            out.println(48 - M);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }
}

Measured memory_bytes: 21460
#include <iostream>
#include <algorithm>
#define rep(i, x) for(int i = 0; i < (x); i++)
typedef long long ll;
using namespace std;

const int inf = (int)1e8;

int N, M, R;
int r[10];
ll G[205][205];

int main(void) {
    cin >> N >> M >> R;
    rep(i, R) cin >> r[i], r[i]--;
    sort(r, r + R);

    rep(i, N) rep(j, N) G[i][j] = inf;
    rep(i, M) {
        int A, B, C;
        cin >> A >> B >> C;
        A -= 1; B -= 1;
        G[A][B] = C;
        G[B][A] = C;
    }

    rep(k, N) rep(i, N) rep(j, N) 
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);

    int ans = inf;
    do {
        int tmp = 0;
        rep(i, R - 1) tmp += G[r[i]][r[i + 1]]; 
        ans = min(ans, tmp);
    } while (next_permutation(r, r + R));

    cout << ans << endl;
}


Measured memory_bytes: 512
import java.io.*;

class Main
{
	public static void main(String args[])throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		for(;;)
		{
			int cnt = 0;
			String str_n = br.readLine();
			if(str_n == null) break;
			int n = Integer.parseInt(str_n);
			for(int a = 0; a <= 9; a++)
			for(int b = 0; b <= 9; b++)
			for(int c = 0; c <= 9; c++)
			for(int d = 0; d <= 9; d++)
			if(a+b+c+d == n)	cnt++;

			System.out.println(cnt);
		}
	}
}

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

string s, t;
int dp[4005][4005], ans;

int main() {
    while(cin >> s){
        cin >> t;
        int n = s.size(), m = t.size();
        for(int i=0;i<=n;i++) fill(dp[i], dp[i]+m+1, 0);
        ans = 0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(s[i]==t[j]){
                    dp[i+1][j+1] = dp[i][j]+1;
                    ans = max(ans, dp[i+1][j+1]);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



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

 
int main() {
    ll x,t;
    cin>>x>>t;
    ll ans=x-t;
    if(ans>=0)cout<<ans<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < n - k; i++) {
        cout << (a[i] < a[i + k] ? "Yes" : "No") << '\n';
    }

    return 0;
}

Measured memory_bytes: 3988
import java.util.Scanner;

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

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] A = new int[N];
      int max = 0;
      int maxIdx = -1;

      for (int i = 0; i < A.length; ++i) {
        A[i] = in.nextInt();

        if (A[i] > max) {
          max = A[i];
          maxIdx = i;
        }
      }

      int sndMax = 0;      
      int sndMaxIdx = -1;
      for (int i = 0; i < A.length; ++i) {
        if (A[i] > sndMax && i != maxIdx) {
          sndMax = A[i];
          sndMaxIdx = i;
        }
      }

      for (int i = 0; i < A.length; ++i) {
        if (i != maxIdx) {
          System.out.println(max);
        } else {
          System.out.println(sndMax);
        }
      }
    }
  }
}

Measured memory_bytes: 106716
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define deb(x) cerr<<#x<<x<<"\n"
#define nax (int)(1e5+2)
using namespace std;
int main(){
   int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
   int k;
   cin>>k;
   cout<<arr[k-1];
   
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
	    String[] input = Io.read();

	    int[] info = parse(input);

	    int ans = calc(info[0], info[1], info[2], info[3]);

	    Io.write(ans);
    }

    private static int[] parse(String[] inputStr) {
        int[] result = new int[inputStr.length];

        for (int i = 0; i < inputStr.length; i++) {
            result[i] = Integer.parseInt(inputStr[i]);
        }

        return result;
    }

    private static int calc(int n, int k, int x, int y) {
        int result = 0;

        if (n >= k) {
            result += k * x;
            result += (n - k) * y;
        } else {
            result += n * x;
        }


        return result;
    }
}

class Io {

    /**
     * 標準入力から1行ずつ受け取る
     * @return
     * @throws IOException
     */
    public static String[] read() throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List<String> inputs = new ArrayList<>();
        String line;
        while ((line = br.readLine()) != null) {
            if (line.equals(""))
                break;

            inputs.add(line);
        }
        br.close();
        return inputs.toArray(new String[0]);
    }

    /**
     * 標準出力
     * @param answer
     */
    public static void write(int answer)
    {
        System.out.println(answer);
    }
}

Measured memory_bytes: 23124
n, m = map(int, input().split())
s = []
c = []
for i in range(m):
  _s, _c = map(int, input().split())
  s.append(_s)
  c.append(_c)

st = [0, 0, 10, 100]
go = [10, 10, 100, 1000]
for i in range(st[n], go[n]):
  i_str = str(i)
  for j in range(m):
    if i_str[s[j]-1] != str(c[j]):
      break
  else:
    print(i)
    break
else:
  print(-1)

Measured memory_bytes: 3064
ni = lambda: int(input())
nl = lambda: list(map(int, input().split()))
nm = lambda: map(int, input().split())

h, w = nm()

coins = []
log = []

for i in range(h):
    a = nl()
    coins.append(a)


for i in range(h - 1):
    for j in range(w):
        if coins[i][j] % 2 == 1:
            coins[i + 1][j] += 1
            coins[i][j] -= 1
            log.append(((j + 1, i + 1), (j + 1, i + 2)))

for j in range(w - 1):
    if coins[h - 1][j] % 2 == 1:
        coins[h - 1][j + 1] += 1
        coins[h - 1][j] -= 1
        log.append(((j + 1, h), (j + 2, h)))

print(len(log))
for l in log:
    print(' '.join(map(str, [l[0][1], l[0][0], l[1][1], l[1][0]])))


Measured memory_bytes: 40120
#include <stdio.h>
#define NUM 1000001

int prime[NUM];

void eratosthenes(void) {
    int i, j;
    for(i = 2; i < NUM; i++ ) {
        for(j = 2; j * i < NUM; j++ ) {
            prime[i * j] = 1;
        }
    }
}

int main(void) {
    int i, count, n, ans;
    eratosthenes();
    while(scanf("%d",&n), n != 0 ) {
        count = 0;
        ans = 0;
        for(i = 2; count < n; i++ ) {
            if(!prime[i]) {
                ans += i;
                count++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 4504
n,C,*H=map(int,open(0).read().split());
dp=[0];
P=[0];
def f(I,h):
    return dp[I]+H[I]*(H[I]-2*h)
def c(x,y,z):
    return (H[y]-H[x])*(f(y,0)-f(z,0))>(H[z]-H[y])*(f(x,0)-f(y,0))
for i in range(1,n):
    while len(P)>1 and f(P[0],H[i])>f(P[1],H[i]):P.pop(0)
    dp+=[f(P[0],H[i])+H[i]**2+C]
    while len(P)>1 and c(P[-2],P[-1],i):P.pop()
    P+=[i]
print(dp[-1])

Measured memory_bytes: 27200
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  vi va;
  
  int a, b, c;
  cin >> a >> b >> c;
  
  int d = max(a,max(b, c));
  
  int x = 0;
  
  if ((3*d % 2) == ((a+b+c) % 2)) {
    x = d;
  } else {
    x = d+1;
  }
  
  cout << (3*x-(a+b+c))/2;
  
  return 0;
}

Measured memory_bytes: 3644
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		int q=sc.nextInt();
		StringBuilder front=new StringBuilder();
		StringBuilder back=new StringBuilder();
		StringBuilder ss=new StringBuilder(s);
		boolean ch=true;
		for(int i=0; i<q; i++){
			int t=sc.nextInt();
			if(t==1){
				ch=!ch;
			}else{
				int f=sc.nextInt();
				char c=sc.next().charAt(0);
				if(f==1){
					if(ch){
						front.append(c);
					}else{
						back.append(c);
						
					}
				}else{
					if(ch){
						
						back.append(c);
					}else{
						front.append(c);
					}
				}
			}
		}
		if(ch){
			front.reverse();
			System.out.println(front+ss.toString()+back);
		}else{
			back.reverse();
			ss.reverse();
			System.out.println(back+ss.toString()+front);
		}
		
	}
}


Measured memory_bytes: 120960
import itertools,math

def distance(x1,y1,x2,y2):
    d=((x1-x2)**2+(y1-y2)**2)**0.5
    return d

N=int(input().strip())
x=[0]*N
y=[0]*N

for i in range(N):
    x[i],y[i]=list(map(int,input().strip().split()))

lst=list(range(N))
dist=0
for v in itertools.permutations(lst):
    for i in range(N-1):
        dist+=distance(x[v[i]],y[v[i]],x[v[i+1]],y[v[i+1]])
print(dist/math.factorial(N))   

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

const int N = 1e5 + 100;
int p[N];
bool used[N];

void make_pair(int i) {
    p[i] = i;
}

int find_id(int a) {
    if (p[a] == a)
        return a;
    return p[a] = find_id(p[a]);
}

void union_pair(int a, int b) {
    a = find_id(a);
    b = find_id(b);
    if (a == b)
        return;
    p[b] = a;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    used[0] = 1;
    for (int i = 0; i < N; ++i)
        make_pair(i);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > f;
    for (int i = 0; i < n; ++i) {
        int t, cost;
        cin >> t >> cost;
        t = m - t + 1;
        if (t < 0)
            continue;
        f.push_back({cost, t});
    }
    sort(f.begin(), f.end());
    reverse(f.begin(), f.end());
    long long ans = 0;
    for (auto x : f) {
        int tmp = find_id(x.second);
        while(tmp != 0 && used[tmp]) {
            union_pair(tmp - 1, tmp);
            tmp = find_id(tmp);
        }
        if (!used[tmp]) {
            ans += x.first;
            union_pair(tmp - 1, tmp);
            used[tmp] = 1;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1784