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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_a() {
	ll n, m;
	ll x, y;
	ll a, b, d;
	//ll c;
	//char c;
	//ll h, w;
	ll k;
	string s, t;
	ll l_ans = 0;
	string s_ans = "NG";
	ll l, r;

	cin >> n;

	V h(n);
	rep(i, n) cin >> h[i];

	ll mh = h[0];
	rep(i, n) {
		if (h[i] >= mh) {
			l_ans++;
		}
		mh = max(mh, h[i]);
	}

	cout << l_ans << "\n";

	return;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(7);

	solve_abc_a();

	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
void pre(){}
void solve(){
    ll a;
    long double b;
    cin>>a>>b;
    ll ans = a*b;
    cout<<ans<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}





Measured memory_bytes: 3748
a = input()
b = input()
c = input()
n = len(a) + len(b) + len(c)

turn = 0
for i in range(n):
	if turn == 0:
		if len(a) == 0:
			win = "A"
			break
		draw = a[0]
		a = a[1:]
	elif turn == 1:
		if len(b) == 0:
			win = "B"
			break
		draw = b[0]
		b = b[1:]
	elif turn == 2:
		if len(c) == 0:
			win = "C"
			break
		draw = c[0]
		c = c[1:]
	if draw == "a":
		turn = 0
	elif draw == "b":
		turn = 1
	elif draw == "c":
		turn = 2

print(win)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

using namespace std;
typedef long long ll;

ll a, b, c, d;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d}) << endl;
}

Measured memory_bytes: 3648
S = [list(input()) for _ in range(3)]
d = {0: "a", 1: "b", 2: "c"}
D = {"a":0, "b":1, "c":2}

n = 0
for _ in range(len(S[0]) + len(S[1]) + len(S[2])):
  N = n
  if len(S[n]) > 0:
    n = D[S[n][0]]
    S[N].pop(0)
  else:
    print(str.upper(d[n]))
    break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;
const double PI = acos(-1.0);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}

using namespace std;

int main()
{
    int n, a, b;
    cin >> n;
    vector<int> p(n), q(n), v(n);
    rep(i, n)
    {
        cin >> p[i];
        v[i] = i + 1;
    }
    rep(i, n)
    {
        cin >> q[i];
    }
    int c = 0;
    do
    {
        c++;

        if (p == v)
        {
            a = c;
        }
        if (q == v)
        {
            b = c;
        }

    } while (next_permutation(v.begin(), v.end()));

    print(abs(a - b));
}


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

int main(){
	int n, m;
	cin >> n >> m;
	int* a = new int[(n+1)*(m+1)];
	for (int i = 0; i < n + 1; i++){
		for (int j = 0; j < m + 1; j++){
			if (i < n && j < m){
				cin >> a[i*(m + 1) + j];
			}
			else{
				a[i*(m + 1) + j] = 0;
			}
		}
	}
	for (int i = 0; i < n+1; i++){
		for (int j = 0; j < m+1; j++){
			if (i != n && j != m){
				a[i*(m + 1) + m] += a[i*(m + 1) + j];
			}
			if (i != n){
				a[n*(m + 1) + j] += a[i*(m + 1) + j];
			}
			cout << a[i*(m + 1) + j] << ((j == m) ? "\n" : " ");
		}
	}
	delete[] a;
}

Measured memory_bytes: 3104
#include<stdio.h>
#define MAX 11

int main(void)
{
  float x[MAX], sum, p;
  int N, k, kk;
  int i;
  char u1[MAX], u2[MAX], u3[MAX];
  
  scanf("%d", &N);

  for(i = 0 ; i < N ; i++)
  {
    scanf("%f %c%c%c", &x[i], &u1[i], &u2[i], &u3[i]);
    k = u1[i];
    kk ='J';
    if(k == kk)
      p = x[i];
    else
      p = x[i] * 380000.0;
    sum = p + sum;
  }
  
  printf("%f", sum);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  rep(i, n){
    ll a;
    cin >> a;
    while(a%2==0){
      a /= 2;
      ans++;
    }
  }
  print(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int n, m, x[200005], ta, tb;
 
int main() {
	scanf("%d%d", &n, &m);
	while (m--) {
		scanf("%d%d", &ta, &tb);
		if ((ta == 1 && ((x[tb] |= 1) == 3)) || (tb == n && ((x[ta] |= 2) == 3))) {
			printf("POSSIBLE\n");
			return 0;
		}
	}
	printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 1024
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
A.sort()
cumsum = A.cumsum()
# sortした後にcumsumを２倍しても一つ隣のAより大きくなっていないものは最後に残れない
# 後ろから調べていって途切れたらそこから左みんなダメ
# print('A', A)
# print('cumsum', cumsum)

for i in range(N - 2, -1, -1):
    if A[i + 1] > cumsum[i] * 2:
        ans = N - 1 - i
        break
else:
    ans = N
print(ans)


Measured memory_bytes: 25016
import java.util.*;
 
class Main {
  public static void main(String[] args) {
	Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    String N = scanner.next();
	char[] S = new char[n];
    S = N.toCharArray();
	long r=0,g=0,b=0;
    for(char Z:S){
      if(Z == 'R')r++;
      else if (Z == 'G')g++;
      else b++;
    }
    long ans = r*g*b;
                  
    for (int i = 0; i < n-2;i++){
      char X;
      char Y;
      X = S[i];
      for (int j = i+1; j < n-1;j++){
        if (S[j] != X){
          Y = S[j];
          if(2*j-i < n){
            if(S[2*j-i] != X && S[2*j-i] != Y){
              ans--;
            }
          }
        }
      }
    }
    System.out.println(ans);
  }  
}

Measured memory_bytes: 36320
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const char DA[10][10]={
	"aad",
	"b.d",
	"bcc",
};
const char D[][10][10]={{
	"aacd",
	"bbcd",
	"efgg",
	"efhh",
},{
	"aaddc",
	"b.eec",
	"bf..b",
	"cf..b",
	"cddaa",
},{
	"aad.ee",
	"b.de..",
	"bcce..",
	".eeaad",
	"e..b.d",
	"e..bcc",
},{
	".ggffcc",
	"gaabb..",
	"gb..zz.",
	"fba....",
	"f.a..aa",
	"c..a..b",
	"c..a..b",
}};
const int N=1010;
char ans[N][N];
int main(){
	memset(ans,'.',sizeof(ans));
	int n;
	cin>>n;
	if(n<=2){
		puts("-1");
		exit(0);
	}
	else if(n==3){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				ans[i][j]=DA[i][j];
			}
		}
	}
	else{
		int x=n/4*4-4;
		// cerr<<x<<endl;
		for(int i=0;i<x;i++){
			for(int j=0;j<x;j++){
				int l=i/4,r=j/4;
				if(l==r){
					ans[i][j]=D[0][i%4][j%4];
				}
			}
		}
		for(int i=x;i<n;i++){
			for(int j=x;j<n;j++){
				ans[i][j]=D[n%4][i-x][j-x];
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			putchar(ans[i][j]);
		}
		printf("\n");
	}
	return 0;
}

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

using namespace std;
#define ll long long int

int main()
{
   ll t;
   t = 1;	
  // cin t;
   while(t--){
       char a;
       cin >> a;
       if(isupper(a))
       cout << "A";
       else
       cout << 'a' << endl;      
   }
}


Measured memory_bytes: 3592
#include <iostream>
    using namespace std;
     
    int main() {
    string a,b;
    while(getline(cin,a),getline(cin,b)){
    int hit=0,blow=0;
    for(int i=0;i<a.size();i+=2){
    if(a[i]==b[i]){
    hit++;
    }else if(b.find(a[i],0)!=string::npos){
    blow++;
    }
    }
    cout<<hit<<" "<<blow<<endl;
    }return 0;
    }

Measured memory_bytes: 1172
N, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
dp = [0 for _ in range(W + 1)]

for a in A:
  for j in range(a[1], W + 1):
    dp[j] = max(dp[j], dp[j - a[1]] + a[0])
print(max(dp))


Measured memory_bytes: 5924
#include<stdio.h>
int main(void)
{
    int a, c, i, wa, ac, tle, re;
    char b[255];
    scanf("%d",&a);
    ac = 0;
    wa = 0;
    tle = 0;
    re = 0;
    
    for ( i = 0; i < a; i++)
    {
        scanf("%s",b);
        if (b[0] == 'A')
        {
        ac = ac + 1;
        }
        else if (b[0] == 'W')
        {
        wa = wa + 1;
        }
        else if (b[0] == 'T')
        {
        tle = tle + 1;
        }
        else if (b[0] == 'R')
        {
        re = re + 1;
        }

    }
    
    // char b[100000];
    // for ( i = 0; i < 100000; i++)
    // {
    //     scanf("%s",&b[i]);
    // }
    // ac = 0;
    // wa = 0;
    // tle = 0;
    // re = 0;
    // for ( i = 0; i < a; i++)
    // {
    //     if (b[i] = "AC")
    //     {
    //         ac = ac + 1;
    //         break;
    //     }
    //     else if (b[i] = "WA")
    //     {
    //         wa = wa + 1;
    //         break;
    //     }
    //     else if (b[i] = "TLE")
    //     {
    //         tle = tle + 1;
    //         break;
    //     }
    //     else if (b[i] = "RE")
    //     {
    //         re = re + 1;
    //         break;
    //     }

    // }
    printf("AC x %d\n",ac);
    printf("WA x %d\n",wa);
    printf("TLE x %d\n",tle);
    printf("RE x %d\n",re);
    return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll var;cin>>var;vec.push_back(var);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define mod2 998244353
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod=1e9+7;
#define piii 3.14159265358979323846264338327950


bool prime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}

//////////////////////////////////////////////////// Lets Do It ////////////////////////////////////////////////////////

void solve(){

    ll x,y;
    cin>>x>>y;

    if(y&1 || 4*x<y || 2*x>y){
        cout<<"No"; return; 
    }

    cout<<"Yes";

    return;
} 
 
int main()
{
    IOS;
    ll t;
    //cin>>t;
    t=1;

    while(t--){
        solve();
        cout<<endl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
} 

Measured memory_bytes: 3616
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    str A, B, C;
    cin >> A >> B >> C;
    if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0]) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include<deque>
#include<queue>
#include<set>
#include <functional>
#include <cmath>


//マクロ
/*動かない・・・
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _roverload3(_1,_2,_3,name,...) name
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(...) _roverload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
//*/
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
//*/
#define All(a) (a).begin(),(a).end()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
//*/
using namespace std;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数
ll a, b;

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

ll gcd(ll a, ll b) {
	if (a < b)return gcd(b, a);
	if (b == 0)return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b)*b;
}

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

	cin >> a >> b;
	cout << lcm(a, b) << endl;
}

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

using namespace std;

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

typedef long long ll;

void solve(){
	int n, k;
	cin >> n >> k;
	vector<bool> has_snack(n, 0);
	for(int i = 0; i < k; ++i) {
		int qty;
		cin >> qty;
		for(int j = 0; j < qty; ++j) {
			int n_snuke;
			cin >> n_snuke;
			has_snack[n_snuke] = 1;
		}
	}
	
	int n_vic = 0;
	for(int i = 1; i <= n; ++i) {
		if(!has_snack[i]) ++n_vic;
	}
	
	cout << n_vic;
}

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

	solve();
    
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007

int main() {
    string s1,s2;
    cin>>s1>>s2;
    int n = s1.length();
    int cnt = 0;
    for(int i=0;i<n;i++){
        if(s1[i] == s2[i])cnt++;
    }
    cout<<cnt<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdint.h>
#define mod 1000000007
#define ull unsigned ll
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pi 3.1415926535897932
using namespace std;

int main()
{

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	ld a, b;
	cin >> a >> b;
	ull j= floor(a * b);
    cout<<j<< "\n";
	return 0;
}



Measured memory_bytes: 3736
import collections
n = int(input())
dict_same = {}
for i in range(n):
  new_str = input()
  count = collections.Counter(new_str)
  temp_dict = {}
  if i == 0:
    for key, value in count.items():
      dict_same[key] = value
  else:
    same_keys = dict_same.keys() & count.keys()
    for one_keys in same_keys:
      temp_dict[one_keys] = min(dict_same[one_keys], count[one_keys])
    dict_same = temp_dict

sorted_dict = sorted(dict_same.items(), key=lambda x:x[0])
result = ""
for one_str, num in sorted_dict:
  result += one_str * num
print(result)

Measured memory_bytes: 3316
import java.util.*;

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

    int N = in.nextInt();
    int M = in.nextInt();
    
    int[] nums = new int[N];
    
    for (int i = 0; i < N; i++) {
      nums[i] = in.nextInt();
    }
    
    HashMap<Integer, Set<Integer>> map = new HashMap<>();
    for (int i = 0; i < M; i++) {
      int A = in.nextInt() - 1;
      int B = in.nextInt() - 1;

      if (!map.containsKey(A)) {
        map.put(A, new HashSet<Integer>());
      }
      if (!map.containsKey(B)) {
        map.put(B, new HashSet<Integer>());
      }

      map.get(A).add(B);
      map.get(B).add(A);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      Set<Integer> path = map.get(i);
      if (path == null) {
        ans++;
        continue;
      }
      boolean shouldAdd = true;
      for (Integer j : path) {
        if (nums[j] >= nums[i]) {
          shouldAdd = false;
          break;
        }
      }

      if (shouldAdd) {
        ans++;
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 86636
#include <iostream>
#include <string>
#include <map>

int main(){
   int N;
   std::cin >> N;
   std::map<std::string, int> mp;
   bool flag = true;
   for (int i=0; i<N; i++){
      char next;
      std::string key;
      std::cin >> key;
      if (i == 0){
         mp[key]++;
         next = key.at(key.size()-1);
      } else{
         if (!((key.at(0) == next) && (mp[key] == 0))){
            flag = false;
         } else{
            mp[key]++;
            next = key.at(key.size()-1);
         }
      }
      //std::cerr << next << std::endl;
   }
   if (flag)
      std::cout << "Yes" << std::endl;
   else
      std::cout << "No" << std::endl;

}



Measured memory_bytes: 256
function Main(input){
	input=input.trim().split(" ");
	let a = parseInt(input[0], 10);
	let b = parseInt(input[1], 10);
	let c = parseInt(input[2], 10);
	let ans = 0;
	for (let i = a; i <= b; i++){
		if (c % i == 0){
			 ans ++;
		}
	}
	console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15296
S = str(input())
T = str(input())

dp = [[0] * (len(T) + 1) for _ in range(len(S) + 1)]

for i in range(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])

lst = []

N = i + 1
M = j + 1
while (N - 1) >= 0 and (M - 1) >= 0:
    if S[N - 1] == T[M - 1]:
        lst.append(S[N - 1])
        N -= 1
        M -= 1
    else:
        if dp[N][M] == dp[N - 1][M]:
            N -= 1
        else:
            M -= 1

print (*lst[::-1], sep = '')

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

int main(){
int n,k;
  cin >> n >> k;
int d[n];
  for(int i=0;i<n;i++) cin>>d[i];
int num[n]={0};
  for(int i=0;i<n;i++){
   if(d[i])num[d[i]-1]++;
  }
  sort(num,num+n,greater<int>());
int count=0;
for(int i=k;i<n;i++){
  if(num[i]>0)count+=num[i];
}
  
 cout << count << endl;
 return 0;


}

Measured memory_bytes: 5140
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <random>
#include <string.h>      //文字列の代入に使う
#include <bits/stdc++.h> //piの利用で必要(M_PI)
#include <algorithm>

int main()
{

    double A, B, H, M;
    std::cin >> A >> B >> H >> M;
    double Ax = A * cos(-((H*60+M) / 360 * M_PI)+M_PI/2),
           Ay = A * sin(-((H*60+M) / 360 * M_PI)+M_PI/2),
           Bx = B * cos(-(M / 30 * M_PI)+M_PI/2),
           By = B * sin(-(M / 30 * M_PI)+M_PI/2);

    double ans = sqrt(pow(Ax - Bx, 2) + pow(Ay - By, 2));
    std::cout <<  std::setprecision(10) <<ans << std::endl;
    return 0;
}


Measured memory_bytes: 4164
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
A=[]
ans=0
AB=[]
for i in range(N):
    a=list(map(int,input().split()))
    ab=[0]*M
    for i in range(M):
        ab[i]=a[i]*B[i]
    AB.append(ab)
for i in range(N):
    if sum(AB[i])>(-1)*C:
        ans+=1
print(ans)

Measured memory_bytes: 3064
k = int(input())
s = list(map(int, input().split()))
a = s[0]
b = s[1]

kotae = False

for i in range(b - a + 1):
    if (a + i) % k == 0:
        kotae = True
        break

if kotae:
    print("OK")
else:
    print("NG")

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

int main(){
  int d,n,m;
  int t[100001];
  int k,left,right,mid,ans;

  while(1){
    cin >> d;
    if(!d)break;

    cin >> n;
    cin >> m;

    t[0] = 0;
    for(int i=1;i<n;i++)cin >> t[i];
    sort(t,t+n);
    t[n] = d;

    ans = 0;
    for(int i=0;i<m;i++){
      cin >> k;

      left = 0;
      right = n;

      while(left+1 < right){
	mid = (left + right) / 2;
	if(t[mid] > k)right = mid;
	else left = mid;
      }
      ans += min(k - t[left],t[right] - k);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1252
import collections
import math
n = int(input())
s_list = list(input())
c = collections.Counter(s_list)
ans = c["R"] * c["G"] * c["B"]
for i in range(n):
    for j in range(i + 1, n):
        k = j + j - i
        if k < n:
            if s_list[i] != s_list[j] and s_list[i] != s_list[k] and s_list[j] != s_list[k]:
                ans -= 1
print(ans)

Measured memory_bytes: 68876
#include<stdio.h>
#include<string.h>

int main(){
  int rx,ry,dir,inc,dx,dy;
  int w,h;
  int dic[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
  char str[128];
  do{
    fgets(str,128,stdin);
    sscanf(str,"%d %d",&w,&h);
    if(w==0&&h==0) break;
    rx=ry=dir=0;
    do{
      fgets(str,128,stdin);
      if(str[0]=='S') break;
      if(str[0]=='F'||str[0]=='B'){
	inc=atoi(strchr(str,' ')+1);
	dx=dic[str[0]=='F'?dir:(dir+2)%4][0]*inc;
	dy=dic[str[0]=='F'?dir:(dir+2)%4][1]*inc;
	if(dx+rx<h&&dx+rx>-1){
	  rx+=dx;
	}else{
	  if(dx+rx>=h) rx=h-1;
	  else rx=0;
	}
	if(dy+ry<w&&dy+ry>-1){
	  ry+=dy;
	}else{
	  if(dy+ry>=w) ry=w-1;
	  else ry=0;
	}
      }else if(str[0]=='R'){
	dir=(dir+1)%4;
      }else if(str[0]=='L'){
	dir=dir-1>-1?dir-1:3;
      }
    }while(1);
    printf("%d %d\n",ry+1,rx+1);
  }while(1);
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)

int main()
{
    int N,a;
    cin >> N;
    REP(i, N) {
        cin >> a;
        if (a % 2 == 1)
            continue;
        int m6, m10;
        m6 = a % 6;
        m10 = a % 10;
        if (m6 != 0 && m10 != 0) {
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    ll sum = 0;
    ll ans = 0;
    rep(i,n) {
        int x; cin >> x;
        if (x == 0) {
            ans += sum/2;
            sum = 0;
        } else sum += x;
    }
    ans += sum/2;
    cout << ans << endl;
}

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

int main()
{
    int num, win;
    cin >> num >> win;

    double ans;
    for(int i=1;i<=num;i++){
        double current=1;
        int now=i;
        current /= num;
        while(now<win){
            now *=2;
            current /=2;
        }
        ans += current;
    }
    cout << setprecision(12)<< ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner scn=new Scanner(System.in);
        int n=scn.nextInt();
        int m=scn.nextInt();
        int max;
        max=Math.max(n+m,n-m);
        max=Math.max(max,n*m);
        System.out.println(max);
    }
}


Measured memory_bytes: 21844
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

for i in range(3):
    c = 0
    for j in range(3):
        if A[i][j] in b:
            c += 1
    if c == 3:
        print('Yes')
        exit()

for i in range(3):
    c = 0
    for j in range(3):
        if A[j][i] in b:
            c += 1
    if c == 3:
        print('Yes')
        exit()

if A[0][0] in b and A[1][1] in b and A[2][2] in b:
    print('Yes')
    exit()
if A[0][2] in b and A[1][1] in b and A[2][0] in b:
    print('Yes')
    exit()

print('No')


Measured memory_bytes: 3064
// ACM-ICPCà\I2007 C. P[LJbg

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n, w, d, p, s;
	while(cin >> n >> w >> d, w){
		vector < pair<int, int> > cake;
		cake.push_back(make_pair(w, d));
		for(int i=0;i<n;i++){
			cin >> p >> s;
			int nw = cake[p-1].first, nd = cake[p-1].second;
			for(int j=p-1;j<i;j++) cake[j] = cake[j+1];
			s %= (nw+nd);
			if(s < nw){
				cake[i] = make_pair(min(s, nw-s), nd);
				cake.push_back(make_pair(max(s, nw-s), nd));
			} else {
				s -= nw;
				cake[i] = make_pair(nw, min(s, nd-s));
				cake.push_back(make_pair(nw, max(s, nd-s)));
			}
		}
		vector <int> S;
		for(int i=0;i<n+1;i++) S.push_back(cake[i].first*cake[i].second);
		sort(S.begin(), S.end());
		for(int i=0;i<n;i++) cout << S[i] << " ";
		cout << S[n] << endl;
	}
}

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

using namespace std;

int a[1000], b[1000];

int result[1000];

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

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

	for (int i = 0; i < m; ++i) {
		cin >> b[i];
	}

	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < n; ++j) {
			if (b[i] >= a[j]) {
				result[j]++;
				break;
			}
		}
	}

	int hoge = -1;

	int ans;

	for (int i = 0; i < n; ++i) {
		if (hoge < result[i]) {
			hoge = result[i];
			ans = i + 1;
		}
	}

	printf("%d\n", ans);
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N;ll A;cin>>N>>A;
    vector<ll> x(N);
    REP(i,N)cin>>x[i];
    ll dp[51][2501][51];
    // dp[i][j][k] i番目までの数字をk個つかって和をjとできるものの場合の数
    REP(i,51)REP(j,2501)REP(k,51)dp[i][j][k]=0;
    dp[0][0][0]=1;
    FOR(i,1,N+1)REP(j,2501)REP(k,N+1){
        if(x[i-1]>j||k==0)dp[i][j][k]=dp[i-1][j][k];
        else{
            dp[i][j][k]=dp[i-1][j-x[i-1]][k-1]+dp[i-1][j][k];
        }
    }
    ll res=0;
    FOR(i,1,N+1)res+=dp[N][A*i][i];
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 51072
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int res = 1;
	bool flag;
	cin >> s;
	int len = s.size();
	if (s[0] == 'B')
		flag = 0;
	else
		flag = 1;
	for (int i = 1; i < len; ++i)
	{
		if ((s[i] == 'B') && (!flag))
			continue;
		else if ((s[i] == 'W') && (flag))
			continue;
		else
		{
			res++;
			flag = (s[i]=='B')?0:1;
		}
	}
	cout << res - 1;
return 0;	
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end();++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

const int INF = ~(1<<31);
const double pi = acos(-1);
const double EPS = 1e-9;
typedef unsigned long long ull;

template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

ll md = 1000000000+7;
int n,m;
bool B[100'005];
ll memo[100'005];
ll dp(int at) {
    if(B[at]) return 0;
    if(at == n) return 1;
    if(at > n) return 0;
    if(memo[at] != -1) return memo[at];
    return memo[at] = (dp(at+1)+dp(at+2))%md;
}

int main() {
    cin.sync_with_stdio(false);
    cin >> n >> m;
    memset(memo,-1,sizeof(memo));
    memset(B,0,sizeof(B));
    rep(i,0,m) {
        int x;
        cin >> x;
        B[x] = true;
    }
    cout << dp(0) << endl;
    return 0;
}



Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int n,r;
int main()
{
	scanf("%d%d",&n,&r);
	if (n>=10) printf("%d\n",r);
	else printf("%d\n",r+100*(10-n));
return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <stdint.h>

int64_t as[100000];

int main(){
  int64_t N;
  scanf("%ld",&N);
  for(int64_t i=0;i<N;i++){
    scanf("%ld",&as[i]);
  }
  int64_t total=0;
  for(int64_t i=0;i<N;i++){
    if(i>0){
      int64_t sub=std::min(as[i-1],as[i]);
      total+=sub;
      as[i-1]-=sub;
      as[i]-=sub;
    }
    total+=as[i]/2;
    as[i]%=2;
  }
  printf("%ld\n",total);
  return 0;
}


Measured memory_bytes: 896
import math
a, b, x = map(int, input().split())
h = x / (a * a)
if x < a*a*b / 2:
    print(90-math.degrees(math.atan(2*x/(a*b*b))))
else:
    print(math.degrees(math.atan((2*(b-x/(a*a)))/a)))



    

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int a, b;

char s[110][110];
const int n=100, m=100;

int main()
{
	cin >> a >> b;
	for(int i=1; i<=n/2; ++i) fill(s[i]+1, s[i]+m+1, '.');
	for(int i=n/2+1; i<=n; ++i) fill(s[i]+1, s[i]+m+1, '#');
	--a; --b;
	for(int i=1; i<=n/2 && b; i+=2){
		for(int j=1; j<=m && b; j+=2){
			s[i][j] = '#'; --b;
		}
	}
	for(int i=2; i<=n/2 && a; i+=2){
		for(int j=1; j<=m && a; j+=2){
			s[n/2+i][j] = '.'; --a;
		}
	}
	cout << n << ' ' << m << '\n';
	for(int i=1; i<=n; ++i) cout << s[i]+1 << '\n';
	return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  int plus = 0;
  int minus = 0;
  vector<int> vec(0);
  for(int i=0; i<N; i++){
    if(S.at(i) == '1'){
      plus++;
      if(minus < 0){
        vec.push_back(minus);
        minus = 0;
      }
    }
    else{
      minus--;
      if(plus > 0){
        vec.push_back(plus);
        plus = 0;
      }
    }
    if(i == N-1){
      if(plus > 0){
        vec.push_back(plus);
      }
      else{
        vec.push_back(minus);
      }
    }
  }
  
  int max_ans = 0;
  int ans = 0;
  if(vec.at(0) > 0){
    if(K >= vec.size()/2){
      max_ans = N;
    }
    else{
      for(int i=0; i<2*K; i+=2){
        max_ans += vec.at(i) + abs(vec.at(i+1));
      }
      max_ans += vec.at(2*K);
      ans = max_ans;
      for(int i=1; 2*K+i*2<vec.size(); i++){
        ans -= vec.at(i*2-2) + abs(vec.at(i*2-1));
        ans += abs(vec.at(2*K+i*2-1)) + vec.at(2*K+i*2);
        max_ans = max(max_ans,ans);
      }
      if(vec.at(vec.size()-1) < 0){
        ans = 0;
        for(int i=1; i<=2*K; i+=2){
          ans += abs(vec.at(vec.size()-i)) + vec.at(vec.size()-i-1);
        }
        max_ans = max(max_ans,ans);
      }
    }
  }
  else{
    if(K >= (vec.size()+1)/2){
      max_ans = N;
    }
    else{
      for(int i=0; i<2*K; i+=2){
        ans += abs(vec.at(i)) + vec.at(i+1);
      }
      max_ans = ans;
      for(int i=1; 2*K+(i-1)*2+1<vec.size(); i++){
        if(i == 1){
          ans -= abs(vec.at(0));
        }
        else{
          ans -= vec.at((i-1)*2-1) + abs(vec.at((i-1)*2));
        }
        ans += abs(vec.at(2*K+(i-1)*2)) + vec.at(2*K+(i-1)*2+1);
        max_ans = max(max_ans,ans);
      }
      if(vec.at(vec.size()-1) < 0){
        ans = 0;
        for(int i=1; i<=2*K; i+=2){
          ans += abs(vec.at(vec.size()-i)) + vec.at(vec.size()-i-1);
        }
        max_ans = max(max_ans,ans);
      }
    }
  }   
  cout << max_ans << endl;     
}

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

const ll max_n = 1000000000000001;

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; ++i)cin >> a[i];
	ll sum = 0;
	for (ll i = 0; i < n; ++i)sum ^= a[i];
	for (ll i = 0; i < n; ++i)cout << (sum ^ a[i]) << " ";
}


Measured memory_bytes: 4748
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int N; cin >> N;
  double D = sqrt( 1+8*N);
  bool ok = D - (double) floor(D) == 0.0;
  if (!ok) {
    cout << "No" << endl; return 0;
  } else {
    cout << "Yes" << endl;
  }
  int numSet = (D-1)/2 +1;
  cout << numSet << endl;
  vector<vector<int >> sets;
  sets.push_back(vi(1,1));
  sets.push_back(vi(1,1));
  int curSet = 1;
  int leftMost = 1;
  for (int i=2; i<=N; i++) {
    if (leftMost == curSet) { 
      sets.push_back(vi(1, i));
      curSet++;
      sets[0].push_back(i);
      leftMost=1;
      continue;
    }
    sets[leftMost++].push_back(i);
    sets[curSet].push_back(i);
  }
  rep(i, sets.size()){
    cout << sets[i].size() << ' ';
    rep(j, sets[i].size()) cout << sets[i][j] << ' ';
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 2304
X = int(input())
N = int(X**(1/5))
ans = [0,0]
for i in range(-2*N-1, 2*N+2):
  for j in range(-2*N-1, 2*N+2):
    if i**5-j**5==X:
      ans = [i, j]
ans = [str(i) for i in ans]
ans = ' '.join(ans)
print(ans)

Measured memory_bytes: 9328
#include<stdio.h>

int main(void)
{
  int s;
  double w, h, BMI;
  
  while(scanf("%d,%lf,%lf",&s,&w,&h)!=EOF)
    {
      BMI = w/(h*h);
      if(BMI>=25)
	printf("%d\n",s);
    }
  return 0;
}

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

using namespace std;

typedef int in;
#define int long long

in main(){
    int n,m;
    cin >> n >> m;
    if(n < 6){
        cout << "0\n";
    }
    else if(n > 12){
        cout << m << endl;
    }
    else{
        cout << m / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include "math.h"
#include <complex>
#include <iomanip>
#define ifor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;
typedef long double ld;
typedef long long int  lli;
typedef complex <double> P;
const double eps = 1e-11;
int vex[4]={1,0,-1,0};
int vey[4]={0,1,0,-1};
int main(){
	string s;
	cin >> s;
	int n = s.length();
	for(int i = 0;i+1<n;i++){
		if(s[i]==s[i+1]){
			cout << i+1 << ' ' << i+2<<endl;
		return 0;
		}
	}

	for(int i = 0;i+2<n;i++){
		if(s[i]==s[i+2]){
			cout << i+1 << ' ' << i+3<<endl;
		return 0;
		}
	}
	cout << -1<<' '<<-1<<endl;

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long 
long long inf = 4654354313333345;
//=================================================================//
int dp[3001][3001];
int sum[3001][3001];
int solve(vector<int>&v, int i, int j) {
    if(i==j) return 0;
    if(dp[i][j]!=-1) return dp[i][j];
    int minCost = inf;
    for(int k = i;k<j;k++) {
        minCost = min(minCost,sum[i][j]+solve(v,i,k)+solve(v,k+1,j));
    }
    return dp[i][j] = minCost;
}

void preprocess(vector<int>&v, int n) {
    for(int i = 1;i<=n;i++) {
        for(int j = i;j<=n;j++) {
            sum[i][j] = v[j] + ((j==i) ? 0 :sum[i][j-1]);
        }
    }
}

#undef int
int main(){
#define int long long 
    int n;
    cin>>n;
    memset(dp, -1, sizeof dp);
    vector<int>v(n+1);
    for(int i=1;i<=n;i++) cin>>v[i];
    preprocess(v,n);
    cout<<solve(v,1,n);
    return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int N,M, dp[305][305][305]; // how many distinct, how many can get back to 1

int ad(int a, int b) { return (a+b)%MOD; }
int mul(int a, int b) { return (ll)a*b%MOD; }

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M;
    dp[0][1][1] = 1;
    F0R(i,M) FOR(j,1,N+1) FOR(k,1,j+1) {
        // new 
        dp[i+1][j+1][k] = ad(dp[i+1][j+1][k],mul(N-j,dp[i][j][k]));
        // not new, cannot get back to 1 
        dp[i+1][j][k] = ad(dp[i+1][j][k],mul(j-k,dp[i][j][k]));
        // can get back to 1
        dp[i+1][j][j] = ad(dp[i+1][j][j],mul(k,dp[i][j][k]));
    }
    cout << dp[M][N][N];
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 110464
#include<stdio.h>
int main()
{
//	while(1){
	int n,s,k;
	scanf("%d %d",&k,&s);
	if(k >= s)
	    n = (s + 2) * (s + 1) / 2;
    else if(s > k && s <= k + k / 2)
	    n = (k + 2) * (k + 1) / 2 + (2 * k - s) * (s - k);
	else if(s > k + k / 2 && s < 2 * k && k % 2 == 0)
		n = (k + 2) * (k + 1) / 2 + (k / 2) * (k / 2) - ((2 * (s - k - k / 2) + k % 2 + k % 2) * (s - k - k / 2) / 2);
    else if(s > k + k / 2 && s < 2 * k && k % 2 != 0)
	{
		if(s == k + k / 2 + 1)
			n = (k + 2) * (k + 1) / 2 + (k / 2 + 1) * (k / 2);
		else
			n = (k + 2) * (k + 1) / 2 + (k / 2 + 1) * (k / 2) - ((2 * (s - k - k / 2) + k % 2 + k % 2) * (s - k - k / 2) / 2);
	}
    else
		n = (3 * k - s + 2) * (3 * k - s + 1) / 2;
	printf("%d\n",n);
//	}
	return 0;
}



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

int main(){
	// sengen
	long long x;
	// nyuryoku
	cin >> x;
	// keisan
	long long sum = 100;
	long long year = 0;
	do{
		sum *= 1.01;
		year++;
	}while(sum < x);
	// syutsuryoku
	cout << year;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <vector>
#include <complex>
#include <cstdlib>
#include <ctime>
using namespace std;

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P,point;
typedef vector<P> polygon;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};
typedef L line;

P crosspoint(const L &l, const L &m) {
	double A = cross(l[1] - l[0], m[1] - m[0]);
	double B = cross(l[1] - l[0], l[1] - m[0]);
	if (abs(A) < EPS && abs(B) < EPS) return m[0];
	return m[0] + B / A * (m[1] - m[0]);
}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

// !CAUTION! number ÍLÈã
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
polygon convex_cut(const polygon& P, const line& l) {
  polygon Q;
  for (int i = 0; i < P.size(); ++i) {
    point A = curr(P, i), B = next(P, i);
    if (ccw(l[0], l[1], A) != -1) Q.push_back(A);
    if (ccw(l[0], l[1], A)*ccw(l[0], l[1], B) < 0)
      Q.push_back(crosspoint(line(A, B), l));
  }
  return Q;
}

double AreaOfPolygon(vector<P> p){
	double S = 0 ; 
	p.push_back(p[0]);
	/*@½p`ÌÊÏö® (½vñèÌê) */
	for(int i = 0 ; i < p.size()-1 ; i++){
		S += (p[i].real() - p[i+1].real()) * (p[i].imag()+p[i+1].imag());
	}
	S /= 2.0;
	return S;
}

double S = 0;

double getArea(vector<P> &g,P b){
	return AreaOfPolygon(convex_cut(g,L(P(0,0),b))) - S/2;
}
int main(){
	srand(time(NULL));
	int N;
	while(cin >> N && N){
		vector<P> g;
		for(int i = 0 ; i < N ; i++){
			double a,b;
			cin >> a >> b;
			g.push_back(P(a,b));	
		}
		
		S = AreaOfPolygon(g);
		vector<double> o[2];
		bool done = 0;
		while(!o[0].size() || !o[1].size()){
			double r = 2*M_PI / 1000000000	 * ((unsigned int)rand() % 1000000000);
			o[getArea(g, P(cos(r) , sin(r)) ) > 0].push_back(r);
			if( fabs(getArea(g, P(cos(r) , sin(r)))) < 1e-8){
				printf("%.15lf %.15lf%c",cos(r) * 1000 , sin(r) * 1000,10);
				done = 1;
				break;
			}
			//cout << getArea(g, P(cos(r) , sin(r))) << " " << r << endl;
			
		}
		if(done) continue;
		double l = o[0][0] , r = o[1][0];
		bool f = false;
		if( l > r ) swap(l,r) , f = 1;
		for(int _ = 0 ; _ < 128 ; _++){
			double m = (l+r) / 2.0;
			if( getArea(g,P(cos(m) , sin(m))) > 0 ) {
				if(f) l = m;
				else r = m;
			}else{
				if(f) r = m;
				else l = m;
			}
		}
		//cout << getArea(g,P(cos(l) , sin(l))) << endl;
		printf("%.15lf %.15lf%c",cos(l) * 1000 , sin(l) * 1000,10);
		exit:;
	}
}

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

ll howmanytimes(ll x){
    ll count =0;
    ll sum =0;
    while(x>1){
        x/=2;
        count++;
    }
    for(ll i=0;i<count;i++){
        sum += pow(2,i);
    }
    return pow(2,count)+ sum;
}


int main() {
    ll H;
    cin >>H;
    ll a=howmanytimes(H);
    cout <<a<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int n, m, x, y, kx, ky, ans, i, f[N], cnt[N];
int find_root(int x) {
	if (f[x] == x) return x;
	return f[x] = find_root(f[x]);
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	for (i = 1; i <= n; i++) {
		f[i] = i;
		cnt[i] = 1;
	}
	while (m--) {
		cin >> x >> y;
		kx = find_root(x);
		ky = find_root(y);
		if (kx != ky) {
			f[kx] = ky;
			cnt[ky] += cnt[kx];
		}
	}
	for (i = 1; i <= n; i++) if (f[i] == i) ans = max(ans, cnt[i]);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 5148
#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;

struct price
{
     ll l;
    double pr;
}p[5];


bool cmp(price a,price b)
{
    return a.pr < b.pr;
}
int main()
{
    int q,h,s,d;
    ll n;
    while (scanf("%d%d%d%d",&q,&h,&s,&d)!=EOF)
    {
    scanf("%lld",&n);
    n*=4;
    p[1].pr= q *1.0 ;
    p[1].l=1;
    p[2].pr= h *1.0 / 2;
    p[2].l=2;
    p[3].pr= s *1.0 / 4;
    p[3].l=4;
    p[4].pr= d *1.0 / 8;
    p[4].l=8;
    sort(p+1,p+1+4,cmp);
    ll  res=0;
    for (int i=1;i<=4;i++)
      {
          ll get = n / p[i].l;
          n -= get * p[i].l;
          res += (ll ) get *  (ll) (p[i].l * p[i].pr);
      }
      cout<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    for (auto e: v) os << e << ",";
    os << "]";
    return os;
}

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// print floating-point number
// cout << fixed << setprecision(12) <<

// }}}

int N, M;
int p[100010];
string s[100010];
bool c[100010];
int t[100010];

void solve()
{
    REP (i, M) {
        if (s[i] == "AC") c[p[i]-1] = true;
        else if (!c[p[i]-1]) t[p[i]-1]++;
    }
    ll ac = 0, pe = 0;
    REP (i, N) {
        if (c[i]) {
            ac++;
            pe += t[i];
        }
    }
    cout << ac << " " << pe << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    REP (i, M) cin >> p[i] >> s[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 6656
def main():
    N = int(input())
    A = list(map(int, input().split()))
    length = 1
    limit = 10 ** 18
    if 0 in A:
        print(0)
        return
    for i in range(N):
        length = length *  A[i]
        if length > limit:
            print('-1')
            return
    print(length)
    return
if __name__ == '__main__':
    main()

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

int main() {
  int N,K;
  cin >> N >> K;
  int x,sum=0;
  for(int i=0;i<N;i++) {
    cin >> x;
    if(x<K-x) sum += 2*x;
    else sum+=2*(K-x);
  }
  cout << sum << endl;
    
}


Measured memory_bytes: 256