akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
#define debug(V) rep(i, V.size()) cout << V[i] << " ";
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*988244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v;
string S, T;
vl A, B;
map<ll, ll> M;
void input() {
    cin >> x >> n;
    rep(i, n) {
        cin >> a;
        M[a] = 1;
    }
}
void solve() {
    a = 0;
    while(1) {
        if(M[x - a] == 0) {
            cout << x - a << endl;
            return;
        }
        if(M[x + a] == 0) {
            cout << x + a << endl;
            return;
        }
        a++;
    }
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    solve();
}

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

using namespace std;

typedef long long ll;

int main(){
	int n, m;
	cin >> n >> m;
	int x[m];
	for(int i = 0; i < m; i++)cin >> x[i];
	sort(x, x+m);
	ll xx[m-1];
	for(int i = 0; i < m-1; i++)xx[i] = x[i+1]-x[i];
	sort(xx, xx+m-1);
	if(m <= n)cout << 0 << endl;
	else{
		ll ans = 0;
		for(int i = 0; i < m-n; i++)ans += xx[i];
		cout << ans << endl;
	}
    return 0;
}

Measured memory_bytes: 1408
sx, sy, tx, ty = map(int, input().split())
ans = []

for i in range(ty-sy):
    ans.append("U")
for i in range(tx-sx):
    ans.append("R")
for i in range(abs(sy-ty)):
    ans.append("D")
for i in range(abs(sx-tx)):
    ans.append("L")

ans.append("L")
for i in range(ty-sy+1):
    ans.append("U")
for i in range(tx-sx+1):
    ans.append("R")
ans.append("D")
ans.append("R")
for i in range(abs(sy-ty)+1):
    ans.append("D")
for i in range(abs(sx-tx)+1):
    ans.append("L")
ans.append("U")
print(*ans, sep='')




Measured memory_bytes: 9280
#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define MOD 1000000007

string s;
int dp[N][15];
int num;
void Add(int &x,int y)
{
	x+=y;
	if(x>=MOD) x-=MOD;
}

int main()
{
	
	cin>>s;
	for(int i=0;i<s.size();i++)
		num=(num*10+((s[i]=='?')?'0':s[i])-'0')%13;
	if(s[0]!='?') dp[0][0]=1;
	else for(int i=0;i<=9;i++)
			dp[0][i]=1;
	for(int i=1;i<s.size();i++)
	for(int k=0;k<=12;k++)
		if(s[i]!='?') Add(dp[i][k*10%13],dp[i-1][k]);
		else for(int j=0;j<=9;j++)
			 	Add(dp[i][(k*10+j)%13],dp[i-1][k]);
	cout<<dp[s.size()-1][(13-num+5)%13]<<'\n';
	
	return 0;
}

Measured memory_bytes: 6272
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
#define MOD  1000000007


int main(int argc, char const *argv[]) {
  int A1,A2,A3;
  std::cin >> A1 >> A2 >> A3;
  int ans = max ({ A1 , A2 , A3 }) - min ({ A1 , A2 , A3 });
  std::cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
  }
  vector<int> B(N);
  rep(i, N) {
    cin >> B[i];
  }

  int Asum = 0, Bsum = 0;
  rep(i, N) {
    Asum += A[i];
    Bsum += B[i];
  }

  int surplus = Asum - Bsum;
  if (surplus < 0) {
    cout << -1 << '\n';
    return 0;
  }

  vector<int> D(N);
  rep(i, N) {
    D[i] = A[i] - B[i];
  }

  sort(all(D));
  auto iter = lower_bound(all(D), 0);
  int ind = distance(D.begin(), iter);

  int ans = N;
  while (true) {
    if (ind < N && D[ind] <= surplus) {
      ans--;
      surplus -= D[ind++];
    } else {
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

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

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,k;cin>>n>>k;
    vector<ll>x(n);
    int yy=0;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    ll ans=INF;
    for(int i=0;i<n-k+1;i++){//i也会被包含所以最后一段是x[n-k]~x[n-1]
        chmin(ans,abs(x[i])+abs(x[i+k-1]-x[i]));
        chmin(ans,abs(x[i+k-1])+abs(x[i+k-1]-x[i]));
    }
    
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <istream>
#include <set>
#include <queue>
#define rep0(i,n) for (long long int i = 0; i <= (n); ++i)
#define rep1(i,n) for (long long int i = 1; i <= (n); ++i)
#define REP(a,b) for (long long int i = a; i <= (b); ++i) 
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	set<char>a;
	map<char, int>b;
	int count = 0;
	string s;
		cin >> s;
	rep0(i, 3) {
		b[s[i]]++;
		a.insert(s[i]);
	}
	if (a.size() == 2) {
		for (auto& j : b) {
			if (j.second == 2) {
				++count;
			}
		}
		cout << ((count == 2) ? "Yes" : "No") << endl;
	}
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * @author varun on 7/1/2018
 * @project CompetitiveProgramming
 */
public class Main {
    private static long GCD(long a, long b) { return b==0 ? a : GCD(b, a%b); }
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        long N = scanner.nextInt();
        System.out.println(((N*(long)2)/GCD(N,(long)2)));
    }
}


Measured memory_bytes: 23892
using System;
using System.Linq;

class E
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int n = h[0], k = h[1];
		Console.WriteLine(Totients(k).Select((x, i) => i == 0 ? 0 : x * ((MInt)(k / i)).Pow(n)).Aggregate((x, y) => x + y));
	}

	static int[] Totients(int n)
	{
		var b = new bool[n + 1];
		for (int p = 2; p * p <= n; ++p) if (!b[p]) for (int x = p * p; x <= n; x += p) b[x] = true;
		var r = new int[n + 1];
		for (int x = 1; x <= n; ++x) r[x] = x;
		for (int p = 2; p <= n; ++p) if (!b[p]) for (int x = p; x <= n; x += p) r[x] = r[x] / p * (p - 1);
		return r;
	}
}

struct MInt
{
	const int M = 1000000007;
	public long V;
	public MInt(long v) { V = (v %= M) < 0 ? v + M : v; }

	public static implicit operator MInt(long v) => new MInt(v);
	public static MInt operator +(MInt x, MInt y) => x.V + y.V;
	public static MInt operator *(MInt x, MInt y) => x.V * y.V;

	public MInt Pow(int i) => MPow(V, i);
	public override string ToString() => $"{V}";

	static long MPow(long b, int i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}
}


Measured memory_bytes: 28720
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
int main(){
    cin>>N;
    cout<<(N/500)*1000+((N%500)/5)*5;

    return 0;
}

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

int main(){


    int a;
    int i,j,k;
    int counter = 0;
    cin >> a;
    int box[a];

    for(i = 0;i < a;i++) {cin >> box[i];}
    if(a<3){cout << 0; return 0;}

    for(i=0;i<a-2;i++)
        for(j=i+1;j<a;j++)
            for(k=j+1;k<a;k++)
            {
                if((box[i] != box[j]) && (box[i] != box[k]) && (box[j] != box[k]) && (box[i]+box[j]>box[k]) && (box[i]+box[k]>box[j])&& (box[k]+box[j]>box[i]) ){counter = counter + 1; }
            }

    cout << counter << endl;


    

}

Measured memory_bytes: 3148
N,M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
D = []
if N < M:
  for i in range(M-1):
    D.append(abs(X[i+1]-X[i]))
  D.sort(reverse = True)
  for k in range(N-1):
    D[k] = 0
  print(sum(D))
else:
  print(0)

Measured memory_bytes: 13968
/**
class cfmaster {
 public:
  struct code {
  	see the details down there !
  };
};
**/
#include <bits/stdc++.h>

using namespace std;

const int inf =  (int) 1e9 + 10;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) {
  	cin >> a[i] >> b[i] >> c[i];
	}
	vector<vector<int>> dp(n, vector<int>(3));
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for (int i = 1; i < n; i++) {
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
		dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
	}
	cout << *max_element(dp[n - 1].begin(), dp[n - 1].end()) << '\n';
  return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    string s;
    map<char, ll> S;
    for (int i = 0; i < N; i++) {
        cin >> s;
        if (s.at(0) == 'M') {
            if (!S.count('M')) S['M'] = 1;
            else S['M']++;
        }
        else if (s.at(0) == 'A') {
            if (!S.count('A')) S['A'] = 1;
            else S['A']++;
        }
        else if (s.at(0) == 'R') {
            if (!S.count('R')) S['R'] = 1;
            else S['R']++;
        }
        else if (s.at(0) == 'C') {
            if (!S.count('C')) S['C'] = 1;
            else S['C']++;
        }
        else if (s.at(0) == 'H') {
            if (!S.count('H')) S['H'] = 1;
            else S['H']++;
        }
    }
    ll m = S['M'], a = S['A'], r = S['R'], c = S['C'], h = S['H'];
    ll ans = m * (a * (r + c + h) + r * (c + h) + c * h) + a * (r * (c + h) + c * h) + r * c * h;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3576
a,b,c = gets.split.map {|s| s.to_f}
include Math
r = c * PI / 180.0
h = b * sin(r)
s = a * h / 2.0
c = (a*a + b*b - 2*a*b*cos(r))**0.5
printf("%.8f\n", s)
printf("%.8f\n", a+b+c)
printf("%.8f\n", h)

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

using namespace std;
const int maxn=1e5+5;
char a[maxn];
int main()
{
    while(~scanf("%s", a))
    {
        int len=strlen(a);
        if(len&1)
        {
            if(a[0]==a[len-1])printf("Second\n");
            else printf("First\n");
        }
        else
        {
            if(a[0]==a[len-1])printf("First\n");
            else printf("Second\n");
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
using namespace std;



int main(void)
{
    int c[3][3];
    
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            cin >> c[i][j];
        }
    }

   if((c[1][1] + c[0][0] == c[0][1] + c[1][0]) and
      (c[1][2] + c[0][0] == c[1][0] + c[0][2]) and
      (c[2][1] + c[0][0] == c[2][0] + c[0][1]) and 
      (c[2][2] + c[0][0] == c[2][0] + c[0][2]))
    {
        cout << "Yes" << endl;
        return 0;
    }
   
   cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n, m;
	P[] cs;
	int[] rs;
	P t, s;

	void run(){
		for(;;){
			n=sc.nextInt();
			if(n==0){
				break;
			}
			cs=new P[n];
			rs=new int[n];
			for(int i=0; i<n; i++){
				int x=sc.nextInt();
				int y=sc.nextInt();
				rs[i]=sc.nextInt();
				cs[i]=new P(x, y);
			}
			m=sc.nextInt();
			for(int i=0; i<m; i++){
				int tx=sc.nextInt();
				int ty=sc.nextInt();
				int sx=sc.nextInt();
				int sy=sc.nextInt();
				t=new P(tx, ty);
				s=new P(sx, sy);
				solve();
			}
		}
	}

	void solve(){
		boolean f=false;
		for(int i=0; i<n; i++){
			P[] ps=isCL(cs[i], rs[i], t, s);
			for(P p : ps){
				if(between(t.x, s.x, p.x)&&between(t.y, s.y, p.y)){
					f=true;
				}
			}
		}
		println(f?"Safe":"Danger");
	}

	boolean between(double x1, double x2, double x){
		return (x1<x+EPS&&x<x2+EPS)||(x1+EPS>x&&x+EPS>x2);
	}

	// ¼üÆ~Ìð_(p1 Éß¢)
	P[] isCL(P c, double r, P p1, P p2){
		double x=p1.sub(c).dot(p2.sub(p1));
		double y=p2.sub(p1).abs2();
		double d=x*x-y*(p1.sub(c).abs2()-r*r);
		if(d<-EPS)
			return new P[0];
		if(d<0)
			d=0;
		P q1=p1.sub(p2.sub(p1).mul(x/y));
		P q2=p2.sub(p1).mul(sqrt(d)/y);
		return new P[]{q1.sub(q2), q1.add(q2)};
	}

	class P{
		double x, y;

		P(){
			this(0, 0);
		}

		P(double x, double y){
			this.x=x;
			this.y=y;
		}

		P add(P p){
			return new P(x+p.x, y+p.y);
		}

		P sub(P p){
			return new P(x-p.x, y-p.y);
		}

		P mul(double m){
			return new P(x*m, y*m);
		}

		P div(double d){
			return new P(x/d, y/d);
		}

		double abs(){
			return Math.sqrt(abs2());
		}

		double abs2(){
			return x*x+y*y;
		}

		double arg(){
			return Math.atan2(y, x);
		}

		// inner product
		double dot(P p){
			return x*p.x+y*p.y;
		}

		// outer product
		double det(P p){
			return x*p.y-y*p.x;
		}

		P rot90(){
			return new P(-y, x);
		}

		// conjugation
		P conj(){
			return new P(x, -y);
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
N, K = map(int, input().split())
Aall = set(list(range(1, N+1)))
A = []
for i in range(N*2):
  try: 
    if i % 2 != 0:
      a = list(map(int, input().split()))
      A.extend(a)
    else:
      d = list(map(int, input().split()))
  except EOFError:
    d = 1
print(len(Aall-set(A)))

Measured memory_bytes: 9156
n, m = map(int, input().split())
A = sorted([[int(i) for i in input().split()] for i in range(m)], key = lambda x: x[1])

cnt = 0
posi = 0
for s, g in A:
    if s >= posi:
        posi = g
        cnt += 1
        
print(cnt)

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

int main()
{
  string s;
  cin >> s;
  
  rep(i, s.length())
  {
    if (0 == i % 2)
    { 
      cout << s[i];
    }
  }
    
  return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main { //クラス名はMain
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        int x1 = Integer.parseInt(s1);
        int x2 = Integer.parseInt(s2);
        System.out.printf("%d %d\n", x1 * x2, (x1 + x2) * 2);
    }
}


Measured memory_bytes: 26232
#include "bits/stdc++.h"
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;

void gen() {exit(0);}
int main() {
    #ifdef DEBUG
//    freopen("input", "r", stdin);
//    freopen("output", "w", stdout);
//    gen();
    #endif
    int d, n;
    scanf("%d %d", &d, &n);
    
    int ans = 0;
    int size = (int)pow(100, d);
    for (int i = 0; i < n; i++) {
        ans += size;
        int count = 0;
        int cur = ans;
        while (cur >= 100) {
            count++;
            cur /= 100;
        }
        if (count > d) ans += size;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
def dist(x1, y1, x2, y2)
  Math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
end

n = gets.chomp.to_i
n.times do
  xa, ya, ra, xb, yb, rb = gets.chomp.split.map(&:to_f)
  d = dist(xa, ya, xb, yb)
  if d > ra + rb
    puts 0
  elsif d < (ra - rb).abs
    puts (ra > rb) ? 2 : -2
  else 
    puts 1
  end
end

Measured memory_bytes: 8760
// thanks to https://www.hamayanhamayan.com/entry/2020/01/18/233933
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;
  vector<vl> ab(n, vl(2));
  rep(i, n) {
    cin >> ab[i][0];
  }
  rep(i, n) {
    cin >> ab[i][1];
  }

  constexpr ll maxi = 51;
  constexpr ll inf = 1LL<<60;
  vector<vl> dp(1LL << n, vl(maxi, inf));

  dp[0][0] = 0;
  rep(mask, 1LL<<n) {
    rep(i, maxi) {
      //if (dp[mask][i] == inf) continue;

      ll done = 0;
      rep(j, n) {
        if (mask >> j & 1) done++;
      }

      rep(j, n) {
        if (mask >> j & 1) continue;

        ll parity = abs(j-done)%2;
        if (i > ab[j][parity]) continue;

        ll inversion = 0;
        rep(k, j) {
          if (!(mask & (1LL << k))) inversion++;
        }

        cmin(dp[mask | (1<<j)][ab[j][parity]], dp[mask][i] + inversion);
      }
    }
  }

  ll ans = inf;
  rep(i, maxi) {
    cmin(ans, dp[(1LL<<n)-1][i]);
  }

  if (ans == inf) cout << -1 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 114944
import sys
S = input()[::-1]
t = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
while len(S) > 0:
    if S[:5] == t[0]:
        S = S[5:]
    elif S[:7] == t[1]:
        S = S[7:]
    elif S[:5] == t[2]:
        S = S[5:]
    elif S[:6] == t[3]:
        S = S[6:]
    else:
        print('NO')
        sys.exit()
print('YES')

Measured memory_bytes: 3188
import fractions
A, B, C, D = map(int,input().split())
X = (A-1)//C + (A-1)//D - (A-1)//(C*D//(fractions.gcd(C,D)))
Y = B//C + B//D - B//(C*D//(fractions.gcd(C,D)))
print(B-(A-1)-(Y-X))

Measured memory_bytes: 5688
MOD = 10 ** 9 + 7

s = str(input())

s = list(s)

cur = [0] * 13

if s[0] != "?":
    cur[int(s[0])] = 1
else:
    for j in range(10):
        cur[j] = 1

for i in range(1,len(s)):
    pre = cur[:]
    cur = [0] * 13
    if s[i] != "?":
        for j in range(13):
            q = (j * 10 + int(s[i])) % 13
            cur[q] += pre[j] % MOD
    else:
        for j in range(13):
            for k in range(10):
                p = (j * 10 + k) % 13
                cur[p] += pre[j] % MOD

print(cur[5] % MOD)


Measured memory_bytes: 49776
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    A = sorted(enumerate(A), reverse=True, key=lambda x: x[1])

    dp = [[0 for i in range(N + 1)] for j in range(N + 1)]
    for i in range(N):
        for j in range(0, N - i):
            idx, a = A[i + j]
            #idx = indices[i + j]
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a * abs(idx - i))
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + a * abs(N - 1 - j - idx))
    result = -1
    for i in range(N):
        tmp = dp[i][N - i]
        if tmp > result:
            result = tmp
    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 137112
#include <bits/stdc++.h>
#define  ref(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
typedef long long ll;

using namespace std;
ll n,ans=1;

int main()
{
    cin>>n;
    ref(i,n){
        ll a;
        cin>>a;
        if(ans==-1&&a!=0) continue;
        if(a==0||ans==0) {ans=0; continue;}
        if(a>=(pow(10,18)/ans+1)) ans=-1;
        else {
            ans*=a;
            if(ans>INF) ans=-1;
        }
    }
    cout<<ans;
    return 0;
    }



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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 998244353ll;
const ll MAXN = (ll) 3e5 + 100;
const ll INF = (ll) 9223372036854775;
const ld EPS = (ld) 1e-8;

vector<ll> a, b, ans;

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n;
	cin >> n;
	ll v;
	for(int i = 0; i< n;i++){
		cin >> v;
		a.pb(v);
	}
	while(a.size()){
		b.clear();
		ll ind = -1;
		for(int i = 0; i < a.size();i++){
			if(a[i] == i + 1){
				ind = i;
			}
		}
		if(ind == -1) return cout << -1, 0;
		for(int i = 0; i < a.size(); i++){
			if(ind == i) continue;
			b.pb(a[i]);
		}
		ans.pb(ind + 1);
		a.clear();
		for(auto x : b) a.pb(x);
	}
	reverse(all(ans));
	for(auto x : ans) cout << x << '\n';
	return 0;
}


/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/




Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let n = get!(usize);
    let v = get!([i64];n);
    let mut dp = vec![vec![0; 3]; n + 10];
    dp[0][0] = v[0][0];
    dp[0][1] = v[0][1];
    dp[0][2] = v[0][2];
    for j in 1..n {
        for i in 0..3 {
            if i == 0 {
                let mut score = 0;
                score = std::cmp::max(score, dp[j - 1][1] + v[j][i]);
                score = std::cmp::max(score, dp[j - 1][2] + v[j][i]);
                //eprintln!("i == 0, score: {}", score);
                dp[j][i] += score;
            } else if i == 1 {
                let mut score = 0;
                score = std::cmp::max(score, dp[j - 1][0] + v[j][i]);
                score = std::cmp::max(score, dp[j - 1][2] + v[j][i]);
                //eprintln!("i == 1, score: {}", score);
                dp[j][i] += score;
            } else if i == 2 {
                let mut score = 0;
                score = std::cmp::max(score, dp[j - 1][1] + v[j][i]);
                score = std::cmp::max(score, dp[j - 1][0] + v[j][i]);
                //eprintln!("i == 2, score: {}", score);
                //eprintln!(
                //    "dp[j - 1][0]: {}, dp[j - 1][1]: {},  v[j][i]: {}",
                //    dp[j - 1][0],
                //    dp[j - 1][1],
                //    v[j][i]
                //);
                dp[j][i] += score;
            }
        }
    }
    let mut ans = std::cmp::max(dp[n - 1][0], dp[n - 1][1]);
    ans = std::cmp::max(ans, dp[n - 1][2]);
    println!("{}", ans);
}


Measured memory_bytes: 18684
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<string> svec(3);
  svec[0] = "Sunny";
  svec[1] = "Cloudy";
  svec[2] = "Rainy";
  
  string str;
  cin >> str;
  for(int i=0; i<3; ++i){
    if(str==svec[i]){
      cout << svec[(i+1)%3] << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500*500)

def dfs(pos, not_pos, tree_dict, ans_li, length):
  n_li = tree_dict[pos]
  for n, w in n_li:
    if n == not_pos:
      continue
    new_length = length+w
    if new_length%2 == 0:
      ans_li[n] = 0
    else:
      ans_li[n] = 1
    ans = dfs(n, pos, tree_dict, ans_li, new_length)
  return ans_li

def run():
  N = int(input())
  tree_dict = {}
  ans_li = [0]*(N+1)
  for n in range(N-1):
    u, v, w = map(int, input().split())
    tree_dict.setdefault(u, []).append((v, w))
    tree_dict.setdefault(v, []).append((u, w))
  length = 0
  ans = dfs(1, -1, tree_dict, ans_li, length)
  for a in ans[1:]:
    print(a)
    

if __name__ == '__main__':
  run()

Measured memory_bytes: 89076
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

N = ri()
D = factorization(N)
L = []
tmp = 0
for i in range(1, 41):
    tmp += i
    L.append(tmp)
ans = 0
for d in D:
    if d[0] == 1:
        continue
    ans += bisect_right(L, d[1])
print(ans)

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

int main(void){
    int x, a, b;
    cin >> x >> a >> b;
    if(a >= b){
        cout << "delicious\n";
    }else if(x >= (b-a)){
        cout << "safe\n";
    }else{
        cout << "dangerous\n";
    }
}

Measured memory_bytes: 256
from functools import reduce

n, m = map(int, input().split())
mod = 10 ** 9 + 7

if abs(n - m) >= 2:
    print(0)
elif abs(n - m) == 1:
    a = reduce(lambda x, y: (x * y) % mod, range(1, n + 1))
    b = reduce(lambda x, y: (x * y) % mod, range(1, m + 1))
    ans = (a * b) % mod
    print(ans)
elif n == m:
    c = reduce(lambda x, y: (x * y) % mod, range(1, n + 1))
    ans = (c*c * 2) % mod
    print(ans)


Measured memory_bytes: 3572
#include <set>
#include <iostream>
#define ll long long int
using namespace std;

int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = k;
    for(int i=1; i<n; i++){
        ans *= k-1;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

// With path compression and weights

public class Main {
	static int[] parent;
	static int[] weights;
	
	static void set(int x) {
		parent[x] = x;
		weights[x] = 1;
	}
	
	static void union(int x, int y) {
	    int a = find(x);
	    int b = find(y);
	    if(a != b) {
	    	if(weights[a] > weights[b]) {
	    		parent[b] = a;
	    		weights[a] += weights[b];
	    	} else {
	    		parent[a] = b;
	    		weights[b] += weights[a];
	    	}
	    }
	    	
	}
	
	static int find(int x) {
		 int curr = x;
		 if(parent[curr] == curr) return curr;
		 parent[curr] = find(parent[curr]);
		
		 return parent[curr];
		 // path compression
	}
	
	static boolean checkConnection(int x, int y) {
		return find(x) == find(y);
	}
	
	public static void main(String[] args) {
		
		//Set up Scanner
		Scanner in = new Scanner(System.in);
		
		//set up users
		int users = in.nextInt();
		
		// set up parent and weights
		parent = new int[users];
		weights = new int[users];
		int relations = in.nextInt();
		
		// set up parent
		parent = new int[users];
		
		//fill parent with reference to itself
		for(int i = 0; i < users; i++) {
			set(i);
		}
		
		//update unions in parent
		for(int i = 0; i < relations; i++) {
			union(in.nextInt(), in.nextInt());
		}
		
		int queries = in.nextInt();
		
		for (int i = 0; i < queries; i++) {
			int a = in.nextInt();
			int b = in.nextInt();
			if (checkConnection(a, b)) {
				System.out.println("yes");
			} else { 
				System.out.println("no");
			}
		}

		
		//close scanner
		in.close();

	}
}



Measured memory_bytes: 70212
using System;

namespace ITP1_1_B
{
    class Program
    {
        static void Main(string[] args)
        {
            //1つの整数xを読み込んで、xの3乗を計算し結果を出力する

            int i = int.Parse(Console.ReadLine());      //コンソール画面に入力された文字を読み込み、int型に変換
                                                        //→int型変数のiに格納

            int x = i * i * i;                          //一つの整数を読み込んで3乗する

            Console.WriteLine(x);
        }
    }
}



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

using namespace std;

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

typedef long long ll;

void solve(){
	int h, w, k;
	cin >> h >> w >> k;
	char s[h][w];
	for(auto i = 0; i < h; ++i) {
		for(auto j = 0; j < w; ++j) {
			cin >> s[i][j];
		}
	}
	int cnt = 0;
	for(auto i = 0; i < (1 << h); ++i) {
		for(auto j = 0; j < (1 << w); ++j) {
			int black = 0;
			for(auto k = 0; k < h; ++k) {
				for(auto l = 0; l < w; ++l) {
					if(((i >> k) & 1) == 0 && ((j >> l) & 1) == 0 
						&& s[k][l] == '#') ++black;
				}
			}
			if(black == k) ++cnt;
		}
	}
	cout << cnt << '\n';
}

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


Measured memory_bytes: 3588
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
int N, M;
int main() {
	cin >> N;
	if (N < 1000)
		cout << "ABC" << endl;
	else {
		cout << "ABD" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
a1=[int(i) for i in input().split()]
a2=[int(i) for i in input().split()]
a3=[int(i) for i in input().split()]
for l in sys.stdin:
  if int(l) in a1:
    a1[a1.index(int(l))]=0
  elif int(l) in a2:
    a2[a2.index(int(l))]=0
  elif int(l) in a3:
    a3[a3.index(int(l))]=0
m=sum(a1)*sum(a2)*sum(a3)
for i in range(3):
  m*=a1[i]+a2[i]+a3[i]
  m*=a1[i]+a2[1]+a3[2-i]
print('Yes' if m==0 else 'No')

Measured memory_bytes: 3064
from collections import defaultdict
N, M = map(int, input().split())
P = []
S = []
for i in range(M):
  p, s = input().split()
  P.append(int(p))
  S.append(s)
d = defaultdict(int)
d1 = defaultdict(int)
for i in range(M):
  if S[i] == "WA":
    if d[P[i]] != 1:
      d1[P[i]] += 1
  elif S[i] == "AC":
    d[P[i]] = 1
for i in range(M):
  if d[P[i]] == 0 and d1[P[i]] > 0:
    d1[P[i]] = 0
print(sum(d.values()), sum(d1.values()))

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

bool wareru(int v, int c){
    if (v / c >= 1 && v % c == 0){
        return true;
    }
    return false;
}

int gcd(int a, int b, int c){
    int m = min({a,b,c});
    for (int i = m; i >= 2; i--){
        if (wareru(a,i) && wareru(b,i) && wareru(c,i)){
            return i;
        }
	}
	return 1;
}

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

	int k;
	cin >> k;
	int r = 0;
	for (int i = 1; i <= k; i++){
	    for (int j = 1; j <= k; j++){
	        for (int l = 1; l <= k; l++){
	            r += gcd(i,j,l);
	        }
	    }
	}
	cout << r << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int l[200010] = {}, r[200010] = {};
bool L[200010] = {}, R[200010] = {};
int main() {
	int n, k, c; cin >> n >> k >> c;
	string s; cin >> s;
	for(int i = 0; i < n;) {
		if(i - 1 >= 0) l[i] = l[i - 1];
		if(s[i] == 'o') {
			L[i] = true;
			++l[i];
			if(c == 0) {
				++i;
				continue;
			}
			int d = 1;
			while(i + d < n and d <= c) {
				l[i + d] = l[i];
				++d;
			}
			i = (i + d);
		} else {
			++i;
		}
	}
	for(int i = n - 1; i >= 0;) {
		if(i + 1 < n) r[i] = r[i + 1];
		if(s[i] == 'o') {
			R[i] = true;
			++r[i];
			if(c == 0) {
				--i;
				continue;
			}
			int d = 1;
			while(i - d >= 0 and d <= c) {
				r[i - d] = r[i];
				++d;
			}
			i = (i - d);
		} else {
			--i;
		}
	}
	for(int i = 0; i < n; ++i) {
		if(L[i]) l[i]--;
		if(R[i]) r[i]--;
		if(l[i] + r[i] == k - 1) {
			cout << i + 1 << '\n';
		}
	}
	return 0;
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 55;
struct node {
    int v, a, b;
};
vector<node> G[N];
int c[N], d[N];
ll f[N][N * N];

int main() {
    int n, m, s;
    scanf("%d%d%d", &n, &m, &s), s = min(s, 2500);
    for (int i = 1; i <= m; i++) {
        int u, v, a, b;
        scanf("%d%d%d%d", &u, &v, &a, &b);
        G[u].push_back({v, a, b});
        G[v].push_back({u, a, b});
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &c[i], &d[i]);
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N * N; j++) {
            f[i][j] = 1e18;
        }
    }
    f[1][s] = 0;
    typedef tuple<ll, int, int> T;
    priority_queue<T, vector<T>, greater<T> > qu;
    qu.push(T(0, 1, s));
    while (!qu.empty()) {
        ll t = get<0>(qu.top());
        int u = get<1>(qu.top()), w = get<2>(qu.top());
        qu.pop();
//        if (f[u][w] > t)continue;
        for (int i = 0; i < G[u].size(); i++) {
            int v = G[u][i].v, a = G[u][i].a, b = G[u][i].b;
            if (w >= a && f[v][w - a] > t + b) {
                f[v][w - a] = t + b;
                qu.push(T(t + b, v, w - a));
            }
        }
        if (f[u][min(w + c[u], 2500)] > t + d[u]) {
            f[u][min(w + c[u], 2500)] = t + d[u];
            qu.push(T(t + d[u], u, min(w + c[u], 2500)));
        }
    }
    for (int i = 2; i <= n; i++) {
        ll ans = 1e18;
        for (int j = 0; j <= 2500; j++) {
            ans = min(ans, f[i][j]);
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 6672
#include<bits/stdc++.h>
#define SZ(x) x.size()
#define pii pair<int,int>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
int x[105];
int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d", x + i);
    int ans = INF;
    for(int p = 1; p <= 100; p++) {
        int tmp = 0;
        for(int i = 0; i < n; i++)
            tmp += (x[i] - p) * (x[i] - p);
        ans = min(ans, tmp);
    }
    printf("%d", ans);
}


Measured memory_bytes: 256
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)] 
w1=0
h1=0
w2=w
h2=h

for i in a:
    if i[2]==1:
        w1=max(w1,i[0])
    elif i[2]==2:
        w2=min(w2,i[0])
    elif i[2]==3:
        h1=max(h1,i[1])
    elif i[2]==4:
        h2=min(h2,i[1])
if min((w2-w1),(h2-h1))<=0:
    print(0)
else:
    print((w2-w1)*(h2-h1))
   


Measured memory_bytes: 3064
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int cnt = 0;
    boolean tf;

    void run(){
	while(sc.hasNext()){
	    String a = sc.next();
	    if(a.length()==1){
		cnt++;
		continue;
	    }
	    tf = true;
	    solve(a);
	    if(tf){
		cnt++;
		//System.out.println(a);
	    }
	}
	System.out.println(cnt);
    }

    void solve(String a){
	String[] s = new String[a.length()];
	int i;
	for(i=0; i<a.length(); i++)
	    s[i] = a.substring(i, i+1);
	i=0;
	while(i<s.length/2){
	    if(!s[i].equals(s[a.length()-i-1])){
		tf = false;
	    }
	    i++;
	}
    }
}

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

signed main() {
	int h, w;
	cin >> h >> w;
	vector<pair<int, int>> d;
	rep(i, h) {
		int w;
		cin >> w;
		d.push_back(make_pair(w, 0));
	}
	rep(i, w) {
		int w;
		cin >> w;
		d.push_back(make_pair(w, 1));
	}
	sort(d.begin(), d.end(), greater<pair<int, int>>());
	int all = 0;
	int na = 0;
	int nb = 0;
	for(auto i: d) {
		if(i.second == 0) {
			all += nb * i.first;
			na++;
		}
		else {
			all += na * i.first;
			nb++;
		}
	}
	cout << all << endl;
}


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

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

    vector<ll> l;

    l.emplace_back(2);
    l.emplace_back(1);

    rep(i, n-1){
        l.emplace_back(l[l.size()-1]+l[l.size()-2]);
    }

    cout << l[l.size()-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define endl '\n';
typedef long long ll;
typedef long double ld;
using namespace std;


int main() {
  vector<int> a(3);
  for (int &x : a) cin >> x;
  sort(a.begin(), a.end());
  cout << a[0] + a[1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	int n, k, otv = 0, t = 0;
	string s;
	cin >> n >> k >> s;
	if (n == 1) {
		cout << 0;
	}
	else {
		vector <char> ss(n + 1);
		for (int i = 0; i + 1 < n; ++i) {
			if (t != i && s[i - 1] == 'L' && s[i] == 'R' && s[i + 1] == 'L' && k > 0) {
				ss[i - 1] = 'L';
				ss[i] = 'L';
				ss[i + 1] = 'L';
				k -= 1;
				otv += 2;
				t = i + 1;
			}
			else if (t != i && s[i - 1] == 'R' && s[i] == 'L' && s[i + 1] == 'R' && k > 0) {
				ss[i - 1] = 'R';
				ss[i] = 'R';
				ss[i + 1] = 'R';
				k -= 1;
				otv += 2;
				t = i + 1;
			}
			else if (s[i] == 'L' && i != 0 && s[i - 1] == 'L') {
				++otv;
			}
			else if (s[i] == 'R' && s[i + 1] == 'R') {
				++otv;
			}
			if (t != i + 1) {
				ss[i] = s[i];
			}
		}
		if (s[n - 1] == 'L' && s[n - 2] == 'L') {
			++otv;
		}
		ss[n - 1] = s[n - 1];
		int beg = 0;
		if (ss[0] == 'L') {
			for (int i = 0; i < n; ++i) {
				if (ss[i] == 'R') {
					beg = i;
					break;
				}
			}
			if (beg == 0) {
				t = -1;
			}
			else {
				t = -2;
			}
		}
		ss[n] = 'R';
		if (t != -1) {
			for (int i = beg; i < n; ++i) {
				if (k > 0 && ss[i] == 'L' && ss[i + 1] == 'R' && i != n-1) {
					otv += 2;
					--k;
				}
				else if (k > 0 && ss[i] == 'L' && ss[i + 1] == 'R') {
					++otv;
				}
			}
			if (t == -2 && k > 0) {
				otv += 1;
			}
		}
		cout << otv;
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <math.h>
using namespace std;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	if (a + b < c + d)
	{
		cout << "Right" << endl;
	}
	else if (a + b == c + d)
	{
		cout << "Balanced" << endl;
	}
	else
	{
		cout << "Left" << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,j,k,c;
cin>>i;
if(i%2==0)
{
char a[i];
for(j=0;j<i;j++)
cin>>a[j];
for(k=0;k<(i/2);k++)
{if(a[k]==a[k+i/2])
c=0;
else
{c=1;
break;}
}
if(c==0)
cout<<"Yes";
else
cout<<"No";
}
else
cout<<"No";
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a,b,c,d,e,k,f;
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &k);
    f = e - a;
    if(f <= k){
        printf("Yay!");
    }else{
        printf(":(");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

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

    vector<vector<int>> X((N),vector<int>(D));

    for (int i = 0; i < N;i++)
        for (int j = 0; j < D;j++)
            cin >> X[i][j];
    
    int count = 0;

    for (int i = 0; i < N;i++){
        for (int j = i + 1; j < N;j++){
            int dis = 0;
            for (int l = 0; l < D;l++){
                dis += (X[i][l] - X[j][l]) * (X[i][l] - X[j][l]);
            }
            if(ceil(sqrt(dis)) == floor(sqrt(dis))){
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 N, M;
  cin >> N >> M;
  vector<i64> P(M);
  vector<string> S(M);
  rep(i,0,M) cin >> P[i] >> S[i];
  vector<i64> cnt(N + 1);
  i64 pena = 0;
  i64 ac = 0;
  rep(i,0,M) {
    if(S[i] == "WA") {
      if(cnt[P[i]] == -1) continue;
      else cnt[P[i]]++;
    }
    else {
      if(cnt[P[i]] == -1) continue;
      else ac++, pena += cnt[P[i]], cnt[P[i]] = -1;
    }
  }
  cout << ac << " " << pena << endl;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  REP(i,N) cin >> w[i] >> v[i];

  vector<vector<ll>> dp(N + 1, vector<ll> (W + 1, 0));
  REP(i,N)REP(j, W + 1) {
    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
    if(j + w[i] <= W) {
      dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
    }
  }

  ll ret = 0;
  REP(j, W + 1) ret = max(ret, dp[N][j]);
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 80256
#include <stdio.h>
int main(){
  int n,H[251],p,l,r,i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&H[i]);
  }

 for(i=1;i<=n;i++){  
   p=i/2;
   l=2*i;
   r=2*i+1; 
   printf("node %d: key = %d, ",i,H[i]);
   if(i!=1) printf("parent key = %d, ",H[p]);
   if(i*2<=n) printf("left key = %d, ",H[l]);
   if(i*2+1<=n) printf("right key = %d, ",H[r]);
   printf("\n");
 }
 return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<iomanip>

using namespace std;

#define rep(i, a, n) for (int i = (a); i < (n); i++)

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期

  int n,t;
  cin>>n>>t;

  int a[n];
  rep(i,0,n){cin>>a[i];}

  int sum=n*t;
  rep(i,0,n-1){
    if(a[i+1]-a[i]<=t){
      sum-=t-(a[i+1]-a[i]);
    }
  }

  cout<<sum<<endl;
}

Measured memory_bytes: 1024