akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
typedef long long ll;
using namespace std;

vector<pair<int,int>> v[100010];
ll dist[100010];
const ll INF=1e10;
vector<set<int>> s(100010);

void dijkstra(){
  priority_queue<pair<ll,int>> PQ;
  //priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> PQ;
  for(int i=0;i<=100005;i++) dist[i]=INF;
  PQ.push(make_pair(0,1));
  dist[1]=0;

  while(!PQ.empty()){
    pair<ll,int> f=PQ.top();
    PQ.pop();
    int t=f.second;

    if(dist[t]<-f.first) continue;

    for(int i=0;i<v[t].size();i++){
      pair<int,int> u=v[t][i];
      ll c=0;
      if(s[t].count(u.second)==0) c++;

      if(dist[u.first]>dist[t]+c){
        s[u.first].clear();
        s[u.first].insert(u.second);
        dist[u.first]=dist[t]+c;
        PQ.push(make_pair(-dist[u.first],u.first));
      }else if(dist[u.first]==dist[t]+c){
        if(s[u.first].count(u.second)==0){
          s[u.first].insert(u.second);
          //PQ.push(make_pair(dist[u.first],u.first));
        }
        //s[u.first].insert(u.second);
      }
      //cout<<u.first<<" "<<u.second<<" "<<dist[u.first]<<endl;
    }
  }

  return;
}

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

  for(int i=0;i<m;i++){
    int p,q,c;
    scanf("%d %d %d",&p,&q,&c);
    v[p].push_back(make_pair(q,c));
    v[q].push_back(make_pair(p,c));
  }

  dijkstra();

  //for(int i=0;i<n;i++) cout<<i+1<<" "<<dist[i+1]<<endl;

  if(dist[n]==INF) cout<<-1<<endl;
  else cout<<dist[n]<<endl;


  return 0;
}


Measured memory_bytes: 24180
#include <stdio.h>
int main(void){
    int n;
    scanf("%d\n",&n);
    int p[1000000];
    
    p[0]=n;
    int i=0;
    
    int s=1;
    while(s){
        
        if(p[i]%2==1){
            p[i+1]=3*p[i]+1;
        }else{
            p[i+1]=p[i]/2;
        }
        
        for(int j=0;j<=i;j++){
            if(p[j]==p[i+1]){
                printf("%d\n",i+2);
                s=0;
                break;
                
            }
        }
        
        i++;
    }
   
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];

            var ans = N - 1;
            for (var i = 1L; i * i <= N; ++i)
            {
                if ((N / i) * i == N)
                    ans = Min(ans, N / i - 1 + i - 1);
            }
            WriteLine(ans);

            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int x;cin >> x;
  string s;cin >> s;
  if(x>=3200)cout << s << endl;
  else cout<< "red" << endl;
  return 0;
}


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




int main(void){
char s;
int a[27];
char ss='a';
for(int i=0;i<=26;i++){
a[i]=0;
}
while(scanf("%c",&s)!=EOF){
    if(s>='a'&&s<='z'){
        a[s-'a']++;
    }
    else if(s>='A'&&s<='Z'){
        a[tolower(s)-'a']++;
    }
}
for(int i=0;i<=25;i++){
printf("%c : %d\n",ss+i,a[i]);
}


}



Measured memory_bytes: 2120
import collections

def check(input_list):

    vote_dict = collections.Counter(input_list)
    max_value = max(vote_dict.values())

    result_list = [k for k, v in vote_dict.items() if v == max_value]
    result_list.sort()
    
    return result_list

if __name__ == '__main__':
    num = int(input())
    input_list = [input() for a in range(num)]

    for str in check(input_list):
        print(str)
        

Measured memory_bytes: 35564
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <map>
#include <cmath>
#include <vector>

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

typedef unsigned long long ull;
typedef long long ll;
using namespace std;

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

    map<ll, int> a_b;
    vector<ll> keys(n);
    ll price; int drink_num;
    rep (i, n) {
        cin >> price >> drink_num;
        if (a_b[price]) {
            a_b[price] += drink_num;
        } 
        else {
            /* code */
            a_b[price] = drink_num;
        }
        // cout << a_b[price] << endl;
    }

    ll count = 0; ll ans = 0;
    rep (i, m) {
        ll key = a_b.begin()->first;
        ans += key;
        count++;
        // cout << ans << " " << count << endl;
        if (count == a_b[key])
        {
            /* code */
            a_b.erase(begin(a_b));
            count = 0;
        }
        if (i == m-1) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <algorithm>
#include <experimental/random>

using namespace std;
#ifdef __DEBUG__
    void debug_out() { cerr << endl; } 
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 
#endif

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int _N;
vector<int> _A, _B;
inline void input(){
    fast_io();
    cin >> _N;
    _A = fetch_vec<int>(_N);
    _B = fetch_vec<int>(_N);
}

void chmax(int &a, int b){if(a<b) a=b;};

inline int solve(int N, vector<int> A, vector<int> B){
    vector<int> cntA(N+1,0), cntB(N+1,0);
    for(int x:A) cntA[x]++;
    for(int x:B) cntB[x]++;
    for (int i = 1; i <= N; i++)
    {
        if((cntA[i]+cntB[i])>N){
            cout << "No" << "\n";
            return 0; 
        }
    }
    vector<int> IA = cntA, IB = cntB;
    for (int i = 0; i < N; i++)
    {
        IA[i+1] += IA[i];
        IB[i+1] += IB[i];
    }

    int x = 0;
    for (int k = 1; k <= N; k++)
    {
        if(cntA[k]==0 || cntB[k]==0) continue;
        chmax(x, IA[k]-IB[k-1]);
    }
    
    cout << "Yes" << "\n";
    // xだけBをずらす.
    for (int i = 0; i < N; i++)
    {
        cout << B[(N+i-x)%N];
        if(i!=N-1) cout << " ";
    }
    cout << "\n";
    

    return 0;
}   



int test(){
    int n = 5;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; i++)
    {
        a[i] = std::experimental::randint(1, n);
        b[i] = std::experimental::randint(1, n);
    }
    sort(a.begin(),a.end());    
    sort(b.begin(),b.end());

    debug(n);
    debug(a);
    debug(b);
    solve(n, a, b);
    return 0;
}

int main()
{
    // int t = 10;
    // while(t--) test();
    input();
    solve(_N, _A, _B);
    return 0;
}


Measured memory_bytes: 9528
#include<stdio.h>

int main(void)
{
	int r, g, b,kazu;

	scanf("%d%d%d", &r, &g, &b);

	kazu = r * 100 + g * 10 + b;

	if (kazu % 4 == 0)
		printf("YES\n");
	else
		printf("NO\n");

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int H, W, N; cin >> H >> W >> N;
    vec X(N), Y(N);
    mat O(H, vec(0));
    REP(i, N){
        cin >> X[i] >> Y[i];
        X[i]--;
        Y[i]--;
        O[X[i]].push_back(Y[i]);
    }
    REP(i, H) SORT(O[i]);

    int ans = 0, M = 0;
    FOR(i, 1, H){
        if(O[i].size() > 0){
            if(O[i][0] <= M) break;
            int j = Lower_bound(O[i], M + 1);
            if(!(j != O[i].size() && O[i][j] == M + 1)) M++;
        }else M++;
        ans++;
    }
    ans++;

    cout << ans;


    
    return 0;
}

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

int n;
vector<int> h;
int ret = 0;

int main(void) {
	cin >> n;
	for (size_t i = 0; i < n; i++) {
		int hi;
		cin >> hi;
		h.push_back(hi);
	}

	while (accumulate(h.begin(), h.end(), 0) > 0) {
		int i;
		for (i = 0; i < n; i++) {
			if (h[i] > 0)
				break;
		}
		int j;
		for (j = i + 1; j < n; j++) {
			if (h[j] == 0)
				break;
		}
		int sub = *min_element(h.begin() + i, h.begin() + j);
		ret += sub;
		for (int k = i; k < j; k++)
			h[k] -= sub;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;

void cinv(vector<ll> &V){
	ll t;
	cin >> t;
	V.push_back(t);
}

int main()
{
	ll N,X,sum=0;
	vector<ll> v;
	cin >> N >> X;
	fore(i,0,N){
		cinv(v);
		sum=sum+v[i];
	}
	sort(v.begin(),v.end());
	sum=X-sum;
	cout << N+sum/(*v.begin()) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<string>
using namespace std;
int main(){
  int N;
  cin >> N;
  set<string> S;
  for(int i=0;i<N;i++){
    string t;
    cin >> t;
    S.insert(t);
  }
  cout << S.size() << endl;
}

Measured memory_bytes: 19120
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;

int C[200000];
long long dp[200000];
long long MOD = 1000000007;
int main(){
    int N;
    cin >> N;

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

    map <int, int> last;
    dp[0] = 1;
    last[C[0]] = 0;
    for(int i = 1; i < N; i++){
        if(last.find(C[i]) == last.end()){
            dp[i] = dp[i - 1];
            last[C[i]] = i;
        } else {
            if(last[C[i]] < i - 1){
                dp[i] = (dp[i - 1] + dp[last[C[i]]]) % MOD;
            } else {
                dp[i] = dp[i - 1];
            }
            last[C[i]] = i;
        }
    }
    cout << dp[N - 1] << endl;
    return 0;
}


Measured memory_bytes: 11904
n = int(input())
ans = []
L = list(map(int,input().split()))
if len(list(filter(lambda x:x==L[0] ,L))) == len(L):
    print(n//2)
    quit()


import collections as col
L1 = L[::2]
L2 = L[1::2]
c1 = sorted(list(col.Counter(L1).items()),key=lambda x:x[1])[::-1]
c2 =sorted(list(col.Counter(L2).items()),key=lambda x:x[1])[::-1]

for i in range(3):
    for j in range(3):
        try:
            tmp1 = c1[i][0]
            tmp2 = c2[j][0]
            if tmp1 == tmp2 :
                continue
            a1 = n//2 - c1[i][1]
            a2 = n//2 - c2[j][1]
            ans.append(a1+a2)
        except:
            pass
print(min(ans))


Measured memory_bytes: 64748
#include<stdio.h>
int main(void)
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a<b)
    printf("a < b\n");
    else if(a>b)
    printf("a > b\n");
    else
    printf("a == b\n");
    return 0;
}



Measured memory_bytes: 2088
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n;

int main(){
    scanf("%ld", &n);
    printf("%ld\n", (n-1)/2);
}


Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

import itertools
import math
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]


seq = []
for i in range(n):
    seq.append(i)

a = list(itertools.permutations(seq))
#print(a)

ans = 0
for i in a:
    for j in range(0,n-1):
        #idx1とidx2との距離
        ans += math.sqrt((l[i[j]][0] - l[i[j+1]][0])**2 + (l[i[j]][1] - l[i[j+1]][1])**2)


print(ans/len(a))



Measured memory_bytes: 13984
#include <bits/stdc++.h>
#define MAX 100008
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define forn(a,b,c) for(int a=b;a<c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
int n,a[MAX],b[MAX],c[MAX],ans = 0,dp[MAX][3];
int play(int i, int flag)
{
    if(i >= n)
        return 0;
    if(dp[i][flag] != -1)
        return dp[i][flag];
    if(flag == 0)
        return dp[i][flag] = max(b[i] + play(i + 1, 1), c[i] + play(i + 1, 2));
    else if(flag == 1)
        return dp[i][flag] = max(a[i] + play(i + 1, 0), c[i] + play(i + 1, 2));
    else if(flag == 2)
        return dp[i][flag] = max(a[i] + play(i + 1, 0), b[i] + play(i + 1, 1));
    else
        return max(max(a[i] + play(i + 1, 0), b[i] + play(i + 1, 1)), c[i] + play(i + 1, 2));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    forn(i,0,n)
        cin >> a[i] >> b[i] >> c[i];
    memset(dp,-1,sizeof(dp));
    ans = play(0,3);
    cout << ans;
    return 0;
}



Measured memory_bytes: 7296
n = int(input())
dp = [[0] * n for i in range(3)]

dp[0][0], dp[1][0], dp[2][0] = map(int, input().split())

for i in range(1, n):
    a, b, c = map(int, input().split())
    dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + a
    dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + b
    dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + c

print(max(dp[0][n - 1], dp[1][n - 1], dp[2][n - 1]))

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int r, d, x;
    cin >> r >> d >> x;

    irep(i, 10) {
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
} /*atcoder*/


Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
 
  string s; cin >> s;
  int x_, y_; cin >> x_ >> y_;
  vector<int> X, Y;
  int co = 0, cnt = 0;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == 'T') {
      if(cnt % 2 == 0) {
          X.push_back(co);
          co = 0; cnt ++;
      } else {
          Y.push_back(co);
          co = 0; cnt ++;
      }
      continue;
    }
    if(s[i] == 'F') {
      co ++;
      if(i == s.size() - 1) {
        if(cnt % 2 == 0) {
          X.push_back(co);
        } else {
          Y.push_back(co);
        }
      }
    }
  }
  bool dpx[8010][16010];
  bool dpy[8010][16010];
  x_ += 8000; y_ += 8000;
  rep(k, 8001) {
    rep(i, 16001) {
      dpx[k][i] = false;
      dpy[k][i] = false;
    }
  }
  dpx[0][8000] = true;
  dpx[1][X[0] + 8000] = true;
  dpy[0][8000] = true;
  rep1(k, X.size() - 1) {
    rep(x, 16001) {
      if(x - X[k] >= 0) dpx[k + 1][x] |= dpx[k][x - X[k]];
      if(x + X[k] <= 16000) dpx[k + 1][x] |= dpx[k][x + X[k]];
    }
  }
  rep(k, Y.size()) {
    rep(y, 16001) {
      if(y - Y[k] >= 0) dpy[k + 1][y] |= dpy[k][y - Y[k]];
      if(y + Y[k] <= 16000) dpy[k + 1][y] |= dpy[k][y + Y[k]];
    }
  }
  if(dpx[X.size()][x_] && dpy[Y.size()][y_]) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}

Measured memory_bytes: 250752
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int L[200005];
int R[200005];

vector<int>vec[505]; 

int cnt[505][505];

int main(){


	int N,M,Q;

	scanf("%d %d %d",&N,&M,&Q);

	int i,j;
	for(i=0;i<M;i++){
		scanf("%d %d",&L[i],&R[i]);
		vec[L[i]].push_back(R[i]);
	}

	for(i=1;i<=N;i++){
		if(vec[i].size()>0){
			sort(vec[i].begin(),vec[i].end());
		}
	}



	for(i=1;i<=N;i++){
		for(j=1;j<=N;j++){
			if(vec[j].size()>0){
				cnt[i][j]+=lower_bound(vec[j].begin(), vec[j].end(), i+1)-vec[j].begin();//軸jにi以下は何個あるか
			}
		}

	}


	for(i=0;i<Q;i++){
		int p,q;
		scanf("%d %d",&p,&q);
		int ans=0;
		for(j=p;j<=q;j++){
			ans+=cnt[q][j];
		}
		printf("%d\n",ans);
	}

	return 0;
}

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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if ((A + B) > (C + D))
    {
        cout << "Left" << endl;
    }
    else if ((A + B) < (C + D))
    {
        cout << "Right" << endl;
    }
    else
    {
        cout << "Balanced" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

const ll INF = 1e18;
ll N;
ll a[410];
ll dp[410][410];
ll sum[410][410];

ll dfs (ll l, ll r)
{
    if (dp[l][r] < INF) {
        return dp[l][r];
    }
    for (int i = l; i < r; i++) {
        dp[l][r] = min(dp[l][r], dfs(l, i) + dfs(i + 1, r) + sum[l][r]);
    }
    return dp[l][r];
}

int main ()
{
    cin >> N;
    REP(i,N) cin >> a[i];

    REP(i,410)REP(j,410) dp[i][j] = INF;
    REP(i,N) dp[i][i] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            ll sumt = 0;
            for (int k = i; k <= j; k++) {
                sumt += a[k];
            }
            sum[i][j] = sumt;
        }
    }

    dfs(0, N - 1);

    cout << dp[0][N - 1] << endl;

    return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi a(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i + 1];
  }
  int idx = 1;
  int now = 1;
  while (idx <= n) {
    if (a[idx] == now) {
      now++;
    }
    idx++;
  }
  // cout << "idx=" << idx << ",now=" << now << endl;
  if (now == 1) {
    cout << -1 << endl;
  } else {
    cout << (n - (now - 1)) << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    cout << fixed << setprecision(10);
    int n;cin>>n;
    vector<double> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    double c=(a[0]+a[1])/2;
    for(int i=2;i<n;i++){
        c = (c+a[i])/2;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <algorithm>

using namespace std;

struct Event {
	int ty, tx;
	int t;
	Event(){}
	Event(int ty, int tx, int t) : ty(ty), tx(tx), t(t){}
};

bool reach[16][16][16];

int main()
{
	int sy, sx;
	int ty[10], tx[10];
	int n;
	int dx[] = {-1, 0, 1, -2, 2, -2, 2, -2, 2, -1, 0, 1};
	int dy[] = {2, 2, 2, 1, 1, 0, 0, -1, -1, -2, -2, -2};
	
	while (scanf("%d %d", &sx, &sy) && sy){
		scanf("%d", &n);
		if (n == 0) puts("NA");
		
		for (int t = 0; t < n; t++){
			scanf("%d %d", tx + t, ty + t);
		}
		
		queue<Event> q;
		
		bool flag = false;
		for (q.push(Event(sy, sx, 0)); q.size(); q.pop()){
			Event x = q.front();
			if (x.t == n){
				puts("OK");
				flag = 1;
				break;
			}
			for (int i = 0; i < 12; i++){
				int ny = x.ty + dy[i], nx = x.tx + dx[i];
				if (ny < 0 || ny > 9 || nx < 0 || nx > 9) continue;
				if (abs(ny - ty[x.t]) <= 1 && abs(nx - tx[x.t]) <= 1){
					q.push(Event(ny, nx, x.t + 1));
				}
			}
		}
		if (!flag) puts("NA");
	}
	
	return (0);
}

Measured memory_bytes: 1040
#include<iostream>
#include<vector>

using namespace std;
int main(void)
{
    int n,y,m,d;
    cin>>n;
    int small=39*5;
    int big=200;
    while(n--){
        int c=0;
        cin>>y>>m>>d;
        
        if(y%3){
            if(m%2){
                c+=20-d;
            }
            else
                c+=19-d;
            m++;d=20;
            while(m<=10){
                if(m%2)
                    c+=20;
                else
                    c+=19;
                m++;
            }
            y++;
            d=20;
            m=10;
        }
        else{
            c-=d;
            while(m>1){
                c-=20;
                m--;
            }
        }
        if(y%3){
            c+=39*5;
            y++;
        }
        c+=200;
        c+=(999-y)/3*small*2+((999-y)/3)*big+1;
        cout<<c<<endl;
    }
}

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

using namespace std;

int A,B,C,X,Y,a;
priority_queue <int,vector<int>,greater<int> > q;

int main(){
  cin >> A >> B >> C >> X >> Y;
  q.push(A*X+B*Y);
  q.push(2*C*max(X,Y));
  if(X>Y){
    q.push((X-Y)*A+2*C*Y);
  }else{
    q.push((Y-X)*B+2*C*X);
  }
  cout << q.top() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define  fill(st,et,val,arr) for(int i=st;i<=et;i++)arr[i]=val;
#define all(v) v.begin(),v.end()
template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}
 
const int M=1e9 + 7;
const int MAX=1e5+7;
using namespace std;
bool comp(int a,int b)
{	
	return a>b;
}
void printQ(vector<int> q)
{   
    cout<<"v->  ";
	for(int i=0;i<q.size();i++)
	{
		cout<<q[i]<<" ";
	}
	cout<<endl;
}
pair<int,int> fl(int n)
{
	vector<int> v;
	while(n>0)
	{
		v.pb(n%10);
		n/=10;
	}
	return {v[v.size()-1],v[0]};
}
int32_t main() 
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    map<pair<int,int>,int> mp;
    int ans=0;
    for(int i=1;i<=n;i++)
    {   
        pair<int,int> p=fl(i);
        //cout<<i<<"-> "<<p.first<<" "<<p.second<<endl;
    	ans+=(2*mp[{p.second,p.first}]);
    	if(p.second==p.first)ans++;
    	mp[p]++;
	}
	cout<<ans<<endl;
	return 0;
}













Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p == NIL) printf("root, ");
  else if(T[u].l == NIL) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].r != NIL) calcDepth(T[u].r,p);
  if(T[u].l != NIL) calcDepth(T[u].l,p+1);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 6376
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<functional>
 #include<utility>
 
 using namespace std;

 int main()
 {
   long long int m,n;
   cin>>m>>n;
   long long int kk=m*m;
   long long int kkk=m*m*m;
   long long int kkkk=m*m*m*m;
   long long int ans=1;
   while(n>4)
   {
     ans=((ans*kkkk)%1000000007);
     n-=4;          
   }
   if(n==4) ans=((ans*kkkk)%1000000007);
   else if(n==3) ans=((ans*kkk)%1000000007);
   else if(n==2) ans=((ans*kk)%1000000007);
   else ans=((ans*m)%1000000007);
   cout<<ans<<endl;
   //while(1);
   return 0;
 }

Measured memory_bytes: 3088
import sys
input = sys.stdin.readline
ma = lambda : map(int,input().split())
ni = lambda : int(input())

n = ni()
A = list(ma())
A.sort()
ma = A[-1]
mi = -1

for a in A:
    if abs(a - ma/2) <abs(mi - ma/2):mi =a

print(ma,mi)


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

using namespace std;

#define ll 			long long
#define db			double
#define up(i,j,n)		for (int i = j; i <= n; i++)
#define down(i,j,n)	for (int i = j; i >= n; i--)
#define cadd(a,b)		a = add (a, b)
#define cpop(a,b)		a = pop (a, b)
#define cmul(a,b)		a = mul (a, b)
#define pr			pair<int, int>
#define fi			first
#define se			second
#define SZ(x)		(int)x.size()
#define bin(i)		(1 << (i))
#define Auto(i,node)	for (int i = LINK[node]; i; i = e[i].next)

template<typename T> inline bool cmax(T & x, T y){return y > x ? x = y, true : false;}
template<typename T> inline bool cmin(T & x, T y){return y < x ? x = y, true : false;}
template<typename T> inline T dmax(T x, T y){return x > y ? x : y;}
template<typename T> inline T dmin(T x, T y){return x < y ? x : y;}

const int MAXN = 4e5 + 5;
const int oo = 2e9;

int N, a[MAXN], mx[MAXN][2], n, ans[MAXN];

inline void upd(int ss, int v){
	if (v >= mx[ss][0]) {
		mx[ss][1] = mx[ss][0];
		mx[ss][0] = v;
	}else cmax(mx[ss][1], v);
}

int main(){
#ifdef cydiater
	freopen("input.in", "r", stdin);
#endif
	scanf("%d", &N);
	n = bin(N) - 1;
	up (ss, 0, n) mx[ss][0] = mx[ss][1] = -oo; 
	up (ss, 0, n) {
		int x; scanf("%d", &x);
		int tt = n ^ ss;
		for (int s = tt; s; s = (s - 1) & tt) upd(n ^ s, x);
		upd(n, x);
	}
	ans[0] = -oo;
	up (i, 1, n) {
		ans[i] = mx[i][0] + mx[i][1];
		cmax(ans[i], ans[i - 1]);
	}
	up (i, 1, n) printf("%d\n", ans[i]);
	return 0;
}



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

const int maxn = 100010;
int n, K, p[maxn];

int main() {
    scanf("%d %d", &n, &K);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &p[i]);
    }
    int pos = min_element(p + 1, p + n + 1) - p, ans = n;
    auto calc = [&](int x) {
        return x < 0 ? 0 : (x + K - 2) / (K - 1);
    };
    for (int i = 1; i <= min(pos, K); i++) {
        ans = min(ans, calc(pos - i) + calc(n - pos - (K - i)) + 1);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 640
// Last Change: 05/25/2019 21:15:19.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll r, D, x;
  cin >> r >> D >> x;

  for (int i = 0; i < 10; ++i) {
    x = r * x - D;
    cout << x << endl;
  }

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string S;
  int Q;

  cin >> S >> Q;

  deque<char> pre, suf;

  bool flip = false;

  F0R(i, Q) {
    int T;
    cin >> T;
    if (T == 1) {
      flip = !flip;
      continue;
    }

    int F;
    char c;
    cin >> F >> c;

    if (F == 1) {
      // 先頭に追加
      if (!flip) pre.push_front(c);
      else suf.push_back(c);
    }
    else {
      // 末尾に追加
      if (!flip) suf.push_back(c);
      else pre.push_front(c);
    }
  }

  string r;
  r.reserve(S.size() + pre.size() + suf.size());
  if (!flip) {
    for (auto c : pre) {
      r += c;
    }
    r += S;
    for (auto c : suf) {
      r += c;
    }
  }
  else {
    for (auto it = suf.rbegin(); it != suf.rend(); it++) r += *it;
    reverse(S.begin(), S.end());
    r += S;
    for (auto it = pre.rbegin(); it != pre.rend(); it++) r += *it;
  }
  cout << r;
}
#endif


Measured memory_bytes: 1104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int SIZE_FACT = 5000;
vector<ll> fact, invfact;
ll comb(int n, int k) {
	return fact[n] * invfact[k] % mod * invfact[n-k] % mod;
}
ll modpow(ll n, int k) {
	ll r = 1;
	while (k > 0) {
		if (k&1) (r *= n) %= mod;
		(n *= n) %= mod;
		k >>= 1;
	}
	return r;
}
ll f(int n, int m) {
	return comb(n+m-1, n);
}
int main() {
	fact.resize(SIZE_FACT);
	invfact.resize(SIZE_FACT);
	fact[0] = invfact[0] = 1;
	for (int i = 1; i < SIZE_FACT; ++ i) {
		fact[i] = fact[i-1] * i % mod;
		invfact[i] = modpow(fact[i], mod-2);
	}

	int S;
	cin >> S;
	ll r = 0;
	for (int i = 1; i*3 <= S; ++ i) {
		(r += f(S-i*3, i)) %= mod;
	}
	cout << r << endl;
}


Measured memory_bytes: 3724
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <climits>
#include <algorithm>
#include <cctype>
#include <cstdlib>
using namespace std;

typedef long long LL;

const LL inf = LLONG_MAX / 2;

struct node{
	char ch;
	LL refcnt;
	LL len;
	vector<node*> to;
	
	node(char c, LL r = 0, LL len = -1)
	: ch(c), refcnt(r), len(len) {}
};

struct state{
	int stnum;
	node *nd;
	LL a, b;
	size_t cntr;
	
	state(int s, node *nd, LL a, LL b, size_t c)
	: stnum(s), nd(nd), a(a), b(b), cntr(c) {}
};

node *alp[26];
node emp(0, inf, 0);
string ans;

node *getnode(int c){
	if(c == '.'){ return &emp; }
	node *&ret = alp[c - 'a'];
	if(!ret){ ret = new node(c); }
	return ret;
}

void delnode(node *nd){
	queue<node*> q;
	q.push(nd);
	while(q.empty()){
		nd = q.front();
		q.pop();
		for(size_t i = 0; i < nd->to.size(); ++i){
			node *next = nd->to[i];
			if(!--next->refcnt){
				q.push(next);
			}
		}
		delete nd;
	}
}


void dfs(node *nd0, LL a0, LL b0){
	stack<state> stk;
	stk.push(state(0, nd0, a0, b0, 0));
	while(!stk.empty()){
		state &tp = stk.top();
		int &num = tp.stnum;
		node *&nd = tp.nd;
		LL &a = tp.a;
		LL &b = tp.b;
		size_t &cntr = tp.cntr;

		if(num == 0){
			if(a >= b){
				stk.pop();
				continue;
			}
			if(nd->ch){
				nd->len = 1;
				if(a == 0){
					ans += nd->ch;
				}
				stk.pop();
				continue;
			}
			if(nd->len >= 0 && nd->len <= a){
				stk.pop();
				continue;
			}

			nd->len = 0;
			num = 1;
		}
		else if(num == 1){
			if(cntr >= nd->to.size()){
				stk.pop();
				continue;
			}
			node *next = nd->to[cntr];
			
			while(next->to.size() == 1){
				node *tmp = next;
				nd->to[cntr] = next->to[0];
				next = next->to[0];

				if(--tmp->refcnt){
					++next->refcnt;
					break;
				}

				delete tmp;
			}

			num = 2;
			stk.push(state(0, next, a, b, 0));
		}
		else if(num == 2){
			node *next = nd->to[cntr];
			LL olen = next->len;
			a = max(a - olen, 0LL);
			b = max(b - olen, 0LL);
			nd->len = min(nd->len + olen, inf);

			if(next->len == 0){
				nd->to.erase(nd->to.begin() + cntr);
				--cntr;
				if(!--next->refcnt){
					delnode(next);
				}
			}
			
			++cntr;
			num = 1;
		}
	}
}

int main(){
	ios::sync_with_stdio(false);

	string s;
	LL q, a, b;
	char c;
	cin >> s >> q >> a >> b;
	--a;

	node *root = new node(0);
	root->to.resize(s.size());
	for(size_t i = 0; i < s.size(); ++i){
		node *next = getnode(s[i]);
		root->to[i] = next;
		++next->refcnt;
	}

	for(LL i = 0; i < q; ++i){
		cin >> c >> s;
		node *nd = alp[c - 'a'];
		if(!nd){ continue; }
		alp[c - 'a'] = 0;

		nd->ch = 0;
		nd->to.resize(s.size());
		for(size_t j = 0; j < s.size(); ++j){
			node *next = getnode(s[j]);
			nd->to[j] = next;
			++next->refcnt;
		}
	}

	dfs(root, a, b);
	if(ans.size() < b - a){
		ans = ".";
	}
	cout << ans << '\n';
	
	delnode(root);
}

Measured memory_bytes: 60352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;
string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    string S[N];
    rep(i, N) cin >> S[i];
    int cnt = 0;
    rep(i, N){
        bool able = true;
        rep(j, N)rep(k, N){
            int p = (j+i)%N, q = (k+i)%N;
            if(S[p][k] != S[q][j]) able = false;
        }
        if(able) cnt++;
    }
    cout << cnt*N << endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    int A[100][100],B[100],C[100];
    for (int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            cin >> A[i][j];
        }
    }
    for (int i = 0;i < m;i++){
        cin >> B[i];
    }
    for (int i = 0;i < n;i++){
        C[i] = 0;
        for(int j = 0;j < m;j++){
            C[i] += A[i][j] * B[j];
        }
        cout << C[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  string T;
  cin >> T;
  for (int i = 0; i < T.size(); i++) {
    if (T.at(i) == '?') {
      T.at(i) = 'D';
    }
  }
  for (int i = 0; i < T.size(); i++) {
    cout << T.at(i);
  }
  cout << endl;
}

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

using namespace std;

#define MAX 1000001
using ull = unsigned long long;
using P = tuple<int, int, int>;

const ull b = 1000000007ULL;

vector<ull> rolling_hash(char* S, int N, vector<ull>& p)
{
    vector<ull> h(N + 1);
    for (int i = 0; i < N; i++) {
        h[i + 1] = h[i] * b + S[i];
        p[i + 1] = p[i] * b;
    }
    return h;
}

int main()
{
    char S[MAX];
    scanf("%s", S);
    
    int N = strlen(S);
    vector<ull> p(N + 1);
    p[0] = 1;
    
    bool found = 0;
    auto h = rolling_hash(S, N, p);    
    
    vector<P> v;
    for (int i = 0; i < N; i++) {
        int A = i + 1;
        int B = (N - 3 * A) / 2;

        if (B <= 0) continue;
        if ((N - 3 * A) % 2 != 0) continue;

        auto A1 = h[A] - h[0] * p[A];
        auto B1 = h[A + B] - h[A] * p[B];
        auto A2 = h[A * 2 + B] - h[A + B] * p[A];
        auto B2 = h[2 * (A + B)] - h[A * 2 + B] * p[B];
        auto A3 = h[N] - h[2 * (A + B)] * p[A];

        if (A1 == A2 && A2 == A3 && B1 == B2) {
            found = 1;
            v.emplace_back(A + B, A, B);
        }
    }

    sort(v.begin(), v.end());
    
    if (!found) {
        printf("mitomerarenaiWA\n");
    } else {
        printf("Love ");
        int size = get<0>(v[0]);
        for (int i = 0; i < size; i++) {
            printf("%c", S[i]);
        }
        printf("!\n");
    }        
    return 0;
}

Measured memory_bytes: 19752
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[100005],b[100005];
	for(int i=0;i<n;i++)
	  cin>>a[i],b[i]=a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
	  if(b[i]-a[i]>1)
	  {
	  	cout<<"No";
	  	return 0;
	  }	
	}  
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    vector<int>arr = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;cin >> K;
    cout << arr[K-1] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

#define vcitr vector<int>::iterator
#define vcsitr vector<string>::iterator
#define mapcitr map<char, int>::iterator
#define mapsitr map<string, int>::iterator

typedef long long ll;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }

int a[5050];

int main() {
	int n;
	
	while (cin>>n) {
		if (n==0) break;
		for (int i=0; i<n; i++) cin >> a[i];
		
		int ans = -iINF;
		for (int i=0; i<n; i++) {
			int sum = 0;
			for (int j=i; j<n; j++) {
				sum += a[j];
				ans = max(ans, sum);
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1172
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define SF scanf
#define PF printf
#define MAXN 300010
#define INF 0x3FFFFFFF
#define MOD 998244353
using namespace std;
typedef long long ll;
typedef map<ll,ll>::iterator mit;
int n,q;
ll qx[MAXN];
map<ll,ll> mp;
ll used[MAXN];
int main(){
	SF("%d%d",&n,&q);
	for(int i=1;i<=q;i++)
		SF("%lld",&qx[i]);
	qx[0]=n;
	mp[qx[q]]++;
	for(int i=q-1;i>=0;i--){
		while(mp.rbegin()->first>qx[i]){
			mit it=mp.end();
			it--;	
			mp[it->first%qx[i]]+=it->second;
			mp[qx[i]]+=it->second*(it->first/qx[i]);
			mp.erase(it);
		}
	}
	mit it=mp.begin();
	for(;it!=mp.end();it++)
		used[it->first]+=it->second;
	for(int i=n;i>=1;i--)
		used[i]=used[i]+used[i+1];
	for(int i=1;i<=n;i++)
		PF("%lld\n",used[i]);
}

Measured memory_bytes: 10624
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
using int64 = long long;

vector< int64 > divisor(int64 n)
{
    vector< int64 > ret;
    for(int64 i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return(ret);
}
int main(){
    ll n;
    cin >> n;
    auto d = divisor(n);
    ll ans = 0;;
    for(ll  a : d){
        ll m = n/a-1;
        if(m>=1){
            ll aa = n/m;
            ll bb = n % m;
            if(aa == bb)ans+= m;
        }
    }
    cout << ans << endl;
}
int main2(){
    int n;
    cin >> n;
    vector<string>s(n);
    rep(i,n)cin >> s[i];
    int ans = 0;
    rep(i,n){
        int k = (int) s[i].size();
        rep(j,k-1){
            if(s[i][j] == 'A' and s[i][j+1] == 'B')ans++;
        }
    }
    int a = 0, b = 0, c = 0, d = 0;
    rep(i,n){
        if(s[i][0] == 'A'){
            if(s[i].back() == 'A')a++;
            else b++;
        }else if(s[i][0] == 'B'){
            if(s[i].back() == 'A')c++;
            else d++;
        }
    }
    return 0;
}

Measured memory_bytes: 384
Seg = [
  0b0111111,
  0b0000110,
  0b1011011,
  0b1001111,
  0b1100110,
  0b1101101,
  0b1111101,
  0b0100111,
  0b1111111,
  0b1101111
]

while (n = $stdin.gets.to_i) != -1 do
  prev = 0b0000000
  n.times do
    nextNumber = Seg[$stdin.gets.to_i]
    printf("%07d\n", (prev ^ nextNumber).to_s(2))
    prev = nextNumber
  end
end

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

int main() {
  int N; //支払金額
  
  cin >> N; //支払金額の入力
  
  if (N % 1000 == 0){
  	cout << 0 << endl;
  }else{
  	cout << 1000 * (N / 1000 + 1) - N << endl;
  }
}


Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    vector<vi> dp(n+1,vi(2,-LINF));
    dp[0][0] = 0;
    rep(i,n)rep(j,2){
        int t = a[i];
        if(j) t *= -1;
        dp[i+1][0] = max(dp[i+1][0], dp[i][j]+t);
        if(i < n-1)dp[i+1][1] = max(dp[i+1][1], dp[i][j]-t);
        //cout << i+1 << " " << dp[i+1][0] << " " << dp[i+1][1] << endl;
    }
    cout << max(dp[n][0],dp[n][1]) << endl;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>
#include <fstream>
using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
const double pi = 3.14159265359;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll K;
    cin >> N >> K;
    int Q;
    cin >> Q;
    vector<int> a(Q);
    for (int i = 0; i < Q; ++i)cin >> a[i], a[i]--;
    vector<ll> b(N,K);
    for (int i = 0; i < Q; ++i) {
        b[a[i]]++;
    }
    for (int i = 0; i < N; ++i) {
        b[i] -= Q;
    }
    for (int i = 0; i < N; ++i) {
        //cout << b[i] << endl;
        if (b[i] > 0)cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1792