akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
signed main(){
  int a,b;
  cin>>a>>b;
  out(max(a+a-1,max(a+b,b+b-1)));
}


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

using namespace std;

int N;

void input(){
  cin >> N;
}

int main(){
  input();
  for(int a=1;a<10;a++){
    for(int b=a;b<10;b++){
      if(a*b==N){
	cout << "Yes" << endl;
	return 0;
      }
    }
  }
  cout << "No"<< endl;
  return 0;
}


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

fn main() {
   input! {
      l: String,
   }

   let l: Vec<_> = l.as_bytes().iter().map(|&a| a == b'1').collect();
   let n = l.len();
   let mut dp1 = vec![0; n + 1];
   let mut dp2 = vec![1; n + 1];
   for (i, &b) in l.iter().enumerate() {
      dp1[i + 1] = dp1[i] * 3;
      if b {
         dp2[i + 1] = 2 * dp2[i];
         dp1[i + 1] += dp2[i];
      } else {
         dp2[i + 1] = dp2[i];
      }
      dp1[i + 1] %= MOD;
      dp2[i + 1] %= MOD;
   }
   println!("{}", (dp1[n] + dp2[n]) % MOD);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define LLI long long int
#define pii pair<int,int>
#define fst first
#define sec second
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;

LLI pwr( LLI n, LLI k)
{
    LLI ret = 1;
    for( int i=1; i<=k; i++)
    {
        ret *= n;
    }
    return ret;
}

int main()
{
    LLI i,j;
    LLI X;

    scanf("%lld", &X);
    LLI A = 0, B = 0;

    for( i=1; i<=200; i++)
    {
        for( j=-200; j<=200; j++)
        {
            if( pwr( i, 5) - pwr( j, 5) == X)
            {
                A = i;
                B = j;
            }
        }
    }

    printf("%lld %lld\n", A, B);


    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
long long choose(long long a){
  return a*(a-1)/2;
}

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
    a.at(i)--;
  }
  vector<int> count(n);
  for(int i=0;i<n;i++) count.at(a.at(i))++;
  long long tot=0;
  for(int i=0;i<n;i++) tot+=choose(count.at(i));
  for(int i=0;i<n;i++){
    long long ans=0;
    ans+=tot;
    ans-=choose(count.at(a.at(i)));
    ans+=choose(count.at(a.at(i))-1);
    cout<<ans<<endl;
  }
}
  



Measured memory_bytes: 4096
#include <stdio.h>

int main()
{
	int i, N, p[20001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(p[i]));

	int a[20001], b[20001];
	for (i = 1; i <= N; i++) {
		a[i] = ((i - 1) * 40000) + 1;
		b[i] = ((N - i) * 40000) + 1;
	}
	for (i = 1; i <= N; i++) a[p[i]] += i;
	
	printf("%d", a[1]);
	for (i = 2; i <= N; i++) printf(" %d", a[i]);
	printf("\n%d", b[1]);
	for (i = 2; i <= N; i++) printf(" %d", b[i]);
	printf("\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1932
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n,y;
	int a=-1,b=-1, c=-1;
	std::cin >> n;
	std::cin >> y;
	for (int i = 0; i <=n; i++) {
		for (int j = 0; j <= n - i; j++) {
			if (9000 * i + 4000 * j + 1000 * n == y) {
				a = i;
				b = j;
				c = n - i - j;
				break;
			}
		}
	}
	cout << a<<" " << b<<" " << c;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int a, b, c, k; scanf("%d%d%d%d", &a, &b, &c, &k);

	int cnt = 0;
	while(b <= a) {
		b <<= 1;
		cnt++;
	}
	while(c <= b) {
		c <<= 1;
		cnt++;
	}
	
	printf("%s\n", (cnt <= k ? "Yes" : "No"));
	return 0;
}


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

void insert_sort(int n,int A[]){
    for(int i=0;i<n;i++){
    int x=A[i];
    int j;
    for(j=i-1;j>=0;j--){
        if(x<A[j])A[j+1]=A[j];
        else break;
    }
    A[j+1]=x;
    for(int k=0;k<n;k++){
        if(k!=0)printf(" ");
        printf("%d",A[k]);
    }
    printf("\n");
    }
    return ;
}

int main(){
    int n;
    cin>>n;
    int A[n];
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    insert_sort(n,A);
}


Measured memory_bytes: 3208
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

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

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}

ll cnt[502][502];

int main() {
	IOS;
	int d, n;
	cin >> d >> n;
	int s = 1;
	REP(i, d)s *= 100;
	if (n == 100)cout << s * 101 << endl;
	else cout << s * n << endl;
}



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

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

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

class NODE{
public:
	int x1;
	int y1;
	int x2;
	int y2;
	int depth;
};

int conv(char c){
	switch(c){
	case '2':return 0;
	case '4':return 2;
	case '8':return 1;
	case '6':return 3;
	case '5':return 4;
	}
	cout << "aaaaaaaa" << endl;
}
int main(){
	int X,Y,tx,ty,kx,ky;
	char data[22][22];
	string cmd;
	while(cin >> Y >> X , X){
		rep(i,22)rep(j,22)data[i][j] = '+';
		rep(i,Y)rep(j,X){
			cin >> data[1+i][1+j];
			if(data[1+i][1+j] == 'A'){
				tx = 1+j;
				ty = 1+i;				
				data[1+i][1+j] = '.';
			}
			if(data[1+i][1+j] == 'B'){
				kx = 1+j;
				ky = 1+i;				
				data[1+i][1+j] = '.';
			}
			
		}
		cin >> cmd;
		queue<NODE> Q;
		NODE t = {tx,ty,kx,ky,0};
		Q.push(t);
		
		bool done[22][22][22][22][10] = {0};
		
		while(Q.size()){
			NODE q = Q.front();Q.pop();
			if( done[q.x1][q.y1][q.x2][q.y2][q.depth%cmd.size()] )continue;
			done[q.x1][q.y1][q.x2][q.y2][q.depth%cmd.size()] = true;
			
			if(q.x1 == q.x2 && q.y1 == q.y2){
				cout << q.depth << " " <<  q.y1-1 << " " << q.x1-1 << endl;
				goto end;
			}
			rep(i,5){
				NODE next;
				next.x1 = q.x1 + dx[i];
				next.y1 = q.y1 + dy[i];
				next.x2 = q.x2 + dx[ conv( cmd[q.depth%cmd.size()] ) ];
				next.y2 = q.y2 + dy[ conv( cmd[q.depth%cmd.size()] ) ];
				next.depth = q.depth + 1;
				if(data[next.y1][next.x1] != '.'){
					next.x1 = q.x1;
					next.y1 = q.y1;
				}
				if(data[next.y2][next.x2] == '+'){
					next.x2 = q.x2;
					next.y2 = q.y2;
				}
				Q.push(next);
			}
		}
		cout << "impossible" << endl;
		end:;	
	}
}

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

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

long long lcm(long long  a, long long b) {
  return a*b / gcd(a, b);
}

int main() {
  long long a; cin >> a;
  long long b; cin >> b;
  cout << lcm(a, b) << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    CAXBC solver = new CAXBC();
    solver.solve(1, in, out);
    out.close();
  }

  static class CAXBC {

    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt();
      int ans = 0;
      for (int a = 1; a <= n; ++a) {
        for (int b = 1; b * a <= n; ++b) {
          int c = n - b * a;
          if (c >= 1) {
            ++ans;
          }
        }
      }
      out.println(ans);
    }

  }

  static class InputReader {

    private InputStream stream;
    private static final int DEFAULT_BUFFER_SIZE = 1 << 16;
    private static final int EOF = -1;
    private byte[] buf = new byte[DEFAULT_BUFFER_SIZE];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (this.numChars == EOF) {
        throw new UnknownError();
      } else {
        if (this.curChar >= this.numChars) {
          this.curChar = 0;

          try {
            this.numChars = this.stream.read(this.buf);
          } catch (IOException ex) {
            throw new InputMismatchException();
          }

          if (this.numChars <= 0) {
            return EOF;
          }
        }

        return this.buf[this.curChar++];
      }
    }

    public int nextInt() {
      int c;
      for (c = this.read(); isSpaceChar(c); c = this.read()) {
      }

      byte sgn = 1;
      if (c == 45) {
        sgn = -1;
        c = this.read();
      }

      int res = 0;

      while (c >= 48 && c <= 57) {
        res *= 10;
        res += c - 48;
        c = this.read();
        if (isSpaceChar(c)) {
          return res * sgn;
        }
      }

      throw new InputMismatchException();
    }

    public static boolean isSpaceChar(int c) {
      return c == 32 || c == 10 || c == 13 || c == 9 || c == EOF;
    }

  }
}



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

#define INF 1000000000
#define LM 55555
using namespace::std;


long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int a) {
	if (a < 0) {
		return -a;
	}
	return a;
}

int A,B,C,X,Y,N, M[LM],num,v[55555],ch,ans;
string s[50], t[100];
int chx[4] = { 1,0,0,-1 };
int chy[4] = { 0,1,-1,0 };
bool a, b, c;
int main() {
	cin >> A >> B >> C >> X >> Y;
	ans = 0;
	if (A + B > 2 * C) {
		ans += 2 * C*min(X, Y);
		if (X > Y) {
			if (A < 2 * C) {
				ans += (X - Y)*A;
			}
			else {
				ans += (X - Y)*2*C;
			}
		}
		else {
			if (B < 2 * C) {
				ans += (Y - X)*B;
			}
			else {
				ans += (Y - X) * 2 * C;
			}
		}
	}
	else {
		ans = A*X + B*Y;
	}
	cout<< ans << endl;
	return 0;
}




Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;

int main(){
    int n;
    cin >> n;
    vector<float> v(n);
    rep(i,n) cin >> v[i];
    sort(v.begin(), v.end(), greater<float>());
    float a1 = 0;
    float a2 = 0;
    rep(i, n-1){
        a1 = v.back(); v.pop_back();
        a2 = v.back(); v.pop_back();
        v.push_back((a1+a2)/2);
    }
    cout << v.back() << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int isPalindrone(string chaine){
    string chaine1 = chaine;
    reverse(chaine.begin(),chaine.end()) ;
    return (chaine==chaine1);
}
int main()
{
    string name ;
    cin>>name;
    if ( isPalindrone(name) && isPalindrone(name.substr(0,(name.size()-1)/2)) && isPalindrone(name.substr((name.size()+1)/2,(name.size()-1)/2)))
        cout<<"Yes" ;
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
red = n-k
mod=10**9+7

nCk =[[0]*2005 for _ in range(2005)]
for i in range(2003):
    nCk[i][0] = 1

for i in range(1,2003):
    for j in range(1,i+1):
        nCk[i][j] = nCk[i-1][j]+nCk[i-1][j-1]

for i in range(1,k+1):
    print(nCk[k-1][i-1]*nCk[red+1][i]%mod)


Measured memory_bytes: 357604
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int d[2010][2010], e[2010][2010];
string s[2010];

int w, h, c[2010][2010], l[2010], r[2010];
int largest_rectangle() {
  int ans = max(h, w);
  VI hist(w-1,1);
  REP(i,h-1) {
    REP(j,w-1){
			if(c[i][j]==0) hist[j]++;
			else hist[j]=1;
		}
		stack<int> t;
		REP(k,w-1){
			while(!t.empty() and hist[t.top()]>= hist[k]) t.pop();
			l[k]=(!t.empty()?t.top()+1:0);
			t.push(k);
		}
		while(!t.empty()) t.pop();
	    for(int k=w-1; k>=0; --k){
			while(!t.empty() and hist[t.top()]>= hist[k]) t.pop();
			r[k]=(!t.empty()?t.top():w-1);
			t.push(k);
		}
		REP(k,w-1){
			int cur = hist[k] * (r[k] - l[k]) + hist[k];
			chmax(ans,cur);
		}
	}
  return ans;
}

signed main(void)
{
  cin >> h >> w;
  REP(i, h) cin >> s[i];
  REP(i, h) REP(j, w) {
    if(s[i][j] == '#') d[i][j] = 1;
    else d[i][j] = 0;
  }
  REP(i, h) REP(j, w-1) e[i][j] = d[i][j] ^ d[i][j+1];
  REP(i, h-1) REP(j, w-1) c[i][j] = e[i][j] ^ e[i+1][j];

  // REP(i, h-1) {
  //   REP(j, w-1) {
  //     cout << c[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  cout << largest_rectangle() << endl;

  return 0;
}


Measured memory_bytes: 51584
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    int H, W, A, B; cin >> H >> W >> A >> B;

    rep(i, H) {
        rep(j, W) {
            if (i < B) {
                if (j < A) {
                    cout << 0;
                } else {
                    cout << 1;
                }
            } else {
                if (j < A) {
                    cout << 1;
                } else {
                    cout << 0;
                }
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
local mfl = math.floor
local a, b, c, d, e, f = io.read("*n", "*n", "*n", "*n", "*n", "*n")
local alim = mfl(f / (100 * a))
local ret = {0, 100 * a}
for i_a = 0, alim do
  local rem = f - i_a * 100 * a
  local blim = mfl(rem / (100 * b))
  for i_b = 0, blim do
    local rem2 = rem - i_b * 100 * b
    local clim = mfl(rem2 / c)
    for i_c = 0, clim do
      local rem3 = rem2 - i_c * c
      local dlim = mfl(rem3 / d)
      for i_d = 0, dlim do
        local t1, t2 = i_c * c + i_d * d, (i_a * a + i_b * b) * 100 + i_c * c + i_d * d
        if (100 + e) * t1 <= t2 * e then
          if ret[1] * t2 < ret[2] * t1 then
            ret[1], ret[2] = t1, t2
          end
        end
      end
    end
  end
end
print(ret[2] .. " " .. ret[1])


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

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.reserve(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }

bool same(int x, int y) { return root(x) == root(y); }

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

int main() {
  int R;
  cin >> R;
  if (R < 1200) {
    cout << "ABC" << endl;
  } else if (R < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
}


Measured memory_bytes: 256
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
def run():
    T = int(input())
    for ii in range(T):
        N, A, B, C, D = map(int, input().split())
        stack = [(0, N)]
        min_num = float('inf')
        visited = {}
        while stack:
            money, current = heappop(stack)
            if current > N:continue
            if current in visited.keys():
                continue
            visited[current] = 0
            if current == 0:break

            for pro, cost in ((2, A), (3, B), (5, C)):
                tmp = current % pro
                next_num1 = (current - tmp)//pro
                next_num2 = (current + pro - tmp)//pro
                cond1 = N >= current + pro - tmp
                if pro == 2:
                    heappush(stack, (min(cost, D * next_num1) + tmp * D + money, next_num1))
                    if next_num2 != tmp:# and (not next_num2 % 3 or not next_num2 % 5):
                        heappush(stack, (min((2 - tmp) * D + cost + money, (next_num2 - tmp) * D + money), next_num2))
                elif pro == 3:
                    heappush(stack, (min(cost, D * (2 * next_num1))+ tmp * D + money, next_num1))
                    #if 2 * next_num2 != tmp:# and (not next_num2 % 2 or not next_num2 % 5):
                    heappush(stack, (min((3 - tmp) * D + cost + money, (2 * next_num2 - 3 + tmp) * D + money), next_num2))
                else:
                    heappush(stack, (min(cost, D * (4 * next_num1))+ tmp * D + money, next_num1))
                    #if 4 * next_num2 != tmp:# and (not next_num2 % 2 or not next_num2 % 3):
                    heappush(stack, (min((5 - tmp) * D + cost + money, (4 * next_num2 - 5 + tmp) * D + money), next_num2))

                #if next_num1 < min_num:
                #    heappush(stack, (min(cost, D * ((pro-1) * next_num1))+ tmp * D + money, next_num1))
                #if next_num2 < min_num and (pro - 1) * next_num2 != tmp and current < 5:
                #    heappush(stack, (min((pro - tmp) * D + cost + money, ((pro-1) * next_num2 - tmp) * D + money), next_num2))
        print(money)
if __name__ == "__main__":
    run()


Measured memory_bytes: 12768
N = int(input())
A = list(map(int, input().split()))
As = sorted(A)
cumax = [0]*N
ma = 0
for i, a in enumerate(A):
    cumax[i] = max(cumax[i-1], a)

ias = 0
pma = 0
ofs = 0
for i, a in enumerate(cumax):
    if a == pma:
        print(0)
        continue
    s = 0
    while ias < N and As[ias] <= a:
        s += As[ias] - ofs
        ias += 1
    s += (N-ias)*(a-ofs)
    pma = a
    ofs = a
    print(s)


Measured memory_bytes: 14516
import sys
from collections import deque
h,w,k = map(int, sys.stdin.readline().rstrip("\n").split())
sx,sy,gx,gy = map(int, sys.stdin.readline().rstrip("\n").split())
sx,sy,gx,gy = sx-1,sy-1,gx-1,gy-1
labyrinth = [line.rstrip("\n") for line in sys.stdin]
INF = float('inf')
footprint = [ [[(INF,INF)]*4 for j in range(w)] for i in range(h) ]
m = [(-1, 0), (0, 1), (1, 0), (0, -1)]
q = deque()
for d in range(4):
    footprint[sx][sy][d] = (1,0)
    q.append((sx,sy,d,1,0))
while q:
    x, y, d, c, kk = q.popleft()
    for nd in range(4):
        if nd == d:
            mx,my = m[d]
            nkk = 1 if kk == k else kk + 1
            nc = c + 1 if kk == k else c
        else:
            mx,my = 0,0
            nkk = 0
            nc = c + 1
        nx = x + mx
        ny = y + my
        if 0 <= nx < h and 0 <= ny < w and labyrinth[nx][ny] == '.' and footprint[nx][ny][nd] > (nc, nkk):
            footprint[nx][ny][nd] = (nc, nkk)
            if nc == c:
                q.appendleft((nx, ny, nd, nc, nkk))
            else:
                q.append((nx, ny, nd, nc, nkk))
ans = INF
for d in range(4):
    ans = min(ans, footprint[gx][gy][d][0])
ans = -1 if ans == INF else ans
print(ans)

Measured memory_bytes: 404112
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    string p;
    for(int i=0;i<t.length()-1;i++){
        p+=t[i];
    }
    if(p==s) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3628
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author lstd
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}



void debug_out() { cerr << endl; }

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

int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

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

using namespace std;

class BPowerSocket {
public:
	void solve(std::istream& in, std::ostream& out) {
		int a, b;
		in >> a >> b;

		int ans = 0, ts = 0;

		while(ts < b) {
			if (ts == 0)
				ts += a;
			else
				ts += (a-1);
			ans++;
		}

		out << (b == 1? 0 : ans);


	}
};

int main() {
	BPowerSocket solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
/** Author: Nicklaus **/
 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
#define PI 3.14159265358979324
int n;

int main(){
	int H,W,h,w;
	cin>>H>>W>>h>>w;
	cout<<(H*W) - ((h*W) + (H*w) - (h*w))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	int sum=0;
	FOR(i,1,1000){
		sum+=i;
		if(sum-a==sum+i+1-b){
			cout<<sum-a<<endl;
			return 0;
		}
	}
}

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

int main()
{
    int n, ac=0, wa=0, tle=0, re=0;
    cin>>n;
    while(n--)
    {
        string s;
        cin>>s;
        if(s[0]=='A') ac++;
        if(s[0]=='W') wa++;
        if(s[0]=='T') tle++;
        if(s[0]=='R') re++;
    }

    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}


Measured memory_bytes: 3576
#include<stdio.h>

int main(void){
    int n=0,m=0;
    int  answert[10000]={0};
    int answerh[10000]={0};
    int taro[101]={0};
    int taroF=0;
    int hanako[101]={0};
    int hanakoF=0;
    int count=0;
    int s=0;
    for(int i=0;i<10000;i++){
        answerh[i]=-1;
        answert[i]=-1;
    }
    while(1){
        scanf("%d %d",&n,&m);
        if(n==0&&m==0) break;
        for(int i=0;i<n;i++){
            scanf("%d",&taro[i]);
            taroF+=taro[i];
        }
        for(int i=0;i<m;i++){
            scanf("%d",&hanako[i]);
            hanakoF+=hanako[i];
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(taroF-taro[i]+hanako[j]==hanakoF-hanako[j]+taro[i]){
                    if(answert[count]+answerh[count]>taro[i]+hanako[i]&&s==1){
                        answert[count]=taro[i];
                        answerh[count]=hanako[j];
                    }
                    else if(s==0){
                        answert[count]=taro[i];
                        answerh[count]=hanako[j];
                        s=1;
                    }
                    break;
                }
            }
            
        }
        count++;
        taroF=0;
        hanakoF=0;
        s=0;
    }
    for(int i=0;i<count;i++){
        if(answert[i]==-1&&answerh[i]==-1){
            printf("-1\n");
        }
        else printf("%d %d\n",answert[i],answerh[i]);
    }
    return 0;
}


Measured memory_bytes: 2032
dp=[100000 for i in range(100001)]
dp[0]=0
l=[1]
i=6
while i<=100000:
    l.append(i)
    i*=6
i=9
while i<=100000:
    l.append(i)
    i*=9
for i in range(1,100001):
    for j in l:
        if j<=i and dp[i-j]+1<dp[i]:
            dp[i]=dp[i-j]+1
print(dp[int(input())])


Measured memory_bytes: 44912
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
long long n, ans;
map <char, int> mp;
char s[1000];
long long a[10];
int main() {
	cin >> n;
	mp['M'] = 1;
	mp['A'] = 2;
	mp['R'] = 3;
	mp['C'] = 4;
	mp['H'] = 5;
	for (int i= 1; i <= n; ++i) {
		scanf("%s", s + 1);
		if (!mp[s[1]]) continue;
		a[mp[s[1]]]++;
	}
	//for (int i = 1; i <= 5; ++i) cout << a[i];
	for (int i = 1; i <= 5; ++i) {
		for (int j =i + 1; j <= 5; ++j) {
			if (i == j) continue;
			for (int k = j + 1; k <= 5; ++k) {
				if (k == i || k == j) continue;
				ans += a[k]* a[j] * a[i];
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <climits>
#include <unordered_map>
#include <queue>


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

inline int ctoi(char c) {
    return (int)(c -'0');
}

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

int main() {
    P p1, p2, p3, p4;
    cin >> p1.first >> p1.second >> p2.first >> p2.second;

    ll d_x = p2.first - p1.first;
    ll d_y = p2.second - p1.second;

    p3.first = p2.first - d_y;
    p3.second = p2.second + d_x;

    p4.first = p3.first - d_x;
    p4.second = p3.second - d_y;

    cout << p3.first << " "
         << p3.second << " "
         << p4.first << " "
         << p4.second << endl;
    return 0;
}

Measured memory_bytes: 256
def selectionSort(A,N):
    b = 0
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if A[minj] > A[j]:
                minj = j
        A[i],A[minj] = A[minj],A[i]
        if minj != i:
            b += 1
        
    print(*A)
    print(b)

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

selectionSort(A,N)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
typedef pair<int, int> P; typedef pair<ll, ll>PLL;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<=former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
void princ(auto x){cout<<x<<" ";}; void print(auto x){cout<<x<<"\n";};
///////////////////////////////////////////////////////////////////////////////////

ll n;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll inp;
    set<ll> s;
    cin>>n;
    rep(i,n){
        cin>>inp;
        s.insert(inp);
    }
    print(s.size());
    return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;

typedef long long ll;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999

ll N,c,order[100010];

multiset<ll> s;

int main(){
  scanf("%lld",&N);
  REP(i,N){
    scanf("%lld",&c);
    order[c]=i+1;
  }
  s.insert(0);
  s.insert(0);
  s.insert(N+1);
  s.insert(N+1);
  ll x,y,z,w,sum=0,t;
  for(int i=N;i>0;i--){
    s.insert(order[i]);
    auto k=s.find(order[i]);
    x =*(++k);
    y =*(++k);
    k=s.find(order[i]);
    z=*(--k);
    w=*(--k);
    t=(y-x)*(order[i]-z)+(z-w)*(x-order[i]);
    sum+=t*i;
  }
  printf("%lld",sum);
}


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

#define ll long long
#define pii pair<int, int>
#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

using namespace std;

void solve() {
    ll N;
    cin >> N;
    
    ll ans = N * (N-1) / 2;
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import heapq

N,M=map(int,input().split())
l=list(map(int,input().split()))
h=[]
for i in range(N):
    heapq.heappush(h,10**9-l[i])

for i in range(M):
    num=10**9-heapq.heappop(h)
    num=num//2
    heapq.heappush(h,10**9-num)

print(10**9*len(h)-sum(h))

Measured memory_bytes: 14180
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
 

signed main(){

  int p,r,t;
  cin>>p>>r>>t;
  
  vector<int> LL(r);
  for(int i=0;i<r;i++) cin>>LL[i];

  vector<vector<int> > n(p,vector<int> (r));
  for(int i=0;i<p;i++)
    for(int j=0;j<r;j++) cin>>n[i][j];


  vector<int> P(t),R(t);
  for(int i=0;i<t;i++) cin>>P[i]>>R[i], P[i]--,R[i]--;
  
  
  auto deadLock=[&](int x){
    vector<int> L = LL;
    vector<queue <int> > Q(r);
    vector<vector<int> > cnt(p,vector<int> (r,0));
    
    auto ok = [&](int p){
      for(int i=0;i<r;i++) if(n[p][i] != cnt[p][i]) return 0;
      return 1;
    };

    auto freeL = [&](int p){
      for(int i=0;i<r;i++) L[i] += cnt[p][i], cnt[p][i] = 0;
    };
    
    auto use =[&](){
      int res = 0;
      for(int i=0;i<r;i++){
	if(Q[i].empty()) continue;
	if(L[i] == 0) continue;
	int process = Q[i].front(); Q[i].pop();
	L[i]--, cnt[process][i]++;
	if(!ok(process)) continue;
	freeL(process);
	res = 1;
      }
      return res;
    };
    
    for(int i=0;i<x;i++){
      int pi = P[i];
      int ri = R[i];
      Q[ri].push(pi);
      while(use());
    }
    
    auto sum=[&](int p){
      int res = 0;
      for(int i=0;i<r;i++) res += cnt[p][i];
      return res;
    };

    auto canFree=[&](int p){
      for(int i=0;i<r;i++) if(n[p][i] - cnt[p][i] > L[i]) return 0;
      return 1;
    };

    int update = 1;
    while(update){
      update = 0;
      for(int i=0;i<p;i++){ //process
	if(sum(i) == 0) {continue;}
	if(!canFree(i)) continue;
	update = 1;
	freeL(i);
	while(use());
      }
    }

    for(int i=0;i<p;i++) if(sum(i)) return 1;   
    for(int i=0;i<r;i++) if(!Q[i].empty()) return 1;
    return 0;
  };

  
  int ans = -1;
  {
    int L = 1, R = t+1;
    while(L+1<R){
      int M = (L+R)/2;
      if(deadLock(M)) R = M;
      else L = M;
    }
    ans = R;
    if(R == t+1) ans = -1;
  }

  cout<<ans<<endl;
  
  return 0;
}



Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

template <typename T>
struct BIT {
    int n;
    vector<T> data;
    BIT(int n) : n(n + 1), data(n + 1, 0) {}
    void add(int i, T x) {
        for (int j = i; j < n; j += (j & -j)) {
            data[j] += x;
        }
    }
    T sum(int i) {
        T s(0);
        for (int j = i; j > 0; j -= (j & -j)) {
            s += data[j];
        }
        return s;
    }
};

int n, q;
int c[500001];
int d[500001];  // 既に出た同じ色の球で最も右の位置（ないなら0）
vector<pair<int, int>> query;

int main() {
    cin >> n >> q;
    reps(i, n) cin >> c[i];
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        query.push_back(make_pair(r, l));
    }
    auto query_sorted = query;
    sort(all(query_sorted));
    int seen = 1;
    BIT<int> bit(n);
    map<pair<int, int>, int> ans;
    for (const auto& p : query_sorted) {
        while (p.first >= seen) {
            if (d[c[seen]] != 0) {
                bit.add(d[c[seen]], -1);
            }
            d[c[seen]] = seen;
            bit.add(d[c[seen]], 1);
            seen++;
        }
        ans[p] = bit.sum(p.first) - ((p.second != 1) ? bit.sum(p.second - 1) : 0);
    }
    rep(i, q) { cout << ans[query[i]] << endl; }
    return 0;
}

Measured memory_bytes: 48716
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	private static final String YES = "Yes";

	private static final String NO = "No";

	public static void main(String[] args) {

		int[][] arr = scan();
		System.out.println(process(arr) ? YES : NO);
	}

	private static int[][] scan() {

		Scanner sc = new Scanner(System.in);
		int[][] arr = new int[3][3];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				arr[i][j] = sc.nextInt();
			}
		}
		sc.close();
		return arr;
	}

	private static boolean process(int[][] arr) {

		Map<String, Integer> map = new HashMap<>();

		return invoke(arr, map, 0);
	}

	private static boolean invoke(int[][] arr, Map<String, Integer> map, int j) {

		String aKey = "a" + j;
		int val;
		int a;
		int b;
		String bKey;
		while (j < arr.length) {
			a = arr[0][j];
			if (map.get(aKey) == null) {
				map.put(aKey, a);
			} else {
				a = map.get(aKey);
			}
			if (a < 0) {
				return false;
			}

			for (int i = 0; i < arr.length; i++) {
				val = arr[i][j];
				bKey = "b" + i;
				b = val - a;

				if (map.get(bKey) == null) {
					map.put(bKey, b);
				} else if (b != map.get(bKey)) {
					if (j > 0) {
						map.put(aKey, map.get(aKey) - 1);
						return invoke(arr, map, j);
					}
					map.put(bKey, b);
				} else {
					b = map.get(bKey);
				}

				if (b < 0 || val != (a + b)) {
					map.put(aKey, map.get(aKey) - 1);
					return invoke(arr, map, j);
				}
			}
			return invoke(arr, map, j + 1);
		}
		return true;
	}
}

Measured memory_bytes: 21844
A,B,C = map(int,input().split())
 
counter = 0
 
while not A == B == C:
    A,B,C = sorted([A,B,C])
    if C - A > 1:
        A += 2
        counter += 1
    else:
        A += 1
        B += 1
        counter += 1
        
print(counter)

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

struct comp {
	int mod;
	comp(int x) : mod(x) {}
	bool operator()(const int& a, const int& b) const {
		return a % mod < b % mod;
	}
};

int main() {
	int n; cin >> n;
	vector<int> a(n), b(n);
	for (auto&& x : a)cin >> x;
	for (auto&& x : b)cin >> x;
	int ans = 0;
	for (int p = 0; p < 30; ++p) {
		sort(b.begin(), b.end(), comp(1 << p));

		bool btog = false;
		for (int i = 0; i < n; ++i) {
			btog ^= (b[i] >> p) & 1;
		}

		for (int i = 0; i < n; ++i) {
			int val = (1 << p) - (a[i] % (1 << p)) - 1;
			int pos = upper_bound(b.begin(), b.end(), val, comp(1 << p)) - b.begin();
			int pval = (a[i] >> p) & 1;
			bool tog = (pval ? pos & 1 : (n - pos) & 1);
			tog ^= btog;
			if (tog)ans ^= (1 << p);
		}
	}
	cout << ans << '\n';

	return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
///1<<3シフト演算子 とは　0001の1を三つずらして1000にする, これは8を表しておりつまりbitは0から7まで
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
int n,x,y;

int dist(int i, int j){
    int ans;
    ans = min(abs(i-j),min(abs(i-x)+1+abs(y-j),abs(j-x)+1+abs(y-i)));
    return ans;
}

int main(){

    cin >> n >> x >> y;
    map<int,int> k;
    for(int i = 1; i < n; i++)for(int j = i+1; j < n+1; j++){
        k[dist(i,j)]++;
    }
    for(int i = 1; i < n; i++)  cout << k[i] << endl;
    return 0;
}

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

typedef long long LL;
const int MAXN=3111;
const LL Md=1000000007;
const LL Inv2=(Md+1)/2;
LL f[MAXN][MAXN];
LL tf[MAXN][MAXN];
int n, m, a[MAXN];

int main() {
	scanf("%d%d", &n, &m);
	for(int i=1;i<=n;++i) {
		scanf("%d", &a[i]);
	}
	for(int i=1;i<=n;++i) {
		for(int j=1;j<=n;++j) {
			f[i][j]=(a[i]>a[j] ? 1 : 0);
		}
	}
	LL wgh=1;
	for(int i=1, x, y;i<=m;++i) {
		wgh=wgh*2ll%Md;
		scanf("%d%d", &x, &y);
		for(int j=1;j<=n;++j) {
			tf[x][j]=(f[y][j]*Inv2%Md+f[x][j]*Inv2%Md)%Md;
			tf[j][x]=(f[j][y]*Inv2%Md+f[j][x]*Inv2%Md)%Md;
			tf[y][j]=(f[y][j]*Inv2%Md+f[x][j]*Inv2%Md)%Md;
			tf[j][y]=(f[j][y]*Inv2%Md+f[j][x]*Inv2%Md)%Md;
		}
		tf[x][y]=(f[x][y]*Inv2%Md+f[y][x]*Inv2%Md)%Md;
		tf[y][x]=(f[y][x]*Inv2%Md+f[x][y]*Inv2%Md)%Md;
		for(int j=1;j<=n;++j) {
			f[x][j]=tf[x][j];
			f[j][x]=tf[j][x];
			f[y][j]=tf[y][j];
			f[j][y]=tf[j][y];
		}
	}
	LL ans=0;
	for(int i=1;i<=n;++i) {
		for(int j=i+1;j<=n;++j) {
			ans=(ans+f[i][j])%Md;
		}
	}
	ans=ans*wgh%Md;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 149760
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    int n;
    cin >> n;

    vec<int> v(n);
    for (auto &e : v)
    {
        cin >> e;
    }

    map<int, int> odd, even;
    for (int i = 0; i < n; ++i)
    {
        if (i % 2 == 0)
        {
            even[v[i]]++;
        }
        else
        {
            odd[v[i]]++;
        }
    }

    auto calc = [](int size, map<int, int> &m) {
        int ret = 1000000000;
        int key = 0;
        for (auto e : m)
        {
            if (ret >= size - e.second)
            {
                key = e.first;
                ret = size - e.second;
            }
        }

        m[key] = 0;
        return make_pair(key, ret);
    };

    vec<pair<int, int>> o, e;
    o.push_back(calc(n / 2, odd));
    o.push_back(calc(n / 2, odd));
    e.push_back(calc(n / 2, even));
    e.push_back(calc(n / 2, even));

    int ans = 1000000000;
    if (o[0].first == e[0].first)
    {
        ans = min({o[0].second + e[1].second, o[1].second + e[0].second});
    }
    else
    {
        ans = o[0].second + e[0].second;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5376