akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i = (a);i < (b); i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

const int N = 80010;

int len;
char line[N];

int dp[N][11];

int solve()
{
  memset(dp, 0, sizeof(dp));
  rep(i, len) {
    int d = line[i] - '0';
    dp[i + 1][d] = !!d;
    rep(j, 11)
      dp[i + 1][j] += dp[i][(d - j + 11) % 11];
  }

  int ret = 0;
  rep(i, len)
    ret += dp[i + 1][0];
  return ret;
}

int main()
{
  while (fgets(line, sizeof(line), stdin), *line != '0') {
    len = strlen(line);
    line[--len] = '\0';
    printf("%d\n", solve());
  }

  return 0;
}

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

#define mem(a,n) memset(a,n,sizeof(a))
#define memc(a,b) memcpy(a,b,sizeof(b))
#define rep(i,a,n) for(int i=a;i<n;i++) ///[a,n)
#define pb push_back
#define IO ios::sync_with_stdio(false)
#define fre freopen("in.txt","r",stdin)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
typedef unsigned long long ull;
const double PI=acos(-1.0);
const double E=2.718281828459045;
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int MOD=1e3;
const int N=1e2+5;
const ll maxn=2e5+5;
const int dir[4][2]= {-1,0,1,0,0,-1,0,1};

int n;
bool vis[N];
int match[N];
vector<int>g[N];
int a[N],b[N],c[N],d[N];
void init()
{
    mem(vis,0);
    rep(i,0,n+1) g[i].clear();
}
bool dfs(int u)
{
    for(auto v:g[u])
    {
        if(vis[v]) continue;
        vis[v]=1;
        if(match[v]==-1||dfs(match[v]))
        {
            match[v]=u;
            return true;
        }
    }
    return false;
}

void solve()
{
    int ans=0;
    mem(match,-1);
    rep(i,0,n)
    {
        mem(vis,0);
        if(dfs(i)) ans++;
    }
    cout<<ans<<endl;
}
int main()
{
    cin>>n;
    rep(i,0,n) cin>>a[i]>>b[i];
    rep(i,0,n) cin>>c[i]>>d[i];
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            if(a[i]<c[j]&&b[i]<d[j])
                g[i].pb(j);
        }
    }
    solve();
    return 0;
}


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

int main(){
    //input
    long long N;
    cin >> N;
    vector<long long> A_vec;
    long long A;
    long long i;
    for(i=1; i<=N; i++){
        cin >> A;
        A_vec.push_back(A-i);
    }

    //calc
    sort(A_vec.begin(),A_vec.end());
    A = A_vec[N/2];
    long long ans=0;
    for(i=0; i<A_vec.size(); i++){
        ans += abs(A-A_vec[i]);
    }

    //answer
    cout << ans << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 5268
#include<iostream>
#include<list>
#include<vector>
#include<string>
#include<cmath>

using namespace std;

int main(){
  	int N, K;
	cin >> N;
  	cin >> K;
    long res = K;
    
    for(int i = 2; i <= N; i++){
      res = res * (K-1);
    }
  
    cout << res << endl;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [L, R] = string_to_int(inputs[0])

    if R - L >= 2019:
        return 0

    min = L * R
    for i in range(L, R):
        for j in range(i+1, R+1):
            c = (i*j) % 2019
            if min > c:
                min = c
    return min


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, M = mi()
ks = []
for i in range(M):
    a = li()
    ks.append(a)
P = li()

cnt = 0
pattern = [0]*N

def dfs(pattern, pos):
    if pos == N:
        for i in range(M):
            num , *switches = ks[i]
            if sum([pattern[sw-1] for sw in switches]) % 2 != P[i]:
                break
        else:
            global cnt
            cnt += 1
    else:
        pattern[pos] = 0
        dfs(pattern, pos+1)
        pattern[pos] = 1
        dfs(pattern, pos+1)
        
dfs(pattern, 0)
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	int ans = 0;
	ans += n / 25;
	n %= 25;

	ans += n / 10;
	n %= 10;

	ans += n / 5;
	n %= 5;

	ans += n;

	cout << ans << endl;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
    ll a, b, x;
    cin >> a >> b >> x;
    if(a == 0){
        cout << b/x+1 << endl;
    }else{
        cout << (b/x+1)- ((a-1)/x+1) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader breader = getReader();
		int n = getInt(breader); 
		int[] num = getAry(breader);
		int snum = 0;
		for(int i = 0; i < n ; i++ ) {
			int mini=i;
			for( int j = i+1 ; j < n ; j++ ) {
				if ( num[mini] > num[j] ) {
					mini = j;
				}
			}
			if ( mini != i) {
				int k = num[mini];
				num[mini] = num[i];
				num[i] = k;
				snum++;
			}
		}
		putAry(num);
		System.out.println(snum);
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(System.in)));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static int[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	}
	public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	}
	public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	}

	

}

Measured memory_bytes: 17112
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int[] v=new int[n];
        HashMap<Integer,Integer> mapE=new HashMap<>();
        HashMap<Integer,Integer> mapO=new HashMap<>();
        HashMap<Integer,Integer> map=new HashMap<>();
        for (int i = 0; i < n; i++) {
            v[i]=sc.nextInt();
            map.put(v[i], map.getOrDefault(v[i], 0)+1);
            if(i%2==0){
                mapE.put(v[i],mapE.getOrDefault(v[i], 0)+1);
            }else{
                mapO.put(v[i], mapO.getOrDefault(v[i],0)+1);
            }
        }
        
        if(map.get(v[0])==n){
            out.println(n/2);
            exit(0);
        }
        
        int Emax=0,Omax=0;
        for(int k:mapE.keySet()){
            Emax=max(Emax,mapE.get(k));
        }
        for(int k:mapO.keySet()){
            Omax=max(Omax,mapO.get(k));
        }
        int tmpE=0,tmpO=0;
        for(int k:mapE.keySet()){
            if(mapE.get(k)==Emax)tmpE=k;
        }
        for(int k:mapO.keySet()){
            if(mapO.get(k)==Omax)tmpO=k;
        }
        int Emax2=0,Omax2=0;
        for(int k:mapE.keySet()){
            if(k!=tmpO)Emax2=max(Emax2,mapE.get(k));
        }
        for(int k:mapO.keySet()){
            if(k!=tmpE)Omax2=max(Omax2,mapO.get(k));
        }
        out.println(min(n-Omax-Emax2,n-Omax2-Emax));
    }
}

Measured memory_bytes: 70056
import java.util.*;

class RMQ{
	private int size, data[];
	private int query(int a, int b, int k, int l, int r){
		if (r <= a || b <= l) {
			return Integer.MAX_VALUE;
		}
		if (a <= l && r <= b) {
			return data[k];
		}
		int lc = query(a,b,2*k,l,(l+r)/2);
		int rc = query(a, b, 2*k+1, (l+r)/2, r);
		return Math.min(lc,rc);
	}
	RMQ(int s){
		for(size = 1; size<s;){
			size *= 2;
		}
		data = new int[size*2];
		for(int i = 0; i<size*2; i++){
			data[i] = Integer.MAX_VALUE;
		}
	}
	public void update(int pos, int x){
		pos += size;
		data[pos] = x;
		while(pos >1){
			pos /=2;
			data[pos] = Math.min(data[2*pos],data[2*pos+1]);
		}
	}
	public int find(int l, int r){
		return query(l,r,1,0,size);
	}
}

class Main{
	public static void main(String[] args) throws java.lang.Exception{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		RMQ r = new RMQ(n);
		for (int i = 0; i < q; i++) {
			int c = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			if (c==0) {
				r.update(x,y);
			} else {
				System.out.println(r.find(x,y+1));
			}
		}
	}
}


Measured memory_bytes: 105532
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 

using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
int main(void){
	int N;
	VI array;
	cin >> N;
	REP(i,N){
		int a;
		cin >> a;
		array.PB(a);
	}
	int state = 1;
	int num = 0;
	int cnt = 1;
	REP(i,N-1){
		if(state == 1){
			if(array[i] == array[i+1]){
				state = 1;
			}
			else if(array[i] > array[i+1]){
				state = 2;
			}
			else if(array[i] < array[i+1]){
				state = 3;
			}
			// if(i==N-2)cnt++;
		}
		else if(state == 2){ //ascending?
			if(array[i] >= array[i+1]){

			}
			else{
				state = 1;
				cnt++;
			}
		}
		else if(state == 3){ //ascending?
			if(array[i] <= array[i+1]){

			}
			else{
				state = 1;
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}



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

bool isPrime(int n){
    for(int i = 2; i*i <=n ;i++){
        if(n % i == 0) return false;
    }
    return n != 1;
}

int main(){
    int n;
    while(cin >> n, n){
        int ans = 0;
        for(int i = n + 1; i <= 2 * n; i++){
            if(isPrime(i)) ans++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
  	int n;
    cin>>n;
    while(n!=0)
    {
      if(n%10==7)
      {
        cout<<"Yes";
          return 0;
      }
      n/=10;
    }
    cout<<"No";
}

Measured memory_bytes: 3692
N, M, K = map(int, input().split())
INF = 10**9
 
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def size(self, x):
        return -self.parents[self.find(x)]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
 
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
 
    def group_count(self):
        return len(self.roots())
 
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
 
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
 
 
union_find = UnionFind(N)
friend_num_list = [0]*N
block_num_list = [0]*N
 
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    friend_num_list[a] += 1
    friend_num_list[b] += 1
    union_find.union(a, b)
 
for _ in range(K):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if union_find.same(c, d):
        block_num_list[c] += 1
        block_num_list[d] += 1
 
ans_list = [0]*N
for i in range(N):
    ans = union_find.size(i) - friend_num_list[i] - block_num_list[i] - 1
    ans_list[i] = ans
print(*ans_list)

Measured memory_bytes: 14904
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

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

const int N = 2e5 + 10; 
int n, a; ll p, ans = 0; 
map<ll, int> mp; 

int main(int argc, char const *argv[]) {
    scanf("%d", &n); 
    mp[0] = 1; 
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &a); 
        p += a; ans += mp[p]++; 
    }
    printf("%lld\n", ans);
}   

Measured memory_bytes: 12800
n, k = map(int, input().split())
h = list(map(int, input().split()))
 
cost = [0 for _ in range(len(h))]
 
for i in range(len(h)):
    if i == 0:
        continue
    if i == 1:
        cost[i] = abs(h[i] - h[i - 1])
    else:
        cost[i] = min(cost[i - 1 - k] + abs(h[i] - h[i - 1 - k]) for k in range(min(i, k)))
print(cost[i])

Measured memory_bytes: 56160
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b,c,d; cin >> a>>b>>c>>d;
	if ((abs(a - b) <= d && abs(b - c) <= d)||abs(a-c)<=d)cout << "Yes";
	else cout << "No";

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
# N: サイコロの綿の数
# K: 相手の得点
p=0
for n in range(1,N+1):
    s=1/N
    while n<K:
        n*=2
        s*=0.5
    #print(n,s)
    p+=s
print(p)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define rep(i,x,n) for(int (i)=(x);(i)<(n);(i)++)
using namespace std;

int main(){
    
    int n;
    long ans=0;
    cin >> n;
    vector<long> a(n+1),b(n);
    rep(i,0,n+1)cin >> a[i];
    rep(i,0,n)cin >> b[i];

    rep(i,0,n){

        if(b[i] >= a[i]){
            ans += a[i];
            b[i] -= a[i];
            if(b[i] >= a[i+1]){
                ans += a[i+1];
                a[i+1] = 0;
            }else{
                ans += b[i];
                a[i+1] -= b[i];
            }
        }else{
            ans += b[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
i = bisect.bisect_left(a,0)
if i % 2 == 0:
    ans = abs(sum(a[:i]))+sum(a[i:])
else:
    if i == n:
        ans = abs(sum(a[:i-1]))+a[i-1]
    else:
        ans = abs(sum(a[:i-1]))+abs(a[i]+a[i-1])+sum(a[i+1:])
print(ans)


Measured memory_bytes: 14480
import java.util.*;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        for(int i=1;i<10;i++)for(int j=1;j<10;j++){
            if(i*j==n){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");


    }

}


Measured memory_bytes: 22996
#import pysnooper
#import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
print(n**3)

Measured memory_bytes: 3444
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int p[10000];
int h[10000];
int n;
int q;
 queue<int>z;
int pa(int x){
	int zz;
	if (p[x] == x){
		for (; z.empty() == 0;){
			zz = z.front();
			p[zz] = x;
			z.pop();
		}
		return x;
	}
	else{
		z.push(x);
		return pa(p[x]);
	}
}
void un(int x, int y){
	int max;
	if (h[x] < h[y]){
		p[x] = y;
	}
	else if(h[x]>h[y]){
		p[y] = x;
	}
	else{
		p[y] = x;
		h[x]++;
	}
}
void ju(int x, int y){
	if (x == y)printf("1\n");
	else printf("0\n");
}
int main(void){
	scanf("%d %d", &n,&q);
	int w, x, y;
	int a, b;
	for (int i = 0; i < 10000; i++){
		h[i] = 1;
		p[i] = i;
	}
	for (int qq; qq < q; qq++){
		scanf("%d %d %d", &w, &x, &y);
		a = pa(x);
		b = pa(y);
		if (w == 0)un(a, b);
		else ju(a, b);
	}

		return 0;
	}

Measured memory_bytes: 2728
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> v;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        v.push_back({x,y});
    }
    for(int i=0;i<n-2;i++){
        if(v[i].F==v[i].S and v[i+1].F==v[i+1].S and v[i+2].F==v[i+2].S){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No";
}

Measured memory_bytes: 3636
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF (1LL<<60)
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
#define MSB(x) (63-__builtin_clzll(x))
#define pcnt(x) (__builtin_popcountll(x))
#define parity(i,j) (i&(1LL<<j))
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n;
  cin >> n;

  if(n%2==0){
    int ans = 0,tmp = 10;
    while(tmp <= n) ans += n/tmp, tmp *= 5;
    cout << ans << endl; 
  }
  else cout << 0 << endl;
 
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        String ans = "No";

        if (Math.abs(a - c) <= d) {
            ans = "Yes";
        } else if (Math.abs(a - b) <= d && Math.abs(b - c) <= d){
            ans = "Yes";
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 21972
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ k, x ] <- readInts
	putStrLn $ intercalate " " $ map show [ x - k + 1 .. x + k - 1 ]

Measured memory_bytes: 508
#include <stdio.h>
#include <algorithm>
#include <deque>
#include <math.h>

using namespace std;

typedef long long ll;

#define N 110000

ll a[N];

int main() {
    int n;
    while (scanf("%d", &n) != EOF) {
        for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
        sort(a, a + n);
        if (n == 1 || n == 0) puts("0");
        if (n == 2) printf("%lld\n", a[1] - a[0]);
        else {
            int i = 0, j = n - 1;
            deque<ll> q;
            q.push_back(a[j--]);
            q.push_back(a[i++]);
            while (i <= j) {
                ll f = q.front(); ll b = q.back();
                if (i == j) {
                    if (abs(f - a[i]) > abs(b - a[i])) {
                        q.push_front(a[i++]); break;
                    } else {
                        q.push_back(a[j--]); break;
                    }
                }
                if (abs(f - a[i]) + abs(b - a[j]) > abs(f - a[j]) + abs(b - a[i])) {
                    //printf("1  %lld %lld\n", a[i], a[j]);
                    q.push_front(a[i++]); q.push_back(a[j--]);
                } else {
                    //printf("2  %lld %lld\n", a[i], a[j]);
                    q.push_front(a[j--]); q.push_back(a[i++]);
                }
            }
            ll res = 0;
            ll x = q.front(); q.pop_front(); //printf("%lld\n", x);
            while (!q.empty()) {
                ll y = q.front(); q.pop_front();
                //printf("%lld\n", y);
                res += abs(x - y);
                x = y;
            }
            printf("%lld\n", res);
        }
    }
    return 0;
}


Measured memory_bytes: 1792
n, m = map(int, input().split())
a = list()
for i in range(n) :   #1行ずつn行まで読み込みlistに格納
 a.append(list(map(int, input().split())))
b = list()
for j in range(m) :
 b.append(int(input()))
      
for i in range(n) :
 s = 0
 for j in range(m) :
   s += a[i][j] * b[j]
 print(s)


Measured memory_bytes: 6004
N = int(input())
A = list(map(int, input().split()))

cs = [0] * N
cs[0] = A[0]
for i in range(1, N):
  cs[i] = cs[i-1] + A[i]

B = [0 for i in range(N)]
B[1] = 0
left = 0
for i in range(2, N - 1):
  t = abs(cs[i] - cs[left] * 2) 
  for j in range(left + 1, i):
    if abs(cs[i] - cs[j] * 2) > t:
      left = j - 1
      break
    t = abs(cs[i] - cs[j] * 2)
  else:
    left = i - 1
  B[i] = left
E = [0 for i in range(N)]
E[N - 2] = N - 2
right = N - 2
for i in range(N - 3, 0, -1):
  t = abs(cs[N - 1] - cs[right] * 2 + cs[i]) 
  for j in range(right - 1, i, -1):
    if abs(cs[N - 1] - cs[j] * 2 + cs[i]) > t:
      right = j + 1
      break
    t = abs(cs[N - 1] - cs[j] * 2 + cs[i])
  else:
    right = i + 1
  E[i] = right

Ans = 10**15
for i in range(1, N - 2):
  b = cs[B[i]]
  c = cs[i] - cs[B[i]]
  d = cs[E[i]] - cs[i]
  e = cs[-1] - cs[E[i]]
  t = max(b, c, d, e) - min(b, c, d, e)
  if Ans > t:
    Ans = t
print(Ans)

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

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  for (int i= 0; i < N; i++) {
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  string out = "";
  for (int i = 0; i < N; i++) {
    out += S.at(i);
  }
  cout << out << endl;
}


Measured memory_bytes: 256
use proconio::{fastout, input};
use proconio::marker::Chars;

#[fastout]
fn main() {
    input! {
        n: usize,
        c: Chars,
    }

    let mut left = 0;
    let mut right = n-1;
    let mut ans = 0;

    while left < right {

        while left < n && c[left] == 'R' {
            left += 1;
        }

        while right > 0 && c[right] == 'W' {
            right -= 1;
        }
    
        if left < right {
            ans += 1;
            left += 1;
            right -= 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 3052
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int divide(int a)
{
    int ret = 0;
    int len = 0;
    while(a > 0){
        if(a & 1){
            ++ len;
        }
        a >>= 1;
        if(!(a & 1) && len > 0){
            ret ^= (1 << (len - 1));
            len = 0;
        }
    }
    return ret;
}

vector<vector<int> > to(18);
vector<int> memo(1<<18, -1);

int grundy(int curr)
{
    if(memo[curr] != -1)
        return memo[curr];

    vector<bool> x(50, false);
    for(int i=0; i<18; ++i){
        if(!(curr & (1 << i)))
            continue;
        for(unsigned j=0; j<to[i].size(); ++j)
            x[grundy(curr ^ to[i][j])] = true;
    }

    for(int i=0; ; ++i){
        if(!x[i])
            return memo[curr] = i;
    }
}

int main()
{
    for(int i=0; i<18; ++i){
        set<int> s;
        for(int j=0; j<(1<<(i+1))-1; ++j)
            s.insert(divide(j) ^ (1 << i));
        to[i] = vector<int>(s.begin(), s.end());
    }

    int n;
    cin >> n;

    int init = 0;
    for(int i=0; i<n; ++i){
        int a = 0;
        int p;
        string s;
        cin >> p >> s;
        for(unsigned j=0; j<s.size(); ++j){
            a *= p;
            if('0' <= s[j] && s[j] <= '9')
                a += s[j] - '0';
            else if('A' <= s[j] && s[j] <= 'Z')
                a += s[j] - 'A' + 10;
            else
                a += s[j] - 'a' + 36;
        }
        init ^= divide(a);
    }

    if(grundy(init) == 0)
        cout << "lose" << endl;
    else
        cout << "win" << endl;

    return 0;
}

Measured memory_bytes: 2068
N = int(input())
if N < 10 :
    print(N)
elif N < 100 :
    print(9)
elif N < 1000 :
    print(N-90)
elif N < 10000 :
    print(909)
elif N < 100000 :
    print(N-9090)
else : print(90909)





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

int main(void)
{
	int r, g, b, n;
	int i, j, k;
	int sum = 0;
	
	
	scanf("%d%d%d%d", &r, &g, &b, &n);
	
	for(i = 0; i <= n / r; i++) {
		for(j = 0; j <= n / g; j++) {
			if(i * r + j * g > n) {
				break;
			}
			if( (n - r * i - g * j) % b != 0) {
				continue;
			}
			sum++;
		}
	}
	
	printf("%d\n", sum);
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <string>
#include <vector>

using namespace std;

int main(){

  int ro,wo,c,r;
  int count=0,w=0;
  vector<int> result;

  while(true){
    cin>>ro>>wo>>c>>r;
    if(ro+wo+c+r==0) break;

    w=0;
    if(ro/wo<c){
      while(true){
	++w;
	if((ro+w*r)/wo>=c) break;
      }
    }
    result.push_back(w);
    ++count;
  }

  for(int i=0; i<count; ++i){
    cout << result[i] << endl;
  }

  
  return 0;
}



Measured memory_bytes: 3104
n=int(input())
r_min=int(input())
r_t=int(input())
g_max=r_t-r_min
r_min=min(r_t,r_min)

for _ in range(n-2):
    r_t=int(input())
    g_max=max(g_max,r_t-r_min)
    r_min=min(r_t,r_min)

print(g_max)


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N, M;
    cin >> N >> M;
    int cnt = 0;
    map<int, int>likes;
    for (int i=0; i<N; i++){
        int ki;
        cin >> ki;
        for (int j=0; j<ki; j++){
            int Aik;
            cin >> Aik;
            likes[Aik-1]++;
        }
    }

    for (int i=0; i<M; i++){
        if (likes[i] == N){
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

int main(){
    int na[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int in_;

    cin >> in_;
    cout << na[in_-1];
    return 0;
}

Measured memory_bytes: 256
N, A, B = map(int,input().split())
d = B - A
ans = 0
if d % 2 == 0:
    print(d//2)
    exit()
else:
    if A == 1 or B == N:
        print(1+d//2)
        exit()
    if A-1 < N-B:
        ans += A-1
        B -= A-1
        d = B-1
        ans += 1+d//2
    else:
        ans += N-B
        A += N-B
        d = N-A
        ans += 1+d//2
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

string s;
vector<ll> vs;

int main() {
    cin >> s;
    ll ans = 0;
    bool two = false;
    rep(i,s.size()) {
        if (i == 0 || two) {
            two = false;
            ans++;
        } else if (s[i-1] == s[i]) {
            two = true;
            i++;
            if (i == s.size()) break;
            ans++;
        } else {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] l = new int[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
			sum += l[i];
		}
		Arrays.sort(l);
		sum -= l[n - 1];
		if (l[n - 1] < sum) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

using namespace std;

int main() {

	string a, b, c;

	cin >> a >> b >> c;

	if (a.back() == b[0]) {

		if (b.back() == c[0])
			cout << "YES";

		else
			cout << "NO";

	}

	else
		cout << "NO";

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

string s;

int main()
{
    cin >> s;

    int a,z;

    for(int i = 0;i < s.size();i++)
    {
        if(s[i] == 'A')
        {
            a = i;
            break;
        }
    }
    for(int i = s.size() - 1;i >= 0;i--)
        if(s[i] == 'Z')
        {
            z = i;
            break;
        }

    cout << z - a + 1 << endl;
    return 0;
}

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

int main(){
  string S;
  int K;
  cin >> K >> S;
  int a = S.size();
  if(a <= K){
    cout << S << endl;
  }else{
    for(int i = 0; i < K; i++){
      cout << S[i];
    }
    cout << "..." << endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int ,int>;

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

#define INF 99999999
#define MOD (int)1e9 + 7
#define rep(i,n) for(int i = 0;i<n;i++)
#define all(x) x.begin(),x.end()

string s[100010];   
string K;

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

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (k == j*(n - i) + i*(m - j)) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 1024
# それぞれソート済みとして, 整数でAi<BjかつBj<Ckとなるjを求める(にぶたん)

N = int(input())
A = list(sorted(list(map(int, input().split()))))
B = list(sorted(list(map(int, input().split()))))
C = list(sorted(list(map(int, input().split()))))


def lower_bound(arr, target):
    # targetを超える最小の値のインデックス
    if target > arr[-1]:
        return None
    left, right = 0, len(arr)
    while left < right:
        mid = (left + right) // 2
        if arr[mid] > target:
            right = mid
        else:
            left = mid + 1
    return right


def upper_bound(arr, target):
    # target以上の最小の値のインデックス
    if target < arr[0]:
        return None
    left, right = 0, len(arr)
    while left < right:
        mid = (left + right) // 2
        if arr[mid] >= target:
            right = mid
        else:
            left = mid + 1
    return right


count = 0

for b in B:
    ai = upper_bound(A, b)
    ci = lower_bound(C, b)
    if ai is not None and ci is not None:
        count += ai * (N - ci)

print(count)


Measured memory_bytes: 107876
#include <iostream>
using namespace std;
int main(){
    int N,max,count,c;
    int A[100];
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int k=0;k<100;k++){
        for(int j=0;j<N;j++){
            if(max==A[j]){
                A[j]=0;
            }
            if(j==0){
                max=A[j];
                c=0;
            }
            if(max<A[j]){
                max=A[j];
                c=j;
            }
        }
        A[c]=0;
        if(max != 0){
            count++;
        }
    }
    cout << count <<endl;
}


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

int main() {
    ll N;
    cin >> N;
    vector<ll> head(N+1,0);
    rep(i,N){
        ll num;
        cin>>num;
        head[num]++;
    }
    for(int i=1;i<=N;i++){
        cout<<head[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 4820
// abc174_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

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

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

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



template <typename T>
struct RangeTree {
    int n;
    vector<vector<T>> dat;
    vector<T> val;

    explicit RangeTree(vector<T>& val_): val(val_) {
        n = 1;
        while (n < val.size()) n <<= 1;
        dat.assign(n << 1, vector<T>());

        build(0, 0, val.size());
    }

    void build(int k, int l, int r) {
        if (r-l == 1) {
            dat[k].emplace_back(val[l]);
        } else {
            int lch = 2*k+1, rch = 2*k+2;
            build(lch, l, (l+r)/2);
            build(rch, (l+r)/2, r);
            dat[k].resize(r-l);
            merge(dat[lch].begin(), dat[lch].end(), dat[rch].begin(), dat[rch].end(), dat[k].begin());
        }
    }

    int query(int i, int j, T x) {
        return query(i, j, x, 0, 0, val.size());
    }

    int query(int i, int j, T x, int k, int l, int r) {
        if (j <= l || r <= i) return 0;
        // x以下の要素の数
//        if (i <= l && r <= j) return upper_bound(dat[k].begin(), dat[k].end(), x) - dat[k].begin();
        // x未満の要素の数
        if (i <= l && r <= j) return lower_bound(dat[k].begin(), dat[k].end(), x) - dat[k].begin();
        int lch = query(i, j, x, 2*k+1, l, (l+r)/2);
        int rch = query(i, j, x, 2*k+2, (l+r)/2, r);
        return lch+rch;
    }
};


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

    int N, Q;
//    cin >> N >> Q;
    scanf("%d", &N);
    scanf("%d", &Q);
    vector<int> C(N);
//    REP(i, N) {scanf("%d", cin >> C[i]; C[i]--;}
    REP(i, N) {scanf("%d", &C[i]); C[i]--;}

    vector<int> last(N, N);
    vector<int> nxt(N);
    REP_REV(i, N){
        nxt[i] = last[C[i]];
        last[C[i]] = i;
    }

    // [l,r)で、r未満の要素の数を数える
    RangeTree<int> rt(nxt);

    REP(i, Q){
        int l, r;
//        cin >> l >> r; l--;
        scanf("%d", &l); l--;
        scanf("%d", &r);
        int ans = r - l - rt.query(l, r, r);
//        print(ans);
        printf("%d\n", ans);
    }


    return 0;
}


Measured memory_bytes: 98776
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
using namespace std;

ll n, ans;

inline ll read(){
	ll s = 0, w = 1;
	char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) w *= ch == '-' ? -1 : 1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0';
	return s * w;
}

inline ll gcd(ll a, ll b){
	if (a < b) swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}

inline void work(){
	n = read();
	REP(i, 1, n)
		REP(j, 1, n)
			REP(k, 1, n){
				if (min(i, min(j, k)) == 1) ans++;
				else if (i == j && j == k) ans += i;
					else ans += gcd(i, gcd(j, k));
			}
	printf("%lld\n", ans);
}

int main(){
	work();
	return 0;
}

Measured memory_bytes: 3764
def f(n):
	if n % 2 == 0:
		return int(n/2)
	else:
		return int(3*n+1)

a_list = [int(input())]

count = 0
while True:
	target = f(a_list[-1])
	if target in a_list:
		a_list.append(target)
		print(len(a_list))
		break
	else:
		a_list.append(target)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    string s;
    cin >> s;
    bool judge = true;
    if(s.size() %2 == 1){
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < s.size(); ++i) {
        if(i % 2 == 0){
            if(s[i] != 'h'){
                judge = false;
            }
        }else{
            if(s[i] != 'i'){
                judge = false;
            }

        }
    }
    if(judge){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
set<char>in;
for(int i=0;i<s.size();i++){char j=s[i];
in.insert(j);
}
if(in.size()==2){cout << "Yes";
}
if(in.size()!=2){cout << "No";
}
return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,m] <- getIntList
    xy <- VU.replicateM m $ do
        [x,y] <- getIntList
        return (x-1,y-1)
    let result = VU.create $ do
            balls <- VUM.replicate n (1 :: Int)
            red <- VUM.replicate n False
            VUM.write red 0 True
            VU.forM_ xy $ \(x,y) -> do
                VUM.modify balls pred x
                VUM.modify balls succ y
                nx <- VUM.read balls x
                cx <- VUM.read red x
                when (nx == 0) $ VUM.write red x False
                when cx $ VUM.write red y True
            return red
    print . VU.length $ VU.filter id result

Measured memory_bytes: 7756
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<functional>
using namespace std;
#define INF 1e15
#define MOD 1000000007
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
#define END system("PAUSE");return 0
int n, m, cnt[26], x, y, z;
char c[111][111];
signed main() {
	cin >> n >> m;
	rep(i, n) {
		rep(j, m) {
			cin >> c[i][j];
			cnt[c[i][j] - 'a']++;
		}
	}
	//x:1個の個数
	//y:2個の個数
	//z:4個の個数
	if (n % 2 && m % 2)x=1;
	if (n % 2)y += m / 2 * 2;
	if (m % 2)y += n / 2 * 2;
	z = n * m - y - x;
	y /= 2, z /= 4;
	rep(i, 26) {
		while (cnt[i] >= 4 && z >= 1) {
			z--, cnt[i] -= 4;
		}
	}
	rep(i, 26) {
		while (cnt[i] >= 2 && y >= 1) {
			y--, cnt[i] -= 2;
		}
	}
	rep(i, 26) {
		while (cnt[i] >= 1 && x >= 1) {
			x--, cnt[i] -= 1;
		}
	}
	if (x || y || z)puts("No");
	else puts("Yes");
	END;
}


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



int w[105], v[105], dp[105][100005];
int main() {
        int n, lim; cin >> n >> lim;
        int tot = 0;
        for (int i = 1; i <= n; i++) cin >> w[i] >> v[i], tot += v[i];


        for (int i = 0; i <= n; i++) for (int j = 0; j <= tot; j++) dp[i][j] = 1e9;
        dp[0][0] = 0;


        for (int i = 1; i <= n; i++) {
                for (int j = 0; j <= tot; j++) {
                        dp[i][j] = dp[i - 1][j];
                        if (j - v[i] >= 0 && dp[i - 1][j - v[i]] ^ (int) 1e9) {
                                dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
                        }
                }
        }


        for (int j = tot; j >= 0; j--) {
                int mn = 1e9;
                for (int i = 0; i <= n; i++) mn = min(mn, dp[i][j]);
                if (mn <= lim) {
                        cout << j;
                        return 0;
                }
        }
}

Measured memory_bytes: 42944
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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; }

#define keta setprecision(10) //10桁表示


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n)
	{
		cin >> a[i];
	}

	vector<vector<int>> ans(h, vector<int>(w));

	int it = 0;

	for (int i = 0; i < h; i++)
	{
		if (i % 2)
		{
			for (int j = w - 1; j >= 0; j--)
			{
				if (a[it] == 0)
				{
					it++;
				}
				a[it]--;
				ans[i][j] = it + 1;
			}
		}
		else
		{
			for (int j = 0; j < w; j++)
			{
				if (a[it] == 0)
				{
					it++;
				}
				a[it]--;
				ans[i][j] = it + 1;
			}
		}
	}

	rep(i, h)
	{
		rep(j, w-1)
		{
			cout << ans[i][j] << " ";
		}
		cout << ans[i][w - 1];
		cout << endl;
	}
	debug;
	return 0;
}

Measured memory_bytes: 632