akhauriyash/Code-Regression huggingface dataset:
/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(int i=1;i<=n;i++)
#define   FOR(i,a,b)      for(int i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
#define   ret             return 
#define   sz(x)           (LL)x.size()
LL n,i,j,ans = 0,k;
string s ; 
LL dp[1000000] ; 
LL a[1000000] ; 
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k ; 
    REP(i,n) cin>>a[i] ; 
    dp[1] = 0 ; 
    dp[2] = abs(a[2] - a[1]) ; 
    for(int i=3;i<=n;i++) 
    {  dp[i] = (LL)1E9 ; 
       for(int j=i-1;j>=max(1LL,i-k);j--) 
       dp[i] = min(dp[j] + abs(a[j] - a[i]),dp[i]) ; 
    }
    cout<<dp[n] ; 

}
//Check for 0,1 and other corner cases.

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

/// read the question correctly (is y a vowel?)
/// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

const int mx =  1234567;
const double exp1 =  1e-6;
const int md =  1e9+7;
typedef long long ll;

int ar[mx],xar[mx],uses[mx];
ll arr[mx];
int tab[1000][1000];
string st[200005];
int ar1[mx],ar2[mx];
map<int ,int>mpii;
map<int ,char>mpic;
map<char ,int>mpci;


int main(){

    int tk=1,n,m;
//    freopen("in.txt","r", stdin);
//    freopen("out.txt","w", stdout);

    while(scanf("%d",&n) == 1){
        map<string, int>mp;
        int mm = 0;
        for(int i = 0; i < n; i++){
            string s;
            cin>>s;
            st[i] = s;
            mp[s]++;
            mm = max(mm, mp[s]);
        }
       vector<string> st2;
        int k = 0;
        for(int i = 0; i < n; i++){
            if(mp[st[i]] == mm){
                st2.push_back(st[i]);
                mp[st[i]] = 0;
            }
        }
        sort(st2.begin(), st2.end());
        for(int i = 0; i < st2.size(); i++){
            cout<<st2[i]<<endl;
        }


    }

    return 0;
}


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

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------

int main(void) {
  int n, k;
  cin >> n >> k;
  vecb have(n,false);
  rep(i,k){
    int d;
    cin >> d;
    rep(j,d){
      int a;
      cin >> a;
      if(!have[a-1]) have[a-1]=true;
    }
  }

  int ans=0;
  rep(i,n){
    if(!have[i]) ans++;
  }
  prt(ans);
}


Measured memory_bytes: 3628
using System;

namespace _3027
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			int ret = 0;
			for (; Math.Pow(2, ret + 1) - 1 <= n; ret++) ;
			Console.WriteLine(ret);
		}
	}
}


Measured memory_bytes: 18020
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
int n, apc, amd1, amd2, ex1[200005], ex2[200005];
char x[200005];
int calc(int x){
	int ret = 1;
	for(; x; x %= __builtin_popcount(x), ret++);
	return ret;
}
int main(){
	scanf("%d\n%s", &n, x);
	ex1[0] = ex2[0] = 1;
	rep(i,n) if(x[i] == '1') apc++;
	rep(i,n){
		(amd1 *= 2) %= apc + 1;
		if(apc != 1) (amd2 *= 2) %= apc - 1;
		if(x[i] == '1'){
			amd1++;
			amd2++;
		}
		ex1[i+1] = ex1[i] * 2 % (apc + 1);
		if(apc != 1) ex2[i+1] = ex2[i] * 2 % (apc - 1);
	}
	rep(i,n){
		int ans = 0;
		if(x[i] == '0') ans = calc((amd1+ex1[n-i-1]) % (apc+1));
		else if(apc != 1) ans = calc((amd2-ex2[n-i-1]+apc-1) % (apc-1));
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 5496
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll fac[1] = {1}, inv[1] = {1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}
ll cmb(ll r, ll c) {return fac[r] * inv[c] % MOD * inv[r - c] % MOD;}

priority_queue<int, vector<int>, greater<int>> pq;
vector<int> v;

string mat[1000000];
set<int> xx[1000000];
set<int> yy[1000000];
int dist[1000000];

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

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

    int sx, sy, ex, ey;
    cin >> sx >> sy >> ex >> ey;
    sx--; ex--; sy--; ey--;

    for (int i = 0; i < n; i++) {
        cin >> mat[i];
        for (int j = 0; j < m; j++) {
            xx[i].insert(j);
            yy[j].insert(i);
        }
    }

    memset(dist, -1, sizeof(dist));
    queue<int> q;
    q.push(sx*m+sy);
    dist[sx*m+sy] = 0;
    xx[sx].erase(sy);
    yy[sy].erase(sx);

    int i, j, flag = 0;
    while (!q.empty()) {
        int tv = q.front();
        q.pop();

        i = tv/m, j = tv%m;
        auto b = xx[i].begin();

        for (auto a = xx[i].lower_bound(j); a != xx[i].end(); a = b) {
            if (*a - k > j || mat[i][*a]=='@') break;
            b = next(a);
            xx[i].erase(a);
            yy[*a].erase(i);
            dist[i*m+*a] = dist[tv]+1;
            q.push(i*m+*a);
        }

        auto st = xx[i].lower_bound(j);
        if (st != xx[i].begin()) {
            flag = 0;
            for (auto a = --st; ; a = b) {
                if (*a + k < j || mat[i][*a]=='@') break;

                if (a != xx[i].begin()) b = prev(a);
                else flag = 1;

                xx[i].erase(a);
                yy[*a].erase(i);
                dist[i * m + *a] = dist[tv] + 1;
                q.push(i * m + *a);
                if (flag) break;
            }
        }

        auto bb = yy[j].begin();
        for (auto a = yy[j].lower_bound(i); a != yy[j].end(); a = b) {
            if (*a - k > i || mat[*a][j]=='@') break;
            b = next(a);
            yy[j].erase(a);
            xx[*a].erase(j);
            dist[*a*m+j] = dist[tv]+1;
            q.push(*a*m+j);
        }

        auto ss = yy[j].lower_bound(i);
        if (ss != yy[j].begin()) {
            flag = 0;
            for (auto a = --ss; ; a = bb) {
                if (*a + k < i || mat[*a][j]=='@') break;

                if (a != yy[j].begin()) bb = prev(a);
                else flag = 1;

                bb = prev(a);
                yy[j].erase(a);
                xx[*a].erase(j);
                dist[*a*m+j] = dist[tv]+1;
                q.push(*a*m+j);
                if (flag) break;
            }
        }
    }
    cout << dist[ex*m+ey];
}

Measured memory_bytes: 227520
#include<bits/stdc++.h>
using namespace std;
int main(){

    string s;
cin>>s;
for(int i=1;i<=s.size();i++){
    regex reg("0B");
    s=regex_replace(s,reg,"");
    regex regex1("1B");
    s=regex_replace(s,regex1,"");

}
    regex regex2("B");
    s=regex_replace(s,regex2,"");



    cout<<s<<endl;
    return 0;
}



Measured memory_bytes: 3744
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 1e9 + 7;

int n;
long long pp;
char a[5][60];
int flag[60];
int main()
{
	pp = 1;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf(" %c", &a[1][i]);
	for(int i = 1; i <= n; i++) scanf(" %c", &a[2][i]);
	for(int i = 1; i <= n; i++) 
	{
		if(a[1][i] == a[2][i]) flag[i] = 1;
		else flag[i] = 2;
	}
	for(int i = 1; i <= n; i++)
	{
		if(flag[i] == 1 && i == 1) {
			pp *= 3;
			continue;
		}
		else if(i == 1){
			i++;
			pp *= 6;
			continue;
		}

		if(flag[i] == 1) {
			if(flag[i - 1] == 1) {
				pp *= 2;
				pp = pp % MAXN;
			}
			else if(flag[i - 1] == 2) {
				pp *= 1;
				pp = pp % MAXN;
			}
		}
		else if(flag[i] == 2) {
			if(flag[i - 1] == 1) {
				pp *= 2;
				pp = pp % MAXN;
			}
			else if(flag[i - 1] == 2) {
				pp *= 3;
				pp = pp % MAXN;
			}
			i++;
		}
	}
	printf("%lld\n", pp);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
//#define int long long
using namespace std;

int n;
int a[500][500];

//[l, r)
void dfs(int l, int r, int x) {
	//cout << l << " " << r << " " << x << endl;
	if (r - l == 1) return;
	int m = (r - l) / 2;
	
	int i, j;
	for (i = l; i < l + m; i++) {
		for (j = l + m; j < r; j++) {
			a[i][j] = x;
		}
	}
	
	//cout << "l = " << l << ", r = " << r << ", x = " << x << endl;
	//cout << "m = " << m << endl;
	dfs(l, l + m, x + 1);
	dfs(l + m, r, x + 1);
}

signed main() {
	cin >> n;
	dfs(0, n, 1);
	
	int i, j;
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			cout << a[i][j];
			if (j + 1 < n) cout << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define PRIM 3
#define INF (1 << 29)
#define LINF (1LL << 60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

string s;

bool ok(int x) {
    for (int p = 0; p < 2; p++) {
        bool ng = false;
        int bottom = p, top = x;
        if (top % 2 != p)
            top--;
        for (char c : s) {
            if (c == '0')
                bottom--, top--;
            if (c == '1')
                bottom++, top++;
            if (c == '?')
                bottom--, top++;
            if (bottom < 0)
                bottom += 2;
            if (top > x)
                top -= 2;
            if (top < bottom)
                ng = true;
        }
        if (!ng)
            return true;
    }
    return false;
}

int main() {
    cin >> s;

    int bottom = 0, top = s.size();
    while (top - bottom > 1) {
        int mid = (top + bottom) / 2;
        if (ok(mid))
            top = mid;
        else
            bottom = mid;
    }
    cout << top << endl;
    return 0;
}

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

int main() {
    int n, k, x, y;
    cin >> n >> k >> x >> y;

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

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int t = sc.nextInt();

		int minCost = Integer.MAX_VALUE;

		for(int i = 0; i < n; i++){
			int tmpC = sc.nextInt();
			int tmpT = sc.nextInt();

			if(tmpT <= t){
				minCost = Math.min(tmpC, minCost);
			}
		}

		System.out.println(minCost == Integer.MAX_VALUE ? "TLE" : minCost);

	}

}


Measured memory_bytes: 21716
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ull = unsigned long long;

#define rep(i,x) for(int i = 0; i<x; i++)

int main(){
    int x;
    cin >> x;
    if(x){
        cout << "0";
    }else{
        cout << "1";
    }
    return 0;
}

Measured memory_bytes: 3632
# coding: utf-8

#整数の入力
#a = int(input())
#スペース区切りの整数の入力
a, b, c = map(int, input().split())
#文字列の入力
#s = input()

if a == b:
    s = c
elif b == c:
    s = a
else :
    s = b

#出力
print(str(s))

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    ll a, b, k;
    cin >> a >> b >> k;
    ll ans = max(ll(0),a-k);
    if(ans==0) {
        b = max(ll(0), b+a-k);
    }
    cout << ans << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define x first
#define y second
#define ll long long
#define dl double
#define pii pair<int,int>
#define pb push_back
#define all() begin(),end()
#define nl '\n'
#define adm(a,b,m) ((a+b)%m)
#define gum(a,b,m) ((a*1LL*b)%m)
#define lo(i,j,n) for(int i=j;i<n;i++)


int main(){
	int a,b;
	cin>>a>>b;
	int c=0;
	while(b--){
		c++;
		if(c%100==0)c++;
	}
	cout<<c<<string(2*a,'0')<<nl;
}

Measured memory_bytes: 256
#include <iostream>

std::string nextContest(std::string S);

int main(void) {
    std::string S;
    
    std::cin >> S;
    std::cout << nextContest(S) << std::endl;
    
    return 0;
}

std::string nextContest(std::string S) {
    if(S == "ABC") {
        return "ARC";
    }
    
    return "ABC";
}

Measured memory_bytes: 3588
/*
********************
Author : Sahil Kundu
********************
*/
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb(i) push_back(i)
#define pp() pop_back()
#define f first
#define s second
#define mk(l,r) make_pair(l,r)
#define all(vc) vc.begin(),vc.end()
#define bg(vc) vc.begin()
#define ed(vc) vc.end()
#define ms(i,j) memset(i,j,sizeof i)
#define w(t) while(t--)
const ll MAX=1e5+5;
const ll INF=2e18;
bool isprime[MAX];
vector<ll> vc;
void init()
{
    ms(isprime,true);
    isprime[1]=false;
    for(ll i=2;i*i<=MAX;i++)
    {
        if(isprime[i])
        {
            for(ll j=i*i;j<=MAX;j+=i)
                isprime[j]=false;
        }
    }
    for(ll i=2;i<=MAX;i++)
        if(isprime[i])
        vc.pb(i);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    //init();
    w(t)
    {
        ll n;cin>>n;
        string s;
        cin>>s;
        if(s.length()<=n)
            cout<<s<<endl;
        else {
            for(int i=0;i<n;i++)
                cout<<s[i];
        	cout<<"...\n";}
    }
}
/*
ll msb(ll x)
{
	ll k=(ll)log2(x);
	return (ll)(pow(2,k));
}
#define gc getchar_unlocked
void scanint(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}*/

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
using namespace std;
const db pi = acos(-1.0);
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int N = 1e5 + 10;
int n, lk, cnt;
int val[N], res[N];

bool check()
{
    int sum = 0;
    int num = 0;
    rep(i, 2, n)
    {
        int t = val[i] + val[i - 1];
        if (t > sum)
	        sum = t, num = i - 1;
    }
    cnt = 0;
    if (sum < lk) return 0;
    else
    {
    	rep(i, 1, num - 1)
        	cnt ++, res[cnt] = i;
        rrep(i, n - 1, num + 1)
	        cnt ++, res[cnt] = i;
        cnt ++;
        res[cnt] = num;
        return 1;
    }
}

int main()
{
    n = read();
    lk = read();
    rep(i, 1, n)
    	val[i] = read();
    if (check())
    {
        puts("Possible");
        rep(i, 1, cnt)
	        printf("%d\n", res[i]);
    }
    else puts("Impossible");
    return 0;
}


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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

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

    int ans = a <= 9 && b<= 9 ? a*b : -1;
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

#define INF (1<<(4*4-1))
#define MOD 1000000007

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

   int A,B,C;
   cin>>A>>B>>C;
   cout<<A*B/2<<endl;
   return 0;
}


Measured memory_bytes: 256
import numpy as np

# N, A, B = list(map(int, input().split(" ")))

N = int(input())
A, B = [], []

for _ in range(N):
    a, b = list(map(int, input().split(" ")))
    A.append(a)
    B.append(b)

C = [a + b for a, b in zip(A, B)]

order = np.argsort(C)[::-1]

res = 0

for i in order[::2]:
    res += A[i]
for i in order[1:][::2]:
    res -= B[i]

print(res)

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    int H, W;
    cin >> H >> W;

    if(H == 1 || W == 1) {
        printf("1\n");
        return 0;
    }

    int ans = H * W / 2;
    if(H % 2 != 0 && W % 2 != 0) {
        ans++;
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<map>
#include<tuple>
using namespace std;

int main(void)
{
	string s;
	cin >> s;

	int x, y;
	cin >> x >> y;

	vector<int> movement;
	string str;
	istringstream iss(s);
	while(getline(iss, str, 'T')){
		movement.push_back(str.size());
	}

	const int width = 10000;
	const int sz = width * 2;
	vector<vector<bool>> dpx(movement.size()+1, vector<bool>(sz, false)), dpy(movement.size()+1, vector<bool>(sz, false));

	dpx[0][width] = dpy[0][width] = true;
	dpx[1][width+movement[0]] = dpy[1][width] = true;
	for(int i=1; i<movement.size(); i++){
		// x
		if(i%2 == 0){
			for(int j=0; j<sz; j++){
				dpy[i+1][j] = dpy[i][j];
				if(dpx[i][j] == true){
					dpx[i+1][j+movement[i]] = true;
					dpx[i+1][j-movement[i]] = true;
				}
			}
		}
		// y
		else{
			for(int j=0; j<sz; j++){
				dpx[i+1][j] = dpx[i][j];
				if(dpy[i][j] == true){
					dpy[i+1][j+movement[i]] = true;
					dpy[i+1][j-movement[i]] = true;
				}
			}
		}
	}

	string ret = "No";
	if(dpx[movement.size()][width+x] == true && dpy[movement.size()][width+y] == true)
		ret = "Yes";

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 39808
from sys import stdin
N, M, C = (int(i) for i in input().split())
B = [int(x) for x in stdin.readline().rstrip().split()]
A = [[int(i) for i in input().split()] for i in range(N)]

score = 0
for i in range(N):
    total = 0
    for j in range(M):
        total = total + A[i][j]*B[j]
    total = total + C
    if total > 0:
        score += 1

print(score)



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

int main(void)
{
    int a,b;
    cin >> a >> b;
    if(a == b){cout << a + b << endl;}
    else if(max(a,b) == a){cout << a * 2 - 1 << endl;}
    else{cout << b * 2 - 1 << endl;}
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		// 計算
		String result = "Odd";
		if(a*b%2 == 0) result = "Even";
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cnt[114514];
int main(){
	ll n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		ll a,b;
		cin>>a>>b;
		cnt[a]++;
		cnt[b]++;
	}
	for(int i=1;i<=n;i++){
		if(cnt[i]%2){
			cout<<"NO\n";
			return 0;
		}
	}
	cout<<"YES\n";
	return 0;
}


Measured memory_bytes: 4420
public class Main {
	public static void main(String[] args) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int[] a = new int[1];
		int[] b = new int[1];
		do {
			int x = sc.nextInt();
			if (x == 0) { break;}
			a[a.length - 1] = x;

			b = new int[a.length];
			for (int j = 0;j < a.length;j++){
				b[j] = a[j];
			}
			a = new int[a.length + 1];
			for (int j = 0;j < b.length;j++){
				a[j] = b[j];
			}
		} while (true);
		for (int i = 0;i < b.length;i++) {
			System.out.println("Case " + (i+1) + ": " + b[i]);
		}
	}
}

Measured memory_bytes: 161924
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;
// gcd
LL gcd(LL a, LL b) {
	while(b){
		auto t=a%b;
		a=b;
		b=t;
	}
	return a;
}


const int L=1e4+10;
LL a[L];
bool comp[L];
int main() {
	int N;
	cin >> N;
	for(int i=N;i>=0;i--){
		cin >> a[i];
	}
	LL g=abs(a[N]);
	for(int i=0;i<N;i++){
		g=gcd(g,abs(a[i]));
	}
	vector<int> r;
	for(int i=2;i<L;i++){
		if(comp[i])continue;
		for(int j=i*i;j<L;j+=i){
			comp[j]=true;
		}
		while(g%i==0){
			g/=i;
		}
		if(a[0]%i)continue;
		LL s[L]={};
		for(int j=0;j<=N;j++){
			LL v=a[j]%i;
			if(v<0){
				v+=i;
			}
			s[j%(i-1)]+=v;
		}
		bool ok=true;
		for(int j=0;j<i;j++){
			if(s[j]%i){
				ok=false;
				break;
			}
		}
		if(ok){
			r.push_back(i);
		}
	}
	for(LL i=L;i*i<=g;i++){
		if(g%i==0){
			r.push_back(i);
		}
		while(g%i==0){
			g/=i;
		}
	}
	if(g!=1&&a[0]%g==0){
		r.push_back(g);
	}
	for(auto v:r){
		cout << v << endl;
	}


	return 0;
}



Measured memory_bytes: 1016
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 2**(n//2)%mod
if n % 2 == 0:
    l = n ** 2
else:
    l = (n - 1) * (n + 1)
if sum(a) == l // 2:
    print(ans)
else:
    print(0)

Measured memory_bytes: 13880
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <cstring>
#include <iostream>
#include<iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iterator>
#define debug() puts("what the fuck")
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
const int INF= 0x3f3f3f3f;
const int MAXN= 1e6+10;
const int N=2e5+1;
const int mod=1e9+7;
double PI=3.1415926535898;
typedef long long ll;
/*int fastpow_mod(long long a,long long b)
{
    long long ans=1,base;
    if(a<0)
        base=(a+mod)%mod;
    else
        base=a%mod;
    while(b)
    {
        if(b&1!=0)
            ans=ans*base%mod;
        b=b>>1;
        base=base*base%mod;
    }
    return ans;
}*/
int gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    int n,m;
    cin>>n;
    m=abs(gcd(n,2));
    cout<<2*n/m<<endl;
    return 0;
}


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

using i64 = int64_t;

int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.length();
  vector<string> ss;
  for (int l = 1; l <= k; l++)
    for (int i = 0; i < n - l + 1; i++) {
      ss.push_back(s.substr(i, l));
    }
  sort(ss.begin(), ss.end());
  unique(ss.begin(), ss.end());
  cout << ss[k - 1] << '\n';
}

Measured memory_bytes: 4316
#include<iostream>
#include<cmath>
#include <vector>
using namespace std;

int main() {

  int A = 0;
  int B = 0;
  int C = 0;
  int K = 0;

  cin >> A >> B >> C >> K;

  if (K <= A) {
    cout << K << endl;
    return 0;
  }
  if (K > A && K <= ( A + B )) {
    cout << A << endl;
    return 0;
  }
  if (K > ( A + B ) && K <= ( A + B + C)) {
    cout << A - (K - A - B) << endl;
    return 0;
  }
}

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

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int  N=100000 +10, M=(ll)1e9+1 ;
const int mod =998244353 ,sz=5 ;

void work(){
  ll n;
  cin >> n;
  vl a(n),b(n);
  double p=0;
  for(ll i=0;i<n;i++){
    cin >> a[i];
    p+=(1.0/a[i]);
  }
  p=(1.0)/p;
  cout << fixed << setprecision(6) <<  p;
  
    
}
int main(){
 ios_base::sync_with_stdio(0);
 cin.tie(0);
    ll t;
    // cin >> t;
    t=1;
    while(t--){
            work();
    }
   return 0;

}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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; }



int main()
{
  ll H,W,M; cin>>H>>W>>M;
  vector<pair<ll,ll>> grid(M); 
  rep(i,M) {
    ll y,x; cin>>y>>x; y--; x--;
    grid[i]={x,y};
  }
  
  //各々の行と列
  vector<ll> gyo(H,0);
  vector<ll> retsu(W,0);
  ll max_gyo=0,max_retsu=0;
  for(auto p:grid){
    ll x,y; tie(x,y)=p;
    gyo[y]++; retsu[x]++;
    chmax(max_gyo,gyo[y]);
    chmax(max_retsu,retsu[x]);
  }
  
  //行と列の候補のリストアップ
  vector<ll> gyo_vec(0);
  vector<ll> retsu_vec(0);
  rep(i,H) if(max_gyo==gyo[i]) gyo_vec.push_back(i);
  rep(i,W) if(max_retsu==retsu[i]) retsu_vec.push_back(i);
  
  if(gyo_vec.size()*retsu_vec.size()>M) {cout<<max_gyo+max_retsu<<endl; return 0;}
  
  //list作成
  set<pair<ll,ll>> list;
  for(auto p:grid) list.insert(p);
  
  //解法
  for(auto y:gyo_vec){
    for(auto x:retsu_vec){
      if(!list.count({x,y})) {cout<<max_gyo+max_retsu<<endl; return 0;}
    }
  }
  
  cout<<max_gyo+max_retsu-1<<endl;
  
  return 0;
}

Measured memory_bytes: 33696
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;};
  Mint operator-(Mint a) const{return Mint(v)-=a;};
  Mint operator*(Mint a) const{return Mint(v)*=a;};
  Mint operator/(Mint a) const{return Mint(v)/=a;};

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  // find x s.t. a^x = b
  static T log(T a,T b){
    const T sq=40000;
    unordered_map<T, T> dp;
    dp.reserve(sq);
    Mint res(1);
    for(int r=0;r<sq;r++){
      if(!dp.count(res.v)) dp[res.v]=r;
      res*=a;
    }
    Mint p=Mint(a).inv().pow(sq);
    res=b;
    for(int q=0;q<=MOD/sq+1;q++){
      if(dp.count(res.v)){
        T idx=q*sq+dp[res.v];
        if(idx>0) return idx;
      }
      res*=p;
    }
    assert(0);
    return T(-1);
  }

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  int n,l;
  cin>>n>>l;
  vector<int> ws(n);
  for(int i=0;i<n;i++) cin>>ws[i];
  sort(ws.begin(),ws.end());

  {
    int sum=0;
    for(int w:ws) sum+=w;
    if(sum<=l) drop(1);
  }

  using M = Mint<int>;
  M ans{0};
  int sum=0;
  for(int s=0;s<n;s++){
    vector<M> dp(l+1,0);
    dp[0]=M(1);
    for(int i=s+1;i<n;i++)
      for(int j=l-ws[i];j>=0;j--)
        dp[j+ws[i]]+=dp[j];

    for(int i=l-ws[s]+1;i<=l;i++)
      if(i-sum>=0) ans+=dp[i-sum];

    sum+=ws[s];
    if(sum>l) break;
  }

  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int a,b,c,d;cin >> a >> b >> c >> d;
    vector <int> res(105);
    FOR(i,a,b) res[i]++;
    FOR(i,c,d) res[i]++;
    int result = COUNT(res,2)-1;
    //if (result) cout << COUNT(res,2)-1 << endl;
    if (result == -1) cout << 0 << endl;
    else cout << result << endl;
}

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

const int MAXN=2000001;

int n,q;

int head[MAXN],pnt[MAXN],nxt[MAXN],w[MAXN]={0},vis[MAXN],sum[MAXN]={0};

int po=1;
void add(int a,int b)
{
	pnt[po]=b;
	nxt[po]=head[a];
	
	head[a]=po;
	po++;
	
}

void dfs(int v,int fa)
{
	for(int i=head[v];i!=-1;i=nxt[i]){
		int to=pnt[i];
		if(to!=fa) 
		{
			sum[to]+=sum[v];
			dfs(to,v);
		}
	}
}

signed main(){
	memset(head,-1,sizeof(head));
	scanf("%lld%lld",&n,&q);
	
	for(int i=1;i<=n-1;++i)
	{
		int u,v;
		scanf("%lld%lld",&u,&v);
		add(u,v);
		add(v,u);
	}
	sum[1]=1; 
	
	for(int i=1;i<=q;++i)
	{
		int r,s;
		scanf("%lld%lld",&r,&s);
		sum[r]+=s;
	} 
	cout<<endl;
	dfs(1,0);
	for(int i=1;i<=n;++i)
	{
		cout<<sum[i]-1<<" ";
	} 
	return 0;
}

Measured memory_bytes: 38400
n = gets.to_i
ss = []
n.times { ss << gets.strip }
m = gets.to_i
tt = []
m.times { tt << gets.strip }

ans = 0
ss.each do |w|
  blue = ss.select {|s| s == w}.count
  red = tt.select {|s| s == w}.count
  next if blue - red <= 0
  ans = [ans, blue - red].max
end

puts ans


Measured memory_bytes: 1916
# coding: utf-8
O = input()
E = input()

if len(O) == len(E):
    print("".join([o+e for o,e in zip(O, E)]))
elif len(O) > len(E):
    print("".join([o+e for o,e in zip(O, E)]) + O[-1])
else:
    print("".join([o+e for o,e in zip(O, E)]) + E[-1])

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#define lli long long int
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 57;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;

void solve()
{
    lli n;
    cin>>n;
    cout<<fixed<<setprecision(10);
    double ans = (n + 1) / 2;
    ans /= n;
    cout<<ans;
    return ;
}
/*
7
6 7 4 1 2 11 6
5
1 2 10 4 5
*/

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

    lli t;
    t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int A, B; cin >> A >> B;
    
    int cnt=0;
    for(int i=A; i<=B; ++i){
        string s = to_string(i);
        if(s[0]==s[4] && s[1]==s[3]){ ++cnt; }
    }
    
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const ll MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vll H(N);
    REP(i, N)
        cin >> H[i];
    REPR(i, N-2) {
        if (H[i+1] < H[i])
            H[i]--;
            if (H[i+1] < H[i]) {
                cout << "No" << endl;
                return 0;
            }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1024
def resolve():
	w = ['dream', 'dreamer', 'erase', 'eraser']
	for i in range(len(w)):
		w[i] = w[i][::-1]
	s = input()[::-1]
	t = ''
	for i in s:
		t += i
		if t in w:
			t = ''
	if len(t):
		print("NO")
	else:
		print("YES")
resolve()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using Tuple = tuple<int, int, int>;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<int> r(n+1,0);
    vector<int> g(n+1,0);
    vector<int> b(n+1,0);
    for(int i=n-1; i>=0; i--) {
        if(s[i] == 'R') {
            r[i] = r[i+1] + 1;
            g[i] = g[i+1];
            b[i] = b[i+1];
        } else if(s[i] == 'G') {
            r[i] = r[i+1];
            g[i] = g[i+1] + 1;
            b[i] = b[i+1];
        } else {
            r[i] = r[i+1];
            g[i] = g[i+1];
            b[i] = b[i+1] + 1;
        }
    }

    ll sum = 0;
    rep(i, n) FOR(j, i+1, n) {
        if(s[i] == 'R') {
            if(s[j] == 'G') {
                sum += b[j+1];
                if(j + (j-i) < n && s[j + (j-i)] == 'B') sum--;
            } else if(s[j] == 'B') {
                sum += g[j+1];
                if(j + (j-i) < n && s[j + (j-i)] == 'G') sum--;
            }
        } else if(s[i] == 'G') {
            if(s[j] == 'R') {
                sum += b[j+1];
                if(j + (j-i) < n && s[j + (j-i)] == 'B') sum--;
            } else if(s[j] == 'B') {
                sum += r[j+1];
                if(j + (j-i) < n && s[j + (j-i)] == 'R') sum--;
            }
        } else {
            if(s[j] == 'R') {
                sum += g[j+1];
                if(j + (j-i) < n && s[j + (j-i)] == 'G') sum--;
            } else if(s[j] == 'G') {
                sum += r[j+1];
                if(j + (j-i) < n && s[j + (j-i)] == 'R') sum--;
            }
        }
    }

    cout << sum << endl;

    return 0;

}


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

bool cmp(pair<double,string>& a, pair<double,string>& b){
    if(a.first != b.first){
        return a.first > b.first;
    }else{
        return a.second < b.second;
    }
}

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

        vector<pair<double, string> > v(n);
        for(int i=0; i<n; i++){
            string name;
            int p,a,b,c,d,e,f,s,m;
            cin >>name>>p>>a>>b>>c>>d>>e>>f>>s>>m;
            int get = f*m*s;
            int time = a+b+c +(d+e)*m;
            double rate = (get-p)/(double)time;
            v[i]=make_pair(rate, name);
        }
        sort(v.begin(), v.end(), cmp);

        for(int i=0; i<n; i++){
            cout << v[i].second << endl;
        }
        cout << "#" << endl;
    }
    return 0;
}
        

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	long double a, b, c;
	cin >> a >> b >> c;
	
	// (a + 2sqrt(ab) + b < c
	// 4ab < (c-a-b)^2

	ll x = c-a-b;

	if (x > 0 && 4*a*b < x*x) cout << "Yes" << endl;
	else cout << "No" << endl;

}



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

int main(){
  string s;
  cin>>s;
  int maxcnt=0;
  int cnt=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C'){
      cnt++;
    }else{
      maxcnt=max(cnt,maxcnt);
      cnt=0;
    }
  }
  maxcnt=max(cnt,maxcnt);
  cout<<maxcnt<<endl;
  

}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}
template < typename T, typename U >
ostream &operator<<(ostream &os, const pair< T, U > &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c, i;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

template < typename A, size_t N, typename T >
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> K;
	vector< int > H(N + 1, 0);
	rep(i, N) cin >> H[i + 1];
	vector< vector< int > > dp(N + 1, vector< int >(N + 1, LINF));
	dp[0][0] = 0;
	rep(i, N) rep(j, N) {
		rep(k, i + 1) {
			chmin(dp[i + 1][j + 1], dp[k][j] + max(0LL, H[i + 1] - H[k]));
		}
	}
	int ans = LINF;
	rep(i, N + 1) rep(j, N + 1) {
		if (N - j > K)
			continue;
		chmin(ans, dp[i][j]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4356
/**
 *    author:  FromDihPout
 *    created: 2020-07-26
**/

#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second

const long long INF = 1e18;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    vector<pair<pair<int,int>, int>> edges(m);
    for (int i = 0; i < m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        edges[i] = {{u, v}, w};
    }
    
    vector<long long> score(n, -INF);
    score[0] = 0;
    for (int i = 0; i < n; i++) {
        for (auto e : edges) {
            int u = e.f.f, v = e.f.s, w = e.s;
            if (score[u] >= -INF) {
                score[v] = max(score[v], score[u] + w);
            }
        }
    }
    long long prev = score[n-1];
    for (int i = 0; i < n; i++) {
        for (auto e : edges) {
            int u = e.f.f, v = e.f.s, w = e.s;
            if (score[u] >= -INF) {
                score[v] = max(score[v], score[u] + w);
            }
        }
    }
    if (score[n-1] > prev) {
        cout << "inf" << '\n';
    }
    else {
        cout << prev << '\n';
    }
    return 0;
}

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

ll mod(ll n)
{
    if (n < 0)
        return n + 1000000007;
    else
        return n % 1000000007;
}

int main()
{
    // ll n, sum = 0, d_sum = 0, ans = 0;
    // cin >> n;
    // rep(i, n)
    // {
    //     ll a;
    //     cin >> a;
    //     sum = mod(sum + a);
    //     d_sum = mod(d_sum + mod(a * a));
    // }
    // sum = mod(sum);
    // d_sum = mod(d_sum);

    // cout << mod(mod(mod(sum * sum) - d_sum) / 2) << endl;
    // return 0;
    ll n, sum = 0, ans = 0;
    cin >> n;
    ll a[n], b[n];
    rep(i, n)
    {
        cin >> a[i];
        sum += a[i];
        sum=mod(sum);
    }

    for (ll i = 0; i < n - 1; i++)
    {
        sum -= a[i];
        // sum %= 1000000007;
        sum=mod(sum);
        ans += (a[i] * sum);
        ans=mod(ans);
        // ans %= 1000000007;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5140