akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int n, x, y;
vector<vector<int>> e;
vector<int> cnt;
vector<int> dp;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> x >> y;
    e.resize(n + 1);
    cnt.assign(n + 1, 0);
    if (x != y) {
        e[x].push_back(y);
        e[y].push_back(x);
    }
    for (int i = 1; i < n; ++i) {
        e[i].push_back(i + 1);
        e[i + 1].push_back(i);
    }
    for (int i = 1; i <= n; ++i) {
        dp.assign(n + 1, -1);
        dp[i] = 0;
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (auto v: e[u]) {
                if (dp[v] == -1) {
                    dp[v] = dp[u] + 1;
                    q.push(v);
                }
            }
        }
        for (int j = i + 1; j <= n; ++j) {
            if (1 <= dp[j] && dp[j] < n) {
                cnt[dp[j]] += 1;
            }
        }
    }
    for (int i = 1; i < n; ++i) {
        cout << cnt[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 384
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e12
using namespace std;

const int maxn = 110000;

int X,Y,Z,n;
ll a[maxn],b[maxn],c[maxn];
bool v[maxn];
struct node{ll a,b,c;}s[maxn];
inline bool cmpc(const node x,const node y){return x.c<y.c;}

ll ans;
ll pre[maxn],suf[maxn];
struct E{ll x;};
inline bool operator <(const E x,const E y){return x.x>y.x;}
priority_queue<E>q;

int main()
{
	scanf("%d%d%d",&X,&Y,&Z); n=X+Y+Z;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld%lld",&a[i],&b[i],&c[i]); ans+=c[i];
		s[i]=(node){a[i]-c[i],b[i]-c[i],a[i]-b[i]};
	}
	sort(s+1,s+n+1,cmpc);
	
	for(int i=1;i<=n;i++)
	{
		pre[i]=pre[i-1];
		if(i>Y)
		{
			if((q.top()).x<s[i].b) 
				pre[i]-=(q.top()).x,q.pop(),pre[i]+=s[i].b,q.push((E){s[i].b});
		}
		else pre[i]+=s[i].b,q.push((E){s[i].b});
	}pre[0]=-1e12;
	while(!q.empty()) q.pop();
	for(int i=n;i>=1;i--)
	{
		suf[i]=suf[i+1];
		if(n-i>=X)
		{
			if((q.top()).x<s[i].a)
				suf[i]-=(q.top()).x,q.pop(),suf[i]+=s[i].a,q.push((E){s[i].a});
		}
		else suf[i]+=s[i].a,q.push((E){s[i].a});
	}suf[n+1]=-1e12;
	ll now=LLONG_MIN;
	for(int i=1;i<=n;i++) if(i>=Y&&n-i>=X)
	{
		ll temp=pre[i]+suf[i+1];
		if(temp>now) now=temp;
	}
	ans+=now;
	printf("%lld\n",ans);
	
	return 0;
}


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

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

int main(){
    int x;
    cin >> x;
    int A[100020] = {};
    bool B[100020] = {};
    for(int i=2;i<100010;i++){
        A[i] = i;
    }
    for(int i=2;i<100010;i++){
        if(!B[i]){
            for(int j=i*2;j<100010;j+=i){
                B[j] = true;
            }
        }
    }
    for(int i=x;i<100010;i++){
        if(!B[i]){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

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

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll k; cin >> k;
    if (k > (n-1)*(n-2)/2){
        cout << -1 << endl;
        return 0;
    }
    ll edges_base = n-1;
    ll edges_additional = (n-1)*(n-2)/2 - k;
    cout << edges_base + edges_additional << endl;
    REP(i, edges_base){
        cout << 1 << " " << i+2 << endl;
    }
    ll e = 0;
    bool b = false;
    for (int i=3; i<=n; i++){
        for (int j=2; j<i; j++){
            if (e == edges_additional){
                b = true;
                break;
            }
            e++;
            cout << i << " " << j << endl;
        }
        if (b == true){
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

d = defaultdict(lambda: 0)

def get_card(num, mode):
    for _ in range(num):
        w = input()
        if mode == 'blue':
            d[w] += 1
        elif mode == 'red':
            d[w] -= 1

            
if __name__ == '__main__':
    n = int(input())
    get_card(n, mode='blue')
    m = int(input())
    get_card(m, mode='red')
    ans = sorted(d.items(), key=lambda x: x[1], reverse=True)
    if ans[0][1] >= 0:
        print(ans[0][1])
    else:
        print(0)

Measured memory_bytes: 3316
/* Justin Choi */
#include <bits/stdc++.h>
using namespace std;

string FILENAME = "filename";
#define io ifstream fin(FILENAME + ".in"); ofstream fout(FILENAME + ".out")
#define fwrite(X) fout << X;
#define fwriteln(X) fout << X << endl;
#define qio ios_base::sync_with_stdio(false); cin.tie(NULL)

#define forl(V, N) for(int V = 0; V < N; V++)
#define for1(V, N) for(int V = 1; V <= N; V++)
#define fore(E, X) for(auto &E:X)
#define newl cout << endl
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
#define rem(X) X.top(); X.pop()
#define setmin(A, B) A = min(A, B)
#define setmax(A, B) A = max(A, B)

#define graph unordered_map<int, unordered_set<int>>
#define um unordered_map
#define us unordered_set
#define vi vector<int>
#define pi pair<int, int>
#define ll long long
#define pb push_back
#define mp make_pair
#define ins insert

int main() {
    qio; int n, m; cin >> n >> m;
    int ca = 0, pen = 0;
    um<int, int> occ;
    forl(i, m) {
        int q; string s; cin >> q >> s;
        if(s.compare("WA") == 0) {
            if(occ[q] != -1) occ[q]++;
        }
        else {
            if(occ[q] != -1) {
                ca++; pen+=occ[q];
                occ[q] = -1;
            }
        }
    }
    cout << ca << " " << pen << endl;
}

Measured memory_bytes: 4388
/*  "Sahand Alitanloo"  */
#include <bits/stdc++.h>
#define F first
#define S second
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define per(i) cout<<fixed<<setprecision(i)
#define pb push_back
#define all(v) begin(v),end(v)
#define endl '\n'
using namespace std;
typedef pair<int,int> pii;
typedef long double ld;
typedef long long ll;
const int MAX_N = 1e5+10;
const ll mod = 1e9+7;
const ll INF = 1e9;
inline ll bpow(ll t,ll n){ll ans=1;while(n>0){if(n&1)ans=(ans*t)%mod;t=(t*t)%mod,n>>=1;}return ans;}
/*
ll fact[MAX_N],ifact[MAX_N];
inline ll c(ll n,ll k){if(k>n||k<0)return 0;return (fact[n]*ifact[k]%mod*ifact[n-k])%mod;}
inline void get_fact(){fact[0]=1;ifact[0]=1;for(ll i=1;i<MAX_N;i++)fact[i]=(fact[i-1]*i)%mod,ifact[i]=bpow(fact[i],mod-2);}
*/

int rem[MAX_N];
main(){
    fast();per(0);
    //get_fact();
    int n;cin>>n ;
	for(int i=0;i<n;i++){
		int t;cin>>t ;
		rem[t%4]++ ;
	}
	if( ( (rem[1] + rem[3] <= rem[0] + 1) && (rem[2] == 0) ) || (rem[1] + rem[3] <= rem[0]) )
		cout<<"Yes" ;
	else
		cout<<"No" ;
}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    static ArrayList<ArrayList<Integer>> graph;
    static int[] indegree;
    static int[] dist;
    static boolean[] visited;

    public static void main(String[] args) {
        int n, m;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        graph = new ArrayList<ArrayList<Integer>>(n);
        indegree = new int[n];
        dist = new int[n];
        visited = new boolean[n];
        for (int i = 0; i < n; i++)
            graph.add(i, new ArrayList<>());
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            graph.get(a-1).add(b-1);
            indegree[b-1]++;
        }
        for (int i = 0; i < n; i++) {
            if (!visited[i] && indegree[i] == 0) {
                dfs(i);
            }
        }
        int ans = 0;
        for(int dis : dist) {
            ans = Math.max(ans, dis);
        }
        System.out.println(ans);

    }

    private static void dfs(int a) {
        if(visited[a]) return;
        visited[a] = true;
        for (int b : graph.get(a)) {
            dist[b] = Math.max(dist[b],dist[a] + 1);
            indegree[b]--;
            if (indegree[b] == 0) {
                dfs(b);
            }
        }
    }
}


Measured memory_bytes: 113436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int n,q;
string s;
const int q_max=2e5+2;
char t[q_max],d[q_max];

bool ljudge(int pos){
  int cpos=pos;
  rep(i,q){
    if(s[cpos]==t[i]){
      if(d[i]=='L') cpos--;
      else cpos++;
      if(cpos<0){
	return true;
      }
    }
  }
  return false;
}

bool rjudge(int pos){
  int cpos=pos;
  rep(i,q){
    if(s[cpos]==t[i]){
      if(d[i]=='L') cpos--;
      else cpos++;
      if(cpos>=n){
	return true;
      }
    }
  }
  return false;
}

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

  cin >> n >> q;
  cin >> s;
  rep(i,q){
    cin >> t[i] >> d[i];
  }
  if(ljudge(n-1) || rjudge(0)){
    cout << 0 << endl;
    return 0;
  }
  int ans=0;
  int ub=n;  
  int lb=0;
  int left=ub;
  if(ljudge(0)){
    while(ub-lb>1){
      int mid=(ub+lb)/2;
      if(ljudge(mid)) lb=mid;
      else {
	ub=mid;
      }
    }
    left=ub;
  }
  else left=0;//安全

  ub=n;lb=0;
  int right=lb;
  if(rjudge(n-1)){
    while(ub-lb>1){
      int mid=(ub+lb)/2;
      if(rjudge(mid)) ub=mid;
      else {
	lb=mid;
      }
    }
    right=lb;
  }
  else right=n-1;
  //  cout << left << " " << right << endl;
  cout << max(right - left +1,0) << endl;

  
  return 0;
    

}


Measured memory_bytes: 976
from collections import defaultdict

def gcd(x,y):
    if max(x,y) % min(x,y) == 0 : return min(x,y)
    else : return gcd(min(x,y) ,max(x,y)%min(x,y))

if __name__ == '__main__' :
        a,b = [int(i) for i in input().split(" ")]
        print(gcd(a,b))


Measured memory_bytes: 6000
// 　　＿＿
// 　／　<＠ﾌ
//  ｜(ﾉﾉハ))
//  ﾉ从ﾟヮﾟ从
// 　ﾉ｜ｿﾉГ|つ author:hotarunx
// 〈_ﾉ^^^ヽ|
// 　~~tｧtｧ~
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    string s;
    cin >> s;

    int ans = 0;
    int c = 0;

    for (int i = 0; i < 3; i++) {
        if (s[i] == 'R')
            c++;
        else
            c = 0;
        ans = max(c, ans);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
#define mod 1000000007
#define ll long long
#define int long long
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
int mul(int x,int y){return 1LL*x*y%mod;}
int qpow(int x,int y)
{
	int ans=1;
	while(y)
	{
		if(y&1) ans=ans*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ans;
}
int inv(int x)
{
	return qpow(x,mod-2);
}
int C(int x,int y)
{
	int ans=1;
	for(int i=0;i<y;i++) ans=ans*(x-i)%mod;
	int sub=1;
	for(int i=1;i<=y;i++) sub=sub*i%mod;
//	cout<<ans<<" "<<sub<<endl;
//	printf("%d %d %d\n",x,y,ans*inv(sub)%mod);
	return ans*inv(sub)%mod;
}
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	int n,a,b;
	cin>>n>>a>>b;
	int tot=qpow(2,n)-1;
	tot=(tot-C(n,a)-C(n,b))%mod;
	tot=(tot+mod)%mod;
	cout<<tot<<endl;
#ifdef __LOCAL__
	cout<<"Time Used : "<<clock()<<endl;
#endif
	return 0;
}
 

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main(){
    ll n,m; cin >> n >> m;
    if(m - n * 2 >= 0) cout << n + (m - n * 2) / 4 << endl;
    else cout << m / 2 << endl;
    
}

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

int main()
{
    string S;
    cin >> S;

    ll n = S.size();
    char start = S.at(0);
    bool zero = false;
    if (start == '0')
    {
        zero = true;
    }
    int res = 0;
    for (int i = 0; i < n; i++)
    {
        if (zero)
        {
            if (S.at(i) != '0')
                res++;
        }
        else
        {
            if (S.at(i) != '1')
                res++;
        }
        zero = !zero;
    }

    cout << res << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll ok = 100000;
  ll ng = 0;
  while(abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if((mid - 1) * (k - 1) + k >= n)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

int main()
{
    int i = 0;
    while (true)
    {
        ++i;
        int x, y;
        cin >> x >> y;
        if (x || y)
        {
            cout << min(x, y) << " " << max(x, y) << endl;
        }
        else
        {
            break;
        }
    }

    return 0;
}


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

int main()
{
	int n;
	string str;
	cin >> n;

	set <string> a;

	for (int i = 0; i < n; i++) {
		cin >> str;
		a.insert(str);
	}
	cout << size(a);
}

Measured memory_bytes: 19216
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main(void){
	string S; cin >> S;
	char lst = S[S.length() - 1];
	if (lst == 's') cout << S << "es" << endl;
	else cout << S << "s" << endl;
	return 0;
}

Measured memory_bytes: 3628
import itertools

N = int(input())

syougen_list = []
people = [-1] * N
for i in range(N):
    a_i = int(input())
    a_i_list = []
    for j in range(a_i):
        a_i_list.append(list(map(int, input().split())))
    syougen_list.append(a_i_list)


output = 0
for i in itertools.product([1,0], repeat=N):
    legal = True
    for index, j in enumerate(i):
        if j == 1:
            syougen = syougen_list[index]
            for k in syougen:
                if i[k[0] - 1] != k[1]:
                    legal = False
                    break
    if not legal:
        continue

    match = True
    honest_syougen_list = []
    for index, j in enumerate(i):
        if j == 1:
            honest_syougen_list += syougen_list[index]
    for j in honest_syougen_list:
        if people[j[0] - 1] == -1:
            people[j[0] - 1] = j[1]
        elif people[j[0] - 1] != j[1]:
            match = False
            break
    if match:
        number = i.count(1)
        if number >= output:
            output = number

print(output)

Measured memory_bytes: 3064
A = int(input())
B = int(input())
C = int(input())
X = int(input())

res = 0

for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if a*500 + 100*b + c*50 == X:
        res += 1
        
print(res)

Measured memory_bytes: 3060
sx, sy, tx, ty = [int(x) for x in input().split()]
ret = 'R' * (tx - sx) + 'U' * (ty - sy)
ret += 'L' * (tx - sx) + 'D' * (ty - sy)
ret += 'D' + 'R' * (tx - sx + 1) + 'U' * (ty - sy + 1) + 'L'
ret += 'U' + 'L' * (tx - sx + 1) + 'D' * (ty - sy + 1) + 'R'
print(ret)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  long long r = 0, g = 0, b = 0;
  for(int i = 0; i < n; i++) {
    if(s.at(i) == 'R') r++;
    else if(s.at(i) == 'G') g++;
    else b++;
  }
  long long sum = r * g * b;
  for(int i = 0; i < (n - 2); i++) {
    for(int j = i + 1; j < (n - 1); j++) {
      if(s.at(i) != s.at(j)) {
        if(j + (j - i) >= n) {
          continue;
        }
        char x = s.at(j + (j - i));
        if(s.at(i) != x && s.at(j) != x) sum--;
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <cstring>
using namespace std;

namespace zyt
{
	template<typename T>
	inline void read(T &x)
	{
		char c;
		bool f = false;
		x = 0;
		do
			c = getchar();
		while (c != '-' && !isdigit(c));
		if (c == '-')
			f = true, c = getchar();
		do
			x = x * 10 + c - '0', c = getchar();
		while (isdigit(c));
		if (f)
			x = -x;	
	}
	template<typename T>
	inline void write(T x)
	{
		static char buf[20];
		char *pos = buf;
		if (x < 0)
			putchar('-'), x = -x;
		do
			*pos++ = x % 10 + '0';
		while (x /= 10);
		while (pos > buf)
			putchar(*--pos);	
	}
	typedef long long ll;
	const int N = 1e5 + 10;
	int n, id[N];
	ll arr[N], ans[N];
	bool cmparr(const int i, const int j)
	{
		return arr[i] == arr[j] ? i < j : arr[i] > arr[j];	
	}
	int work()
	{
		read(n);
		for (int i = 0; i < n; i++)
			read(arr[i]), id[i] = i;
		sort(id, id + n, cmparr);
		int fir = 0, sec = 1;
		while (sec < n)
		{
			while (sec < n && arr[id[sec]] == arr[id[sec - 1]])
				sec++;
			if (sec == n)
				break;
			ans[id[fir]] += (ll)(arr[id[fir]] - arr[id[sec]]) * sec;
			if (id[fir] > id[sec])
				fir = sec;
			else
				arr[id[fir]] = arr[id[sec]];
			sec++;
		}
		ans[id[fir]] += arr[id[fir]] * n;
		for (int i = 0; i < n; i++)
			write(ans[i]), putchar('\n');
		return 0;	
	}	
}
int main()
{
	return zyt::work();	
}

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

#define N 25

typedef struct{
  int left, right;
}Node;

Node tree[N];
int n;
char root[N];

void visit_pre(int p){
  printf(" %d", p);
  if(tree[p].left != -1) visit_pre(tree[p].left);
  if(tree[p].right != -1) visit_pre(tree[p].right);
}

void visit_in(int p){
  if(tree[p].left != -1) visit_in(tree[p].left);
  printf(" %d", p);
  if(tree[p].right != -1) visit_in(tree[p].right);
}

void visit_post(int p){
  if(tree[p].left != -1) visit_post(tree[p].left);
  if(tree[p].right != -1) visit_post(tree[p].right);
  printf(" %d", p);
}
int main(){
  int i, r;
  scanf("%d", &n);
  memset(root, 1, n);
  for(i=0;i<n;i++) tree[i].left = tree[i].right = -1;
  for(i=0;i<n;i++){
    int idx, l, r;
    scanf("%d %d %d", &idx, &l, &r);
    tree[idx].left = l;
    tree[idx].right = r;
    root[l] = root[r] = 0;
  }
  for(i=0;i<n;i++) if(root[i]) r = i;
  printf("Preorder\n");
  visit_pre(r);
  printf("\n");
  printf("Inorder\n");
  visit_in(r);
  printf("\n");
  printf("Postorder\n");
  visit_post(r);
  printf("\n");
  return 0;
}



Measured memory_bytes: 2068
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<list>
#include<iterator>
#include<cstdlib>
#include<ctime>
#include<stdio.h>
#define _CRT_SECURE_NO_WARNINGS
#define __USE_MINGW_ANSI_STDIO
#define Fast ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
#define ll long long
#define ff float
#define oo bool
#define ii int
#define ch char
#define dd double
#define ld long double
#define ss string
#define pb push_back
#define all(c) c.rbegin(), c.rend()
#define loop(i,m,n) for(ll i=m;i<n;i++)
#define for1(i,m,n) for(ll i=m;i>=n;i--)
#define for2(i,m,n) for(ll i=m;i<=n;i++)
using namespace std;
//ld pi = 3.14159265359;
//const ll mod = 1e9 + 7;
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
ii main()
{
	//cout << fixed << setprecision(1);
	Fast;
	ll n; cin >> n;
	vector<ll>v(n);
	loop(i, 0, n)
	{
		cin >> v[i];
	}
	sort(all(v));
	ll sa = 0, sb = 0;
	for (ii i = 0; i < n; i += 2)
	{
		sa += v[i];
	}
	for (ii i = 1; i < n; i += 2)
	{
		sb += v[i];
	}
	cout << sa - sb;
}
/*
  //freopen(".in","r",stdin);
  //freopen(".out","w",stdout);

  scanf("%",&);
  printf("%",);
*/

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

typedef struct  List
{
	int key;
	struct  List *next, *prev;
}List;

List *head;

void init();
void listInsert(int);
List* listSearch(int);
void listDelete(List*);
void deleteFisrt();
void deleteLast();
void deleteKeyList(int);
void printList();

int main(void){
	int key, n,i,size = 0;
	char command[20];
	int np =0,nd = 0;

	scanf("%d" ,&n);
	init();

	for(i=0;i<n;i++){
		scanf("%s", command);		
		//printf("%s\n", command);
		if(command[0] == 'i'){scanf("%d",&key); listInsert(key); np++; size++;}
		else if(command[0] == 'd'){
			if(strlen(command) > 6){
				//printf("%c\n", command[6]);
				if(command[6] == 'F')deleteFisrt();
				else if(command[6] == 'L')deleteLast();
			}else {
				scanf("%d",&key);
				deleteKeyList(key); nd++;
			}
			size--;
		}
	}

	printList();
	printf("\n");
	return 0;

}

void init(){
	head = (List *) malloc(sizeof(List));
	head -> next = head;
	head -> prev = head;
}

void listInsert(int key){
	List *k = (List *)malloc(sizeof(List));
	k->key = key;
	k->next =head->next;
	head -> next -> prev = k;
	head -> next = k;
	k -> prev = head;
	//printList();
}

List* listSearch(int key){
	List *target = head -> next;
	while(target != head && target -> key != key){
		target = target -> next;
	}
	return target;
}

void listDelete(List *t){
	if(t == head) return;
	t -> prev -> next = t ->next;
	t -> next ->prev = t->prev;
	free(t);
}

void deleteFisrt(){
	listDelete(head -> next);
		//printList();
}

void deleteLast(){
	listDelete(head -> prev);
		//printList();
}

void deleteKeyList(int key){

	listDelete(listSearch(key));
		//printList();
}

void printList(){
	List *target = head ->next;
	int i = 0;
	while(1){
		if(target == head)break;
		if(i == 0) printf("%d", target->key);
		else printf(" %d",target -> key);
		i++;
		target = target -> next;
	}
}

Measured memory_bytes: 33080
#pragma region GNUC
//以下を参考にした
//https://yukicoder.me/wiki/auto_vectorization
#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif
#pragma endregion

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <cassert>//assert();
#include <fstream>
#include <random>
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)

/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;
#pragma region Math
// 最大公約数
template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
//inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}

// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
//inline T lcm(T a, T b){return a * b / gcd(a, b);}

template<class T>
T pow(T x,int n){
	T mul = x;
	T ans = (T)1;
	while(n){
		if(n&1){
			ans *= mul;
		}
		mul *= mul;
		n >>= 1;
	}
	return ans;
}
#pragma endregion //math

void solve(){
	int B=0;
	int C=0;
	for(int i=0;i<3;++i){
		int temp;
		cin >> temp;
		if( temp == 5 ){
			B++;
		}else if(temp == 7 ){
			C++;
		}
	}
	if( B==2 && C==1){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//std::cout << std::fixed;//小数を10進数表示
	//cout << setprecision(16);//小数点以下の桁数を指定
	
	solve();
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }

#define INF 1 << 30
int main() {
	string s, t;
	cin >> s >> t;
	sort(all(s));
	sort(all(t), greater<char>());
	int f = -1;
	rep(i, 0, min(s.size(), t.size())) {
		if (s[i] > t[i]) {
			f = 0;
			break;
		}
		else if (s[i] < t[i]) {
			f = 1;
			break;
		}
	}
	if (f == -1)f = s.size() < t.size();
	puts(f ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main()
{
	int a,b,c;
	int cnt=0;
 
	scanf("%d %d %d",&a,&b,&c);

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

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int s1[n+5];
    int s2[n+5];
    for(int i=0;i<n;i++)
    {
        cin>>s1[i];
    }
    for(int j=0;j<n;j++)
    {
        cin>>s2[j];
    }
    int sum1=0;
    int sum2=0;
    for(int i=0,j=0;i<n,j<n;i++,j++)
    {
        if(s1[i]>s2[j])
        {
            sum1+=s1[i];
            sum2+=s2[j];
        }
    }
    int ans=abs(sum1-sum2);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3620
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n, m = _ia()
    h = list(_ia())
    adj = [[] for _ in range(n)]
    for _ in range(m):
        a, b = _ia()
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)
    ans = 0
    for i in range(n):
        hi = h[i]
        f = True
        for j in adj[i]:
            hj = h[j]
            if hi <= hj:
                f = False
                break
        if f:
            ans += 1
    return ans


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 89664
s = input()
slist = list(s)

def rev(some):
    return list(reversed(some))
    
def check(slist):
    n = len(slist)
    if rev(slist) != slist:
        return "No"
    else:
        first_half = slist[0:int((n-1)/2)]
        second_half = slist[int(((n+3)/2))-1:(n+1)]
        if first_half != rev(first_half):
            return "No"
        else:
            if second_half != rev(second_half):
                return "No"
            return 'Yes'

print(check(slist))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9

int ma(int n) {
    return (n + 9) / 10 * 10;
}

int mud(int n) {
    return ma(n) - n;
}

int main(){
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    
    int sum = ma(a) + ma(b) + ma(c) + ma(d) + ma(e);
    int sai = max({mud(a), mud(b), mud(c), mud(d), mud(e)});
    cout << sum - sai << endl;

    return 0;
}

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

const int Maxn = 400015;

int n, k;
char str[Maxn];

int main()
{
    scanf("%d %d", &n, &k);
    scanf("%s", str);
    for (int i = n - 2; i >= 0; i -= 2)
        str[i] = str[i] == 'A'? 'B': 'A';
    for (int i = n; i < Maxn; i++)
        str[i] = 'A';
    char sav = n % 2 == 0? 'B': 'A';
    int pnt = 0;
    while (pnt < n && k > 0) {
        k--;
        if (str[pnt] == sav) str[pnt] = str[pnt] == 'A'? 'B': 'A';
        else pnt++;
    }
    if (pnt >= n) {
        k %= 2;
        if (k)
            if (str[pnt] == sav) str[pnt] = str[pnt] == 'A'? 'B': 'A';
            else pnt++;
    }
    for (int i = n - 2; i >= 0; i -= 2)
        str[pnt + i] = str[pnt + i] == 'A'? 'B': 'A';
    str[pnt + n] = '\0';
    printf("%s\n", str + pnt);
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    ll N, X;
    cin>>N>>X;
    ll sum = 0;
    ll cnt = 1;
    REP(i, N){
        ll y;
        cin>>y;
        sum += y;
        if(sum<=X) cnt++;
    }
    cout << cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        if(a<b){
        System.out.println("a < b");
        }else if (b<a){
        System.out.println("a > b");
        }else if(a==b){
        System.out.println("a == b");
        }
        
    }
}    
          

Measured memory_bytes: 26184
import java.io.*;

class Main
{
   public static void main(String[] args) throws IOException
   {

      BufferedReader br =
       new BufferedReader(new InputStreamReader(System.in));

      String str1 = br.readLine();
      String str2[] = str1.split(" ");
      int a = Integer.parseInt(str2[0]);
      int b = Integer.parseInt(str2[1]);
      int c = a*b;
      int d = 2*(a+b);
      System.out.println( c + " " + d );

   }
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

Weight visit(const Graph &g, Graph& T, int i, int j)
{
  if (T[i][j].weight >= 0) return T[i][j].weight;
  T[i][j].weight = g[i][j].weight;
  int u = T[i][j].dst;
  rep(k, T[u].size()) {
    if (T[u][k].dst == i) continue;
    T[i][j].weight = max(T[i][j].weight, visit(g,T,u,k)+g[i][j].weight);
  }
  return T[i][j].weight;
}

vector<Weight> HeightOfTree(const Graph& g)
{
  const int n = g.size();
  Graph T(g); // memoise on tree
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < T[i].size(); ++j)
      T[i][j].weight = -1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < T[i].size(); ++j)
      if (T[i][j].weight < 0)
        T[i][j].weight = visit(g, T, i, j);

  vector<Weight> ht(n); // gather results
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < T[i].size(); ++j)
      ht[i] = max(ht[i], T[i][j].weight);
  return ht;
}

int n;
int s, t;
Weight w;

int main()
{
  cin >> n;
  Graph g(n);
  rep(i, n){
    cin >> s >> t >> w;
    g[s].pb(Edge(s, t, w));
    g[t].pb(Edge(t, s, w));
  }

  vi res = HeightOfTree(g);

  vrep(v, res) cout << *v << endl;

  return 0;
}

Measured memory_bytes: 3108
import sys

N=int(input())
d=[-1 for _ in range(N)] #木の根から頂点i+1までの距離d[i]
d[0]=0 #根までの距離はゼロ
tree=[[] for _ in range(N)] #木の初期化、多次元リストを追加するのでからの要素を頂点の数だけ用意

for _ in range(N-1):
    u,v,w=map(int,input().split())
    u-=1 #序数のズレ補正
    v-=1
    tree[u].append([v,w]) #頂点u+1から伸びる辺の先v+1と辺の長さwをtree[u]に登録
    tree[v].append([u,w]) #逆からも登録

def dfs(u,D): #根からの距離Dである頂点u+1から先の分岐を探索
    sys.setrecursionlimit(10**6) #再帰回数の上限突破(N回ループのためN以上の数字を設定)
    for v,w in tree[u]: #木の頂点u+1から伸びる辺の先tree[u][0]と距離tree[u][1]をv,wとして取り出し全てについてforループ
        if d[v]==-1: #根から頂点v+1までのの距離d[v]が未記入だった場合(初期値-1)
            d[v]=(D+w) #根から頂点u+1までの距離Dに頂点u+1からv+1までの距離wを加えて根からの距離dのリストに格納
            dfs(v,D+w) #DFSなので次の頂点に移って探索続行、分岐は後回し。
            #木の末端に到達したらfor文中の変数で元の分岐に戻るが既にdが記入済みなのでif中の再帰を避けて次の頂点を探索

dfs(0,0) #(0,0)から始める、すなわち頂点1を根とした木を考える
for i in d:
    print(i%2) #解説にある通り、根からの距離の偶奇で色分けをすればよい

Measured memory_bytes: 90068
N, K = gets.split.map(&:to_i)
ab_list = N.times.map { gets.split.map(&:to_i) }

table = Hash.new { 0 }
ab_list.each do |(a, b)|
  table[a] += b
end
a_count_list = table.sort_by { |a, _| a }
count = 0
a_count_list.each do |a, c|
  if count + c >= K
    puts a
    exit 0
  end
  count += c
end


Measured memory_bytes: 15864
#include <bits/stdc++.h>
#define elif else if
using namespace std;


int a,b,c;
string s,t,r;


int main(void){
    cin>>s>>t>>r;
    transform (s.begin (), s.end (), s.begin (), ::toupper);
    cout<<s[0];
    transform (t.begin (), t.end (), t.begin (), ::toupper);
    cout<<t[0];
    transform (r.begin (), r.end (), r.begin (), ::toupper);
    cout<<r[0]<<endl;
}

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

int main() {
	long long N, M; cin >> N >> M;
	vector<long long>C(M);
	for (long long i = 0; i < M; i++) {
		cin >> C.at(i);
	}
	vector<long long>DP(100000, 1e9);
	for (long long i = 0; i <= N; i++) {
		DP.at(i) = i;
	}
	for (long long i = 0; i <= N; i++) {
		long long MIN = DP.at(i) + 1;
		for (long long j = 0; j < M; j++) {
			if (i + 1 < C.at(j)) MIN = min(MIN, DP.at(i) + 1);
			else MIN = min(MIN, min(DP.at(i) + 1, DP.at(i + 1 - C.at(j)) + 1));
		}
		DP.at(i + 1) = MIN;
	}
	cout << DP.at(N) << endl;
}


Measured memory_bytes: 3612
S = input()
T = input()
# S = 'acac'
# T = 'acm'
# DP[i][j]=Sのi文字とTのj文字の編集距離
DP = [[0 for j in range(len(T)+1)] for i in range(len(S)+1)]
for i in range(len(S)+1):
    DP[i][0] = i
for j in range(len(T)+1):
    DP[0][j] = j
for i in range(1, len(S)+1):
    for j in range(1, len(T)+1):
        if S[i-1] == T[j-1]:
            c = 0
        else:
            c = 1
        DP[i][j] = min(DP[i-1][j]+1, DP[i][j-1]+1, DP[i-1][j-1]+c)
print(DP[len(S)][len(T)])



Measured memory_bytes: 44016
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

int main(){
    string s; cin >> s;
    if(s=="Sunny"){
        cout << "Cloudy" << endl;
    }
    else if(s=="Cloudy"){
        cout << "Rainy" << endl;
    }
    else{
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define re register
inline int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0'){
		t=(t<<3)+(t<<1)+v-48;
		v=getchar();
	}
	return t;
}
using namespace std;
int n,p[2002],x,y;
signed main(){
	n=read();x=read();y=read();
	for(re int i=1;i<=n;++i)for(re int j=i+1;j<=n;++j)++p[min(j-i,abs(i-x)+1+abs(j-y))];
	for(re int i=1;i<n;++i)printf("%d\n",p[i]);
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
 
    var (N) = readInts()
    var power = 0
 
    while (N > 0) {
        N /= 2
        power += 1
    }
 
    println(Math.pow(2.toDouble(), power.toDouble() - 1).toInt())
}
 
fun readInts(): List<Int> = readStrings().map { it.toInt() }
fun readStrings(): List<String> = readLine()!!.split(" ")

Measured memory_bytes: 35976
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#define massert(x) assert(x)
#else
#define debug(args...) // Just strip off all debug tokens
#define massert(x)
#endif
struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

int a[100001];
int main(){	
#ifdef WAAUTOMATON
	//freopen("in.txt","r",stdin);
#endif
	int n;
	LL c,k;
	cin>>n>>c>>k;
	int ans=0;
	int nt=0,cnt=0;
	for(int i=1; i<=n; ++i) {
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1; i<=n; ++i) {
		int t=a[i];
		if(t>nt || c==cnt) {
			nt=t+k;
			cnt=1;
			++ans;
		} else {
			++cnt;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(void){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int min_result{A*X+B*Y};

    for(int c{0}; c<=2*max(X, Y); c+=2){
        int result0 = C*c;
        int result1 = A*(max(0, X-c/2));
        int result2 = B*(max(0, Y-c/2));
        int result = result0 + result1 + result2;
        if( result < min_result){
            min_result = result;
        }
    }

    cout << min_result << endl;
}


Measured memory_bytes: 3544
#include <iostream>

using namespace std;

int main()
{
	int N;
	int start = 400;
	int end = 599;

	int increment = 200;
	int kyu = 8;
	cin >> N;
	for (int i = start, j= end ; kyu >= 0; i += increment, j += increment) {
		if (N >= i && N <= j) {
			cout << kyu << endl;
			break;
		}
		kyu--;
	}
	return 0;
}


Measured memory_bytes: 3596
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;

int n,a[maxn];

int main() {
    //freopen("in.cpp","r",stdin);
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    if(n&1){
        int ret = 1;
        if(a[0]!=0)ret=0;
        for(int i=1;i<n;i+=2){
            if(a[i]!=a[i+1]||a[i+1]!=i+1)ret=0;
            else {
            ret+=ret;
            if(ret>=mod)ret-=mod;
            }
        }
        cout<<ret<<endl;
    } else {
        int ret = 1;
        for(int i=0;i<n;i+=2){
            if(a[i]!=a[i+1]||a[i+1]!=i+1)ret=0;
            else {
            ret+=ret;
            if(ret>=mod)ret-=mod;
            }
        }
        cout<<ret<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
{-# LANGUAGE OverloadedLists     #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}

import           Control.Monad
--import           Control.Monad.Loops
import           Data.IORef
import           Data.Maybe
import qualified Data.Text     as T
import qualified Data.Text.IO  as T
import           GHC.Base
import           System.IO

import qualified Data.Array    as A
import qualified Data.IntMap   as I
import           Data.List
import qualified Data.Map      as M
import qualified Data.Set      as S
import qualified Data.Vector   as V

-- for Text
(+.+) = T.append
(!.!) = T.index

-- for Vector
count :: (a -> Bool) -> V.Vector a -> Int
count p = V.length . V.filter p

-- for IO
readT :: Read a => T.Text -> a
readT = read . T.unpack

getLineSpc :: Read a => IO [a]
getLineSpc = do
  t <- T.getLine
  let xs = map readT $ T.split (== ' ') t
  return xs

getLineSpcVec :: Read a => IO (V.Vector a)
getLineSpcVec = do
  t <- T.getLine
  let xs = V.fromList $ map readT $ T.split (== ' ') t
  return xs

----------
-- main --
----------
main :: IO ()
main = already2018

already2018 :: IO ()
already2018 = do
  s <- getLine
  let (xs, y : ys) = splitAt 3 s
  putStrLn $  xs ++ '8' : ys

Measured memory_bytes: 380
import copy
N = int(input())
A = list(map(int, input().split()))

count_dict = [0] * N
for each in A:
    count_dict[each - 1] += 1

all_types = 0
for value in count_dict:
    all_types += value * (value - 1) // 2

# result_dict = {}
# for each in a_types:
#     result_dict[each] = all_types - count_dict[each] + 1

for a in A:
    print(all_types - count_dict[a - 1] + 1)

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

using namespace std;
using ll = long long;

ll seg[200005*4];
vector<ll> h;

int n;

void update(int targ, int l, int r, int idx, ll val){
    if(targ>r || targ<l) return;
    if(l==r){
        seg[idx] = val;
        return;
    }
    int mid = (l+r)/2;
    update(targ, l, mid, idx*2, val);
    update(targ, mid+1, r, idx*2+1, val);
    seg[idx] = max(seg[idx*2], seg[idx*2+1]);
}

ll query(int x, int y, int l, int r, int idx){
    if(x>r || y<l) return 0;
    if(x<=l && r<=y) return seg[idx];
    int mid = (l+r)/2;
    return max(query(x, y, l, mid, idx*2), query(x,y,mid+1,r,idx*2+1));
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    h.resize(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
        h[i]--;
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        ll q = query(0, h[i]-1, 0, n-1, 1);
        update(h[i], 0, n-1, 1, q+a);
        ans = max(ans, q+a);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
// #include <cmath>
// #include <numeric>
// #include <regex> //正規表現
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


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

string S, T; cin >> S >> T;

int cnt = 0;
rep(i, 0, 3) {
    if (S[i] == T[i]) ++cnt;
}

cout << cnt << endl;
}

// 境界，出力文字列 チェック



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

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


vector<string> toRPN(string s){
    stack<string> ope;
    vector<string> ret;
    int len=s.size();
    
    for(int i=0;i<len;i++){
        if( isdigit(s[i]) ){
            string tmp="";
            for(int j=i;j<len;j++){
                if( isdigit(s[j]) )tmp+=s[j];
                else break;
            }
            ret.push_back(tmp);
            i+=tmp.size()-1;
            
        }else{
            if( s[i]=='(' )ope.push("(");
            
            else if( s[i]==')' ){
                if( ope.empty() )return {"invalid"};
                
                while( ope.top()!="(" ){
                    ret.push_back( ope.top() );
                    ope.pop();
                    
                    if( ope.empty() )return {"invalid"};
                }
                if( ope.empty() )return {"invalid"};
                ope.pop();
                
            }else if( s[i]=='*' || s[i]=='/' ){
                while( ope.size() && ( ope.top()=="*" || ope.top()=="/" ) ){
                    ret.push_back( ope.top() );
                    ope.pop();
                }
                ope.push( string(1,s[i]) );
                
            }else if( s[i]=='+' || s[i]=='-' ){
                while( ope.size() && ( ope.top()=="*" || ope.top()=="/" || ope.top()=="+" || ope.top()=="-" ) ){
                    ret.push_back( ope.top() );
                    ope.pop();
                }
                ope.push( string(1,s[i]) );
            }
        }
    }
    while( ope.size() ){
        ret.push_back( ope.top() );
        ope.pop();
    }
    
    return ret;
}




int solveRPN(vector<string> s){
    stack<int> stk;
    
    
    for(int i=0;i<s.size();i++){
        if( (s[i]!="+" && s[i]!="-" && s[i]!="*" && s[i]!="/") )stk.push( stoi(s[i])  );
        else{
            int b=stk.top(); stk.pop();
            int a=stk.top(); stk.pop();
            
            if(s[i]=="+")stk.push(a+b);
            if(s[i]=="-")stk.push(a-b);
            if(s[i]=="*")stk.push(a*b);
            if(s[i]=="/")stk.push(a/b);
        }
    }
    
    
    return stk.top();
}


int main(){
    int n;
    cin>>n;
    rep(i,n){
        string s;
        cin>>s;
        
        s.erase(s.size()-1);
        
        vector<string> poland;
        poland=toRPN(s);
        
//        rep(i,poland.size())cout<<poland[i];cout<<endl;
        
        int ans;
        ans=solveRPN(poland);
        
        cout<<ans<<endl;
    }
    
    return 0;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int mINF = 1e9;
const int MOD = 1e9+7;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,-1,0,1};
    int h,w;cin >> h >> w;
    vector<vector<char>> G(h,vector<char>(w));
    vector<vector<int>> dist(h,vector<int>(w,-1));
    queue<pair<int,int>> que;
    rep(i,h){
        rep(j,w){
            cin >> G[i][j];
            if(G[i][j]=='#'){
                dist[i][j] = 0;
                que.push(make_pair(i,j));
            }
        }
    }

    while(!que.empty()){
        int y,x;
        tie(y,x) = que.front();
        que.pop();
        for(int i=0;i<4;i++){
            int ndx = x + dx[i];
            int ndy = y + dy[i];
            if(ndx<0||ndx>=w||ndy<0||ndy>=h||G[ndy][ndx]=='#'||dist[ndy][ndx]!=-1)continue;
            dist[ndy][ndx] = dist[y][x] + 1;
            que.push(make_pair(ndy,ndx));
        }
    }

    int ans = 0;
    rep(i,h){
        rep(j,w){
            chmax(ans,dist[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13328