akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

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

Measured memory_bytes: 3016
n, m = map(int, input().split())
a = [0] * m
b = [0] * m
for i in range(m):
    a[i], b[i] = map(int, input().split())
'''
check = 0


for i in range(m):
    if a[i] == 1:
        check = b[i]
        for j in range(m):
            if a[j] == check and b[j] == n:
                print("POSSIBLE")
                exit()

print("IMPOSSIBLE")

'''
start = []
leave = []
for i in range(m):
    if a[i] == 1:
        start.append(b[i])
    elif b[i] == n:
        leave.append(a[i])

if set(start) & set(leave):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 33920
#!/usr/bin/env python3

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    K = int(input())
    S = input()

    if len(S) > K:
        print(S[:K]+'...')
    else:
        print(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9108
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		int cnt=0;
		while(n!=1){
			if(n%2==0)
				n/=2;
			else
				n=n*3+1;
			cnt++;
		}
		cout<<cnt<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> vi;
typedef long double LD;
typedef pair <int,int> pii;
typedef pair <int,LL> piL;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=305*4;
int n;
int d1,d2;
pii p1[N],p2[N];
int c1=0,c2=0;
int vis[N][N];
int color[N][N];
void dfs1(int x,int y,int c){
  	if (x<1||y<1||x>n*2||y>n*2)
      	return;
 	if (vis[x][y])
      	return;
 	vis[x][y]=1;
  	color[x][y]|=c;
  	For(i,1,c1)
      	dfs1(x+p1[i].fi,y+p1[i].se,c^1);
}
void dfs2(int x,int y,int c){
  	if (x<1||y<1||x>n*2||y>n*2)
      	return;
 	if (vis[x][y])
      	return;
 	vis[x][y]=1;
  	color[x][y]|=c;
  	For(i,1,c2)
      	dfs2(x+p2[i].fi,y+p2[i].se,c^2);
}
int main(){
  	n=read(),d1=read(),d2=read();
  	For(i,0,d1){
		int a=d1-i*i;
      	if (a>=0){
          	int j=sqrt(a);
          	if (j*j==a){
              	p1[++c1]=mp(i,j);
              	p1[++c1]=mp(i,-j);
              	p1[++c1]=mp(-i,j);
              	p1[++c1]=mp(-i,-j);
            }
        }
  	}
  	For(i,0,d2){
      	int a=d2-i*i;
      	if (a>=0){
        	int j=sqrt(a);
        	if (j*j==a){
              	p2[++c2]=mp(i,j);
              	p2[++c2]=mp(i,-j);
              	p2[++c2]=mp(-i,j);
              	p2[++c2]=mp(-i,-j);
            }
      	}
    }
  	clr(vis);
  	For(i,1,n*2)
      	For(j,1,n*2)
      		if (!vis[i][j])
              	dfs1(i,j,0);
	clr(vis);
  	For(i,1,n*2)
      	For(j,1,n*2)
      		if (!vis[i][j])
              	dfs2(i,j,0);
 	For(t,0,3){
      	int c=0;
      	For(i,1,n*2)
          	For(j,1,n*2)
          		if (color[i][j]==t)
                  	c++;
     	if (c>=n*n){
          	c=n*n;
          	For(i,1,n*2)
              	For(j,1,n*2)
              		if (c>0&&color[i][j]==t)
                      	c--,printf("%d %d\n",i-1,j-1);
         	return 0;
        }
    }
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> num(n);
    for(int i = 0; i < n; i++){
      int a, b;
      cin >> a >> b;
      num[i] = make_pair(b, a);
    }

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

    int count = 0;
    for(int i = 0; i < n; i++){
      count += num[i].second;
      if(count > num[i].first){
        cout << "No" << endl;
        return 0;
      }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1792
a, b, c, x, y = map(int,input().split())

ans=float("inf")
for i in range(max(x, y) + 1):
    if i <= min(x, y):
        temp = a * (x - i) + b *(y - i) + c * 2 * i
        ans = min(temp, ans)
    else:
        if x > y:
            temp = a * (x - i) + c * 2 * i
        else:
            temp = b * (y - i) + c * 2 * i
            ans = min(ans, temp)
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    string s;
    while (cin >> s) {
        set<char> S(ALL(s));
        int ans = inf;
        FOR_ALL(ch,S) {
            string x = s, y;
            int res = 0;
            while (set<char>(ALL(x)).size() > 1) {
                y.clear();
                const int n = x.size();
                FOR(i,0,n-1) {
                    if (x[i] == *ch)
                        y += *ch;
                    else if (x[i+1] == *ch)
                        y += *ch;
                    else
                        y += x[i];
                }
                res ++;
                swap(x,y);
            }
            ans = min(ans,res);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    int j,k;
    if(a>b){
        j=a;
        k=b;
    }else{
        j=b;
        k=a;
    }
    string out="";
    for(int i=0;i<j;i++){
        out+=to_string(k);
    }
    cout<<out<<endl;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto s = RD!(char[]);
	auto K = RD;

	foreach (i, c; s)
	{
		auto num = c - 'a';
		if (num == 0) continue;
		if (26-num > K) continue;
		s[i] = 'a';
		K -= 26-num;
	}
	if (K != 0)
	{
		auto num = s[$-1] - 'a';
		debug writeln(num, " ", K, " ", ((num+K)%26));
		s[$-1] = [cast(char)('a'+((num+K)%26))].to!string[0];
	}

	writeln(s);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 2584
#include <stdio.h>

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left, int mid, int right) {
  int i, j, k;
  int n1 = mid -left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  i=0, j=0;
  for(k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  int mid;
  if(left+1 < right) {
    mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",cnt);

  return 0;
}


Measured memory_bytes: 5648
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define pob(x) pop_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin()+n)
// #define int long long
#define P pair<int, int>
typedef long long ll;

const long long int MOD = 1e9+7;
const int INF = -1;
ll dp[100005][13];

signed main(void) {
	int N;
	cin >> N;
	float sum = 0;
	rep(i, N) {
		float tmp;
		cin >> tmp;
		sum += 1/tmp;
	}

	cout << 1/sum << endl;

}


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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String keyWord = sc.next();
		keyWord = keyWord.toUpperCase();

		ArrayList<String> wordLists = new ArrayList<>();
		while(true) {
			String word = sc.next();
			if(word.equals("END_OF_TEXT")) break;
			wordLists.add(word.toUpperCase());
		}

		sc.close();

		// 単語数を計測
		int count = 0;
		for(String word : wordLists) {
			if(word.equals(keyWord)) count++;
		}

		System.out.println(count);

	}

}



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

int main()
{
    const std::string str_false = "Hoshino";
    const std::string str_true = "Hoshina";

    u_int num_of_data;
    std::string text;
    std::cin >> num_of_data;
    std::cin.ignore();
    
    for(u_int i = 0; i < num_of_data; ++i){
        getline(std::cin, text);
        int index =  0;
        
        while((index = text.find(str_false, index)) != -1)
            text.replace(index, str_false.size(), str_true);
        std::cout  << text << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
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;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) {
            os << ',';
        }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    int k;
    cin >> k;
    for(int i = 0; i < k; i++) {
        cout << "ACL";
    }
    cout << endl;
}

Measured memory_bytes: 3604
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define ll long long
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define forn(x) for(int i=1;i<=x;i++) 
#define sforn(x, y) for(int i=1;i<=x;i++)for(int j=1;j<=y;j++)
#define pii pair<int, int>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

/*
    LOL KEK CHEBUREK
 
    PIHALITI
 
 */
ll arr[1000100];
ll cnt[1000100];
void no(){
    cout << 0 << endl;
    exit(0);
}
ll mod = 998244353;
void mul(ll &a, ll b){
    a *= b;
    a %= mod;
    if(a < b) a += mod;
}
int main(){ speed;
    ll n;
    cin >> n;
    for(int i=1;i<=n;i++) {
        cin >> arr[i];
        ++cnt[arr[i]];
    }
    if(arr[1]!=0) no();
    if(cnt[0]!= 1) no();
    ll ans = 1;
    for(int i=1;i<=n;i++){
        if(!cnt[i-1] && cnt[i]) no();
    }
    for(int i=2;i<=n;i++){
        mul(ans, cnt[arr[i] - 1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;
 
    int c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0,any=0;
    for (int i = 0; i < n; i++) {
        int a = 0;
        cin >> a;
        if (a < 400) {
            c1 = 1;
        } else if (a < 800) {
            c2 = 1;
        } else if (a < 1200) {
            c3 = 1;
        } else if (a < 1600) {
            c4 = 1;
        } else if (a < 2000) {
            c5 = 1;
        } else if (a < 2400) {
            c6 = 1;
        } else if (a < 2800) {
            c7 = 1;
        } else if (a < 3200) {
            c8 = 1;
        } else {
            any++;
        }
    }
 
    int min = c1+c2+c3+c4+c5+c6+c7+c8;
    int max = min + any;
 
    if (min == 0 && any > 0) {
        min = 1;
        max = any;
    } 
    cout << min << " " << max << endl;
 
    return 0;
}

Measured memory_bytes: 256
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main {
	static InputStream is;
	static PrintWriter out;
	static String INPUT = "";

	static void solver() {
		int n = ni();
		int[] l = new int[2*n];
		for (int i = 0; i < 2 * n; i++) {
			l[i] = ni();
		}
		Arrays.sort(l);
		long sum = 0;
		for (int i = 0; i < n; i++) {
			sum += l[2 * i];
		}
		System.out.println(sum);
	}

	public static void main(String[] args) throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		solver();
		out.flush();
	}

	static long nl() {
		try {
			long num = 0;
			boolean minus = false;
			while ((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'))
				;
			if (num == '-') {
				num = 0;
				minus = true;
			} else {
				num -= '0';
			}

			while (true) {
				int b = is.read();
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	static char nc() {
		try {
			int b = skip();
			if (b == -1)
				return 0;
			return (char) b;
		} catch (IOException e) {
		}
		return 0;
	}

	static double nd() {
		try {
			return Double.parseDouble(ns());
		} catch (Exception e) {
		}
		return 0;
	}

	static String ns() {
		try {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			if (b == -1)
				return "";
			sb.append((char) b);
			while (true) {
				b = is.read();
				if (b == -1)
					return sb.toString();
				if (b <= ' ')
					return sb.toString();
				sb.append((char) b);
			}
		} catch (IOException e) {
		}
		return "";
	}

	public static char[] ns(int n) {
		char[] buf = new char[n];
		try {
			int b = skip(), p = 0;
			if (b == -1)
				return null;
			buf[p++] = (char) b;
			while (p < n) {
				b = is.read();
				if (b == -1 || b <= ' ')
					break;
				buf[p++] = (char) b;
			}
			return Arrays.copyOf(buf, p);
		} catch (IOException e) {
		}
		return null;
	}

	public static byte[] nse(int n) {
		byte[] buf = new byte[n];
		try {
			int b = skip();
			if (b == -1)
				return null;
			is.read(buf);
			return buf;
		} catch (IOException e) {
		}
		return null;
	}

	static int skip() throws IOException {
		int b;
		while ((b = is.read()) != -1 && !(b >= 33 && b <= 126))
			;
		return b;
	}

	static boolean eof() {
		try {
			is.mark(1000);
			int b = skip();
			is.reset();
			return b == -1;
		} catch (IOException e) {
			return true;
		}
	}

	static int ni() {
		try {
			int num = 0;
			boolean minus = false;
			while ((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'))
				;
			if (num == '-') {
				num = 0;
				minus = true;
			} else {
				num -= '0';
			}

			while (true) {
				int b = is.read();
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	static void tr(Object... o) {
		if (INPUT.length() != 0)
			System.out.println(Arrays.deepToString(o));
	}

}


Measured memory_bytes: 8020
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll N;
ll A[100000];
bool ans = false;

int main(void) {
    // insert code here...
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    sort(A, A+N);
//    for(int i = 0; i < N; i++){
//        cout << A[i] << endl;
//    }
    

    if(A[0]==1){
        ans = true;
    }
    
    for(int i = 0; i < N - 1; i++){
        if(ans){
            break;
        }
        ll a, b, c;
        a = A[i];
//        cout << a << endl;
        b = A[i+1];
//        cout << b << endl;
        while(1){
            c = b%a;
//            cout << c << endl;
            if(c==1){
                ans = true;
                break;
            }
            if(c==0){
                A[i+1] = a;
                break;
            }
            b = a;
            a = c;
        }
        if(ans){
            break;
        }
    }
    
    if(ans){
        cout << 1 << endl;
    }else{
        cout << A[N-1] << endl;
    }
    
    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

ll A[100005], B[100005], C[100005];
ll As[100005], Bs[100005];
int main()
{
	int N;
	ll ans = 0;

	cin >> N;
	memset(As, 0, 100005);
	memset(Bs, 0, 100005);

	rep(i, N)
		cin >> A[i];
	rep(i, N)
		cin >> B[i];
	rep(i, N)
		cin >> C[i];

	sort(A, A + N);
	sort(B, B + N);
	sort(C, C + N);

	for(int i = N - 1; i > -1; i--)
	{
		As[i] = B + N - upper_bound(B, B + N, A[i]);
		if(i == N - 1)
			Bs[i] = C + N - upper_bound(C, C + N, B[i]);
		else
			Bs[i] = Bs[i + 1] + C + N - upper_bound(C, C + N, B[i]);
	}

	rep(i, N)
		ans += Bs[N - As[i]];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
const int maxn = 123456;
int u[maxn];
void init(){
	for(int i = 0; i < maxn; i++) u[i] = i;
}
int find(int x){
	if(x == u[x]) return x;
	return u[x] = find(u[x]);
}
int join(int x, int y){
	x = find(x);
	y = find(y);
	if(x^y){
		u[x] = y;
		return true;
	}
	return false;
}
int deg[maxn], x[maxn], y[maxn];
int main(){
	int n, m; cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> x[i] >> y[i]; x[i]--; y[i]--;
		deg[x[i]]++;
		deg[y[i]]++;
	}
	for(int i = 0; i < n; i++){
		if(deg[i]&1) return !printf("No\n");
	}
	for(int i = 0; i < n; i++){
		if(deg[i] >= 6) return !printf("Yes\n");
	}
	for(int i = 0; i < n; i++){
		if(deg[i] >= 4){
			init();
			for(int j = 0; j < m; j++){
				if(x[j] != i && y[j] != i){
					if(!join(x[j], y[j])){
						return !printf("Yes\n");
					}
				}
			}
		}
	}
	return !printf("No\n");
}



Measured memory_bytes: 1920
n, x = STDIN.gets.split(' ').map(&:to_i)

# layers(l) = 'B' + layers(l-1) + 'P' + layers(l-1) + 'B'

class Burger
  def initialize(n)
    @layers = [1]
    @number_of_patties = [1]

    n.times do |i|
      @layers << 2 * @layers[i] + 3
      @number_of_patties << 2 * @number_of_patties[i] + 1
    end
  end

  def solve(n, x)
    if n == 0
      if x == 0
        return 0
      else
        return 1
      end
    end

    if x == 1
      return 0
    elsif x > 1 && x <= @layers[n-1] + 1
      return solve(n-1, x - 1)
    elsif x == @layers[n-1] + 2
      return @number_of_patties[n-1] + 1
    elsif x > @layers[n-1] + 2 && x <= 2*@layers[n-1] + 2
      return @number_of_patties[n-1] + 1 + solve(n - 1, x - 1 - 1 - @layers[n - 1])
    elsif x == 2*@layers[n-1] + 3
      return 2 * @number_of_patties[n-1] + 1
    end
  end
end

burger = Burger.new(n)
p burger.solve(n, x)


Measured memory_bytes: 1788
class UnionFind:
    def __init__(self, n):
        self.p = [i for i in range(n)]
        self.components = n  # 連結成分の数

    def root(self, x):
        if self.p[x] != x:
            stack = [x]
            while True:
                top = stack[-1]
                if self.p[top] == top:
                    break
                else:
                    stack.append(self.p[top])
            for v in stack:
                self.p[v] = top
        return self.p[x]
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.p[x] = y
            self.components -= 1
    
    def same(self, x,y):
        return (self.root(x) == self.root(y))

N, M = map(int,input().split())
edges = [list(map(int,input().split())) for _ in range(M)]

ans = 0
for i in range(M):
    UF = UnionFind(N)
    for j in range(M):
        if i == j: continue
        UF.unite(edges[j][0]-1, edges[j][1]-1)
    
    if UF.components > 1:
        ans += 1
print(ans)

Measured memory_bytes: 68088
#include <iostream>
#include <limits>
#include <cfenv>
#include <cmath>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <random>
#include <math.h>
#include <list>
#include <random>
#include <functional>


#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()

using lli = long long int;
using pii = std::pair<int, int>;

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


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



int main(void){
    int X; scanf("%d", &X);
    int C = X / 100;
    if(X <= C * 105) puts("1");
    else puts("0");

    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
int h,w,k;
string grid[6];
int main()
{
	cin>>h>>w>>k;
	string state;
	for(int i=0;i<h;i++) {
		cin>>state;
		grid[i]=state;
	}
	int sol=0;
	//grid created!
	for(int rowMask=0;rowMask<=(1<<h)-1;rowMask++)
		for(int columnMask=0;columnMask<=(1<<w)-1;columnMask++) {
			int cnt=0;
			for(int i=0;i<h;i++) {
				for(int j=0;j<w;j++) {
					//check if we painted this row red, and this column red, and check if black or white
					if((rowMask>>i&1)==0&&(columnMask>>j&1)==0&&grid[i][j]=='#')
						cnt++;
				}
			}
			if(cnt==k)
				sol++;
		}
	cout<<sol<<endl;
		
}



Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n, l, t;
int x[100001];
int w[100001];
int s[100001];
int ans[100001];
int main() {
    scanf("%d%d%d", &n, &l, &t);
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", x + i, w + i);
    }
    int x0 = x[1];
    for (int i = n; i > 0; --i) {
        x[i] = (x[i] - x[1] + l) % l;
    }
    int md = 0;
    if (w[1] != 1) {
        md = 1;
        w[1] = 1;
        for (int i = 2; i <= n; ++i) {
            if (i < n + 2 - i) {
                swap(x[i], x[n + 2 - i]);
                swap(w[i], w[n + 2 - i]);
            }
            x[i] = (l - x[i]) % l;
            w[i] ^= 3;
        }
    }
    int col = 0;
    for (int i = 1; i <= n; ++i) {
        s[i - 1] = ((x[i] + (3 - 2ll * w[i]) * t) % l + l) % l;
        if (w[i] == 1) continue;
        col += (2ll * t - x[i] + l) / l;
        col %= n;
    }
    int c = s[0];
    
    sort(s, s + n);
    int x = upper_bound(s, s + n, c) - s - 1;
    
    for (int i = 0; i < n; ++i) {
        ans[(col - x + i + n) % n] = s[i];
    }
    for (int i = 0; i < n; ++i) {
        printf("%d\n", md ? (l - ans[(n - i) % n] + x0) % l : (ans[i] + x0) % l);
    }
    
	return 0;
}


Measured memory_bytes: 2816
// ABC136B - Uneven Numbers

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

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

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

	int ans = 0;
	for (int i = 1; i <= N; i++) {
		if ((1 <= i)&&(i <= 9)) {
			++ans;
		} else if ((100 <= i)&&(i <= 999)) {
			++ans;
		} else if ((10000 <= i)&&(i <= 99999)) {
			++ans;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(){
  int n, k; cin >> n >> k;
  vector<ll> h(n); rep(i,n) cin >> h[i];
  sort(all(h));
  if(k>n) k=n;
  ll ans=0;
  rep(i,n-k) ans += h[i];
  cout << ans;
  
return 0;
}


Measured memory_bytes: 1792
N = int(input())
h = list(map(int,input().split()))
#足場(n+1)につくまでのコストの最小値
f = [0]*(N)
for i in range(1,N):
    if i == 1:
        f[i] = abs(h[i]-h[i-1])
    else:
        f[i] = min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]))
    
    

print(f[N-1])

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/04/04  Problem: ABC 042 A / Link: http://abc042.contest.atcoder.jp/tasks/abc042_a  ----- */


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

	multiset<int>se;
	FOR(i, 0, 3) {
		int a; cin >> a;
		se.insert(a);
	}
	LL ans =(se.count(5)==2)&&(se.count(7)==1);
	auto print_yesno = [](LL yes, int mode = 0) {
		if (mode == 0) {
			cout << (yes ? "yes" : "no") << endl;
		}
		else if (mode == 1) {
			cout << (yes ? "Yes" : "No") << endl;
		}
		else if (mode == 2) {
			cout << (yes ? "YES" : "NO") << endl;
		}
		else assert(0);
	};
	print_yesno(ans,2);

	return 0;
}


Measured memory_bytes: 256
class Counter
  @@max_size = 3
  def initialize(max, cond)
    @max = max
    @cond = cond
    @queue = []
    @count = 0
  end
  def run
    @queue << [1, @max, []]
    while @queue.size > 0 do
      task = @queue.shift
      from, to, nums = task
      (from..to).each do |i|
        new_nums = nums + [i]
        if new_nums.size >= @@max_size
          if new_nums.reduce{|sum, n| sum + n} == @cond
            @count += 1
          end
        else
          if i + 1 <= @max
            @queue << [i + 1, @max, new_nums]
          end
        end
      end
    end
    return @count
  end
end

lines = STDIN.read.split("\n")
lines.each do |line|
  n, x = line.split(' ').map(&:to_i)
  break if n == 0 && x == 0
  puts Counter.new(n, x).run()
end

Measured memory_bytes: 8896
#include <iostream>
using namespace std;
int main() {
    int a, b, k;
    int p;
    cin >> k;
    cin >> a >> b;
    p = b / k;
    if (a <= p*k) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<pair<long long, long long>>v1, v2;
long long power[16], power2[16];
long long solve(long long F, int p) {
	long long sum = 0;
	for (int i = p; i < p + 6; i++)sum += power[i] * ((F / power2[i - p]) % 10);
	return sum;
}
int main() {
	power[0] = 1; for (int i = 1; i < 16; i++)power[i] = power[i - 1] * (-10);
	power2[0] = 1; for (int i = 1; i < 16; i++)power2[i] = power2[i - 1] * (+10);
	for (int i = 0; i < 10000; i++) { v1.push_back(make_pair(solve(i, 0), i)); }
	for (int i = -999999; i < 1000000; i++) { v2.push_back(make_pair(solve(i, 4), i)); }
	sort(v2.begin(), v2.end());
	while (true) {
		long long r; cin >> r; if (r == 0)break;
		for (int i = 0; i < 10000; i++) {
			long long pos1 = lower_bound(v2.begin(), v2.end(), make_pair((r - v1[i].first), 0LL)) - v2.begin();
			if (pos1 < v2.size() && v2[pos1].first == (r - v1[i].first)) { cout << i + v2[pos1].second * 10000 << endl; }
		}
	}
	return 0;
}

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

ll m, n, x, y, z;

int main()
{
	cin >> n;

	ll x = 0, y = 0, i = 1;

	while(true){

		x += i;
		i++;


		if(x >= n){

			i--;
			x = x - i;
			y = n - x;

			break;
		}

	}

	//cout << i << ' ' << x << ' ' << y << endl;


	for(ll j = 1; j <= y; j++) printf(")");
	printf("(");
	for(ll j = y + 1; j <= i; j++) printf(")");

	for(ll j = 2; j <= i; j++) printf("(");
	cout << endl;


	return 0;
}

Measured memory_bytes: 3084
package main

import (
	"fmt"
)

func main() {
	var n, a int
	fmt.Scan(&n)
	ret := make([]int, n)
	for i := 0; i < n-1; i++ {
		fmt.Scan(&a)
		ret[i] = a
	}
	result := make([]int, n+1)
	for _, i := range ret {
		result[i]++
	}
	for i := 1; i < len(result); i++ {
		fmt.Println(result[i])
	}
}


Measured memory_bytes: 7984
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int main()
{
	int n,k,x,y,cost;
	scanf("%d%d%d%d",&n,&k,&x,&y);
	if(n<=k)
	{
		cost=n*x;
	}
	else
	{
		cost=k*x+(n-k)*y;
	}
	printf("%d\n",cost);
	return 0;
}

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

void fnInput(int64_t& rnNumber)
{
  cin >> rnNumber;
}

int64_t fnMinStepGet(int64_t nNumber)
{
  int nSqrtInt = sqrt(nNumber);
  int nMultpler;
  int64_t nMultplcand;
  int64_t nMinDiff = INT64_MAX;

  for (int n = 1; n <= nSqrtInt; n++)
  {
    if (nNumber % n == 0)
    {
      int64_t nOther = nNumber / n;
      if (nOther - n < nMinDiff)
      {
        nMultplcand = nOther;
        nMultpler = n;
        nMinDiff = nMultplcand - nMultpler;
      }
    }
  }

  return (nMultplcand + nMultpler - 2);
}

int main()
{
  int64_t nNumber;

  fnInput(nNumber);
  cout << fnMinStepGet(nNumber) << endl;

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
	int h, w; cin>>h>>w;
	vector<string> m(110);
	bool erasex[110]={}, erasey[110]={};
	for (int i=0; i<h; ++i){
		cin>>m[i];
		if (m[i].find('#')==string::npos)erasey[i]=1;//行iに'#'が一つもなければ、消す列にします。
	}
	bool tmp;
	for (int j=0; j<w; ++j){
		tmp=1;
		for (int i = 0; i<h; ++i)if (m[i][j]=='#')goto L_erase;
		erasex[j]=1;//列jに'#'が一つもなければ、消す列にします。
	L_erase:;
	}

	for (int i=0; i<h; ++i)if (!erasey[i]){
		for (int j=0; j<w; ++j){
			if (!erasex[j])cout<<m[i][j];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i =0; i < n ;i++)
using namespace std;
int v[500][500];
int p[500];

int main(){
    int N;
    cin >> N;
    int n = 3;
    int t = 3;
    
    if(N==1){
        cout << "Yes" <<endl;
        cout << "2" <<endl;
        cout << "1 1"  <<endl;
        cout << "1 1"  <<endl;
        return 0;
    }

    while(n < 100001){
        if(n==N)
        {

            
            cout << "Yes" <<endl;
            cout << t << endl;
            int val=1;
            for(int i =0; i < t ;i++){
                for(int j =i+1; j < t ;j++){
                    v[i][p[i]] = val;
                    p[i]++;
                    v[j][p[j]] = val;
                    p[j]++;
                    val++;
                }
            }
            for(int i =0; i < t ;i++){

                cout << t-1;
                for(int j =0; j < t-1  ;j++){
                    cout  << " " << v[i][j];
                }
                cout << endl;
            }

            return 0;
        }
        n += t;
        t +=1;
        //cout << n << " "<<t<< " ";
        
    } 
    cout << "No" <<endl;

    return 0;

   
}

Measured memory_bytes: 2304
// ALDS1_11_B.cpp
// Graph I - Depth First Search

#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

struct Vertex
{
    int id;
    vector<int> adjList;
    int d = 0;
    int f = 0;
};

int cnt = 0;

void dfs(vector<Vertex> &V, int n, int i)
{
    if (V[i].d != 0 && V[i].f != 0)
        return;
    int len = V[i].adjList.size();
    V[i].d = ++cnt;

    for (int j = 0; j < len; j++) {
        int next = V[i].adjList[j];
        if (V[next].d == 0) {
            // V[next].d = ++cnt;
            dfs(V, n, next);
            //V[next].f = ++cnt;
        }
    }
    V[i].f = ++cnt;
}

int main()
{
    int n;
    cin >> n;
    vector<Vertex> V(n);
    int id;
    int num;
    for (int i = 0; i < n; i++) {
        cin >> id >> num;
        V[id-1].id = id-1;
        int tmp;
        for (int j = 0; j < num; j++) {
            cin >> tmp;
            V[id-1].adjList.push_back(tmp-1);
        }
    }
    for (int i = 0; i < n; i++)
        dfs(V, n, i);
    for (int i = 0; i < n; i++) {
        printf("%d %d %d\n", i + 1, V[i].d, V[i].f);
    }
    return 0;
}

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

int main() {
	long long N, A, B, C, D;
	bool check = false;
	cin >> N >> A >> B >> C >> D;
	for (int i = 0; i < N; i++) {
		long long X, Y;
		X = A + C * i - D * (N - i - 1);
		Y = A + D * i - C * (N - i - 1);
		if (X <= B && B <= Y) check = true;
	}
	if (check) cout << "YES";
	else cout << "NO";
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll x; cin >> x;
	ll a = x/100, b = x%100;

	bool ra = a >= 1 && a <= 12;
	bool rb = b >= 1 && b <= 12;
	
	if (ra) cout << (rb ? "AMBIGUOUS" : "MMYY") << endl;
	else cout << (rb ? "YYMM" : "NA") << endl;


}



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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
    int Q; cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}


Measured memory_bytes: 21736
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

//文字列中にある'BC'は操作によって分断されたり新しく増えたりすることがない
//
int main() {
	string S; cin >> S;
	string New = "";
	if (S.size() < 3) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < S.size(); ++i) {
		if (S[i] != 'B') {
			New += S[i];
		}
		else {
			if (i+1<S.size()&&S[i + 1] == 'C') {
				New += 'D';
				i++;
			}
			else {
				New += 'B';
			}
		}
	}
	vector<string>s;
	for (int i = 0; i < New.size(); ++i) {
		int k = i;
		string x = "";
		while ((New[k] == 'A' || New[k] == 'D')&&k<New.size()) {
			x += New[k];
			k++;
		}
		if (x != "")s.push_back(x);
		i = k;
	}
	ll cnt = 0;
	for (int i = 0; i < s.size(); ++i) {
		int k = 0;
		for (int j = 0; j < s[i].size(); ++j) {
			if (s[i][j] == 'D') {
				cnt += j - k;
				k++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3328
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if A == B:
    print("YES")
elif A < B:
    if A + V * T >= B + W * T:
        print("YES")
    else:
        print("NO")
else:
    if A - V * T <= B - W * T:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9192
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {
	private static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();

		long top = N;
		long sum = 0;
		for (long i = 1; i <= N; i++) {
			long bottom = N / (i + 1);
			if (top == bottom) {
				break;
			}

			for (long j = top; j > bottom; j--) {
				long mod = N % j;
				if (mod == i) {
					sum += j;
				}
				if (mod >= i) {
					break;
				}
			}
			top = bottom;
		}
		System.out.println(sum);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public char nextChar() throws IOException {
			return (char) skip();
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

Measured memory_bytes: 23248
S=input()
N=len(S)+1

a=[0]
temp=0
f=0
mx_idx=0

for i in range(1,N):
    if S[i-1]=="<":
        if f>=0:
            a.append(a[i-1]+1)
            temp+=1
            f=1
        else:
            if temp>0:
                for j in range(mx_idx+1,i):
                    a[j]-=temp
            elif temp<0:
                for j in range(mx_idx,i):
                    a[j]-=temp
            a.append(1)
            temp=1
            f=1
    else:
        if f<=0:
            a.append(a[i-1]-1)
            temp-=1
            f=-1
        else: 
            a.append(a[i-1]-1)
            temp-=1
            mx_idx=i-1
            f=-1

if temp<0:
    for j in range(mx_idx, N):
        a[j] -= temp
print(sum(a))


Measured memory_bytes: 24092
#include "bits/stdc++.h"
using namespace std;
int main(){
	int a;
	cin >> a;
	vector<float> res(a);
	float sum = 0;
	for(int x = 0; x<a; x++){
		cin >> res[x];
		sum += 1/res[x];
	}
	cout << 1/sum;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

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

using namespace std;

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

    vector<pair<int, int>> p;
    rep(i, m) {
	int a, b;
	cin >> a >> b;
	p.push_back(make_pair(a, b));
    }

    int g_bit = 0;
    rep (i, n)
	g_bit |= (1 << i);

    int res = 0;
    queue<pair<int, int>> que; /* now_point, flg */
    que.push(make_pair(1, 1)); /* スタート地点(現在地１、到達頂点１) */    

    while (!que.empty()) {
	pair<int, int> now = que.front();
	que.pop();

	if ((now.second & g_bit) == g_bit) {
	    res++;
	    continue;
	}
	
	rep (i, (int)p.size()) {
	    if (now.first == p[i].first) {
		if ((now.second >> p[i].second - 1) & 1) /* 到達済み */
		    continue;
		else
		    que.push(make_pair(p[i].second, now.second | (1 << (p[i].second - 1))));

	    } else if (now.first == p[i].second) {
		if ((now.second >> p[i].first - 1) & 1) /* 到達済み */
		    continue;
		else
		    que.push(make_pair(p[i].first, now.second | (1 << (p[i].first - 1))));
	    }
	}
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256