akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

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

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

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

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


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    map<int,int> ma;
    rep(i,n){
        auto itr = ma.upper_bound(-a[i]);
        if(itr != ma.end()){
            int num = itr->first;
            //cout << (itr->first) << " " << (itr->second) << endl;
            ma[num]--;
            if(ma[num] == 0){
                ma.erase(num);
            }
        }
        ma[-a[i]]++;
    }
    int ans = 0;
    for(auto x: ma){
        ans += x.second;
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int> > vp;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define out(n) cout << (n) << endl;
#define vut(v) rep(i, v.size()) out(v[i]);

int main() {
  cin.tie(0);

  int n, m, d[100001] = {0};
  cin >> n >> m;

  int a, b;
  rep(i, 0, m) {
    cin >> a >> b;
    d[a]++, d[b]++;
  }

  rep(i, 0, n + 1) {
    if(d[i] & 1) {
      out("NO")
      return 0;
    }
  }

  out("YES")
}


Measured memory_bytes: 640
program main
  implicit none
  integer :: h,w,i,j
  integer,allocatable :: x(:,:) 
  character(50) :: s,t
  character :: a

  read(*,*) h,w
  allocate(x(0:h+1,0:w+1))
  x(:,:)=0
  
  do i=1,h
     read(*,*) s

     do j=1,w
        if(s(j:j)=='#')then
           x(i,j)=-10
           x(i,j+1)=x(i,j+1)+1
           x(i,j-1)=x(i,j-1)+1
           x(i-1,j)=x(i-1,j)+1
           x(i-1,j+1)=x(i-1,j+1)+1
           x(i-1,j-1)=x(i-1,j-1)+1
           x(i+1,j)=x(i+1,j)+1
           x(i+1,j+1)=x(i+1,j+1)+1
           x(i+1,j-1)=x(i+1,j-1)+1
        endif
     enddo
  enddo
  
  do i=1,h
     t='0'
     do j=1,w
        if(x(i,j)<0)then
           t(j:j)='#'
        else
           write(a,'(i1)') x(i,j)
           t(j:j)=a
        endif
     enddo
     write(*,*) t
  enddo

end program main
        
        

     

  



Measured memory_bytes: 2952
#include <iostream>
#include <string>


using namespace std;


int S (int n) {
   int ret = 0;
   while(n > 0) {
      ret += n%10;
      n /= 10;
   }

   return ret;
}
      
   
int main () {
   int n; cin >> n;

   int s = S(n);

   if(n%s == 0) {
      cout << "Yes" << endl;
   } else {
      cout << "No" << endl;
   }
}


Measured memory_bytes: 256
def main():
    n,m=map(int,input().split(' '))
    n_list=[[int(i) for i in list(input().split(' '))] for i in range(n)]
    m_list=[[int(i) for i in list(input().split(' '))] for i in range(m)]
    inf = 4*10**8+1
    for i in n_list:
        tmp = inf
        ans = 1
        for num,j in enumerate(m_list):
            m_dis=abs(i[0]-j[0]) +abs(i[1]-j[1])
            if m_dis < tmp:
                tmp = m_dis
                ans = num+1
        print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    b = S()
    b = b[0]
    if b == "A":
        print("T")
    elif b == "T":
        print("A")
    elif b == "C":
        print("G")
    elif b == "G":
        print("C")
    return

#B
def B():
    s = S()
    print(s.count("A")+s.count("G")+s.count("C")+s.count("T"))
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 39152
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	string str;
	cin>>str;
	int n=(int)str.size();
	ll dp[100005][13];
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	bool flag = false;
	int fix;
	for(int idx=0;idx<=n;idx++)
	{
		if(str[idx]=='?')
			flag = true;
		else
		{
			flag = false;
			fix = str[idx]-'0';
		}
		for(int digit=0;digit<=9;digit++)
		{
			if(!flag && digit!=fix)
				continue;
			for(int rem=0;rem<=12;rem++)
			{
				dp[idx+1][(rem*10+digit)%13]+=dp[idx][rem];
			}
		}
        for(int rem=0;rem<=12;rem++)
            dp[idx+1][rem]%=1000000007;
	}
	cout<<dp[n][5];
	return 0;
}

Measured memory_bytes: 10704
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

using LL = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int a[33], k, b, c[33], n, m;
int main() {
	cin >> n >> m;
	REP(i, m) a[i] = 1;
	REP(i, n) {
		REP(i, m) c[i] = 0;
		cin >> k;
		REP(j, k) {
			cin >> b;
			c[b - 1] = 1;
		}
		REP(i, m) a[i] = a[i] & c[i];
	}
	int ans = 0;
	REP(i, m) ans += a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
#define rep(i,l,r) for(ll i=l;i<=r;i++)

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll n;cin>>n;
    ll ans=inf;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ans=min(ans,i+(n/i)-2);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
from decimal import *
n, k = map(int, input().split())
p = list(map(int, input().split()))
ho_list = [0] * n

for j in range(0, n):
    ho_list[j] = (p[j] + 1) / 2

sum_list = [0] * (n + 1)
sum_list[0] = ho_list[0]
for i in range(1, n):
    sum_list[i] = sum_list[i - 1] + ho_list[i]
ans = 0

for i in range(k - 1, n):
    ans = max(ans, abs(sum_list[i] - sum_list[i - k]))
print("{:.12f}".format(ans))


Measured memory_bytes: 99332
n = int(input())
n_apperances = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for i in range(n):
    s = input()
    n_apperances[s] += 1

for key in n_apperances:
    print('{} x {}'.format(key, n_apperances[key]))


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

int main() {
  int n;
  int a;
  int b;
  int c;
  cin >> n;
  a = n % 10;
  n = n / 10;
  b = n % 10;
  n = n / 10;
  c = n % 10;
  cout << a + b + c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF=2E5;
typedef pair<int,int> Pair;

int main(){
    long long X,Y;
    cin >> X >> Y;
    int cnt=1;
    while(true){
        if(X*2<=Y){
            X*=2;
            cnt++;
        }else{
            break;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	while(true) {
	    int l = s.nextInt();
	    if(l==0) break;
	    int a = 0;
	    boolean f = true;
	    for(int i=1 ; i<13 ; i++) {
		int m = s.nextInt();
		int n = s.nextInt();
		a += m;
		a -= n;
		if(a>=l && f) {
		    System.out.println(i);
		    f = false;
		}
	    }
	    if(f) System.out.println("NA");
	}
    }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

#include <boost/multiprecision/cpp_int.hpp>
using Z = boost::multiprecision::cpp_int;

int main() {
	IN(int, n);
	vector<Z> a(n);
	cin >> a;
	sort(ALL(a));
	if(a[0] == 0) { OUT(0); exit(0); }
	Z p = 1;
	RF(e, a) {
		p *= e;
		if(p > 1'000'000'000'000'000'000) { OUT(-1); exit(0); }
	}
	OUT(p);
}


Measured memory_bytes: 6792
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stdlib.h>
#include <map>

using namespace std;

int main() {
    long long n;
    cin >> n;
    long long a,b;
    int min = 11,digita,digitb;
    for(int i = 1; i <= 100000; i++) {
        a = i;
        if(n % a == 0) {
            b = n/a;
            digita = 0;
            digitb = 0;
            while(a > 0) {
                a = a/10;
                digita++;
            }
            while(b > 0) {
                b = b/10;
                digitb++;
            }
        }
        if(min > max(digita,digitb)) {
            min = max(digita,digitb);
        }
    }
    cout << min;
    return 0;
}



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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

struct UnionFind {
    int n;
    vector<int> dat;
    UnionFind(int size): n(size), dat(size, -1) { }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (dat[y] < dat[x]) swap(x, y);
            dat[x] += dat[y];
            dat[y] = x;
        }
        return x != y;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    int root(int x){
        return dat[x] < 0 ? x : dat[x] = root(dat[x]);
    }
    int size(int x){
        return -dat[root(x)];
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n,m; cin >> n >> m;
    auto uf = UnionFind(n);
    rep(i,m){
        int x,y,z; cin >> x >> y >> z;
        uf.unite(x-1,y-1);
    }
    int ans = 0;
    rep(i,n){
        if(uf.root(i) == i) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main() {
	string a;
	while (cin >> a&&a != "#") {
		char h[9][9];
		int sum = 0;
		int b[2] = { 0,0 };
		for (int i = 0; i < a.length(); i++) {
			if (a[i] =='/') {
				b[0]++;
				b[1] = 0;
			}
			else {
				if (a[i] >= '0'&&a[i] <= '9') {
					int e = a[i] - '0';
					for (int j = b[1]; j < b[1] + e; j++) {
						h[b[0]][j] = '.';
					}
					b[1] += e;
				}
				else {
					h[b[0]][b[1]] = 'b';
					b[1]++;
				}
			}
		}
		int x, y, x2, y2;
		cin >> x >> y >> x2 >> y2;
		x--;
		y--;
		x2--;
		y2--;
		h[x][y] = '.';
		h[x2][y2] = 'b';
		for (int i = 0; i <= b[0]; i++) {
			int sum = 0;
			for (int j = 0; j < b[1]; j++) {
				if (h[i][j] == '.') sum++;
				else {
					if (sum != 0) {
						cout << sum;
						sum = 0;
					}
					cout << 'b';
				}
			}
			if (sum != 0) cout << sum;
			if(i!=b[0])cout << '/';
		}
		cout << endl;
	}
}

Measured memory_bytes: 3120
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <cstring>
#include <fstream>

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, m, k;

	cin >> n >> m >> k;

	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= m; j++)
		{
			int x = n * j + (m - j) * i - j * i;
			//cout << i << ' ' << j << ' ' << x << '\n';
			if (x == k)
			{
				cout << "Yes" << '\n';
				return 0;
			}
		}
	}

	cout << "No" << '\n';

	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
q=int(input())
sa=sum(a)
bc=[]
for _ in range(q):
    b,c=map(int,input().split())
    bc.append([b,c])
d={}
for i in range(n):
    if a[i] not in d:
        d[a[i]]=1
    else:
        d[a[i]]+=1

for i in range(q):
    b=bc[i][0]
    c=bc[i][1]
    cb=c-b
    if b in d:
        sa+=cb*d[b]
        if c in d:
            d[c]+=d[b]
            d[b]=0
        else:
            d[c]=d[b]
            d[b]=0

    print(sa)



Measured memory_bytes: 33008
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    int n, m;
    long[][] graph;
    final long INF = Long.MAX_VALUE;

    public static void main(String[] args) {
        Main prob = new Main();
        prob.read();
        prob.solve();
    }

    void read() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        graph = new long[n][n];
        for (int i = 0; i < n; i++)
            Arrays.fill(graph[i], INF);
        for (int i = 0; i < m; i++) {
            int from = sc.nextInt();
            int to = sc.nextInt();
            long cost = sc.nextLong();
            graph[from][to] = cost;
        }
    }

    void solve() {
        long[][] anss = new long[n][n];
        long[] dist = new long[n];

        for (int start = 0; start < n; start++) {
            Arrays.fill(dist, INF);
            dist[start] = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    for (int k = 0; k < n; k++) {
                        if (dist[j] != INF &&
                                graph[j][k] != INF &&
                                dist[k] > dist[j] + graph[j][k]) {
                            dist[k] = dist[j] + graph[j][k];
                            if (i == n - 1) {
                                System.out.println("NEGATIVE CYCLE");
                                return;
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < n; i++) {
                anss[start][i] = dist[i];
            }
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (anss[i][j] == INF)
                    sb.append("INF ");
                else
                    sb.append(anss[i][j]+ " ");
            }
            sb.deleteCharAt(sb.length() - 1);
            sb.append("\n");
        }
        System.out.print(sb.toString());
    }

}

Measured memory_bytes: 59140
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL)
#define PI acos(-1.0)
#define TEST(n) cout<<"dhukse"<<n<<'\n'
#define endl '\n'
#define FILEREAD freopen("input.txt","r",stdin)
#define FIXED(n) cout << fixed << setprecision(n);
#define CASE(n) cout<<"Case " << n << ": ";
long long Set(long long N,long long pos){ return N=N | (1<<pos);}
long long reset(long long N,long long pos){return N= N & ~(1<<pos);}
bool check(long long N,long long pos){return (bool)(N & (1<<pos));}
long long min(long long a, long long b){if(a<b)return a;else return b;}
long long max(long long a, long long b){if(a>b)return a;else return b;}

/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////In the name of almighty ALLAH/////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Coded By: pranonrahman////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////


long long rec(long long n)
{
    if(n==1)    return 1;
    if(n==0)    return 0;
    return 1+2*rec(n/2);
}


int main()
{
    FAST;
    long long t=1;
   // cin >> t;
    long long T = t;
    while(t--)
    {
        long long h;
        cin >> h;
        long long cnt=0;
        cout << rec(h) << endl;
    }
    return 0;
}



Measured memory_bytes: 256
# https://atcoder.jp/contests/abc094/tasks/abc094_a

import itertools
import collections
import bisect

def main():
    A, B, X = map(int, input().split())
    rest = X - A
    if rest < 0 or rest > B:
        print("NO")
    else:
        print("YES")


if __name__ == '__main__':
    main()


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

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, N) cin >> L[i];
    sort(L.begin(), L.end());
    int ma = L[L.size()-1];
    int sum = 0;
    rep(i, N-1) sum += L[i];
    if (ma < sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

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

template<typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	string S;
	cin >> S;

	int a = 0, b = 0;
	for (auto s : S) {
		if (s == 'a') {
			if (a + b < A + B) {
				cout << "Yes" << endl;
				a++;
			}
			else cout << "No" << endl;
		}
		else if (s == 'b') {
			if (a + b < A + B && b < B) {
				cout << "Yes" << endl;
				b++;
			}
			else cout << "No" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 896
// ABC106B - 105

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;

int divisor(int n) {
	int ans = 0;

	for (int i = 1; i <= n; i++) {
		if (n % i == 0) {
			++ans;
		}
	}

	return ans;
}

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

	int ans = 0;
	for (int i = 1; i <= N; i += 2) {
		if (divisor(i) == 8) {
			++ans;
		}
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

V p[100001], q[100001];

// union by size + path having
class UnionFind {
public:
	vector <ll> par; // 各元の親を表す配列
	vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}
};
UnionFind tree(100001);

void solve_abc() {
	ll n, m, k;
	ll ans = 0;

	cin >> n >> m >> k;


	ll a, b, c, d;
	rep(i, m) {
		cin >> a >> b;
		p[a].push_back(b);
		p[b].push_back(a);
		tree.merge(a, b);
	}
	V dis(n + 1, 0);
	rep(i, k) {
		cin >> c >> d;
		if (tree.issame(c, d)) {
			dis[c]--;
			dis[d]--;
		}
		q[c].push_back(d);
		q[d].push_back(c);
	}

	ll size = 0;
	rep(i, n - 1) {
		size = tree.size(i + 1) - 1;
		cout << size - p[i + 1].size() + dis[i + 1] << " ";
	}
	cout << tree.size(n) - 1 - p[n].size() + dis[n] << "\n";
}

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

	solve_abc();

	return 0;
}

Measured memory_bytes: 15348
n, A, B, k = list(map(int, input().split()))

MOD = 998244353
MAX = n+2

fact, inverse = [0]*(MAX), [0]*(MAX)
fact[0], inverse[0] = 1, 1
for i in range(1, MAX):
  fact[i] = (fact[i-1]*i)%MOD
  inverse[i] = pow(fact[i], MOD-2, MOD)

def mod_comb(n, r):
  if n<r or n==0: return 0
  if r==0: return 1
  return (((fact[n]*inverse[r])%MOD)*inverse[n-r])%MOD

ans = 0
for i in range(n+1):
  if (k-A*i)%B == 0:
    b = (k-A*i)//B
    if 0<=b<=n:
      ans = (ans+mod_comb(n, i)*mod_comb(n, b))%MOD

if ans==0:
  print(1)
else:
  print(ans)

Measured memory_bytes: 45296
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b+c || b == a+c || c == a+b)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

// 全部列挙する

func main() {
	var n int
	fmt.Scan(&n)

	positions := make([][]int, n)
	for i :=0; i < n; i++ {
		var x, y int
		fmt.Scan(&x, &y)
		positions[i] = []int{x,y}
	}

	ans := 0.0
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				continue
			}
			diffX := float64(positions[i][0] - positions[j][0])
			diffY := float64(positions[i][1] - positions[j][1])
			ans += math.Sqrt(diffX*diffX + diffY*diffY)
		}
	}
	fmt.Println(ans/float64(n))
}


Measured memory_bytes: 512
X, Y, Z, K = map(int,input().split())
A = sorted(list(map(int,input().split())))[::-1]
B = sorted(list(map(int,input().split())))[::-1]
C = sorted(list(map(int,input().split())))[::-1]

temp = []
t = 0
for a in A:
    for b in B:
        temp.append(a+b)
temp = (sorted(temp)[::-1])[:K]

ans = []
for a in temp:
    for c in C:
        ans.append(a+c)
ans = (sorted(ans)[::-1])[:K]
print(*ans, sep="\n")


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n;cin >> n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    ll money=1000,kabu=0;
    for(int i=0;i<n-1;i++){
        if(a[i]<a[i+1]){//単調増加！今が買い時！
            ll t = money/a[i];
            kabu += t;
            money -= t*a[i];
        }
        else if(a[i]>a[i+1]){//単調減少！売るだけ無駄！
            money += kabu*a[i];
            kabu = 0;
        }
        else continue; //安定型
    }
    money += kabu*a[n-1];
    COUT(money);
}


Measured memory_bytes: 3596
while True:
    H, W =map(int,input().split())
    
    if(H == W == 0):
        break
    
    for i in range(H):
        for j in range(W):
            if(i == 0 or i == H - 1 or j == 0 or j == W - 1):
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()    


Measured memory_bytes: 7000
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=2e5+5;
int ans[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
    {
        int a;
        scanf("%d",&a);
        ans[a]++;
    }
    for(int i=1;i<=n;i++)
        printf("%d\n",ans[i]);
    return 0;
}


Measured memory_bytes: 2464
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize, h: u64,
        ab: [(u64, u64); n]
    }
    let mut a = ab.iter().map(|&(p,_)| p) .collect::<Vec<_>>();
    let mut b = ab.iter().map(|&(_,q)| q) .collect::<Vec<_>>();
    a.sort();
    b.sort();
    b.reverse();
    let mut cnt = 0;
    let mut h_rest = h;
    for i in 0..n {
        if h_rest == 0 || a[n-1] > b[i] {
            break;
        }
        h_rest = h_rest.saturating_sub(b[i]);
        cnt += 1;
    }
    cnt += (h_rest + a[n-1] - 1) / a[n-1];
    println!("{}", cnt);
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
int main(){
	FAST
	ll n;
	cin>>n;
	n %= 1000;
	n = 1000 - n, n %= 1000;
	cout<<n<<'\n';
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    ll sub = B - A;
    ll count = 0;
    if(sub % 2 == 0) count = sub / 2; //Aと、Bとの差が偶数であるとき、差を2で割った値分のラウンド数で戦える
    else{
        count = min(A-1, N-B) + 1 + (sub-1) / 2; //AとBの差が奇数であるとき、末端に近いほうの卓にいる人が、
                                                 //末端で勝ち負け1回してsubを1つ減らすことで、subが偶数になる。
    }
    cout << count << endl;
    return 0;
}

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

using namespace std;

typedef struct{
	char name[11];
	int time;
}Process;

class ProcessQueue{
public:
	ProcessQueue(int size):
		m_size(size),
		m_head(0),
		m_tail(0),
		number(0)
	{
		m_process = new Process[m_size];
	};

	~ProcessQueue(){
		delete[] m_process;
	};

	void enQueue(Process process){
		//strcpy(m_process[m_tail].name,process.name);
		//m_process[m_tail].time = process.time;

		m_process[m_tail] = process;	//=??§??£??\????

		number++;

		if(m_tail < m_size-1){
			m_tail++;
		}else{	//?????°?????????
			m_tail = 0;
		}
	};

	Process deQueue(){
		number--;
		if(m_head < m_size-1){
			m_head++;
			return m_process[m_head-1];
		}else{	//?????°?????????
			m_head = 0;
			return m_process[m_size-1];
		}
	};

	int getNumber(){
		return number;
	}

private:
	int m_head;
	int m_tail;
	int m_size;
	int number;
	Process* m_process;

};

int main(){

	int n,q,totaltime=0;
	scanf("%d%d",&n,&q);

	ProcessQueue queue(n);

	Process tmp;
	for(int i = 0; i < n; i++){
		scanf("%s%d",&tmp.name,&tmp.time);
		queue.enQueue(tmp);
	}

	while(queue.getNumber() != 0){
		tmp = queue.deQueue();
		if(tmp.time - q > 0){
			totaltime += q;
			tmp.time -= q;
			queue.enQueue(tmp);
		}else{
			totaltime += tmp.time;
			printf("%s %d\n",tmp.name,totaltime);
		}
	}

}



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

int main(){

    string a,b;
    cin >> a >> b;

    long long ans = 0;
    for(int i=0;i<a.length();i++){
        if(a[i]==b[i])
            ans++;
    }
    cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

bool ch(string &s, string &t){
    int pos=0;
    for(int i=0;i<t.size();i++){
        if(pos==s.size()){
            return 0;
        }
        if(s[pos]==t[i]){
            pos++;
        } else {
            pos++;
            i--;
        }
    }
    return 1;
}

int main(void) {
    
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    rep(i,10){
        rep(j,10){
            rep(k,10){
                string t="";
                t+=(char)(i+'0');
                t+=(char)(j+'0');
                t+=(char)(k+'0');
                if(ch(s,t))ans++;
            }
        }
    }
    fin(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std; 
int main() {
	
	char s[100] = {};
	int i = 0,flag=0;	
	cin >> s;

	while (true){

		if (s[i] == 0) {
			break;

		}
		else if (i%2==0) {
			if (s[i] == 'R' || s[i]== 'U' || s[i] == 'D') {

			}
			else {
				flag = 1;
				break;
			}
		}
		else if (i % 2 == 1) {
			if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')
			{

			}
			else {
				flag = 1;
				break;
			}
		}
		i++;
	}

	if (flag == 1) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}


	return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')

# 要素updateと区間クエリ
class SegmentTree(object):

    def __init__(self, A, e, fn):  # O(N)
        """
        :param A: 区間クエリの対象となる配列
        :param e: 単位元 fn(a, e) = fn(e, a) = a
        :param fn: (a, b) -> x な関数 a, bは交換則を満たす
        """
        self.e = e
        self.fn = fn
        self.length = 2 ** (len(A) - 1).bit_length()
        self.tree = [e] * 2 * self.length
        for i in range(len(A)):
            self.tree[i + self.length - 1] = A[i]
        for i in reversed(range(self.length - 1)):
            self.tree[i] = self.fn(self.tree[2 * i + 1], self.tree[2 * i + 2])

    # 配列のi番目をxに更新する
    def update(self, i, x):  # O(logN)
        i += self.length - 1
        self.tree[i] = x
        while i:
            i = (i - 1) // 2
            self.tree[i] = self.fn(self.tree[i * 2 + 1], self.tree[i * 2 + 2])

    # 区間[p, q)に関するクエリに答える
    def query(self, p, q):  # O(logN)
        if q <= p:
            return self.e
        p += self.length - 1
        q += self.length - 2
        res = self.e
        while q - p > 1:
            if p & 1 == 0:
                res = self.fn(res, self.tree[p])
            if q & 1 == 1:
                res = self.fn(res, self.tree[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.fn(res, self.tree[p])
        else:
            res = self.fn(self.fn(res, self.tree[p]), self.tree[q])
        return res

    # 現在のi番目の要素を取得する
    def at(self, i):  # O(1)
        return self.tree[i + self.length - 1]


N, Q = MI()
C = LMI()
LR = []
for i in range(Q):
    l, r = MI0()
    LR.append((i, l, r))

LR.sort(key=lambda x: x[2])
seg = SegmentTree([0] * N, 0, lambda a, b: a + b)
idx = dict()
cur = 0
ans = [0] * Q
for i, l, r in LR:
    while cur <= r:
        if C[cur] in idx:
            seg.update(idx[C[cur]], 0)
            seg.update(cur, 1)
            idx[C[cur]] = cur
        else:
            seg.update(cur, 1)
            idx[C[cur]] = cur
        cur += 1
    ans[i] = seg.query(l, r + 1)
for a in ans:
    print(a)

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

int n;
vector<set<int>> g;

bool solve();

int main() {
  cin >> n;
  g.resize(n);
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    g[--a].insert(--b);
    g[b].insert(a);
  }
  if (solve())
    cout << "First" << endl;
  else
    cout << "Second" << endl;
  return 0;
}

bool solve() {
  vector<int> ch;
  queue<int> bl, wh;
  ch.assign(n, 0);
  for (int i = 0; i < n; ++i)
    if (g[i].size() == 1) bl.push(i);
  while (bl.size() || wh.size()) {
    while (bl.size()) {
      int now = bl.front();
      bl.pop();
      for (auto to : g[now]) {
        g[to].erase(now);
        if (ch[to]) return 1;
        ch[to] = 1;
        if (g[to].size() == 1) wh.push(to);
      }
    }
    while (wh.size()) {
      int now = wh.front();
      wh.pop();
      for (auto to : g[now]) {
        g[to].erase(now);
        if (g[to].size() == 1) {
          if (ch[to])
            wh.push(to);
          else
            bl.push(to);
        }
        if (g[to].size() == 0 && !ch[to]) return 1;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 17972
#include"stdio.h"
int main(void){
  int N;
  int i,j;
  scanf("%d",&N);
  int H[N],L[N],count=0,max=0;
  for( i=0; i<N; i++){
    scanf("%d",&H[i]);
    L[i]=0;
  }
  for( i=0; i<N; i++ ){
    count=0;
    for( j=i; j<N; j++){
      if( H[j]<H[j+1] || j==N-1 ){
        L[i]=count;
        i += count;
        break;
      }
      count++;
    }
    if( max<L[i-count] ){
      max=L[i-count];
    }
  }
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 896
c = []
for i in range(3):
    c.append(list(map(int, input().split())))

for i in range(1, 3):
    diff = c[0][0] - c[i][0]
    for j in range(3):
        c[i][j] += diff

for i in range(3):
    if not (c[0][i] == c[1][i] == c[2][i]):
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 3064
import re
s = input()
pa = s.replace('x', '')
if pa != pa[::-1]:
    print(-1)
else:
    ans = 0
    sp = re.split(r'[a-wyz]', s)
    for r, l in zip(sp, sp[::-1]):
        ans += abs(len(r) - len(l))
    print(ans // 2)

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

int main()
{
    long long a, b, c;
    cin >> a >> b >> c;
    if (c - a - b < 0)
    {
        cout << "No" << endl;
        return 0;
    }
    if (4 * a * b < (c - a - b) * (c - a - b))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  ll tmp = 111;
  while(tmp<N){
    tmp+=111;
  }
  cout << tmp << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
using namespace std;
const int N=3030,M=100010;
const long long Mod=1e9+7;
const int MAX=2e9;
long long ans,n,q,a[N],x[N],y[N],f[N][N],inv;
long long power(long long x,long long y){
    long long sum=1,base=x;
    while(y){
        if(y&1) sum=(sum*base)%Mod;
        base=(base*base)%Mod;
        y>>=1;
    }
    return sum;
}
int main(){
    //freopen("problem.in","r",stdin);
    //freopen("problem.out","w",stdout);
    scanf("%lld%lld",&n,&q);
    inv=power(2,Mod-2);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(int i=1;i<=q;i++) scanf("%lld%lld",&x[i],&y[i]);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            f[i][j]=(a[i]<a[j]);
        }
    }
    for(int i=1;i<=q;i++){
        f[x[i]][y[i]]=f[y[i]][x[i]]=(f[x[i]][y[i]]+f[y[i]][x[i]])*inv%Mod;
        for(int j=1;j<=n;j++){
            if(j==x[i]||j==y[i]) continue;
            f[j][y[i]]=f[j][x[i]]=(f[j][x[i]]+f[j][y[i]])*inv%Mod;
            f[x[i]][j]=f[y[i]][j]=(f[x[i]][j]+f[y[i]][j])*inv%Mod;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<i;j++){
            ans=(ans+f[i][j])%Mod;
        }
    }
    printf("%lld\n",ans*power(2,q)%Mod);
    return 0;
}

Measured memory_bytes: 72064
/*
 * X Y
*/

#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <cassert>

using namespace std;

const int MAX = 2000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
  long long X, Y, z, a, b;
  cin >> X >> Y;

  if ((X + Y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }

  COMinit();

  z = (X + Y) / 3;
  a = Y - z;
  b = X - z;

  // a+b C a

  cout << COM(a+b, a) << endl;
}


Measured memory_bytes: 47104