akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define foru(i,a,b) for ( int i= int(a);i<=int(b); i++)
using namespace std;
string s;
char a[1000005];
int b[1000005];

int main(){
    ios_base::sync_with_stdio(0);
    //freopen("jjooii.inp","r",stdin);
    //freopen("jjooii.out","w",stdout);
    cin >> s;
    s='a'+s;
    s=s+'a';
    //foru(i, 0, 1000000) a = s[i] + a;
    //cout << a << endl'
    int luu,n,res;
    res=0;
    luu=1;n=0;
    foru(i,1,s.size()-1)
        if (s[i]!=s[i-1]) {
            //a=a+s[i];
            n++;
            a[n]=s[i];
            b[n-1]=luu;
            luu=1;
        } else luu++;
    //cout<<a<<endl;
    foru(i,3,n)
        if (a[i]=='I' && a[i-1]=='O' && a[i-2]=='J' && b[i]>=b[i-1] && b[i-2]>=b[i-1]) res=max(res,b[i-1]);
    cout << res << endl;
    return 0;
}

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

using namespace std;
typedef long long int ll;
ll N1097 = 1000000007LL;

ll dp[101][100001];
int main(){
    int N, W;
    cin >> N >> W;
    int w[101], v[101];
    for(int i=1;i<=N;i++){
        scanf("%d", &w[i]);
        scanf("%d", &v[i]);
    }
    for(int h=0;h<=W;h++){
        for(int i=1;i<=N;i++){
            dp[i][h] = dp[i-1][h];
            if(h-w[i]>=0){
                dp[i][h] = max(dp[i][h], dp[i-1][h-w[i]]+v[i]);
            }
        }
    }
    cout << dp[N][W] << endl;
}




Measured memory_bytes: 78336
#include <iostream>
#include <iostream>
#include <string>
#include <vector>

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

int main(){
    int a, b, c;
    int flag_five = 0, flag_seven = 0;

    // 入力
    std::cin >> a >> b >> c;

    if(a == 5) flag_five++;
    else if(a == 7) flag_seven++;

    if(b == 5) flag_five++;
    else if(b == 7) flag_seven++;
    
    if(c == 5) flag_five++;
    else if(c == 7) flag_seven++;
    

    if((flag_five == 2)&&(flag_seven == 1)) std::cout << "YES" << std::endl;
    else std::cout << "NO" << std::endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
using namespace std;

string S;
long long K;


int main() {
	cin >> S;
	cin >> K;
	int ans = 1;

	for (int i = 0; i < K; i++) {
		if (S[i]-'0' != 1) {
			ans = S[i]-'0';
			break;
		}
	}

	cout << ans << endl;
}

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


int main(){
  int n,m;
  cin>>n>>m;
  vector<int> ac(n),pena(n);
  for(int i=0;i<m;i++){
    int num;
    string str;
    cin>>num>>str;
    --num;
    if(ac[num]) continue;
    if(str=="AC"){
      ac[num] =1;
    }else {
      pena[num]++;
    }
  }
  int AC=0,PENA=0;
  for(int i=0;i<n;i++){
    AC+=ac[i];
    if(ac[i]) PENA+=pena[i];
  }
  printf("%d %d\n",AC, PENA);
  return 0;
}
  
    
  
  
  
  
  


Measured memory_bytes: 1024
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#define inf 2147483647
#define eps 1e-9
using namespace std;
typedef long long ll;
int n,tot,a[800001];
char s[500001];
void mul(int a[],int &n,int k){
    int p=0;
    tot=0;
    for(int i=1;i<=n;i++){
        p=a[i]*k+p;
        a[i]=p%10;
        tot+=a[i];
        p/=10;
    }
    if(p)a[++n]=p;
    tot+=p;
}
void add(int a[],int &n,int k){
    int p=0;
    tot-=a[1];
    a[1]+=k;
    p=a[1]/10;
    a[1]%=10;
    tot+=a[1];
    for(int i=2;i<=n;i++){
        tot-=a[i];
        a[i]+=p;
        p=a[i]/10;
        a[i]%=10;
        tot+=a[i];
        if(!p)break;
    }
    if(p)a[++n]=p;
    tot+=p;
}
int main(){
    scanf("%s",s);
    n=strlen(s);
    for(int i=1;i<=n;i++){
        a[i]=s[n-i]-'0';
    }
    mul(a,n,9);
    for(int i=1;i<=n;i++){
        add(a,n,9);
        if(tot%9==0&&i*9>=tot)return printf("%d",i),0;
    }
    return 0;
}

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

int main(){
	vector<int> v;
	for(int i = 0; i < 10; i++){
		int input;
		cin >> input;
		v.push_back(input);
	}

	sort(v.begin(), v.end(), greater<int>());

	cout << v.at(0) << endl << v.at(1) << endl << v.at(2) << endl;

	return 0;
}

Measured memory_bytes: 1216
S = input().strip()
N = len(S)
K = int(input())
dp = [[0]*(K+1) for _ in range(N+1)]
dp2 = [[0]*(K+1) for _ in range(N+1)]
dp[0][K] = 1
dp2[0][K] = 1
for i in range(N):
    for j in range(K+1):
        dp[i+1][j] = dp[i][j]
        if j != K: dp[i+1][j] += dp[i][j+1] * 9
    dd = int(S[N-i-1])
    for j in range(K+1):
        if dd == 0:
            dp2[i+1][j] = dp2[i][j]
        else:
            if j != K:
                dp2[i+1][j] = dp[i][j] + dp[i][j+1]*(dd-1) + dp2[i][j+1]
            else:
                dp2[i+1][j] = dp[i][j]
print(dp2[N][0])


Measured memory_bytes: 38256
#include <iostream>
using namespace std;
int main(void){
    int H, W;
    while(true){
        cin >> H >> W;
        if(H == 0 && W == 0){
            break;
        }
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3096
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;
	if (N >= K) cout << K * X + (N - K) * Y << endl;
	else cout << X * N << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a,b;
    vector<vector<int>> adj(m+1);
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        if(a<=m)
            adj[a].push_back(b);
    }
    priority_queue<int> q;
    for(int i=1;i<=m;i++)
    {
        sort(adj[i].rbegin(),adj[i].rend());
    }
    long int ans=0;
    for(int i=1;i<=m;i++)
    {
        for(int j=0;j<min(m,(int)adj[i].size());j++)
        {
            q.push(adj[i][j]);
        }
        if(!q.empty())
        {
            ans+=q.top();
            q.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5632
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

signed main(){
	char s[4];
	cin >> s;
	
	sort(s,s+4);
	
	if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) cout << "Yes" << endl;
	else cout << "No" << endl;
	
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    ll a;
    double b;
    cin >> a >> b;
    ll c = round(100*b);
    cout << a*c/100 << endl; 
    return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n;
	cin>>n;
	vector<int>p(n);
	rep(i,n)cin>>p[i];
	int ans=0;
	repi(i,1,n-1){
		int max_ = max(max(p[i-1],p[i]),p[i+1]);
		int min_ = min(min(p[i-1],p[i]),p[i+1]);
		if(p[i]==min_||p[i]==max_)continue;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
  return modpow(a, mod - 2, mod);
}

int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > A(N);
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
  }
  std::vector<int > prime(1000004, 0);
  prime[0]=1;
  prime[0]=1;
  for (int i=2; i<1000004; i++){
    if (prime[i]==0){
      prime[i]=i;
      for (int j=2*i; j<1000004; j+=i){
	if (prime[j]==0){
	  prime[j]=i;
	}
      }
    }
  }
  
  std::map<int, int > mp;
  for (int i=0; i<N; i++){
    int a=A[i];
    std::map<int, int > tmp;
    while(a!=1){
      tmp[prime[a]]++;
      mp[prime[a]]=std::max(mp[prime[a]], tmp[prime[a]]);
      a /= prime[a];
    }
  }
  long long sum = 1;
  long long mod = 1e9+7;
  for (auto &entry: mp){
    for (int i=0; i<entry.second; i++){
      sum *= entry.first;
      sum %= mod;
    }
  }
  long long ans = 0;
  long long temp;
  for (int i=0; i<N; i++){
    temp = sum;
    temp *= modinv((long long)A[i], mod);
    temp %= mod;
    ans += temp;
    ans %= mod;
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c[200001];
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>c[i];
  }
  sort(c,c+a);
  for(int i=0;i<a-1;i++){
    if(c[i]==c[i+1]){
      cout<<"NO"<<endl;
      return(0);
    }

  }
  cout<<"YES"<<endl;
  return(0);
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
	int A, B, C, D, E, K;
	cin >> A >> B >> C >> D >> E >> K;
	
	if(E - A <= K) {
    	cout << "Yay!" << endl;
    }else {
    	cout << ":(" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
main()
{
  int w, h, n;
  cin >> w >> h >> n;
  int x, y, a, g, j, k, l;
  g = j = 0;
  k = w;
  l = h;
  for (int i = 0;i<n;i++){
    cin >> x >> y >> a;
    if(a==1&&g<x)
      g = x;
      else if(a==2&&k>x)
        k = x;
        else if(a==3&&j<y)
          j = y;
          else if(a==4&&l>y)
            l = y;
  }
  if(g>=k||j>=l)
    cout << 0 << endl;
    else
      cout << (k - g)*(l - j) << endl;
}


Measured memory_bytes: 256
from collections import deque
h, w = map(int, input().split())
a = ['#' * (w+2)] + ['#' + input() + '#' for i in range(h)] + ['#' * (w+2)]
for i in range(h+2):
    a[i] = list(a[i])

d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
x = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if a[i][j] == '#':
            x.append((i, j))

ans = 0
while x:
    y = []
    for i, j in x:
        for di, dj in d:
            if a[i+di][j+dj] == '.':
                a[i+di][j+dj] = '#'
                y.append((i+di, j+dj))
    x = y
    ans += 1
    # for i in range(h+2):
    #     print("".join(a[i]))
    # print()

ans -= 1
print(ans)


Measured memory_bytes: 131756
def c_many_medians(N, X):
    Y = sorted(X)
    ans = []
    for xi in X:  # 数列から除く要素を選定
        # 中央値の候補はYの N//2 - 1 番目または N//2 番目
        # 除かれた要素がYの N//2 番目より小さければ中央値は N//2 番目
        # (Yにおけるxiより"右"の要素がすべて"左"に1つずれるため)
        # そうでなければ中央値は N//2 - 1 番目
        # (Yにおけるxiより右の要素が左にずれても中央値の要素番号に影響しない)
        pos = N // 2 if xi < Y[N // 2] else (N // 2) - 1
        ans.append(str(Y[pos]))
    return '\n'.join(ans)

N = int(input())
X = [int(i) for i in input().split()]
print(c_many_medians(N, X))


Measured memory_bytes: 31764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int i = 0; 
  while(i < N){
    string col;
    cin >> col;
    
    if(col == "Y"){
      cout << "Four" << endl;
        break;
    }
    else if(i == N - 1){
       cout << "Three" << endl;
    }
   
 
    
    i ++;
  }
  
}

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

int main(){
    int a,b,m;
    cin >> a >> b >> m;
    vector<int> aa(a),bb(b);
    for(int i = 0; i < a; i++)
    cin >> aa[i];
    for(int i = 0; i < b; i++)
    cin >> bb[i];
    vector<int> x(m),y(m),c(m);
    for(int i = 0; i <m; i++)
    cin >> x[i] >> y[i] >> c[i];

int ans = 10000000;
    for(int i = 0; i < m; i++){
        ans = min(ans,aa[x[i] - 1] + bb[y[i] - 1] - c[i]);
    }
    sort(aa.begin(),aa.end());
    sort(bb.begin(),bb.end());
    ans = min(ans,aa[0] + bb[0]);
    cout << ans << endl;
}

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

int main(){
  long long a,b,c,k;
  cin>>a>>b>>c>>k;
  long long ans=0;
  if(a>=k) ans=k;
  else if(a+b>=k) ans=a;
  else ans=a-(k-a-b);
  cout<<ans<<endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;

int main()
{
    int a[5];
    int n=3;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int ans=INT_MAX;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            ans=min(ans,a[i]+a[j]);
        }
    }
    cout<<ans<<endl;
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
void W(int line[],int temp[]){
    line[0]=temp[2];
    line[3]=temp[0];
    line[5]=temp[3];
    line[2]=temp[5];
}
void S(int line[],int temp[]){
    line[1]=temp[0];
    line[5]=temp[1];
    line[4]=temp[5];
    line[0]=temp[4];
}
void E(int line[],int temp[]){
    line[2]=temp[0];
    line[5]=temp[2];
    line[3]=temp[5];
    line[0]=temp[3];
}
void N(int line[],int temp[]){
    line[1]=temp[5];
    line[0]=temp[1];
    line[4]=temp[0];
    line[5]=temp[4];
}
int main(void){
    int line[6],i,t,temp[6];
    char ope[101];
    for(i=0;i<6;i++)
        scanf("%d",&line[i]);
    scanf("%s",ope);
    t=0;
    while(ope[t]){
        for(i=0;i<6;i++)
            temp[i]=line[i];
        if(ope[t]=='W')
            W(line,temp);
        else if(ope[t]=='S')
            S(line,temp);
        else if(ope[t]=='E')
            E(line,temp);
        else
            N(line,temp);
        t++;
    }
    printf("%d\n",line[0]);
    return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll=long long;
using P = pair<int,int>;
int main(){
    int D,T,S;
    cin >> D >> T >> S;
    if(T*S>=D)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a > k){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int a, b;
  cin >> a >> b;
  if (a == 1) a = 100;
  if (b == 1) b = 100;

  cout << (a == b ? "Draw" : (a > b ? "Alice" : "Bob")) << endl;
}


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

using namespace std;

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

int main() {
	for (int a, b; cin >> a >> b;) {
		cout << GCD(a, b) << " " << LCM(a, b) << endl;
	}
	return 0;
}


Measured memory_bytes: 3068
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 0
if a[0] != 0:
    ans = -1
elif n == 1:
    ans = 0
else:
    b = a[1:]
    for k,i in enumerate(b):
        if i <= 1:
            ans += i
        else:
            num = i-a[k]
            if num == 1:
                ans += 1
            elif num <= 0:
                ans += i
            else:
                ans = -1
                break
print(ans)

Measured memory_bytes: 12584
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        System.out.println(n[2] / n[0] * n[1]);
    }

}


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

int main(){
  int N;
  
  cin >> N;
  vector<string> S(N);
  for(int i = 0;i < N;i++) cin >> S.at(i);
  
  sort(S.begin(), S.end());
  
  int cnt = 1, cnt_max = -1;
  for(int i = 1;i < N;i++){
    if(S.at(i-1) == S.at(i)) cnt++;
    else{
      cnt_max = max(cnt_max, cnt);
      cnt = 1;
    }
  }
  cnt_max = max(cnt_max, cnt);
  cnt = 1;
  for(int i = 1;i < N;i++){
    if(S.at(i-1) == S.at(i)) cnt++;
    else{
      if(cnt == cnt_max) cout << S.at(i-1) << endl;
      cnt = 1;
    }
  }
  if(cnt == cnt_max) cout << S.at(N-1) << endl;
  
  return 0;
}

Measured memory_bytes: 9572
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long sum =0;
		long N = sc.nextLong();
		for (int i=1;i<=N;i++) {
			if (i%3!=0&&i%5!=0) {
				sum +=i;
			}
		}
		System.out.println(sum);
  	}
}

Measured memory_bytes: 35872
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1e9+7;

int main(){
    int n;
    cin>>n;
    int a[100101];
    int cnt2=0;int cnt4=0;
    rep(i,0,n){
        cin>>a[i];
        if(a[i]%4==0)cnt4++;
        else if(a[i]%2==0)cnt2++;
    }
    int x=n-2*cnt4-1;
    bool can=false;
    if(n/2<=cnt4)can=true;
    else if(x<cnt2 && 2<=cnt2)can=true;
    if(can)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> T& chmin(T &a, const U &b){return a = (a<=b?a:b);}
template <typename T, typename U> T& chmax(T &a, const U &b){return a = (a>=b?a:b);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

const LLI mod = 1e9+7;

LLI dp[300][101000];

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

  int N,X;
  while(cin >> N >> X){
    vector<LLI> S(N); cin >> S;

    sort(ALL(S));
    reverse(ALL(S));

    fill_array(dp,0);

    dp[0][X] = 1;

    REP(i,N){
      FORE(j,0,X){
	(dp[i+1][j%S[i]] += dp[i][j]) %= mod;
	(dp[i+1][j] += dp[i][j]*(N-i-1)%mod) %= mod;
      }
    }

    LLI ans = 0;

    FORE(i,0,X) (ans += i*dp[N][i]) %= mod;
    
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 236928
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 20;
ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

char in[20];
int main() {
	scanf("%s", in);
	printf("2018%s\n", in + 4);
	return 0;
}
//*/

Measured memory_bytes: 256
n = gets.to_i
n.times{
    result = "NA"
    snake = gets.chomp
    case snake
    when /^>'=+#=+~/
        left, right = snake.split("#")
        result = "A" if left.count("=") == right.count("=")
    when /^>\^(Q=)+~~$/
        result = "B"
    end
    puts result
}

Measured memory_bytes: 8912
// nlather (Nishant Raj Lather)
// Chrollo_Lucifer

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define rep(i, x, n) for(ll i = x; i < n; i++)
#define rrep(i, x, n) for(ll i = x; i >= n; i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define e emplace
#define mp make_pair
#define debug(this) cout<<"> "<<#this<<" : "<<this<<"\n"
typedef long long int ll;
typedef long double ld;
typedef pair< ll, ll > pii;
typedef vector< ll > vi;
typedef vector< vi > vvi;
const ll MOD = 1e9+7;
ld PI=3.1415926535897932384626;
ld EPS = 1e-9;
#define endl '\n'

int main() {
	boost;
	ll n, a ,b;
	cin >> n >> a >> b;
	cout << min(n * a, b);
}
























Measured memory_bytes: 764
N=int(input())
A=list(map(int,input().split()))
flag=0
for i in range(N):
  if A[i]%2==0:
    if A[i]%3==0 or A[i]%5==0:
      flag=0
    else:
      flag=1
      break
      
if flag==0:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int n=0;
int st[4]={};
double dp[305][305][305]={};
 
double solve(int a, int b, int c){
	if(a+b+c == 0) return 0.0;
	
	if(dp[a][b][c] != -1)
		return dp[a][b][c];
		
	// probability of select dish having sushi
	double ks = (double)n/(a+b+c);
	double ans=0;
	if(a) {
			   // require draw dice * prob of select a, (a=no of dish having a sushi) 
		ans += ( solve(a-1, b, c) + ks ) * a/(a+b+c);
	}
	
	if(b) {
			   // require draw dice * prob of select a, (a=no of dish having a sushi) 
			   // a+1 remove 2's sushi do become 1
		ans += ( solve(a+1, b-1, c) + ks ) * b/(a+b+c);
	}
	
	if(c) {
			   // require draw dice * prob of select a, (a=no of dish having a sushi) 
		ans += ( solve(a, b+1, c-1) + ks ) * c/(a+b+c);
	}
	
	return dp[a][b][c] = ans;
}
 
void solve(){
	cin >> n;
	int x;
	for(int i=0; i<n; i++) {
		cin >> x;
		st[x]++;
	}
	
	for(int i=0; i<=n; i++)
		for(int j=0; j<=n; j++)
			for(int k=0; k<=n; k++)
				dp[i][j][k]=-1;
	
	double ans = solve(st[1], st[2], st[3]);	
	cout << setprecision(12) << fixed << ans << "\n";
}
 
int main(){
	solve();
}


Measured memory_bytes: 220876
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int V = I[0], E = I[1];
		var es = new int[E][];
		for (var i = 0; i < E; i++) es[i] = G;
		var uf = new UnionFindTree(V);
		var ans = new long[E];
		var sum = V * (V - 1L) / 2;
		for (var i = E - 1; i >= 0; i--)
		{
			ans[i] = sum;
			int u = es[i][0] - 1, v = es[i][1] - 1;
			if (!uf.IsSameCategory(u,v))
			{
				sum -= uf.GetSize(u) * (long)uf.GetSize(v);
				uf.UniteCategory(u, v);
			}
		}
		for (var i = 0; i < E; i++) WriteLine(ans[i]);
	}
}
class UnionFindTree
{
	int N;
	int[] parent, rank, size;
	public UnionFindTree(int capacity)
	{
		N = capacity;
		parent = new int[N];
		rank = new int[N];
		size = new int[N];
		for (var i = 0; i < N; i++) { parent[i] = i; size[i] = 1; }
	}
	public int GetSize(int x) => size[GetRootOf(x)];
	public int GetRootOf(int x) => parent[x] == x ? x : parent[x] = GetRootOf(parent[x]);
	public bool UniteCategory(int x, int y)
	{
		if ((x = GetRootOf(x)) == (y = GetRootOf(y))) return false;
		if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; }
		else
		{
			parent[y] = x; size[x] += size[y];
			if (rank[x] == rank[y]) rank[x]++;
		}
		return true;
	}
	public bool IsSameCategory(int x, int y) => GetRootOf(x) == GetRootOf(y);
}


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


int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(auto &i:a)cin >> i;
	
	vector<int> b(100001),c(100001);
	for(int i = 0;i<n;i++)
	{
		//cout<<a[i]<<endl
		if(i&1)b[a[i]]++;
		else c[a[i]]++;
	}
	//sort(b.begin(),b.end(),greater<>());
	//sort(c.begin(),c.end(),greater<>());
	vector<pair<int,int>> B,C;
	int b1=0,b2=0,c1=0,c2=0;
	int bb=-1,bb2=-1,cc=-1,cc2=-1;
	for(int i =0 ;i<100001;i++)
	{
		if(b[i])
		{
			B.emplace_back(b[i],i);
		}
		if(c[i])
		{
			C.emplace_back(c[i],i);
		}
	}
	//cout<<c[105]<<' '<<b[105]<<endl;
	sort(B.rbegin(),B.rend());
	sort(C.rbegin(),C.rend());
	b1 = B[0].first;bb = B[0].second;
	c1 = C[0].first;cc = C[0].second;
	if(B.size()>1)
	{
		b2 = B[1].first;bb2 = B[1].second;
	}
	if(C.size()>1)
	{
		c2 = C[1].first;cc2 = C[1].second;
	}

	if(bb==cc)
	{
		if(c1>b1)
		{
			cout<<n-c1-b2<<endl;
		}
		else if(c1<b1)
		{
			cout<<n-b1-c2<<endl;
		}
		else if(c2>b2)
		{
			cout<<n-c2-b1<<endl;
		}
		else if(c2<b2)
		{
			cout<<n-b2-c1<<endl;
		}
		else
		{
			//cout<<c2<<endl;
			cout<<n-b1-c2<<endl;
		}
	}
	else 
	{
		//cout<<';'<<endl;
		cout<<n-b1-c1<<endl;
	}
}

Measured memory_bytes: 2428
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().solveA();
		//		new Main().solveB();
		//		new Main().solveC();
		//		new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int a = 0;
		int b = 0;

		try {
			scanner = new Scanner(System.in);
			a = scanner.nextInt();
			b = scanner.nextInt();
			if (a > 8 || b > 8) {
				System.out.println(":(");
			} else {
				System.out.println("Yay!");
			}
		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();
			lineBC = scanner.nextInt();
			lineCA = scanner.nextInt();

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();
			lineBC = scanner.nextInt();
			lineCA = scanner.nextInt();

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();
			lineBC = scanner.nextInt();
			lineCA = scanner.nextInt();

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 21716
import math
def divisor(x):
    div=[]
    for i in range(1,int(x**(1/2))+1):
        if x%i==0:
            div.append(i)
            if i!=x//i:
                div.append(x//i)
    return sorted(div)

N=int(input())
aa=divisor(N)
bb=[]
for i in range(math.ceil(len(aa)/2)):
    bb.append(aa[i]**2+aa[len(aa)-i-1]**2)
m=bb.index(min(bb))
n=aa[m]-1
r=aa[len(aa)-1-m]-1
print(n+r)

Measured memory_bytes: 3380
#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>
#include <iomanip> 

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;
typedef tuple<int,int,int> iii;

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

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}


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

//#############################
const int MAXN = 1000005;
ll memo[MAXN][2], n;
vector<int> digits;

ll dp(int i, bool flag) {
    if (i >= n)
        return 0;

    if (memo[i][flag] != -1)
        return memo[i][flag];
    
    ll a, b;

    // no change expected
    if (flag == 1)
        a = digits[i] + min(dp(i+1, 1), dp(i+1, 0));


    // giving a bigger banknote
    if (flag == 0)
        b = 1 + (10 - digits[i]) + min(dp(i+1,1), max((ll)0, dp(i+1, 0)-2));

    return memo[i][flag] = (flag ? a : b);
}

int main() {
    fastIO();
    string s;
    cin >> s;

    digits = vector<int>(s.size());
    n = s.size();
    REP(i,s.size())
        digits[i] = s[i] - '0';
    memset(memo, -1, sizeof(memo));

    ll ans = min(dp(0,0), dp(0,1));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 67740
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<bitset>

using namespace std;

int main()
{
	int n,m;
	cin >> n >> m;
	vector<int> k(m);
	vector<vector<int> > s(m);
	
	for(int i=0;i<m;i++)
	{
		cin >> k[i];
		s[i]=vector<int>(k[i]);
		for(int j=0;j<k[i];j++)
			cin >> s[i][j];
	}
	vector<int> p(m);
	for(int i=0;i<m;i++)
		cin >> p[i];


	int ans=0;

	for(int x=0;x<=((1<<(n))-1);x++)
	{
//	cout << bitset<10>(x) << endl;
		bool flag=true;
		for(int i=0;i<m;i++)
		{
			int a=0;
			for(int j=0;j<s[i].size();j++)
			{
				a^=(x>>(s[i][j]-1));
//				cout << i << " " << j << " ";
//				cout << bitset<10>(a) << endl;
			}
			if(a%2!=p[i])flag=false;
		}
		if(flag)ans++;
			
	}

	cout << ans << endl;

}


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()
A = LIST()

M = max(A+[K]).bit_length()

bitcnt = [0] * M
for a in A:
    # ビット毎に立っている数を数える
    i = 0
    while (a>>i) > 0:
        bitcnt[i] += a >> i & 1
        i += 1

dp = list2d(M+1, 2, -INF)
dp[M][0] = 0
for i in range(M-1, -1, -1):
    bit = 1 << i
    for j in range(2):
        # 今回のビットを立てない
        if j == 0:
            # Kが立っていれば、今回でsmaller確定する
            if bit & K:
                dp[i][1] = max(dp[i][1], dp[i+1][0] + bit*bitcnt[i])
            else:
                dp[i][0] = max(dp[i][0], dp[i+1][0] + bit*bitcnt[i])
            dp[i][1] = max(dp[i][1], dp[i+1][1] + bit*bitcnt[i])
        # 今回のビットを立てる
        else:
            # まだsmaller確定前なら、Kも立っている場合のみ遷移できる
            if bit & K:
                dp[i][0] = max(dp[i][0], dp[i+1][0] + bit*(N-bitcnt[i]))
            dp[i][1] = max(dp[i][1], dp[i+1][1] + bit*(N-bitcnt[i]))
print(max(dp[0][0], dp[0][1]))


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

vector<int> A(3);

int main() {
  int a = 0;
  
  for(int i = 0; i < 3; i++) {
    cin >> A.at(i);
    
    a += A.at(i);
  }
  
  if(a >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
}

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

int main(){
    int N;
    std::string C;
    std::cin >> N >> C;
    
    int left = 0;
    int right = N - 1;
    int cnt = 0;
    while(left < right){
        if(C[left] != 'W'){
            left++;
        }else if(C[right] != 'R'){
            right--;
        }else{
            left++;
            right--;
            cnt++;
        }
    }
    
    std::cout << cnt << std::endl;
    
    return 0;
}



Measured memory_bytes: 3712
from collections import deque

R,C=list(map(int,input().split()))
ans=[[0 for _ in range(C+2)] for _ in range(R+2)]
wall,flag = 0,False

maze=[['#']*(C+2)]+[list("#"+input()+"#") for _ in range(R)]+[['#']*(C+2)]

for i in range(R+2):
  wall += maze[i].count('#')
wall = wall - ((R+2)*(C+2)-R*C)

vector=[(1,0),(0,1),(-1,0),(0,-1)]
road=deque()
road.append([1,1])

while road:
  ny,nx=road.popleft()
  for i,j in vector:
    my,mx=ny+i,nx+j
    if not ans[my][mx] and maze[my][mx] == ".":
      ans[my][mx] = ans[ny][nx]+1
      road.append([my,mx])
      if my == R and mx == C:
        root=ans[my][mx]+1
        print(R*C-wall-root)
        exit()
        
if not flag:
  print("-1")

Measured memory_bytes: 3316
'''
Created on 2019/09/23

@author: oiwaiman
'''


import numpy as np

n = int(input())
aaa = np.fromiter(list(map(int, input().split())), np.int64)

all_x = np.bitwise_xor.reduce(aaa)

mask = ~all_x
bbb = aaa & mask

ans = 0
while True:
    a = bbb.max()
    if a == 0:
        break
    b = 1<<(int(a).bit_length() -1)
    bbb[bbb & b > 0] ^= a
    if ans & b == 0:
        ans ^= a


print (ans*2 + all_x)

Measured memory_bytes: 24268
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int Q;
int main(){
    //エラトステネスの篩
    int MAXX = 101010;
    vector<int> is_prime(MAXX,1);
    is_prime[0] = 0; is_prime[1] = 0;
    for(int i = 2; i < MAXX; i++){
        if(!is_prime[i]) continue;
        for(int j = i*2; j < MAXX; j += i) is_prime[j] = 0;
    }
    //2017-like
    vector<int> a(MAXX,0);
    for(int i = 0; i < MAXX; i++){
        if(i % 2 == 0) continue;
        if(is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }
    //累積和
    vector<int> s(MAXX,0);
    for(int i = 0; i < MAXX; i++) s[i+1] = s[i]+a[i];
    //クエリ
    cin >> Q;
    for(int q = 0; q < Q; q++){
        int l,r; cin >> l >> r;
        r++;
        cout << s[r] - s[l] << endl;
    }
}




Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
    int a[10]={0};
    int n,k,ans=0,flag=0,x;
    scanf("%d %d",&n,&k);

    for(int i=0;i<k;i++)
    {
        scanf("%d",&x);
        a[x]++;
    }
    for(int i=n;i<1000000;i++)
    {
        int t=i;
        flag=0;
        while(t)
        {
            int p=t%10;
            if(a[p]!=0)
            {
                flag=1;
                break;
            }
            t/=10;
        }
        if(flag==1)
            continue;
        else{
            ans=i;
            break;
        }
    }
    printf("%d\n",ans);

}


Measured memory_bytes: 3804
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 + 7


def main():
    ans = 0
    cs = np.cumsum(np.array(a))
    for i in range(n-1):
        s = (cs[-1] - cs[i]) % mod
        ans = (ans+(a[i]*int(s)) % mod) % mod
    return ans


n, *a = map(int, read().split())
a = main()
print(a)


Measured memory_bytes: 45968
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
// #define all(x) (x).begin(),(x).end()
// #pragma GCC optimize ("-O3")
// using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
// typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
// template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
// template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using namespace std;

struct Edge {
    int to;
    int len;
    Edge(int t, int l) : to(t), len(l) { }
};
using Graph = vector<vector<Edge>>;


vector<int> color;
bool dfs(Graph &G,int v,int cur=0)
{
  color[v]=cur;
  //cout<<"color["<<v<<"]:"<<color[v]<<endl;
  
  fore(next_v,G[v]){
    //cout<<"v:"<<v<<" next_v:"<<next_v.to<<" len:"<<next_v.len<<endl;
    if(color[next_v.to]!=-1){
      if(color[v]==color[next_v.to] && next_v.len%2!=0) return false;
      continue;
    }
    if(next_v.len%2!=0){
      dfs(G,next_v.to,1-cur);
    }
    else{
      bool flag_=dfs(G,next_v.to,cur);
      if(!flag_) dfs(G,next_v.to,1-cur);
    }
  }
  return true;
}

int main(void)
{
  int N;
  cin>>N;
  
  Graph G(N);
  rep(i,0,N-1){
    int u,v,w;
    cin>>u>>v>>w;
    u--;v--;
    G[u].push_back(Edge(v,w));
    G[v].push_back(Edge(u,w));
  }
  //rep(i,0,N){
  //  rep(j,0,G[i].size()){
  //    cout<<"G["<<i<<"]["<<j<<"].to:"<<G[i][j].to<<" .len:"<<G[i][j].len<<endl;
  //  }
  //}
  
  
  
  color.assign(N,-1);
  dfs(G,0);
  
  rep(i,0,N){
    cout<<color[i]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 8960
N, M = map(int, input().split(' '))
A = []
for i in range(N):
    a, b = map(int, input().split(' '))
    A.append([a, b])
A.sort()
i = -1
count=0
while(True):
    i += 1
    count += A[i][1]
    if count >= M:
        print(A[i][0])
        break

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

int main() {
    int N, M, K; cin >> N >> M >> K;
    bool P=false;
    for(int i=0; i<=N; ++i){
        for(int j=0; j<=M; ++j){
            if((N-i)*j+(M-j)*i==K){
                P=true;
                break;
            }
        }
    }
    if(P) cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	ll N;
	cin>>N;

	// for (ll k=2; k<=N; ++k) {
		// ll x=N;
		// while (k<=x) {
			// if (x%k==0) x=x/k;
			// else x-=k;
		// }
		// if (x==1) {
			// cerr<<k<<endl;
		// }
	// }
	// cerr<<endl;

	ll res=1;
	if (N>2) res++;
    for (ll i=2; i*i<=N; i++) {
		if (N%i==1) {
			res++;
			if (i*i<N-1) res++;
		} else if (N%i==0) {
			ll x=N;
			while (x%i==0) x/=i;
			if (x%i==1) res++;

			x=N;
			ll j=N/i;
			if (j==i) continue;
			while (x%j==0) x/=j;
			if (x%j==1) res++;
		}
	}

	cout<<res<<'\n';
}


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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

int h, w;
char c[514][514];
bool b[514][514];
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 }, bl, wh;

void dfs(int x, int y) {
	if (c[x][y] == '#') bl++;
	else if (c[x][y] == '.') wh++;
	b[x][y] = false;
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i], ny = y + dy[i];
		if (nx<0 || ny<0 || nx>w - 1 || ny>h - 1) continue;
		if (!b[nx][ny]) continue;
		if (c[x][y] == c[nx][ny]) continue;
		dfs(nx, ny);
	}
}

signed main() {
	cin >> h >> w;
	int ans = 0;
	rep(i, h) {
		rep(j, w) {
			cin >> c[j][i];
			b[j][i] = true;
		}
	}
	rep(i, h) {
		rep(j, w) {
			if (b[j][i]){
				dfs(j, i);
				ans += bl * wh;
				bl = 0;
				wh = 0;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 8192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_107
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] ni = ReadInts();
            WriteLine(ni[0] - ni[1] + 1);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std; 
int ketasu(long long k) {
	if (k < 10)return 1;
	if (k < 100)return 2;
	if (k < 1000)return 3;	
	if (k < 10000)return 4;
	if (k < 100000)return 5;
	if (k < 1000000)return 6;
	if (k < 10000000)return 7;
	if (k < 100000000)return 8;
	if (k < 1000000000)return 9;
	if (k < 10000000000)return 10;
	if (k < 100000000000)return 11;
}
int main() {
	long long n; cin >> n;
	int num = 30;
	for (long i = 1; i <= sqrt(n); i++){
		if (n%i != 0)continue;
		long long u = n / i;
		num = min(max(ketasu(i), ketasu(u)), num);
	}
	cout << num << endl;
	char c; cin >> c;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define It set<node>::iterator
#define endl '\n'
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int n;
int arr[1000];

int main(){
	cin>>n;
	for(int i=1;i<=n;++i) cin>>arr[i];
	for(int i=1;i<=n;++i){
		if(arr[i]%2==0){
			if(arr[i]%3!=0&&arr[i]%5!=0) return puts("DENIED"),0;
		}
	}
	puts("APPROVED");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100000+5;
int a[N];
bool cmp(int x,int y){
	return x>y;
}
int main()
{
	int t;
	int s[N][3];
	int b[N];
	memset(b,0,sizeof(b));
	scanf("%d",&t);
	for(int i=0;i<t;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<t;i++){
		s[i][0]=a[i]+1;
		s[i][1]=a[i]-1;
		s[i][2]=a[i];
	}
	int k=0;
	for(int i=0;i<t;i++){
		b[s[i][0]]++;
		b[s[i][1]]++;
		b[s[i][2]]++;
	}
	sort(b,b+N,cmp);
	printf("%d\n",b[0]);
 } 

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

int main(){

    string s;
    cin >> s;

    map<char, int> dict;
    for (int i=0; i<s.size(); i++){
        dict[s.at(i)]++;
    }

    if (dict.size() == 2){
        for (auto p: dict){
            auto value = p.second;
            if (value != 2){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    else{
        cout << "No" << endl;
        return 0;
    }

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

Measured memory_bytes: 256