akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

void addtosyoutai(int*,int*,int,int,int);

int main(void) {
	int ninsuu;
	int friends[500*500];
	int listlength;
	int syoutai[500];
	int tomodatia;
	int tomodatib;
	int i;
	int ii;
	int syoutaininsuu;
	while(1) {
		scanf("%d",&ninsuu);
		scanf("%d",&listlength);
		if(ninsuu==0 && listlength==0)break;
		for(i=0;i<ninsuu;i++) {
			for(ii=0;ii<ninsuu;ii++) {
				friends[i*500+ii]=0;
			}
			syoutai[i]=0;
		}
		for(i=0;i<listlength;i++) {
			scanf("%d %d",&tomodatia,&tomodatib);
			friends[(tomodatia-1)*500+(tomodatib-1)]=1;
			friends[(tomodatib-1)*500+(tomodatia-1)]=1;
		}
		addtosyoutai(friends,syoutai,0,ninsuu,1);
		syoutaininsuu=0;
		for(i=1;i<ninsuu;i++) {
			if(syoutai[i])syoutaininsuu++;
		}
		printf("%d\n",syoutaininsuu);
	}
	return 0;
}

void addtosyoutai(int friends[],int syoutai[],int you,int ninsuu,int gonext) {
	 int i;
	 for(i=0;i<ninsuu;i++) {
		 if(friends[you*500+i]) {
			 syoutai[i]=1;
			 if(gonext)addtosyoutai(friends,syoutai,i,ninsuu,0);
		 }
	 }
}

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    string s;
    cin >> s;
    while(s.pop_back(), 1){
        if(s.size() % 2 == 0 && s.substr(0, s.size() / 2) == s.substr(s.size() / 2))
            break;
    }
    cout << s.size() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll NIL = -1;
const ll MAX = 100005;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

struct Node {
  ll parent;
  ll left;
  ll right;
};

vector <Node> t(MAX);
vector <ll> d(MAX);

void print(ll u) {
  cout << "node " << u << ": ";
  cout << "parent = " << t.at(u).parent << ", ";
  cout << "depth = " << d.at(u) << ", ";
  
  if (t.at(u).parent == NIL) {
    cout << "root, ";
  } else if (t.at(u).left == NIL) {
    cout << "leaf, ";
  } else {
    cout << "internal node, ";
  }
  
  cout << '[';
  for (ll i = 0, c = t.at(u).left; c != NIL; i++, c = t.at(c).right) {
    if (i) cout << ", ";
    cout << c;
  }
  cout << ']' << endl;
  return;
}

void setDepth(ll u, ll p) {
  d.at(u) = p;
  if (t.at(u).right != NIL) setDepth(t.at(u).right, p);
  if (t.at(u).left != NIL) setDepth(t.at(u).left, p+1);
  return;
}

int main() {
  ll n;
  cin >> n;
  rep(i, n) {
    t.at(i).parent = NIL;
    t.at(i).left = NIL;
    t.at(i).right = NIL;
  }
  ll id, k, l;
  rep(i, n) {
    cin >> id >> k;
    ll c;
    rep(j, k) {
      cin >> c;
      if (j == 0) {
        t.at(id).left = c;
      } else {
        t.at(l).right = c;
      }
      l = c;
      t.at(c).parent = id;
    }
  }
  ll r;
  rep(i, n) {
    if (t.at(i).parent == NIL) {
      r = i;
    }
  }
  setDepth(r, 0);
  rep(i, n) print(i);
}


Measured memory_bytes: 10676
#include <iostream>
#include <queue>
#include <string>

using namespace std;

int main()
{
	priority_queue<int> s;

	string instruction;
	int v;
	while (1) {
		cin >> instruction;
		if (instruction == "insert") {
			cin >> v;
			s.push(v);
		} else if (instruction == "extract") {
			cout << s.top() << endl;
			s.pop();
		} else if (instruction == "end") {
			break;
		}
	}

	return 0;
}



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

class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var d = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var ans = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = i + 1; j < n; j++) 
            {
                ans += d[i] * d[j];
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//

        int N;
        cin >> N;

        int a = N / 4;
        int b = N / 7;

        for (int i = 0; i < a+1; i++)
        {
                for (int j = 0; j < b+1; j++)
                {
                        if (4*i+7*j==N)
                        {
                                cout << "Yes" << endl;
                                return 0;
                        }
                }
                
        }

        cout << "No" << endl;
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


int main(){
  int N; cin >> N;
  vector <int> A(N), B(N);

  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];

  bool flag = true;

  vector < pair<int, int> > AP(N), BP(N);
  for (int i = 0; i < N; i++){
    AP[i] = make_pair(A[i], i);
    BP[i] = make_pair(B[i], i);
  }
  sort(AP.begin(), AP.end());
  sort(BP.begin(), BP.end());

  for (int i = 0; i < N; i++){
    if (AP[i].first > BP[i].first){
      cout << "No" << endl; return 0;
    }
  }
    
  for (int i = 0; i < N - 1; i++){
    if (AP[i + 1].first <= BP[i].first){
      cout << "Yes" << endl; return 0;
    }
  }

  vector <int> P(N);
  for (int i = 0; i < N; i++){
    P[AP[i].second] = BP[i].second;
  }
  int X = 0, cnt = 0;

  do{
    X = P[X]; cnt++;
  } while (X != 0);
  

  if (cnt == N) cout << "No" << endl;
  else cout << "Yes" << endl;
  
  return 0;
}


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

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

int main() {
	int N; cin >> N;
	string S; cin >> S;
  if(N%2) {cout << "No" << endl; return 0;}
    
	if(S.substr(0,N/2)==S.substr(N/2,N/2)) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
	int stu = 0;
	double p[40] = {};
	char dosu[6][40];

	std::cin >> stu;

	for (int i = 0; i < stu; i++) {
		std::cin >> p[i];
		if (p[i] < 165.0) {
			dosu[0][i] = '*';
		
		}
		else if (p[i] < 170.0) {
			dosu[1][i] = '*';
			
		}
		else if (p[i] < 175.0) {
			dosu[2][i] = '*';
			
		}
		else if (p[i] < 180.0) {
			dosu[3][i] = '*';
			
		}
		else if (p[i] < 185.0) {
			dosu[4][i] = '*';
		
		}
		else {
			dosu[5][i] = '*';
		}
		

	}

	std::cout << "1:";
	for (int j1 = 0; j1 < 40; j1++) {

		if (dosu[0][j1] == '*') {
			std::cout << dosu[0][j1];
		}
	}
	std::cout << std::endl;
	std::cout << "2:";
	for (int j2 = 0; j2 < 40; j2++) {
		if (dosu[1][j2] == '*') {
			std::cout << dosu[1][j2];
		}
	}
	std::cout << std::endl;
	std::cout << "3:";
	for (int j3 = 0; j3 < 40; j3++) {
		if (dosu[2][j3] == '*') {
			std::cout << dosu[2][j3];
		}
	}
	std::cout << std::endl;
	std::cout << "4:";
	for (int j4 = 0; j4 < 40; j4++) {
		if (dosu[3][j4] == '*') {
			std::cout << dosu[3][j4];
		}
	}
	std::cout << std::endl;
	std::cout << "5:";
	for (int j5 = 0; j5 < 40; j5++) {
		if (dosu[4][j5] == '*') {
			std::cout << dosu[4][j5];
		}
	}
	std::cout << std::endl;
	std::cout << "6:";
	for (int j6 = 0; j6 < 40; j6++) {
		if (dosu[5][j6] == '*') {
			std::cout << dosu[5][j6];
		}
	}
	std::cout << std::endl;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>
using namespace std;
constexpr char nl = '\n';
using ll = long long;
using boost::irange;
namespace rng {
    using namespace boost;
    using namespace boost::range;
    using namespace boost::adaptors;
}

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> auto operator>>(istream& in, C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, istream&>::type {
    for (auto& v : c) { in >> v; } return in; }
template<class C> auto operator<<(ostream& out, const C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, ostream&>::type {
    int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
constexpr auto color_s_ = "\033[2m\033[33m", color_e_ = "\033[0m";
template<class T> void trace_(const T& v) { cerr << v; }
template<class T> void trace_(const vector<vector<T>>& m) { cerr << "\n"; for (const auto& v : m) { trace_(v); cerr << "\n"; } }
template<class T> void trace_(const char* s, const T& v) { cerr << color_s_ << s << "="; trace_(v); cerr << color_e_ << "\n"; cerr.flush(); }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { cerr << color_s_; for (; *s != ','; ++s) { cerr << *s; } cerr << "="; trace_(v); cerr << ","; trace_(++s, vs...); }
#define TRACE(...) trace_(#__VA_ARGS__, __VA_ARGS__)
#else
#define TRACE(...)
#endif

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    cin >> a;
    ll sum = rng::accumulate(a, 0LL);
    if (sum > n) {
        cout << -1 << nl;
    } else {
        cout << (n - sum) << nl;
    }
}


Measured memory_bytes: 3696
#include <iostream>

using namespace std;
#define For(i,xx,yy) for (int i=xx; i <=yy ; ++i)
int m,d,a[5];
int main()
{
    long long dem =0  ;
    cin>>m>>d ;
    For(i,1,m)
        For(j,1,d)
        {
            int dd=j ;
            a[1]=dd%10 ;
            dd=dd/10 ;
            a[0]=dd%10 ;
            //cout<<a[0]<<a[1]<<"\n";
            if (a[0]>=2 && a[1]>=2 &&(a[1]*a[0]==i))
                ++dem ;
        }
    cout<<dem;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int h,w;
  cin>>h>>w;
  
  string board[110];
  
  for(int i=0;i<h;i++)
  {
       cin>>board[i];
  }
 
 bool goodx[h];
 bool goody[w];
  
  for(int i=0;i<h;i++)
  { goodx[i]=false;}
    
  for(int i=0;i<w;i++)
  { goody[i]=false;}
  
  for(int i=0;i<h;i++)
  {
      for(int j=0;j<w;j++)
      {
          if(board[i][j]=='#')
          {
               goodx[i]=true;
               goody[j]=true;
          }
      }      
  }
  
  
  
  for(int i=0;i<h;i++)
  {
     if(goodx[i])
     {
      for(int j=0;j<w;j++)
      {
        if(goody[j])
        {
          cout<<board[i][j];
        }
       }  
     }
        cout<<endl;
      
  }
}

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


int main(void) {
	int a, b;
	scanf("%d %d", &a, &b);
	int m = min(a, b);
	int M = max(a, b);
	for (int i = 0; i < M; i++) {
		printf("%d", m);
	}


	return 0;
}


Measured memory_bytes: 3824
N = int(input())
a = [[int(input()), False] for i in range(N)]


num = 1
for i in range(N):
    if a[num-1][1]:
        print(-1)
        break
    if a[num-1][0] == 2:
        print(i+1)
        break
    a[num-1][1] = True
    num = a[num-1][0]

Measured memory_bytes: 16372
k = int(input())
s = input()
# k = 10 ** 6
# s = 'a'*10**6
n = len(s)
mod = 10 ** 9 + 7
ans = 0

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, n + k + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


for i in range(k + 1):
    ans = (ans + cmb(n - 1 + k - i, k - i, mod) * pow(26, i, mod) * pow(25, k - i, mod)) % mod
print(ans)

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

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

int H,W,h[1510],w[1510],ans;
int cnt_h[1500010],cnt_w[1500010];

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

	while(true) {
		ans=0;
		REP(i,1500010) cnt_h[i]=cnt_w[i]=0;
		cin>>H>>W;
		if(H==0&&W==0) break;
		REP(i,H) {
			cin>>h[i+1];
			h[i+1]+=h[i];
		}
		REP(i,W) {
			cin>>w[i+1];
			w[i+1]+=w[i];
		}
		FOR(i,1,H+1) {
			FOR(j,0,i) {
				cnt_h[h[i]-h[j]]++;
			}
		}
		FOR(i,1,W+1) {
			FOR(j,0,i) {
				cnt_w[w[i]-w[j]]++;
			}
		}
		REP(i,1500010) ans+=cnt_h[i]*cnt_w[i];
		cout<<ans<<endl;
	}

	return 0;
}



Measured memory_bytes: 14880
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class DSwapAndFlip {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        const int INF = ten(5);
        int N;
        in>>N;
        vc<pii> A(N);
        for(auto& a : A) in>>a.first;
        for(auto& a : A) in>>a.second;
        vvc<int> dp(1<<N, vc<int>(N, INF));
        vvc<pii> last(1<<N, vc<pii>(N, {0, -1}));
        REP(i, N){
            int mask = 1 << i;
            dp[mask][i] = i;
            last[mask][i].first = 1;
            if(i&1) last[mask][i].second = A[i].second;
            else last[mask][i].second = A[i].first;
        }
        FOR(i, 1, 1<<N){
            REP(j, N){
                if((i>>j&1)==0 or dp[i][j]==INF) continue;
                int cnt = 0;
                for(int k=N-1;0<=k;--k){
                    if(i>>k&1){
                        ++cnt;
                        continue;
                    }
                    int d = abs(k+cnt-last[i][j].first);
                    int val = (d-cnt) & 1 ? A[k].second : A[k].first;
                    if(val<last[i][j].second) continue;
                    int nmask = i | (1<<k);
                    if(chmin(dp[nmask][k], dp[i][j]+d)){
                        last[nmask][k].first = last[i][j].first + 1;
                        last[nmask][k].second = val;
                    }
                }
            }
        }
        int ans = INF;
        for(auto& a : dp.back()) chmin(ans, a);
        if(ans==INF) out<<"-1\n";
        else out<<ans<<'\n';
    }
};


int main() {
	DSwapAndFlip solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }



int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll N, K, C; cin >> N >> K >> C;
  string S; cin >> S;
  
  //main
  vll left(N+2,0), right(N+2,0), ldleft(N+2,-1e18), ldright(N+2,1e18);
  
  bool flag = true; ll count = 0; ll tmp = -1e18;
  for(int i=1; i<=N; i++){
    if(S[i-1] == 'o' && flag){
      left[i] = left[i-1]+1; 
      flag = false; count = C;
      ldleft[i] = i; tmp = i;
    }else{
      if(count > 1){//休んでいない。
        count --;
      }else if(count == 1){//休みきった。
        count --; flag = true; 
      }
      left[i] = left[i-1];
      ldleft[i] = tmp;
    }
  }
  
  flag = true; count = 1e18; tmp = 1e18;
  for(int i=N; i>=1; i--){
    if(S[i-1] == 'o' && flag){
      right[i] = right[i+1]+1; 
      flag = false; count = 0;
      ldright[i] = i; tmp = i;
    }else{
      if(count < C-1){//休んでいない。
        count ++;
      }else if(count == C-1){//休みきった。
        count ++; flag = true; 
      }
      right[i] = right[i+1]; 
      ldright[i] = tmp;
    }
  }
  
  
  // output
  /*ll ans = 0;
  for(int i=1; i<=N; i++){ cout << left[i] << " " << right[i] << endl;}*/
  if(C != 0){
    for(int i=1; i<=N; i++){
      if((left[i-1]+right[i+1]) == K-1 && (ldright[i+1]-ldleft[i-1])>=C+1  && S[i-1] == 'o'){
        cout << i << endl; 
      }
    }
  }else{
    ll cnt = 0;
    FOR(i,N){ if(S[i]=='o') cnt ++; } 
    if(cnt==K){
      FOR(i,N){ 
        if(S[i]=='o'){
          cout << i+1 << endl; 
        }
      } 
    }else{
       
    }
  }
  
  //FOR(i,N+2){ cout << ldleft[i]; } cout << endl;
  //FOR(i,N+2){ cout << ldright[i]; } cout << endl;

  return 0;
}

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	int n=read();
	string s=readString();
	vi dp(n+1,0);
	REP(i,n){
		if(s[i]=='W'){
			dp[i+1]++;
		}else{
			dp[0]++;
			dp[i]--;
		}
	}
	int ans=n;
	REP(i,n){
		chmin(ans,dp[i]);
		dp[i+1]+=dp[i];
	}
	print(ans);
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define pb(a)           push_back(a)
#define ll              long long int
#define scd(a)          scanf("%d",&a)
#define mp(a,b)         make_pair(a,b)
#define scl(w)          scanf("%I64d",&w)
#define scdd(a,b)       scanf("%d %d",&a,&b)
#define srt(a)          sort(a.begin(),a.end())
#define rsrt(a)         sort(a.rbegin(),a.rend())
#define scll(a,b)       scanf("%I64d %I64d",&a,&b)
///4direction ->        int del_x[]={-1,0,1,0},del_y[]={0,1,0,-1};
#define input(v,n)      for (int i=0;i<n;i++){int a;cin >> a;v.push_back(a);}
#define inputll(v,n)    for (ll i=0;i<n;i++){ll a;cin >> a;v.push_back(a);}
#define vii             vector < int >
#define vll             vector < ll >
#define pii             pair < int , int >
#define pll             pair < ll , ll >
#define mk              make_pair
#define inf8            100000008
#define inf18           1000000000000000018
#define MAX             10000001

using namespace std;
 int main()
 {
     ll x,s=0,y;
     cin>>x;
     y=x;
     while(x!=0){
        s+=x%10;
        x/=10;
     }
     if(y%s==0){
        cout<<"Yes"<<endl;
     }
     else{
        cout<<"No"<<endl;
     }

 }

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;i++) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int dp[100005],arr[100005];

int main()
{jizz
	dp[0]=1e9;
	int n;
	cin >> n >> arr[1];
	for(int i=2;i<=n;++i)
		cin >> arr[i],dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	cout << dp[n] << "\n";
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
  int n,i;
  int a[3]={1,1,1};
  int max;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  max=a[0];
  if(a[1]>max){
    max=a[1];
  }
  if(a[2]>max){
    max=a[2];
  }
  if(n==2){
    for(i=1;i<max;i++){
      if(a[0]%i==0 && a[1]%i==0){
	printf("%d\n",i);
      }
    }
  }
  else if(n==3){
    for(i=1;i<max;i++){
      if(a[0]%i==0 && a[1]%i==0 && a[2]%i==0){
	printf("%d\n",i);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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 n,k,x,y;
    cin >> n >> k >> x >> y;
    if(n > k)cout << x*k + y*(n - k) << endl;
    else cout << x*n << endl;
    return 0;
}

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

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

int main (){
    ll n;
    map<int,int> mp;
    cin >> n;
    int sum=0;
    rep(i,n){
        ll a;
        cin >> a;
        sum+=a;
        mp[a]++;
    }
    int l=mp.size();
    if(n%3!=0){
        if(sum==0) cout << "Yes" <<endl;
        else cout << "No" <<endl;
    }
    else {
        if(sum==0){
            cout << "Yes" <<endl;
            return 0;
        }
        if(l==2){
            int j=0;
            int x,y;
            int xc,yc;
            for(auto p:mp){
                if(j==0) {
                    x=p.first;xc=p.second;
                }
                else {
                    y=p.second;yc=p.second;
                }
                j++;
            }
            if(x==0&&xc==n/3&&y!=0&&y==2*n/3) cout << "Yes" <<endl;
            else cout << "No" <<endl;
        }
        else if(l==3){
            int j=0;
            int x,y,xy;
            int xc,yc,xyc;
            for(auto p:mp){
                if(j==0){
                    x=p.first;xc=p.second;
                }
                else if(j==1){
                    y=p.first;yc=p.second;
                }
                else {
                    xy=p.first;xyc=p.second;
                }
                j++;
            }
            int z=x^y;
            int xyz=xy^z;
            if(xyz==0&&xc==n/3&&yc==n/3&&xyc==n/3) cout << "Yes" <<endl;
            else cout << "No" <<endl;
        }
        else cout <<"No" <<endl;
    }

    return 0;
}


Measured memory_bytes: 3840
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define ll long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12

int n;
int map[60][60];
int from[60];
int pre[60];
int low[60];
int toutatu=1;
int bridge[60];
int dummy;

//bridgeが1のものが橋の終点、fromに対になる点が収納される
int search(int x){
	int i;

	if(pre[x]==0){
		pre[x]=toutatu;
		low[x]=toutatu;
		toutatu++;
	}

	fr(i,1,n+1){
		if(map[x][i]==1&&from[x]!=i){
			if(pre[i]>0){
				if(low[i]<low[x]){
					low[x]=low[i];
					search(from[x]);
				}
			}else{
				from[i]=x;
				dummy=search(i);
			}
		}
	}

	if(pre[x]==low[x]){
		bridge[x]=1;
	}else{
		bridge[x]=0;
	}

	return low[x];
}


int main(void)
{
	//変数の宣言
//	int n;
	int m;
	int a[1500];
	int b[1500];
//	int map[60][60];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;
	
	
	//データの読み込み
	scanf("%d %d",&n,&m);
//	scanf_s("%d %d",&n,&m);

	fr(i,0,m){
		scanf("%d %d",&a[i],&b[i]);
//		scanf_s("%d %d",&a[i],&b[i]);	
	}

	fr(i,0,n+1){
		fr(j,0,n+1){
			map[i][j]=0;
		}
	}

	fr(i,0,m){
		map[a[i]][b[i]]=1;
		map[b[i]][a[i]]=1;
	}

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理
	
	search(1);
	bridge[1]=0;
	fr(i,0,n+1){
		ans=ans+bridge[i];
	}

	//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",ans);
	
	fr(i,0,n+1){
		if(bridge[i]==1){
//			printf("(%d,%d)は橋",i,from[i]);
		}
	}

//	printf("pre[7]=%d,low[7]=%d",pre[7],low[7]);
	
	//	printf("結果の出力終了\n");

	
	return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
#define pi pair<int,int>
using namespace std;
int main(){
   ll n, w; 
   cin>> n >> w;
    ll wei[n] , val[n] ;
   for(int i =0 ; i < n ; ++i)
     cin>> wei[i] >> val[i] ; 
   
   ll dp[n+2][w+ 2] ; 
   for(int i =0 ; i<= n ; ++i){
	   
	   for(int j =0 ; j <= w ; ++j){
		   if(j == 0 ||i ==0 )
		    dp[i][j] = 0 ; 
		    else if(wei[i-1] > j)
				dp[i][j]= dp[i-1][j] ;
			else
		dp[i][j] = max(dp[i-1][j]  , val[i-1] + dp[i-1][j - wei[i-1]]) ; 
                 }
       }

cout<<dp[n][w]<<endl;

}






Measured memory_bytes: 79744
import java.util.*;

public class Main {
	public static void printArray(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + ", ");
		}
		System.out.println();
	}

	public static <T> void printArrayT(T[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + ", ");
		}
		System.out.println();
	}

	public static class Triple implements Comparable<Triple> {
		public int A, B, C;

		Triple(int A, int B, int C) {
			this.A = A;
			this.B = B;
			this.C = C;
		}

		@Override
		public String toString() {
			return String.format("(%d, %d, %d)", A, B, C);
		}

		@Override
		public int compareTo(Triple o) {
			int a = this.A - o.A;
			if (a != 0)
				return a;
			int b = this.B - o.B;
			if (b != 0)
				return b;
			return this.C - o.C;
		}
	}

	static final long MOD = 1000000007;

	// 逆数
	public static long inv(long n) {
		return pow(n, -1);
	}

	// 累乗
	// n ^ (P-1) == 1 (mod P) を利用すると
	// 1/n == n^(P-2)
	public static long pow(long n, int exp) {
		if (exp < 0) {
			exp += (MOD - 1);
		}
		long x = 1;
		while (exp > 0) {
			if ((exp & 1) == 1) {
				x *= n;
				x %= MOD;
			}
			n *= n;
			n %= MOD;
			exp >>= 1;
		}
		return x;
	}

	// 階乗
	public static long fac_len(int n, int len) {
		long x = n;
		for (int i = 1; i < len; i++) {
			x *= n - i;
			x %= MOD;
		}
		return x;
	}

	// コンビネーション
	public static long comb(int n, int m) {
		if (m * 2 > n) {
			m = (n - m);
		}
		if (m == 0) return 1;
		return fac_len(n, m) * inv(fac_len(m, m)) % MOD;
	}

	public static void fillpow(long[] xs, long x) {
		long s = 1;
		for (int i = 0; i < xs.length; i++) {
			xs[i] = s;
			s *= x;
			s %= MOD;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); // 2 * 10^5
		int A = sc.nextInt(); // 2 * 10^5
		int B = sc.nextInt(); // 2 * 10^5
		int C = sc.nextInt(); // 2 * 10^5

		long sum = 0;
		// ちょうどN回で終わる可能性 * N
		// sum += N * pow(A * inv(A+B), N);
		// sum += (N+1) * pow(A * inv(A+B), N - 1) * pow(B * inv(A+B), 1) * comb(N, 1);
		// ちょうどN+1回で終わる可能性 * N+1
		// ちょうど 2N-1 回で終わる可能性 * 2N-1 を足す

		long pA = A * inv(A + B) % MOD;
		long pB = B * inv(A + B) % MOD;
		long[] powA = new long[N + 1];
		long[] powB = new long[N + 1];
		long[] combN = new long[N + 1];
		fillpow(powA, pA);
		fillpow(powB, pB);

		combN[0] = comb(N - 1, 0);
		for (int i = 1; i <= N; i++) {
			// combN[i] = comb(N + i - 1, i);
			combN[i] = combN[i - 1] * (N+i-1) % MOD * inv(i) % MOD;
		}

		for (int i = 0; i < N; i++) {
			long a = powA[N] * powB[i] % MOD;
			long b = powA[i] * powB[N] % MOD;
			sum += (N + i) * (a + b) % MOD * combN[i] % MOD;
		}
		// System.out.println("sum = " + sum);
		// 最後に 1/(1-C) を掛ける Cが1に近いほど試行回数が増える
		sum *= 100;
		sum %= MOD;
		sum *= inv(A + B);
		sum %= MOD;
		System.out.println(sum);
	}
}


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

int main (){
  int N;
  cin >> N;
  string S;
  
  for (int i = 0; i < N; i++){
    cin >> S;
    if(S == "Y"){
      cout << "Four" << endl;
      break;
    }
    if(i == N - 1){
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define all(c) (c).begin(), (c).end()

//analyze testcases thoroughly before starting implementation

void solve () {
	int n;
	cin>>n;
	vector <pair <int, int> > d(n);
	int count = 0;
	bool can = false;
	for (int i = 0; i < n; i++) {
		cin>>d[i].first>>d[i].second;
		if (can) continue;
		if (d[i].first == d[i].second) {
			if (i > 0 && d[i-1].first == d[i-1].second) {
				count++;
			}
			if (count >= 2) {
				can = true;
				continue;
			}
		}
		else count = 0;
	}
	can ? cout<<"Yes" : cout<<"No";
}

int main() {
	fastIO;
	int t = 1; 
	//cin>>t;
	while (t--) {
		solve();
		cout<<'\n';
	}
	return 0;
}

/*
check for edge cases : n = 0, 1 etc
check for overflows and out of bounds
*/

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

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

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

class XorBase {
    private:
        std::vector<long long> base;
    public:
        XorBase() {}
        void add(long long x) {
            for (long long b : base) {
                if ((x ^ b) < x) {
                    x ^= b;
                }
            }
            if (x != 0) base.push_back(x);
        }
        bool check(long long x) const {
            for (long long b : base) {
                if ((x ^ b) < x) {
                    x ^= b;
                }
            }
            if (x == 0) return true;
            else return false;
        }
};

void solve() {
    int T;
    cin >> T;

    vector<int> res(T);
    for (int i=0; i<T; ++i) {
        int N;
        cin >> N;
        vector<ll> a(N);
        for (int i=0; i<N; ++i) cin >> a[i];
        string s;
        cin >> s;
        XorBase base;
        for (int j=N-1; j>=0; --j) {
            if (s[j] == '0') {
                base.add(a[j]);
            } else {
                if (!base.check(a[j])) {
                    res[i] = 1;
                    break;
                }
            }
        }
    }
    for (int x : res) cout << x << '\n';
}

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

    solve();

    return 0;
}


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

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

using namespace std;

const string YES = "STABLE";
const string NO  = "UNSTABLE";

struct Data {
  int adj;
  double centroid;
  double xmin,xmax;
  double denominator;
};

int h,w,IDMap[60][10];
string c[60];
Data arr[200];
bool visited[60][10];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

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

void makeMap() {
  memset(IDMap,-1,sizeof IDMap);
  int ID = 0;
  rep(i,h) rep(j,w) if( c[i][j] != '.' && !visited[i][j] ){
    visited[i][j] = true;
    IDMap[i][j] = ID;
    deque<int> deq;
    deq.push_back(j+i*w);
    while( !deq.empty() ) {
      int cur = deq.front(); deq.pop_front();
      int x = cur % w, y = cur / w;
      rep(k,4) {
        int nx = x + dx[k], ny = y + dy[k];
        if( !isValid(nx,ny) ) continue;
        if( c[ny][nx] != c[i][j] ) continue;
        if( visited[ny][nx] ) continue;
        visited[ny][nx] = true;
        IDMap[ny][nx] = ID;
        deq.push_back(nx+ny*w);
      }
    }
    ++ID;
  }
  memset(visited,false,sizeof visited);
}

void compute() {
  memset(visited,false,sizeof visited);
  rep(i,200) arr[i].adj = -1, arr[i].centroid = 0, arr[i].xmin = DBL_MAX, arr[i].xmax = -DBL_MAX, arr[i].denominator = 0;
  makeMap();
  vector<int> IDs;
  rep(y,h) rep(x,w) if( c[y][x] != '.' && !visited[y][x] ) {
    int ID = IDMap[y][x];
    IDs.push_back(ID);
    deque<int> deq;
    deq.push_back(x+y*w);
    visited[y][x] = true;
    while( !deq.empty() ) {
      int cur = deq.front(); deq.pop_front();
      int cx = cur % w, cy = cur / w;
      arr[ID].centroid += ( (double)cx + 0.5);
      arr[ID].denominator = 1;
      rep(i,4) {
        int nx = cx + dx[i], ny = cy + dy[i];
        if( !isValid(nx,ny) ) {
          if( i == 0 ) {
            arr[ID].xmin = min(arr[ID].xmin,(double)cx);
            arr[ID].xmax = max(arr[ID].xmax,(double)cx+1.0);
          }
          continue;
        }
        if( c[ny][nx] != c[y][x] ) {
          if( c[ny][nx] != '.' && i == 0 ) {
            arr[ID].adj = IDMap[ny][nx];
            arr[ID].xmin = min(arr[ID].xmin,(double)cx);
            arr[ID].xmax = max(arr[ID].xmax,(double)cx+1.0);
          }
          continue;
        }
        if( !visited[ny][nx] ) {
          visited[ny][nx] = true;
          deq.push_back(nx+ny*w);
        }
      }
    }
  }
  rep(i,(int)IDs.size()) if( arr[IDs[i]].adj != -1 ) {
    arr[arr[IDs[i]].adj].centroid += arr[IDs[i]].centroid;
    arr[arr[IDs[i]].adj].denominator += arr[IDs[i]].denominator;
  }
  rep(i,(int)IDs.size()) if( arr[IDs[i]].xmin != DBL_MAX ) {
    double centroid = arr[IDs[i]].centroid / ( 4.0 * arr[IDs[i]].denominator );
    if( !( arr[IDs[i]].xmin < centroid && centroid < arr[IDs[i]].xmax ) ) {
      cout << NO << endl;
      return;
    }
  }
  cout << YES << endl;
}

int main() {
  while( cin >> w >> h, w|h ) {
    rep(i,h) cin >> c[i];
    compute();
  }
  return 0;
}

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

bool f(bool a, bool b) {
    if (a && !b) return false;
    return true;
}

int main() {
    int n;
    cin >> n;
    vector<bool> hoge(n);
    for (int i = 0; i < n; i++) {
        char c;
        cin >> c;
        hoge[i] = c == 'T';
    }

    bool ans = f(hoge[0], hoge[1]);
    for (int i = 2; i < n; i++) {
        ans = f(ans, hoge[i]);
    }

    cout << (ans ? "T" : "F") << endl;
}


Measured memory_bytes: 3084
// n本の棒から3本選ぶのは nC3 通り
// 全通り試すと大体 8 x 10^9 だから間に合わない
//
// ソートして a を固定しつつループ回してみる
// 
// 答えみてしまった
// Cをbinary_searchして計算量小さくするのを思いつかなかった
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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



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

  ll n;
  cin >> n;
  vector<ll> l(n);
  rep(i, n) cin >> l[i];
  sort(l.begin(), l.end()); // O(NlogN)

  ll ans = 0;
  for(ll i = n-1; i >= 2; i--){
    for(ll j = i-1; j >= 1; j--) {
      // こいつ以下かつj以上のindex全部行けるってこと
      ll c_index = upper_bound(l.begin(), l.end(), l[i]-l[j])-l.begin();
      if (c_index < j) {
        //printf("a: %lld, b: %lld, c_index: %lld\n", l[i], l[j], c_index);
        ans += j-c_index;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll A,B,C,D; cin >> A >> B >> C >> D;
    ll res = max(min(B,D) - max(A,C),0LL);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_LV_MAX		55										// 最大レベル

// 内部変数
static FILE *szpFpI;											// 入力
static int siLV;												// レベル
static long long sl1ACnt[D_LV_MAX];								// 総数[レベル]
static long long sl1PCnt[D_LV_MAX];								// パティの総数[レベル]

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// パティの枚数 - 取得
long long
fGetPCnt(
	int piLV					// <I> レベル
	, long long plCnt			// <I> 枚数
)
{
	// 枚数 >= 総数
	if (plCnt >= sl1ACnt[piLV]) {

		// 取得済
		if (sl1PCnt[piLV] > 0) {
			return sl1PCnt[piLV];
		}

		// レベル
		if (piLV == 0) {
			sl1PCnt[piLV] = 1;
		}
		else {
			sl1PCnt[piLV] = fGetPCnt(piLV - 1, plCnt) * 2 + 1;		// 下位へ
		}

		return sl1PCnt[piLV];
	}

	long long llSum = 0;

	// 層前半部分
	if (plCnt > 0) {
		llSum = fGetPCnt(piLV - 1, plCnt - 1);
	}

	// 層中間
	long long llMdl = sl1ACnt[piLV] / 2 + 1;
	if (plCnt >= llMdl) {
		llSum++;
	}

	// 層後半部分
	if (plCnt > llMdl) {
		llSum += fGetPCnt(piLV - 1, plCnt - llMdl);
	}

	return llSum;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// データ - 初期化
	memset(sl1PCnt, 0, sizeof(sl1PCnt));						// パティの総数[レベル]

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// レベル・層数 - 取得
	long long llCnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%lld", &siLV, &llCnt);

	// 総数 - セット
	sl1ACnt[0] = 1;
	for (i = 1; i <= siLV; i++) {
		sl1ACnt[i] = sl1ACnt[i - 1] * 2 + 3;
	}

	// パティの枚数 - 取得
	long long llPCnt = fGetPCnt(siLV, llCnt);

	// 結果 - セット
	sprintf(lc1Out, "%lld\n", llPCnt);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
    #define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
    #define printd(x) printf("%.12f\n", ans);
    #define print(x) cout << (x) << endl;
    #define Yes() cout << "Yes" << endl;
    #define No() cout << "No" << endl;
    #define YES() cout << "YES" << endl;
    #define NO() cout << "NO" << endl;
    #define all(x) (x).begin(),(x).end()
    #define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
    template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
    template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
    using namespace std;
    using ll = long long;
    using pll = pair<ll, ll>;
     
    int main(void) {
        int n;
        cin >> n;
        int a[n + 1], b[n], aa[n + 1], bb[n];
        rep (i, n + 1) cin >> a[i];
        rep (i, n) cin >> b[i];
        rep (i, n + 1) aa[i] = a[i];
        rep (i, n) bb[i] = b[i];
     
        ll ans1 = 0, ans2 = 0;
        for (int i = 0; i < n; i++) {
            if (b[i] >= a[i]) {
                ans1 += a[i];
                b[i] -= a[i];
            }
            else {
                ans1 += b[i];
                b[i] = 0;
            }
            if (b[i] >= a[i + 1]) {
                ans1 += a[i + 1];
                a[i + 1] = 0;
            }
            else {
                ans1 += b[i];
                a[i + 1] -= b[i];
            }
        }
     
        for (int i = n - 1; i >= 0; i--) {
            if (bb[i] >= aa[i + 1]) {
                ans2 += aa[i + 1];
                bb[i] -= aa[i + 1];
            }
            else {
                ans2 += bb[i];
                bb[i] = 0;
            }
            if (bb[i] >= aa[i]) {
                ans2 += aa[i];
                aa[i] = 0;
            }
            else {
                ans2 += bb[i];
                aa[i] -= bb[i];
            }
        }
            
        cout << max(ans1, ans2) << endl;
        return 0;
    }

Measured memory_bytes: 1792
#include <stdio.h>

#define COL 3 //列
#define LINE 2 //行

//連立方程式1つとxyの答えを持つ
typedef struct{
	double data[LINE][COL];
	double x_answer;
	double y_answer;
} Question;


int main(){
	Question q[100];
	int q_num = 0;//問題数
	int i,j,k = 0;
	int d;

	//入力の最後まで処理
	while( q_num < 100 ){
		for(i=0; i<LINE; i++){
			for(j=0; j<COL; j++){
				if( scanf("%lf",&q[q_num].data[i][j]) == EOF){
					goto end; 
				}
			}
		}
		
		q_num++;
	}
	
	end:

	//問題を解く処理
	for(i=0; i<q_num; i++){
		//前進消去
		//(2)' = (2)-(1)*a10/a00
		for(j=COL-1; j>=0; j--){
			q[i].data[1][j] -= q[i].data[0][j] * q[i].data[1][0] / q[i].data[0][0];
		}
		
		q[i].y_answer =  q[i].data[1][2] / q[i].data[1][1] ;

		q[i].x_answer =  (q[i].data[0][2] - q[i].data[0][1] * q[i].y_answer) / q[i].data[0][0] ;

	}

	for(k=0; k<q_num; k++){
		printf("%.3lf %.3lf\n",q[k].x_answer,q[k].y_answer);
	}


	return 0;
}

Measured memory_bytes: 656
#include "stdio.h"

int main(int argc, char const *argv[])
{
    int a,b;
    scanf("%d %d",&a,&b);

    if(b%a==0){
        printf("%d\n",a+b);
    }else{
        printf("%d\n",b-a);
    }
    return 0;
}

Measured memory_bytes: 128
s = ["0"] + list(input())
t = ["0"] + list(input())
n, m = len(s), len(t)
dp = [[0] * m for _ in range(n)]
for i in range(1, n):
    for j in range(1, m):
        if s[i] == t[j]:
            dp[i][j] = dp[i - 1][j - 1] + 1
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
ans = []
c = dp[n - 1][m - 1]
for i in range(n - 1, 0, -1):
    if m == 0:
        break
    for j in range(m - 1, 0, -1):
        if s[i] == t[j] and dp[i][j] == c:
            ans.append(s[i])
            c -= 1
            m = j
            break
        elif dp[i][j] < c:
            break
ans.reverse()
print("".join(ans))

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

using namespace std;

int main()
{
    int n,i,j,b[100];
    char a[200];
  scanf("%d",&n);

int p=n-1;
    scanf("%s",a);
int f=n;
    for(i=0;i<100;i++)
        {b[i]=1;}
        int r=0;
    while(p--)
    {
        f--; int o=0;int k;
        for(i=0; i<f; i++)
        {

            for(j=n-1;j>=f;j--)
            {
                k=a[j]-'a';
                if((a[i]==a[j])&&b[k])
                {
                    o++;b[k]=0;//printf("f=%d,%c\n",f,a[i]);
                }
            }
        }
        memset(b,1,sizeof(b));
        if(r<o)
                r=o;
    }
     //sort(s,s+r+1);
    // for(i=0;i<r;i++)
       printf("%d\n",r);



    return 0;
}


Measured memory_bytes: 256