akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int x, n;
    cin >> x >> n;
    if(n == 0)
    {
        cout << x << '\n';
        return 0;
    }
    vector<int> p(n);
    int i;
    for(i=0;i<n;i++)
        cin >> p[i];
    sort(p.begin(), p.end());
    int  diff = 200, id = -1;
    for(i=0;i<=200;i++)
    {
        if(!binary_search(p.begin(), p.end(), i))
        {
            if(diff > abs(x-i))
            {
                diff = abs(x-i);
                id = i;
            }
        }
    }
    cout << id << '\n';
}

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

const int maxn = 2001;

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

int ix,iy;
int x,y,n;

bool solve(string s,string t){
    int tx = ix,ty = iy;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            ty+=1;
        }
       // cout<<tx<<" "<<x<<endl;
        if(ty>y) return true;

        if(s[i]=='D'){
            tx+=1;
        }
        if(tx>x) return true;
        if(t[i]=='L'){
            if(ty-1>=1) ty-=1;
        }
        if(t[i]=='U'){
            if(tx-1>=1) tx-=1;
        }
    }
    tx = ix;
    ty = iy;
    for(int i=0;i<n;i++){
        if(s[i]=='L'){
            ty-=1;
        }
        if(ty==0) return true;
        if(s[i]=='U'){
            tx-=1;
        }
        if(tx==0) return true;
        if(t[i]=='R'){
            if(ty+1<=y) ty+=1;
        }
        if(t[i]=='D'){
            if(tx+1<=x) tx+=1;
        }
    }
    return false;

}

int main(){
  
    cin>>x>>y>>n;
    cin>>ix>>iy;
    string s;
    cin>>s;
    string t;
    cin>>t;

   // string ans = "NO";

    if(solve(s,t)){
        cout<<"NO";
    }
    else{
        cout<<"YES";
    }

    return 0;
}


Measured memory_bytes: 1160
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == '?':
        break
    elif op == '+':
        print(a+b)
    elif op == '-':
        print(a-b)
    elif op == '*':
        print(a*b)
    else:
        print(a//b)




Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
typedef long long ll;

using namespace std;

int main(){
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for (ll i=0; i<n; i++){
        cin >> a[i];
    }
    ll before = 1;
    ll now = 1;
    map<ll, ll> mp;
    mp[1]++;
    for (ll i=0; i<n; i++){
        now = a[before-1];
        before = now;
        if (mp[now]==1){
            break;
        }
        mp[now]++;
    }
    //cout << now << endl;
    
    ll count = 0;
    ll count1 = -1;
    ll count2 = 0;
    ll before2 = 1;
    ll now2 = 1;
    for (ll i=0; i<n; i++){
        if (now2 == now  && count1 == -1){
            count1 = count;
            count = 0;
        }
        else if (now2 == now  && count1 != -1){
            count2 = count;
            break;
        }
        count += 1;
        now2 = a[before2-1];
        before2 = now2;
    }
    //cout << count1 << " " << count2 << endl;
    
    ll kisoku = k - count1 + 1;
    ll amari = kisoku % count2;
    if (amari == 0){
        amari = count2;
    }
    
    ll before3 = now;
    ll now3 = now;
    if (count2!=0 && n<k){
        for (ll i=0; i<amari-1; i++){
            now3 = a[before3-1];
            before3 = now3;
            //cout << now3 << endl;
        }
    }
    else{
        before3 = 1;
        now3 = 1;
        for (ll i=0; i<k; i++){
            now3 = a[before3-1];
            before3 = now3;
            //cout << now3 << endl;
        }
    }
    cout << now3 << endl;
    return 0;
}

Measured memory_bytes: 17328
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int n, ans = 0;
    long long s;
    long long l[100];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            for (int k = j+1; k < n; k++) {
                if (l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) {
                    continue;
                }
                s = l[i] + l[j] + l[k];
                if (s > max(l[i], max(l[j], l[k]))*2) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
from collections import deque
def main():
    n = int(input())
    d = list(map(int, input().split()))
    d.sort()
    q = []
    q = deque(q)
    q.append(0)
    ans = float("inf")
    for v in d:
        if q[0]-(-v) < v-q[-1]:
            ans = min(ans, v-q[-1])
            q.append(v)
        else:
            ans = min(ans, q[0]-(-v))
            q.appendleft(-v)
    ans = min(ans, q[0]-(-12) + 12-q[-1])
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n; cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int ans = 0;
    for (int i = 1; i < n-1; i++) {
        vector<int> v;
        for (int j = i-1; j <= i+1; j++) {
            v.push_back(p[j]);
        }
        sort(v.begin(), v.end());
        if (v[1] == p[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 50 + 5, INF = 0x3f3f3f3f, M = N << 1;

int a[N];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      ans += a[i] * a[j];
    }
  }
  cout << ans << '\n';
}

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

using namespace std;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  int x = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    x ^= a[i];
  }
  
  for(int i = 0; i < n; i++) {
    cout << (a[i]^x) << ' ';
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3984
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x-r>=0 && W-(x+r)>=0 && H-(y+r)>=0 && y-r>=0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#define MAX 310

using namespace std;

int n,ansf;
int ans[MAX][MAX];
char a[MAX][MAX];
bool test;

int main()
{
    cin>>n;
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>a[i][j];
    for(int i=0;i<n;i++) for(int j=0;j<n;j++)
      for(int ls=1;ls<=n;ls++)
        if(a[(i+n-ls+1)%n][j]==a[i][(j+n-ls+1)%n])
          ans[i][j]++;
        else break;
    for(int A=0;A<n;A++) for(int B=0;B<n;B++){
      test=true;
      for(int ca=0;ca<n;ca++)
        if(ans[(ca+A)%n][(ca+B)%n]<ca+1){
          test=false;
          break;
        }
      //cout<<A<<" "<<B<<" "<<test<<'\n';
      ansf+=test;
    }
    cout<<ansf;
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long a,unsigned long long b);
int main()
{
    int N;
    unsigned long long T;
    cin >> N;
    cin >> T;
    unsigned long long t;
    for (int i=0;i<N-1;i++)
    {
        cin >> t;
        T=T*(t/gcd(T,t));
    }
    cout << T << endl;
return 0;
}

unsigned long long gcd(unsigned long long a,unsigned long long b)
{
    unsigned long long q,r;
    if (a>b)
    {
        q=a/b;
        r=a%b;
        if (r==0) return b;
        else return gcd(b,r);
    }
    else
    {
        q=b/a;
        r=b%a;
        if (r==0) return a;
        else return gcd(a,r);
    }  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
bool pr(ll n)
{
for(ll i=3;i<=sqrt(n);i+=2)
{
if(n%i==0)
{
return 0;
}
}
return 1;
}
int main()
{
ll a,b;
cin>>a>>b;
ll g=__gcd(a,b);
ll ans=0;
ll j=g;
for(ll i=2;i<=sqrt(g);i+=2)
{
bool ok=0;
while(j%i==0)
{
j/=i;
ok=1;
}
ans+=ok;
if(i==2)
{
i--;
}
}
cout<<ans+1+(j!=1)<<endl;
}

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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    if(s[0] == '1'){ ans += 1;}
    if(s[1] == '1'){ ans += 1;}
    if(s[2] == '1'){ ans += 1;}
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int n;
int R[2][N], G[2][N], B[2][N];
char s[N];

int main() {
	scanf("%d", &n);
	scanf("%s", s + 1);
	for(int i = 1; i <= n; ++i) {
		R[0][i] = R[0][i - 1] + (s[i] == 'R');
		G[0][i] = G[0][i - 1] + (s[i] == 'G');
		B[0][i] = B[0][i - 1] + (s[i] == 'B');
	}
	for(int i = n; i >= 1; --i) {
		R[1][i] = R[1][i + 1] + (s[i] == 'R');
		G[1][i] = G[1][i + 1] + (s[i] == 'G');
		B[1][i] = B[1][i + 1] + (s[i] == 'B');
	}
	long long ans = 0;
	for(int i = 1; i <= n; ++i) {
		if(s[i] == 'R') {
			ans += G[0][i - 1] * B[1][i + 1];
			ans += G[1][i + 1] * B[0][i - 1];
		} else if(s[i] == 'G') {
			ans += R[0][i - 1] * B[1][i + 1];
			ans += R[1][i + 1] * B[0][i - 1];
		} else if(s[i] == 'B') {
			ans += R[0][i - 1] * G[1][i + 1];
			ans += R[1][i + 1] * G[0][i - 1];
		}
	}
	for(int len = 1; len <= n; ++len) {
		for(int i = 1; i <= n; ++i) {
			if(i - len < 1) continue;
			if(i + len > n) continue;
			ans -= (s[i - len] != s[i] && s[i + len] != s[i] && s[i - len] != s[i + len]);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll N,K;
    cin >> N >> K;
    vector<pll> ab(N);
    REP(i, N){
        cin >> ab[i].fi >> ab[i].se;
    }
    
    SORT(ab);

    ll total = 0;
    REP(i, N){
        total += ab[i].se;
        if(total >= K){
            pr(ab[i].fi);
            break;
        }
    }
}

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

int main(void){
	int n;
	string str;

	cin>>n;
	str=to_string(n);

	if(str[0]=='7' || str[1]=='7' || str[2]=='7')
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

	return 0;
}

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

using namespace std;

int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0);
   
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
   
    double ans = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
   
   printf("%.8lf\n",ans);
   
   
   return 0;
}


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

int main(){
	string s;cin>>s;
	int match = 0;
	for(int i='a';i<='c';i++) for(int j=0;j<s.size();j++) if(s[j] == i){
		match += 1;
		break;
	}
	if(match == 3) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
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);

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    ll a, b, c, d;
    in2(a, b);
    in2(c, d);

    ll ans = a * c;
    chmax(ans, a * d);
    chmax(ans, b * c);
    chmax(ans, b * d);

    outl(ans);

    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll a,b,c;
	cin>>a>>b>>c;

	ll k=(a-b);
	if(k>=c){
		cout<<"0";
	}
	else{
		cout<<(c-k);
	}

	return 0;
}

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

#define ll     long long
#define fr     first
#define sec    second
#define rep(i,n)  for(i=0;i<n;i++)
#define vi     vector <int>
#define vc     vector <char>
#define vl     vector <ll>
#define vb     vector <bool>
#define pb     push_back
#define M      1000000007
#define ios    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open   freopen("input.txt","r",stdin);
#define close  freopen("output.txt","w",stdout);
#define M_PI   3.14159265358979323846
#define pp     pair<int,int>
#define nn 100003

int main()
{
    ios;
    ll i,a[5];
    rep(i,5)
    {
        cin>>a[i];
        if(a[i]==0)
            cout<<i+1;
    }
    return 0;
}


Measured memory_bytes: 3608
/*author:revolIA*/
/*明日を変えるなら今日変えなきゃ*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+7,mod = 1e9+7;
ll dp[maxn];
ll Pow2[maxn] = {1};
char str[maxn];
ll dfs(int len,int limit,int cnt){
    //printf("%d %d %d\n",len,limit,cnt);
    if(!len)return Pow2[cnt];
    if(!limit && ~dp[len])return dp[len]*Pow2[cnt]%mod;
    //printf("judge : %d\n",limit && (str[len] == '0'));
    ll sum = dfs(len-1,limit && (str[len] == '0'),cnt);
    if(!limit || str[len]-'0')sum += dfs(len-1,limit,cnt+1);
    sum %= mod;
    return (!limit)?dp[len] = sum : sum;
}
int main(){
    memset(dp,-1,sizeof dp);
    for(int i=1;i<maxn;i++)Pow2[i] = Pow2[i-1]*2%mod;
    scanf("%s",str+1);
    int n = strlen(str+1);
    reverse(str+1,str+1+n);
    printf("%lld\n",dfs(n,1,0));
    return 0;
}


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

using namespace std;

int main() {
	int n,c,k;

	int clst = 0;
	cin >> n >> c >> k;
	int t[n];
	for(int i = 0; i < n; i++){
		cin >> t[i];
	}
	sort(t,t+n);

	int cus = 0;
	int ans = 1;
	int dep = 0;

	for(int i = 0; i < n; i++){
		if(cus == 0){//最初
			cus++;
			dep = t[i] + k;
			//cout << "dep : " << dep << endl;
		}else if(cus < c && dep >= t[i]){//乗せる
			cus++;
		}else{
			ans++;
			cus = 1;
			dep = t[i] + k;//set
			//cout << "dep : " << dep << endl;
		}
	}
	cout << ans << endl;
	return 0;
}
/*


*/


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		var q = sc.nextInt();
		var q1 = new int[q];
		var q2 = new int[q];
		for (var i = 0; i < q; i++) {
			q1[i] = sc.nextInt();
			q2[i] = sc.nextInt();
		}
		sc.close();

		var sum = (long) (n - 2) * (n - 2);
		var x = new Main().new SortedMap();
		var y = new Main().new SortedMap();
		x.put(n, n);
		y.put(n, n);
		for (var i = 0; i < q; i++) {
			var qt = q1[i];
			var qv = q2[i];
			if (qt == 1) {
				var v = x.searchValue(qv);
				sum -= v - 2;
				update(y, v, qv);
			} else {
				var v = y.searchValue(qv);
				sum -= v - 2;
				update(x, v, qv);
			}
		}
		System.out.println(sum);
	}

	private static void update(SortedMap map, int key, int value) {
		if (map.containsKey(key)) {
			map.put(key, Math.min(map.get(key), value));
		} else {
			map.put(key, value);
		}
	}

	public class SortedMap {
		List<Integer> list;
		HashMap<Integer, Integer> map;

		public SortedMap() {
			this.list = new ArrayList<Integer>();
			this.map = new HashMap<Integer, Integer>();
		}

		public boolean containsKey(int key) {
			return this.map.containsKey(key);
		}

		public int get(int key) {
			return this.map.get(key);
		}

		public void put(int key, int value) {
			this.list.add(search(key), key);
			this.map.put(key, value);
		}

		public void remove(int index) {
			this.map.remove(list.get(index));
			this.list.remove(index);
		}

		public int searchValue(int key) {
			return this.map.get(this.list.get(search(key)));
		}

		public int getKey(int index) {
			return this.list.get(index);
		}

		private int search(int key) {
			var min = 0;
			var max = this.list.size();
			while (max - min > 1) {
				var mid = min + (max - min) / 2;
				if (this.list.get(mid) <= key) {
					min = mid;
				} else {
					max = mid;
				}
			}

			if (max - min == 1 && this.list.get(min) <= key) {
				min++;
			}
			return min;
		}
	}
}

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

const int MAXN = 100000;

int N, S, W, Q;
int a[MAXN + 10];
map<int, int> Cnt;

void a_table()  {
    int g = S;
    for(int i=0; i<N; i++) {
        a[i] = (g/7) % 10;
        if( g%2 == 0 ) { g = (g/2); }
        else           { g = (g/2) ^ W; }
    }
}

void work() {
    int i, ans = 0, MOD = 0, TEN = 1;

    Cnt.clear();
    Cnt[0] = 1;
    for(i = N - 1; i >= 0; i--)  {
        MOD = (MOD + a[i] * TEN) % Q;
        TEN = TEN * 10 % Q;
        if(a[i] != 0)   {
            ans += Cnt[MOD];
        }
        Cnt[MOD]++;
    }

    cout << ans << endl;
}

int main()  {
    while(scanf("%d%d%d%d", &N, &S, &W, &Q) == 4 && (N || S || W || Q)) {
        a_table();
        if(Q == 5 || Q == 2)
		{
			int ans = 0;
			int cnt = 0;
			for(int i = 0;i < N;i++)
			{
				if(a[i] != 0)cnt++;
				if(a[i] % Q == 0)ans += cnt;
			}
			printf("%d\n",ans);
			continue;
		}
        work();
    }
    return 0;
}

Measured memory_bytes: 5692
using System;

namespace msol
{
    class Program
    {
        static void Main()
        {
            var x = int.Parse(Console.ReadLine());
            Console.WriteLine(GetClass(x));
        }
        static int GetClass(int rate)
        {
            var tmp = rate - (rate % 200);
            return 10 - tmp / 200;
        }
    }
}


Measured memory_bytes: 27524
use std::vec::Vec;
use std::cmp::min;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let (h, w) = read_touple::<usize>();
    let mut grid = vec![];
    for _ in 0..h {
      let t: Vec<char> = read::<String>().chars().collect();
      grid.push(t);
    }

    let dist = grid_bfs(&grid, (0, 0), (h-1, w-1), '#');
    println!("{}", dist[h-1][w-1]);
}

use std::collections::VecDeque;
fn grid_bfs(grid: &Vec<Vec<char>>, start: (usize, usize), goal: (usize, usize), skip: char) ->Vec<Vec<usize>>
{
    assert!(grid.len() > 0);
    assert!(grid[0].len() > 0);

    fn connect_vec(a: usize, b: usize, h: usize, w: usize) -> Vec<(usize, usize)> {
        let mut res = Vec::new();
        // if a > 0 {
        //     res.push((a - 1, b));
        // }
        if a < h - 1 {
            res.push((a + 1, b));
        }
        // if b > 0 {
        //     res.push((a, b - 1));
        // }
        if b < w - 1 {
            res.push((a, b + 1));
        }

        res
    }
    let h: usize = grid.len();
    let w: usize = grid[0].len();
    let mut q = VecDeque::new();
    let mut visit = vec![vec![false; w]; h];
    let mut dist = vec![vec![std::usize::MAX/2; w]; h];
    // init
    let (x, y) = start;
    visit[x][y] = true;
    q.push_back(start);

    dist[x][y] = 0;
    if grid[0][0] == skip {
       dist[0][0] += 1;
    }


    while let Some(now) = q.pop_front() {
        let (a, b) = now;
        for (x, y) in connect_vec(a, b, h, w) {
          if (grid[x][y] == '#' && grid[a][b] == '.')  {
             dist[x][y] = min(dist[a][b] + 1, dist[x][y]);
          } else {
            dist[x][y] = min(dist[a][b], dist[x][y]);
          }
          if !visit[x][y] {
            visit[x][y] = true;
            q.push_back((x, y));
          }
        }
    }
    return dist;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 100000000000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl
 
 
signed main(){
    int A,B;
    cin >> A >> B;
    int Ans=0;
    if(A>B){
        Ans+=A;A--;
    }else{
        Ans+=B;B--;
    }
    if(A>B){
        Ans+=A;A--;
    }else{
        Ans+=B;B--;
    }
    cout << Ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
def main():
    def trial_division(n):
        """
        nの約数のリストをO(sqrt(n))で求める
        """
        divs = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divs.append(i)
                if i != n//i:
                    divs.append(n//i)
        return divs
    N, M = (int(i) for i in input().split())
    ans = 0
    divs = trial_division(M)
    for d in divs:
        if M >= N*d:
            ans = max(ans, d)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull n,i,ans=1,a[100005];

int main(){
	cin>>n;
	
	for(i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]==0){
			cout<<0;
			return 0; 
		}
	}
	
	for(i=1;i<=n;i++){
			if(a[i]==0){
				continue;
			}else if(1000000000000000000ll/ans<a[i]){
				cout<<-1;
				return 0;
			}else{
				ans*=a[i];
			}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4328
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  int key;
  Node *r, *l, *p;

};

Node *root, *NIL;

Node * find(Node *u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->l;
    else u = u->r;
  }
  return u;
}

void insert(int k){
  Node *x = root,*y = NIL, *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->l;
    }
    else{
      x = x->r;
    }
  }

  z->p = y;
  if(y == NIL){
    root = z;
  }
  else{
    if(z->key < y->key){
      y->l = z;
    }
    else{
      y->r = z;
    }
  }
}

void inorder(Node *u){
  if(u == NIL) return;
  inorder(u->l);
  printf(" %d", u->key);
  inorder(u->r);
}

void preorder(Node *u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->l);
  preorder(u->r);
}

int main(){
  int n, i, x;
  string com;

  scanf("%d", &n);

  for(i = 0 ; i < n ; i++){
    cin >> com;
    if(com[0] == 'f'){
      scanf("%d", &x);
      Node *t = find(root, x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(com == "insert"){
      scanf("%d", &x);
      insert(x);
    }
    else if(com == "print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 22084
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	int n;
	while (cin >> n) {
		int ans = n % 39;
		if (!ans)ans = 39;
		printf("3C%02d\n", ans);
	}
}


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

int main(){
    int N;
    cin >> N;
    int count = 0;
    for (int i = 1; i <= N; i += 2){
        int yakusu_count = 0;
        for (int j = 1; j <= i; j++){
            if (i % j == 0){
                yakusu_count++;
            }
        }
        if (yakusu_count == 8){
            count++;
        }
    }
    cout << count << endl;
}


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

using namespace std;
int main(){
  int n;
  cin >> n;
  int ac=0,wa=0,tle=0,re=0;
  
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    if(s=="AC")	ac++;
    if(s=="WA")	wa++;
    if(s=="TLE")	tle++;
    if(s=="RE")	re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 3600
sx,sy,tx,ty = map(int,input().split())
x=tx-sx
y=ty-sy
S="L"
S+="U"*(y+1)
S+="R"*(x+1)
S+="D"*(y+1)
S+="L"*(x)
S+="U"*(y)
S+="R"*(x+1)
S+="D"*(y+1)
S+="L"*(x+1)
S+="U"
print(S)

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

vector<pair<int, int>> edges[100010];
int colors[100010];

void dfs(int x, int p) {
  for (auto pa : edges[x]) {
    int v, w;
    tie(v, w) = pa;
    if (v == p) continue;
    if (w % 2 == 0) colors[v] = colors[x];
    else colors[v] = 1 - colors[x];
    dfs(v, x);
  }
}

void solve() {
  int n;
  cin >> n;
  rep(i, n - 1) {
    int u, v, w;
    cin >> u >> v >> w;
    edges[u].emplace_back(v, w);
    edges[v].emplace_back(u, w);
  }
  dfs(1, -1);
  reps(i, n) {
    cout << colors[i] << '\n';
  }
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
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;
}
vector<ll> getNums(ll N) {
    vector<ll> num(N);
    REP(i, N) {
        cin >> num[i];
    }
    return num;
}
int main() {
    string str;
    cin >> str;

    ll sum = 0;
    for (auto c : str) {
        sum += c - '0';
    }
    cout << ((sum % 9 == 0) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3712
use std::collections::*;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let a: Vec<i64> = sc.vec(n);
    let b: Vec<i64> = a.iter().enumerate().map(|(i, e)| e + (i as i64)).collect();
    let c: Vec<i64> = a.iter().enumerate().map(|(i, e)| (i as i64) - e).collect();
    let mut ans: i64 = 0;
    let mut count: BTreeMap<i64, i64> = BTreeMap::new();
    for i in 0..n {
        ans += *count.entry(c[i]).or_insert(0);
        *count.entry(b[i]).or_insert(0) += 1;
    }
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 17228
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

vector<int> v[101010],art;
vector <pint> bridge;
int low[101010],ord[101010];

void dfs(int& count,int from,int x){
    ord[x]=count++;
    low[x]=ord[x];
    bool isart=false;
    int cnt=0;
    for(auto to:v[x]){
        if(to==from)continue;
        if(ord[to]==-1){
            cnt++;
            dfs(count,x,to);
            if(ord[x]<low[to])bridge.push_back({min(x,to),max(to,x)});
            if(from!=-1&&ord[x]<=low[to])isart=true;
            low[x]=min(low[x],low[to]);
        }
        else low[x]=min(low[x],ord[to]);
    }
    if(from==-1&&cnt>1)isart=true;
    if(isart)art.push_back(x);
}

int main(){
    int n,m;
    cin>>n>>m;
    rep(i,m){
        int s,t;
        cin>>s>>t;
        v[s].push_back(t);
        v[t].push_back(s);
    }
    rep(i,n)ord[i]=low[i]=-1;
    int count=0;
    dfs(count,-1,0);
    sort(bridge.begin(),bridge.end());
    rep(i,bridge.size()){
        cout<<bridge[i].first<<" "<<bridge[i].second<<endl;
    }
    return 0;
}


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

int main()
{
 int N;
 while(cin>>N, N) {
   int ans=0;

  for (int i=1; i<N; i++) {
    int sum=0;
    for (int j=i; sum<N; j++) {
      sum += j;
      if (sum==N) ans++;
    }
  }

  cout << ans << endl;
 }
}

Measured memory_bytes: 1160
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H = I()
    A = [0]
    tmp = LI()
    for i in tmp:
        A.append(i)

    def maxHeapify(A, i):
        l = 2*i
        r = 2*i+1
        if l <= H and A[l] > A[i]:
            largest = l
        else:
            largest = i
        if r <= H and A[r] > A[largest]:
            largest = r

        if largest != i:
            A[i], A[largest] = A[largest], A[i]
            maxHeapify(A, largest)

    def buildMaxHeap(A):
        for i in range(H//2, 0, -1):
            maxHeapify(A, i)

    buildMaxHeap(A)

    ans = ''
    for i in range(1, H+1):
        ans += ' ' + str(A[i])
    print(ans)

if __name__ == '__main__':
    resolve()



Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
int a[101];
int main()
{
	int i,n,sum=0,minn=10000;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	for(i=1;i<=n;i++)
		minn=min(minn,abs(sum-a[i]*n));
	for(i=1;i<=n;i++)
	{
		if(minn==abs(sum-a[i]*n))
		{
			printf("%d",i-1);
			return 0;
		}
	}
    return 0;
}

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

#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define khela_shuru int main()
#define khela_shesh return 0
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vii vector <pair<int, int>>
#define FOR(i,a,b) for(int (i)=(a); i<(b); i++)
#define en '\n'

khela_shuru{

    ///Balsal jinish daka dakir kaaj ekhane

    FAST_IO;

    /// Bhulbhal coding shuru ekhan theke

    int r{};
    cin >> r;

    double PI = acos(-1);
    double c = 2 * PI * r;

    cout << fixed << setprecision(3) << c << endl;

    khela_shesh;
}


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

struct edge{
    int to, cost;
    };

void dfs(int current_node, vector<vector<edge>> &G, stack<edge> &candidate_nodes, vector<int> &color_map){
    for(int i=0;i<G.at(current_node).size();i++){
        edge next_cand = G.at(current_node).at(i);
        //色を塗っておく
        int node = next_cand.to;
        int cost = next_cand.cost;

        if(color_map.at(node)>-1){
            //すでに行ったことがあるのでスキップ
            continue;
        }

        if(cost%2==0){
            //偶数なので同じ色
            color_map.at(node) = color_map.at(current_node)==0? 0:1;
        }else{
            //奇数なので違う色
            color_map.at(node) = color_map.at(current_node)==0? 1:0;
        }

        candidate_nodes.push(next_cand);
    }
    //次に行くところがなくなったらおしまい
    if(candidate_nodes.size()==0){
        return ;
    }
    //次の探索
    edge next_node = candidate_nodes.top();
    candidate_nodes.pop();
    dfs(next_node.to, G, candidate_nodes, color_map);
}

int main(){

    int N;
    cin>>N;


    //グラフの定義
    vector<vector<edge>> G(N+1);
    for(int i=0;i<N-1;i++){
        int u, v, w;
        cin>> u >> v >> w;
        edge a1 = {v,w};
        edge a2 = {u,w};
        G.at(u).push_back(a1);
        G.at(v).push_back(a2);
    }
    vector<int> color_map(N+1);
    for(int i=0;i<N+1;i++){
        color_map.at(i) = -1;
    }
    color_map.at(1) = 0;
    //ここから深さ優先探索をする
    stack<edge> candidate_nodes;
    int current_node = 1;
    dfs(current_node, G, candidate_nodes, color_map);

    for(int i=1;i<color_map.size();i++){
        cout<<color_map.at(i)<<endl;
    }






    return 0;
}

Measured memory_bytes: 6784
#python3

MOD = int(1e9+7)

def main():
    n, m = map(int, input().split())
    a = [int(input()) for _ in range(m)]
    broken = [0]*(n+1)
    for i in a:
        broken[i] = 1; 

    dp = [0]*(n+2)
    dp[n] = 1
    for i in reversed(range(n)):
        if broken[i]:
            dp[i] = 0;
            continue; 
        dp[i] = (dp[i+1] + dp[i+2]) % MOD

    print(dp[0])
main()

Measured memory_bytes: 8616
#include <iostream>

using namespace std;

const int maxx = 5;
int x[maxx];

int main()
{
    for (int i = 0 ; i < 5 ; i++){
        cin >> x[i];
        if (x[i] == 0){
            cout << i + 1;
        }
    }
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>

using namespace std;

void solve()
{
	double a, b, c, d, e, f;
	while(cin >> a >> b >> c >> d >> e >> f)
	{
		double y = (c * d - a * f) / (b * d - a * e);
		double x = (c - b * y) / a;
		printf("%.3f %.3f\n", x, y);
	}
}

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

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

int main() {
  int n,l;
  vector<string> s;
  
  cin>>n>>l;
  for(int i=0;i<n;i++){
    string t;
    cin>>t;
    s.push_back(t);
  }
  
  sort(s.begin(),s.end());
  
  for(int i=0;i<n;i++){
    cout<<s.at(i);
  }
  
}


Measured memory_bytes: 256
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define P pair<int,int>
#define inf 1000000007
//P pa(114,514);   ,vector<P>vec(N,0);
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
ll llmin(ll a,ll b){
  if(a>b) return b;
  else return a;
}
 
//cout << setprecision(123);
int main(){
  int N,M,co=0;
  bool ok=false;
  ll ans=0;
  cin>>N>>M;
  
  vector<int>a(N);
  REP(i,N)cin>>a[i];
  
  vector<pair<int,int>>v(M);
  REP(i,M){
    cin>>v[i].second>>v[i].first;
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  sort(a.begin(),a.end());
    REP(i,M){
      
     for(int j=co;j<co+v[i].second;j++){
       
       if(v[i].first>a[j]){
         a[j]=v[i].first;
       }
       else {
         ok=true;
         break;
       }

     }
      co+=v[i].second;
      if(ok){
        break;
      }
   }
    
  
  
  REP(i,N)ans+=a[i];
  
  
  
  cout << ans <<endl;
}

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

int main(){
    while(true){
        int n, m;
        cin >> n >> m;
        if(n == 0){
            break;
        }
        
        vector< pair<int, int> > pd(n);
        for(int i=0; i<n; i++){
            cin >> pd[i].second >> pd[i].first;
        }
        sort(pd.begin(), pd.end(), greater< pair<int, int> >());
        
        for(int i=0; i<pd.size(); i++){
            if(m <= pd[i].second){
                pd[i].second -= m;
                break;
            }else{
                m -= pd[i].second;
                pd[i].second = 0;
            }
        }

        int ans = 0;
        for(int i=0; i<n; i++){
            ans += pd[i].first * pd[i].second;
        }
        cout << ans << endl;
    }
  
    return 0;
}

Measured memory_bytes: 3100
//                _                                      
//  ___ _ __ ___ (_) __ ___      ___   _ _ __ ___  _ __  
// / __| '_ ` _ \| |/ _` \ \ /\ / / | | | '_ ` _ \| '_ \ 
// \__ \ | | | | | | (_| |\ V  V /| |_| | | | | | | |_) |
// |___/_| |_| |_|_|\__, | \_/\_/  \__,_|_| |_| |_| .__/ 
//                  |___/                         |_|  
//code by smigwump
//https://codeforces.com/blog/entry/62393 hashing hack protection
//https://codeforces.com/blog/entry/61587 rand() alternatives
//https://codeforces.com/blog/entry/61675 randomized hack protection
#include <bits/stdc++.h>
typedef long long ll;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define REP(i,a,b) for(ll i = a; i <= b; i++)
#define PER(i,a,b) for(ll i = a; i >= b; i--)

using namespace std;

int main() {
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
	// #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long double d,t,s;
    cin>>d>>t>>s;
    if((d/s) <= t) {
    	cout<<"Yes\n";
    }
    else {
    	cout<<"No\n";
    }
	return 0;
}

Measured memory_bytes: 3740
N = int(input())
an = [0] + [int(i) for i in input().split()]+[0]
cn = [abs(an[i+1]-an[i]) for i in range(N+1)]
ct = sum(cn)
cs = [ct-cn[i]-cn[i+1]+abs(an[i]-an[i+2]) for i in range(N)]
print('\n'.join(map(str,cs)))


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

int main() {
    string s;
    cin >> s;
    if (s == "Sunny") cout << "Cloudy" << endl;
    else if (s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;

    return 0;
}

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

import collections

n = int(input())
balls = list(map(int, input().split(' ')))

dic = collections.Counter(balls)
total = 0
for v in dic.values():
    if (v < 2):
        continue
    total += int(v * (v - 1) / 2)

for i in range(n):
    num = balls[i]
    print(total - dic[num] + 1)


Measured memory_bytes: 26780
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <list>
#include <vector>
#include <map>
#include <time.h>
#include <cstdlib>
#include <iomanip>
#include <array>

#pragma warning(disable:4996)

using namespace std;

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



int main(void) {
	string str, dd = {"CODEFESTIVAL2016"};
	int ans = 0;
	cin >> str;
	FOR(i, 0, str.length()) {
		if (str[i] != dd[i])ans++;
	}
	cout << ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}


vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

  ll n, p;
  cin >> n >> p;

  auto ev = prime_factorize(p);
  ll ans = 1;
  for(auto p : ev){
    for(ll j = 0; j < p.second/n; j++) ans *= p.first;
  }
  cout << ans << endl;
  return 0;
}

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

struct RollingHash{
  typedef unsigned long long ull;
  string S;
  ull B;
  int len;
  vector<ull> hash,p;
  RollingHash(){}
  RollingHash(string S_,ull B_=1000000007LL):
    S(S_),B(B_),len(S.length()),hash(len+1),p(len+1){
    hash[0]=0;p[0]=1;
    for(int i=0;i<len;i++){
      hash[i+1]=hash[i]*B+S[i];
      p[i+1]=p[i]*B;
    }
  }
  ull find(int l,int r){
    return hash[r]-hash[l]*p[r-l];
  }
};

int main(){
	string a,b;
	cin>>a>>b;
	RollingHash A(a),B(b);
	for(int i=0;i+b.size()<=a.size();i++){
		if(A.find(i,i+b.size())==B.find(0,b.size()))cout<<i<<endl;
	}
}


Measured memory_bytes: 20516
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLine >>= print . solve 

-- | 
-- >>> solve [81,58]
-- 110
-- >>> solve [4,54]
-- 31
solve :: [Int] -> Int
solve [x, y] = x + y `div` 2

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

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

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

    ll L[N], kind = 0;
    REP(i, N) {
        cin >> L[i];
        
        int tmp = 0;
        REP(j, i) {
            if(L[j] == L[i]) {
                tmp ++;
            }
        }
        if(tmp == 0) {
            kind ++;
        }
    }
    sort(L, L + sizeof(L)/sizeof(*L));

    ll ans = 0;
    FOR(i, 0, N - 1) {
        ll cnt = 1;
        if(L[i] == L[i + 1]) {
            while(i < N && L[i] == L[i + 1]) {
                cnt++;
                i++;
            }
        }

        ll cnt2 = 0;
        FOR(j, i + 1, N - 1) {
            ll dj = 1;
            while(j < N - 1 && L[j] == L[j + 1]) {
                j++;
                dj ++;
            }

            FOR(h, j + 1, N) {
                ll dh = 0;
                if(L[h] > abs(L[i] - L[j]) && L[h] < L[i] + L[j]) {
                    dh ++;
                    while(h < N - 1 && L[h] == L[h + 1]) {
                        h++;
                        dh ++;
                    }
                    cnt2 += dj * dh;
                }
            }
        }
        
        ans += cnt*cnt2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3592