akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

vector<pair<int,int>> As[100];

int main() {
	int N, A, x, y;
	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> A;
		for (int j = 0;j < A;j++) {
			cin >> x >> y;
			x--;
			As[i].push_back({ x,y });
		}
	}

	vector<bool> B(N);
	bool jd;
	int c, ans = 0;
	for (int i = 0;i < (1 << N);i++) {
		c = 0;
		jd = 1;
		x = i;
		for (int j = 0;j < N;j++) {
			B[j] = x & 1;
			c += B[j];
			x /= 2;
		}

		for (int j = 0;j < N;j++) {
			if (!B[j])continue;
			for (auto p : As[j]) {
				tie(x, y) = p;
				if (y == 0) {
					if (B[x] == 1) {
						jd = 0;
						break;
					}
				}
				else {
					if (B[x] == 0) {
						jd = 0;
						break;
					}
				}
			}
			if (!jd)break;
		}

		if (!jd)continue;
		ans = max(c, ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string a, b, c;
  cin >> a >> b >> c;
  char dif = 'A' - 'a';
  printf ("%c%c%c\n" , a[0] + dif, b[0] + dif, c[0] + dif);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll l, r;
    cin >> l >> r;
    r = (r - l) >= 2019 ? r = l + 2019 : r;
    ll min = LLONG_MAX;
    for (ll i = l; i < r; i++)
    {
        for (ll k = l + 1; k <= r; k++)
        {
            if (i * k % 2019 < min)
                min = i * k % 2019;
        }
    }
    cout << min << endl;
}


Measured memory_bytes: 256
{-# LANGUAGE PartialTypeSignatures #-}
module Main (main) where

import Control.Monad
import qualified Data.ByteString.Char8 as C8
import qualified Data.Char as C
import qualified Data.List as L

main :: IO ()
main = do
  [n,m,q] <- readInts
  replicateM q readInts >>= output . solve n m

solve :: Int -> Int -> [[Int]] -> _
solve n m xs = fst $ maximum $  map (\v -> (f v, v)) $ gen m n 1
  where
    f vec = sum $ map (\[a,b,c,d] -> if ((vec!!(b-1)) - (vec!!(a-1)))==c then d else 0) xs

    gen m 0 _ = [ [] ]
    gen m n a = [ i:is | i <- [a..m], is <- gen m (pred n) i ]

output :: _ -> IO ()
output = print

-- utils
readInts :: IO [Int]
readInts = L.unfoldr (C8.readInt . C8.dropWhile C.isSpace) <$> C8.getLine

Measured memory_bytes: 6628
#include <bits/stdc++.h>
#include<deque>
#define jio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
//#define mp make_pair
#define pb push_back
#define lld long long int
#define clr clear()
#define ff first
#define ss second
#define N 1000005
//#define M 1000
#define endl '\n'
#define c_s_b() __builtin_popcount()

#define sze 10000009
#define pii pair<int,int>
#define big 100050
#define int long long

using namespace std;
const ll INF = 1e18L+5;
int n,W;
int val[200];
int wt[201];
int dp[105][big];

int ks(int n,int max_val){
        if(max_val==0) return 0;
    if(n<0 || max_val<0){
        return INF;
    }


  /*  if(n==0){
        return val[n];
    }   */
    if(dp[n][max_val]!=-1) return dp[n][max_val];
    if(max_val>=val[n]){

        return dp[n][max_val]=min(ks(n-1,max_val-val[n])+wt[n],ks(n-1,max_val));
    }
     else
         return dp[n][max_val]=ks(n-1,max_val);
    //return dp[n][max_val]=min(ks(n-1,max_val-val[n])+wt[n],ks(n-1,max_val));

}




int32_t main(){
   jio;
    cin>>n>>W;
    int max_val=0;
    for(int i=0;i<n;i++){
        cin>>wt[i]>>val[i];
        max_val+=val[i];
    }
     memset(dp,-1,sizeof(dp));

     int ans=0;
    // cout<<max_val<<endl;
     for(int i=max_val;i>=0;i--){
        if(ks(n-1,i)<=W){
            ans=i;
            break;
        }

     }

     cout<<ans<<endl;













    return 0;


}


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

const int MAXN = 2000, mod = 1e9+7;

int dp[MAXN*2+5][MAXN*2+5];

int n;
int u[200005], v[200005];

int fac[MAXN*5+5], ifac[MAXN*5+5], inv[MAXN*5+5];

inline int choose(int n, int m)
{ return (long long)fac[n]*ifac[m]%mod*ifac[n-m]%mod; }

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &u[i], &v[i]);
		dp[-u[i]+MAXN][-v[i]+MAXN]++;
	}
	for (int i = 0; i <= MAXN*2; i++) {
		for (int j = 0; j <= MAXN*2; j++) {
			if (i) (dp[i][j] += dp[i-1][j]) %= mod;
			if (j) (dp[i][j] += dp[i][j-1]) %= mod;
		}
	}
	fac[0] = ifac[0] = 1, inv[1] = 1;
	for (int i = 2; i <= MAXN*5; i++) inv[i] = (mod-(long long)mod/i*inv[mod%i]%mod)%mod;
	for (int i = 1; i <= MAXN*5; i++) fac[i] = (long long)fac[i-1]*i%mod, ifac[i] = (long long)ifac[i-1]*inv[i]%mod;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		(ans += dp[u[i]+MAXN][v[i]+MAXN]) %= mod;
		(ans += mod-choose(u[i]*2+v[i]*2, u[i]*2)) %= mod;
	}
	cout << ((long long)ans*inv[2]%mod+mod)%mod << endl;
	return 0;
}


Measured memory_bytes: 64512
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MOD = 1000000007;

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


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

void solve() {
    int q;
    std::string s;
    std::cin >> q >> s;

    int ans = 0;
    while (q--) {
        std::string t;
        std::cin >> t;
        int m = t.length();

        bool ok = false;
        for (int l = 1; l < m; ++l) {
            for (int i = 0; i < m; ++i) {
                int j = i;
                bool judge = true;

                for (char c : s) {
                    if (j >= m || t[j] != c) judge = false;
                    j += l;
                }

                if (judge) ok = true;
            }
        }

        if (ok) ++ans;
    }

    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}



Measured memory_bytes: 3216
def calc(x, y, z):
    return (x + y + z) ** 2 - x * y - y * z - z * x

def comb(x):
    fact = 1
    while x > 1:
        fact *= x
        x -= 1
    return fact

N = int(input())
res = [0] * (N + 1)
for i in range(1, 100):
    for j in range(i, 100):
        for k in range(j, 100):
            tmp = calc(i, j, k)
            if tmp > N:
                continue
            cnt = len(set([i, j, k]))
            res[tmp] += 6 // comb(4 - cnt)
print(*res[1:], sep='\n')

Measured memory_bytes: 9372
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){

    int i, N, M, count=0;
    scanf("%d%d",&N,&M);
    int table[N+1], heat[N+1];

    for(i=0;i<=N;i++){
        table[i] = 1;
    }

    for(i=1;i<=N;i++){
        scanf("%d",&heat[i]);
    }

    for(i=0;i<M;i++){
        int a, b;
        scanf("%d%d",&a, &b);
        if(heat[a]==heat[b]){
            table[a]--;
            table[b]--;
        }else if(heat[a]<heat[b]){
            table[a]--;
        }else{
            table[b]--;
        }
    }

    for(i=1;i<=N;i++){
        if(table[i]==1){
            count++;
        }
    }

    printf("%d",count);

    return 0;
}

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

int h, w;
bool naka(int x, int y){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

string maptmp;
queue<pair<pair<int, int>,  int> > que;

int maps[1010][1010];

int main(){

  cin >> h >> w;
  for(int i = 0;i < h;i++){
    cin >> maptmp;
    for(int j = 0;j < w;j++){
      if(maptmp[j] == '.'){
        que.push(make_pair(make_pair(i,j),0));
        maps[i][j] = 0;
      }else{
        maps[i][j] = maptmp[j] - '0';
      }
    }
  }

  int ans = 0;
  pair<pair<int, int>, int> data;

  while(!que.empty()){
    data = que.front();
    que.pop();
    ans = max(ans, data.second);

    int y = data.first.first;
    int x = data.first.second;
    for(int i = -1;i <= 1;i++){
      for(int j = -1;j <= 1;j++){
        if(naka(x+j,y+i) && maps[y+i][x+j] > 0){
          maps[y+i][x+j]--;
          if(maps[y+i][x+j] == 0){
            que.push(make_pair(make_pair(y+i,x+j),data.second+1));
          }
        }
      }
    }
  }

  cout << ans << endl;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<string> S(N);
    for(int i=0; i<N; i++) cin >> S.at(i);

    vector<string> rs;
    for(auto &s : S)
    {
        for(auto itr = s.begin(); itr != s.end();)
        {
            if(*itr == '(' && *(itr+1) == ')')
            {
                itr = s.erase(itr, itr+2);
                itr--;
            }
            else itr++;
        }
        // cout << s << endl;
        if(!s.empty()) rs.push_back(s);
    }

    auto comp = [](string &a, string &b){
        auto aitr = a.find_first_of('(');
        int alsize = (aitr == string::npos ? a.size() : aitr);
        int arsize = a.size() - alsize;
        int adiff = arsize - alsize;
        auto bitr = b.find_first_of('(');
        int blsize = (bitr == string::npos ? b.size() : bitr);
        int brsize = b.size() - blsize;
        int bdiff = brsize - blsize;
        if((adiff >= 0) && (bdiff < 0)) return true;
        if(adiff >= 0 && bdiff >= 0) return alsize < blsize;
        if(adiff < 0 && bdiff < 0) return arsize > brsize;
        return false;
    };

    sort(rs.begin(), rs.end(), comp);

    int cnt = 0;
    int ans = 0;
    for(int i=0; i<rs.size(); i++)
    {
        for(auto c : rs[i])
        {
            if(cnt <= 0 && c == ')') ans++;
            else if(c == ')') cnt--;
            else cnt++;
        }
    }
    // for(auto s : rs) cout << s;
    // for(int i=0; i<rs.size(); i+=rs.size()/20) cout << rs[i] << '\n';
    // cout << ans << " " << cnt << endl;
    ans += cnt;
    cout << ((ans==0) ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 67448
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorderBeginnerContest121 {
    class A {
        static void Main(string[] args) {
            string[] HW = Console.ReadLine().Split(' ');
            int H = int.Parse(HW[0]);
            int W = int.Parse(HW[1]);

            string[] hw = Console.ReadLine().Split(' ');
            int h = int.Parse(hw[0]);
            int w = int.Parse(hw[1]);

            Console.WriteLine((H - h) * (W - w));
        }
    }
}

Measured memory_bytes: 13140
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

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

    int N, K, Q;

    cin >> N >> K >> Q;

    vector<int> A(N);

    for(int i = 0; i < Q; i++) {
        int a;
        cin >> a;
        A[a - 1]++;
    }

    for(int i = 0; i < N; i++) {
        if(K - (Q - A[i]) <= 0) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);++i)
#define reps(i,n) for(int i = 1;i <= (n);++i)
using namespace std;
int main(){
  int k,n;
  cin >> n >> k;
  cout << n - k + 1 << '\n';
  return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, m, a, b;

	cin >> n >> m;

	vector<pair<ll, ll>> v;

	REP(i, m) {
		cin >> a >> b;
		v.push_back(make_pair(b, a));
	}

	sort(v.begin(), v.end());

	ll ans = 0;
	ll prev = 0;

	REP(i, m) {
		if (v[i].second > prev) {
			ans++;
			prev = v[i].first - 1;
		}
	}

	cout << ans << endl;
}

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

#define rep(i, n) for(long long i=0;i<n;i++)
using ll = long long;
const ll INF = (1LL<<60);

int main(){

    ll n, r; cin >> n >> r;

    if(n>10){
        cout << r << endl;
    }
    else{
        cout << r+(100*(10-n)) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(int argc, const char * argv[]){
    char s[101], p[100];
    int i=0, j=0,count_s=0, count_p=0,flag = 0, tmp_s;
    
    scanf("%s",s);//sの文字列入力
    scanf("%s",p);//pの文字列入力
    
    for(i=0;s[i]!='\0';i++){//s文字列の長さを求める
        count_s++;
    }
    
    for(i=0;p[i]!='\0';i++){//p文字列の長さを求める
        count_p++;
    }
    
    for(i=0;i<=count_s;i++){//s文字列の最後まで続ける
        if(s[i] == p[j]){//pの始めの文字が見つかった場合
            tmp_s = i;//現在の場所を保存
            while(1){//無限ループ
                if(i == count_s){//探している途中で文字列の最後まで行ったら始めに戻る
                    i = 0;
                }
                
                if(s[i] != p[j]){//探している途中で違う文字を見つけた場合は無限ループを抜けて始めの文字探しに戻る
                    i = tmp_s;
                    j = 0;
                    break;
                }else{
                    i++;
                    j++;//文字が同じだった場合は次の文字に移る
                }
                
                if(j == count_p){//最後まで同じ文字列だった場合
                    i = tmp_s;
                    flag = 1; //フラグが立つ
                    break;
                }
            }
        }
    }
    
    if(flag == 1){ //フラグが立つ（文字列が見つかった場合）
        printf("Yes\n");
    }else{//見つからなかった場合
        printf("No\n");
    }
    
    return 0;
}


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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

using namespace std;

const int maxh = 11, maxw = 1*1000+10;
string s[maxh];
int tmp, h, w, last, ans = 2 * maxw, b[maxh], cnt, k, cur, t[maxh];

int main()
{
	ios::sync_with_stdio(0);
	cin >> h >> w >> k;
	for (int i = 0; i < h; i++)
		cin >> s[i];
	for (int i = 0; i < (1 << (h - 1)); i++)
	{
		last = -1;
		cur = __builtin_popcount(i);
		tmp = i;
		memset(t, 0, sizeof t);
		for (int j = 0; j < h - 1; j++, tmp >>= 1)
			b[j] = tmp & 1;
		for (int j = 0; j < w; j++)
		{
			cnt = 0;
			for (int l = 0; l < h; l++)
			{
				t[cnt] += s[l][j] - '0';
				if (t[cnt] > k)
				{
					if (last == j)
					{
						last = maxw;
						cur = 2 * maxw;
						break;
					}
					last = j;
					cur++;
					memset(t, 0, sizeof t);
					j--;
					break;
				}
				if (b[l])
					cnt++;
			}
			if (last == maxw)
				break;
		}
		ans = min(ans, cur);
	}
	cout << ans;
	return 0;
}


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

int main() {
	
	long A = 0;
	long B = 0;
	long C = 0;
	long K = 0;

	scanf("%ld %ld %ld", &A, &B, &K);

	if (A < K) {
		C = K - A;
		A = 0;
		B = B - C;
      if (B < 0){
        B = 0;
      }
	}
	else {
		A = A - K;
	}

	printf("%ld %ld", A, B);

	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

int pop_count(int x) {
	int ct = 0;
	while (x > 0) {
		ct += x % 2;
		x /= 2;
	}
	return ct;
}


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

	int MAXN = 200100, n, i, j, k, ct, x, r;
	string s;

	vector<long long> c(MAXN);
	c[0] = 0;
	for (i = 1; i < MAXN; i++) c[i] = 1 + c[i % pop_count(i)];
	   
	cin >> n >> s;
	ct = 0;
	for (auto ch : s) {
		if (ch == '1') ct++;
	}

	vector<long long> ans(n);
	   	 
	if (ct == 0) ans.assign(n, 1);
	else {
		// calculate all 0 bits
		vector<long long> v1(n);
		v1[n - 1] = 1;
		for (i = n - 2; i >= 0; i--) {
			v1[i] = (v1[i + 1] * 2) % (ct + 1);
		}
		r = 0;
		x = 1;
		for (i = n - 1; i >= 0; i--) {
			r = (r + (s[i] - '0') * x) % (ct + 1);
			x = (x * 2) % (ct + 1);
		}

		for (i = 0; i < n; i++) {
			if (s[i] == '0') {
				x = (r + v1[i]) % (ct + 1);
				ans[i] = 1 + c[x];
			}
		}

		// calculate all 1 bits
		if (ct == 1) {
			for (i = 0; i < n; i++) {
				if (s[i] == '1') {
					ans[i] = 0;
				}
			}
		}
		else {
			vector<int> v2(n);
			v2[n - 1] = 1;
			for (i = n - 2; i >= 0; i--) {
				v2[i] = (v2[i + 1] * 2) % (ct - 1);
			}
			r = 0;
			x = 1;
			for (i = n - 1; i >= 0; i--) {
				r = (r + (s[i] - '0') * x) % (ct - 1);
				x = (x * 2) % (ct - 1);
			}

			for (i = 0; i < n; i++) {
				if (s[i] == '1') {
					x = (r + (ct - 1) * 100 - v2[i]) % (ct - 1);
					ans[i] = 1 + c[x];
				}
			}
		}
	}

	for (i = 0; i < n; i++) cout << ans[i] << "\n";

	return 0;
}


Measured memory_bytes: 8584
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  int n;
  cin>>n;
  for(int i=0;i<1000;i++){
    string s=to_string(n+i);
    if(s[0]==s[1]&&s[1]==s[2]){
      cout<<s<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
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 beki(int a, int n){
    if(n == 0) return 1;
    ll ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1) ans = ans * a;
    return ans;
}

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

    string S; cin >> S;
    ll K; cin >> K;
    int n = S.size();
    bool allsame = true;
    rep(i,n-1) {
        if(S[i] != S[i+1]) { allsame = false; break; }
    }
    if(allsame) {
        ll ans = n * K;
        cout << ans / 2 << endl;
        return 0;
    }

    if(S[0] != S[n-1]) {
        int l = 0;
        int cnt = 1;
        rep(i,n-1){
            if(S[i] == S[i+1]) cnt++;
            else {
                l += cnt / 2;
                cnt = 1;
            }
        }
        l += cnt / 2;
        ll ans = K * l;
        cout << ans << endl;
    }
    else {
        int l = 0;
        int cnt = 1;
        rep(i,n-1){
            if(S[i] == S[i+1]) cnt++;
            else {
                l += cnt / 2;
                cnt = 1;
            }
        }
        l += cnt / 2;
        ll ans = K * l;

        string T = S + S;
        int i = 0;
        while(T[n-1-i] == T[n-1]) i++;
        int j = 0;
        while(T[n] == T[n+j]) j++;
        int sub = (i+j) / 2 - i / 2 - j / 2;
        ans += (K - 1) * sub;
        cout << ans << endl; 
    }


    return 0;
}

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

#define BOLT ios_base::sync_with_stdio(0)
#define newline cout << "\n"
#define eline cerr << "\n"
#define LL_MAX 9223372036854775807
#define LL_MIN -9223372036854775808
#define IN_FILE freopen("input.txt", "r", stdin)
#define OUT_FILE freopen("output.txt", "w", stdout)

long long arr[100000+2][3];
long long dp[100000+2][3];
int n;

// g++ -o contest contest.cpp

void USEFILE(){
    IN_FILE;
    OUT_FILE;
}

void reset(){
    memset(arr, 0, sizeof arr);
    memset(dp, -1, sizeof dp);
}

long long process(int i, int j){

     // cout << "Incoming: " << i << " " << j; newline;

    if(i >= n) return 0;
    if(dp[i][j] != -1) return dp[i][j];
    long long ans = 0;
    for(int k = 0 ; k < 3; k++){
        if(k == j && i != 0) {
            continue;
        }
        // cout << "\tOutgoing: " << i << " " << j;newline;
        ans = max(ans , arr[i][k] + process(i+1, k));
    }
    dp[i][j] = ans;
    return ans;
}



void solve(int kase){
    reset();
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < 3 ; j++){
            cin >> arr[i][j];
        }
    }
    cout << process(0,0);newline;
}


int main(){
    BOLT;
    // USEFILE();
    int t, kase = 0;
    // cin >> t;
    // while(t--)
    //      solve(++kase);
    solve(0);

return 0;
}


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

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

bool contains(string s, string t) {
    int n = s.size()/2;
    REP(i,n) {
        string ss = s.substr(i,t.size());
        if (ss == t) return true;
    }
    return false;
}

bool iscyclic(string s, string t) {
    if (contains(s, t)) return true;
    else return false;
}

int main() {
    string s, t;
    cin >> s >> t;
    s += s;
    if (iscyclic(s, t)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(){
  int n, m; cin >> n >> m;
  int ans = 0;
  for (int i = 1; i <= 1e5; i++) {
    if (m % i == 0) {
      if (i >= n) ans = max(m/i, ans);
      if (m/i >= n) ans = max(i, ans);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    for(int num = A; num <= 100000; num += A) {
        if(num % B == C) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long A, long long B, long long N) {
  lli ret = 0;

  rep(i, min(A + 1, N + 1)) { chmax(ret, (A * i) / B - A * (i / B)); }
  chmax(ret, (A * N) / B - A * (N / B));
  if (B - 1 <= N) {
    chmax(ret, ((A * (B - 1)) / B));
  }
  cout << ret << endl;
}

signed main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long N;
  scanf("%lld", &N);
  solve(A, B, N);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 3692
N = gets.chomp.to_i
a = {}
N.times do |i|
  a[i+1] = gets.chomp.split(" ").map(&:to_i)
end

require "set"

days = 0
cnt = 0
vs = Set.new
players = Set.new((1..N))
total_cnt = N * (N - 1) / 2

until players.empty?
  days += 1
  players.each do |i|
    next if vs.include?(i) || a[i].empty?

    i2 = a[i].first
    next if i != a[i2].first || vs.include?(i2)

    vs << a[i].shift
    vs << a[i2].shift
    cnt += 1
  end
  if cnt >= total_cnt
    puts days
    exit 0
  end
  players = vs
  vs = Set.new
end

puts "-1"


Measured memory_bytes: 56980
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxLim 65530

#define inchar			getchar//_unlocked
#define outchar(x)		putchar(x)//_unlocked(x)

template<typename T> void inpos(T &x) {
	x = 0;
	register T c = inchar();
	while(((c < 48) || (c > 57)) && (c != '-')) c = inchar();
	bool neg = false;
	if (c=='-') neg = true;
	for(; c < 48 || c > 57; c = inchar()) ;
	for(; c > 47 && c < 58; c = inchar()) {
		x = (x<<3) + (x<<1) + (c&15);
	}
	if(neg) x = -x;
}

template<typename T> void outpos(T n) {
	if(n < 0) { outchar('-'); n *= -1; }
	char snum[65];
	int i = 0;
	do {
		snum[i++] = n % 10 + '0';
		n /= 10;
	} while(n);
	i = i - 1;
	while (i >= 0) outchar(snum[i--]);
}
double tick() { 
	static clock_t oldticks;
	clock_t newticks = clock();
	double diff = 1.0 * (newticks - oldticks) / CLOCKS_PER_SEC; 
	oldticks = newticks;
	return diff;
}

int main () {
	int n,k;
	inpos(n);
	inpos(k);
	int arr[n+200] = {0};
	for (int i = 0;i<n;i++) {
		inpos(arr[i]);
	}
	for (int i  = n;i<n+200;i++) {
		arr[i] =arr[n-1];
	}
	// for (int i = 0;i<n+200 ; i++) {
	// 	outpos(arr[i]);
	// 	outchar(' ');
	// }
	// arr[n]=arr[n-1];
	// arr[n+1] = arr[n];
	int dp[n+200]={0};
	
	// same but i+1 ....i+2 ke jagah i + 
	int temp;
	for (int i = n-1;i>=0;i--) { // nth wale stone pe 
		// dp [i] = min (dp[i+1] + abs(arr[i] -arr[i+1] ), dp[i+2] + abs(arr[i+2] - arr[i] )) ;
		int mini = __INT_MAX__;
		for (int j = 1;j<=k ;j++ ) {
			temp = dp[i+j] + abs(arr[i] - arr[i+j]);
			// cout <<" T " <<temp<< endl;
			if (temp < mini) {
				mini = temp;
			}
		}
		dp [i] = mini;

	}
	outpos(dp[0]) ;//outchar(' ');
	// 
}

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

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

  for(int i=a;i<=b;i++){
    if(i%k==0){
      x=1;
    }
  }
  if(x==1){
    cout<<"OK";
  }else{
    cout<<"NG";
  }
}


Measured memory_bytes: 3628
/*
ID: Barry Wang
LANG: C++11
TASK: 
*/
#include <bits/stdc++.h>
using namespace std;
/*---define tricks---*/
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define revsort(b,e) sort(b,e),reverse(b,e)
#define X first
#define Y second
#define Chtolly return 0
/*---define types---*/
typedef long long ll;
typedef list<int> li;
typedef queue<int> qi;
typedef deque<int> dqi;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef unsigned int uint;
/*---define variables---*/
const int inf=(1<<29);
int k; 
int cnt;
int head[1000005],from[1000005],to[1000005],nxt[1000005],val[1000005];
bool vis[1000005];
int dis[1000005];
queue<int> q;
/*---define function---*/

void add(int x,int y,int w){
	from[++cnt]=x;
	to[cnt]=y;
	val[cnt]=w;
	nxt[cnt]=head[x];
	head[x]=cnt;
}

void BFS(){
	memset(vis,0,sizeof(vis));
	memset(dis,0x3f,sizeof(dis));
	dis[1]=0;
	vis[1]=1;
	q.push(1);
	while(!q.empty()){
		int x=q.front();
		q.pop(); 
		vis[x]=0;
		for(int i=head[x];i;i=nxt[i]){
			int y=to[i];
			if(dis[y]>dis[x]+val[i]){
				dis[y]=dis[x]+val[i];
				if(!vis[y]){
					vis[y]=1;
					q.push(y);
				}
			}
		}
	}
}

/*---main code---*/
int main(){
	FIO;
	cin>>k;
	for(int i=0;i<k;++i){
		int x=i,y=(i+1)%k,yy=(i*10)%k;
		add(x,y,1);
		add(x,yy,0);
	}
	BFS();
	cout<<dis[0]+1<<'\n';
	return 0;
}


Measured memory_bytes: 14720
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()

    lS = list(S)
    acnt = 0
    ans = 0
    for i in range(len(S) - 2):
        if lS[i] == "A":
            acnt += 1
        else:
            acnt = 0

        if lS[i] == "A" and lS[i + 1] == "B" and lS[i + 2] == "C":
            ans += acnt
            lS[i + 2] = "A"
            if acnt > 1:
                lS[i + 1] = "A"
                acnt -= 2

    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 10576
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pm(m) for(auto itr=(m).begin();itr!=(m).end();itr++){itr->first<<" "<<itr->second<<"\n";}
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
#define bug(x) cout<<(x)<<" ";exit(0);
int mod = 1000000007;
int mod1 = 998244353;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
vector<int> g[Max];
bool vis[Max];
int d, x, y;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
void ex(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        ex(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}


void dfs(int u){

	vis[u]=1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(vis[v]!=1)
			dfs(v);
	}
}



int power(int a,int b){
    if(b==1)return a;
    if(a>mod)a%=mod;
    int r=1;
    while(b){
        if(b&1)r=r%mod*a%mod;
        a=a%mod*a%mod;
        b/=2;
    }
    return r;
}
class uf{
    vector<int> v;
    vector<int> sz;
    
    
    public :
    uf(int n){
        v.resize(n+1);
        iota(v.begin()+1,v.end(),1);
        sz.resize(n+1,1);
        //1 to sz
    }
    int root(int b){
        while(v[b]!=b){
            b = v[b];
        }   
        return b;
    }
    void u(int a, int b){
        //combine a and b
        
        int ra=root(a);
        int rb=root(b);
        if(ra==rb)return ;
        if(sz[ra]<sz[rb]){
            v[ra] = v[rb];
            sz[rb]+=sz[ra];
        }else{
            v[rb]=v[ra];
            sz[ra]+=sz[rb];
        }
    }
    bool f(int a,int b){
        //same set
        return (root(a)==root(b));
    }
   
    
};
vector<int> matmul(vector<int> a,vector<int> b){
    vector<int> c(4,0);
    c[0] = (a[0]%mod*b[0]%mod + a[1]%mod*b[2]%mod)%mod;
    c[1] = (a[0]%mod*b[1]%mod + a[1]%mod*b[3]%mod)%mod;
    c[2] = (a[2]%mod*b[0]%mod + a[3]%mod*b[2]%mod)%mod;
    c[3] = (a[2]%mod*b[1]%mod + a[3]%mod*b[3]%mod)%mod;
    return c;
}
vector<int> id={1,0,0,1};

int32_t main(){
	IO
	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
    int x,k,d;
    cin>>x>>k>>d;
    if(x<0)x*=-1;
    int mn = x/d;
    
    
    if(k<=mn){
        x-=k*d;
        cout<<x<<"\n";
    }
    else{
        x-=mn*d;
        int left = k-mn;
        if(left%2==0){
            cout<<abs(x)<<"\n";
        }
        else{
            cout<<abs(x-d)<<"\n";
        }
    }
}

Measured memory_bytes: 5964
#include<stdio.h>

int main()
{
  int a, b, c, box, i;
  scanf("%d %d %d", &a, &b, &c);
  for (i = 0; i < 3; i++){
    if (a > b) {
      box = a;
      a = b;
      b = box;
    } else if (b > c) {
      box = b;
      b = c;
      c = box;
    } else if (a > c) {
      box = c;
      c = a;
      a = box;
    }
  }
  printf("%d %d %d\n", a, b, c);
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class A
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		var S = GetString();
		int N = S.Length;
		if(N % 2 == 1)
		{
			WriteLine("No");
			return;
		}
		for(int i = 0; i < N; i+= 2)
		{
			if(!S.Substring(i, 2).Equals("hi"))
			{
				WriteLine("No");
				return;
			}
		}
		WriteLine("Yes");
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 13140
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#include<vector>
using namespace std;
int main(){
    int N,X;cin>>N>>X;
    vector<int>D(N+1);
    D[0] = 0;
    for(int i=1;i<=N;i++){
        int L;cin>>L;
        D[i] = L+D[i-1];
    }

    int ans=0;
    //cout << D.size()<<endl;
    for(int i=0;i<D.size();i++){
        //cout << D[i] << endl;
        if(D[i] <= X){
            ans++;
        }

    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int l = a + b;
	int r = c + d;
	if (l > r) {
		cout << "Left\n";
	}
	else if (l == r) {
		cout << "Balanced\n";
	}
	else {
		cout << "Right\n";
	}
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <chrono>
#include<bitset>
#include<deque>
#include <map>
#define vint vector<int>
#define vint2 vector<vint>
#define vchar vector<char>
#define vchar2 vector<vchar> 
#define vchar3 vector<vchar2> 
#define pr pair<int,int>
#define vpr vector<pr>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
typedef  long long int ll;
using namespace std;
//CHAR_BIT	ビット フィールドではない最小変数のビット数。	8
//SCHAR_MIN	signed char 型変数の最小値。	–128
//SCHAR_MAX	signed char 型変数の最大値。	127
//UCHAR_MAX	unsigned char 型変数の最大値。	255 (0xff)
//CHAR_MIN	char 型変数の最小値。 - 128、 / J オプション使用時は 0
//CHAR_MAX	char 型変数の最大値。	127、 / J オプション使用時は 255
//MB_LEN_MAX	多文字定数の最大バイト数。	5
//SHRT_MIN	short 型変数の最小値。	–32768
//SHRT_MAX	short 型変数の最大値。	32767
//USHRT_MAX	unsigned short 型変数の最大値。	65535 (0xffff)
//INT_MIN	int 型変数の最小値。	–2147483647 – 1
//INT_MAX	int 型変数の最大値。	2147483647
//UINT_MAX	unsigned int 型変数の最大値。	4294967295 (0xffffffff)
//LONG_MIN	long 型変数の最小値。	–2147483647 – 1
//LONG_MAX	long 型変数の最大値。	2147483647
//ULONG_MAX	unsigned long 型変数の最大値。	4294967295 (0xffffffff)




int  main(){
	ll N;
	cin >> N;
	int mode = -1;
	ll b;
	int cnt = 1;
	REP(i, N){
		ll a;
		cin >> a;
		if (i == 0)b = a;
		if (mode == -1){
			if (a > b){ mode = 0; }
			if (a < b){ mode = 1; }
		}
		else if (mode == 0){
			if (a < b){ mode = -1; cnt++; }
		}
		else{
			if (a>b){ mode = -1; cnt++; }
		}

		b = a;
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  cin>>k;
  vector<long long> v;
  for(int i=1;i<=9;i++)
    v.push_back(i);
    for(int i=0;i<v.size();i++){
      if(v.size()>=k)
        break;
      if(v[i]%10==0){
        v.push_back(v[i]*10);
        v.push_back(v[i]*10+1);
      }
      else{
        if(v[i]%10==9){
          v.push_back(v[i]*10+8);
          v.push_back(v[i]*10+9);
        }
        else{
          v.push_back(v[i]*10+v[i]%10-1);
          v.push_back(v[i]*10+v[i]%10);
          v.push_back(v[i]*10+v[i]%10+1);
        }
      }
    }
  cout<<v[k-1];
}

Measured memory_bytes: 1400
import sys
def main():
    N,x=tuple(map(int,sys.stdin.readline().split()))
    A=list(map(int,sys.stdin.readline().split()))
    pa,r=0,0
    for a in A:
        c=a+pa-x
        if c>0:
            r+=c
            pa=a-c
        else:pa=a
    print(r)
if __name__=='__main__':main()

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a);i < (b);++i)
#define FORR(i, b, a) for (int i = (b) - 1;i >= 0;--i)
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = (n) - 1;i >= 0;--i)
#define ITER(itr, v) for(auto itr = v.begin();itr != v.end();++itr)
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N;
	cin >> N;
	vector<int> L(N);
	REP(i, N) cin >> L[i];
	SORT(L);
	ll res = 0;
	for (int i = 0;i < N - 2;++i) {
		for (int j = i + 1;j < N - 1;++j) {
			int k = lower_bound(L.begin() + j + 1, L.end(), L[i] + L[j]) - L.begin();
			res += k - j - 1;
		}
	}
	cout << res << endl;

	return 0;
}

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

using namespace std;

bool backtrack(int r, string& s, vector<char>& ops)
{
	auto i = ops.size();
	if (i == 3) return r == 7;
	ops.push_back('+');
	if (backtrack(r + s[i+1] - '0', s, ops)) return true;
	ops.back() = '-';
	if (backtrack(r - s[i+1] + '0', s, ops)) return true;
	ops.pop_back();
	return false;
}

int main()
{
	string s;
	cin >> s;
	vector<char> ops;
	backtrack(s[0]-'0', s, ops);
	cout << s[0] << ops[0] << s[1] << ops[1] << s[2] << ops[2] << s[3] << "=7" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 	int n;
  	string s;
  	cin >> n;
  	cin >> s;
  	if(n < 3200){
      cout << "red" << endl;
    } else{
      cout << s << endl;
    }
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a.at(i);
    }
    vector<int> hoge(n);
    hoge=a;
    sort(hoge.begin(), hoge.end());
    int max=hoge.at(n-1);
    int next_max=hoge.at(n-2);
    for(int i=0; i<n; i++){
        if(a.at(i)==max){
            cout<<next_max<<endl;
        }else{
            cout<<max<<endl;
        }
    }
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  char s[101];
  char t[101];
  char tmp;
  int i, j;
 
  scanf("%s",s);
  scanf("%s",t);
  
  for(i=0;i<(int)strlen(s)-1;i++){
    for(j=i+1;j<(int)strlen(s);j++){
      if(s[i] > s[j]){
        tmp = s[i];
        s[i] = s[j];
        s[j] = tmp;
      }
    }
  }
  for(i=0;i<(int)strlen(t)-1;i++){
    for(j=i+1;j<(int)strlen(t);j++){
      if(t[i] < t[j]){
        tmp = t[i];
        t[i] = t[j];
        t[j] = tmp;
      }
    }
  }
  if(strcmp(s,t)<0)
    printf("Yes\n");
  else
    printf("No\n");
  
  return 0;
}
  

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque
from operator import itemgetter
from heapq import heappop, heappush
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
H, W = inpl()
G = [[1]*(W+2)]
for _ in range(H):
    G.append([1] + [int(s=="#") for s in input()] + [1])
G.append([1]*(W+2))

ans = 0
for h in range(1, H+1):
    for w in range(1, W+1):
        if G[h][w] == 1:
            continue
        dist = [[-1]*(W+2) for _ in range(H+2)]
        dist[h][w] = 0
        Q = deque()
        Q.append([h, w])
        while Q:
            ph, pw = Q.popleft()
            for dh, dw in [[0, 1], [1, 0], [-1, 0], [0, -1]]:
                qh, qw = ph+dh, pw + dw
                if G[qh][qw]:
                    continue
                if dist[qh][qw] == -1:
                    dist[qh][qw] = dist[ph][pw] + 1
                    Q.append([qh, qw])
                
        for y in range(1, H+1):
            for x in range(1, W+1):
                ans = max(ans, dist[y][x])
print(ans)

Measured memory_bytes: 46044
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

int main() {
    int N;
    cin >> N;
    long long ret = 0;
    for(int i=0; i<=N; ++i) {
        if((i % 3 == 0) || (i % 5 == 0)) {
            continue;
        }
//        cout << i << endl;
        ret += i;
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	cin >> s;
	bool ans = true;

	for (int i = 0; i < s.length(); i++) {
		if (i % 2 == 0) {
			if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') ans = false;
		}
		else if (i % 2 != 0) {
			if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') ans = false;
		}
	}
	if (s.length() == 0) cout << "No" << endl;
	else if (ans == false) cout << "No" << endl;
	else cout << "Yes" << endl;


	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	p := iSScan(n)
	fmt.Println(sum(p) - max(p)/2)
}


Measured memory_bytes: 1776
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define ll long long

void solve()
{
    ll N, K, Q;
    cin >> N >> K >> Q;

    vector<ll> A(Q);
    vector<ll> point(N, K - Q);
    for (ll i = 0; i < Q; i++)
    {
        cin >> A.at(i);
        point.at(A.at(i) - 1)++;
    }

    for (ll i = 0; i < N; i++)
    {
        cout << (point.at(i) > 0 ? "Yes" : "No") << endl;
    }
}

// 各参加者の得点の式 K - Q + 正解数
// これを作り、最後に列挙して終わる

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 2176
#include <cstdio>
using namespace std;

int main(void)
{
    
    while (1){
        int n;
        scanf("%d", &n);
        if (n == 0) break;
        
        int A, B;
        int A_sum = 0, B_sum = 0;
        
        for (int i = 0; i < n; i++){
            scanf("%d %d", &A, &B);
            
            if (B < A){
                A_sum += A + B;
            }
            else if (A < B){
                B_sum += A + B;
            }
            else {
                A_sum += A;
                B_sum += B;
            }
        }
        
        printf("%d %d\n", A_sum, B_sum);
        
    }
    
    return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
#define ALL(a) a.begin(),a.end()
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

bool IsPrime(ll num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}

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

    ll ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

int kunt[N + N];

vector < int > inp;

int main(){
    int n, k;
    fastScan(n); fastScan(k);
    for(int i = 1; i <= n; i++){
        int x; fastScan(x);
        kunt[x]++;
    }
    for(int i = 1; i < N + N; i++){
        if(kunt[i] > 0) inp.pb(kunt[i]);
    }
    sort(inp.rbegin(), inp.rend());
    int ans = 0;
    while(inp.size() > k){
        ans += inp.back();
        inp.pop_back();
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 2168