akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var A = ReadLine().Split(' ').Select(int.Parse).OrderByDescending(a => a).ToArray();

        var ans = A[0] - A[1] + A[1] - A[2];

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 28400
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    ll tmp = 100;
    ll x;
    cin >> x;
    int cnt = 0;

    while(tmp < x){
        tmp = tmp*1.01;
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}


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

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> p(N);
  for(int i=0;i<N;++i) cin>>p[i];

  sort(p.begin(),p.end());
  int sum=0;
  for(int i=0;i<K;++i) sum += p[i];

  cout<<sum<<endl;
}


Measured memory_bytes: 3632
MAX = 55555
p = [1]*(MAX+1)
p[0], p[1] = 0, 0
pp = []

for i in range(2, MAX, 2):
  p[i] = 0

for i in range(3, int(MAX**0.5)+1, 2):
  if p[i]:
    for j in range(i*2, MAX, i):
      p[j] = 0

for i in range(MAX+1):
  if p[i] and i%5==1:
    pp.append(i)

n = int(input())
print(" ".join(map(str, pp[:n])))

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

using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
const ll INF = 1001001000100010;
const ld PI = 3.14159265358979323846;


int main() {
int A,B,C,X,Y,Z=0;
cin>>A>>B>>C>>X>>Y;
if((A+B)<=2*C){
    cout<<A*X+B*Y<<endl;
    
}
else{
    while((X>=1)&&(Y>=1)){
        X--;Y--;Z+=2;
    }
    if((A>2*C)&&(X>0)){
        while(X>0){
            X--;Y--;Z+=2;
        }
    }
    if((B>2*C)&&(Y>0)){
        while(Y>0){
            X--;Y--;Z+=2;
        }
    }
    cout<<A*max(0,X)+B*max(0,Y)+C*Z<<endl;
}
return 0;
}



Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Add Sub Mul
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  printf("%d\n", max(max(a + b, a - b), a * b));
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main(){
long long n;
cin>>n;
long long sum=0;
for(long long i=0;i<n;i++){
long long u=0;
cin>>u;
sum+=u;
}
cout<<sum/n<<endl;
 
}


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

void shakespeare() {
  string a,b,c;
  cin >> a >> b >> c;
  cout << a.at(0) << b.at(0) << c.at(0) << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt=1;
  //cin >> tt;
  while(tt--) shakespeare();
 
  return 0;
}

Measured memory_bytes: 3632
n,m = map(int, input().split())
ans = 0
buf = [0]*m
for i in range(n):
  a = list(map(int, input().split()))[1:]
  for j in a:
    buf[j-1] += 1

for a in buf:
  if a == n:
    ans += 1

print(ans)    

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
void dfs(graph &G, vector< int > &ans, int x, int p, int c) {
	ans[x] = c;
	for (auto e : G[x]) {
		if (e.to == p)
			continue;
		int nc = c;
		if (e.d & 1) {
			nc = 1 - c;
		}
		dfs(G, ans, e.to, x, nc);
	}
}
signed main() {
	cin >> N;
	graph G(N);
	rep(i, N - 1) {
		int u, v, w;
		cin >> u >> v >> w;
		--u;
		--v;
		G[u].emplace_back(u, v, w);
		G[v].emplace_back(v, u, w);
	}
	vector< int > ans(N);
	dfs(G, ans, 0, -1, 0);
	rep(i, N) cout << ans[i] << endl;
	return 0;
}

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

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

  ll n;
  cin >> n;
  int l = 0,  r = n-1;
  string sl, sr;
  cout << l << endl;
  cin >> sl;
  cout << r << endl;
  cin >> sr;

  if(sl == "Vacant" || sr == "Vacant")
    return 0;
  while(true) {
    int m = (l + r + 1) / 2;
    cout << m << endl;
    string sm;
    cin >> sm;
    if(sm == "Vacant")
      return 0;

    if( ((m-l) + (sm == sl)) % 2 == 0) {
      r = m;
      sr = sm;
    } else {
      l = m;
      sl = sm;
    }
  }
}


Measured memory_bytes: 852
n, a, b = map(int, input().split())

ans = (b-a)//2
if a%2 == b%2:
    print(ans)
else:
    if a-1 >= n-b:
        ans += n-b+1
        a = a+n-b+1
        b = n
        print(ans)
    elif n-b > a-1:
        ans += a
        b = b-a
        a = 1
        print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int N = 1005;

int n, m, a, b;
int c[N][N];
int s[N];
int d[N];

int cmp(int x, int y) { return s[x] > s[y];}

int main() {
	//freopen("a.in", "r", stdin);
	scanf("%d %d %d %d", &n, &m, &a, &b);
	fo(i, 1, m) d[i] = i;
	fo(i, 0, n) fo(j, 0, m) {
		if(a * i + (m - a) * (n - i) == b * j + (n - b) * (m - j)) {
			//pp("%d %d %d\n", i, j, a * i + (m - a) * (n - i));
			fo(k, 1, j) s[k] = b;
			fo(k, j + 1, m) s[k] = n - b;
			fo(k, 1, n) {
				int len = k <= i ? a : m - a;
				sort(d + 1, d + m + 1, cmp);
				fo(u, 1, len) {
					int x = d[u];
					s[x] --;
					c[k][x] = 1;
					//pp("%d %d %d\n", k, x, c[k][x]);
				}
			}
			fo(x, 1, n) {
				fo(y, 1, m) pp("%d", c[x][y]);
				hh;
			}
			return 0;
		}
	}
}


Measured memory_bytes: 5120
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {

		Scanner sc = new Scanner(System.in);
		int s = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());

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

}


Measured memory_bytes: 26992
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define min(a,b) ((a)<(b) ? (a):(b))
#define max(a,b) ((a)>(b) ? (a):(b))

int gcd(int a, int b){
    while( b ){
        int m = a % b;
        a = b;
        b = m;
    }
    return a;
}

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

int isPrim(int a){
    if(a==1){
        return 0;
    }
    for(int i=2;i<=(a+1)/2;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}

long long mod_pow(long long x, long long n, long long mod){
    //xのn乗を計算するのにn乗を2進表記にして計算
    //x^22 = x^16 + x^4 + x^2
    long long ret=1;
    while(n>0){
        if(n%2==1){
            ret=(ret*x)%mod;//答えに付加
        }
        x=(x*x)%mod;//2乗
        n=n/2;
    }
    return ret;
}

struct VV{
    int x;
    int y;
    int z;
};

class LessInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        if(riLeft.x == riRight.x){
            return riLeft.y > riRight.y;
        }
        return riLeft.x > riRight.x;
        
    }
};

class indInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        return riLeft.x < riRight.x;
        
    }
};

struct XX{
    long long a;
    long long b;
};

class xxIntu {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第1条件
        if(riLeft.a != riRight.a){
            return riLeft.a > riRight.a;//<:昇順(小さい順)、>:降順(大きい順)
        }
        //第2条件
        return riLeft.b > riRight.b;
    }
};
bool operator< (const XX &riLeft, const XX &riRight){
    return riLeft.a < riRight.a;
};
bool operator> (const XX &riLeft, const XX &riRight){
    return riLeft.a > riRight.a;
};


int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //getline(cin, target);
    //cin >> x >> y;
    //ここから
    
    long long N,L;
    cin >> N >> L;

    vector<XX> a;
    a.clear();
    
    for(long long i=0;i<N;i++){
        long long tmp;
        cin >> tmp;
        XX v;
        v.a=tmp;
        v.b=i;
        a.push_back(v);
    }
    int f=0;
    vector<long long> ans;
    ans.clear();
    

    long long i;
    for(i=0;i<a.size()-1;i++){
        if(a[i].a+a[i+1].a>=L){
            f=1;
            ans.push_back(i+1);
            break;
        }
    }
    for(long long j=i+1;j<a.size()-1;j++){
        ans.push_back(j+1);
    }
    for(long long j=i;j>0;j--){
        ans.push_back(j);
    }
    
    if(f==0){
        cout << "Impossible" << endl;
    }else{
        cout << "Possible" << endl;
        for(int i=0;i<ans.size();i++){
            cout << ans[ans.size()-1-i] << endl;
        }
    }
    
    //ここまで
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}

Measured memory_bytes: 4208
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    fast_io();
    int x;
    cin >> x;
    if (x >= 30)
        cout << "Yes\n";
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define graph vector< vector<int> >
#define vs vector<string>
/**  '' "\n" ^ -  =**/

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    sf(n);
    vector<pair<int,int> > a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++)
    {
        cout<<a[i].second+1;ps();
    }
}


Measured memory_bytes: 1664
#import re
import sys
input = sys.stdin.readline
#import heapq
#import bisect
#from collections import deque
#import math

def main():
    n = int(input())
    A = list(map(int, input().split()))
    Ans = [0]*n
    for i in range(n-1):
        Ans[A[i]-1] += 1
    for i in range(n):
        print(Ans[i])

    


    
if __name__ == '__main__':
    main()


Measured memory_bytes: 91400
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << endl
#define print10(ele) cout << fixed << setprecision(10) << (ele) << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  REP(i, 4) {
    if (s[i] == '+')
      ans++;
    else
      ans--;
  }
  print(ans);
  return 0;
}

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

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var split = Console.ReadLine().Split(' ');
            max(split);
        }
        public static void max(string[] split){
            var A = int.Parse(split[0]);
            var B = int.Parse(split[1]);
            var C = int.Parse(split[2]);
            if(A>B){
                if(C>B){
                        if(A>C)Console.WriteLine(A*10+B+C);
                        else Console.WriteLine(C*10+B+A);
                }else{
                        Console.WriteLine(A*10+B+C);
                }
            }else{
                if(A>C)Console.WriteLine(B*10+A+C);
                else {
                    if(B>C)Console.WriteLine(B*10+A+C);
                    else Console.WriteLine(C*10+A+B);
                }
            }
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<cmath>
#define REP(i,s,n) for(int i=0;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace  std;

int main(){
  int n; cin >> n;
  // cout << n;
  // double c; cin >> c;
  // cout << c;
  double xa, ya, ra, xb, yb, rb;
  rep(i,n){
    cin >> xa >> ya >> ra >> xb >> yb >> rb;
    // cout << xa << ya << ra << xb << yb << rb;
    double rd2 = sqrt(pow((xa-xb),2) +pow((ya-yb), 2));
    if(ra+rb<rd2) cout<<0<<endl;
    else if(ra>rb+rd2) cout<<2<<endl;
    else if(rb>ra+rd2) cout<<-2<<endl;
    else cout<<1<<endl;
  }
  return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
#define s second
#define f first
const int MOD = 1e9+7;
using namespace std;

ll llmax(ll x, ll y){
	if (x > y) return x;
	return y;
}

ll llmin(ll x, ll y){
	if (x > y) return y;
	return x;
}

bool is_prime(int x){
	for (int i = 2; i*i <= x; i++){
		if (!(x%i)) return false;
	}
	return true;
}


int main(){
	int n, k, r, s, p, ans = 0;
	string t;
	cin >> n >> k >> r >> s >> p >> t;
	vector<char> vec(n);

	for (int i = 0; i < k; i++){
		if (t[i] == 'r'){
			vec[i] = 'p'; 
		}else if (t[i] == 's'){
			vec[i] = 'r';
		}else{
			vec[i] = 's';
		}
	}

	for (int i = k; i < n; i++){
		if (t[i] == 'r' && vec[i-k] != 'p'){
			vec[i] = 'p'; 
		}else if (t[i] == 's' && vec[i-k] != 'r'){
			vec[i] = 'r';
		}else if (t[i] == 'p' && vec[i-k]!= 's'){
			vec[i] = 's';
		}else{
			vec[i] = 'n';
		}
	}

	for (int i = 0; i < n; i++){
		if (vec[i] == 'r') ans += r;
		if (vec[i] == 's') ans += s;
		if (vec[i] == 'p') ans += p;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 512
#include <cstdio>
#include <cmath>
using namespace std;
int N, M, num[4];
int main() {
  scanf("%d %d", &N, &M);
  for(int i = 0; i <= 3; ++i) num[i] = -1;
  bool ok = true;
  for(int i = 0, s, c; i < M; ++i) {
    scanf("%d %d", &s, &c);
    if(num[s] < 0) num[s] = c;
    else if(num[s] != c) ok = false;
  }
  if(N > 1 && num[1] == 0) ok = false;
  if(N > 1 && num[1] < 0) num[1] = 1;
  if(N == 1 && num[1] < 0) num[1] = 0;
  for(int i = 1; i <= 3; ++i) {
    if(num[i] < 0) num[i] = 0;
  }
  int ans = 0;
  if(ok) {
    for(int i = 1; i <= N; ++i) {
      ans += num[i]*pow(10, N-i);
    }
  } else {
    ans = -1;
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 128
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


N = int(input())
a = int(input())

print(N*N-a)

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main () {
    int n, m;
    cin >> n >> m;

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

    int road[50] = {0};
    for (int i = 0; i < m; i++) {
        road[a[i] - 1]++;
        road[b[i] - 1]++;
    }

    for (int i = 0; i < n; i++) {
        cout << road[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
//#include "debug.cpp"

int mod(int n,int m){
    n%=m;
    n+=m;
    return n%m;
}

int power(int a,int b,int m){
    int ans=1;
    while(b>0){
        if(b&1)
            ans=mod(ans*a,m);
        a=mod(a*a,m);
        b/=2;
    }
    return ans;
}

int32_t main() 
{ 
    boost;
    int n,p;
    cin>>n>>p;
    string s;
    cin>>s;
    int ans=0;
    if(p==2 or p==5){
        for(int i=0;i<n;i++){
            if((s[i]-'0')%p==0)
                ans+=i+1;
        }
        cout<<ans<<endl;
        return 0;
    }
    int mp[p+1]={0};
    mp[0]=1;
    int cur=0;
    for(int i=0;i<n;i++){
        cur=cur+(s[i]-'0')*power(10,n-i+1,p);
        cur=mod(cur,p);
        mp[cur]++;
    }

    for(int i=0;i<p;i++)
        ans+=mp[i]*(mp[i]-1)/2;
    cout<<ans<<endl;
}


Measured memory_bytes: 720
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n;
  int s[SIZE];
  int dp[101][10] = {};

  scanf("%d",&n);

  for(int i=0;i<=n;i++){
    for(int j=0;j<10;j++){
      dp[i][j] = -INF;
    }
  }

  dp[0][0] = 0;
  
  for(int i=0;i<n;i++){
    scanf("%d",s+i);

    for(int j=0;j<10;j++){
      dp[i+1][j] = max(dp[i][j], dp[i+1][j]);
      dp[i+1][(j+s[i])%10] = max(dp[i+1][(j+s[i])%10], dp[i][j]+s[i]);
    }
    
  }

  int ans = 0;
  
  for(int i=1;i<10;i++){
    ans = max(ans, dp[n][i]);
  }

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


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++)

struct city{
		int x,y,i;
		city(){};
		city(int x_,int y_,int i_){
			x=x_,y=y_,i=i_;
		};

};

struct edge{
			int cst,e1,e2;
		edge(){};
		edge(int cst_,int e1_,int e2_){
			cst=cst_,e1=e1_,e2=e2_;
		};
		bool operator<(const edge& o)const{return cst>o.cst;}			
};

struct unionFind{
	size_t n;
	vector<int> pr;
	unionFind(size_t n_){
		n=n_;
		pr.resize(n,-1);
	};
	int root(int a){
		if(pr[a]==-1)return a;
		else return pr[a]=root(pr[a]);
	}
	void unify(int a,int b){
		a=root(a);b=root(b);
		if(a==b)return;
		pr[b]=a;
	}
	bool same(int a,int b){return root(a)==root(b);}
};


signed main(){
	size_t n;cin>>n;
	vector<city>c(n);
	rep(i,n){cin>>c[i].x>>c[i].y;c[i].i=i;}
	priority_queue<edge> pq;
	sort(begin(c),end(c),[&](const city a,const city b){return a.x<b.x;});
//	for(auto&& u:c)cerr<<u.i<<" ";
//	cerr<<endl;
	rep(i,n-1)pq.push(edge(c[i+1].x-c[i].x,c[i].i,c[i+1].i));

	sort(begin(c),end(c),[&](const city a,const city b){return a.y<b.y;});
//	for(auto&& u:c)cerr<<u.i<<" ";
//	cerr<<endl;

	rep(i,n-1)pq.push(edge(c[i+1].y-c[i].y,c[i].i,c[i+1].i));

	unionFind uf(n);
	int cnt=0,sm=0;
	while(!pq.empty()){
	edge x=pq.top();pq.pop();
//	cerr<<x.cst<<" "<<x.e1<<" "<<x.e2<<endl;
      if(uf.same(x.e1,x.e2))continue;
		uf.unify(x.e1,x.e2);
		cnt++;sm+=x.cst;	
		if(cnt==n-1)break;
	}	
	cout<<sm<<endl;

	
	
	 
}

Measured memory_bytes: 10864
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007
#define MAXS(x,y) (x = max(x,y))
#define MINS(x,y) (x = min(x,y))

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;

int dp[3001][3001];

void print_lcs(string &s, string &t, int i, int j){
  // printf("%d %d\n",i,j);
  if(i == 0 || j == 0){
    return;
  }

  // printf("%c %c\n",s[i-1],t[j-1]);
  // printf("%d %d %d\n", dp[i-1][j-1],dp[i-1][j], dp[i][j-1]);
  if(s[i-1] == t[j-1]){
    print_lcs(s,t,i-1,j-1);
    cout << s[i-1];
  }else{
    if(dp[i-1][j] >= dp[i][j-1]){
      print_lcs(s,t,i-1,j);
    }else{
      print_lcs(s,t,i,j-1);
    }
  }
}

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

  REP(i,3001)REP(j,3001)dp[i][j] = 0;

  FOR(i,1,s.size()+1)FOR(j,1,t.size()+1){
    if(s[i-1] == t[j-1]){
      MAXS(dp[i][j], dp[i-1][j-1]+1);
    }else{
      MAXS(dp[i][j], dp[i-1][j]);
      MAXS(dp[i][j], dp[i][j-1]);
    }
  }

  // REP(i,s.size()+1){
  //   REP(j,t.size()+1){
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  print_lcs(s,t,s.size(),t.size());
  cout << endl;
}

Measured memory_bytes: 35968
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
	int n, m; cin >> n >> m;
	vi l(m), r(m);
	rep(i, m) cin >> l[i] >> r[i];
	int L, R;
	L = *max_element(l.begin(), l.end());
	R = *min_element(r.begin(), r.end());
	int ans = min(R, n) - max(L, 1) + 1;
	if (L <= R) cout << ans << endl;
	else cout << 0 << endl;
}


Measured memory_bytes: 1024
import sys
import itertools

import numpy as np


def main():
    def readline() -> str:
        s = sys.stdin.readline()
        return s.rstrip()

    h, w, k = map(int, readline().split())  # type: int, int, int
    field: np.ndarray = np.array(
        tuple(
            tuple(0 if c == "." else 1 for c in readline()) for _ in range(h)
        )
    )

    answer: int = 0

    for pattern_num in range(2 ** (h + w)):
        test_field = field.copy()
        pattern_num_bin = format(pattern_num, f"0{h+ w}b")
        h_bin: str = pattern_num_bin[:h]
        w_bin: str = pattern_num_bin[h:]

        for row in range(h):
            if h_bin[row] == "1":
                test_field[row] = np.ones((w,)) * 2

        for column in range(w):
            if w_bin[column] == "1":
                test_field[:, column] = np.ones((h,)) * 2

        if np.sum(test_field == 1) == k:
            answer += 1

    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27152
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, a: i64, b: i64, c: i64, mut k: i64);
    let mut ret = 0i64;
    if a <= k {
        k -= a;
        ret = a;
    } else {
        ret = k;
    }
    if b <= k {
        k -= b;
    } else {
        k = 0;
    };
    if c <= k {
        ret -= c;
    } else {
        ret -= k;
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

int main(){
  int A;
  int B;
  int C;
  cin >> A >> B >> C;
  
  if(A+B+C <= 21){
    cout << "win" << endl;
  }
  
  else{
    cout << "bust" << endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,n,m;
    cin>>a>>b>>c>>n>>m;
    if(a+b<2*c){
        cout<<a*n+b*m;
    }
    else{
        long kq;
        if(m>=n){
            kq=min(m*2*c,n*2*c+(m-n)*b);
            cout<<kq;
        }
        else{
            kq=min(n*2*c,m*2*c+(n-m)*a);
            cout<<kq;
        }
    }
}

Measured memory_bytes: 256
D=int(input())
*c,=map(int,input().split())
# for Greedy
ci=[(c[i-1],i) for i in range(1,27)]
ci=[(0,0)]+ci
# ci=[(0,0)]+sorted(ci,reverse=True)

last=[[0]*27]*(D+1)
S=[[0]*27]*(D+1)
DP=[[0]*27]*(D+1)
T=[0]*(D+1)

for d in range(1,D+1):
    *S[d],=map(int,input().split())
    S[d]=[0]+S[d]
    
for d in range(1,D+1):
    T[d] = int(input())

def do_id(i,d):
    dn=0
    last[d][i]=d    
    for k in range(1,27):
      if k!=i:
        dn += ci[k][0]*(d-last[d][k])
    return S[d][i]-dn

Satis=0  
for d in range(1,D+1):
    Satis+=do_id(T[d],d)
    print(Satis)
  
def cal():  
  for d in range(1,D+1):
    mxid=0
    mxi,mxd=0,0
    for i in range(1,27):
      tc,ti=ci[i]
      doid=do_id(ti,d)
      if doid>mxid:
           mxid=doid
           mxi,mxd=ti,d
    DP[mxd][mxi]=mxid             
    last[mxd][mxi]=d
  print(DP)    
    



Measured memory_bytes: 9396
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
using namespace std;
const int MAX = 1e5 + 10;
const ll MOD = 1e9 + 7;
int N, M, K, Q;
queue<int> v2, v3, v6;

int main()
{
	int i, j, k;
	scanf("%d", &N);
	if (N == 3) {
		printf("2 5 63");
		return 0;
	}
	for (i = 2; i <= 30000; i+=2) {
		if (i % 3 == 0) v6.push(i);
		else if(i%3 == 1 || i%3 == 2) v2.push(i);
	}
	for (i = 3; i <= 30000; i += 2) {
		if (i % 3 == 0) v3.push(i);
	}
	int cnt = N / 2;
	vector<int> ans;
	ans.push_back(v3.front());
	v3.pop();
	ans.push_back(v3.front());
	v3.pop();
	cnt--;
	while (cnt--) {
		if (!v2.empty()) {
			ans.push_back(v2.front());
			v2.pop();
			ans.push_back(v2.front());
			v2.pop();
		}
		else if (!v3.empty()) {
			ans.push_back(v3.front());
			v3.pop();
			ans.push_back(v3.front());
			v3.pop();
		}
		else if (!v6.empty()) {
			ans.push_back(v6.front());
			v6.pop();
			ans.push_back(v6.front());
			v6.pop();
		}
	}
	if (N % 2) {
		ans.push_back(30000);
	}
	for (i = 0; i <ans.size(); ++i) {
		printf("%d ", ans[i]);
	}
	
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std; 
#define deb(x) cout << #x <<"="<< x <<endl;
#define deb2(x,y) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<endl;
#define deb3(x,y,z) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<<endl;
#define deb4(x,y,z,a) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<< ", "<<#a <<"="<<a << endl;
#define debarr(x) cout << #x<<"::"<<endl;for(int i : x){cout << i <<" ";} cout <<endl;
#define rep(i,n) for(int i=0;i<(n);i++)
#define fr(i,a,b) for(int i=(a);i<(b);i++)
#define frd(i,a,b) for(int i=(a);i>=(b);i--)
#define vi vector<int>
#define int long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'
#define fi first
#define se second
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)

#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define print2(a) for(auto x:a){for(auto y:x)cout<<y<<" ";cout<<endl;}; 



void solve(){
	int n, m , x;
	cin >> n >> m >> x;
	vector <vi> arr;
	arr.resize(n);
	int cnt = 0;
	
	map <int,int> mm;
	
	rep(i,n){
		int x1;
		cin >> x1;
		rep(j,m){
			int y;
			cin >> y;
			arr[cnt].pb(y);
		}
		mm[cnt] = x1;
		++cnt;
		
	}
	
	int mn = 1e18;
	
	for(int i = 0 ; i < (1<<n) ; i++){
		vi skills(m,0);
		int cst = 0;
		
		for(int j = 0 ; j < n ; ++j){
			if(i & (1 << j)){
				cst += mm[j];
				for(int k1 = 0 ; k1 < m ; ++k1){
					skills[k1] += arr[j][k1];
				}
				
			}
			
		}
		
		sort(all(skills));
		
		if(skills[0] >= x){
			mn = min(cst, mn);
		} 
		
	}
	
	if(mn == 1e18){cout << -1 << endl; return;}
	
	cout << mn << endl;



}





signed main(){
    cin.tie(NULL),ios_base::sync_with_stdio(false),cout.tie(NULL);
    int t=1;

    while(t--)solve();
    return 0;
}



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

int main() {
    int N, K; cin >> N >> K;
    vector<double> S(N + 1, 0);
    for(int i=0; i<N; ++i) {
        int a; cin >> a;
        S[i + 1] = S[i] + (a + 1) / 2.0;
    }

    double res = 0;
    for(int i=K; i<=N; ++i) {
        res = max(res, S[i] - S[i - K]);
    }
    cout << fixed << setprecision(10) << res << endl;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

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

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

char s[MAXN];
int cnt[200];

void solve(){
	int n;
	scanf("%d%s", &n, &s[0]);
	REP(i, 0, n) {
		cnt[s[i]]++;
	}
	if (cnt['R'] > cnt['B']) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

int main() {
  int n;
  cin>>n;
  vector<int> h(n);
  rep(i,n){
    cin>>h[i];
  }
  reverse(h.begin(),h.end());
  bool ans=true;
  rep(i,n-1){
    if(h[i+1]-h[i]>=2){
      ans=false;
    }else if(h[i+1]-h[i]==1){
      h[i+1]--;
    }
  }
  if(ans){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
const double PI = acos(-1.0);
const string ALP = "abcdefghijklmnopqrstuvwxyz";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int main(){
  int n,p;
  cin >> n;
  vector<int> a(n);
  vector<bool> b(n);
  REP(i,n){
    cin >> a[i];
    a[i]--;
    b[i]=false;
  }
  p=0;
  for(int i=0;;i++){
    b[p]=true;
    p=a[p];
    if(b[p]){
      cout << -1;
      break;
    }
    if(p==1){
      cout << ++i;
      break;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include <iostream>
#include <string.h>
#include <cstdlib>

using namespace std;

#define BUF_SIZE 1024

struct Node{
	int data;
	Node* prev;
	Node* next;
};

class ConnectedList{
public:
	ConnectedList(){
		motherNode = new Node();
		motherNode->data = -1;
		motherNode->prev = motherNode;	
		motherNode->next = motherNode;
	};
	~ConnectedList(){
		Node* tmpNode = motherNode->next;
		Node* nextNode;
		while(tmpNode != motherNode){
			nextNode = tmpNode->next;
			delete tmpNode;
			tmpNode = nextNode;
		}
		delete motherNode;
	};
	void insertNode(int x){
		Node* tmpNode = motherNode->next;
		motherNode->next = new Node();
		motherNode->next->data = x;
		motherNode->next->next = tmpNode;
		motherNode->next->prev = motherNode;
		tmpNode->prev = motherNode->next;
	};
	void deleteNode(int x){
		Node* tmpNode = motherNode->next;
		while(tmpNode != motherNode && tmpNode->data != x){
			tmpNode = tmpNode->next;
		}
		if(tmpNode != motherNode){	
			tmpNode->prev->next = tmpNode->next;
			tmpNode->next->prev = tmpNode->prev;
			delete tmpNode;
		}
	};

	void deleteFirst(){
		Node* tmpNode = motherNode->next;
		motherNode->next = motherNode->next->next;
		motherNode->next->prev = motherNode;
		delete tmpNode;	
	};

	void deleteLast(){
		Node* tmpNode = motherNode->prev;
		motherNode->prev = motherNode->prev->prev;
		motherNode->prev->next = motherNode;
		delete tmpNode; 
	};

	void showList(){
		Node* tmpNode = motherNode->next;
		printf("%d",tmpNode->data);
		tmpNode = tmpNode->next;
		while(tmpNode != motherNode){
			printf(" %d",tmpNode->data);
			tmpNode = tmpNode->next;
		}
		printf("\n");
	}

private:
	Node* motherNode;
};


int main(){

	char buf[BUF_SIZE];
	int n = atoi(fgets(buf,BUF_SIZE,stdin));

	ConnectedList list;

	for(int i = 0; i < n; i++){

		fgets(buf,BUF_SIZE,stdin);

		if(buf[6] == 'F'){
			list.deleteFirst();
		}else if(buf[6] == 'L'){
			list.deleteLast();
		}else{
			int S = 0;
			
			if(buf[0] == 'i'){	//insert x

				for(int i = 0; buf[i] != '\0';i++){
					if(buf[i] >= '0' && buf[i] <= '9'){
						S = 10*S + (buf[i] - '0');
					}
				}
				list.insertNode(S);
			}else{	
				for(int i = 0;buf[i] != '\0';i++){
					if(buf[i] >= '0' && buf[i] <= '9'){
						S = 10*S + (buf[i] - '0');
					}
				}
				list.deleteNode(S);
			}

		}

	}

	list.showList();

}

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

const int INF = 100000000;
const int M = 200000;

vector<int> v1[4][400002];
vector<int> v2[2][200002];

int main()
{
    int n;
    cin >> n;
    int x[200002], y[200002];
    char u[200002];
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> u[i];
        if(u[i] == 'U'){
            v1[0][x[i] + y[i]].push_back(x[i]);
            v1[1][y[i] - x[i] + M].push_back(x[i]);
            v2[0][x[i]].push_back(y[i]);
        }
        if(u[i] == 'D'){
            v1[2][x[i] + y[i]].push_back(x[i]);
            v1[3][y[i] - x[i] + M].push_back(x[i]);
        }
        if(u[i] == 'R'){
            v2[1][y[i]].push_back(x[i]);
        }
    }
    for(int i = 0; i < 4; i++){
        for(int j = 0; j <= 400000; j++) sort(v1[i][j].begin(), v1[i][j].end());
    }
    for(int i = 0; i < 2; i++){
        for(int j = 0; j <= 200000; j++) sort(v2[i][j].begin(), v2[i][j].end());
    }
    int ans = INF;
    for(int i = 0; i < n; i++){
        if(u[i] == 'D'){
            auto itr = lower_bound(v2[0][x[i]].begin(), v2[0][x[i]].end(), y[i]);
            if(itr != v2[0][x[i]].begin()){
                ans = min(ans, (y[i] - *--itr) * 5);
            }
        }
        if(u[i] == 'R'){
            auto itr1 = lower_bound(v1[0][x[i] + y[i]].begin(), v1[0][x[i] + y[i]].end(), x[i]);
            if(itr1 != v1[0][x[i] + y[i]].end()){
                ans = min(ans, (*itr1 - x[i]) * 10);
            }
            auto itr2 = lower_bound(v1[3][y[i] - x[i] + M].begin(), v1[3][y[i] - x[i] + M].end(), x[i]);
            if(itr2 != v1[3][y[i] - x[i] + M].end()){
                ans = min(ans, (*itr2 - x[i]) * 10);
            }
        }
        if(u[i] == 'L'){
            auto itr1 = lower_bound(v2[1][y[i]].begin(), v2[1][y[i]].end(), x[i]);
            if(itr1 != v2[1][y[i]].begin()){
                ans = min(ans, (x[i] - *--itr1) * 5);
            }
            auto itr2 = lower_bound(v1[2][x[i] + y[i]].begin(), v1[2][x[i] + y[i]].end(), x[i]);
            if(itr2 != v1[2][x[i] + y[i]].begin()){
                ans = min(ans, (x[i] - *--itr2) * 10);
            }
            auto itr3 = lower_bound(v1[1][y[i] - x[i] + M].begin(), v1[1][y[i] - x[i] + M].end(), x[i]);
            if(itr3 != v1[1][y[i] - x[i] + M].begin()){
                ans = min(ans, (x[i] - *--itr3) * 10);
            }
        }
    }
    if(ans == INF) cout << "SAFE" << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 67616
#include<stdio.h>
#include<algorithm>
using namespace std;
long long gcd(long long a,long long b){
	while(a){
		b%=a;
		long long c=a;
		a=b;b=c;c=a;
	}
	return b;
}
int main(){
	long long a,b;
	scanf("%lld%lld",&a,&b);
	long long g=gcd(a,b);
	printf("%lld\n",(a-gcd(a,b))*3);
}

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

typedef long long int ll;
using namespace std;
const long long mod=1e9+7;
int main(){
	int N,M,s,num=0;
	ll count=1;
	cin >> N>>M;
	
	vector<int> oks(N+1,true);
	vector<ll> dp(N+1,0);
	for(int i=0;i<M;i++){
		cin>>s;
		oks[s]=false;
	}
	dp[0]=1;
	for(int i=1;i<N+1;i++){
		if(oks[i]){
			if(i==1){
				dp[i]=1;
			}else{
				dp[i]=dp[i-1]+dp[i-2];
				dp[i]%=mod;
			}
		}else{
			dp[i]=0;
		}
	}
	cout << dp[N] <<endl;
	return 0;
		
}

Measured memory_bytes: 1408
n = int(input())
a = list(map(int,input().split()))
a1 = set(a)
a2 = list(a1)
ans = 0
for i in range(len(a2)):
  for j in range(len(a2)):
    ans = max(ans,abs(a2[i] - a2[j]))
print(ans)

Measured memory_bytes: 9076
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	string s;
	cin >> s;
	if(s.size()%2==0){
		for(int i=0;i<s.size()-2;i+=2){
			cout << s[i];
		}
		cout << s[s.size()-2] << endl;
	}
	if(s.size()%2==1){
	for(int i=0;i<s.size()-1;i+=2){
			cout << s[i];
		}
		cout << s[s.size()-1] << endl;
	}
	return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


ll x;

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

    cin>>x;

    ll ans = 1000LL*(x/500);

    x = x % 500;

    ans += 5LL*(x/5);

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
   int a;
   int b;
   int sa;
	
	public void solve(){
		Scanner sc = new Scanner(System.in);
  		 for(int i=0;i<=6;i++){
            a = sc.nextInt();
            b = sc.nextInt();
			sa = a-b;
            System.out.println(sa);
        }
    }
	public static void main(String[] args){
		Main obj = new Main();
		obj.solve();
	}
}
	

Measured memory_bytes: 17176
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int V, E;
    cin >> V >> E;
    vector<tuple<int, int, int>> edge;
    REP(i,E){
        int s, t, w;
        cin >> s >> t >> w;
        edge.emplace_back(w, s, t);
    }
    sort(edge.begin(), edge.end());
    UnionFind uf(V);
    ll ans = 0;
    REP(i,E){
        int u, v, cost;
        tie(cost, u, v) = edge[i];
        if(uf.issame(u, v)) continue;
        uf.unite(u, v);
        ans += cost;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4560
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;

signed main(){
    ll s;
    ll w;
    cin>>s>>w;
    if(s<=w) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> ans(N, 0);
    vector<bool> ans1(N, false);
    for (int i = 0; i < M; i++)
    {
        int s, c;
        cin >> s >> c;
        s--;
        if(ans1[s] == true && c != ans[s]){
            cout << -1 << endl;
            return 0;
        }
        ans1[s] = true;
        ans[s] = c;
    }
    if(N != 1 && ans[0] == 0 && ans1[0] == true){
        cout << -1 << endl;
        return 0;
    }
    if(ans1[0] == false && N!= 1)
        ans[0] = 1;

    for (int i = 0; i < N;i++){
        cout << ans[i];
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets
a = gets.split.map(&:to_i).map{|x| x - 1}
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)

ans = 0
a.each_with_index do |ai, i|
  ans += b[ai]
  if i > 0 && a[i-1] == ai - 1
    ans += c[a[i-1]]
  end
end
p ans

Measured memory_bytes: 1916
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator 
const int MxN=  2e5+1;
ll ar[MxN];
void solve() {
    ll n;cin>>n;
    for(int i=1;i<=n;i++) {
        ll x; cin>>x;
        ar[i] = x + ar[i-1];
    }
    ll res = LONG_MAX;
    for(int i=1;i<n;i++) {
        res = min(res, abs(2*ar[i] - ar[n]));
    }
    cout<< res << endl;
}

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std; 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
#define int long long
#define endl '\n'
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fi first
#define se second
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void solve(){
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]) {
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

signed main()
{
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    int tests=1;
    // cin >> tests;
    while (tests--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
su = 0
l = list(map(int,input().split()))
l1 = Counter(l)
for k in l1.values():
  su += k*(k-1)//2
for t in l:
  a = l1[t]
  q = su-a*(a-1)//2+(a-1)*(a-2)//2
  print(q)

Measured memory_bytes: 26772
#include <iostream>
using namespace std;
int main(void){
    int a, b;
    cin >> a;
    cin >> b;
    
    if(a>b){
        cout << "a > b" << "\n";
    }else if(a<b){
        cout << "a < b" << "\n";
    }else{
        cout << "a == b" << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    int A[N];
    for(int i = 0; i < N; ++i) cin >> A[i];
    
    int sum = 0;
    for(int i = 0; i < N; ++i) sum += A[i];
    
    sort(A, A+N, greater<int>());

    if(A[M-1] >= (sum+4*M-1)/4/M) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256