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

int N;
int a[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  int p = 0, q = 0, r = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] % 4 == 0) p++;
    else if (a[i] % 2 == 0) q++;
    else r++;
  }
  if (q) r++;
  cout << (p - r >= -1 ? "Yes" : "No") << endl;

  return 0;
}

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

using namespace std;

int main() {
  int n;
  while( cin >> n ) {
    vector<int> v;
    for( int i = 0; i < n; i++ ) {
      int t;
      cin >> t;
      v.push_back( t );
    }
    sort( v.begin(), v.end() );
    int sum = 0;
    for( int i = 0; i < n; i++ ) {
      sum += ( v[ i ] * ( n - i ) );
    }
    cout << sum << endl;
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1220
import numpy as np

n = int(input())
data = [list(map(int, input().strip().split())) for _ in range(n)]

# i 日目に 活動 j をして夏休みを終了した
# ばあいの幸福の総和の最大値
dp = np.zeros((n, 3), dtype=np.int)
dp[0] = np.array(data[0], dtype=np.int)

for i in range(1, n):
    dp[i][0] = data[i][0] + max(dp[i - 1][1], dp[i - 1][2])
    dp[i][1] = data[i][1] + max(dp[i - 1][2], dp[i - 1][0])
    dp[i][2] = data[i][2] + max(dp[i - 1][0], dp[i - 1][1])

ans = np.max(dp[n - 1])
print(ans)


Measured memory_bytes: 50604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		double n = sc.nextDouble();
		System.out.println(n * 2 * Math.PI);
		;

	}

	static int getDigit(int n, int d) {
		return n / d != 0 ? 1 + getDigit(n / d, d) : 1;
	}

	static class FastScanner {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		public FastScanner(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
			tokenizer = null;
		}

		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public String nextLine() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					return reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}

			return tokenizer.nextToken("\n");
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}
}

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

int main(){
	int n,a;
	cin >> n >> a;
	
	int x = (n % 500) - a;
	
	if(x <= 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}
		
	

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>

using namespace std;

int main(void){
	int n, i, j;
	double x1,y1,x2,y2,x3,y3, r, px, py;
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
		if((y2 - y1) * (x3 - x1) - (y3 - y1) * (x2 - x1) == 0){
			if(x1 == x2 && x2 == x3){
				px = x1;
				py = (max(y1,max(y2,y3)) + min(y1,min(y2,y3))) / 2;
				r = fabs(max(y1,max(y2,y3)) - py);
			}
			else{
				double tx1, ty1, tx2, ty2;
				if(x1 > x2 && x1 > x3){
					tx1 = x1, ty1 = y1;
				}else if(x2 > x1 && x2 > x3){
					tx1 = x2, ty1 = y2;
				}else{
					tx1 = x3, ty1 = y3;
				}
				if(x1 < x2 && x1 < x3){
					tx2 = x1, ty2 = y1;
				}else if(x2 < x1 && x2 < x3){
					tx2 = x2, ty2 = y2;
				}else{
					tx2 = x3, ty2 = y3;
				}
				px = (tx1 + tx2) / 2;
				py = (ty1 + ty2) / 2;
				r = sqrt(pow(tx1 - px,2.0) + pow(ty1 - py,2.0));
			}
		}else{
			py = ((x3 - x1) * (pow(x2,2.0) - pow(x1,2.0) + pow(y2,2.0) - pow(y1,2.0)) - (x2 - x1) * (pow(x3,2.0) - pow(x1,2.0) + pow(y3,2.0) - pow(y1,2.0))) / (2 * ((y2 - y1) * (x3 - x1) - (y3 - y1) * (x2 - x1)));
			px = ((y3 - y1) * (pow(y2,2.0) - pow(y1,2.0) + pow(x2,2.0) - pow(x1,2.0)) - (y2 - y1) * (pow(y3,2.0) - pow(y1,2.0) + pow(x3,2.0) - pow(x1,2.0))) / (2 * ((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)));
			r = sqrt(pow(px - x1,2.0) + pow(py - y1,2.0));
		}
		printf("%.3f %.3f %.3f\n",px,py,r);
	}
	return 0;
}

Measured memory_bytes: 1248
import math, cmath

D = 90
p = complex(0, 0)
while True:
    r, d = map(float, input().split(','))
    if r == d == 0:
        print(int(p.real))
        print(int(p.imag))
        exit()

    p += cmath.rect(r, math.radians(D))
    D -= d

Measured memory_bytes: 7796
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
    ll n; cin>>n;
    cout<<(n+1)/2<<endl;
}

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

int main() {
  int N,K,count;
  cin >> N >> K;
  for(int i = 0;i < N;i++){
    int x;
    cin >> x;
    if(x>K-x)count += 2*(K-x);
    if(x<=K-x)count += 2*x;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll=long long;
int main(){
  ll n; cin >> n;
  vector<ll> h;
  for(int i=0; i<n; i++){
    ll a; cin >> a;
    h.push_back(a);
  }
  if(h[0]>=1) h[0]--;
  for(int i=1; i<n-1; i++){
    if(h[i-1]<h[i]) h[i]--;
    if(h[i]>h[i+1]) {cout << "No"; return 0;}
  }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 4324
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli dp[401][401];
/*This function is used to give the
sum of colours from a to be
after taking mod by 100*/

lli Sum(lli val[],lli a,lli b)
{
   lli sumv=0;
   for(lli i=a;i<=b;++i)
      sumv=sumv+val[i];
   return sumv;
}
/*This approach is very much similar to matrix chain multipliaction, where
we minimize the number of products/multiplications. Here we calculate the
residual smoke from both sides and then use this for storing the product.
dp[a][b] contains the value of product */
lli HarryMatMul(lli val[],lli a,lli b)
{
   if(dp[a][b]!=-1)
      return dp[a][b];
   else if(a==b)
   {
      dp[a][b]=0;
      return 0;
   }
   lli temp;
      for(lli k=a;k<b;++k)
      {
         temp=HarryMatMul(val,a,k)+HarryMatMul(val,k+1,b)
         +Sum(val,a,k)+Sum(val,k+1,b);

         if(dp[a][b]==-1||temp<dp[a][b])
            dp[a][b]=temp;
      }
      //for(int i=--0;i<)
      return dp[a][b];
}
int main() {
   lli n;
    //freopen("input.txt","r",stdin);
 cin>>n;
  // {
      lli val[n];
      memset(dp,-1,sizeof(dp));
      for(lli i=0;i<n;++i)
         cin>>val[i];
      cout<<HarryMatMul(val,0,n-1);//
      //printf("%d\n",HarryMatMul(val,0,n-1));
     /* for(int i=0;i<n;i++)
      {
          for(int j=0;j<n;j++)
            cout<<dp[i][j]<<" ";
          cout<<"\n";
      }*/
  // }
   return 0;
}


Measured memory_bytes: 1536
N,A,B=map(int,input().split())
t=0
for n in range(1,N+1):
    #print(n)
    m=n
    c=0
    while m//10>0:
        c+=m%10
        m=m//10
    c+=m
    #print(c)
    if A<=c and c<=B:
        t+=n
print(t)


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

const int MAX_N = 100010;

int memo[MAX_N];
int rec(int n)
{
    if (n == 0)
        return 0;
    if (memo[n] != -1)
        return memo[n];

    int res = n;

    for (int i = 1; i <= n; i *= 6)
        res = min(res, rec(n - i) + 1);
    for (int i = 1; i <= n; i *= 9)
        res = min(res, rec(n - i) + 1);
    return memo[n] = res;
}

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < MAX_N; i++)
        memo[i] = -1;
    cout << rec(N) << endl;
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  string O,E;
  cin >> O >> E;
  for(int i=0;i<O.size()-1;i++){
    cout << O.at(i) << E.at(i);
  }
  if(O.size()>E.size()) cout << O.at(O.size()-1);
  else  cout << O.at(O.size()-1) << E.at(E.size()-1);
  cout << endl;
  
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    ll N, K;
    double sum = 0;
    double temp;
    cin >> N >> K;
    temp = 1.0 / N;
    for(ll i = 1;i <= N;i++) {
        double tmp = temp;
        ll point = i;
        while(point < K) {
            tmp /= 2.0;
            point *= 2;
        }
        sum += tmp;
    }
    cout << fixed << setprecision(12) << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

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

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

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


int main(){
    int n;cin>>n;
    VEC(int,a,n);
    ll res = INF;
    for(int i=-100;i<101;i++){
        ll r = 0;
        rep(j,n){
            r += pow(a[j]-i,2);
        }
        res = min(res,r);
    }
    cout<<res<<endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
   string a,b;
   cin>>a>>b;

   long long int p,i,sum=0;

   p=a.length();
   for(i =0 ; i<p ; i++)
   {
       if(a[i]!=b[i]) sum++;
   }
   cout<<sum;
}



Measured memory_bytes: 3912
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define reft0(i, j) setfill('0') << setw(i) << j

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(){
    ll N;

    cin >> N;

    ll dp[100010];
    rep(i, 0, 35) dp[i] = MAX;
    dp[0] = 0;

    rep(cnt, 0, N+1){
        if (cnt > 0){
            dp[cnt] = dp[cnt-1]+1;

            ll cnt6 = 6;
            while(cnt >= cnt6){
                chMin(dp[cnt], dp[cnt-cnt6]+1);
                cnt6 *= 6;
            }
            ll cnt9 = 9;
            while(cnt >= cnt9){
                chMin(dp[cnt], dp[cnt-cnt9]+1);
                cnt9 *= 9;
            }
        }
    }

    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
  int n;
  cin >> n;
  char c[200000];
  bool f = true;
  rep(i, n){
    cin >> c[i];
    if(c[i] == 'R') f = false;
  }
  //Rがなければ抜ける。
  if(f){
    cout << 0 << endl;
    return 0;
  }
  
  int ans = 0;
  int pos = n-1;
  rep(i, n){
    if(c[i] == 'W'){
      while(c[pos] == 'W') pos--;
      if(i >= pos) break;
      c[pos] = 'W';
      c[i] = 'R';
      ans++;
    }
  }
  cout << ans << endl;
}



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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int main(){
	cin.sync_with_stdio(false);
	string str;
	cin >> str;

	rep(i, str.size()) {
		if (str[i] == ',') {
			cout << " ";
		} else {
			cout << str[i];
		}
	}
	cout << endl;
	
	return 0;
}

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

int main() {
	string str="";
	cin>>str;
	if(str.length()%2==0)
	cout<<"No\n";
	else
	{
		int n=str.length();
		int fg=0;
		for(int i=0;i<n/2;++i)
		{
			if(str[i]!=str[n-i-1])
			{
				fg=1;
				break;
			}
		}
		if(fg==1)
		cout<<"No\n";
		else
		{
		int flag=0;
		string res="";
		string temp="";
		for(int i=0;i<(n-1)/2;++i)
		{
			res+=str[i];
		}
		for(int i=(n-1)/2-1;i>=0;--i)
		{
			temp+=str[i];
		}
		if(res!=temp)
		{
			flag=1;
		}
		string str1="";
		string str2="";
		for(int i=(n+3)/2-1;i<n;++i)
		{
			str1+=str[i];
		}
		for(int i=n-1;i>=(n+3)/2-1;--i)
		{
			str2+=str[i];
		}
		if(str1!=str2)
		flag=1;
		if(flag==1)
		cout<<"No\n";
		else
		cout<<"Yes\n";
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
    double n, m, d;
    double ans;
    scanf("%lf%lf%lf", &n, &m, &d);
    if (d==0) ans=1.0/n*(m-1);
    else ans=2.0*(n-d)/(n*n)*(m-1);
    printf("%.15f\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<stack>
#include<map>
#include<sstream>
using namespace std;

typedef vector<bool> V;
typedef pair<int,int> P;

int stoi(string x){
  stringstream ss(x);
  int r; ss >> r;
  return r;
}

int cal(int a,int b,string op){
  int res;
  if(op == "+")res = a+b;
  else if(op == "-")res = a-b;
  else if(op == "*")res = a*b;
  else res = a/b;
  return (res + 256) % 256;
}

int main(){
  string s,c[100];
  int m,n,a,b;
  map<string,P> h;
  V t1(256),t2(256),t3(256);

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

  cin >> n;
  for(int i=0;i<n;i++)cin >> c[i];

  stack<V> p;
  for(int i=0;i<n;i++){
    if(c[i] == "+" || c[i] == "-" || c[i] == "*" || c[i] == "/"){
      t2 = p.top(); p.pop();
      t1 = p.top(); p.pop();
      for(int j=0;j<256;j++)t3[j] = false;
      for(int j=0;j<256;j++)
	for(int k=0;k<256;k++)
	  if(t1[j] && t2[k]){
	    if(!k && c[i] == "/"){
	      cout << "error\n";
	      return 0;
	    }else t3[cal(j,k,c[i])] = true;
	  }
      p.push(t3);
    }else if(h.find(c[i]) != h.end()){
      for(int j=0;j<256;j++)t3[j] = false;
      a = h[c[i]].first; b = h[c[i]].second;
      for(int j=a;j<=b;j++)t3[j] = true;
      p.push(t3);
    }else{
      for(int j=0;j<256;j++)t3[j] = false;
      t3[stoi(c[i])] = true;
      p.push(t3);
    }
  }
  cout << "correct\n";
}

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


using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main(){

	int n;
	cin >> n;

	vector<int> a(n);
	REP(i, n)cin >> a[i];
	int b = INF;
	int ans = 0;
	REP(i, n) {
		if (b >= a[i]) {
			ans++;
			b = a[i];
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 1024
#include <iostream>
#include <string>

bool check_sqrt(int n)
{
  for(int i = 0; i * i <= n; i++){
    if(i * i == n) return true;
  }
  return false;
}

int main(void)
{
  std::string a, b;
  int num;
  std::cin >> a >> b;
  num = std::stoi(a + b);
  //std::cout << num << std::endl;
  if(check_sqrt(num)){
    std::cout << "Yes" << std::endl;
  }else{
    std::cout << "No" << std::endl;
  }
  return 0;
}


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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll x, y;
  cin >> x >> y;

  if (x > y) {
    swap(x, y);
  }

  if (x <= 1 && y <= 1) {
    cout << "Brown" << endl;
    return 0;
  }

  if (y - x <= 1) {
    cout << "Brown" << endl;
  } else {
    cout << "Alice" << endl;
  }

  return 0;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N, M; cin >> N >> M;
    map<int, int> digit2NumMap;
    for (int i = 0; i < M; ++i)
    {
        int si, ci; cin >> si >> ci;
        // ０以外で最初の桁はゼロ以外
        if (N > 1 && si == 1 && ci == 0)
        {
            cout << -1 << endl;
            return 0;
        }
        auto itr = digit2NumMap.find(si);
        if (itr == digit2NumMap.end())
        {
            digit2NumMap[si] = ci;
        }
        else
        {
            // 過去の結果と矛盾するとNG
            if (ci != itr->second)
            {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= N; ++i)
    {
        // 数字指定がない場合
        if (digit2NumMap.find(i) == digit2NumMap.end())
        {
            if (i == 1) ans += 1;
            else ans += 0;
        }
        // 数字指定がある場合は必ずその数字
        else
        {
            ans += digit2NumMap[i];
        }
        ans *= 10;
    }
    ans /= 10;
    if (N == 1 && M == 0)
    {
        ans = 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int max(int N, int d[]);

int main(void){
  int N;
  int d[100] = {};
  int d_new[100] = {};//d[100]を大きい順に並べ替えたもの
  int i, j, k;
  int count = 0;

  scanf("%d", &N);
  for(i = 0; i < N; i++){
    scanf("%d", &d[i]);
  }

  j = max(N, d);
  d_new[0] = d[j];
  d[j] = 0;
  count++;

  for(i = 1; i < N; i++){
    do{
      j = max(N, d);
      d_new[i] = d[j];
      d[j] = 0;
    }while(d_new[i] == d_new[i-1]);
    if(d_new[i] != 0){
      count++;
    }else{
      break;
    }
  }

  printf("%d\n", count);

  return 0;
}

//d[i]を最大にするiのうち最小のものを求める関数
int max(int N, int d[]){
  int max;
  int i, j;

  max = d[0];
  for(i = 1; i < N; i++){
    if(d[i] > max){
      max = d[i];
    }
  }

  for(i = 0; i < N; i++){
    if(d[i] == max){
      j = i;
      break;
    }
  }

  return j;
}


Measured memory_bytes: 128
import math
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[a[0]]
c={}
c[b[0]%m]=1
for i in range(1,n):
  b.append(b[i-1]+a[i])
  c[b[i]%m]=c.get(b[i]%m,0)+1
print(sum(map(lambda x:math.factorial(x)//(math.factorial(x-2)*math.factorial(2))if x>1else 0,c.values()))+c.get(0,0))

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

int main(){
    int N; cin >> N;
    vector<pair<int,int>> ans(N);
    for(int i = 0; i < N; i++){
        int a; cin >> a;
        ans.at(i) = make_pair(a,i+1);
    }
    sort(ans.begin(),ans.end());
    for (int i = 0; i < N; i++) cout << ans.at(i).second << endl;
}

Measured memory_bytes: 1664
void main()
{
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], k = tmp[1];

    int[] h = new int[n];
    foreach (i; 0 .. n)
    {
        h[i] = readln.chomp.to!int;
    }

    h.sort!"a < b";
    int[] diff = new int[n-1];
    foreach (i; 0 .. n-1)
    {
        diff[i] = h[i+1] - h[i];
    }

    int total = diff[0..k-1].sum;
    int result = diff[0..k-1].sum;
    foreach (i; k-1 .. n-1)
    {
        total += diff[i] - diff[i-k+1];
        result = min(result, total);
    }
    result.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 3580
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    int N, K;
    string S;
    cin >> N >> K >> S;
    if(S.at(K-1) == 'A') S.replace(K-1, 1, "a");
    if(S.at(K-1) == 'B') S.replace(K-1, 1, "b");
    if(S.at(K-1) == 'C') S.replace(K-1, 1, "c");
    cout << S << endl;
    return 0;
}

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    int a, b;
    cin >> a >> b;

    if(a>b)
    swap(a,b);

    for (int i = 0; i < b; i++)
    {
        cout << a;
    }
    cout << endl;
}


Measured memory_bytes: 256
N,A,B = map(int,input().split())
maxi = B*(N-1) + A
mini = A*(N-1) + B
if A > B:
    print(0)
elif N == 0:
    print(0)
elif A == B:
    print(1)
elif N == 1:
    print(0)
else:
    print(maxi - mini + 1)

Measured memory_bytes: 3060
//By Tushar Gautam
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln "\n"
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long int  ll;
typedef long double  ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
ll t,n,m,k,x,y,w;
int main(){
	fastio;
	cin>>n>>w;
	v64 ach(LIM,MOD);
	ach[0]=0;
	forn(i,n){
		cin>>x>>y;
		rforn(i,LIM-1){
			if(i+y<=LIM) ach[i+y]=min(ach[i+y],ach[i]+x);
		}
	}
	ll ans=0;
	forn(i,LIM) if(ach[i]<=w) ans=i;
	cout<<ans<<ln;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,m,V,P;
#define Maxn 100010
int a[Maxn];
ll sum[Maxn];
int main(){
	scanf("%d%d%d%d",&n,&m,&V,&P);
    for(int i=1;i<=n;++i)scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=1;i<=n;++i)sum[i]=sum[i-1]+a[i];
    int Ans=0;
    for(int i=1;i<=n;++i){
		int t1=upper_bound(a+1,a+n+1,a[i])-a;t1--;
		int t2=upper_bound(a+1,a+n+1,a[i]+m)-a;t2--;
		if(n-t2>=P)continue;
		ll res=1ll*m*V;
		res-=1ll*m*(n-t2);
		if(res<=0){
			Ans++;
			continue;
		}
		res-=1ll*m*t1;
		if(res<=0){
			Ans++;
			continue;
		}
		res-=1ll*(a[i]+m)*(t2-t1);
		res+=sum[t2]-sum[t1];
		if(res<=0){
			Ans++;
			continue;
		}
		int haha=P-1-(n-t2);
		if(haha>t2-t1){
			Ans++;
			continue;
		}
		if(sum[t2]-sum[t2-haha]-1ll*haha*a[i]>=res)Ans++; 
    } 
    printf("%d\n",Ans);
    return 0;
} 

Measured memory_bytes: 1408
#include <iostream>
#include <map>

using namespace std;

int main()
{
	int N;
	cin >> N;
	map<int, int> m;

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

	int ans = 0;
	for (const auto &e : m) {
		if (e.first <= e.second) {
			ans += e.second - e.first;
		}
		else {
			ans += e.second;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4736
#include <iostream>
using namespace std;
int main(){
    int A,B,X;
    string message;
    cin >> A >> B >> X;
    if (A==X||A+B==X)message ="YES";
    else if(A+B<X||A>X)message ="NO";
    else {
        for (int i=0;i<B;++i){
            if(X==A+i){
                message="YES";
            break;}
        }
    }cout << message;

return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 105
#define MOD 998244353
#define NIN -100000000
#define EPS 0.0000000001
bool exists[MAX];
int main()
{
    int n,i,j,x;
    scanf("%d %d",&x,&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&j);
        exists[j]=true;
    }
    int l=x,r=x;
    for(i=x;i>=0&&exists[i];i--)
    {

    }
    l=i;
    for(i=x;i<=100&&exists[i];i++)
    {

    }
    r=i;
    if(x-l<=r-x)
    {
        printf("%d",l);
    }
    else
    {
        printf("%d",r);
    }
    return 0;
}


Measured memory_bytes: 3836
#include <stdio.h>

int main(){
  int n, t;
  scanf("%d", &n);
  for(int i=0; i<n; i++){
    scanf("%d", &t);
    if(t%2 == 0 && !(t%3==0 || t%5==0)){
      printf("DENIED\n");
      return 0;
    }
  }
  printf("APPROVED\n");
  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    slow = 0
    fast = 0
    collide = -1
    while True:
        slow = A[slow]-1
        fast = A[A[fast]-1]-1
        if slow == fast:
            collide = slow
            break
    # print("loop detect")
    slow = 0
    fast = collide
    begin = 0
    while True:
        if slow == fast:
            break
        slow = A[slow]-1
        fast = A[fast]-1
        begin += 1
    # print("begin detect")
    loopC = 0
    while True:
        slow = A[slow]-1
        fast = A[A[fast]-1]-1
        loopC+=1
        if slow == fast:
            break
    # print("loop length detect")
    if begin >=K:
        current = 0
        for i in range(K):
            current = A[current]-1
        print(current+1)
    else:
        K -= begin
        current = 0
        for i in range(begin):
            current = A[current] - 1
        for i in range(K%loopC):
            current = A[current]-1
        print(current+1)
    pass

if __name__ == '__main__':
    main()


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

int main(){
	int N,field;
	int *player;
	char c[101];
	while(true){
		cin >> N;
		if(N == 0)
			break;
		player = new int[N];
		for(int i=0; i<N; i++)
			player[i] = 0;
		field = 0;
		cin >> c;
		for(int i=0; i<100; i++){
			if(c[i] == 'M'){
				player[i%N]++;
			}else if(c[i] == 'S'){
				field += player[i%N]+1;
				player[i%N] = 0;
			}else{
				player[i%N] += field+1;
				field = 0;
			}
		}
		sort(player, player+N);
		for(int i=0; i<N; i++)
			cout << player[i] << ' ';
		cout << field << endl;
		delete[] player;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>

using namespace std;

char a[50][50], b[50][50];
int n, m;

bool solve(int x, int y) {
    for (int i = 0; i < m; ++i)
        for (int j = 0; j < m; ++j)
            if (b[i][j] != a[i + y][j + x]) return false;
    return true;
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) cin >> a[i][j];
    for (int i = 0; i < m; ++i) for (int j = 0; j < m; ++j) cin >> b[i][j];
    int maxDiff = n - m;
    for (int x = 0; x <= maxDiff; ++x)
        for (int y = 0; y <= maxDiff; ++y) {
            if (solve(x, y)) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
    int h,a;
    cin>>h>>a;
    h%a==0 ? cout<<h/a : cout<<h/a+1;
}

Measured memory_bytes: 256
#include <iostream>
 using namespace std;
 
int main() {
  int W,H,x,y,r;
  
  cin >> W >> H >> x >> y >> r;

  if (x-r < 0 || x+r > W || y-r < 0 || y+r > H){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  } 

  return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
#define endl '\n'
#define inf 0x3f3f3f3f
#define lb lower_bound
#define db(x) {cout <<"#db " << x << endl;}
#define here() {cout <<"here \n";}
#define mod 1000000007
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2e5+5;
int n ;
int a[N],x[N];
int ans = 0;
signed main(){
	cin >> n;
	for(int i = 0 ; i < n ; i ++){
		cin >> a[i];
		if(!i) if(a[i] != 0) {cout << "-1";return 0;}
		if(i) if(a[i] - a[i-1] > 1){ cout <<"-1";return 0;}
		
	}
	for(int i = 1 ; i < n ; i ++){
		if(a[i] == a[i-1] + 1) ans ++;
		else ans += a[i];
	}
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 1792
import math
 
a_0, b_0 = input().split()
a = int(a_0)

small = str(a*int(b_0[-2:]))


if len(small) >= 3:
  ans = a*int(b_0[0:-3]) +int(small[:-2])
else:
  ans = a*int(b_0[0:-3])
print(ans)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int maxN = 100005;
const int INF = 1e9;

class TaskA {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		string s;
		cin >> s;
		cout << (s == "ABC" ? "ARC" : "ABC") << endl;

	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};

int main(){
	srand(time(NULL));
	ios_base::sync_with_stdio(false);
	TaskA solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
int main(void)
{
    int h,n,i,sum = 0;
    scanf("%d%d",&h,&n);
    int a[n];
    for(i = 0; i < n; i++)
    {
        scanf("%d",&a[i]);
        sum += a[i];
    }
    if(h <= sum)
        printf("Yes");
    else
        printf("No");


    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
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 v = 0;
	for (int i = 0; i < k; i++) {
		v += p[i];
	}

	printf("%d", v);

	return 0;
}



Measured memory_bytes: 3692
s = input()
t = input()

lens = len(s)
lent = len(t)

ans = 1000

for i in range(lens - lent + 1):
    k = 0
    for j in range(i,lent + i):
        if s[j] != t[j-i]:
            k += 1
    ans = min(ans,k)

print(ans)

Measured memory_bytes: 8948
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <algorithm>
 
int main(void){
	int n;
	std::cin >> n;
	std::vector<int64_t> a(n);
	for(int i=0;i<n;i++)std::cin >> a[i];
	//i-1番目までの数の和の最大値
	std::vector<int64_t> dp(n+1), dp_inv(n+1);
	dp[0] = 0;
	dp_inv[0] = 0;
	for(int i=0;i<n;i++){
		//i, i+1の符号を反転させない
		if(i == 0){
			dp[i+1] = dp[i] + a[i];
		}else{
			dp[i+1] = std::max(dp[i] + a[i], dp_inv[i] - a[i]);
		}
		//i, i+1の符号を反転させる
		if(i == 0){
			dp_inv[i+1] = dp[i] - a[i];
		}
		else{
			dp_inv[i+1] = std::max(dp[i] - a[i], dp_inv[i] + a[i]);
		}
	}
	std::cout << dp[n] << std::endl;
}

Measured memory_bytes: 2560
# coding: utf-8
from math import log2, ceil
N, K = map(int, input().split())
ans = 0
for i in range(N):
    tmp = i+1
    x = 0
    while tmp < K:
        tmp *= 2
        x += 1
    ans += 1/N * (0.5**x)
print(ans)

Measured memory_bytes: 3060
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let n : i32 = s.trim().parse().ok().unwrap();
    let mut ans : i32 = 0;
    for _i in 0..n {
        let mut t = String::new();
        std::io::stdin().read_line(&mut t).ok();
        let v : Vec<i32> = t.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
        ans += v[1] - v[0] + 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
class Node
  attr_accessor :order, :parent, :child, :edges, :lowest, :visited, :isArticulation
  def initialize
    @order = nil
    @parent = -1
    @child = []
    @edges = []
    @lowest = nil
    @visited = false
    @isArticulation = false
  end
end

def dfs(root, g)
  t = 1
  stack = []
  g[root].order = g[root].lowest = t
  g[root].visited = true

  stack << root
  while stack.size > 0
    u = stack[-1]
    flag = true
    g[u].edges.each{|x|
      if g[x].visited == false
        t += 1
        g[x].order = g[x].lowest = t
        g[x].visited = true
        g[x].parent = u
        g[u].child << x
        flag = false
        g[u].lowest = [g[u].lowest, g[x].lowest].min
        stack << x
        break
      elsif x != g[u].parent
        g[u].lowest = [g[u].lowest, g[x].order].min
      end
    }
    if flag
      stack.pop
      g[u].child.each{|v|
        g[u].lowest = [g[u].lowest, g[v].lowest].min
        g[u].isArticulation = true if (u != root && g[u].order <= g[v].lowest)
        if g[u].order < g[v].lowest
          if u < v
            $bridge << [u, v]
          else
            $bridge << [v, u]
          end
        end
      }
    end
  end
  g[root].isArticulation = true if g[root].child.size > 1
end

$bridge = []

$t = 1
v, e = gets.split.map(&:to_i)
graph = Array.new(v){Node.new}
e.times{
  s, t = gets.split.map(&:to_i)
  graph[s].edges << t
  graph[t].edges << s
}

dfs(0, graph)

# v.times{|i|
#   puts "#{graph[i].order} #{graph[i].parent} #{graph[i].lowest} #{graph[i].child}"
# }

# v.times{|i|
#   if graph[i].isArticulation
#     puts i
#   end
# }

$bridge.sort.each{|a, b|
  puts "#{a} #{b}"
}

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

void insertionSort(int A[], int N){
    int v;
    int i, j;
    
    for(int k = 0; k < N; k++){
            if(k == 0){
                cout << A[k];
            }else{
                cout << " " << A[k];
            }
        }
    
    cout << endl;
    
    for(i = 1; i < N; i++){
        v = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
            A[j+1] = v;
        }
        
        for(int k = 0; k < N; k++){
            if(k == 0){
                cout << A[k];
            }else{
                cout << " " << A[k];
            }
        }
        
        cout << endl;
    }
}

int main(void){
    int N;
    
    cin >> N;
    
    int A[N];
    
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    insertionSort(A, N);
    
}



Measured memory_bytes: 3112
let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ ->
    Scanf.scanf "%d " @@ fun a -> a in
  Array.fold_left (fun (prev, (acc, curr)) a ->
    a,
    if a = prev then (acc, curr + 1)
    else (curr :: acc, 1)) (max_int, ([], 1)) as_
  |> (fun (_, (acc, curr)) -> curr :: acc)
  |> List.map (fun i -> i / 2)
  |> List.fold_left ( + ) 0
  |> Printf.printf "%d\n"


Measured memory_bytes: 384
///
// File:  a.go
// Author: ymiyamoto
//
// Created on Thu Apr  5 20:22:53 2018
//
package main

import (
	"fmt"
)

var N int
var A []int

const (
	inc  = 0
	dec  = 1
	none = 2
)

func main() {
	fmt.Scan(&N)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}

	count := 0
	state := none
	for i := 1; i < len(A); i++ {
		if A[i-1] < A[i] {
			if state == dec {
				state = none
				count++
			} else if state == none {
				state = inc
			}
		} else if A[i-1] > A[i] {
			if state == inc {
				state = none
				count++
			} else if state == none {
				state = dec
			}
		}
	}

	fmt.Println(count + 1)
}


Measured memory_bytes: 5504
a, b, c = map(int, input().split(" "))
mod = a % b
if mod == c:
    print("YES")
else:
    mod_list = [mod]
    while True:
        mod_next = (mod + a) % b
        if mod_next in mod_list:
            print("NO")
            exit()
        else:
            if mod_next == c:
                print("YES")
                exit()
            else:
                mod_list.append(mod_next)
                mod = mod_next

Measured memory_bytes: 3064
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

sum = a.inject(&:+)
divs = []
t = 1
while t * t <= sum
  if sum % t == 0
    divs << t
    divs << sum / t if sum / t != t
  end
  t += 1
end
divs.sort!.reverse!
divs.each do |d|
  r = a.map { |ai| ai % d }
  r.sort!
  sumr = [tmp = 0].concat(r.map { |ri| tmp += ri })
  rdiff = r.map { |ri| d - ri }
  sumrd = [tmp = 0].concat(rdiff.map { |ri| tmp += ri })
  n.times do |i|
    if k >= sumr[i] - sumr[0] && sumr[i] - sumr[0] == sumrd[n] - sumrd[i]
      puts d
      exit
    end
  end
end
puts 1

Measured memory_bytes: 17912
import numpy as np

L, A, B, M = (int(i) for i in input().split())
keta = [0] * 18
for i in range(18):
    keta[i] = min((10**i - A - 1)//B, L-1)
keta.reverse()
for i in range(18):
    if keta[i] < 0:
        keta[i] = -1
        break
keta.reverse()

def power(g, N, M):
    if N == 0:
        g = np.array([1, 0, 0, 0, 1, 0, 0, 0, 1]).reshape(3, 3)
    elif N == 1:
        pass
    elif N%2 == 0:
        g = np.linalg.matrix_power(power(g, N//2, M), 2)
    elif N%2 == 1:
        g = np.dot(g, power(g, N-1, M))
    return g%M

ans = 0
for i in range(18):
    N = i + 1
    mi = keta[i] + 1
    if mi < 0:
        continue
    if i != 17:
        ma = keta[i+1]
    else:
        ma = L-1
    if mi >= L:
        break
    t = np.array([ans, (A + B*mi)%M, 1])
    g = np.array([10**N%M, 0, 0, 1, 1, 0, 0, B%M, 1]).reshape(3, 3)
    g = power(g, ma-mi+1, M)
    g = np.dot(t, g)
    ans = g[0]%M
print(ans)

Measured memory_bytes: 14304
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int A, B, count = 0;
  cin >> A >> B;
  
  for ( int i = A; i <= B; i++ ){
    
    if ( (i % 10 == i / 10000) && ( i / 10 % 10 == i / 1000 % 10) )
      count++;
    
  }
  
  cout << count << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

char s[N], t[N];
int main(){
  int n;  scanf("%s",s);
  n=strlen(s);
  int x=0;
  int cur=0,f=0;
  while(cur<n){
    while(cur<n&&s[cur]!=s[f]) cur++,x+=1+(cur==n);
    cur++; f^=1;
  }
  if(x){
    t[0]=s[0];
    int fl=0;
    REPP(i,1,n)t[i]=s[i+1];
    REP(i,n-1) if(t[i]!=t[i%2]) fl=1;
    if(!fl) x=1;  
  }
  //printf("%d\n",x);
  if(x==0) printf("Second\n"); else if(x==1) printf("First\n"); else{
    if((n%2==0&&s[0]!=s[n-1]) ||(s[0]==s[n-1]&&n%2==1)) printf("Second\n"); else printf("First\n");
  }
  return 0;
}

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

int main(void) {
  int w,h,n;
  cin >> w >> h >> n;
  int x[n], y[n], a[n];
  rep(i,n) {cin >> x[i] >> y[i] >> a[i]; }
  int p=0, q=w, r=0, s=h;
  rep(i,n) {
    if(a[i] == 1) {
      if(p < x[i]) p = x[i];
    } else if (a[i] == 2) {
      if(q > x[i]) q = x[i];
    } else if (a[i] == 3) {
      if (r < y[i]) r = y[i];
    } else {
      if (s > y[i]) s = y[i];
    }
  }
  if (p < q && r < s) {
    cout << (q-p)*(s-r) << endl;
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)


int main(){

    long long int n,a,b;
    cin>>n>>a>>b;
    if(n==0||(n==1&&a!=b)||a>b){
        cout << 0 << endl;
    }else{
        cout << 1 + ((n - 2) * (b - a)) << endl;
    }
    return 0;
}   

Measured memory_bytes: 256
class UnionFind:

    def __init__(self, n):
        self.t = [-1] * (n + 1)

    def flatten(self):
        for i, _ in enumerate(self.t):
            self.find_root(i)

    def union(self, a, b):
        ra = self.find_root(a)
        rb = self.find_root(b)
        if ra != rb:
            self.t[max(ra, rb)] = min(ra, rb)

    def find_root(self, x):
        t = []
        while self.t[x] > 0:
            t.append(x)
            x = self.t[x]
        for _t in t:
            self.t[_t] = x
        return x


def solve(string):
    n, m, k, *abcd = map(int, string.split())
    r = [1] * (n + 1)
    uf = UnionFind(n)
    for a, b in zip(*[iter(abcd[:2 * m])] * 2):
        r[a] += 1
        r[b] += 1
        uf.union(a, b)
    uf.flatten()
    for i, v in enumerate(uf.t):
        uf.t[i] = i if v < 0 else v
    mp = {k: set([]) for k in set(uf.t[1:])}
    for i, v in enumerate(uf.t[1:], start=1):
        mp[v].add(i)
    for c, d in zip(*[iter(abcd[2 * m:])] * 2):
        r[c] += 1 if d in mp[uf.t[c]] else 0
        r[d] += 1 if c in mp[uf.t[d]] else 0
    mp = {k: len(v) for k, v in mp.items()}
    return " ".join([str(mp[uf.t[i]] - r[i]) for i in range(1, n + 1)])


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


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

int dp[101000];
int n;
int h[101000];

int main(){
	cin>>n;
	for(int i=1;i<=n;++i) cin>>h[i];
	dp[2]=abs(h[2]-h[1]);
	for(int i=3;i<=n;++i) {
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n]<<"\n";
	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
#define all(x) (x).begin(),(x).end()


int main() {
  int N;
  cin >> N;
  vector<vector<int>> openStore(N, vector<int>(10));
  vector<vector<ll>> point(N, vector<ll>(11));
  for(int i=0; i<N; i++){
    for(int j=0; j<10; j++){
      cin >> openStore[i][j];
    }
  }
  for(int i=0; i<N; i++){
    for(int j=0; j<=10; j++){
      cin >> point[i][j];
    }
  }

  ll maxScore = -1000000000000;
  for (int bit = 1; bit < (1 << 10); ++bit) {
    vector<int> openJ(10,0);
    for (int i = 0; i < 10; ++i) {
       if (bit & (1 << i)) openJ[9 - i] = 1;
    }

    vector<int> dock(N, 0);
    for(int i=0; i<N; i++){
      for(int j=0; j<10; j++){
        if(openJ[j] == 1 && openStore[i][j] == 1) dock[i]++;
      }
    }

    ll sum = 0;
    for(int i=0; i<N; i++){
      sum += point[i][dock[i]];
    }
    maxScore = max(maxScore, sum);
  }

  cout << maxScore << ln;
 }


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	int n;
	cin >> n;
	cout << n*800-n/15*200 << endl;
}

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

int main() {
	char ch;
	int counter[26] = { 0 };
	while (cin >> ch) {
		ch = tolower(ch);
		int num = ch - 'a';
		counter[num]++;
	}
	for (int i = 0;i < 26;i++)
		cout << (char)(i + 'a') << " : " << counter[i] << endl;
}

Measured memory_bytes: 3076
n = int(input())
A = [0]*n
for i in range(n):
    A[i] = int(input())-1

i = 0
d = 0
c = 0
for _ in range(n):
    c += 1
    d = A[i]
    if d==1:
        break
    else:
        i = d
print(c if c!=n else -1)

Measured memory_bytes: 6900