akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAX 101
#define WHITE -1
#define GRAY -2
#define BLACK -3

int time;
int d[MAX];
int f[MAX];
int color[MAX];
int n;
int C[MAX][MAX];

void DFS();
void Visit(int);

int main(){
  int i,j,c,I,J;

  for(i=1; i <= n; i++){
    for(j=1; j <= n; j++){
      C[i][j] = 0;
    }
  }

  scanf("%d",&n);

  for(i=1; i <= n; i++){
    scanf("%d",&I);
    scanf("%d",&c);
    for(j=1; j <= c; j++){
      scanf("%d",&J);
      C[I][J] = 1;
    }
  }

  DFS();

  for(i=1; i <= n; i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }

  return 0;
}

void DFS(void){
  int i;
  for(i=1; i <= n; i++){
    color[i] = WHITE;
  }
  time = 0;
  for(i=1; i <= n; i++){
    if(color[i] == WHITE){
      visit(i);
    }
  }
}

void visit(int u){
  int i;
  color[u] = GRAY;
  d[u] = ++time;
  for(i=1; i <= n; i++){
    if(C[u][i] == 1){    
      if(color[i] == WHITE){
	visit(i);
      }
    }
  }
  color[u] = BLACK;
  f[u] = ++time;
}



Measured memory_bytes: 2104
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

N=intput()
node=[list() for _ in range(N+1)]
done=[False]*(N+1)
color=[0]*(N+1)
ans=[0]*(N-1)
S=dict()
for i in range(N-1):
    u,v=mint()
    node[u].append(v)
    node[v].append(u)
    S[(u,v)]=i
    S[(v,u)]=i
q=deque([1])
done[1]=True
while q:
    u=q.popleft()
    c=1
    for v in node[u]:
        if not done[v]:
            if c==color[u]:
                c+=1
            color[v]=c
            ans[S[(u,v)]]=c
            done[v]=True
            q.append(v)
            c+=1
print(max(ans))
lprint(ans)

Measured memory_bytes: 137940
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int[] l = new int[n];
    int l_max = 0;
    int l_sum = 0;
    
    for(int i=0; i<n; i++) {
      l[i] = Integer.parseInt(str[i]);
      l_max = Math.max(l_max,l[i]);
      l_sum += l[i];
    }
    if(l_sum-l_max>l_max)
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}

Measured memory_bytes: 22484
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   vi v(n);
   rep(i,0,n)cin>>v[i];
   int cnt=0;
   for(int i=0;i<n;i++)
   {
       for(int j=(i+1);j<n;j++)
       {
           for(int k=(j+1);k<n;k++)
           {
               int mx=max(v[i],max(v[j],v[k]));
               int sum=(v[i]+v[j]+v[k]);
               sum-=mx;
               if(v[i]==v[j] || v[j]==v[k] || v[i]==v[k])continue;
               if(sum>mx)cnt++;
           }
       }
   }
   cout<<cnt<<endl;
}



Measured memory_bytes: 3660
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1e18 + 10;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using edge = pll;
const int max_v = 100100;

int n;
vector<edge> G[max_v];
ll d[max_v]; 

void dijkstra(int s){ 
    priority_queue<pll, vector<pll>, greater<pll>> que;
    fill(d, d+n, LINF); 
    d[s] = 0;
    que.push(pll(0, s));

    while(!que.empty()){
        pll p = que.top(); que.pop();
        int v = p.second; 
        if(d[v] < p.first) continue; 

        for(edge e: G[v]){
            int to = e.first; ll cost = e.second;
            if(d[to] > d[v] + cost){
                d[to] = d[v] + cost;
                que.push(pll(d[to], to));
            }
        }
    }
}

int main(){
    cin >> n;
    rep(i, n-1){
        ll a, b, c; cin >> a >> b >> c; a--, b--;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }
    int q, k; cin >> q >> k; k--;
    dijkstra(k);
    rep(i, q){
        int x, y; cin >> x >> y; x--, y--;
        cout << d[x] + d[y] << ln;
    }
}


Measured memory_bytes: 14040
//url:
//problem name: 

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

map<ll,ll> mp;

const int MOD = 1000000007;

void prime_factorial(int N) {
    for(int i = 2; i * i <= N; i++) {
        if(N % i == 0) {
            ll ex = 0;
            while(N % i == 0) {
                ex++;
                N /= i;
            }
            if(mp.count(i)) mp[i] += ex;
            else mp[i] = ex;
        }
    }
    if(N != 1) {
        if(mp.count(N)) mp[N]++;
        else mp[N] = 1;
    }
}

int main() {
    int N;
    cin >> N;
    ll ans = 1;
    for(int i = 1; i <= N; i++) {
        prime_factorial(i);
    }
    for(auto x:mp) {
        //cout << x.first << " " << x.second << endl;
         ans *= x.second+1;
         ans %= MOD;
    }
    cout << ans << endl;
}


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

using namespace std;

const int MAX = 55;
int n, a, x[MAX];
long long dp[MAX][MAX][MAX * MAX];
long long cnt = 0;

int main() {
  cin >> n >> a;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < MAX * MAX - x[i]; k++) {
        dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
        dp[i + 1][j][k] += dp[i][j][k];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cnt += dp[n][i][i * a];
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 66560
#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cmath>
#include <complex>
#include <algorithm>
#include <tuple>
#include <algorithm>
#include <limits>
#include <map>
#include <valarray>
#include <list>

using namespace std;

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

const int MN = 55;

int d4[4][2] = {
    {1, 0},
    {0, 1},
    {-1, 0},
    {0, -1}
};

bool g[MN][MN][4];

bool can[MN][MN][4], canb[MN][MN][4];

int main() {
    int n, sx, sy, t;
    cin >> n >> sx >> sy >> t; sx++; sy++;
    for (int i = 0; i < n; i++) {
        int ax, ay, bx, by;
        cin >> ax >> ay >> bx >> by; ax++; ay++; bx++; by++;
        if (ax == bx) {
            if (ay > by) swap(ay, by);
            for (int j = ay; j < by; j++) {
                g[j][ax][0] = g[j+1][ax][2] = true;
            }
        } else {
            if (ax > bx) swap(ax, bx);
            for (int j = ax; j < bx; j++) {
                g[ay][j][1] = g[ay][j+1][3] = true;
            }
        }
    }
    string qu = "NESW";
    fill_n(can[sy][sx], 4, true);
    for (int i = 0; i < t; i++) {
        int di; char ty;
        cin >> di >> ty;
        int qd;
        for (int k = 0; k < 4; k++) {
            if (qu[k] == ty) {
                qd = k;
                break;
            }
        }
        for (int t = 0; t < di; t++) {
            fill_n(canb[0][0], MN*MN*4, false);
            for (int x = 0; x < MN; x++) {
                for (int y = 0; y < MN; y++) {
                    for (int d = 0; d < 4; d++) {
                        if (!g[y][x][d]) continue;
                        if (!can[y][x][d]) continue;
                        int yy = y+d4[d][0], xx = x+d4[d][1];
                        for (int nd = 0; nd < 4; nd++) {
                            if (d == (nd+2)%4) continue;
                            if (t == di-1 && d != qd && nd != qd) continue;
                            if (!g[yy][xx][nd]) continue;
                            canb[yy][xx][nd] = true;
                        }
                    }
                }
            }
            copy_n(canb[0][0], MN*MN*4, can[0][0]);
        }
    }

    for (int x = 0; x < MN; x++) {
        for (int y = 0; y < MN; y++) {
            for (int d = 0; d < 4; d++) {
                if (can[y][x][d]) {
                    printf("%d %d\n", x-1, y-1);
                    break;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long int ll;
const ll MOD (1e9+7);
const ll INF (2e9);
const int MAX_N (200001);

int main(void) {
    int N,W;
    cin>>N>>W;
    int w[100];
    int v[100];
    cin>>w[0]>>v[0];
    for(int i=1;i<N;i++){
        cin>>w[i]>>v[i];
        w[i]-=(w[0]-1);
    }
    ll wmemo=w[0];
    w[0]=1;
    int **dp = new int*[101];
    for (int i = 0; i < 101; i++) {
         dp[i] = new int[404];
    }//dp[j][k]=:個数、重さ　最大価値

    for(int j=0;j<=N;j++){
        for(int k=0;k<=4*N;k++){
            dp[j][k]=-INF;
        }
    }
    
    dp[0][0]=0;

    for(int i=0;i<N;i++){//賞品iについて
        for(int j=N-1;j>=0;j--){
           for(int k=4*N-1;k>=0;k--){
                dp[j+1][k+1]=max((ll)dp[j+1][k+1],(k+1-w[i]>=0 ? dp[j][k+1-w[i]] : -INF )+v[i]);
           }
        }
    }
    // cout<<endl<<endl;
    int ans=0;
    for(int j=0;j<=N;j++){
        for(int k=0;k<=4*N;k++){
            // cout<<j<<","<<k<<","<<dp[j][k]<<endl;
            if(j*(wmemo-1)+k<=W){
                ans=max(ans,dp[j][k]);
                // cout<<ans<<endl;
        }
            }
    }
    // cout<<wmemo<<"a";
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less

using namespace std;
#define md 1000000007
#define itn int
#define pb push_back
#define mp make_pair
#define ull unsigned long long int
#define ll long long int
#define ppi pair<int, int>
#define ppl pair<ll, ll>
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ff first
#define lb lower_bound
#define ub upper_bound
#define ss second
#define inf 1e9
#define enld '\n'
#define cuot cout
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \
  cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \
       << z << endl
#define trace4(a, b, c, d)                                                     \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e)                                                  \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f)                                               \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
       << #f << ": " << f << endl
#define trace(v)                                                               \
  for (auto it = v.begin(); it != v.end(); it++)                               \
    cerr << *it << " ";                                                        \
  cerr << endl;
#define linf 1e18
#define reset(x) memset(x, 0, sizeof(x))
#define rep(i, a, b) for (int i = a; i < b; i++)

using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    oset;

void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

vector<pair<int,int> > adj[100005];

int col[100005];

void dfs(int i,int p,int c){
    col[i]=c;
    for(auto x:adj[i]){
        int v=x.ff;
        if(v==p)continue;
        if(x.ss%2)
            dfs(v,i,1-c);
        else
            dfs(v,i,c);
    }
}

void solve() {
    int n;cin>>n;
    rep(i,1,n){
        int u,v,w;cin>>u>>v>>w;
        u--;v--;
        adj[u].pb(mp(v,w));
        adj[v].pb(mp(u,w));
    }
    dfs(0,0,0);
    rep(i,0,n)
    cout<<col[i]<<" ";
    cout<<endl;
}
int main() {
  fastio();
  int t;
  t = 1;
  //   cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int d[100000];

int main()
{
	int N;

	cin >> N;
	rep(i, N) cin >> d[i];

	sort(d, d + N);

	cout << d[N / 2] - d[N / 2 - 1] << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
int inf = 1000000000;
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}
int Max(int x, int y) {
	if (x > y)return x;
	else return y;
}
int Min(int x, int y) {
	if (x < y)return x;
	else return y;
}
int kai(int x) {
	int cnt = 1;
	if (x == 0)return 1;
	cnt = kai(x - 1);
	return x * cnt;
}
int prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
void prime_factor(int n) {
	int cnt = 1;
	map<int, int>res;
	int m = n;
	for (int i = 2; i <= n; i++) {
		if (prime(i)) {
			while (m%i == 0) {
				++res[i];
				m /= i;
			}
		}
	}
	cout << n << ":" << endl;
	for (int i = 2; i <= n; i++) {
		if (res[i]) {
			cout << i << " " << res[i] << endl;
		}
	}
	cout << endl;
}
/*Library End!*/


signed main() {
	string s;
	cin >> s;
	if (s.size() == 2) {
		cout << s[0] << s[1] << endl;
	}
	else {
		cout << s[2] << s[1] << s[0] << endl;
	}
	endre;
}


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

const long long MOD = 1000000007;
const int MAX_C = 2001;
long long Com[MAX_C][MAX_C];

using namespace std;

void calc_com() {
    memset(Com, 0, sizeof(Com));
    Com[0][0] = 1;
    for (int i = 1; i < MAX_C; i++) {
        Com[i][0] = 1;
        for (int j = 1; j <= i; j++) {
            Com[i][j] = (Com[i-1][j-1] + Com[i-1][j]) % MOD;
        }
    }
}


int main() {
    int N, K; cin >> N >> K;

    calc_com();
    for (int i = 1; i <= K; i++) {
        int ans = (Com[N-K+1][i] * Com[K-1][i-1]) % MOD;
        cout << ans << "\n";
    }

}




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

int gcd(int a,int b) {
if (a%b == 0) return b;
else return gcd (b,a%b);

}

int main() {
int N,X;
cin >> N >> X;
vector<int> vec(N);
cin >> vec.at(0);
int mini = abs(X - vec.at(0));
for (int i = 1;i < N;i++) {
    cin >> vec.at(i);
    mini = min(mini,gcd(mini,abs(X - vec.at(i))));
}

cout << mini << endl;


return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    char w[105];
    cin>>w;
    int N;
    N=strlen(w);
    int check[26];
    for(int i=0;i<26;i++){
        check[i]=0;
    }
    bool ans=true;
    int c;
    for(int i=0;i<N;i++){
        if('a'<=w[i]&&w[i]<='z') {
            c=w[i]-'a';
            check[c]++;
        }
        else ans=false;
    }
    int count=0;
    for(int i=0;i<26;i++){
        if(check[i]%2==0) count++;
    }
    if(count!=26) ans=false;
    if(ans==true) cout<<"Yes";
    else cout<<"No";
    return 0;
}



Measured memory_bytes: 256
MOD=10**9+7
N,M=map(int,input().split())
A=[int(input()) for _ in range(M)]
L=[-1 for _ in range(N)]
p=0
if A == []:
  A=[0]
if 1 == A[p]:
  L[0] = 0
  if p < M-1:
    p +=1
else:
  L[0] = 1
if N>1:
  if 2 == A[p]:
    L[1] = 0
    if p < M-1:
      p+=1
  else:
    L[1]=L[0]+1
for i in range(2,N):
  if i+1 == A[p]:
    L[i] = 0
    if p < M-1:
      p+=1
  else:
    L[i]=L[i-1]+L[i-2]
print(L[-1]%MOD)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
#define PINT pair<int,int>
#define f1 first
#define s2 second
const int INF = 1e9 + 7;

using namespace std;

int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) ) return 0;
    else if(m%n==0) return n;
    else if(n%m==0) return m;

	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}

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

    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i,n) cin >> a[i];

    sort(a.begin(),a.end());
    if(k > a[n-1]){
        cout << "IMPOSSIBLE\n";
        return 0;
    }

    if(*lower_bound(a.begin(),a.end(),k) == k){
        cout << "POSSIBLE\n";
        return 0;
    }
    int adiv = a[0];
    REP(i,n) adiv = gcd(adiv,a[i]);
    if(k%adiv) cout << "IMPOSSIBLE\n";
    else cout << "POSSIBLE\n";
    return 0;
}


Measured memory_bytes: 640
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import heapq
import copy

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    arr.sort(reverse=True)
    c=[]
    heapq.heapify(c)
    ans=0
    for i in range(n):
        if i==0:
            heapq.heappush(c,(-1)*arr[i])
        else:
            ans+=heapq.heappop(c)*(-1)
            heapq.heappush(c,(-1)*arr[i])
            heapq.heappush(c,(-1)*arr[i])
    print(ans)
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 39280
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <queue>
#include <iomanip>
#include <algorithm>
using namespace std;

const int Maxn = 4005;
const int Maxm = 2005;

int n, k;
int W[Maxn][Maxn], B[Maxn][Maxn];
int nW[Maxm][Maxm], nB[Maxm][Maxm];
int res;

int main()
{
	scanf("%d %d", &n, &k);
	while (n--) {
		int x, y; char c; scanf("%d %d %c", &x, &y, &c);
		x %= (2 * k); y %= (2 * k);
		x += 2 * k; y += 2 * k;
		if (c == 'W') {
			W[x - (k - 1)][y - (k - 1)]++;
			W[x + 1][y - (k - 1)]--;
			W[x - (k - 1)][y + 1]--;
			W[x + 1][y + 1]++;
		}
		else {
			B[x - (k - 1)][y - (k - 1)]++;
			B[x + 1][y - (k - 1)]--;
			B[x - (k - 1)][y + 1]--;
			B[x + 1][y + 1]++;
		}
	}
	for (int i = 0; i < Maxn; i++)
		for (int j = 0; j < Maxn; j++) {
			if (i > 0) {
				W[i][j] += W[i - 1][j];
				B[i][j] += B[i - 1][j];
			}
			if (j > 0) {
				W[i][j] += W[i][j - 1];
				B[i][j] += B[i][j - 1];
			}
			if (i > 0 && j > 0) {
				W[i][j] -= W[i - 1][j - 1];
				B[i][j] -= B[i - 1][j - 1];
			}
			nW[i % (2 * k)][j % (2 * k)] += W[i][j];
			nB[i % (2 * k)][j % (2 * k)] += B[i][j];
		}
	for (int i = 0; i < 2 * k; i++)
		for (int j = 0; j < 2 * k; j++)
			res = max(res, nB[i][j] + nB[(i + k) % (2 * k)][(j + k) % (2 * k)] +
						   nW[(i + k) % (2 * k)][j] + nW[i][(j + k) % (2 * k)]);
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 156928
# def calc(ran, count, cans, X):
#   for n in ran:
#     if n == 0:
#       while cans[n+1] + cans[n] > X:
#         cans[n] -= 1
#         count += 1  
#       continue
#     if n + 1 == N:
#       while cans[n-1] + cans[n] > X:
#         cans[n] -= 1
#         count += 1  
#       continue
#     while cans[n-1] + cans[n] > X or cans[n+1] + cans[n] > X:
#       cans[n] -= 1
#       count += 1
#   return count, cans

# N, X = map(int, input().split())
# cans = list(map(int, input().split()))

# count = 0

# # odd_range = range(1, N, 2)
# # even_range = range(0, N, 2)
# # count, cans = calc(odd_range, count, cans, X)
# # count, cans = calc(even_range, count, cans, X)

# # even_count = count
# # print(min(odd_count, even_count))

# for i in range(0, N-1):
#   if cans[i] + cans[i+1] > X:
#     cans[i+1] -= X - cans[i]
#     count += 1
# print(count)
n, x = map(int, input().split())
l = list(map(int, input().split()))
 
y = 0
if l[0] > x:
    w = l[0] - x
    y += w
    l[0] -= w
 
for i in range(n-1):
    if l[i] + l[i+1] > x:
        z = l[i+1] + l[i] - x
        y += z
        l[i+1] -= z
 
print(y)

Measured memory_bytes: 14052
#include <iostream>
#include<cstring>
#include<cmath>
using namespace std;

int main() {
	// your code goes here
	int a,b;
	cin>>a>>b;
	int k=b,p;
	while(k)
	{
	  p++;
	  k=k/10;
	}
	int d=a*pow(10,p)+b;
    k=sqrt(d);
	k=round(k);
	if(k*k==d)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

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

int a[128],n;

bool check(int x,int y){
  for(int i=0;i<n;i++){
    if(x<=a[i] && a[i]<=y){
      return true;
    }
  }
  return false;
}

main(){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n);

  int ans1=0;

  if(check(1,399)){
    ans1++;
  }
  if(check(400,799)){
    ans1++;
  }
  if(check(800,1199)){
    ans1++;
  }
  if(check(1200,1599)){
    ans1++;
  }
  if(check(1600,1999)){
    ans1++;
  }
  if(check(2000,2399)){
    ans1++;
  }
  if(check(2400,2799)){
    ans1++;
  }
  if(check(2800,3199)){
    ans1++;
  }



  if(a[n-1]<3200){
    cout << ans1 << " " << ans1 <<endl;
  }else{
    for(int i=0;i<n;i++){
      if(a[i]>=3200){
        if(ans1==0){
          cout << "1" << " " << ans1+n-i <<endl;
        }else{
          cout << ans1 << " " << ans1+n-i <<endl;
        }
        break;
      }
    }
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,x,y,f[100005][30],ans;
vector <int> a[100005];
void dfs(int x,int fa){
	int z=-1,y;
	for (int i=0;i<a[x].size();++i)
	if (a[x][i]!=fa){
		dfs(y=a[x][i],x);
		for (int j=0;j<30;++j){
			if (f[y][j]&f[x][j]) z=max(z,j);
			f[x][j]|=f[y][j];
		}
	}
	for (++z;z<30;++z)
	if (!f[x][z]) break;
	f[x][z]=1; ans=max(ans,z);
	for (--z;~z;--z) f[x][z]=0;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<n;++i){
		scanf("%d%d",&x,&y);
		a[x].push_back(y);
		a[y].push_back(x);
	}
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 24320
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <time.h>
int main(){
    long long i,j,n,ans=0,a[200020]={},sum[200020]={};
    scanf("%lld",&n);
    for(i=0; i<n; i++){
        scanf("%lld",&a[i]);
        sum[0]+=a[i];
    }
    for(i=1; i<n; i++){
        sum[i]=sum[i-1]-a[i-1];
    }
    for(i=0; i<n; i++){
        sum[i]=sum[i]%1000000007;
    }
    for(i=0; i<n-1; i++){
        ans+=a[i]*sum[i+1];
        ans=ans%1000000007;
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 4856
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<cstdio>
#define MAXA 100000
#define MAX 2000000000?
#define rer(i,j,k) for((i)=(j);(i)<(k);++(i))
#define ret(i,j,k) for((i)=(j);(i)>(k);--(i))
using namespace std;
bool cmp(int a, int b){
	return a > b;
}
int main(){
	int num[55] = {0}, i, n, k, j;
	cin >> n >> k;
	rer(i,0,n){
		cin >> num[i];
	}
	sort(num,num+n, cmp);
	int sum = 0;
	rer(i,0,k){
		sum+=num[i];
	}
	cout << sum;
	return 0;
} 

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

int k,dp[50][100010]={}; bool used[50][100050]={};
bool f(int sum,int r){
    if(sum==0&&r==0)return 1;
    if(used[sum][r])return dp[sum][r];
    used[sum][r]=1;
    rep(i,0,10)if(sum-i>=0&&f(sum-i,(r*10+i)%k)){
        dp[sum][r]=1; break;
    }return dp[sum][r];
}

int main(){
    scanf("%d",&k);
    int m=0,kk=k;
    while(kk){
        m+=kk%10; kk/=10;
    }
    rep(i,1,m)if(f(i,0)){
        printf("%d\n",i); return 0;
    }
    printf("%d\n",m);
    return 0;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

struct event{
    ll t, type, val;
    bool operator<(const event& a){
        return t < a.t;
    }
};

int main(int argc, const char * argv[]) {
    // input
    cout << fixed << setprecision(10);
    ll N, Q; cin >> Q >> N;
    vector<event> eves;
    vector<ll> D(N);
    rep(i, Q){
        ll s, t, q;
        cin >> s >> t >> q;
        eves.push_back({s-q, 1, q}); // add
        eves.push_back({t-q, -1, q}); // erase
    }
    rep(i, N){
        cin >> D[i];
    }

    sort(ALL(eves));

    int k = 0;
    multiset<ll> st;
    rep(i, N){
        // D[i]以下のイベントを全て処理する(stにins, erase)
        while(k < eves.size() && eves[k].t <= D[i]){
            if(eves[k].type == 1){
                st.insert(eves[k].val);
            }
            else {
                st.erase(st.find(eves[k].val));
            }
            k++;
        }

        // stの最小値を調べて出力
        if(st.empty()){
            cout << -1 << endl;
        }
        else{
            cout << *st.begin() << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 23016
import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int m = sc.nextInt();
    	UnionFindTree uft = new UnionFindTree(n);
    	for (int i = 0; i < m; i++) {
    	    uft.unite(sc.nextInt() - 1, sc.nextInt() - 1);
    	}
    	System.out.println(uft.getMax());
    }
    
    static class UnionFindTree {
        int[] parents;
        int[] counts;
        
        public UnionFindTree(int size) {
            parents = new int[size];
            counts = new int[size];
            for (int i = 0; i < size; i++) {
                parents[i] = i;
                counts[i] = 1;
            }
        }
        
        public int find(int x) {
            if (parents[x] == x) {
                return x;
            } else {
                return parents[x] = find(parents[x]);
            }
        }
        
        public boolean smae(int x, int y) {
            return find(x) == find(y);
        }
        
        public void unite(int x, int y) {
            int xx = find(x);
            int yy = find(y);
            if (xx == yy) {
                return;
            }
            parents[xx] = yy;
            counts[yy] += counts[xx];
        }
        
        public int getMax() {
            int max = 0;
            for (int x : counts) {
                max = Math.max(max, x);
            }
            return max;
        }
    }
}


Measured memory_bytes: 61908
import sys
from collections import deque

N, M = map(int, sys.stdin.readline().split())

edges = [[] for _ in range(N)]
for _ in range(M):
    l, r, d = map(int, sys.stdin.readline().split())
    edges[l-1].append((r-1, d))
    edges[r-1].append((l-1, -d))

visited = {}
# その人へのパスが複数あり、距離が異なる場合は矛盾
for i in range(N):
    if i in visited:
        continue

    # 連結グラフごとに相対的な距離を決定
    # dist = [0 for _ in range(N)]
    q = deque([(i, 0)])
    while q:
        l, c = q.popleft()
        if l in visited:
            if visited[l] != c:
                print("No")
                sys.exit()
            continue
        
        visited[l] = c
        # dist[l] = c

        for r, nd in edges[l]:
            q.append((r, c+nd))
    # print(dist)

print("Yes")

Measured memory_bytes: 121200
#include <bits/stdc++.h>
#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (int) (k); ++i)
#define Rep(i, j, k) for(R int i = (j); i >= (int) (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 100011;
const ll INF = 5e16;

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread(buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit(ch); dd) f ^= (ch == '-');
		for (; isdigit(ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) x = -x, putchar('-');
		if (x > 9) write(x / 10); putchar(x % 10 | 48);
	}

	inline void wrn ( ll x ) { write(x), putchar(' '); }

	inline void wln ( ll x ) { write(x), putchar('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x), wln(y); }

}

using IO::wln;
using IO::read;

namespace Cesare {
	
	ll A, B, Ans;
	
	tr1::unordered_map <ll, ll> alb;
	
	int main() {
		A = read(), B = read();
		for (R ll i = 2; i * i <= A; ++i)
			if (A % i == 0) {
			alb[i] = 1;
			while (A % i == 0) A /= i;
		}
		if (A > 1) alb[A] = 1;
		for (R ll i = 2; i * i <= B; ++i) 
			if (B % i == 0) {
			Ans += alb[i];
			while (B % i == 0) B /= i;
		} 
		if (B > 1) Ans += alb[B];
		return wln(Ans + 1), 0;
	}
	
}

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	return Cesare :: main();
}

/*

*/






Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val monsterHP = sc.nextInt()
    val magicKinds = sc.nextInt()

    val magics = Array.fill(magicKinds)((sc.nextInt(), sc.nextInt()))

    val dp = Array.fill(monsterHP + 1)(Int.MaxValue)
    dp(0) = 0

    for {
      (attackPoint, magicPoint) <- magics
      i <- (0 to monsterHP)
    } {
      if (dp(i) != Int.MaxValue) {
        val targetHP = Math.min(monsterHP, i + attackPoint)
        dp(targetHP) = Math.min(dp(targetHP), dp(i) + magicPoint)
      }
    }

    val ans = dp(monsterHP)
    println(ans)
  }

}


Measured memory_bytes: 29568
#include <algorithm>
#include <iostream>
using namespace std;
typedef pair<int, int> P;

int main()
{
    int r, c, n;
    cin >> r >> c >> n;
    int k = 0;
    P p[100002];
    for(int i = 0; i < n; i++){
        int x[2], y[2];
        cin >> x[0] >> y[0] >> x[1] >> y[1];
        int t[2] = {-1, -1};
        for(int j = 0; j < 2; j++){
            if(y[j] == 0 || x[j] == r) t[j] = x[j] + y[j];
            else if(y[j] == c || x[j] == 0) t[j] = r * 2 + c * 2 - (x[j] + y[j]);
        }
        sort(t, t + 2);
        if(t[0] == -1) continue;
        p[k] = P(t[0], t[1]);
        k++;
    }
    sort(p, p + k);
    int par[100002];
    par[0] = -1;
    for(int i = 1; i < k; i++){
        par[i] = i - 1;
        while(par[i] != -1){
            if(p[i].first < p[par[i]].second){
                if(p[i].second > p[par[i]].second){
                    cout << "NO" << endl;
                    return 0;
                }
                break;
            }
            par[i] = par[par[i]];
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1408
N = int(input())

MOD = 10 ** 9 + 7
memo = [{} for i in range(N + 1)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i - 1], t[i] = t[i], t[i - 1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True

def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    
    if cur == N:
        return 1
    
    ret = 0
    for c in 'ACGT':
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret
    return ret

print(dfs(0, 'TTT'))


Measured memory_bytes: 48220
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		Set<Long> set = new HashSet<Long>();
		
		for(int i = 0; i < n; i++) {
			long a = Long.parseLong(sc.next());
			
			if(set.contains(a)) {
				set.remove(a);
			}else{
				set.add(a);
			}
		}
		
		System.out.println(set.size());
		
	}
}


Measured memory_bytes: 49552
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
char = "".join(chr(97+i) for i in range(n))


def dfs(s, idx):
    if len(s) == n:
        print(s)
    else:
        for i in range(idx):
            if i+1 != idx:
                dfs(s+char[i], idx)
            else:
                dfs(s+char[i], idx+1)


dfs("a", 2)

Measured memory_bytes: 4412
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> S(N, 0);
    for (auto & s : S) cin >> s;
    int total = accumulate(S.begin(), S.end(), 0);
    if (total % 10 != 0){
        cout << total << endl;
        return 0;
    }
    vector<bool> dp(total + 1, false);
    dp[0] = true;
    for (auto & s : S){
        for (int i = total; i >= s; --i){
            if (dp[i - s]) dp[i] = true;
        }
    }
    for (int i = total; i >= 0; --i){
        if (dp[i] and (i % 10 != 0)){
            cout << i << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List
import qualified Data.IntMap as IM
import Debug.Trace

type Map = IM.IntMap (IM.IntMap Int)

main :: IO ()
main = do
  n <- readLn :: IO Int
  fs <- replicateM n $ map (== 1) <$> getInts
  ps <- replicateM n $ zip [0..] <$> getInts
  let as = IM.fromList $ zip [1..] $ map IM.fromList ps
  print $ solve fs as

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: [[Bool]] -> Map -> Int
solve fs ps = maximum $ go xs
  where
    xs = init $ replicateM 10 [True, False]
    go [] = []
    go (y:ys) =
      let ns = f y fs in
--        trace (show ns) $
        foldr (\(i, j) b ->
                  (ps IM.! i) IM.! j + b) 0 ns : go ys
    f ns ms = zip [1..] $
              map (length
                   . filter id . zipWith (&&) ns) ms


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

int main()
{
  int n, m;
  while (cin>>n>>m) {
    if (!n && !m) break;
    vector<int> field(n);
    for (int i=0; i < n; ++i) {
      cin >> field[i];
    }
    vector<int> sai(m);
    for (int i=0; i < m; ++i) {
      cin >> sai[i];
    }
    int ans = 0;
    int p = 0;
    while (true) {
      p += sai[ans++];
      if (p >= n-1) break;
      if (p < 0) p = 0;
      p += field[p];
      if (p >= n-1) break;
      if (p < 0) p = 0;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
N = int(input())
A = []
for i in range(2):
    A.append(list(map(int, input().split())))
tot = []
for i in range (N):
    temp = 0
    for j in range (i+1):
        temp += A[0][j]
    for j in range (i, N):
        temp += A[1][j]
    tot.append(temp)
print(max(tot))

Measured memory_bytes: 3060
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

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

    set<ll> Z;
    ll ans=0;
    READV(N);
    FORI(i,0,N)
    {
        READV(x);
        Z.insert(x);
        if (*Z.begin()==x)
        {
            ans++;
        }
    }
    cout<<ans<<endl;

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


   
    return 0;
}

Measured memory_bytes: 9600
from collections import Counter
s = Counter(input())
ss = list(s.values())
ss.sort()
if len(ss) != 3:
  if ss[-1] <= 1:
    print('YES')
  else:
    print('NO')
elif ss[2] - ss[0] <= 1:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string.h>
#include <algorithm>

using namespace std;
int w, h;
const int MAX_N = 1005;  //テープのっ数
int n;
int X1[MAX_N];
int X2[MAX_N];
int Y1[MAX_N];
int Y2[MAX_N];

bool fld[MAX_N*6][MAX_N*6];

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int compress(int *x1, int *x2, int W) {
    vector<int> xs;
    for (int i = 0; i < n; i++) {
        for (int d = -1; d <= 1; d++) {
            int nx1 = x1[i] + d;
            int nx2 = x2[i] + d;
            if (nx1 >= 0 && nx1 < W) xs.push_back(nx1);
            if (nx2 >= 0 && nx2 < W) xs.push_back(nx2);
        }
    }
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()),xs.end());
    for (int i = 0; i < n; i++) {
        x1[i] = (int)(find(xs.begin(), xs.end(), x1[i]) - xs.begin());
        x2[i] = (int)(find(xs.begin(), xs.end(), x2[i]) - xs.begin());
    }
    
    return (int)xs.size();
}
int main(int argc, const char * argv[])
{
    while (true) {
        scanf("%d %d", &w, &h);
        if (h == 0 && w == 0) break;
        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
            scanf("%d %d %d %d", &X1[i], &Y1[i], &X2[i], &Y2[i]);
            X2[i]--;  //X2はw-1以下
            Y2[i]--;
        }
        
        w = compress(X1, X2, w);
        h = compress(Y1, Y2, h);
        
        memset(fld, 0, sizeof(fld));
        for (int i = 0; i < n; i++) {
            for (int x = X1[i]; x <= X2[i]; x++) {
                for (int y = Y1[i]; y <= Y2[i]; y++) {
                    fld[y][x] = true;
                }
            }
        }
        /*
         for (int y = h-1; y >= 0; y--) {
         for (int x = 0; x < w; x++) {
         printf("%c",(fld[y][x])? '#' : ' ');
         }
         printf("\n");
         }
         */
        int ans = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (!fld[i][j]) {
                    ans++;
                    queue<pair<int, int> > que;
                    que.push(make_pair(j, i));  //(x, y)
                    while (!que.empty()) {
                        int x = que.front().first;
                        int y = que.front().second;
                        que.pop();
                        
                        for (int i = 0; i < 4; i++) {
                            int nx = x + dx[i];
                            int ny = y + dy[i];
                            if (nx >= 0 && nx < w && ny >= 0 && ny < h) {
                                if (!fld[ny][nx]) {
                                    que.push(make_pair(nx, ny));
                                    fld[ny][nx] = true;
                                }
                            }
                        }
                    }
                }
            }
        }
        printf("%d\n", ans);
    }
    
    return 0;
}

Measured memory_bytes: 36756
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

// vector<vector<int>> data(3, vector<int>(4));

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

  long long a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  long long kyori = max(a, b) - min(a, b);

  if (kyori == 0) {
    cout << "YES";
    return 0;
  }
  long long sa = v - w;
  if (v <= w) {
    cout << "NO";
    return 0;
  } else if (sa * t >= kyori) {
    cout << "YES";
    return 0;
  } else {
    cout << "NO";
  }

  return 0;
}

Measured memory_bytes: 3652