akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;
typedef pair <ll, ll> pll;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, m, pr[N], dp[N];
string s;
pii t[N * 4];
void upd(int v, int l, int r, int pos, pii val) {
    if (l == r) {
        t[v] = val;
        return;
    }
    pos <= md ? upd(v + v, l, md, pos, val) : upd(v + v + 1, md + 1, r, pos, val);
    t[v] = min(t[v + v], t[v + v + 1]);
}
pii get(int v, int l, int r, int left, int right) {
    if (left > r || right < l) return {INF1, INF1};
    if (left <= l and r <= right) return t[v];
    return min(get(v + v, l, md, left, right), get(v + v + 1, md + 1, r, left, right));
}
main() {
    file("stars");
    ios;
    cin >> n >> m >> s;
    s = '#' + s;
    if (s[1] == '1') return !(cout << -1);
    fo(i, 1, n * 4, 1) t[i] = {INF1, INF1};
    upd(1, 1, n, 1, {0, 1});
    fo(i, 2, n + 1, 1) {
        if (s[i] == '1') continue;
        pii p = get(1, 1, n, i - m, i - 1);
        if (p.F != INF1) {
            dp[i] = dp[p.S] + 1;
            pr[i] = p.S;
            upd(1, 1, n, i, {dp[i], i});
        } else upd(1, 1, n, i, {INF1, INF1}), dp[i] = INF1;
    }
    if (dp[n + 1] == INF1) return !(cout << -1);
    vector <int> ans;
    int cur = n + 1;
    while (pr[cur]) {
        ans.eb(cur - pr[cur]);
        cur = pr[cur];
    }
    reverse(all(ans));
    for (int it : ans) cout << it << " ";
    cerr << "\nTime elapsed: " << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}
/**

*/


Measured memory_bytes: 4972
#include<bits/stdc++.h>
using namespace std;
const int N=5e6+5;
int n,now,a[N],b[N],v[N],nex[N],head[N],_head[N];
int gcd(int x,int y){
	while(y){
		int t=y;
		y=x%y,x=t;
	}
	return x;
}
bool vis[N];
priority_queue<int>que;
void add(int x,int y){
	nex[++now]=head[x];
	head[x]=now,v[now]=y;
}
void _add(int x,int y){
	nex[++now]=_head[x];
	_head[x]=now,v[now]=y;
}
void dfs(int x){
	vis[x]=1;
	for(int i=head[x];i;i=nex[i])
		if(!vis[v[i]]){
			_add(x,v[i]),++b[v[i]];
			dfs(v[i]);
		}
}
int main(){
	//freopen("rearranging.in","r",stdin);
	//freopen("rearranging.out","w",stdout);

	scanf("%d",&n);
	for(int i=1;i<=n;i++)	scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		for(int j=n;j;j--)
			if(gcd(a[i],a[j])!=1) add(i,j);
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			dfs(i);
			que.push(i);
		}
	}
	while(!que.empty()){
		int x=que.top();
		que.pop(),printf("%d ",a[x]);
		for(int i=_head[x];i;i=nex[i])
			if(!(--b[v[i]]))	que.push(v[i]);
	}
	putchar('\n');
	return 0;
}


Measured memory_bytes: 33152
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
	map<char, int> conv;
	conv['('] = 0;
	conv[')'] = 0;
	conv['['] = 1;
	conv[']'] = 1;

	map<char, int> mode;
	mode['('] = 1;
	mode[')'] = -1;
	mode['['] = 1;
	mode[']'] = -1;

	string str;
	while ( getline(cin, str), str != "." ) {
		vector<int> prev;
		int nest = 0;
		bool ans = true;
		for (int i = 0; i < str.size(); ++i) {
			if (conv.find(str[i]) != conv.end()) {
				int bid = conv[str[i]];
				if (mode[str[i]] < 0) {
					if (nest <= 0 || prev[nest-1] != bid) ans = false;
					--nest;
				}
				else {
					if (++nest > prev.size()) prev.push_back(bid);
					else prev[nest-1] = bid;
				}
				if (!ans) break;
			}
		}
		if (nest != 0) ans = false;
		if (ans) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

Measured memory_bytes: 1196
input_line = input().split()
W = int(input_line[0])
H = int(input_line[1])
x = int(input_line[2])
y = int(input_line[3])
r = int(input_line[4])

print("Yes" if (r<=x and x<=W-r) and (r<=y and y<=H-r) else "No")




Measured memory_bytes: 5596
#include <stdio.h>


int main(){
	const int MAX_V = 10000;
	int prime[MAX_V+1];
    	int i, k, v;
    	for(i = 2; i <= MAX_V; i++) prime[i] = 1;
    	for(i = 2; i <= MAX_V; i++){
        	if(prime[i]){
        		for(k = 2 * i; k <= MAX_V; k += i){
        			prime[k] = 0;
      			}
       	 	}
    	}
    	while(scanf("%d", &v) != EOF) {
        	for(i = v; i >= 5; i--){
       			if(prime[i] && prime[i-2]) {
               		 	printf("%d %d\n", i-2, i);
                		break;
            		}
        	}
    	}
}

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

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

  vector<int> h(N);
  rep(i, N) cin >> h[i];

  vector<int> cnt(101);
  for (int t = 1; t <= 100; t++) {
    bool on = false;
    int n = 0;
    rep(i, N) {
      if (h[i] >= t)
        on = true;
      if (h[i] < t && on)
        on = false, n++;
    }
    if (on)
      n++;
    cnt[t] += n;
  }

  int ans = 0;
  for (int i = 1; i <= 100; i++)
    ans += cnt[i];
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

const int mod=1e9+7;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int numL=0,numR=0;
    for(int i=0;i<n;i++){
        if(s[i]=='('){
            numL++;
        }else if(s[i]==')'&&numL==0){
            numR++;
        }else if(s[i]==')'&&numL!=0){
            numL--;
        }
    }
    for(int i=0;i<numR;i++){
        cout << '(';
    }
    cout << s;
    for(int i=0;i<numL;i++){
        cout << ')';
    }
    cout << endl;
}

Measured memory_bytes: 256
using System;
public class Program {
  public static void Main() {
    int N = int.Parse(Console.ReadLine());
    for (int i = 0; i < 100/7; i++) {
      for (int j = 0; j < 100/4; j++) {
        if (i*7 + j*4 == N) {
          Console.WriteLine("Yes");
          return;
        }
      }
    }
    Console.WriteLine("No");
  }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n, m ,c;
    cin >>n>>m>>c;

    vector<ll> b(m, 0);
    vector<vector<ll>> a(m, vector<ll>(n, 0));

    rep(i,0,m)
        cin >> b[i];

    rep(j,0,n)
        rep(i,0,m) cin>>a[i][j];

    //rep(j,0,n)
    //    rep(i,0,m) cout << a[i][j];

    ll cnt(0);
    rep(j,0,n)
    {
        ll dot(0);
        rep(i,0,m) dot += a[i][j] * b[i];

        dot += c;

        if(dot > 0) cnt++;
    }

    cout << cnt << endl;

    return 0;
}


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

int main()
{
        ll N; cin >> N;
        vector<ll> cnt(5, 0);
        for (int i = 0; i < N; ++i) {
                string s; cin >> s;
                if (s[0] == 'M') cnt[0]++;
                else if (s[0] == 'A') cnt[1]++;
                else if (s[0] == 'R') cnt[2]++;
                else if (s[0] == 'C') cnt[3]++;
                else if (s[0] == 'H') cnt[4]++;
        }
        ll ans = 0;
        for (int i = 0; i < 3; ++i) {
                for (int j = i+1; j < 4; ++j) {
                        for (int k = j+1; k < 5; ++k) {
                                ans += (cnt[i] * cnt[j] * cnt[k]);
                        }
                }
        }
        cout << ans << endl;


}


Measured memory_bytes: 256
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        k: isize,
        s: isize
    };
    let upper = std::cmp::min(k, s);
    let mut count = 0;
    // 0 <= x <= y <= z <= k で考える
    for x in 0..=upper {
        for y in x..=upper {
            let z = s - x - y;
            if (z > k) {
                continue;
            }
            if (z < 0) || (z < y) {
                break;
            }
            count += if (x == y) && (y == z) {
                1
            } else if (x == y) || (y == z) {
                3
            } else {
                6
            };
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 2128
import Control.Monad.State
 
main :: IO ()
main = do
  n <- readLn
  print $ evalState (step n) (2, 1)
 
step :: Int -> State (Int, Int) Int
step 0 = fst <$> get
step 1 = snd <$> get
step n = get >>= put . lucas >> step (n - 1)
  where lucas (x, y) = (y, x + y)

Measured memory_bytes: 508
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

class Program
{
    static void Main(string[] args)
    {
        var keyence = "keyence";
        var S = sc.ReadStr();

        var ok = S.StartsWith(keyence) || S.EndsWith(keyence);
        if (ok)
        {
            Console.WriteLine("YES");
            return;
        }

        for (int i = 1; i <= 6; i++)
        {
            var s = keyence.Substring(0, i);
            var e = keyence.Substring(i, 7 - i);
            ok = S.StartsWith(s) && S.EndsWith(e);
            if (ok) break;
        }

        Console.WriteLine(ok ? "YES" : "NO");
    }

    static int MOD = (int)1e9 + 7;
    static int INF = (int)1e7 + 1;
    static long LINF = (long)1e13 + 1;
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}



Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int n,m,s,e;
vector<int> ss,ee;
bool vis[100005];
vector<int> g[100005];
bool check(int x)
{
	for(int i=0;i<g[x].size();i++)
		if(!vis[g[x][i]])
			return true;
	return false;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int a,b;
		cin>>a>>b;
		if(i==1)
		{
			s=a;
			e=b;
		}
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vis[s]=vis[e]=1;
	int now=s;
	while(check(now))
	{
		for(int i=0;i<g[now].size();i++)
			if(!vis[g[now][i]])
			{
				now=g[now][i];
				break;
			}
		vis[now]=1;
		ss.push_back(now);
	}
	now=e;
	while(check(now))
	{
		for(int i=0;i<g[now].size();i++)
			if(!vis[g[now][i]])
			{
				now=g[now][i];
				break;
			}
		vis[now]=1;
		ee.push_back(now);
	}
	cout<<ss.size()+ee.size()+2<<endl;
	for(int i=ss.size()-1;i>=0;i--)
		cout<<ss[i]<<' ';
	cout<<s<<' '<<e<<' ';
	for(int i=0;i<ee.size();i++)
		cout<<ee[i]<<' ';
	cout<<endl;
	return 0;
}

Measured memory_bytes: 6904
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll res=pow(x,y/2);
  res*=res;
  res%=mod;
  if(y%2==1) res*=x;
  return res%mod;
}
vector<ll> frac;
vector<ll> frac_;
void set_frac(ll n){
  frac.push_back(1);
  for(ll i=1;i<=n;i++) frac.push_back(i*frac[i-1]%mod);
  for(int i=0;i<=n;i++) frac_.push_back(pow(frac[i],mod-2));
}
ll nCr(ll n,ll r){
  ll res=frac[n];
  res*=frac_[r];
  res%=mod;
  res*=frac_[n-r];
  return res%mod;
}
ll ans[3005]={0};
int main(){
  ll p;
  cin>>p;
  mod=p;
  set_frac(p);
  for(ll i=0;i<p;i++){
    ll a;
    cin>>a;
    if(a==1){
      ans[0]++;
      ll k=1;
      for(ll j=p-1;j>=0;j--){
        ll kans=nCr(p-1,j);
        kans*=k;
        k*=p-i;
        k%=p;
        kans%=p;
        ans[j]-=kans;
        ans[j]+=p;
        ans[j]%=mod;
      }
    }
  }
  for(int i=0;i<p;i++) cout<<ans[i]%mod<<" ";
  cout<<endl;
}


Measured memory_bytes: 384
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var H = input[0];
            var N = input[1];

            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

            for (int i = 0; i < N; i++)
            {
                H -= A[i];
            }
            Console.WriteLine(H <= 0 ? "Yes" : "No");
        }
    }
}

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

int A[100003] , N;

int main(){
	scanf("%d" , &N);
	for(int i = 1 ; i <= N ; ++i) scanf("%d" , &A[i]);
	sort(A + 1 , A + N + 1); int pos = 1;long long sum = 0;
	while(pos <= N){
		int p = pos + 1; sum += A[pos];
		while(p <= N && A[p] <= sum * 2) sum += A[p++];
		if(p == N + 1) cout << p - pos;
		pos = p;
	}
	return 0;
}


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

#define MAXN 3005

using namespace std;

const int mod = 1e9 + 7;

int dp[MAXN], pre[MAXN];

int sub(int a, int b) {

    a -= b;
    if(a < 0)
        a += mod;
    return a;
}

int add(int a, int b) {

    a += b;
    if(a >= mod)
        a -= mod;
    return a;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    string s;
    cin >> n >> s;

    dp[1] = 1;
    for(int i = 2; i <= n; i++) {
        for(int j = 1; j < i; j++)
            pre[j] = add(pre[j - 1], dp[j]);
        for(int j = 1; j <= i; j++) {
            if(s[i - 2] == '<')
                dp[j] = pre[j - 1];
            else
                dp[j] = sub(pre[i - 1], pre[j - 1]);
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; i++)
        ans = add(ans, dp[i]);
    cout << ans << endl;
    return 0;
}


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

int main(){

  int n; cin >> n;
  vector<int> v(n);
  for(int i=0; i<n; i++){
    cin >> v[i];
  }
  for(int i=n-1; i>=0; i--){
    cout << v[i];
    if(i != 0)
      cout << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3072
import java.util.*;

public class Main {
    public static final int[] coins = {
        1, 5, 10, 50, 100, 500
    };

    public static void main(String[] args) {
        int sum = 0;
        try(Scanner scn = new Scanner(System.in)) {
            for(int i = 0; i < coins.length; i++) {
                sum += coins[i] * scn.nextInt();
            }
        }
        System.out.println(sum < 1000 ? 0 : 1);
    }
}

Measured memory_bytes: 26020
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //
        //Compute c1=new Compute();//計算系
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //String answer="No";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int d[]=new int[n];
        for (int i=0;i<n;++i) { d[i]=sc.nextInt(); }
        Arrays.sort(d);

        int k1=d[n/2-1];
        int k2=d[n/2];

        answer=k2-k1;
        if (answer<=0) {answer=0;}

        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        System.out.println(answer);
    }
}

Measured memory_bytes: 50420
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String nl = System.getProperty("line.separator");
		StringBuilder p = new StringBuilder(500);
		StringBuilder d = new StringBuilder(".");
		StringBuilder s = new StringBuilder("#");
		Scanner r = new Scanner(System.in);
		int h, w, i, j, ww;
		String t;
		for (i = 0; i < 4; ++i) {
			d.append(d);
			s.append(s);
		}
		ww = d.length();
		while ((h = r.nextInt()) + (w = r.nextInt()) > 0) {
			while (w > ww) {
				d.append(d);
				s.append(s);
				ww += ww;
			}
			p.append(s.substring(0,w));
			p.append(nl);
			t = d.substring(0, w - 2);
			for (i = 2; i < h; ++i) {
				p.append('#');
				p.append(t);
				p.append('#');
				p.append(nl);
			}
			p.append(s.substring(0,w));
			p.append(nl);
			p.append(nl);
		}
		System.out.print(p);
	}
}

Measured memory_bytes: 18396
import java.util.*;
import java.util.Map.Entry;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
      
      
public class Main {	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		boolean[][] matrix = new boolean[n][n];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				matrix[i][j] = sc.nextInt() == 1?true:false;
			}
		}
		for(int i = 0; i < m; i++) {
			int o = sc.nextInt();
			if(o == 0) {
				int r = sc.nextInt()-1;
				int c = sc.nextInt()-1;
				int size = sc.nextInt();
				int angle = sc.nextInt();
				for(int j = 0; j < angle / 90; j++) {
					boolean[][] submatrix = new boolean[size][size];
					for(int k = 0; k < size; k++) {
						for(int l = 0; l < size; l++) {
							submatrix[l][size - k - 1] = matrix[k + r][l + c];
						}
					}
					for(int k = 0; k < size; k++) {
						for(int l = 0; l < size; l++) {
							matrix[k + r][l + c] = submatrix[k][l];
						}
					}
				}
			}
			else if(o == 1) {
				int r = sc.nextInt()-1;
				int c = sc.nextInt()-1;
				int size = sc.nextInt();
				for(int j = 0; j < size; j++) {
					for(int k = 0; k < size; k++) {
						matrix[j + r][k + c] = !matrix[j + r][k + c];
					}
				}
			}
			else if(o == 2) {
				int r = sc.nextInt()-1;
				boolean tmp = matrix[r][0];
				for(int j = 0; j < n-1; j++) {
					matrix[r][j] = matrix[r][j+1];
				}
				matrix[r][n-1] = tmp;
			}
			else if(o == 3) {
				int r = sc.nextInt()-1;
				boolean tmp = matrix[r][n-1];
				for(int j = n-1; j >= 1; j--) {
					matrix[r][j] = matrix[r][j-1];
				}
				matrix[r][0] = tmp;
			}
			else if(o == 4) {
				int r = sc.nextInt()-1;
				int c = sc.nextInt()-1;
				dfs(r,c,matrix,matrix[r][c]);
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.print(matrix[i][0]?1:0);
			for(int j = 1; j < n; j++) {
				System.out.print(" " + (matrix[i][j]?1:0));
			}
			System.out.println();
		}
	}
	
	static int[] vx = {0,1,0,-1};
	static int[] vy = {1,0,-1,0};
	static void dfs(int y, int x, boolean[][] matrix, boolean target) {
		if(matrix[y][x] != target) return;
		matrix[y][x] = !matrix[y][x];
		int n = matrix.length;
		for(int i = 0; i < 4; i++) {
			int ty = y + vy[i];
			int tx = x + vx[i];
			if(ty < 0 || tx < 0 || tx >= n || ty >= n || matrix[ty][tx] != target) continue;
			dfs(ty,tx,matrix,target);
		}
	}
}

Measured memory_bytes: 27536
#include<iostream>
#include<cstdio>
typedef long long ll;
ll a[3],k;
int main() {
    scanf("%lld%lld%lld%lld",a,a+1,a+2,&k);
    if(k&1) printf("%lld",a[1]-a[0]);
    else printf("%lld",a[0]-a[1]);
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		String[] a = str.split("");
		int[] b = new int[a.length];
		for(int i = 0;i < a.length;i++){
			b[i] = Integer.parseInt(a[i]);
		}
		
		if(b[0]+b[1]+b[2]+b[3] == 7){
			System.out.println(b[0]+"+"+b[1]+"+"+b[2]+"+"+b[3]+"=7");
		}else if(b[0]+b[1]+b[2]-b[3] == 7){
			System.out.println(b[0]+"+"+b[1]+"+"+b[2]+"-"+b[3]+"=7");
		}else if(b[0]+b[1]-b[2]+b[3] == 7){
			System.out.println(b[0]+"+"+b[1]+"-"+b[2]+"+"+b[3]+"=7");
		}else if(b[0]-b[1]+b[2]+b[3] == 7){
			System.out.println(b[0]+"-"+b[1]+"+"+b[2]+"+"+b[3]+"=7");
		}else if(b[0]-b[1]-b[2]-b[3] == 7){
			System.out.println(b[0]+"-"+b[1]+"-"+b[2]+"-"+b[3]+"=7");
		}else if(b[0]+b[1]-b[2]-b[3] == 7){
			System.out.println(b[0]+"+"+b[1]+"-"+b[2]+"-"+b[3]+"=7");
		}else if(b[0]-b[1]+b[2]-b[3] == 7){
			System.out.println(b[0]+"-"+b[1]+"+"+b[2]+"-"+b[3]+"=7");
		}else if(b[0]-b[1]-b[2]+b[3] == 7){
			System.out.println(b[0]+"-"+b[1]+"-"+b[2]+"+"+b[3]+"=7");
		}

    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  int n;
  cin >> n;
  vector<int> f(131072,0);
  REP(i,n){
    int l,r;
    cin >> l >> r;
    ++f[l];
    --f[r+1];
  }
  ++f[0];
  REP(i,131000) f[i+1]+=f[i];
  int answer=0;
  REP(i,131000) if(f[i]>=i) answer=i-1;
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 3348
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 3000050;
using namespace std;
typedef long long ll;
int main()
{
	 int a,b,c,k;
	 cin>>a>>b>>c>>k;
	 int cnt=0;
	 while(b<=a){
	 	cnt++;
	 	b<<=1;
	 }
	 while(b>=c){
	 	cnt++;
	 	c<<=1;
	 }
	 if(cnt<=k)
	 cout<<"Yes";
	 else cout<<"No";
	 return 0;
 } 

Measured memory_bytes: 3632
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

int solve(int n, int m, const std::vector<int>& terms)
{
  auto sum = std::accumulate(terms.begin(), terms.end(), 0);
  return n >= sum ? n - sum : -1;
}

int main()
{
  int n, m;
  std::cin >> n >> m;
  std::vector<int> terms(m);
  for (auto& a : terms) {
    std::cin >> a;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, m, terms) << std::endl;
}


Measured memory_bytes: 3624
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;
using namespace literals;

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int N;
  cin >> N;
  bool ans = false;
  for (int i = 1; i <= 9; ++i) {
    if (N % i != 0)continue;
    int d = N / i;
    if (1 <= d && d <= 9) {
      ans = true;
      break;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define emp emplace
#define fi first
#define se second
#define INF 0x3f3f3f3f
typedef long long ll;
typedef pair<int, int> ii;

bitset<4123456> bs;
int v[2123];

int main(void) {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;

	bs.set(0);
	int s = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		s += v[i];
		bs |= bs << v[i];
	}

	for (int i = (s+1)/2; i <= s; i++) {
		if (bs[i]) {
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}

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

int main(){
    long long n;
    cin >> n;
    vector<long long> dp(100001,0);
    for(long long i=1;i<=100000;i++){
        long long com=1000000;
        for(long long j=1;i-j>=0;j*=6) com=min(com,dp[i-j]);
        for(long long j=1;i-j>=0;j*=9) com=min(com,dp[i-j]);
        dp[i]=com+1;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

ABC = list(map(int, input().split()))

maxABC = max(ABC)
sumABC = sum(ABC)

# 常に合計は+2されていくので偶奇が変化しないことを活用する
if maxABC % 2 != sumABC % 2:
	# 偶奇が合わない時は最大値でぴったりいかないので+1
	maxABC += 1

ans = 0
ans += maxABC - ABC[0]
ans += maxABC - ABC[1]
ans += maxABC - ABC[2]

print(ans // 2)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;


signed main(){
    
    int h, w; cin >> w >> h;
    vector<vector<int>> s(h + 1, vector<int> (w + 1, 0));
    for(int i = 1; i <= h; i++) for(int j = 1; j <= w; j++) cin >> s[i][j];
    for(int i = 1; i <= h; i++) for(int j = 1; j <= w; j++) s[i][j] += s[i][j - 1];
    for(int j = 1; j <= w; j++) for(int i = 1; i <= h; i++) s[i][j] += s[i - 1][j];

    vector<vector<int>> dp(h + 1, vector<int> (w + 1, -1));
    for(int i = 0; i <= h; i++) dp[i][w] = 0;
    for(int j = 0; j <= w; j++) dp[h][j] = 0;

    for(int i = h - 1; i >= 0; i--){
        for(int j = w - 1; j >= 0; j--){
            
            int turn = (i + j) % 2;
                
            if(turn == 0){
                // 先手
                //スコアを最大化したい
                int score = max(dp[i + 1][j] + s[i + 1][w] - s[i + 1][j] - s[i][w] + s[i][j], dp[i][j + 1] - (s[h][j + 1] - s[h][j] - s[i][j + 1] + s[i][j]));
                dp[i][j] = score;
            }else{
                int score = min(dp[i + 1][j] + s[i + 1][w] - s[i + 1][j] - s[i][w] + s[i][j], dp[i][j + 1] - (s[h][j + 1] - s[h][j] - s[i][j + 1] + s[i][j]));
                dp[i][j] = score;
            }
        }
    }
    
    /*
    cout << h << " " << w << endl;
    for(int i = 0; i <= h; i++){
        for(int j = 0; j <= w; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/

    int ans = dp[0][0];
    if(ans < 0) ans = -ans;
    
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 18736
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>
// 多倍長整数型
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;

int main(){
    vector<ll> a(4);
    rep(i, 4)cin >> a[i];
    ll n;
    cin >> n;
    vector<P> ave(4);
    ll d[4] = {8, 4, 2, 1};
    rep(i, 4)ave[i] = P(a[i] * d[i], i);
    sort(ALL(ave));
    //rep(i, 4)cout << ave[i].first << " " << ave[i].second << endl;
  //return 0;
    
    if(ave[0].second == 3){
      ll res = a[3] * (n / 2);
      if(n % 2 == 0){
        cout << res << endl;
        return 0;
      }
      int b = ave[1].second;
      if(b == 0)res += (a[0] * 4);
      else if(b == 1)res += (a[1] * 2);
      else if(b == 2)res += a[2];
      cout << res << endl;
    }
    else {
      ll res = 0;
      int b = ave[0].second;
      if(b == 0)res += (a[0] * 4) * n;
      else if(b == 1)res += (a[1] * 2) * n;
      else if(b == 2)res += a[2] * n;
      cout << res << endl;
    }
}





Measured memory_bytes: 3224
from collections import deque

n, m = map(int, input().split())

graph = [[] for _ in range(n+1)]

for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

dist = [-1] * (n+1)
dist[0] = 0


d = deque()
ans = 1
for j in range(len(dist)):
    if dist[j] != -1:
        continue
    d.append(j)
    cnt = 0
    while d:
        v = d.popleft()
        for i in graph[v]:
            if dist[i] != -1:
                continue
            dist[i] = dist[v] + 1
            d.append(i)
            cnt = cnt + 1
    ans = max(ans,cnt)

print(ans)


Measured memory_bytes: 50440
def bs(array, n, v):
    l = 0
    r = n - 1
    while l <= r:
        p = (l + r) // 2
        if array[p] == v:
            return True
        elif v < array[p]:
            r = p - 1
        else:
            l = p + 1
    return False


def main():
    n = int(input())
    a = [int(i) for i in input().split()]

    input()
    b = [int(i) for i in input().split()]

    cnt = 0
    for i in b:
        if bs(a, n, i):
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()



Measured memory_bytes: 16904
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int N;
vector<long long int> V;
long long int L[105];

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> L[i];
		V.push_back(L[i]);
	}

	/*sort(V.begin(), V.end());
	V.erase(unique(V.begin(), V.end()), V.end());

	int ans = 0;
	int M = V.size();

	for (int i = 0; i < M; i++) {
		for (int j = i + 1; j < M; j++) {
			for (int k = j + 1; k < M; k++) {
				if (V[i] + V[j] > V[k]) { ans++; }
			}
		}
	}*/
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = i+1; j <= N; j++) {
			for (int k = j + 1; k <= N; k++) {
				if (L[i] == L[j]) { continue; }
				if (L[i] == L[k]) { continue; }
				if (L[k] == L[j]) { continue; }
				if (L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[j] + L[k] > L[i]) { ans++; }
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3620
<?php
$inning = trim(fgets(STDIN));

$outs = 0;
$bases = array(1 => 0, 2 => 0, 3 => 0);
$score = 0;
while ($e = trim(fgets(STDIN))) {
  switch ($e) {
    case 'HIT':
      if (!$bases[1]) $bases[1] = 1;
      elseif (!$bases[2]) $bases[2] = 1;
      elseif (!$bases[3]) $bases[3] = 1;
      else ++$score;
      break;
    case 'HOMERUN':
      $score += $bases[1] + $bases[2] + $bases[3] + 1;
      $bases[1] = $bases[2] = $bases[3] = 0;
      break;
    case 'OUT':
      ++$outs;
      if ($outs == 3) {
        echo $score ."\n";
        $outs = $score = $bases[1] = $bases[2] = $bases[3] = 0;
      }
      break;
  }
}

Measured memory_bytes: 15260
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

int main(void){
	char s[100];
	int l,i;
	chin(s);
	l=strlen(s);
	for(i=1;i<l;i++)if(s[i]!='9')break;
	if(i==l) print(s[0]-'0'+9*(l-1));
	else print(s[0]-'0'-1+9*(l-1));
	return 0;
}

Measured memory_bytes: 128
while 1:
    try:
        L = map(float, raw_input().split(','))
        sm = sum(L[:10])
        t = sm / (L[10] + L[11])
        l = t * L[10]
        i = 0
        while l > 0:
            l -= L[i]
            i += 1
        print i
    except:
        break

Measured memory_bytes: 4228
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  int n;
  cin>>n;
  ll maxA=-1e18,maxB=-1e18,minA=1e18,minB=1e18;
  for(int i=0;i<n;i++){
    ll x,y;
    cin>>x>>y;
    maxA=max(x+y,maxA);
    minA=min(x+y,minA);
    maxB=max(x-y,maxB);
    minB=min(x-y,minB);
  }
  cout<<max(maxA-minA,maxB-minB)<<endl;
  return 0;
}


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

using namespace std;

int n;
set<string> S;

int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	scanf("%d", &n);
	
	for (int i = 0; i < n; i++){
		string s;
		cin >> s;
		S.insert(s);
	}

	printf("%d\n", (int)S.size());

	return 0;
}

Measured memory_bytes: 19340
fun main(args: Array<String>) {
  val input = readLine()!!.split(" ")
  val input2 = readLine()!!.split(" ")
  val n = Integer.parseInt(input[0])
  val x = Integer.parseInt(input[1])
  var d = 0
  var i = 0
  var count = 1
  while (i < n) {
    d = d + Integer.parseInt(input2[i])
    if (d <= x) {
      count++
    } else {
	  break
    }
    i++
  }
  println(count)
}

Measured memory_bytes: 37904
N,X= map(int,input().split())
m = [int(input()) for i in range(N)]

sum = 0
for i in range(N):
   sum = sum + m[i]

min = 1001
for i in range(N):
    if (min > m[i]):
        min = m[i]

X = X - sum
N = N + X//min
print(N)

Measured memory_bytes: 3060
def knapsack(N,W,weight,value):
  #初期化
  dp=[[10**7 for i in range(W+1)] for j in range(N+1)]
  for i in range(W+1):
    dp[0][i]=i
  #DP
  for i in range(N):
    for w in range(W+1):
      if weight[i]<=w: #dp[i][w-weight[i]の状態にi番目の荷物が入る可能性がある
        dp[i+1][w]=min(dp[i+1][w-weight[i]]+value[i], dp[i][w])
      else:
        dp[i+1][w]=dp[i][w]
        
  
  return dp[N][W]

N = 12
W = int(input())
weight = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
value = [1,1,1,1,1,1,1,1,1,1,1,1,1]

a = knapsack(N,W,weight,value)

print(a)

Measured memory_bytes: 27032
import sys
I = lambda:map(int,sys.stdin.readline().split())
N = 0xfffff
n, q = I()
c = list(I())
Q = []
for i in range(q):
    l, r = I()
    Q.append(l << 40 | r << 20 | i)

Q.sort()
A = [[] for i in range(N)]
for i, x in enumerate(c):
    A[x].append(i)

B = [0] * N
def P(i, x):
    i+=1
    while i <= n:
        B[i] += x
        i += i & -i

def G(i):
    s = 0
    while i:
        s += B[i]
        i -= i & -i
    return s

for i in A:
    if i:
        P(i[0], 1)
        i.reverse()

t = 0
o = [0] * q
for x in Q:
    l = x >> 40
    r = x >> 20 & N
    i = x & N
    while t+1 < l:
        b = A[c[t]]
        P(b[-1], -1)
        b.pop()
        if b:
            P(b[-1], 1)
        t += 1
    o[i] = G(r) - G(l-1)

for i in o:
    print(i)

Measured memory_bytes: 232700
#include <algorithm>
#include <atcoder/fenwicktree.hpp>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using namespace atcoder;
using ll = long long;

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

    fenwick_tree<ll> fw(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        fw.add(i, a);
    }
    for (int i = 0; i < Q; i++) {
        int q, p, x;
        cin >> q >> p >> x;
        if (q == 0) {
            fw.add(p, x);
        } else {
            cout << fw.sum(p, x) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 8216
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#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 <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
    int n, k, x, y;

	cin >> n >> k >> x >> y;

	if (n <= k) {
		cout << n * x;
	}
	else {
		cout << k * x  + (n - k) * y;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}

int main() {
   fast();
   int n;
   cin>>n;
   int a[n];
   unordered_map<int,int> m;
   for(int i=0;i<n;i++){
    cin>>a[i];
   }
   int allgcd=a[0];
   for(int i=1;i<n;i++){
    allgcd=__gcd(a[i],allgcd);
   }
   const int N=1000001;
   vector<char> is_prime(N+1, true);
   is_prime[0] = is_prime[1] = false;
   for (int i = 2; i <= N; i++) {
    if (is_prime[i] && (long long)i * i <= N) {
        for (int j = i * i; j <= N; j += i)
            is_prime[j] = false;
    }
   }
   vector<int> c;
   for(int i=0;i<=N;i++){
       if(is_prime[i]){
           c.emplace_back(i);
       }
   }
  
   for(int i=0;i<n;i++){
       int l=a[i];
       if(is_prime[l]){
           m[l]++;
       }else{
      for(int j=0;j<(int)c.size();j++){
          if(is_prime[l]){
              m[l]++;
              break;
          }
        if(l%c[j]==0){
          m[c[j]]++;
          while(l%c[j]==0){
               l=l/c[j];
          }
        }
        if(l<c[j]){
            break;
        }
      }
       }
   }
   int g=1;
   for(auto i:m){
    if(i.second==1){
      g=1;
    }else{
      g=0;
      break;
    }
   }
   if(g){
    cout<<"pairwise coprime"<<"\n";
    return 0;
   }
   if(allgcd==1){
      cout<<"setwise coprime"<<"\n";
      return 0;
   }
   cout<<"not coprime"<<"\n";
   return 0;


   
}


Measured memory_bytes: 11600
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[1000010];int a[1000010];
int main(){
    scanf("%s",s);int n=strlen(s),i,j,sum=0,k;
    for(i=1;i<=n;i++) a[i]=(s[n-i]-'0')*9;
    for(i=1;i<=n;i++){
        a[i+1]+=a[i]/10;a[i]%=10;
    }
    if(a[n+1]) n++;
    for(i=1;i<=n;i++) sum+=a[i];
    for(k=1;k<=n*10;k++){
        a[1]+=9;sum+=9;
        j=1;
        while(j<=n){
            if(a[j]<10) break;
            sum-=10;a[j]-=10;
            sum++;a[j+1]++;
            j++;
            if(j==n&&a[j+1]) n++;
        }
        if(sum<=9*k){
            printf("%d\n",k);return 0;
        }
    }
}

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

int mp[1000000];
int w,h,t;
int dx[]={-1,0,1,0},dy[]={0,-1,0,1};

int find(int x){
 if(x==mp[x])return x;
 else{
   mp[x]=find(mp[x]);
   return mp[x];  
 }
}

void unite(int x,int y){
 x=find(x),y=find(y);
 if(x<y)swap(x,y);
 mp[x]=y; 
}

int solve(){
 int n,x,y;
 cin>>n;
 if(find(t)==0)return 0; 
 for(int i=1;i<=n;i++){
   cin>>x>>y;
   int k=y*w+x;
   if(mp[k]==-1){
     mp[k]=k;
     for(int j=0;j<4;j++){
     int nx=x+dx[j],ny=y+dy[j];
     if(nx<0||ny<0||w<=nx||h<=ny||mp[ny*w+nx]==-1)continue;
     unite(ny*w+nx,k);
   }
   if(find(t)==0)return i;
   }
 }
 return -1;
}

int main(){
 char c;
   cin>>w>>h;
   for(int i=0;i<h;i++)
     for(int j=0;j<w;j++){
   mp[i*w+j]=i*w+j;
   cin>>c;
   if(c=='#')mp[i*w+j]=-1;
   if(c=='t')t=i*w+j;
   if(c=='.'||c=='t')
     for(int k=0;k<2;k++)
       if(0<=dy[k]+i&&0<=j+dx[k]&&mp[(dy[k]+i)*w+j+dx[k]]!=-1)
         unite((dy[k]+i)*w+j+dx[k],i*w+j);
     }
   cout<<solve()<<endl;
 return 0;
}

Measured memory_bytes: 5064
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 111;
int M[MAXN];
int sum[MAXN];
vi C[MAXN];
int now[MAXN];

string solve(int n, int d) {
    memset(sum, 0, sizeof(sum));
    memset(now, 0, sizeof(now));
    int need = 0;
    for (int i = 0; i < n; i++) {
        C[i].clear();
        cin >> M[i];
        need += M[i];
        C[i].resize(M[i]);
        for (int j = 0; j < M[i]; j++) {
            cin >> C[i][j];
            sum[i] += C[i][j];
        }
        reverse(C[i].begin(), C[i].end());
    }
    for (int t = 0; t < need; t++) {
        int index = -1, mini = 1e9;
        for (int i = 0; i < n; i++) {
            if (now[i] == M[i]) continue;
            sum[i] -= C[i][now[i]];
            if ((*max_element(sum, sum+n)) - d <= sum[i] && mini > sum[i]) {
                mini = sum[i];
                index = i;
            }
            sum[i] += C[i][now[i]];
        }
        if (index == -1) return "No";
        sum[index] -= C[index][now[index]++];
    }
    return "Yes";
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, d;
    while (cin >> n >> d) {
        if (n==0 &&d==0) break;
        cout << solve(n, d) << endl;
    }
    return 0;
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	int A[N*2];
	rep(i,2*N) cin >> A[i];
	sort(A, A+N*2);
	int ans =  0;
	rep(i,N*2){
		if(i % 2 == 0) ans += A[i];
	}
	cout << ans << endl;
}

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

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

int main(){
  int A,B;
  cin>>A>>B;
  if(B%A==0)
    cout<<A+B<<endl;
  else
    cout<<B-A<<endl;


  return 0;
}


Measured memory_bytes: 256