akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int a,b;
    cin >> a >> b;
    if(a<b)rep(i,b)cout << a;
    else rep(i,a)cout << b;
}

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

int main() {
  char C;
  int i, n, k, l;
  k = 0;
  cin >> n;
  vector<vector<int> > data(14, vector<int>(4));
  for (int i = 1; i < 14; i++) {
    for (int j = 0; j < 4; j++) {
      data.at(i).at(j) = 0;
    }
  }
  while (k < n) {
    cin >> C >> l;
    if (C == 'S') {
      data.at(l).at(0) = 1;
    }
    else if (C == 'H') {
      data.at(l).at(1) = 1;
    }
    else if (C == 'C') {
      data.at(l).at(2) = 1;
    }
    else if (C == 'D') {
      data.at(l).at(3) = 1;
    }
    k++;
  }
  for (int j = 0; j < 4; j++) {
    for (int i = 1; i < 14; i++) {
      if (data.at(i).at(j) == 0) {
        if (j == 0) {
          cout << "S " << i << endl;
        }
        else if (j == 1) {
          cout << "H " << i << endl;
        }
        else if (j == 2) {
          cout << "C " << i << endl;
        }
        else if (j == 3) {
          cout << "D " << i << endl;
        }
      } 
    }
  }
}


Measured memory_bytes: 3168
#include <iostream>
using namespace std;
 
int field[10][10] = {0};
 
void small(int x,int y){
    int vx[4] = {-1,0,1,0};
    int vy[4] = {0,-1,0,1};
    if(x>=0 && x<10 && y>=0 && y<10)
        field[x][y]++;
    for(int i=0;i<4;i++){
        if(x+vx[i]>=0 && x+vx[i] <10 && y+vy[i]>=0 && y+vy[i]<10)
            field[x+vx[i]][y+vy[i]]++;
    }  
}
void mid(int x,int y){
    int vx[3] = {-1,0,1};
    int vy[3] = {-1,0,1};
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
        if(x+vx[i]>=0 && x+vx[i] <10 && y+vy[j]>=0 && y+vy[j]<10)
            field[x+vx[i]][y+vy[j]]++;
        }
    }
}
void large(int x,int y){
    int vx[4] = {-2,0,2,0};
    int vy[4] = {0,-2,0,2};
    mid(x,y);
    for(int i=0;i<4;i++){
        if(x+vx[i]>=0 && x+vx[i] <10 && y+vy[i]>=0 && y+vy[i]<10)
            field[x+vx[i]][y+vy[i]]++;
    }
}
 
void search()
{
    int m = 0;
    int zerocount = 0;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            if(field[i][j]==0)
                zerocount++;
            m = max(m,field[i][j]);
        }
    }
    cout << zerocount << endl;
    cout << m << endl;
}
int main()
{
    int x,y,size;
    char dot;
    while(cin >> x >> dot >> y >> dot >> size){
        if(size == 1)
            small(x,y);
        else if(size == 2)
            mid(x,y);
        else if(size == 3)
            large(x,y);
    }
    search();
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
  ll n;
  cin>>n;
  ll ans=1;
  for(ll i=1;i<=n;i++){
    if((ll)pow(i,2)<=n)ans=max((ll)pow(i,2),ans);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		long[] a = new long[n];
		long sum=0;
		HashMap<Long, Integer> map = new HashMap<>();
		for (i = 0; i < n; i++) {
			a[i] = parseInt(sc.next());
			if(map.get(a[i])==null) {
				map.put(a[i], 1);
			} else {
				map.put(a[i], map.get(a[i])+1);
			}
			sum+=a[i];
		}
		int q = parseInt(sc.next());
		long[] b = new long[q];
		long[] c = new long[q];
		for (i = 0; i < q; i++) {
			b[i] = parseLong(sc.next());
			c[i] = parseLong(sc.next());
		}
		sc.close();
		PrintWriter pw = new PrintWriter(System.out);
		for(i = 0; i < q; i++) {
			if(map.get(b[i])!=null) {
				sum-=b[i]*map.get(b[i]);
				sum+=c[i]*map.get(b[i]);
				if(map.get(c[i])==null) {
					map.put(c[i], map.get(b[i]));
				} else {
					map.put(c[i], map.get(c[i])+map.get(b[i]));
				}
				map.put(b[i], map.get(0));
			}
			pw.println(sum);
		}
		pw.flush();
	}
}


Measured memory_bytes: 60224
#include<bits/stdc++.h>
#define ll long long int
#define eps 1e-9
using namespace std;

int main()
{
    ll t,n,mi,mx,f,c,a,b,x,m,y,q,k;


    cin>>n>>m;
    t=0;
    for(int i=0; i<m; i++)
    {
        cin>>f;
        t+=f;
    }

    if(t>n)
    {
        cout<<-1<<endl;;
    }
    else
    {
        cout<<n-t<<endl;
    }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
int a, b, h, m;
long double p, q, t, Res;

int main()
{
	scanf("%d%d%d%d", &a, &b, &h, &m);
	p = (h + (long double)m / 60.0) * 30.0;
	q = m * 6.0;
	t = fabs(p - q);
	if (t > 180.0) t = 360.0 - t;
	Res = a * a + b * b - 2.0 * a * b * cos(t / 180.0 * pi);
	printf("%.10Lf\n", sqrt(Res));	
}

Measured memory_bytes: 4164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main()
{
    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;
    s[K - 1] = s[K - 1] + 32;
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n;
	cin >> n;
	vi a(3*n);
	rep(i, 3*n) cin >> a[i];
	sort(all(a));
	ll ans = 0LL;
	for(int i = n; i < 3 * n; i+= 2) ans += a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdio.h>
#include <set>
#include <vector>
using namespace std;


int main(){
    int w, h, n;
    int x = 0, y=0;
    cin>>w>>h>>n;

    int i, j;

    for(i=0; i<n; i++){
        int xi, yi, a;
        cin>>xi>>yi>>a;

        if(a==1){
            if(x<xi){
                x = xi;
            }
        }
        else if(a==2){
            if(w>xi){
                w = xi;
            }
        }
        else if(a==3){
            if(y<yi){
                y = yi;
            }
        }
        else if(a==4){
            if(h>yi){
                h = yi;
            }
        }
    }

    if(x>=w || y>=h){
        cout<<"0"<<endl;
    }
    else {
        cout<<(w-x)*(h-y)<<endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	printf("%.10lf\n",1.0*a/b);
	return 0;
} 

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int a,b; cin >> a >> b;
    cout << (a+b-1)/2 + 1 << endl;
    return 0;
}

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

public class Prime
{
    BitArray Sieve;
    // Sieve of Eratosthenes
    public void Init(int max)
    {
        Sieve = new BitArray(max + 1);
        var end = (int)(Math.Sqrt(max) + 0.1);
        Sieve.Set(1, true);
        for (int i = 2; i <= end; i++)
        {
            if (!Sieve.Get(i))
            {
                for (int j = i * 2; j <= max; j += i)
                {
                    Sieve.Set(j, true);
                }
            }
        }
    }

    public bool IsPrime(int n)
    {
        return !Sieve.Get(n);
    }

    public int[] GetPrimes(int n)
    {
        return Enumerable.Range(2, n - 1).Where(i => !Sieve.Get(i)).ToArray();
    }
}

public class PrimeFactorize
{
    int[] Primes;

    public PrimeFactorize(long n)
    {
        var prime = new Prime();
        var max = (int)(Math.Sqrt(n) + 1);
        prime.Init(max);
        Primes = prime.GetPrimes(max);
    }

    static List<long> Factorize(long n, int[] primes)
    {
        var factor = new List<long>();
        foreach (var p in primes)
        {
            while (n % p == 0)
            {
                factor.Add(p);
                n /= p;
            }
            if (n < p)
            {
                break;
            }
        }
        if (n > 1)
        {
            factor.Add(n);
        }
        return factor;
    }

    public List<long> Factorize(long n)
    {
        return Factorize(n, Primes);
    }
}

public static class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var pf = new PrimeFactorize((int)1e6);
        var factorCount = new int[(int)1e6];

        foreach (var a in A)
        {
            var fa = pf.Factorize(a);
            foreach (var f in fa.Distinct())
            {
                factorCount[f]++;
            }
        }

        var pairwise = factorCount.All(v => v <= 1);
        if (pairwise)
        {
            Console.WriteLine("pairwise coprime");
            return;
        }
        var setwise = factorCount.All(v => v != N);
        if (setwise)
        {
            Console.WriteLine("setwise coprime");
            return;
        }
        Console.WriteLine("not coprime");
    }
}

Measured memory_bytes: 117684
#define _USE_MATH_DEFINES //M_PI, M_E
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,y;
	cin>>n>>y;
	for(int i = 0; i<=2000; i++)
	{
		for(int j = 0; j<=2000; j++)
			for(int k = 0 ;k<=2000; k++)
			{
				if(i+j+k>n)break;
				else if(10000*i+5000*j+1000*k==y && i+j+k == n)
				{
					cout<<i<<" "<<j<<" "<<k<<endl;
					return 0;
				}
			}
	}
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

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

  deque<int> deq;
  deq.push_back(1);
  vector<int> dist(K, INF);
  dist[1] = 1;
  while (not deq.empty()) {
    int u = deq.front(); deq.pop_front();
    if (u == 0) {  break; }

    int v1 = (u + 1) % K;
    if (dist[v1] > dist[u] + 1) {
      dist[v1] = dist[u] + 1;
      deq.push_back(v1);
    }

    int v2 = (u * 10) % K;
    if (dist[v2] > dist[u]) {
      dist[v2] = dist[u];
      deq.push_front(v2);
    }
  }
  printf("%d\n", dist[0]);
  return 0;
}

Measured memory_bytes: 896
n=int(input())
a=list(map(int,input().split()))
joushi_dict={}
for i in range(1,n+1):
  joushi_dict[i]=0

for i in range(n-1):
  joushi_dict[a[i]]+=1

for i in range(1,n+1):
  print(joushi_dict[i])

Measured memory_bytes: 38932
#include <stdio.h>
#define N 10

int main(void) {
    int h, w;
    scanf("%d %d", &h, &w);

    char a[N][N] = {{0}};
    for (int i = 0; i < h; i++)
        scanf("%s", a[i]);

    int count = 0;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            if (a[i][j] == '#')
                count++;

    if (count == h + w - 1)
        printf("Possible\n");
    else
        printf("Impossible\n");

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	map<string,ll> mp;
	rep(i,n){
		string s;
		cin>>s;
		sort(begin(s),end(s));
		mp[s]++;
	}
	ll ans=0;
	for(auto itr:mp){
		ans+=(itr.se)*(itr.se-1)/2;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int col[N],f[2];
bool f1;
vector<vector<int>>v;
void dfs(int u,int c){
	col[u] = c;
	f[c]++;
	for(auto i : v[u]){
		if(col[i] == col[u])f1 = 1;
		if(!(col[i] + 1))dfs(i,!c);
	}
}
int main(){
	//freopen("readin.txt","r",stdin);
	int n,m;
	memset(col,-1,sizeof col);
	scanf("%d%d",&n,&m);
	v.resize(n);
	for(int i = 0;i < m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		v[--a].push_back(--b);
		v[b].push_back(a);
	}
	dfs(0,0);
	n = v.size();
	if(f1)cout << n*1LL*(n - 1)/2 - m << endl;
	else cout << f[0]*1LL*f[1]*1LL - m << endl;
}

Measured memory_bytes: 6784
#pragma GCC optimize("Ofast")
	#pragma GCC target("avx,avx2,fma")
	#pragma GCC optimization ("unroll-loops")
	
    #include<bits/stdc++.h>
    using namespace std;
	
    #define ll long long
    #define ull unsigned long long
    #define ld long double
    #define ff first
    #define ss second
    #define null NULL
    #define MAX 1000000000  // 1x10^9
    #define all(c) (c).begin(),(c).end()
    #define eb emplace_back
    #define pb push_back
    #define pf push_front
    #define lb lower_bound   //used for sortted 
    #define ub upper_bound 
    #define m_p make_pair      
    #define mod 1000000007
    #define For(i,n) for(int i=(0);i<(n);++i)
    #define FOR(i,a,b) for(int i=(a);i<=(b);++i)
	#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
    #define in(s3) inserter((s3), (s3).begin())  //	set_union(all(s1),all(s2),in(s3));
    typedef vector<ll> vl;
    typedef vector< vl > vvl;
    typedef pair< ll,ll> pll;
    typedef map< ll,ll> mll;
    
    //  A-65 Z-90 a-97 z-122   A-a = 32   Z-A = z-a = 35
    //	v.push_back(make_pair(min(2 * k[i], l[i]) - min(k[i], l[i]), i));      //int pos = v[i].second;
    //	floor(log10(no) + 1);                   //	to_string(no).length();             ----- length of a number
	//  llabs - long long of abs
	//  labs -long of abs
	//  sqrtf - sq root of float
	//  sqrtl - sq of long double    ( cout << fixed << setprecision(12) << sqrtl(val2) << endl; )
	//  it = find (all(vec), e);     if(it != vec.end());       it - vec.begin();
   	//	size_t found = str.find(str1);    if(found != string::npos); 	 cout<<found;
    	 
	/*	
		1. ^ is XOR and is used to to check odd occurance of number as a number XORed with itself results in zero so all even	occurrances result in zero.
		2.   & is used to check even or odd. (x & 1) ? printf("Odd") : printf("Even"); 
		3.   left shift(<<) - *         right shift(>>) - /
	*/
	
	string to_string(char& x) {      
		string s(1,x);
		return s;    
	} 
	struct obj {
		ull val1;
		ull val2;
		ull pos;
	};
	bool cmp(const pair<int,int>&a,const pair<int,int>&b) {
		if(a.first==b.first)
		return a.second<b.second;
		return a.first<b.first;
	}

	int main() {
		ull n,no;
		ull count=0;
		cin>>n;
		vector<ull> v;
		for(int i=0;i<n;i++)
		{
			cin>>no;
			v.pb(no);
		}
		for(int i=0;i<v.size();i++)
		{
				for(int j=i;j<v.size();j++)
				{
						for(int k=j;k<v.size();k++)
						{
							if(i==j || j==k || i==k || v[i]==0 || v[j]==0 || v[k]==0)
							{
							//cout<<v[i]<<" "<<v[j]<<" "<<v[k]<<" "<<endl;
							continue;
							}
							else
							{
								ull m=max({v[i],v[j],v[k]});
								//cout<<v[i]<<" "<<v[j]<<" "<<v[k]<<" "<<endl;
								if(m<v[i]+v[j]+v[k]-m && v[i]!=v[j] && v[j]!=v[k] && v[i]!=v[k]) 
								{
								//cout<<v[i]<<" "<<v[j]<<" "<<v[k]<<" "<<m<<endl;
								count++;
								}
							}
						}
				}
		}
		cout<<count;
		return 0;
	}






Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lli long long int
#define f(i,a,b) for(i=a;i<b;i++)
#define ff first
#define sc second
#define pb push_back
#define full(v) v.begin(),v.end()
#define ms(a) memset(a,0,sizeof(a))
#define mod 1000000007
#define mod2 998244353
#define msb(b) memset(b,true,sizeof(b))
#define msf(b) memset(b,false,sizeof(b))
#define MAXN 100005
// bool prime[1000000]; // 10**6
// lli pri[100000],x=0;
/*void sieve()
{
  msb(prime);
  prime[0]=prime[1]=false;
  for(int p=2;p*p<=1000000;p++)
  {
    if(prime[p])
    {
      for(int i=p*2;i<=1000000;i+=p)
        prime[i]=false;
      // a[x++]=p;
    }
  }
} */

int main()
{
    fio;
    int t,n,i;
    cin >> n;
    string s;
    int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
    while(n--)
    {
      cin >> s;
      if(s == "AC")
        c1++;
      if(s == "WA")
        c2++;
      if(s == "TLE")
        c3++;
      if(s == "RE")
        c4++;
    }
    cout << "AC x " << c1 << endl;
    cout << "WA x " << c2 << endl;
    cout << "TLE x " << c3 << endl;
    cout << "RE x " << c4 << endl; 
}


Measured memory_bytes: 3592
'use strict'

const main = (input) => {
    input = input.split('\n')[0].split(' ').map(i => parseInt(i))
    const a = input[0]
    const b = input[1]
    console.log((b - a)*(b - a + 1) / 2 - b)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 21064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ans;
        int s1 = Integer.parseInt(s.substring(0, 2));
        int s2 = Integer.parseInt(s.substring(2, 4));
        if (1 <= s1 && s1 <= 12) {
            ans = "MMYY";
            if (1 <= s2 && s2 <= 12) {
                ans = "AMBIGUOUS";
            }
        } else if (1 <= s2 && s2 <= 12) {
            ans = "YYMM";
        } else {
            ans = "NA";
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
n = int(input())
cond = []
for i in range(n):
  a,b = map(int, input().split())
  cond.append([b,a])
  
cond.sort()
b = [cond[i][0] for i in range(n)]
a = [cond[i][1] for i in range(n)]

current = 0

flag = True
for i in range(n):
  if (current + a[i]) > b[i]:
    flag = False
    break
  else:
    current += a[i]
  

if flag:
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 38696
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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(void){
    char s[3]; REP(i,3) cin >> s[i];
    cout << s[0]-'0'+s[1]-'0'+s[2]-'0' << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
    	int i, j;
    	
    	String moji = sc.nextLine();
    	
    	for(char c : moji.toCharArray()) {
    		if('A' <= c && 'Z' >= c) {
    			System.out.print(Character.toLowerCase(c));
    		}
    		else if('a' <= c && 'z' >= c) {
    			System.out.print(Character.toUpperCase(c));
    		}
    		else {
    			System.out.print(c);
    		}
    	}
    	System.out.println();
    }
}


Measured memory_bytes: 26592
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

int main(){

	string s = "CODEFESTIVAL2016";
	string t;
	cin >> t;
	int cnt = 0;
	for (int i = 0; i < 16; i++) {
		if (s[i] != t[i]) {
			cnt++;
		}
	}

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

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int n;
    cin >> n;
    int a[n];
    pair<int, int> s[n+1];
    REP(i, n){
        cin >> a[i];
        a[i] -= 1;
    }
    REP(i, n) cin >> s[i].first;
    REP(i, n-1) cin >> s[i].second;

    int sa=0, pre = a[0];
    REP(i, n){
        if(pre + 1 == a[i]) sa += s[a[i]].first + s[a[i]-1].second;
        else sa += s[a[i]].first;
        pre = a[i];

    }
    cout << sa << endl;
}


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

const double pi=acos(-1);
typedef long long ll;
const int maxn=1e4+10;
int  f[300050],vis[200050];
double F[200050];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    double s=0,ma;
    for(int i=0;i<n;i++){
        cin >> f[i];
        F[i]=(1+f[i])/2.0;
    }
  //  for(int i=0;i<n;i++){
  //      cout << F[i] << " ";
      //  F[i]=(1+f[i])/2;
  //  }
    for(int i=0;i<k;i++)
        s+=F[i];
  //      cout <<endl<< s << endl;
    ma=s;
    for(int i=0,j=k;j<n;i++,j++){

        s=s+(F[j]-F[i]+0.0);
       // cout << s <<" " << F[i] << " " <<F[j] <<endl;
        if(ma<s)
            ma=s;
    }
    cout<<fixed<<setprecision(12)<<ma<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<20;



int main(){
    int L;cin >> L;
    vector<LL> a(L);
    for (int i = 0; i < L; i++) {
        cin >> a[i];
    }
    vector<vector<LL>> dp(L+1,vector<LL> (5,LINF));
    dp[0][0]=0;
    for (int i = 0; i < L; i++) {
        for (int j = 0; j < 5; j++) {
            for (int k = j; k < 5; k++) {
                LL cost;
                if(k==0||k==4){
                    cost=a[i];
                }
                else if(k==1||k==3){
                    if(a[i]==0) cost=2;
                    else cost=a[i]%2;
                }
                else if(k==2){
                    cost=(a[i]+1)%2;
                }
                dp[i+1][k]=min(dp[i+1][k],dp[i][j]+cost);
            }
        }
    }
    LL ans=LINF;
    for (int i = 0; i < 5; i++) {
        ans=min(ans,dp[L][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15872
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int X = scn.nextInt();
		int T = scn.nextInt();

		int cnt = 0;


		while (N > 0) {
			cnt ++;
			N = N - X;
		}

		System.out.println(cnt * T);

	}

}


Measured memory_bytes: 35808
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    ll x, y; cin>>x>>y;
    if(abs(x-y)<=1) cout << "Brown" << endl;
    else cout << "Alice" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define N 5010
#define mo 1000000007
using namespace std;
int n,m,k,l,f[N][N],ans=0,sum[N];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	k--;
	m--;
	l=(n+m)/k;
	f[0][0]=1;
	sum[0]=0;
	fo(i,1,l)
	{
		fo(j,0,n) sum[j+1]=(f[i-1][j]+sum[j])%mo;
		fo(j,0,n)
		{
			if(j>0) f[i][j]=(sum[j]-sum[max(j-k,0)]+mo)%mo;
			if((j>0)&&(j<=n)&&(i*k-j<=m)&&(j%k==n%k)&&((i*k-j)%k)==m%k) (ans+=f[i][j])%=mo;
			f[i][j]=(f[i][j]+f[i-1][j])%mo;
		}
		sum[0]=0;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 75776
#include <stdio.h>

int main(void)
{
	int n = 0, i, num = 0;

	scanf("%d", &n);
	
	int a_array[n];

	for (i = 0; i < n; i++)
	{
		scanf("%d", &num);
		a_array[i] = num;
	}
	for (i = n - 1; i >= 0; i--)
	{
		if (i == 0)
		{
			printf("%d\n", a_array[i]);
		}
		else
		{
			printf("%d ", a_array[i]);
		}
	}

	return 0;
}

Measured memory_bytes: 596
fn main() {
	let mut s = [[[0; 10]; 3]; 4];

	let n = readLine::<usize>();
	for _ in 0..n {
		let xs = read_vec::<i32>();
		let(b, f, r, v) = (xs[0] as usize, xs[1] as usize, xs[2] as usize, xs[3]);
		s[b - 1][f - 1 ][r - 1] += v;
	}
	for i in 0..4 {
		for j in 0..3 {
			for x in &s[i][j] {
				print!(" {}", x);
			}
			println!("");
		}
		if i < 3 {
			println!("####################");
		}
	}
}

fn readLine<T: std::str::FromStr>() -> T {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 5020
def f(L):
    N=len(L)
    c=0
    T=[]
    for i in range(len(L)-1):
        if L[i]>=L[i+1]:
            c+=1
            T.append(c)
        else:
            c=0
    if len(T)==0:
        return 0
    else:
        return max(T)
N=int(input())
L=list(map(int,input().split()))
print(f(L))

Measured memory_bytes: 14252
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int K;
string S;
int A[100010];
int num[100010];

int sa(int s,int t){
	return num[t+1]-num[s];
}

bool check(int m){
	int mi=INF;
	REP(i,N-m+1){
		int R=sa(i,i+m-1);
		if(S[i]=='0'){
			R++;
		}
		DEB(m)DEB(i+m-1)DEB(R)END
		mi=min(mi,R);
	}
	if(mi<=K){
		return true;
	}
	return false;
}


signed main(){
	cin>>N>>K>>S;
	if(S[0]=='0'){
		num[0]=1;
		num[1]=1;
	}
	for(int i=1;i<N;i++){
		if(S[i-1]=='1'&&S[i]=='0'){
			num[i+1]=num[i]+1;
		}
		else{
			num[i+1]=num[i];
		}
	}
	int ok=1,ng=N+1;
	while(abs(ok-ng)>1){
		int mid=(ok+ng)/2;
		if(check(mid)){
			ok=mid;
		}
		else{
			ng=mid;
		}
	}
	cout<<ok<<endl;
	return 0;
}


Measured memory_bytes: 1280
INF = 1000000007

class Edge:
    def __init__(self, to, cap, rev):
        self.to = to
        self.cap = cap
        self.rev = rev

class FF:
    def __init__(self, n):
        self.n = n
        self.adj = []
        for i in range(n):
            self.adj.append([])
        self.used = [False] * n

    def add_edge(self, _from, _to, _cap):
        self.adj[_from].append(Edge(_to, _cap, len(self.adj[_to])))
        self.adj[_to].append(Edge(_from, 0, len(self.adj[_from]) - 1))

    def dfs(self, v, t, f):
        if v == t:
            return f
        self.used[v] = True
        for e in self.adj[v]:
            if self.used[e.to] == False and e.cap > 0:
                d = self.dfs(e.to, t, min(f, e.cap))
                if d > 0:
                 e.cap -= d
                 self.adj[e.to][e.rev].cap += d
                 return d
        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            del self.used
            self.used = [False] * self.n
            f = self.dfs(s, t, INF)
            if f == 0:
                return flow
            flow += f


def main():
    n = int(input())
    reds = [tuple(int(s) for s in input().split()) for _ in range(n)]
    blues = [tuple(int(s) for s in input().split()) for _ in range(n)]
    ff = FF(2 * n + 2)
    for i in range(n):
        ff.add_edge(2 * n, i, 1)
        ff.add_edge(i + n, 2 * n + 1, 1)
    for i, (rx, ry) in enumerate(reds):
        for j, (bx, by) in enumerate(blues):
            if rx < bx and ry < by:
                ff.add_edge(i, j + n, 1)
    print(ff.max_flow(2 * n, 2 * n + 1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 4084
//This template belongs to Juan Carlo Vieri

/*   ____   __               
    /  _/  |  |    __         __        
 __|  |__  |  |   /_/        |  |                 
|__    __| |  |   __    ____ |  | __   ___   _  ___
   |  |    |  |  |  |  /  _/ |  |/ /  / _ \ | |/ _/   
   |  |    |  |  |  | |  |_  |     \ |  __/ |   / 
   |__|    |__|  |__|  \___\ |__|\__\ \___\ |__|
*/

#include <bits/stdc++.h>
using namespace std;

typedef int_fast64_t ll;
typedef long double ld;
typedef int_fast32_t intt;
typedef int_fast32_t tmp_m;
#define deb(x) cout << #x << ' ' << x << endl
#define rep(i, cmp1, cmp2) for (tmp_m i = cmp1; i < cmp2; ++i)
#define repp(i, cmp1, cmp2) for (tmp_m i = cmp1; i >= cmp2; --i)
#define pb push_back
#define st stack
#define pa pair
#define vc vector
#define qu queue
#define pq priority_queue
#define fr first
#define sc second
#define mp map
const ld pi = acos(-1.0);
const intt mod = 1e9 + 7;

struct pr {
  intt x;
  intt y;
  intt dst;
  pr() {}
  pr(intt x, intt y, intt dst) : x(x), y(y), dst(dst) {}
  inline bool operator<(const pr& cmp2) const {
    if (dst != cmp2.dst) return dst < cmp2.dst;
    if (x != cmp2.x) return x < cmp2.x;
    return y < cmp2.y;
  }
  inline bool operator==(const pr& cmp2) const {
    return (cmp2.dst == dst) && (cmp2.x == x) && (cmp2.y == y);
  }
  inline bool operator>(const pr& cmp2) const {
    if (dst != cmp2.dst) return dst > cmp2.dst;
    if (x != cmp2.x) return x > cmp2.x;
    return y > cmp2.y;
  }
};

struct point {
  intt x;
  intt y;
  point() {}
  point(intt x, intt y) : x(x), y(y) {}
  inline bool operator<(const point& cmp2) const {
    if (cmp2.x != x) return cmp2.x < x;
    return cmp2.y < y;
  }
  inline bool operator==(const point& cmp2) const {
    return (cmp2.x == x) && (cmp2.y == y);
  }
  inline bool operator>(const point& cmp2) const {
    if (cmp2.x != x) return cmp2.x > x;
    return cmp2.y > y;
  }
};

class prHash {
 public:
  size_t operator()(const pr& cmp1) const {
    return (hash<intt>()(cmp1.x)) ^ (hash<intt>()(cmp1.y)) ^
           (hash<intt>()(cmp1.dst));
  }
};

class pointHash {
 public:
  size_t operator()(const point& cmp1) const {
    return (hash<intt>()(cmp1.x)) ^ (hash<intt>()(cmp1.y));
  }
};

inline bool spoint(const point& cmp1, const point& cmp2) {
  // swap(cmp1, cmp2);
  if (cmp1.x != cmp2.x) return cmp1.x < cmp2.x;
  return cmp1.y < cmp2.y;
}

inline bool spr(const pr& cmp1, const pr& cmp2) {
  // swap(cmp1, cmp2);
  if (cmp1.dst != cmp2.dst) return cmp1.dst < cmp2.dst;
  if (cmp1.x != cmp2.x) return cmp1.x < cmp2.x;
  return cmp1.y < cmp2.y;
}

void solve() {
  intt n;
  cin >> n;
  string s;
  cin >> s;
  rep(i, 0, min(n, (intt)s.length())){
    cout << s[i];
  }
  if(n < (intt)s.length()){
    cout << "...";
  }
  cout << endl;
}

void init() {
  // remove if interactive
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  // memset(dp, -1, sizeof dp);
}

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


Measured memory_bytes: 3616
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ll dp[410][410];
ll flag[410][410];
ll sum[410];
ll f(ll l,ll r){
  if(flag[l][r])return dp[l][r];
  flag[l][r]=1;
  if(l==r)return 0;
  ll fans=INF;
  for(ll i=l;i<r;i++)fans=min(fans,f(l,i)+f(i+1,r));
  if(l==1)fans+=sum[r-1];
  else fans+=sum[r-1]-sum[l-2];
  return dp[l][r]=fans;
}
  
int main(){
  ll n;cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  sum[0]=a[0];
  for(ll i=1;i<n;i++)sum[i]=sum[i-1]+a[i];
  cout<<f(1,n)<<endl;
} 

Measured memory_bytes: 2816
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<cmath>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<stack>
#include<sstream>
#include<string>
#include<cassert>
#include<ctime>
#include<math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

int main() {
	int N,P;
	scanf("%d%d", &N,&P);
	ll *odd = (ll *)malloc(sizeof(ll)*(N + 1));
	ll *even = (ll*)malloc(sizeof(ll)*(N + 1));
	int *a = (int *)malloc(sizeof(int)*(N + 1));
	for (int i = 1;i <= N;i++)scanf("%d", a + i);
	odd[0] = 0;
	even[0] = 1;
	for (int i = 1;i <= N;i++) {
		if (a[i] % 2 == 0) {
			odd[i] = odd[i - 1] << 1;
			even[i] = even[i - 1] << 1;
		}
		else {
			odd[i] = odd[i - 1] + even[i - 1];
			even[i] = odd[i - 1] + even[i - 1];
		}
	}
	if (P == 0) printf("%lld", even[N]);
	else printf("%lld", odd[N]);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000000000001
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
void YN(int a){if(a==1)printf("Yes\n");if(a==0)printf("No\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

LL st,seg[26][1048576]={0};
void sadd(LL j,LL i,LL n){
  i+=st-1;
  seg[j][i]+=n;
  while(i>0){
    i=(i-1)/2;
    seg[j][i]+=n;
  }
}
LL ssum(LL j,LL a,LL b,LL k,LL l,LL r){
  if(r<=a||b<=l)return 0;
  if(a<=l&&r<=b)return seg[j][k];
  return ssum(j,a,b,2*k+1,l,(l+r)/2)+ssum(j,a,b,2*k+2,(l+r)/2,r);
}

int main(){
  LL N,Q,j,k,n,i,l,r,ans,p,q;
  scanf("%lld",&N);
  char S[N+1],c;
  scanf("%s %lld",S,&Q);
  st=pwmn(N,2);
  rep(j,N)sadd(S[j]-'a',j,1);
  rep(j,Q){
    scanf("%lld",&n);
    if(n==1){
      scanf("%lld %c",&i,&c);
      sadd(S[i-1]-'a',i-1,-1);
      S[i-1]=c;
      sadd(c-'a',i-1,1);
    }else{
      scanf("%lld %lld",&l,&r);
      ans=0;
      rep(k,26)if(ssum(k,l-1,r,0,0,st)>0)ans++;
      printf("%lld\n",ans);
    }
  }

  //printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 215680
let a, b, c, d = Scanf.scanf " %d %d %d %d" @@ fun a b c d -> a, b, c, d
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let rec lcm a b = a / gcd a b * b
let f x = x / c + x / d - x / lcm c d
let _ = b - a + 1 - (f b - f (a - 1)) |> Printf.printf "%d\n"

Measured memory_bytes: 384
A, B, C, X, Y = map(int, input().split())
naive = A * X + B * Y

if X < Y:
    recon = 2 * C * X + B * (Y - X)
else:
    recon = 2 * C * Y + A * (X - Y)

over = 2 * C * max(X, Y)

print(min(naive, recon, over))

Measured memory_bytes: 3060
import java.util.*;

class Main{
	public static void main(String args[]){
		Solve s = new Solve();
		s.solve();
	}
}

class Solve{
	Scanner in = new Scanner(System.in);

	void solve(){
		while(in.hasNext()){
			int n = in.nextInt(), m = in.nextInt();
			if(n == 0 && m == 0) return;
			int[] a = new int[n + m + 1];
			for(int i = 0; i < n + m; i++) a[i] = in.nextInt();
			a[n + m] = 0;
			Arrays.sort(a);
			int ans = a[1] - a[0];
			for(int i = 1; i < n + m + 1; i++) ans = Math.max(ans, a[i] - a[i - 1]);
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 66768
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath> 

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

typedef long long ll;

int N, K;
int ans = 1000000000;
vector<int> x;

// 5 3
// -30 -10 0 10 20 50
// <----K----->   

int main(void) {
  /*入力処理0を含む場合はK--*/
    scanf("%d %d", &N, &K);
    
    bool flag = false;
    int idx;
    
    REP(i, 0, N) {
      int t;
    	scanf("%d", &t);
    	if (t == 0) {
    	  flag = true;
    	  idx = i;
    	  K--;
    	}
    	x.push_back(t);
    }
    
    if(!flag) {
      vector<int>::iterator it = lower_bound(x.begin(), x.end(), 0);
      idx = it - x.begin();
      x.insert(it, 0);
    }

    for (int i = max(0, idx - K); i <= idx && i + K < x.size(); i++) {
    
    	int l1 = abs(0 - x[i]);
    	int l2 = abs(x[i+K] - 0);

    	ans = min(ans, min(l1, l2) * 2 + max(l1, l2));
    }

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

	return 0;
}










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

int N;
vector<char> S;
vector<int> tmp;

int count(int ii) {
	int ret = 0;

	for (int i = 0; i < ii; ++i) {
		if (S[i] == 'W') {
			++ret;
		}
	}

	for (int i = ii + 1; i < N; ++i) {
		if (S[i] == 'E') {
			++ret;
		}
	}

	return ret;
}

int calc() {
	tmp.resize(N);
	fill(tmp.begin(), tmp.end(), 0);

	for (int i = 1; i < N; ++i) {
		if (S[i] == 'E') {
			++tmp[0];
		}
	}

	for (int i = 1; i < N; ++i) {
		tmp[i] = tmp[i - 1];

		if (S[i - 1] == 'W') {
			++tmp[i];
		}

		if (S[i] == 'E') {
			--tmp[i];
		}
	}

	int ret = tmp[0];
	for (int i = 1; i < N; ++i) {
		ret = min(ret, tmp[i]);
	}

	return ret;
}

int main() {
	cin >> N;

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

	/*
	int ans = (1 << 30);
	for (int i = 0; i < N; ++i) {
		ans = min(ans, count(i));
	}

	cout << ans << endl;
	*/
	cout << calc() << endl;
}

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

int main(){
  int N,K,R,S,P;
  cin >> N >> K >> R >> S >> P;
  vector<pair<char,bool> >T(N+K);

  for(int i=0;i<N;i++){
    cin >> T.at(i).first;
    T.at(i).second=true;
  }
  for(int i=N;i<N+K;i++){
    T.at(i).first='a';
  }
  long long sum=0;
  for(int i=0;i<N;i++){
    if(T.at(i).second == true){
      if(T.at(i).first=='r'){
        sum += P;
      }
      if(T.at(i).first=='s'){
        sum += R;
      }
      if(T.at(i).first=='p'){
        sum += S;
      }
      if(T.at(i).first==T.at(i+K).first){
        T.at(i+K).second=false;
      }
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int ctoi(char c) {
	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

int main(void){
    int h,w,k,count=1,score=0;
    long long tmp=0,prev=0,ans=0;
    scanf("%d%d%d",&h,&w,&k);
    char c[h][w+1],m[h][w+1];
    for (int i=0; i<h; i++){
        scanf("%s",m[i]);
    }
    for (int i=1; i<h; i++){
        for (int j=0; j<w; j++){
            
            for (int l=0; l<h; l++){
                strcpy(c[l],m[l]);
            }
            
            c[i][j]='0';    
            tmp=0;
            for (int l=1; l<h; l++){
                for (int m=0; m<w; m++){
                    if (c[l][m]=='0'){
                        for (int n=l; n>0; n--){
                            c[n][m]=c[n-1][m];
                        }
                        c[0][m]='0';
                    }
                }
            }
            
            score=0;
            do {
                prev=tmp;
                
                for (int l=0; l<h; l++){
                    for (int m=1; m<w; m++){
                        
                        if (c[l][m-1]==c[l][m]){
                            count++;
                        } else {
                            if (count>=k){

                                tmp+=pow(2,score)*count*(ctoi(c[l][m-1]));
                                
                                for (int n=0; n<count; n++){
                                    c[l][m-n-1]='0';
                                }
                                
                            }
                            count=1;
                        }
                        if (m==w-1){
                            if (count>=k){
                                tmp+=pow(2,score)*count*(ctoi(c[l][m-1]));
                                for (int n=0; n<count; n++){
                                    c[l][m-n]='0';
                                }
                            }
                            count=1;
                        }
                    }
                }
                
                for (int l=1; l<h; l++){
                    for (int m=0; m<w; m++){
                        if (c[l][m]=='0'){
                            for (int n=l; n>0; n--){
                                c[n][m]=c[n-1][m];
                            }
                            c[0][m]='0';
                        }
                    }
                }
                score++;
                
            } while (prev!=tmp);
            
            if (ans<tmp){
                ans=tmp;
            }
        }
    }
    printf("%lld\n",ans);
	return 0 ;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    map <string,long long> map1;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        map1[s]++;
    }
    map <string,long long> ::iterator itr;
    long long count1=0;
    for(itr=map1.begin();itr!=map1.end();itr++)
    {
        count1+=(itr->second*(itr->second-1))/2;
    }
    cout<<count1;
    return 0;
}


Measured memory_bytes: 11136
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a = 0, b = 0;
		List<Integer> list = new ArrayList<Integer>();
		for(int i = 0; i < n; i++){
			list.add(scan.nextInt());
		}
		if(n%2==1)list.add(0);
		
		Collections.sort(list, Collections.reverseOrder());
		for(int i = 0; i < list.size(); i += 2){
			a += list.get(i);
			b += list.get(i+1);
		}
		
		System.out.println(a - b);
	}
}

Measured memory_bytes: 22228
use std::io;
fn main() {
    let mut string = String::new();
    io::stdin().read_line(&mut string).unwrap();

    let mut iter = string.split_whitespace();

    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    let mut cond = String::new();

    if a > b {
        cond = ">".to_string();
    } else if a < b {
        cond = "<".to_string();
    } else {
        cond = "==".to_string();
    }
    println!("a {} b", cond);
}



Measured memory_bytes: 1052