akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
int main() {
    int N;
    cin >> N;
    double sum = 0;
    double jp = 0;
    double bt = 0;
    for(int i = 0; i < N; i++) {
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY") {
            jp += x;
        } else if(u == "BTC") {
            bt += x;
        }
    }
    // cout << jp << " " << bt << endl;
    bt *= 380000;
    // cout << jp << " " << bt << endl;
    printf("%.5lf", jp+bt);
    // cout << jp + bt << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] array = new long[n];
		long num=-999999999;
		long max = 0;

		for(int i=0;i<n;i++) {
			array[i] = sc.nextLong();
		}

		for(int i=n-1;i>=1;i--) {
			if(array[i]>max) {
				max = array[i];
			}else {
				continue;
			}
			for(int j=i-1;j>=0;j--) {
				if(array[i]-array[j]>num) {
					num = array[i] - array[j];
				}
			}
		}
		System.out.println(num);

	}

	public static boolean judge(long input) {
		if(input == 2) {
			return true;
		}
		if(input <= 1 || input%2 ==0) {
			return false;
		}

		for(int i=3;i<=Math.sqrt(input);i+=2) {
			if(input % i == 0) return false;
		}
		return true;
	}
}



Measured memory_bytes: 103844
import java.util.Scanner;
import java.util.Arrays;
public class Main {
        public static int ii[];
        public static void main(String[] args){
                Scanner in = new Scanner(System.in);
                while(true){
                        int n = in.nextInt();
                        if(n == 0){
                                break;
                        }
                        ii = new int[n];
                        for(int i = 0;i < n; ++i){
                                ii[i] = in.nextInt();
                        }
                        Arrays.sort(ii);
                        int x = ii[0];
                        int c = 1;
                        boolean yet = true;
                        for(int i = 1;i < n; ++i){
                                if(x == ii[i]){
                                        ++c;
                                } else {
                                        if(c > n/2){
                                                System.out.println(x);
                                                yet = false;
                                                break;
                                        }
                                        x = ii[i];
                                        c = 1;
                                }
                        }
                        if(yet && c > n/2){
                                System.out.println(x);
                        } else if(yet){
                                System.out.println("NO COLOR");
                        }
                }
        }
}

Measured memory_bytes: 21000
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define forn(i,n) for(int i = 0; i < (int) n; i++)
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define inf 250000
using namespace std;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

int min(int a, int b, int c, int d) {
  return min(min(a, b), min(c, d));
}

int main() {
  ios;
  int n;
  cin >> n;

  vector<vector<bool>> oc(n, vector<bool>(n, 1));
  vector<vector<int>> dist(n, vector<int>(n));
  forn(i, n) forn(j, n) {
    dist[i][j] = min(i, j, n - i - 1, n - j - 1);
  }

  long long ans = 0;

  forn(tt, n * n) {
    int x;
    cin >> x;
    x--;
    int i = x / n, j = x % n;
    oc[i][j] = 0;
    ans += dist[i][j];

    queue<pair<int, int>> q;
    forn(d, 4) {
      int x = i + dx[d], y = j + dy[d];
      if (x < 0 || x >= n || y < 0 || y >= n) continue;
      if (dist[x][y] > dist[i][j]) {
        dist[x][y] = dist[i][j];
        q.push({x, y});
      }
    }

    while(!q.empty()) {
      i = q.front().first;
      j = q.front().second;
      q.pop();

      forn(d, 4) {
        int x = i + dx[d], y = j + dy[d];
        if (x < 0 || x >= n || y < 0 || y >= n) continue;

        if (dist[x][y] > dist[i][j] + oc[i][j]) {
          dist[x][y] = dist[i][j] + oc[i][j];
          q.push({x, y});
        }
      }
    }
  }

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


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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define bit(n) (1LL<<(n))
// functions
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  ll a, b;
  cin >> a >> b;
  cout << max(a + b, max(a - b, a * b)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main()
{
  int N;
  cin >> N;
  int P[200000];
  for (int i = 0; i < N; ++i) {
    cin >> P[i];
  }
  int ans = 0;
  int m = P[0];
  for (int i = 0; i < N; ++i) {
    m = min(m, P[i]);
    if (m >= P[i]) {
      ans++;
    }
  }
  
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i,n) cin >> l[i];

  int sum = accumulate(l.begin(), l.end(), 0);
  int maxi = *max_element(l.begin(), l.end());

  cout << ((sum - maxi > maxi) ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, d[55][55] = {};
    string s[55] = {};
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> s[i], s[i] = '#' + s[i] + '#';
    for (int i = 0; i <= m + 1; i++) s[0] += '#', s[n + 1] += '#';
    queue<pii> q;
    q.push({1, 1});
    d[1][1] = 1;
    while (!q.empty()) {
        int x = q.front().first, y = q.front().second;
        q.pop();
        if (s[x - 1][y] == '.' && !d[x - 1][y]) d[x - 1][y] = d[x][y] + 1, q.push({x - 1, y});
        if (s[x + 1][y] == '.' && !d[x + 1][y]) d[x + 1][y] = d[x][y] + 1, q.push({x + 1, y});
        if (s[x][y - 1] == '.' && !d[x][y - 1]) d[x][y - 1] = d[x][y] + 1, q.push({x, y - 1});
        if (s[x][y + 1] == '.' && !d[x][y + 1]) d[x][y + 1] = d[x][y] + 1, q.push({x, y + 1});
    }
    if (!d[n][m]) cout << -1;
    else {
        int z = 0;
        for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (s[i][j] == '.') z++;
        cout << z - d[n][m];
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int X,Y;
    scanf("%x%x",&X, &Y);
    if(X<Y)
    {
        printf("<");
    }
    if(Y<X)
    {
        printf(">");
    }
    if(X==Y)
    {
        printf("=");
    }
        return 0;
}

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


  
int main(){
  

  int64_t n,m;
  cin>>n>>m;
  
  int64_t answer=1;
  

  for (int64_t i=1;i<=n;i++){
    answer=(answer*i)%1000000007;
  }
  
  for (int64_t i=1;i<=m;i++){
    answer=(answer*i)%1000000007;
  }
  
  if (n==m){
    cout<<(answer*2)%1000000007;
  }
  
  else if (n==m+1 or n==m-1){
    cout<<answer<<endl;
  }
  
  else {
    cout<<0<<endl;
  }
  
      
}
  

















Measured memory_bytes: 256
x,y=list(map(int, input().split()))
ret=0
if(x==3):ret+=100000
if(x==2):ret+=200000
if(x==1):ret+=300000
if(y==3):ret+=100000
if(y==2):ret+=200000
if(y==1):ret+=300000
if(x==1 and y==1):ret+=400000

print (ret)

Measured memory_bytes: 38256
n, m = map(int, input().split())
X = [0]*n
X[0] = 1
C = [1]*n
for i in range(m):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    if X[x] == 1:
        if C[x] == 1:
            X[x] = 0
            X[y] = 1
            C[x] -= 1
            C[y] += 1
        else:
            X[x] = 1
            X[y] = 1
            C[x] -= 1
            C[y] += 1
    else:
        C[x] -= 1
        C[y] += 1

print(sum(X))


Measured memory_bytes: 75932
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;
	static boolean bElapsed = false;

	void solve() {
		int n = readNum();
		int[] idx = new int[5];
		for (int i = 0; i < n; i++) {
			String line = readLine();
			switch (line.charAt(0)) {
			case 'M':
				idx[0]++;
				break;
			case 'A':
				idx[1]++;
				break;
			case 'R':
				idx[2]++;
				break;
			case 'C':
				idx[3]++;
				break;
			case 'H':
				idx[4]++;
				break;
			}
		}
		long ans = 0;
		for (int i = 0; i < 3; i++) {
			for (int j = i + 1; j < 4; j++) {
				for (int k = j + 1; k < 5; k++) {
					if (idx[i] > 0 && idx[j] > 0 && idx[k] > 0) {
						ans += (long) idx[i] * idx[j] * idx[k];
					}
				}
			}
		}
		pln(ans);
	}

	int abs(int a) {
		return (a >= 0) ? a : -a;
	}

	int max(int a, int b) {
		return (a > b) ? a : b;
	}

	int min(int a, int b) {
		return (a < b) ? a : b;
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++) {
			nums[i] = pint(flds[i]);
		}
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	static BufferedReader _in;
	static PrintWriter _out;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.err.println((end - start) + "ms");
		}
	}
}


Measured memory_bytes: 30884
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

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

  int h,w,n;
  cin >> h >> w >> n;
  
  int grid[h*w];
  int cnt = 0;
  REP(i,n){
    int a;
    cin >> a;
    while(a != 0){
      grid[cnt] = i+1;
      a--;
      cnt++;
    }
  }
  cnt = 0;
  REP(i,h){
    REP(j,w){
      if(i % 2 == 0) cout << grid[i*w+j] << " ";
      else           cout << grid[(i+1)*w-j-1] << " ";
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<queue>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
const int inf=0x3f3f3f3f;
queue<int>Q;
struct edge
{
	int x,y,c,next;long long w;
}a[30010];int len,last[510];
inline void trins(int x,int y,int c,long long w)
{
	len++;
	a[len].x=x;a[len].y=y;a[len].c=c;a[len].w=w;
	a[len].next=last[x];last[x]=len;
}
inline void ins(int x,int y,int c,long long w){trins(x,y,c,w),trins(y,x,0,-w);}
int st,ed,pre[510],f[510];
bool v[510];
long long d[510]; 
inline bool spfa()
{
	memset(d,-63,sizeof(d));
	memset(v,false,sizeof(v));
	Q.push(st);f[st]=inf,d[st]=0,v[st]=true;f[ed]=-1;
	while(!Q.empty())
	{
		int x=Q.front();Q.pop();
		for(int k=last[x];k;k=a[k].next)
		{
			if(!a[k].c)continue;
			int y=a[k].y;
			if(d[y]<d[x]+a[k].w)
			{
				d[y]=d[x]+a[k].w;pre[y]=k;f[y]=min(f[x],a[k].c);
				if(v[y]==false)v[y]=true,Q.push(y);
			}
		}v[x]=false;
	}
	if(f[ed]==-1)return false;
	else return true;
}
int sum;
long long ans;
inline void solve()
{
	int x=ed;
	while(x!=st)
	{
		int k=pre[x];
		a[k].c-=f[ed],a[k^1].c+=f[ed];
		x=a[k].x;
	}sum+=f[ed],ans+=f[ed]*d[ed];
}
struct query
{
	int id,x,y;
}q[350];
struct point
{
	int x,y;long long c;
}p[100];
int L[2][100],R[2][100];
char ss[2];
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n=read();
	for(int i=1;i<=n;i++)scanf("%d%d%lld",&p[i].x,&p[i].y,&p[i].c);
	int m=read();
	for(int i=1;i<=m;i++)
	{
		scanf("%s%d%d",ss+1,&q[i].x,&q[i].y);
		if(ss[1]=='L')q[i].id=0;
		if(ss[1]=='R')q[i].id=2;
		if(ss[1]=='D')q[i].id=1;
		if(ss[1]=='U')q[i].id=3;
	}
	long long mx=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i;j++)L[0][j]=L[1][j]=1,R[0][j]=R[1][j]=100;
		for(int j=1;j<=m;j++)
		{
			if(q[j].id<2)L[q[j].id][q[j].y+1]=q[j].x+1;
			else if(i>q[j].y)R[q[j].id-2][i-q[j].y]=q[j].x-1;
		}
		for(int j=2;j<=i;j++)L[0][j]=max(L[0][j],L[0][j-1]),L[1][j]=max(L[1][j],L[1][j-1]);
		for(int j=i-1;j>=1;j--)R[0][j]=min(R[0][j],R[0][j+1]),R[1][j]=min(R[1][j],R[1][j+1]);
		len=1,memset(last,0,sizeof(last));
		st=0,ed=2*n+1;
		for(int j=1;j<=n;j++)ins(j,j+n,1,p[j].c);
		int now=ed+1;
		for(int j=1;j<=i;j++)
		{
			ins(st,now,1,0),ins(now+1,ed,1,0);
			for(int k=1;k<=n;k++)
			{
				if(p[k].x>=L[0][j] && p[k].x<=R[0][j])ins(now,k,1,0);
				if(p[k].y>=L[1][j] && p[k].y<=R[1][j])ins(k+n,now+1,1,0);
			}now+=2;
		}
		sum=ans=0;
		while(spfa()==true)solve();
		if(sum==i)mx=max(mx,ans);
	}printf("%lld\n",mx);
	return 0;
}

Measured memory_bytes: 640
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


int root(int[] uf, int u) {
  return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));
}
bool connect(int[] uf, int u, int v) {
  u = uf.root(u);
  v = uf.root(v);
  if (u == v) return false;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
  return true;
}


int N, H, W;
int[] X, Y;
long[] A;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      H = readInt();
      W = readInt();
      X = new int[N];
      Y = new int[N];
      A = new long[N];
      foreach (i; 0 .. N) {
        X[i] = readInt() - 1;
        Y[i] = readInt() - 1;
        A[i] = readLong();
      }
      
      auto uf = new int[H + W];
      uf[] = -1;
      auto cnt = new int[H + W];
      
      auto es = new Tuple!(long, int)[N];
      foreach (i; 0 .. N) {
        es[i] = tuple(A[i], i);
      }
      sort(es);
      reverse(es);
      
      long ans;
      foreach (e; es) {
        const i = e[1];
        const ru = uf.root(X[i]);
        const rv = uf.root(H + Y[i]);
        if (ru == rv) {
          if ((-uf[ru]) >= cnt[ru] + 1) {
            ans += A[i];
            cnt[ru] += 1;
          }
        } else {
          if ((-uf[ru]) + (-uf[rv]) >= cnt[ru] + cnt[rv] + 1) {
            ans += A[i];
            uf.connect(ru, rv);
            cnt[uf.root(ru)] = cnt[ru] + cnt[rv] + 1;
          }
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 8316
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[100010];
    rep(i,0,N) cin >> A[i];
    sort(A, A+N);
    if(A[N-1] - A[0] >= 2){
        print("No");
    }else{
        if(A[N-1] == A[0]){
            if(A[0] <= N/2 || A[0] == N-1){
                print("Yes");
            }else{
                print("No");
            }
        }else{
            ll cnt = 0;
            rep(i,0,N){
                if(A[i] == A[0]) cnt++;
            }
            ll v = A[0] + 1 - cnt;
            if(v <= 0){
                print("No");
                return 0;
            }
            if((N-cnt) / 2 >= v){
                print("Yes");
            }else{
                print("No");
            }

        }

    }
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

A = int(input())
L = [int(v) for v in input().split()]
L.sort()

for i in range(A - 1):
    L[i] = (L[i] + L[i + 1]) / 2
    L[i + 1] = 0

    L.sort()

print(L[-1])

Measured memory_bytes: 3064
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
hash = {}
1.step(N) do |i|
  a = get_int
  hash[i] = {
    honest: [],
    unkind: [],
  }
  a.times do
    x, y = get_ints
    if y == 1
      hash[i][:honest].push(x)
    else
      hash[i][:unkind].push(x)
    end
  end
end

high = N
low = 0

# while high - low > 1
#   mid = low + (high - low) / 2
#   success = false
#   [*1..N].combination(mid).each do |c|
#     honest_set = Set.new
#     unkind_set = Set.new
#     contradiction = false
#
#     c.each do |data|
#       honest_set.merge(hash[data][:honest])
#       unkind_set.merge(hash[data][:unkind])
#     end
#
#     if (c.to_set & honest_set).length != honest_set.length
#       contradiction = true
#     else
#       contradiction = true if (c.to_set & unkind_set).length > 0
#     end
#
#     if !contradiction
#       # 矛盾がない
#       p c
#       success = true
#       break
#     end
#   end
#
#   if success
#     low = mid
#   else
#     high = mid
#   end
# end
#
# puts low

n = N
while n > 0
  mid = n
  success = false
  [*1..N].combination(mid).each do |c|
    honest_set = Set.new
    unkind_set = Set.new
    contradiction = false

    c.each do |data|
      honest_set.merge(hash[data][:honest])
      unkind_set.merge(hash[data][:unkind])
    end

    if (c.to_set & honest_set).length != honest_set.length
      contradiction = true
    else
      contradiction = true if (c.to_set & unkind_set).length > 0
    end

    if !contradiction
      # 矛盾がない
      success = true
      break
    end
  end

  break if success
  n -= 1
end

puts n


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

int main(){
  bool flag=true;
  string s;
  cin >> s;
  for(int i=0; i<s.length(); i++){
    if(i%2==0){
      if(s[i]=='L')flag=false;
    }
    else if(s[i]=='R')flag=false;
  }
  cout << (flag ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 760
#include<iostream>

using namespace std;

int main()
{int A, B ,C; cin >> A >> B >> C;
 int M = max(max(A,B),C);
 int N = 3*M - ( A + B + C);
 if(N % 2 == 0){//MをXとして採用// 
   cout << N / 2 << endl;}
 else{ // M + 1　をX　として採用
   cout << ((3*(M + 1 ) - ( A + B + C ))/2) << endl;}
 
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n;
	cin>>n;
	int time[1000];
	int i,j;
	for(i=1; i<=n; i++) {
		cin>>time[i];
	}
	int m;
	cin>>m;
	int p[1000],x[1000];
	for(j=1; j<=m; j++) {
		cin>>p[j]>>x[j];
	}
	int res[1000]= {0};
	for(j=1; j<=m; j++) {
		for(i=1; i<=n; i++) {
			if(i==p[j]) {
				continue;
			} else {
				res[j]+=time[i];
			}
		}
		res[j]+=x[j];
	}
	for(i=1;i<=m;i++){
		cout<<res[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    string S;
    cin >> S;
    int N = S.size();
    int ans = 0;
    for(int i=0; i<N/2; i++){
        if(S[i] != S[N-1-i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        while(true){
        int n = scanner.nextInt();
        if(n == 0){
            System.exit(0);
        }
        int[] cand = new int[26];
        boolean flag = false;
        char a = 'A';
        int no1 = 0;
        int no2 = 0;
        int num = 0;
        int no1num = 0;
        int no2num = 0;
        for(int i = 0;i < n;i++){
            String vote1 = scanner.next();
            char[] vote2 = vote1.toCharArray();
            char vote = vote2[0];
            for(int j = 0;j<26;j++){
                if(a+j == vote){
                    no1num = cand[no1];
                    no2num = cand[no2];
                    cand[j]++;
                    if(cand[j]>no1num){
                        if(j == no2){
                            no2 = no1;
                            no1 = j;
                        }else{
                        no1 = j;
                        }
                    }else if(cand[j]>no2num){
                        no2 = j;
                    }
                    if(cand[no1]-cand[no2]>n-i-1){
                        flag = true;
                        num = i+1;
                        break;
                    }
                    break;
                }
            }
            if(flag == true){
                break;
            }
        }
        if(n == 1){
            System.out.println((char)(a+no1)+" "+n);
        }
        else if(cand[no1] == cand[no2]){
            System.out.println("TIE");
        }else{
            System.out.println((char)(a+no1)+" "+num);
        }
        String gomi = scanner.nextLine();
    }
    }
}


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

int main() {
	int A, B, X;
	cin >> A >> B >> X;
	int ans = 0;
	int thou = X / 1000, hund = thou * 2;
	ans += min(A * thou, B * hund);
	X -= thou * 1000;
	int sum = (X / 500) *  B;
	if (X % 500 != 0) sum += B;
	ans += min(sum, A);
	cout << ans << endl;
}


Measured memory_bytes: 3116
#8:47
MOD=10**9+7
INT_MAX=10**20+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#################################################################################
A=INPUT()
for i in range(5):
    if A[i]==0:
        print(i+1)
        break
        


Measured memory_bytes: 61936
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int[] nums = new int[5];
        for(int i = 0 ; i < nums.length ; i++){
        	nums[i] = input.nextInt();
        }
        Arrays.sort(nums);
        for(int i = nums.length-1 ; i >= 0 ; i--){
        	if(i == 0){
        		System.out.println(nums[i]);
        	}else{
        		System.out.print(nums[i]+" ");
        	}
        }
    }
}

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

using namespace std;


int main()
{
    int N;

    cin >> N;
    vector<int> A, C;

    for ( int i = 0; i < N; i ++ ) {
        int a;
        cin >> a;
        A.push_back( a ); 
        C.push_back( a );
    }

    sort( C.begin(), C.end() );

    int m;
    for ( int i = 0; i < N; i ++ ) {
        m = C[ C.size() - 1 ];
        if ( m == A[i] ) {
            m = C[ C.size()-2 ];
        }
        cout << m << endl;
    }

    return 0;
}


Measured memory_bytes: 3436
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
dp = [10**5 for _ in range(h+1)]
dp[0] = 0
for i in range(1,h+1):
    dp[i] = min([dp[max(0, i-pw)]+ma for pw, ma in ab])
print(dp[h])

Measured memory_bytes: 45420
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

const int MAX = 1000010;
struct BIT {
  int bit[MAX] = {};
  void add(int i, int n) {
    while (i < MAX) {
      bit[i] += n;
      i += i & -i;
    }
  }
  int sum(int i) {
    int res = 0;
    while (i > 0) {
      res += bit[i];
      i -= i & -i;
    }
    return res;
  }
  void clear() {
    for (int i = 1; i < MAX; i++)
      bit[i] = 0;
  }
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  string s;
  cin >> n >> s >> q;
  vector<BIT> alf(26);
  rep(i, s.size())
    alf[s[i]-'a'].add(i+1, 1);
  rep(query, q) {
    int x;
    cin >> x;
    if (x == 1) {
      int i;
      char c;
      cin >> i >> c;
      --i;
      alf[s[i]-'a'].add(i+1, -1);
      alf[c-'a'].add(i+1, 1);
      s[i] = c;
    } else {
      int l, r;
      cin >> l >> r;
      --l;
      int res = 0;
      rep(i, 26) {
        if (alf[i].sum(r)-alf[i].sum(l))
          res++;
      }
      cout << res << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 102556
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
S = gets.chomp

sx = S.split('')

count = 0
last = nil
sx.each do |s|
  count += 1 if last != s
  last = s
end

puts count


Measured memory_bytes: 19292
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    int N;
    int K;
    int d;
    int *A;
    int *ans;
    int count = 0;
    int b;
    int c;
    scanf("%d", &N);
    scanf("%d", &K);
    ans = (int *)malloc(sizeof(int) * (N + 1));
    ans[0] = 0;
    for (c = 1; c <= N; ++c)
    {
        ans[c] = 1;
    }
    for (b = 0; b < K; ++b)
    {
        scanf("%d", &d);
        A = (int *)malloc(sizeof(int) * d);
        for (c = 0; c < d; ++c)
        {
            scanf("%d", A + c);
            ans[A[c]] = 0;
        }
        free(A);
    }
    for (b = 1; b <= N; ++b)
    {
        if (ans[b] != 0)
        {
            ++count;
        }
    }
    printf("%d", count);
    return 0;
}

Measured memory_bytes: 1728
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define maxn 200005
#define ll long long 
using namespace std;

int n,i,j,k,a[maxn],d[maxn],v[maxn],w;

int check(int K){
	if (K==1){
		for(int i=2;i<=n;i++) if (a[i]<=a[i-1])
			return 0;
		return 1;
	}
	w=1,d[w]=a[1],v[w]=0;
	for(i=2;i<=n;i++) if (a[i]<=a[i-1]){
		while (d[w]>a[i]) w--;
		if (d[w]<a[i]) w++,d[w]=a[i],v[w]=1; else {
			for(j=a[i];j>=0;j--) if (w&&d[w]==j&&v[w]+1==K) w--;
			else {
				if (j==0) return 0;
				if (w==0||d[w]!=j) w++,d[w]=j,v[w]=1; else 
					v[w]++;
				break;
			}
		}
	}
	return 1;
}

int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	int l=1,r=n,mid,ans;
	while (l<=r){
		mid=(l+r)>>1;
		if (check(mid)) r=mid-1,ans=mid;
		else l=mid+1;
	}
	printf("%d",ans);
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  }
  int mindf = 1000;
  int ans = 0;
  for(int i = 0; i < n; i++){
    int d = abs(a[i]*n - sum);
    if(mindf > d){
      mindf = d;
      ans = i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import numpy as np
NK = list(map(int, input().split()))
N = NK[0]
K = NK[1]
trick = N
lists = np.zeros(N)
for i in range(K):
    d = int(input())
    A = input().split()
    for j in range(d):
        if lists[int(A[j])-1] == 0:
            lists[int(A[j])-1] = 1
            trick -= 1
print(trick)

Measured memory_bytes: 27104
def mod_inv(n,p):
    if n<0:
        return - mod_inv(-n,p) % p
    if n>p:
        return mod_inv(n % p, p)
    
    def mod_inv_calc(a,b):
        if b==0:
            return (a,1)
        else:
            s,t = mod_inv_calc(b, a % b)
            d = a//b
            return (t, -t*d+s)

    return mod_inv_calc(p,n)[1] % p

N = int(input())
A = [int(a) for a in input().split()]
p = 10**9+7
inv_list = [mod_inv(i+1,p) for i in range(N+2)]

fact_list = [1]
for i in range(N):
    fact_list.append(fact_list[i] * (i+1) % p)
s = 0
sum_list = [inv_list[i] * fact_list[N] % p for i in range(N+2)]

for i in range(N):
    s += inv_list[i]
    
s *= fact_list[N]
s %= p
ans = 0
for i in range(N):
    ans += A[i]*s
    ans %= p
    s += (sum_list[i+1] - sum_list[N-i-1])
    s %= p
    
print (ans)

Measured memory_bytes: 19328
n = io.read("*n", "*l")
t = {}
t.AC = 0
t.WA = 0
t.TLE = 0
t.RE = 0
for i = 1, n do
  s = io.read()
  t[s] = t[s] + 1
end
print("AC x " .. t.AC)
print("WA x " .. t.WA)
print("TLE x " .. t.TLE)
print("RE x " .. t.RE)


Measured memory_bytes: 2792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll gcd(ll x, ll y) { return (y ? gcd(y, x % y) : x); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main() {
	init();

	string s; cin >> s;
	deque<char>ans;
	rep(i, 0, s.size()) {
		ans.push_back(s[i]);
	}
	int Q; cin >> Q;
	bool dir = true;
	rep(i, 0, Q) {
		int a; cin >> a;
		if (a == 1) {
			dir ^= 1;
		}
		else {
			int b; cin >> b;
			char ch; cin >> ch;
			if (b == 1) {
				if (dir) {
					ans.push_front(ch);
				}
				else ans.push_back(ch);
			}
			else {
				if (dir) {
					ans.push_back(ch);
				}
				else ans.push_front(ch);
			}
		}
	}
	if (dir) {
		rep(i, 0, ans.size()) {
			cout << ans[i];
		}
		cout << "\n";
	}
	else {
		rREP(i, 0, ans.size()) {
			cout << ans[i];
		}
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 4008
#include<stdio.h>

int main() {
	char str[100001];
	int acs[100000];
	int N, Q, i,init, end,ct=0,flag=0;
	scanf("%d %d", &N, &Q);
	scanf("%s", str);
	for (i = 0; i < N; i++) {
		if (str[i] == 'A') { flag = 1; }
		else { if (str[i] == 'C'&&flag == 1) { ct++; }flag = 0; }
		acs[i] = ct;
	}
	for (i = 0; i < Q; i++) {
		scanf("%d %d", &init, &end);
		printf("%d\n", acs[end-1] - acs[init-1]);
	}
	return 0;
}


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

const int MAXN=300010;

int n, a, b, l, r, sum, tot=0, now=0;
vector<int> ans[MAXN];

int main() {
	scanf("%d%d%d", &n, &a, &b);
	if(a+b-1>n || 1ll*a*b<1ll*n) {
		puts("-1");
		return 0;
	}
	sum=0;
	for(int i=1;i<a;++i) {
		int now=1+min(b-1, n-sum-b-a+i);
		for(int j=now;j;--j) {
			ans[i].push_back(sum+j);
		}
		sum+=now;
	}
	int on=n;
	for(int i=1;i<=b;++i) {
		ans[a].push_back(on--);
	}
	for(int i=1;i<=n;++i) {
		for(int j=0;j<(int)ans[i].size();++j) {
			printf("%d ", ans[i][j]);
		}
	}
	return 0;
}

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

int main() {
  int a,b,t;
  cin >> a >> b >> t;
  
  int sum = 0;
  int x = 2*t + 1 - 2*a;
  
  while( x >= 0){
    x -= 2*a;
    sum += b;
  }
   
  cout << sum;
  
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define INF 1000000000000000
#define MAXN (int)(1e6)+1
#define MOD 998244353

using namespace std;

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pwi;
typedef pair<lli,lli> plli;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector< vector<pair<int,lli > > > wGraph;
typedef vector<vector<int> > graph;
//typedef vector<vector<int> > matrix;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(6);

    lli a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;

    return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int N, A[10005], e[1000005];
ll modpow(ll a, ll m){
  ll b = 1LL;
  while(m != 0){
    if(m & 1) b = b*a%MOD;
    a = a*a%MOD;
    m = m>>1; 
  }
  return b;
}
int main() {
  scanf("%d", &N);
  ll lcm = 1LL;
  for(int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]); int x = A[i];
    for(int j = 2; j*j <= x; ++j) {
      int t = 0;
      while(x%j == 0) x /= j, ++t;
      e[j] = max(e[j], t);
    }
    e[x] = max(e[x], 1);
  }
  for(int i = 2; i <= 1000000; ++i) {
    while(e[i]--) lcm = lcm*i%MOD;
  }
  ll ans = 0;
  for(int i = 1; i <= N; ++i) {
    ans = (ans+lcm*modpow(A[i], MOD-2))%MOD;
  }
  printf("%ld\n", ans);
}

Measured memory_bytes: 4096
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = mutableListOf<String>()
    for (i in 0 until n) {
        s.add(readLine()!!)
    }

    val m = readLine()!!.toInt()
    val t = mutableListOf<String>()
    for (i in 0 until m) {
        t.add(readLine()!!)
    }

    var max = 0

    for (i in 0 until n) {
        var score = 0
        val target = s[i]
        for (j in 0 until n) {
            if (s[j] == target) {
                score += 1
            }
        }

        for (j in 0 until m) {
            if (t[j] == target) {
                score -= 1
            }
        }

        max = Math.max(max, score)
    }

    println(max)
}

Measured memory_bytes: 33732
// Author: Jinhai Chen
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long ll;

ll a[45];

int main() {
#ifdef CJHCJH
	freopen("data.in","r",stdin);
#endif
	int n;
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	ll sum=0;
	for(int i=0;i<n-1;i++) sum+=a[i];
	if(sum>a[n-1]) puts("Yes");
	else puts("No");


	return 0;
}














Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    int x=x2,y=y2;
    int dx,dy;
    dx=x2-x1;
    dy=y2-y1;

    for (int i=0;i<2;i++){
        swap(dy,dx);
        dx=-dx;
        x+=dx;
        y+=dy;
        cout<<x<<" "<<y<<endl;
    }
    return 0;
}

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

int main(){
    int r; cin >> r;
    int ans = pow(r, 2) * 3;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long

using namespace std;

string s;
int cnt[2019];

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	int n = s.length();
	
	int i;
	int r = 0;
	int t = 1;
	cnt[r]++;
	for (i = s.length() - 1; i >= 0; i--) {
		r = (r + (s[i] - '0') * t) % 2019;
		t = (t * 10) % 2019;
		cnt[r]++;
	}
	
	int ans = 0;
	for (i = 0; i < 2019; i++) {
		ans += cnt[i] * (cnt[i] - 1) / 2;
	}
	cout << ans << endl;
	
	return 0;
}


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

int main(){
  int n,m,p;
  string s;
  while(cin>>n,n){
    m=1;
    int d[6]={1,6,2,5,3,4};
    while(n--){
      cin>>s;
      switch(s[0]){
      case 'N':
	p=d[0];d[0]=d[2];d[2]=d[1];d[1]=d[3];d[3]=p;m+=d[0];break;
      case 'E':
	p=d[0];d[0]=d[5];d[5]=d[1];d[1]=d[4];d[4]=p;m+=d[0];break;
      case 'W':
	p=d[0];d[0]=d[4];d[4]=d[1];d[1]=d[5];d[5]=p;m+=d[0];break;
      case 'S':
	p=d[0];d[0]=d[3];d[3]=d[1];d[1]=d[2];d[2]=p;m+=d[0];break;
      case 'R':
	p=d[2];d[2]=d[4];d[4]=d[3];d[3]=d[5];d[5]=p;m+=d[0];break;
      case 'L':
	p=d[2];d[2]=d[5];d[5]=d[3];d[3]=d[4];d[4]=p;m+=d[0];break;
      }
    }
    cout<<m<<endl;
  }
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main() {
    fastio;
    int n;
    cin >> n;
    int* a = new int[n];
    for (int i = 0; i < n; ++i) cin >> a[i];
    int ans = INT_MAX;
    int lo = *min_element(a, a + n), hi = *max_element(a, a+n);
    for (int i = lo; i <= hi; ++i) {
        int cost = 0;
        for (int j = 0; j < n; ++j) {
            cost += (a[j] - i) * (a[j] - i);
        }
        ans = min(ans, cost);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define forr(i,m,n) for (int i=(m); i<=(n); i++)

#define MAXN 100000
int main() {
  int n;
  int a[MAXN], b[MAXN], c[MAXN];
  int x[MAXN], y[MAXN], z[MAXN];
  cin >> n;
  forr(i,0,n-1) {
    cin >> a[i] >> b[i] >> c[i];
  }
  x[0] = a[0];
  y[0] = b[0];
  z[0] = c[0];
  forr(i,1,n-1) {
    x[i] = max(a[i] + y[i-1], a[i] + z[i-1]);
    y[i] = max(b[i] + x[i-1], b[i] + z[i-1]);
    z[i] = max(c[i] + y[i-1], c[i] + x[i-1]);
  }
  cout << max(x[n-1], max(y[n-1], z[n-1]));
}


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


int b[102];
int main() {
	int n;
	cin >> n;
	int i;
	for(i=1;i<=n-1;i++)
	    cin>> b[i];
	
	
	b[0] = b[n] = 1e9;
	
	int sum =0 ;
	for(i=1;i<=n;i++)
	    sum+=min(b[i], b[i-1]);
	cout<<sum<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int n, m;
    long long ans=0;
    
    cin >> n >> m;
    
    ans = 1900 * m + 100 * (n-m);
    ans *= pow(2, m);
    
    cout << ans << endl;
    
    return 0;
    
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

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

int number(char s) {
	switch(s) {
		case 'I' : return 1;
		case 'V' : return 5;
		case 'X' : return 10;
		case 'L' : return 50;
		case 'C' : return 100;
		case 'D' : return 500;
		case 'M' : return 1000;
	}
	return 0;
}

int main() {
	string s;
	while(cin >> s) {
		int tmp = number(s[0]);
		int num = number(s[1]);
		int ans;
		if(tmp < num) ans = num - tmp;
		else if(tmp >= num) ans = num + tmp;
		tmp = num; 
		FOR(i, 2, s.size()) {
			num = number(s[i]);
			if(tmp < num) {
				ans -= tmp;
				ans += num - tmp;
			}
			else if(tmp >= num) ans += num;
			tmp = num;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2984
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    int a, b, c, d;
    int left, right;

    cin >> a >> b >> c >> d;

    left = a + b;
    right = c + d;

    if (left < right) {
        cout << "Right";
    } else if (left > right) {
        cout << "Left";
    } else {
        cout << "Balanced";
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.v = [-1 for _ in range(n)]  # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed)
        self.bk = [1 if s[r][c] == '#' else 0 for r in range(H) for c in range(W)]
        self.wt = [1 if s[r][c] == '.' else 0 for r in range(H) for c in range(W)]

    def find(self, x):  # xを含む木における根の頂点番号を返す
        if self.v[x] < 0:  # (負)は根
            return x
        else:  # 根の頂点番号
            self.v[x] = self.find(self.v[x])  # uniteでは, 旧根に属する頂点の根が旧根のままなので更新
            return self.v[x]

    def unite(self, x, y):  # 違う根に属していたらrankが低くなるように連結
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if -self.v[x] < -self.v[y]:  # size比較, 　(-1) * (連結頂点数 * (-1)), (正)同士の大小比較
            x, y = y, x  # 連結頂点数が少ない方をyにすると, findでの更新回数が減る？
        self.v[x] += self.v[y]  # 連結頂点数の和を取る, 連結頂点数 * (-1)
        self.v[y] = x  # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする

        self.bk[x % (H * W)] += self.bk[y % (H * W)]
        self.wt[x % (H * W)] += self.wt[y % (H * W)]

    def root(self, x):
        return self.v[x] < 0  # (負)は根

    def same(self, x, y):
        return self.find(x) == self.find(y)  # 同じ根に属するか

    def size(self, x):
        return -self.v[self.find(x)]  # 連結頂点数を返す

    def calc(self, x):
        return self.bk[x % (H * W)] * self.wt[x % (H * W)]

dr = [0, 0, 1, -1]
dc = [1, -1, 0, 0]

H, W = map(int, input().split())
s = [input() for _ in range(H)]
uf = UnionFind(2 * H * W)  # 全頂点 * 2
for r in range(H):
    for c in range(W):
        if s[r][c] == '#':
            for i in range(4):
                nr = r + dr[i]
                nc = c + dc[i]
                if 0 <= nr < H and 0 <= nc < W:
                    if s[nr][nc] == '.':
                        uf.unite(r * W + c, H * W + (nr * W + nc))  # #: *1, .: * 2
        else:
            for i in range(4):
                nr = r + dr[i]
                nc = c + dc[i]
                if 0 <= nr < H and 0 <= nc < W:
                    if s[nr][nc] == '#':
                        uf.unite(H * W + (r * W + c), nr * W + nc)  # #: *1, .: * 2

ans = 0
for r in range(H):
    for c in range(W):
        if uf.root(r * W + c):
            # print(r, c, '#')
            sz = uf.size(r * W + c)
            # print(' ', r * W + c, sz, '#')
            if sz > 1:
                ans += uf.calc(r * W + c)

        if uf.root(H * W + (r * W + c)):
            # print(r, c, '.')
            sz = uf.size(H * W + (r * W + c))
            # print(' ', r * W + c, sz, '.')
            if sz > 1:
                ans += uf.calc(H * W + (r * W + c))

print(ans)
# print(uf.v)


Measured memory_bytes: 76812
a = [1 for i in range(51)]
p = [1 for i in range(51)]


def get(N, X):
    if N == 0:
        return 1 if X > 0 else 0
    elif X <= 1 + a[N-1]:
        return get(N-1, X-1)
    else:
        return p[N-1] + 1 + get(N-1, X-2-a[N-1])


def main():
    N, X = map(int, input().split())
    for i in range(N):
        a[i+1] = 2 * a[i] + 3
        p[i+1] = 2 * p[i] + 1
    ans = get(N, X)
    print(ans)


if __name__ == "__main__":
    main()


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


int main(){
    string S;
    cin>>S;
  	bool s;
    for(char i='a';i<='z';i++){
        s=false; 
        for(int j=0;j<S.size();j++){
            if(i==S[j])s=true;
        }
        if(!s){
            cout<<i<<endl;
            break;
        }
    }
  	if(s)cout<<"None"<<endl;
}

Measured memory_bytes: 512