akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;




ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int main(){
    string str;
    cin >> str;
    if(str == "ABC")cout << "ARC" << endl;
    else cout << "ABC" << endl;
}


Measured memory_bytes: 3600
N = int(input())
S = input()

W = [0] * N
E = [0] * N

W[0] += S[0] == 'W'
E[-1] += S[-1] == 'E'

for i in range(1, N):
    W[i] = W[i - 1] + (S[i] == 'W')
for i in range(N - 1, 0, -1):
    E[i - 1] = E[i] + (S[i - 1] == 'E')

ans = min(E[1], W[-2])
for i in range(1, N - 1):
    ans = min(ans, W[i - 1] + E[i + 1])
print(ans)


Measured memory_bytes: 27148
mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
acum=[0]
for i in range(1,n+1):
  tmp=acum[-1]+pow(i,mod-2,mod)*pow(i+1,mod-2,mod)
  tmp%=mod
  acum.append(tmp)
ans=0
for i in range(n-1):
  ans+=arr[i]*acum[i]
  ans%=mod
  ans-=arr[i]*acum[n-2-i]
  ans%=mod
  ans-=arr[i]*pow(n-1-i,mod-2,mod)
  ans%=mod
for i in range(1,n):
  ans+=arr[-1]*pow(i,mod-2,mod)
  ans%=mod
for i in range(1,n):
  ans*=i
  ans%=mod
print(ans)

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

int main(void){
	int n;
	cin >> n;
	map<string, int [110]> a;
	for(int i = 0; i < n; ++i){
		string s;
		int p;
		cin >> s >> p;
		a[s][p]=i+1;
	}

	for (auto x : a){
		for(int i =105; i >= 0; --i){
			if(x.second[i]!=0){
				cout << x.second[i] << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  long long N;
  cin >> N;
  vector<long long> A(N + 1), B(N);
  for(int i = 0; i < N + 1; i++) cin >> A[i];
  for(int i = 0; i < N + 1; i++) cin >> B[i];
  long long ans = 0;
  for(int i = 0; i < N; i++){
    if(A[i] > B[i]) ans += B[i];
    else{
      ans += A[i];
      B[i] -= A[i];
      if(A[i + 1] <= B[i]) {
        ans += A[i + 1];
        A[i + 1] = 0;
      }
      else{
        ans += B[i];
        A[i + 1] -= B[i];
      }
    }
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>

using namespace std;

#define endl '\n'

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

    string head, tail; cin >> tail;


    int q; cin >> q;

    while (q--) {
        int m; cin >> m;

        if (m == 1) {
            head.swap(tail);
        } else {
            int t;
            char c;
            cin >> t >> c;

            if (t == 1) {
                head += c;
            } else {
                tail += c;
            }
        }
    }

    reverse(head.begin(), head.end());
    cout << head << tail << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  string s;
  cin >> s;
  cout << s.substr(0, 4) << " " << s.substr(4) << endl;
  return 0;
}


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

template<typename T>
ostream& operator << (ostream &out, vector<T> &v) {
	for (auto ele : v) out << ele << " ";
	out << '\n';
	return out;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int x, y;
	cin >> x >> y;
	if (y&1 || y < 2*x || y > 4*x) cout << "No";
	else cout << "Yes";
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
 
using namespace std;
#define endl '\n'
#define MAX 200005
#define pb push_back
#define mk make_pair
#define ll long long

int main() {
    	
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    int l = 0;
    int r = n-1;
    int ans =0;
    while(l < r)
    {
        if(s[l] != s[r]) ans++;
        l++;

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

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

int main(){
    int n, m, h[100000], a[100000], b[100000];
    bool good[100000];
    cin >> n >> m;

    for(int i=0; i<n; i++){
        cin >> h[i];
        good[i] = true;
    }

    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i];
    }

    int answer = 0;
    
    for(int i=0; i<m; i++){
        good[ a[i]-1 ] &= h[ a[i]-1 ] > h[ b[i]-1 ];
        good[ b[i]-1 ] &= h[ a[i]-1 ] < h[ b[i]-1 ];
    }
    
    for(int i=0; i<n; i++){
        answer += int(good[i]);
    }

    cout << answer;

}

Measured memory_bytes: 4880
use std::io;

fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str
}

fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}



fn main(){

    let v = read_t_in_line::<i32>();
    let (a, b, c, d) = (v[0], v[1], v[2], v[3]);
    if a + b > c + d {
        println!("Left");
    }
    else if a + b < c + d {
        println!("Right");
    }
    else{
        println!("Balanced");
    }


}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define watch(x) cerr << (#x) << " is " << (x) << endl
const int mod = 1e9 + 7;

using namespace std;



int main()
{
	#ifdef ME
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	long double b; long long a;
	cin >> a >> b;

	cout << (long long)(a*b) << endl;

	
	return 0;
}

Measured memory_bytes: 3752
use proconio::marker::Bytes;
fn main() {
    proconio::input! {
        a: Bytes,
        b: Bytes,
        c: Bytes,
    }
    let an=a.len();
    let bn=b.len();
    let cn=c.len();
    let k=an.max(bn).max(cn)*2;
    let m=k*2+1;
    let f=|c1: u8, c2: u8| c1!=c2 && c1!=b'?' && c2!=b'?';
    let g=|a: &Vec<u8>, b: &Vec<u8>| {
        let mut ab=vec![true;m*2+1];
        for (i,&a) in a.iter().enumerate() {
            for (j,&b) in b.iter().enumerate() {
                if f(a,b) {
                    ab[m+i-j]=false;
                }
            }
        }
        ab
    };
    let ab=g(&a,&b);
    let ac=g(&a,&c);
    let bc=g(&b,&c);
    let mut t=k*3;
    for (i,&ab) in ab[m-k..=m+k].iter().enumerate() {
        for (j,&ac) in ac[m-k..=m+k].iter().enumerate() {
            if ab && ac && bc[m+j-i] {
                let l=i.min(j).min(k);
                let r=an.max((bn+i).max(cn+j).max(k)-k);
                t=t.min(r+k-l);
            }
    }}
    println!("{}",t);
}

Measured memory_bytes: 2224
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int l = in.nextInt();
        int r = in.nextInt();
        int d = in.nextInt();
        int ans = 0;
        for(int i=l; i<=r; i++) {
            if(i%d==0) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35728
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll 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 * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

signed main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	rep(i, s.size()) {
		if (s[i] + n > 90) {
			cout << char(s[i] + n - 26);
		}
		else {
			cout << char(s[i] + n);
		}
	}
	cout << endl;
}


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 REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;


signed main(){
	int N;
	cin>>N;
	int sum=0,now=1;
	rep(i,inf){
		now*=26;
		if(N<=sum+now){
			N-=sum;N--;
			string s;
			rep(j,i+1){
				s+=('a'+N%26);
				N/=26;
			}
			reverse(all(s));
			cout<<s<<endl;return 0;
		}
		sum+=now;
	}
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
using System.Text.RegularExpressions;

class Program
{
    static int[] ReadInts()
        => Console.ReadLine()
            .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
            .Select(s => int.Parse(s))
            .ToArray();

    static void Main(string[] args)
    {
        int k = ReadInts().First();
        string s = Console.ReadLine();
        if (s.Length <= k)
        {
            Console.WriteLine(s);
        }
        else
        {
            Console.WriteLine($"{s.Substring(0, k)}...");
        }
    }
}


Measured memory_bytes: 28312
function Vector(x, y) {
  this.x = x;
  this.y = y;
}
Vector.prototype.sub = function(v) {
  return new Vector(this.x - v.x, this.y - v.y);
};
Vector.prototype.product = function(v) {
  return this.x * v.y - this.y * v.x;
};

(function(input) {
  var p = input.replace(/\n$/, '').split('\n');
  var n = p.length;
  for (var i = 0; i < n; i++) {
    var a = p.shift().split(',').map(Number);
    console.log(cross.apply(null, a));
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function cross(xa, ya, xb, yb, xc, yc, xd, yd) {
  var va = new Vector(xa, ya);
  var vb = new Vector(xb, yb);
  var vc = new Vector(xc, yc);
  var vd = new Vector(xd, yd);

  var vba = vb.sub(va);
  var vcb = vc.sub(vb);
  var vdc = vd.sub(vc);
  var vad = va.sub(vd);

  var c1 = vba.product(vcb);
  var c2 = vcb.product(vdc);
  var c3 = vdc.product(vad);
  var c4 = vad. product(vba);

  if ((c1 > 0 && c2 > 0 && c3 > 0 && c4 > 0) ||
    (c1 < 0 && c2 < 0 && c3 < 0 && c4 < 0)) {
    return 'YES';
  }
  return 'NO';
}

function cross_(x1, y1, x2, y2) {
  return x1 * y2 - x2 * y1;
}

Measured memory_bytes: 7640
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    int w = sc.nextInt();

    if(s<=w){
      System.out.println("unsafe");
    }else{
      System.out.println("safe");
    }



  }
}

Measured memory_bytes: 35860
#include <stdio.h>

int main(){
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d,stdin);
  if(a + b > c + d) printf("Left\n");
  else if(a + b == c + d) printf("Balanced\n");
  else printf("Right\n");
  return 0;
}

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

int main(){
  int x;
  cin >> x;
  int n=0;
  //int a,b,c,d,e,f;
  for(int a=0; a<=21; a++){
    for(int b=0; b<=21; b++){
      for(int c=0; c<=21; c++){
        for( int d=0; d<=21; d++){
          for(int e=0; e<=21; e++){
            for(int f=0; f<=21; f++){
              if(x == (100*a + 101*b + 102*c+103*d+104*e+105*f)){
                n=1;
              }
            }
          }
        }
      }
    }
  }
  
  if(x>=2100){
    n=1;
  }
  cout << n;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>

int LP[1005][1005] = {};

int main(){
    std::string s, t;
    std::cin >> s >> t;

    int s_size = s.size();
    int t_size = t.size();

    int ans = t_size;
    
    for (int i = 0; i < s_size - t_size + 1; i++)
    {
        int count = 0;
        std::string s_substr = s.substr(i, t_size);
        
        for (int j = 0; j < t_size; j++)
        {
            if (s_substr[j] != t[j])
            {
                count++;
            }
        }
        ans = std::min(ans, count);
    }
    
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3648
A,B,K=map(int,input().split())
cands = set([])
for i in range(A,min(A+K,B+1)):
    cands.add(i)
for i in range(max(A,B-K+1),B+1):
    cands.add(i)
for cand in sorted(list(cands)):
    print(cand)


Measured memory_bytes: 3060
n = int(input())
t, a =  list(map(int,(input().split(' '))))
h = list(map(int,(input().split(' '))))
'''
print(n)
print(t, a)
print(h)
'''
hope = []
for i in range(n):
  hope.append(abs(t - h[i] *0.006-a))
  
  
#print(hope)  
print(hope.index(min(hope))+1)

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

int main()
{
    ll x;
    ll ans=0;
    for(ll i=0;i<5;i++)
     {
        cin >> x;
        if(x==0)
          ans=i+1;
     }
     cout << ans << "\n";
}


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

int main() {
    int n,m;
    cin >> n >> m;
    int L=1,R=n;
    int l,r;
    while(m--) {
        cin >> l >> r;
        L = max(L, l);
        R = min(R,r);
    }
    cout << max(R-L+1, 0) << endl;
}


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



int main()
{
    ll n;
    cin>>n;
    ll l1[n+1];
    ll x=0,s=0;
    for(int i=1;i<=n;i++){
        cin>>l1[i];
        x+=l1[i];
        //if(i==1&&l1[i]==0&&l1[i+1]<=0)x++,s++,l1[i]=1;
        //else if(i==1&&l1[i]==0&&l1[i+1]>0)x--,s++,l1[i]=-1;
        if(i%2==0){
            if(x-l1[i]<=0&&x<=0){
                s+=(ll)abs(-(x-l1[i])+1-l1[i]);
                //cout<<abs(-(x-l1[i])+1-l1[i])<<endl;
                //l1[i]=l1[i]-x+1;
                x=1;
            }}
            else{
                if(x-l1[i]>=0&&x>=0){
                s+=(ll)abs(-(x-l1[i])-1-l1[i]);
                //cout<<abs(-(x-l1[i])-1-l1[i])<<endl;
                //l1[i]=-(x-l1[i]+1);
                x=-1;
            }
            }
            
        }
        ll s2=s;s=0,x=0;
        for(int i=1;i<=n;i++){
        cin>>l1[i];
        x+=l1[i];
        //if(i==1&&l1[i]==0&&l1[i+1]<=0)x++,s++,l1[i]=1;
        //else if(i==1&&l1[i]==0&&l1[i+1]>0)x--,s++,l1[i]=-1;
        if(i%2!=0){
            if(x-l1[i]<=0&&x<=0){
                s+=(ll)abs(-(x-l1[i])+1-l1[i]);
                //cout<<abs(-(x-l1[i])+1-l1[i])<<endl;
                //l1[i]=l1[i]-x+1;
                x=1;
            }}
            else{
                if(x-l1[i]>=0&&x>=0){
                s+=(ll)abs(-(x-l1[i])-1-l1[i]);
                //cout<<abs(-(x-l1[i])-1-l1[i])<<endl;
                //l1[i]=-(x-l1[i]+1);
                x=-1;
            }
            }
            
        }
    
    cout<<min(s,s2)<<endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

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

vector<ll> A;

int main(void) {
    ll K, N;
    cin >> K >> N;

    A.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll acc = 0;
    ll longest = 0;
    for (int i = 1; i < N; i++) {
        acc += A[i] - A[i - 1];
        chmax(longest, A[i] - A[i - 1]);
    }

    acc += K - A[N - 1] + A[0];
    chmax(longest, K - A[N - 1] + A[0]);

    acc -= longest;

    cout << acc << endl;

    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
const int mod = 998244353;
struct mint
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }


int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> l(k), r(k);
    rep(i, k) cin >> l[i] >> r[i];
    vector<mint> dp(n+1), dpsum(n+1);
    dp[1] = 1;
    dpsum[1] = 1;
    for (int i = 2; i <= n; ++i) {
        rep(j,k) {
            int li = i - r[j];
            int ri = i - l[j];
            if (ri < 0) continue;
            li = max(li, 1);
            dp[i] += dpsum[ri]-dpsum[li-1]; // dp[li] ~ dp[ri]
        }
        dpsum[i] = dpsum[i-1] + dp[i];
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

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

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

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

string to_string(vector<bool> v)
{
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
    string res = "";
    for (size_t i = 0; i < N; i++)
    {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

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

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

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

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

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

int main()
{
    int N, M;

    while (cin >> N >> M)
    {
        if (N == 0 && M == 0)
            return 0;
        vector<pair<int, int>> v(N);
        for (int i = 0; i < N; i++)
        {
            cin >> v[i].second >> v[i].first;
        }

        sort(v.rbegin(), v.rend());

        int ans = 0;

        for (int i = 0; i < N; i++)
        {
            if (M >= v[i].second)
            {
                M -= v[i].second;
            }
            else
            {
                ans += (v[i].second - M) * v[i].first;
                M = 0;
            }
        }

        cout << ans << "\n";
    }
}


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

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for (int i = 0; i < N; i++) cin >> p.at(i);
    sort(p.begin(), p.end());
    ll ans = 0;
    for (int i = 0; i < K; i++) ans += p.at(i);
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3632
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <stdio.h>
#include <math.h>
#include <utility>
#include <algorithm>
#include <sstream>

using namespace std;

bool func(pair<string,pair<int,int>> a, pair<string, pair<int, int>> b)
{
	if (a.first == b.first) {
		return a.second.first > b.second.first;
	}
	return a.first < b.first;
}


int main() {
	int n;
	cin >> n;
	vector<pair<string,pair<int,int>>> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i].first >> s[i].second.first;
		s[i].second.second = i+1;
	}
	sort(s.begin(), s.end(), func);
	for (int i = 0; i < s.size(); i++) {
		cout << s[i].second.second << endl;
	}
	return 0;
}


Measured memory_bytes: 256
class Node
  attr_accessor :h, :p
  def initialize(h, p)
    @h = h
    @p = p
  end
end

class Heap
  def initialize
    @nodes = []
  end

  def push(h, p)
    @nodes << Node.new(h, p)
    c = @nodes.size-1
    p = (c-1)/2

    while c != 0 && @nodes[p].h < h
      @nodes[c], @nodes[p] = @nodes[p], @nodes[c]
      c, p = p, (p-1)/2
    end
  end

  def pop
    res = @nodes.first
    if @nodes.size == 1
      @nodes.pop
      return res
    end

    @nodes[0] = @nodes.pop
    p = 0
    c = 2*p+1

    while c < @nodes.size
      if c+1 < @nodes.size && @nodes[c].h < @nodes[c+1].h
        c = c+1
      end
      if @nodes[p].h > @nodes[c].h
        break
      end

      @nodes[p], @nodes[c] = @nodes[c], @nodes[p]
      p, c = c, 2*c+1
    end
    return res
  end

  def size
    @nodes.size
  end

  def print
    puts @nodes.map(&:h)
  end
end

while true do
  n, m, a = gets.split.map(&:to_i)
  break if n|m|a == 0

  nums = []
  (1..n).each{ |i| nums << i }
  heap = Heap.new
  m.times do
    h, p, q = gets.split.map(&:to_i)
    heap.push(h, p-1)
  end

  until heap.size == 0
    p = heap.pop.p
    nums[p], nums[p+1] = nums[p+1], nums[p]
  end

  nums.each_with_index do |num, i|
    if num == a
      puts i+1
      break
    end
  end
end

Measured memory_bytes: 6136
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int i = 0,ii = 0;
  char c;
  string a;
  cin >> a;
  while(a[i]){
    c = a[i];
    ii = ii + (c - '0');
    i++;
  }
  if(ii % 9 == 0){
  cout << "Yes";
  }else{
  cout << "No";
  }
  return 0;
}

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

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

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

int main(void){
    
    char c;

    int ch[26] = {0};

    while(cin >> c){
        if('A' <= c && c <= 'Z') c = char(c+('a'-'A'));
        if('a' <= c && c <= 'z') ch[c-'a']++;
    }

    for(int i = 0;i < 26;i++){
        cout << char(i+'a') << " : " << ch[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3084
S = list(input())
T = list(input())

import sys
input = sys.stdin.readline
# 前計算
S_n = [0] * (len(S) + 1)
# S_n[0] = 1 if S[0] == 'A' else 2
for i in range(1, len(S) + 1):
    if S[i - 1] == 'A':
        S_n[i] = S_n[i - 1] + 1
    else:
        S_n[i] = S_n[i - 1] + 2

T_n = [0] * (len(T) + 1)
# T_n[0] = 1 if T[0] == 'A' else 2
for i in range(1, len(T) + 1):
    if T[i - 1] == 'A':
        T_n[i] = T_n[i - 1] + 1
    else:
        T_n[i] = T_n[i - 1] + 2

q = int(input())
for _ in range(q):
    a, b, c, d = map(int, input().split())
    #output
    S_A = S_n[b] - S_n[a - 1]
    T_A = T_n[d] - T_n[c - 1]
    delta = abs(S_A - T_A)
    if delta % 3 == 0:
        print ('YES')
    else:
        print ('NO') 

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

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(5e18)
#define N (int)(2e5 + 10)

using namespace std;

void solve() {
	int n; cin >> n;
	if (n == 1) {
		cout << 0 << endl;
		return;
	}

	int v1 = 1, v2 = 1, v3 = 1;
	for (int i = 0; i < n; i++) {
		v1 *= 10, v1 %= mod;
		v2 *= 9, v2 %= mod;
		v3 *= 8, v3 %= mod;
	}

	cout << ((v1 - ((2 * v2) % mod) + mod) % mod + v3 % mod) % mod << endl;
}


// Got stuck and want to leave ? look at the bottom once..
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
	// cin >> t_c;
	while (t_c--)
		solve();
}
/*
 * LOOK DUDE ... IT AINT DEFINETELY EASY BUT YOU AINT THAT WEAK EITHER
 * COME ON DUDE .... DONT GET UP UNTIL U GET THE SOLUTION
 * GIVING UP NOT GONNA HELP .. JUST GET YOUR ASS TO WORK ALREADY ..
 * AND FOR FUCKING SAKE ... DONT PANIC !!
*/


Measured memory_bytes: 3652
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = in.nextInt();

        int ans = 0;
        for (int n = 0; n < N; n++) {
            int a = in.nextInt();
            if (n % 2 == 0 && a % 2 == 1)
                ans++;
        }
        out.println(ans);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



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

inline void findMissingCards(multimap<char, int> &cards, char c) {
    auto tmp = cards.equal_range(c);
    vector<int> vec(13);
    for (auto itr = tmp.first; itr != tmp.second; itr++) {
        vec.push_back(itr->second);
    }

    for (int i = 1; i <= 13; i++) {
        auto result = find(vec.begin(), vec.end(), i);
        if (result == vec.end()) {
            cout << c << ' ' << i << '\n';
        }
    }
    return ;
}

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

    int n;
    cin >> n;

    multimap<char, int> cards;
    for (int i = 0; i < n; i++) {
        char tmp;
        int num;
        cin >> tmp >> num;
        cards.emplace(tmp, num);
    }

    findMissingCards(cards, 'S');
    findMissingCards(cards, 'H');
    findMissingCards(cards, 'C');
    findMissingCards(cards, 'D');
    return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  vector<int> dp(n);
  for (int i = 0; i < n; i++) {
    dp[a[i]] = 1;
    if (a[i] > 0) {
      dp[a[i]] = max(dp[a[i]], dp[a[i] - 1] + 1);
    }
  }
  int ans = n - *max_element(dp.begin(), dp.end());
  cout << ans << endl;
}

Measured memory_bytes: 1792
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Mon Jan  7 17:10:15 2019
//
package main

import (
	"fmt"
	"sort"
)

func scanSlice(slice []int) {
	for i := range slice {
		fmt.Scan(&slice[i])
	}
}

func min(slice ...int) int {
	sort.Ints(slice)
	return slice[0]
}

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

func main() {
	var N, K int
	fmt.Scan(&N, &K)

	slice := make([]int, N)
	scanSlice(slice)

	ans := 0
	for i := range slice {
		ans += min(slice[i]*2, abs(slice[i]-K)*2)
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
h, w = map(int, input().split())

A = [str(input()) for _ in range(h)]

from collections import deque
q = deque()
visit = [[-1]*w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if A[i][j] == '#':
            visit[i][j] = 0
            q.append((i, j))

while q:
    y, x = q.popleft()
    for dy, dx in (-1, 0), (1, 0), (0, -1), (0, 1):
        ny, nx = y+dy, x+dx
        if 0 <= ny <= h-1 and 0 <= nx <= w-1 and visit[ny][nx] == -1:
            visit[ny][nx] = visit[y][x]+1
            q.append((ny, nx))
#print(max(visit))
max_ = -1
for i in range(h):
    for j in range(w):
        max_ = max(visit[i][j], max_)
print(max_)

Measured memory_bytes: 87388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    ll N;
    cin >> N;
    vector<ll> C(N);
    rep(i,N){
        cin >> C[i];
        C[i]--;
    }
    map<ll,ll> m;
    map<ll,ll> mc;
    vector<ll> dp(N+1);
    dp[0]=1;
    rep(i,N){
        if (!m.count(C[i])){
            dp[i+1]=dp[i];
        }
        else {
            int j=m[C[i]];
            if (j!=i){
                dp[i+1]=(dp[i]+mc[C[i]])%MOD;
            }
            else {
                dp[i+1]=dp[i];
            }
        }
        m[C[i]]=i+1;
        if (!(i>0&&C[i]==C[i-1])){
            mc[C[i]]+=dp[i];
            mc[C[i]]%=MOD;
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 28416
#include<bits/stdc++.h>
//#define int long long
#define rep(i, l, r) for(register int i = l; i <= r; ++ i)

inline int read() 
{
	char cc = getchar(); int cn(0), flus(1);
	while(cc < '0' || cc > '9') {if(cc == '-') flus = -flus; cc = getchar();}
	while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - 48; cc = getchar();}
	return cn * flus;
}

const int MAXN = 1e5 + 10;
const int Mod = 998244353, G = 3;

signed main()
{
	int a = read(), b = read(), c = read();
	int k = read();
	while(k --) 
	{
		if(b <= a)
		{
			b *= 2;
			continue;
		}
		if(c <= b)
		{
			c *= 2;
			continue;
		}
	}
	if(b > a && c > b) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
 
int a1, b1, a2, b2;
 
int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> a1 >> b1 >> a2 >> b2;
	if (b2 < a1 || b1 < a2) cout << 0 << endl;
	else if (a1 <= a2 && b2 <= b1) cout << b2-a2 << endl;
	else if (a1 <= a2 && b1 < b2) cout << b1-a2 << endl;
	else if (a2 < a1 && b2 <= b1) cout << b2-a1 << endl;
	else if (a2 < a1 && b1 < b2) cout << b1-a1 << endl;
	return 0;
}

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

using namespace std;

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

Measured memory_bytes: 256
N, K = list(map(int, input().split()))
re = {}
for i in range(N):
    a,b = list(map(int, input().split()))
    if a not in re: re[a] = 0
    re[a] += b

re = sorted(re.items())

current = 0
for k, v in re:
    current += v
    if current >= K:
        print(k)
        break

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

int main(){
  int tile=0;
  string S;
  cin >> S;
  
  for(int i=0; i<S.length(); i++){
    if(i%2 == 0 && S[i] == '1') tile++;
    if(i%2 == 1 && S[i] == '0') tile++;
  }
  
  int other=S.length() - tile;
  cout << min(tile,other) << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
 using namespace std;
int main(){
	signed long long arr1[4];
	for(int i=0; i<4; i++)cin>>arr1[i];

	signed long long arr2[4];
	int j=2;
	for(int i=0; i<2; i++){
		arr2[i]=arr1[0]*arr1[j];
		j++;
		//cout<<arr2[i]<<"  ";
	}
	j=2;
	for(int i=2; i<4; i++){
		arr2[i]=arr1[1]*arr1[j];
		j++;
	}
	for(int i=0; i<4; i++){
		if(arr2[i]>arr2[0])arr2[0]=arr2[i];
	}
	cout<<arr2[0]<<endl;
	return 0;
}

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

int main(){

    int cnt = 0;
    int h, w; cin >> h >> w;
    for(int i = 0; i < h * w; i++){
        char c; cin >> c;
        cnt += (c == '#');
    }

    cout << (cnt == h + w - 1 ? "Possible" : "Impossible") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

std::vector<long long> fact, inv;

constexpr auto pow(long long x, long long n, const long long mod) {
    long long ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

constexpr auto inverse(const long long x, const long long p) {
    return pow(x, p - 2, p);
}

void init_factorial(const int n, const long long mod) {
    fact.resize(n + 1);
    inv.resize(n + 1);
    fact[0] = 1;
    for (long long i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (long long i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

int n;
std::vector<std::vector<int>> g;
std::vector<i64> sz, r, ret;
constexpr i64 mod = 1000000007;

i64 szdfs(int v, int p) {
    for (int to : g[v]) if (to != p) sz[v] += szdfs(to, v);
    return ++sz[v];
}

i64 dfs(int v, int p) {
    for (int to : g[v]) {
        if (to == p) continue;
        r[v] = r[v] * dfs(to, v) % mod;
    }
    return r[v] = r[v] * inverse(sz[v], mod) % mod;
}

void dfs2(int v, int p, i64 ot) {
    ret[v] = ot;
    for (int to : g[v]) {
        if (to == p) continue;
        ret[v] = ret[v] * r[to] % mod;
    }
    for (int to : g[v]) {
        if (to == p) continue;
        i64 o = ret[v] * inverse(r[to], mod) % mod * inverse(n - sz[to], mod) % mod;
        dfs2(to, v, o);
    }
}

int main() {
    std::cin >> n;
    init_factorial(n + 10, mod);
    g.resize(n + 1); sz.resize(n + 1); r.resize(n + 1, 1); ret.resize(n + 1);
    for (int i = 1; i < n; i++) {
        int u, v;
        std::cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    szdfs(1, 0);
    dfs(1, 0);
    dfs2(1, 0, 1);

    const i64 co = fact[n - 1];
    for (int i = 1; i <= n; i++) std::cout << co * ret[i] % mod << '\n';

    return 0;
}


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

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if (a < b) 
		if(b<c)
		cout << "Yes" << endl;
		else
			cout << "No" << endl;
	else 
		cout << "No" << endl;
	return(0);
}


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

int main() {
  char c;
  cin >> c;
  string v = "aiueo";
  int a = 0;
  for (int i = 0; i < v.size(); i++) {
    if(c == v.at(i)) {
      a = a + 1;
    }
  }
  if (a == 1) {
    cout << "vowel" <<endl;
  } else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())
c = 30 * h + 0.5 * m - 6 * m
if c >= 180:
    c = 360 - c
ans = (a * a + b * b - 2 * a * b * math.cos(c * math.pi / 180)) ** (0.5)
print(ans)

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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(n,0);
  vector<int> c(n,0),d(n,0);
  int ans=n;
  for(int i=0;i<n;i++){
    cin >> a[i];
    a[i]--;
    if(a[i]-c[a[i]]>=0){
      if(d[a[i]-c[a[i]]]==0) ans--;
      d[a[i]-c[a[i]]]++;
    }
    c[a[i]]++;
  }
  int x,y;
  for(int i=0;i<m;i++){
    cin >> x >> y;
    x--,y--;
    c[a[x]]--;
    if(a[x]-c[a[x]]>=0){
      if(d[a[x]-c[a[x]]]==1) ans++;
      d[a[x]-c[a[x]]]--;
    }
    a[x]=y;
    if(a[x]-c[a[x]]>=0){
      if(d[a[x]-c[a[x]]]==0) ans--;
      d[a[x]-c[a[x]]]++;
    }
    c[a[x]]++;
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N, M; cin >> N >> M;
	vector<int>dp(N + 1);
	vector<int>a(N + 1);
	loop(M) {
		int x; cin >> x;
		a[x] = 1;
	}
	dp[0] = 1;
	rep(i, 0, N) {
		if (a[i])dp[i] = 0;
		if (i + 1 < N+1) {
			(dp[i + 1] += dp[i]) %= MOD;
		}
		if (i + 2 < N+1) {
			(dp[i + 2] += dp[i]) %= MOD;
		}
	}
	dump(dp);
	cout << dp[N] << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<char> s(3);
  for (int i = 0; i < 3; i++) cin >> s[i];
  for (int i = 0; i < 3; i++) {
    if (s[i] == '1') s[i] = '9';
    else if (s[i] == '9') s[i] = '1';
    cout << s[i];
  }
  cout << endl;
}

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

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.nextLine();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}
		list.sort(new Comparator<Integer>() {
			@Override
			public int compare(Integer o1, Integer o2) {
				return o1 - o2;
			}
		});
		int sum = 0;
		for (int i = 0; i < k; i++) {
			sum += list.get(i);
		}
		System.out.println(sum);
	}
}


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

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main() {
  int K;
  cin >> K;
  int64_t sum = 0;
  for(int i=1; i<=K; i++){
    
    for(int j=i; j<=K; j++){
      int gcd_ij=gcd(i,j);
      
      for(int k=j; k<=K; k++){
        int tmp = gcd(gcd_ij,k);
        if(i!=j && i!=k && j!=k){
          sum += 6*tmp;
        }
        else if(i==j && j!=k){
          sum+=3*tmp;
        }
        else if(j==k && i!=j){
          sum+=3*tmp;
        }
        else{
          sum+=tmp;
        }
      }
    }
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
using namespace std;
long long int gcd(long long int x,long long int  y){
   if(y==0)return x;
   return gcd(y,x%y);
}
int main(){
IOS;
int d,s,t;
cin>>d>>s>>t;
if(s*t>=d)cout<<"Yes";
else cout<<"No";
return 0;
}
/*sjleepy*/


Measured memory_bytes: 3644
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll L,R; cin >> L >> R;
    if (R-L >= 2019) {
        cout << 0 << ln;
        return 0;
    }
    ll ans = 2018;
    for(ll i = L; i <= R; ++i) {
        for (ll j = i+1; j <=R; ++j) {
            chmin(ans,i*j%2019);
        } 
    }

    cout << ans << ln;
}

Measured memory_bytes: 256
def main():
    H, W = map(int, input().split())
    canvas = [ list(input()) for i in range(H)]
    possible = True

    for i in range(H):
        for j in range(W):
            if canvas[i][j] == "#":
                if j - 1 >= 0 and canvas[i][j-1] == "#":
                    pass
                elif j + 1 < W and canvas[i][j+1] == "#":
                    pass
                elif i - 1 >= 0 and canvas[i-1][j] == "#":
                    pass
                elif i + 1 < H and canvas[i+1][j] == "#":
                    pass
                else:
                    possible = False
                    
    if possible:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		int N = int.Parse(Console.ReadLine());//配列Aの個数
      　var An = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();//配列An
      	int Q = int.Parse(Console.ReadLine());//試行回数Q
		
		//int count = 0;
		//foreach (var n in An){
    	//	if (n == 0){
        //		count++;
    	//		}
        // 	}
      
        var countArray = new long[100001]; //配列Anに1~100000が何個あるのかの配列(分らなかった)
      	for (int i = 0; i < An.Length; i++)
            {
                countArray[An[i]]++;
            }
       	
      	var sum = An.Sum();//配列の合計値

		for(int i = 1; i <= Q ; i++)
            {
                var BnCn = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
                var B = BnCn[0];
                var C = BnCn[1];
          
          
                sum += (C - B) *  countArray[B];//sum計算
                countArray[C] += countArray[B];//Cの数をBの数分増やす
                countArray[B] = 0;//Bの数を0に
                Console.WriteLine(sum.ToString());
            }
    }
}

Measured memory_bytes: 51116
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if(s<t){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
int main(){
	ll i,cnt = 0,n;
	cin >> n;
	for(i=1;i*i<=n;i++){
		if(n%i==0 && n/i - 1>i){
			cnt += n/i - 1;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256