akhauriyash/Code-Regression huggingface dataset:
// abc178_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int x;
    cin >> x;
    int ans = 1 - x;
    print(ans);


    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<algorithm>
using namespace std;
long long msize[100005],qsum[100005];
main()
{
    long long num;
    scanf("%lld",&num);
    for(long long i=0;i<num;i++)
    {
        scanf("%lld",&msize[i]);
    }
    sort(msize,msize+num);
    qsum[0]=msize[0];
    for(long long i=1;i<num;i++)
    {
        qsum[i]=qsum[i-1]+msize[i];
    }
    long long cnt=1,chk=0;
    for(long long i=num-2;i>=0;i--)
    {
        chk=0;
        if(msize[i+1]<=qsum[i]*2) cnt++;
        else break;
    }
    printf("%lld\n",cnt);
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std ;
#define ll         long long
#define IOS         ios_base::sync_with_stdio(false);   cin.tie(NULL);
#define FOR(i,n)     for(ll i=0;i<n;i++)
#define REP(i,k,n)  for(ll i=k;i<n;i++)
#define nl         "\n"
#define BUFFER         cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define SORT        sort(a,a+n);
#define mod         1000000007
#define pb          push_back

int main()
{
    ll n,sum=0;
    cin>>n;
    ll a[n];
    FOR(i,n)
    cin>>a[i];
    FOR(i,n)
    {
        for(ll j=i+1;j<n;j++)
        {
            sum+=a[i]*a[j];
        }
    }
    cout<<sum<<nl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
using namespace std;



int main()
{
    int A1,A2,A3;
    cin >> A1 >>A2 >> A3;
    int sum = A1 + A2 + A3;
    if(sum >= 22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
}

Measured memory_bytes: 256
var
x,y,z,n,k,a:longint;
begin
readln(k,n);
for x:=0 to k do
  for y:=0 to k do
    begin
      z:=n-x-y;
      if (z>=0)and(z<=k) then inc(a);
    end;
writeln(a);
end.

Measured memory_bytes: 128
from collections import defaultdict, deque

N, M = map(int, input().split())
v = N
n = N+M-1
es = [[int(x)-1 for x in input().split()] for _ in range(n)]
or_cop = [[] for i in range(N)]
for e in es:
    or_cop[e[1]].append(e[0])

outs = defaultdict(list)
ins = defaultdict(int)
for v1, v2 in es:
    outs[v1].append(v2)
    ins[v2] += 1

q = deque(v1 for v1 in range(v) if ins[v1] == 0)
res = []
while q:
    v1 = q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append(v2)
root=res[0]            
LL = [[res[i],i] for i in range(N)]

LL=sorted(LL,key=lambda x: x[0])

for i in range(N):
    i_max=-1
    pare = -1
    if i==root:
        print(0)
    else:
        for cand in or_cop[i]:
            if LL[cand][1]>i_max:
                i_max=LL[cand][1]
                pare=cand
        print(pare+1)

Measured memory_bytes: 75708
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int main(void){
  int N, K;
  cin >> N >> K;
  int i, j;
  vector<int> p(N);
  for(i=0; i<N; i++)
    cin >> p[i];

  //累積和を格納していく．0番目は0
  double cum[N+1];
  cum[0] = 0;

  //i番目の期待値を計算
  //それを用いて累積和を計算していく
  double Ex;
  for(i=0; i<N; i++){
    Ex = ((double)p[i]+1)/2;
    cum[i+1] = cum[i] + Ex;
  }

  //和が最大になるものを動的に見ていく
  double Ex_i;
  double sum_max = 0;
  for(i=0; i<N-K+1; i++){
    //累積和の性質
    Ex_i = cum[i+K] - cum[i];
    if(sum_max < Ex_i)
      sum_max = Ex_i;
  }

  cout << setprecision(10) << sum_max << endl;
  
  return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main()

{
int a, b, c, d;
scanf("%d %d %d", &a, &b, &c);
if (a>b){
	d = a;
	a = b;
	b = d;
}
if (b>c){

	d = b;
	b = c;
	c = d;
}
if (a>b){
	d = a;
	a = b;
	b = d;
}
printf("%d %d %d\n",a,b,c);
return 0;
}


Measured memory_bytes: 2032
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
            int[] input = Input.ScanIntArray();
          Array.Sort(input);
          
          int sum ;
          if(input[0] != input[1] && input[1] != input[2]) sum = 3;
          else if(input[0] == input[1] && input[1] == input[2]) sum = 1;
          else sum = 2;
          Console.WriteLine(sum);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 11348
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(int argc, char const* argv[])
{
	string s;
	cin >> s;
	int n = stoi(s);
	int div = 0;
	for (int i = 0; i < s.size(); i++) {
		div += (s[i] - '0');
	}
	if (n % div == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>
using ll = long long;
using namespace std;


int main() {

    int n;
    cin >> n;
    cout << pow(n, 3) << endl;
    return 0;
}


Measured memory_bytes: 512
using System;

namespace atCoder
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            string[] a = Console.ReadLine().Split(' ');
            double temp = 0.0;

            for (int i = 0; i < n; i++)
            {
                temp += 1 / double.Parse(a[i]);
            }

            Console.WriteLine(1 / temp);
        }
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " = " << x << endl
#define print(x) cout << x << endl;
const ll MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    map<ll, ll> A;
    ll S = 0;
    rep(i, N)
    {
        ll temp;
        cin >> temp;
        if (!A.count(temp))
        {
            A[temp] = 0;
        }
        A[temp]++;
        S += temp;
    }

    ll Q;
    cin >> Q;
    rep(i, Q)
    {
        ll b, c;
        cin >> b >> c;
        S += (c - b) * A[b];

        if (!A.count(c))
        {
            A[c] = 0;
        }

        ll temp = A[b];
        A[c] += temp;
        A[b] = 0;
        cout << S << endl;
    }
}


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

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

constexpr int MOD = 1000000007;

int main(){
    ll N, M;
    read(N, M);
    vector<int> a(M);
    for(int i = 0; i < M; i++){
        read(a[i]);
    }
    vector<ll> dp(N + 1, 0);
    dp[0] = 1;
    for(int i = 0; i < M; i++){
        dp[a[i]] = -1;
    }
    for(int i = 1; i <= N; i++){
        if(dp[i] == -1) continue;
        if(dp[i - 1] > 0) dp[i] = dp[i - 1];
        if(i <= 1) continue;
        if(dp[i - 2] > 0) dp[i] += dp[i - 2];
        dp[i] %= MOD;
    }
    write(dp[N]);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 1408
s[9],c[9];main(n,m){for(;scanf("%d%d",&m,&n)*m;puts("")){int q[1024]={0},i,t,p=m;for(t=i=1;i<=n;i++){scanf("%s",s,*c=0);i%3||strcat(c,"Fizz");i%5||strcat(c,"Buzz");*c||sprintf(c,"%d",i);for(strcmp(s,c)&&p>1&&(q[t]=p--);q[t=t%m+1];);}for(t=i=1;i<=m;i++)q[i]||(t=!printf(" %d"+t,i));}}

Measured memory_bytes: 636
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
const long long INF=1e15;
int N,M,R,r[8];
long long dist[200][200],dp[1<<8][8];
long long f(int mask,int u){
    if(mask==(1<<R)-1)return 0;
    if(dp[mask][u]!=-1)return dp[mask][u];
    long long ret=INF;
    for(int v=0;v<8;v++){
        if(mask&(1<<v))continue;
        ret=min(ret,f(mask|(1<<v),v)+dist[r[u]][r[v]]);
    }
    return dp[mask][u]=ret;
}
int main(){
    scanf("%d %d %d",&N,&M,&R);
    for(int i=0;i<R;i++){
        scanf("%d",&r[i]);
        r[i]--;
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++)dist[i][j]=INF;
    }
    for(int i=0;i<M;i++){
        int u,v,w;
        scanf("%d %d %d",&u,&v,&w);
        u--;
        v--;
        dist[u][v]=w;
        dist[v][u]=w;
    }
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    memset((dp),-1,sizeof(dp));
    long long ans=INF;
    for(int i=0;i<R;i++){
        ans=min(ans,f(1<<i,i));
    }
    printf("%lld\n",ans);
    return 0;
}

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

const int mod = 1e9 + 7;

long long binpow(long long b, int e) {
  long long res = 1;
  while (e) {
    if (e & 1) res *= b, res %= mod;
    e >>= 1;
    b *= b;
    b %= mod;
  }
  return res;
}

long long inv(long long x) {
  return binpow(x, mod - 2);
}

const int N = 3e5 + 10;
long long a[N], cnt[60];

int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 0; j < 60; j++) cnt[j] += a[i] >> j & 1;
  }
  long long ans = 0;
  for (int i = 0; i < 60; i++) {
    ans += (1LL << i) % mod * cnt[i] % mod * (n - cnt[i]) % mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, M, P, ans=0, tmp=0;
vector<vector<pair<ll,ll>>> G;

vector<ll> to[2505];
vector<ll> rto[2505];
bool reachableFrom1[2505];
bool reachableToN[2505];
bool ok[2505];
 
void dfs(int v) {
    if (reachableFrom1[v]) return;
    reachableFrom1[v] = true;
    for (int u : to[v]) {
        dfs(u);
    }
}

void rdfs(int v) {
    if (reachableToN[v]) return;
    reachableToN[v] = true;
    for (int u : rto[v]) {
        rdfs(u);
    }
}
 
signed main() {
    cin >> N >> M >> P;
    G.resize(N);
    for(int i=0;i<M;i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        c -= P;
        c = -c;
        G[a].push_back(make_pair(b,c));
        to[a].push_back(b);
        rto[b].push_back(a);
    }
    dfs(0);
    rdfs(N-1);
    for(int i=0;i<N;i++) {
        ok[i] = reachableFrom1[i]&reachableToN[i];
    }
    { // bellman-ford
        vector<int> d(N,INF);
        d[0] = 0;
        bool upd = true;
        int step = 0;
        while (upd) {
            upd = false;
            for(int a=0;a<N;a++) {
                if(d[a]==INF) continue;
                for(int j=0;j<G[a].size();j++) {
                    ll b = G[a][j].first;
                    ll c = G[a][j].second;
                    if (!ok[a]) continue;
                    if (!ok[b]) continue;
                    int newD = d[a]+c;
                    if (newD < d[b]) {
                        upd = true;
                        d[b] = newD;
                    }
                }
            }
            step++;
            if (step > N) {
                puts("-1");
                return 0;
            }
        }
        ans = max(-d[N-1], 0LL);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4180
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  string search;
  int n;
  int ans = 0;

  cin >> search >> n;

  while(n --> 0){
    string ring; cin >> ring;
    ring += ring.substr(0, ring.size() - 1);
    if(ring.find(search) != string::npos)
      ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
using ll = long long;

ll n, k;
ll arr[100005];
ll cnt_bit[64];
ll x;

int main() {

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

        ll tmp = arr[i];
        ll j = 0;
        while (tmp) {
            if (tmp & 1) cnt_bit[j]++;
            tmp >>= 1;
            j++;
        }
    }

    for (int i = 60; i >= 0; i--) {
        ll mask = 1ll << i;

        if (n - cnt_bit[i] > cnt_bit[i]) {
            if ((x | mask) <= k) x |= mask;
        }
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += arr[i] ^ x;
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{
	string str;
	cin >> str;
	int c = str.size() / 2;
	int ans = 0;
	for( int i = 0; i < c; i++ ){
		int l = i;
		int r = str.size() - i - 1;

		if( str[l] != str[r] )
			ans++;
	}

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
   int  n;
   cin >> n;
   long long a;
   cin >> a;
   long long sum=0;
   for(int i=0;i<(n-1);i++){
       int b;
       cin >> b;
       if(a>=b){
           sum+=a-b;
       }
       else {
           a=b;
       }
   }
   cout << sum << endl;
}

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

#define ub(b,val) upper_bound(b+1,b+n+1,val)-b
#define ll long long

using namespace std;

const int N = 1e5 + 123, MAXN = 1e9;

ll n, m, v, p;

ll a[N], b[N], ans, c[N];

bool check (int in) {
    ll k = 0, id = (n - p + 1);
    if (b[in] + m < b[id])return 0;
    k += (p - 1) * 1ll * m + (in - 1) * 1ll  * m;
    for (int i = in;i <= id;i ++) {
        k += m + b[in] - b[i];
    }
    return (k >= m * v);
}

int main () {
    ios_base::sync_with_stdio (0), cin.tie (0), cout.tie (0);
    cin >> n >> m >> v >> p;
    for (int i = 1;i <= n;i ++) {
        cin >> a[i];
        b[i] = a[i];
    }sort (b + 1, b + n + 1);
    int l = 1, r = n, id = -1;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (check (mid)) {
            r = mid - 1;
            id = mid;
        }else {
            l = mid + 1;
        }
    }
    cout << (id == -1 ? 0 : (n - id + 1));
}


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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e18
#define ret return

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int main(){
	ll n;
	cin >> n;
	ll a = 0;
	ll x;
	for(int i = 0; i < n; i++){
		cin >> x;
		a|=x;
	}
	if(a%2){
		cout<<"first\n";
	}
	else{
		cout<<"second\n";
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>

using namespace std;

vector<vector<int> > ns;

pair<int, int> diameter(int n, int prev){
    if(ns.at(n).size() == 1 && ns.at(n).at(0) == prev){
        return make_pair(0, 0);
    }
    int d = 0;
    int h1 = -1;
    int h2 = -1;
    for(int n2 : ns.at(n)){
        if(n2 == prev){ continue; }
        auto res = diameter(n2, n);
        d = max(d, res.first);
        d = max(d, res.second + 1);
        if(res.second > h1){
            h2 = h1;
            h1 = res.second;
        }else if(res.second > h2){
            h2 = res.second;
        }
    }
    if(h2 > -1){
        d = max(d, h1 + h2 + 2);
    }
    return make_pair(d, h1 + 1);
}

int main(){
    int n;
    scanf("%d", &n);
    ns.resize(n);
    for(int i = 0; i < n - 1; ++i){
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        ns.at(a).push_back(b);
        ns.at(b).push_back(a);
    }
    //printf("diam = %d\n", diameter(0, -1).first);
    if(diameter(0, -1).first % 3 == 1){
        printf("Second\n");
    }else{
        printf("First\n");
    }
    return 0;
}


Measured memory_bytes: 26112
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int a, b;
		int GCD = 0, LCM = 0;
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			a = scan.nextInt();
			b = scan.nextInt();
			GCD = 0;
			LCM = 0;
			/* 最大公約数 */
			for (int i = 1; i <= Math.min(a, b); i++) {
				if ((a % i == 0) && (b % i == 0)) {
					GCD = i;
				}
			}
			/* 最小公倍数 */
			for (int i = 1; i <= Math.min(b, 2000000000); i++) {
				 if((a*i)%b==0){
					 LCM = a*i;
					 break;
				 }
			}
			System.out.println(GCD+" "+LCM);
		}
	}

}

Measured memory_bytes: 20384
#include <stdio.h>
int main(){
    int n,count=0,point=1;
    scanf("%d",&n);
    int a[n],b[n];
    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
        b[i]=0;
    }
     while(1){
        if (point==2){
            break;
        }
        if (b[point-1]==1){
            count=-1;
            break;
        }
        b[point-1]=1;
        point=a[point-1];
        count++;
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    ll r, d, x;
    cin >> r >> d >> x;
    rep(i, 10)
    {
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));


#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(itr, v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl

signed main(){
  int K, N; cin >> K >> N;
  vector<int> A(N+1);
  REP(x, N){cin >> A.at(x);} 

  int sum = 0;
  vector<int> v(N+1);
  FOR(x, 1, N+1) {
    if(x != N) {
      int partSum = A.at(x) - A.at(x-1);
      v.push_back(partSum);
      sum += partSum;
    } else {
      int partSum = (K - A.at(x-1)) + A.at(0);
      v.push_back(partSum);
      sum += partSum;
    }
  }

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

  cout << sum - v.back() << endl;
}


Measured memory_bytes: 6272
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll [[maybe_unused]] = long long;
using ull [[maybe_unused]] = unsigned long long;
using ld [[maybe_unused]] = long double;

[[maybe_unused]] static constexpr int mod = (int)1e9 + 7;
[[maybe_unused]] static constexpr int inf = 100100100;
[[maybe_unused]] static constexpr ll linf = 1e18;
[[maybe_unused]] static constexpr double eps = 1e-9;
[[maybe_unused]] static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, a) for (ll i = a; i >= 0; --i)
#define all(obj) begin(obj), end(obj)
#define rall(obj) rbegin(obj), rend(obj)
#define pb push_back
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<pair<ll, ll>> X;
    rep (i, N) {
        int x;
        cin >> x;
        X.pb({x, i});
    }
    sort(all(X));
    vector<ll> ans(N);
    rep (i, N) {
        if (i < N / 2) {
            ans[X[i].snd] = X[N / 2].fst;
        } else {
            ans[X[i].snd] = X[N / 2 - 1].fst;
        }
    }
    rep (i, N) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 7788
S = gets.chomp

case S
when "SUN"
  ans = 7
when "MON"
  ans = 6
when "TUE"
  ans = 5
when "WED"
  ans = 4
when "THU"
  ans = 3
when "FRI"
  ans = 2
when "SAT"
  ans = 1
end

puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
	  result=(result*base)%modulus;
	  exponent=exponent>>1;
	  base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
string s;
int main(){FAST;
cin>>s;
ll n =s.length();
if(n == 2){
	if(s[0] == s[1]){
		cout<<1<<' '<<2;
	}
	else{
		cout<<-1<<' '<<-1;
	}
	return 0;
}
for(ll i=0;i<n-2;i++){
	set<char>f;
	for(ll j=i;j<i+3;j++){
		f.insert(s[j]);
	}
	if(f.size()<3){
		cout<<i+1<<' '<<i+3;
		return 0;
	}
}
cout<<-1<<' '<<-1;
return 0;
}

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

int main(){
  long long int n,k;
  cin>>n>>k;
  vector<long long int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  if(n==1){
    if(a[0]>=k){
      cout<<0<<endl;
      
    }
    else{
      cout<<1<<endl;
    }
    return 0;
  }
  sort(a.begin(),a.end());
  vector<vector<int>> dpl(n,vector<int>(k+1,0));
  vector<vector<int>> dpr(n,vector<int>(k+1,0));
  dpl[0][0]=true;
  if(a[0]<=k) dpl[0][a[0]]=true;
  for(int i=1;i<n;i++){
    for(int j=0;j<k+1;j++){
      dpl[i][j]=dpl[i-1][j];
      if(j-a[i]>=0){
	dpl[i][j]=(dpl[i][j]||dpl[i-1][j-a[i]]);
      }
    }
  }
  dpr[n-1][0]=true;
  if(a[n-1]<=k) dpr[n-1][a[n-1]]=true;
  for(int i=n-2;i>=0;i--){
    for(int j=0;j<k+1;j++){
      dpr[i][j]=dpr[i+1][j];
      if(j-a[i]>=0){
	dpr[i][j]=(dpr[i][j] || dpr[i+1][j-a[i]]);
      }
    }
  }
  
  int lb=-1,ub=n;
  while(ub-lb>1){
    int mid=(ub+lb)/2;
    bool isok=false;
    for(int val=max(k-a[mid],0LL);val<k;val++){
      for(int x=0;x<k;x++){
	int y=val-x;
	if(y<0) continue;
	if(mid==0){
	  isok=isok||dpr[mid+1][val];
	}
	else if(mid==n-1){
	  isok=isok||dpl[mid-1][val];
	}
	else{
	  isok=(isok||(dpl[mid-1][x] && dpr[mid+1][y]));
	}
      }
    }
    if(isok){
      ub=mid;
    }
    else{
      lb=mid;
    }
  }
  cout<<ub<<endl;
  return 0;
}


Measured memory_bytes: 195968
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

typedef int SumType;
class Sum2D {
public:
    Sum2D() {}
    Sum2D(const vector<vector<SumType>> &a)
        :h((int)a.size()), w((int)a[0].size()), s(h + 1, vector<SumType>(w + 1))
    {
        for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j)
            s[i][j] = s[i - 1][j] + s[i][j - 1] + a[i - 1][j - 1] - s[i - 1][j - 1];
    }

    SumType get(int u, int l, int d, int r) {
        return s[d][r] - s[u][r] - s[d][l] + s[u][l];
    }
private:
    int h, w;
    vector<vector<SumType>> s;
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, Q;
    cin >> N >> M >> Q;

    vector<string> S(N);
    rep(i, N)cin >> S[i];

    vector<vi> vs(N, vi(M)), ey(N, vi(M)), ex(N, vi(M));

    rep(i, N)rep(j, M) {
        if (S[i][j] == '1') {
            vs[i][j] = 1;
            if (i > 0 && S[i - 1][j] == '1') {
                ey[i - 1][j] = 1;
            }
            if (j > 0 && S[i][j - 1] == '1') {
                ex[i][j - 1] = 1;
            }
        }
    }

    Sum2D V(vs), EY(ey), EX(ex);
    rep(i, Q) {
        int u, l, d, r, a, b, c;
        cin >> u >> l >> d >> r;
        --u; --l;
        a = V.get(u, l, d, r);
        b = EY.get(u, l, d - 1, r);
        c = EX.get(u, l, d, r - 1);
        cout << a - b - c << endl;
    }
}


Measured memory_bytes: 100480
import java.io.*;
public class Main {
	private static int sum;
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		while(str.equals("0")!=true){
			sum=0;
			for(int i=0;i<str.length();i++){
				String a=str.substring(i, i+1);
				int n=Integer.parseInt(a);
				sum+=n;
			}
			System.out.println(sum);
			str=br.readLine();
		}
	}
}

Measured memory_bytes: 17164
n, d = list(map(int, input().split()))
x, y = [], []
res = 0
for _ in range(n):
    xi, yi = list(map(int, input().split()))
    if (xi ** 2 + yi ** 2) ** 0.5 <= d:
        res += 1
    x.append(xi)
    y.append(yi)
print(res)


Measured memory_bytes: 97532
#include <bits/stdc++.h>
 
using namespace std;
 
template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}
 
class Solution {
public:
	void solve() {
        int n, ma, mb;
        cin >> n >> ma >> mb;
        vector<vector<int>> dp(401, vector<int>(401, 0x7f7f7f7f));
        dp[0][0] = 0;
        for(int i=0; i < n; i++){
            int a, b, c;
            cin >> a >> b >> c;
            for(int j=400; j - a >= 0; j--){
                for(int k=400; k - b >= 0; k--){
                    updmin(dp[j][k], dp[j-a][k-b] + c);
                }
            }
        }
        int ret = 0x7f7f7f7f;
        for(int i = 1; i * max(ma, mb) <= 400; i++)updmin(ret, dp[i*ma][i*mb]);
        if(ret == 0x7f7f7f7f)cout << -1 << endl;
        else cout << ret << endl;
		return;
	};
};
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
  int a, b;cin>>a>>b;
  if(a<=5){
    cout << 0 << endl;
  }else if (a <=12){
    cout << b/2 << endl;
  }else{
    cout << b << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    char S[4],T[4];

    int i,k=0;

    scanf("%s",&S[0]);
    scanf("%s",&T[0]);

    for(i=0;i<3;i++){
        if(S[i]==T[i]){
            k++;
        }
    }

    printf("%d\n",k);

    return 0;
}

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

ll gcd(ll x,ll y){
  ll a=max(x,y);
  ll b=min(x,y);
  if(a%b==0)
    return b;
  else
    return gcd(b,a%b);
}
  

int main(){
  ll A,B,C,D; cin>>A>>B>>C>>D;
  ll E=C/gcd(C,D)*D;
  
  ll countA=A/C+A/D-A/E;
  ll countB=B/C+B/D-B/E;
  ll count;
  
  if(A%C==0 || A%D==0)
    count=countB-countA+1;
  else
    count=countB-countA;
  
  cout<<B-A+1-count<<endl;
  //cout<<countA<<endl<<countB<<endl<<count<<endl<<E<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict

S = input()
N = len(S)

MOD = 10**9 + 7
mod = 13

A = [1, 10, 9, 12, 3, 4]
D = defaultdict(int)
a = 0

for i in range(N):
  if S[-1-i] == "?":
    D[A[i%6]] += 1
  else:
    a += A[i%6] * int(S[-1-i]) % mod
    a %= mod

ans = [0]*mod
ans[0] = 1

for i, x in D.items():
  for _ in range(x):
    prev = [a for a in ans]
    ans = [0]*mod
    for j in range(mod):
      for y in range(10):
        ans[(j+i*y)%mod] += prev[j]
      ans = [a%MOD for a in ans]

print(ans[(5-a)%mod])

Measured memory_bytes: 75012
#include <iostream>
#include <vector>
 
using namespace std;
 
using ll = long long;
 
vector<ll> fact;
vector<ll> ifact;
const int mod = 1e9 + 7;
 
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll ret = (n & 1) ? x : 1;
  ll half = mod_pow(x, n / 2, mod);
  ret *= half * half % mod;
  return ret % mod;
}
 
void init(int f_max = 200000) {
  fact.resize(f_max + 1);
  ifact.resize(f_max + 1);
  fact[0] = 1;
  for(ll i = 1; i <= f_max; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  ifact[f_max] = mod_pow(fact[f_max], mod - 2, mod);
  for(ll i = f_max - 1; i >= 0; i--) {
  	ifact[i] = (ifact[i + 1] * (i + 1)) % mod;
  }
}

ll comb(ll n, ll k) {
  return fact[n] * ifact[n - k] % mod * ifact[k] % mod;
}
 
int main() {
  init();
  ll N, M, K;
  cin >> N >> M >> K;
  ll sum = 0;
  for(ll d = 1; d <= N; d++) {
    sum += (d * (N - d)) % mod * M % mod * M % mod;
    sum %= mod;
  }
  for(ll d = 1; d <= M; d++) {
    sum += (d * (M - d)) % mod * N % mod * N % mod;
    sum %= mod;
  }
  cout << sum * comb(N * M - 2, K - 2) % mod << endl;
}


Measured memory_bytes: 3328
//karna padega 
#include<bits/stdc++.h>
using namespace std;	
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;	i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n;
		cin >> n ;
		n--;
		cout << (n*(n+1))/2;
	
	
	}
	return 0;
}

Measured memory_bytes: 3620
from collections import defaultdict

N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]

cnts = defaultdict(int)

for s in S:
    cnts[s] += 1

res = 0

for _, v in cnts.items():
    res += v * (v - 1) // 2

print(res)


Measured memory_bytes: 19760
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t; cin >> s >> t;
  int n = s.size();
  s += s;
  rep(i, n) {
    if(s.substr(i, n) == t) {
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}


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

int main(){
    int T;
    cin>>T;
    for(int i=0;i<T;i++){
        int p,q;
        cin>>p>>q;
        bool isprime=true;
        for(int m=-141;m<=141;m++){
            for(int n=-141;n<=141;n++){
                if(m==1&&n==0) continue;
                if(m==-1&&n==0) continue;
                if(m==0&&n==1) continue;
                if(m==0&&n==-1) continue;
                if(m==p&&n==q) continue;
                if(m==-p&&n==-q) continue;
                if(m==-q&&n==p) continue;
                if(m==q&&n==-p) continue;
                int d = m*m+n*n;
                if(d>p*p+q*q||d==0) continue;
                if((m*p+n*q)%d==0&&(m*q-n*p)%d==0){
                    isprime=false;
                    break;
                }
            }
            if(!isprime) break;
        }
        if(isprime){
            cout<<'P'<<endl;
        }else{
            cout<<'C'<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;
  
typedef pair<int,int> P;
 
typedef struct{
    int x,y;
} Point; 
 
int dist(P a){
    return a.first*a.first+a.second*a.second;
}
  
int main(){
    int n;
  
    while(cin >> n ,n){
	Point a;
	vector<P> v;
  
	for(int i = 0 ; i < n ; i++){
	    cin >> a.x >> a.y;
	    v.push_back(P(a.x,a.y));
	}  
  
	sort(v.begin(),v.end());
  
	int ans = 0;
 
	for(int i = 0 ; i < n-1 ; i++){
	    for(int j = i + 1 ; j < n ; j++){
		P b,c,d;
     
		b.first = v[i].first - v[j].first;
		b.second = v[i].second - v[j].second;
     
		c.first = v[i].first - b.second;
		c.second = v[i].second + b.first;
		d.first = v[j].first - b.second;
		d.second = v[j].second + b.first;
 
		if(binary_search(v.begin(),v.end(),c) && binary_search(v.begin(),v.end(),d)){
		    ans = max(ans,dist(b));
		}   
	    }
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3148
#include <cstdio>
#include <algorithm>
const int MAXN=3E5+10;
const int mod=1E9+7;
int N,M;
struct pair {
	int l,r;
	bool operator < (const pair&a) const {
		return r-l < a.r-a.l;
	}
	int len() {return r-l+1;}
}rc[MAXN];
struct FWT {
	int f[MAXN];
	void change(int i,int x) {
		for(;i<=M;i+=i&(-i))
			f[i]+=x;
	}
	int query(int i) {
		int ans=0;
		for(;i;i-=i&(-i))
			ans+=f[i];
		return ans;
	}
}fw;
int main() {
	scanf("%d%d",&N,&M);
	for(int i=1;i<=N;++i) {
		scanf("%d%d",&rc[i].l,&rc[i].r);
	}std::sort(rc+1,rc+N+1);
	/*for(int i=1;i<=N;++i) {
		fw.change(rc[i].l,1);
		fw.change(rc[i].r+1,-1);
	}*/
	int tail=1;
	for(int i=1;i<=M;++i) {
		while(tail<=N&&rc[tail].len()<i){
			fw.change(rc[tail].l,1);
			fw.change(rc[tail].r+1,-1);
			++tail;
		}
		int ans=N-tail+1;
		for(int j=0;j<=M;j+=i) {
			ans+=fw.query(j);
		}printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3712
{-# LANGUAGE BangPatterns #-}
import Data.Word
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U

-- Input: s t
-- Output: arr
--   (arr ! i) ! j == length of lcs of (drop i s, drop j t)
lcsTable :: BS.ByteString -> BS.ByteString -> V.Vector (U.Vector Word16)
lcsTable s t = V.scanr' (\ !x !v ->
                           -- for some i (0 <= i < m),
                           --   x = BS.index s i :: Char
                           --   v = arr ! (i+1) :: U.Vector Word16
                           U.scanr (\(!y,!w,!u) !l ->
                                      -- for some j (0 <= j < n)
                                      --   y = BS.index t j :: Char
                                      --   w = (arr ! (i+1)) ! j :: Word16
                                      --   u = (arr ! (i+1)) ! (j+1) :: Word16
                                      --   l = (arr ! i) ! (j+1) :: Word16
                                      if x == y
                                      then u + 1
                                      else max w l
                                   ) 0 (U.zip3 t' (U.init v) (U.tail v))
                        ) (U.replicate (n+1) 0) (V.fromListN m $ BS.unpack s)
  where !m = BS.length s
        !n = BS.length t
        !t' = U.fromListN n (BS.unpack t)

solve :: BS.ByteString -> BS.ByteString -> BS.ByteString
solve !s !t = let !table = lcsTable s t
                  !m = BS.length s
                  !n = BS.length t
                  recon !i !j | i >= m || j >= n = Nothing
                              | x == y = let !i' = i+1 ; !j' = j+1
                                         in Just (x, (i', j'))
                              | (table V.! (i+1)) U.! j >= (table V.! i) U.! (j+1) = recon (i+1) j
                              | otherwise = recon i (j+1)
                    where x = BS.index s i
                          y = BS.index t j
                  (result, _) = BS.unfoldrN (fromIntegral $ (table V.! 0) U.! 0) (\(!i,!j) -> recon i j) (0,0)
              in result

main = do
  s <- BS.getLine
  t <- BS.getLine
  -- BS.length s <= 3000, BS.length t <= 3000, BS.all isAsciiLower s, BS.all isAsciiLower t
  BS.putStrLn (solve s t)


Measured memory_bytes: 25468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int>P;
#define PI 3.14159265359
#define MOD 1000000007
//ABC166 E 
int main(){
  int N;
  cin >>N;
  vector<int>A(N);
  rep(i,N){cin >>A[i];}
  map<int,int>mp;
  ll ans=0;
  //i<jのとき、Ai+i=j-Ajなるものを探したい。→iを小さいほうから回して
  //mapにAi+iをkeyとしその値の個数をめも。その後i-Aiで検索し、
  //map中の数をansに加える。こうすればi以下の者で一致する数を数えられる。
  rep(i,N){
  	int x=A[i],y,z;
  	y=A[i]+i+1;
  	z=i+1-A[i];
    ans+=mp[z];
    mp[y]++;
  }
  cout<<ans;
}

Measured memory_bytes: 21132
/*------------------------- Bism Allah Alruhmin Alrahim -------------------------------*/
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

ll LCM(ll x , ll y){
	return (x*y) / __gcd(x,y) ;
}

ll NumOfDiv(ll a , ll b , ll k){
	return b/k - a/k + (a%k == 0) ;
}
void start(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int res(int a , int b , int c){
	int x[3] = {a,b,c} ;
	sort(x,x+3);
	return x[1] ;
}

int main()
{
	start();
	int n ; 
	cin >> n ;
	int x[n] ;
	set<int> s;
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i] ;
	} 
	int a = 0 ;
	for (int i = 1; i < n-1; ++i)
	{
		if(res(x[i-1] , x[i] , x[i+1]) == x[i]){
			a++ ;
		}
	} 
	cout << a << endl ;
	return 0 ;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-8L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()
#define int ll
int costs(int now) {
    for (int i = 0; i < 62; ++i) {
        if (now < (1 << i)) {
            return i + 1;
        }
    }
}

int secret_d = 10;
int n;

int interact(int a) {
    int ans = 0;
    cout << "? " << a << endl;
    if (true) {
        int r = 1;
        for (int i = 0; i < 60; ++i) {
            if ((secret_d & (1LL << i))) {
                ans += costs(r) * costs(a);
                r = r * a % n;                
            }
            ans += costs(a) * costs(a);
            a = a * a % n;
        }
    }
    else {
        cin >> ans;
    }
    return ans;
}

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}

long double comb(int a, int b) {
    ld ans = 1;
    for (int q = 0; q < b; ++q) {
        ans *= (ld)(a - q);
        ans /= (ld)(q + 1);
    }
    return ans;
}

void solve(){
    int n;
    cin >> n;
    vector<int> inputs;
    REP(i, n) {
        int a;
        cin >> a;
        inputs.push_back(a);
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += inputs[i] / 2;
    }
    for (int q = 0; q < n-1; ++q) {
        if(inputs[q] % 2 == 1 and inputs[q+1]% 2 == 1){
            ans++;
            q++;
        }
        else if (inputs[q] % 2 == 1 and inputs[q+1] > 0) {
            inputs[q + 1] += 1;
            inputs[q]--;
        }
    }
    cout << ans << endl;
}

#undef int
int main() {
    init();
    solve();
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n, t = 0;
    cin >> n;
    bool color[8] = {};
    rep(i, n) {
        int r;
        cin >> r;
        r /= 400;
        if (r > 7) t++;
        else color[r] = true;
    }
    int mini = 0;
    rep(i, 8) if (color[i]) mini++;
    if (mini == 0) {
        cout << 1 << " " << t << endl;
    } else {
        cout << mini << " " << mini + t << endl;
    }
    return 0;
}

Measured memory_bytes: 256