akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  ll a,v,b,w,t;
  cin>>a>>v>>b>>w>>t;
  ll k = gcd(v,w);
  string ans="";
  if(v==w){
    if(a==b){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
    return 0;
  }
  if(a<b){
    if((v-w>0) && ((double)(b-a)/(v-w)<=t)){
      ans="YES";
    }else{
      ans="NO";
    }
  }else{
    if((v-w>0) && ((double)(a-b)/(v-w)<=t)){
      ans="YES";
    }else{
      ans="NO";
    }
  }
  cout<<ans<<endl;

  return 0;
}


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


int main ()
{

int a;
cin >> a;

if(a<1200)
{
	cout << "ABC" << endl;
}
else if(a<2800)
{
	cout << "ARC" << endl;
}
else
{
	cout << "AGC" << endl;
}

 	return 0;
}












Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int mxN =150000;
int32_t main(){
  ios_base::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);

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




 return 0;}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    int n;
    cin >> n;
    vector<char>s(n);
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    vector<int>e(n,0);
    vector<int>w(n,0);
    if(s[0]=='W') w[0]++;
    else e[0]++;

    for(int i=1;i<n;i++){
        if(s[i]=='W'){
            w[i] = w[i-1] + 1;
            e[i] = e[i-1];
        }
        else {
            w[i] = w[i-1];
            e[i] = e[i-1] + 1;
        }
    }
    vector<int>ans(n,0);
    for(int i=0;i<n;i++){
        if(i==0) ans[i] == e[n-i] - e[i];
        ans[i]=w[i-1]+(e[n-1]-e[i]);
    }
    sort(ans.begin(),ans.end());
    cout << ans[0] << endl;
}

Measured memory_bytes: 6868
from sys import stdin
from sys import setrecursionlimit
import math
from collections import Counter
setrecursionlimit(10 ** 7)

n = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

li = Counter(prime_factorize(n))
count = li.items()

now = 0
lis = []
for i in range(1000):
    lis.append(now+i)
    now += i

lis = lis[1:]

import bisect
point = 0
for i in count:
    a,b = i
    point += bisect.bisect_right(lis,b)

print(point)

Measured memory_bytes: 68148
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <deque>
#include <map>
#include <iomanip>
#include <limits>
#include <map>

using namespace std;

const int CMax = 100002;
const int CVMax = 40;
const int CInf = 2000000001;
const long long CMod = 1000000007;

int n, A[CMax];
long long res = 0;

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


struct TrieNode
{
    struct TrieNode *children[CVMax];
    int ended;
};

struct TrieNode *getNode()
{
    struct TrieNode *pNode = new TrieNode;
    pNode->ended = 0;

    for (int i = 0; i < CVMax; i++) {
        pNode->children[i] = NULL;
    }

    return pNode;
};

void insertWord(struct TrieNode *root, string word) {
    struct TrieNode *pNode = root;
    int tmp;

    for (int i = 0; i < word.length(); i++) {
        tmp = word[i] - 'a';
        if (!pNode->children[tmp]) {
            pNode->children[tmp] = getNode();
        }
        pNode = pNode->children[tmp];
    }

    res += (long long)pNode->ended;

    pNode->ended++;
}

int main()
{
    string S;
    scanf("%d", &n);

    struct TrieNode *root = getNode();

    for (int i = 0; i < n; i++) {
        cin >> S;
        sort(S.begin(), S.end());
        insertWord(root, S);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 157568
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define llu unsigned long long int
#define all(v) v.begin(),v.end()
#define sd size()
#define pi pair<ll,ll>
#define lb(a,b) lower_bound(all(a),b) - a.begin()
#define ub(a,b) upper_bound(all(a),b) - a.begin()
#define sp( a, b)   cout<<setprecision(b)<<a<<" ";
#define mod 1000000007
#define d2 vector<vector<ll>>
#define d1 vector<ll>
#define d1pi vector<pi>
#define d1b vector<bool>
#define p(x) cout<<x;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
const ll N = 2e5+100;
d1 g[N];
vector<bool> vis(N,0);
void un_add_edge(ll a,ll b)
{
        g[a].pb(b);
        g[b].pb(a);
}
void add_edge(ll a,ll b)
{
        g[a].pb(b);
      
}
ll lcm(ll a,ll b)
{
        return (a*b)/__gcd(a,b);
}
int main()
{
        fast;
        ll n;
        cin>>n;
        ll a[n][3],dp[n][3]={0};
        for(ll i=0;i<n;i++)
        {       
                cin>>a[i][0]>>a[i][1]>>a[i][2];
                if(i==0);
                dp[0][0]=a[0][0],dp[0][1]=a[0][1],dp[0][2]=a[0][2];
        }
        
        for(ll i=1;i<n;i++)
        {
                for(ll j=0;j<3;j++)
                {
                        if(j==0)
                        {
                                dp[i][j]=max(dp[i-1][j+1],dp[i-1][j+2])+a[i][j];
                        }
                        else if(j==1)
                        {
                                dp[i][j] = max(dp[i-1][j-1],dp[i-1][j+1])+a[i][j];
                        }
                        else 
                        {
                                dp[i][j] = max(dp[i-1][j-1],dp[i-1][j-2])+a[i][j];
                        }
                }
        }
        cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}



Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int N,M;

	cin >> N >> M;

	vector < pair<int, int> > ab;

	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		ab.push_back(make_pair(a ,b));
	}

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


	int count = 0;
	int min_b = 1000000;

	bool isFirst = true;


	for (auto cur : ab) {
		int a = cur.first;
		int b = cur.second;

		//cout << "a:" << a << "b:" << b << endl;

		//cout << "min_b:" << min_b << endl;

		if (a >= min_b && !isFirst) {
			count ++;
			min_b = b;
			//cout << "hit!" << endl;
			continue; 
		}
		isFirst = false;
		min_b = min(b, min_b);
	}
	count ++;
	cout << count << endl;



	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin>>N;
  int ans = 0;
  for(int i=1;i<=N;i++){
    ans += to_string(i).size() % 2 == 1;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n;
signed main(){
	cin>>n;
	cout<<n*(n-1)/2<<endl;
	return 0;
}

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();

        String s;
        boolean isAns = false;
        for (int i = 0; i< n; i++) {
            s = sc.next();
            if (s.equals("Y")) {
                isAns = true;
                break;
            }
        }

        System.out.println(isAns ? "Four" : "Three");
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	int a,b;cin>>a>>b;
	if(b<a)cout<<a-1<<endl;
	else cout<<a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll N;
	cin >> N;
	int res = 0;
	for (ll i = 2; i*i <= N; ++ i) {
		int c = 0;
		while (N % i == 0) {
			N /= i;
			++ c;
		}
		for (int i = 1, j = 1; j <= c; j += ++ i) {
			++ res;
		}
	}
	if (N > 1) {
		++ res;
	}
	cout << res << endl;
}


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

int main() {
	int n,count=0,co;
	char a[101], b[101], c[101];
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++) {
		co = 0;
		if (a[i] != b[i])co++;
		if (a[i] != c[i])co++;
		if (b[i] != c[i])co++;
		if(co != 0)count += co - 1;
	}
	cout << count << endl;
	return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

ll dp1[1000005],dp2[1000005];
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    vector<int> v;
    vector<pair<int,int> > ans;
    int INF=1000004;
    for(int i=1;;i++){
    	n=i*(i+1)*(i+2)/6;
    	if(n>=INF)break;
    	v.pb(n);
    }
    n=1000004;
    for(int i=1;i<=n;i++){
    	dp1[i]=dp2[i]=mod;
    }
    dp1[0]=dp2[0]=0;
    for(auto& i:v){
    	for(int j=i;j<=n;j++){
    		dp1[j]=min(dp1[j-i]+1,dp1[j]);
    	}
    	if(i%2){
    		for(int j=i;j<=n;j++){
    			dp2[j]=min(dp2[j-i]+1,dp2[j]);
    		}
        }
    }
    while(1){
    	cin>>n;
    	if(n==0)break;
    	ans.pb(make_pair(dp1[n],dp2[n]));
    }
    for(auto& i:ans){
    	cout << i.first<<" "<<i.second<<endl;
    }
    return 0;
}



Measured memory_bytes: 18720
using System;
using System.Linq;

namespace abc073_d
{
	class Program
	{
		static int[,] d;
		static int[] r;
		static bool[] flag;
		const int inf = 100000000;
		static int bfs(int x)
		{
			flag[x] = true;
			int min = inf;
			bool found = false;
			for (int i = 0; i < flag.Count(); i++)
			{
				if (!flag[i])
				{
					found = true;
					min = Math.Min(min, d[r[x], r[i]] + bfs(i));
				}
			}
			flag[x] = false;
			return found ? min : 0;
		}
		static void Main(string[] args)
		{
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			r = Console.ReadLine().Split().Select(int.Parse).ToArray();
			for (int i = 0; i < x[2]; i++) r[i]--;
			flag = new bool[x[2]];
			d = new int[x[0], x[0]];
			for (int i = 0; i < x[0]; i++)
			{
				for (int j = 0; j < x[0]; j++)
				{
					d[i, j] = inf;
				}
			}
			for (int i = 0; i < x[1]; i++)
			{
				int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
				a[0]--; a[1]--;
				d[a[0], a[1]] = a[2]; d[a[1], a[0]] = a[2];
			}
			for (int k = 0; k < x[0]; k++)
			{
				for (int i = 0; i < x[0]; i++)
				{
					for (int j = 0; j < x[0]; j++)
					{
						d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]);
					}
				}
			}
			long ret = long.MaxValue;
			for (int i = 0; i < x[2]; i++)
			{
				ret = Math.Min(ret, bfs(i));
			}
			Console.WriteLine(ret);
		}
	}
}

Measured memory_bytes: 17612
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define ll int64_t
const long MOD = 1e9 + 7;


// 自作のソート関数
// 5で割った余りの大小で比較
bool less_second(const pair<int,long>& lhs, const pair<int,long>& rhs) {
    return lhs.second > rhs.second;
}


int main()
{
  long n;
  cin  >> n;
  vector<long> r(n);
  vector<long> v(n);
  for (int i = 0; i < n; ++i)
  {
     cin >>v[i]; 
     r[i] = v[i];
  }
  sort(v.begin(), v.end(),greater<long>());


  int med = (v.size()+1)/2 - 1;

  for (int i = 0; i < n; ++i){
    if (v[med] <= r[i] ){
      cout << v[med+1] <<endl;
    }else{
      cout << v[med] <<endl;
    }
    
  }
   

  return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9+7;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; ++i) cin >> A[i];
    ll sum[N]; memset(sum, 0, sizeof(sum));
    for(int i = 0; i < N; ++i){
        sum[i] += A[i];
        if(i != 0) sum[i] += sum[i-1];
    }
    ll ans = 0;
    for(int i = 0; i < N-1; ++i){
        ll tmp = sum[N-1] - sum[i];
        tmp %= INF;
        ans += tmp*A[i];
        ans %= INF;
    }
    cout << ans << endl;
    return 0;
}

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

const double EPS = 1e-10;

int main()
{
  int C1, C2, C3;
  while (cin >> C1 >> C2 >> C3) {
    int cnt = 0;
    for (int i = 1; i <= 10; ++i) {
      if (i == C1 || i == C2 || i == C3)
	continue;
      if (C1+C2+i <= 20)
	++cnt;
    }

    if (cnt / 7.0 >= 0.5+EPS)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl 	"\n"

typedef vector< ll > 	vi;
typedef vector< vi > 	vvi;
typedef pair< ll,ll > 	ii;
#define pb 		push_back
#define all(c) 		(c).begin(),(c).end()
#define tr(c,i) 	for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) 	((c).find(x) != (c).end())

#define MOD 	1000000007
#define INF 	(int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))

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

	ll a,b;
	cin>>a>>b;
	ll k= a - (2*b);
	if(k>0)
		cout<<k;
	else cout<<"0";
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void dfs(int v, int p, int c);

	int n;
	using edge = pair<int,int> ;
	vector<vector<edge>> g;
	vector<int> ans;

int main(){
	// sengen
	// nyuryoku
	cin >> n;
	g.assign(n,vector<edge>());
	int u[n-1],v[n-1];
	int w[n-1];
	for(int i=0;i<n-1;i++){
		cin >> u[i] >> v[i] >> w[i];
		u[i]--; v[i]--;
		if(w[i]%2 == 0){
			w[i] = 0;
		}else{
			w[i] = 1;
		}
		g[u[i]].push_back(edge(v[i],w[i]));
		g[v[i]].push_back(edge(u[i],w[i]));
	}
	// keisan
	ans.assign(n,0);
	dfs(0,-1,0);
	for(auto a : ans) cout << a << endl;
	// syutsuryoku
}

void dfs(int v, int p, int c){
	ans[v] = c;
	for(auto nv : g[v]){
		if(nv.first == p){
			continue;
		}
		if(nv.second == 1){
			dfs(nv.first,v,1-c);
		}else{
			dfs(nv.first,v,c);
		}
	}
}

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

int main(){
  ll n,k,q;
  cin >> n >> k >> q;
  vector<ll> a(q);
  rep(i,q){
  	cin >> a[i];
  	--a[i];
  }
  map<int,ll> correct;
  rep(i,q) ++correct[a[i]];
  rep(i,n){
  	ll point = k - q + correct[i];
  	if(point > 0) cout << "Yes" << endl;
  	else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 7680
N = int(input())
S = list(map(int,list(input())))
S_riv=S[::-1]
l_lis=[0]*N
r_lis=[0]*N
mat=([0 for j in range(10)])
l_set=set([])
r_set=set([])
for i,s in enumerate(S):
  l_lis[i]=l_set.copy()
  l_set.add(s)
  
for i,s in enumerate(S_riv):
  r_lis[i]=r_set.copy()
  r_set.add(s)
  
r_lis.reverse()
ans=0
for i,s in enumerate(S):
  length=len(l_lis[i])
  ans+=(length-mat[s])*len(r_lis[i])
  mat[s]=length
  
print(ans)

Measured memory_bytes: 48136
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main() {
    ll n; cin >> n;
    set<ll> a;
    rep(i,n){
        ll b; cin >> b;
        a.insert(b);
    }
    ll k = a.size();
    if(k % 2 == 1)print(k);
    else print(k - 1);
}


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

string dir = "TLURD";
char cons[] = {'w','*','k','s','t','n','h','m','y','r'};
char vowel[] = {'a','i','u','e','o'};

int main() {
	string S;
	cin >> S;
	
	int n = S.size();
	for (int i=0; i<n; i+=2) {
		int k = S[i] - '0', d = dir.find(S[i+1]);
		if (k == 0 && d == 2) cout << "nn";
		else if (k == 1) cout << vowel[d];
		else cout << cons[k] << vowel[d];
	}
	cout << endl;
}


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<unordered_map>
#include<climits>
#include<algorithm>
using namespace std;
typedef long long ll;
#define ip(arr, n) for(int i=0; i<n; i++) cin>>arr[i];
#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define MOD 1000000007
#define MAX 200005

vector<ll>dest(MAX); // what will be my dest when I have done teleporting ith time.
unordered_map<ll, ll>m; // at which teleporting no this dest will come.


int main(){

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

    fstIO;
    
    int n;
    cin>>n;

    ll k;
    cin>>k;

    int arr[n];

    for(int i=0; i<n; i++){
        cin>>arr[i];
        arr[i]--;
    }

    int x=1;
    m[0]=0; // at which place when we done 0 times teleporting, obviously at 0 item(state).
    int start=0;
    int low, high;

    // now we done ith times telporting and find at which dest we are, and check whether this dest
    // occur earliear or not if yes then cyclw present.
    // so we check at which teleporting time the same dest will come, This will be our low and current teleporting index will be high
    for(int i=0; i<=n; i++){
        dest[x] = arr[start]; // at xth teleporting time we are on which state.
        if(m.count(dest[x])){
            low = m[dest[x]];
            high = x;
            break;
        }
        else{
            m[dest[x]]=x;
        }
        x++;
        start = arr[start];
    }

    if(k<high){
        cout<<dest[k]+1<<endl;
    }
    else{
        ll len = high-low;
        k -= low; // as cycle start at low, so first reduce 1 to low times teleporting from k.
        k = k%len;
        cout<<dest[low+k]+1<<endl;
    }

    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N;
    string S;
    cin >> N;

    if(N>=30){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3636
#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 LL INF=1<<30;

int main(){
    int n,k,t,u,v,l;cin >> n >> k >> t >> u >> v >> l;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    d.pb(l);
    double T=0;
    int L=0,K=0,s=0;
    while(L<l){
        if(K*v+L>=l){
            T+=1.*(l-L)/v;
            break;
        }
        if(K==0){
            T+=1.*(d[s]-L)/u;
            L=d[s];
            s++;
            K++;
        }
        else{
            K--;
            while(1){
                if(d[s]>L+v*t){
                    if(L+v*t>=l){
                        L=l;
                        T+=1.*(l-L)/v;
                        break;
                    }
                    else{
                        T+=t;
                        L+=v*t;
                        break;
                    }
                }
                if(s==n){
                    T+=1.*(l-L)/v;
                    cout <<setprecision(10)<<fixed<< T << endl;
                    return 0;
                }
                if(K==k){
                    T+=1.*(d[s]-L)/v;
                    L=d[s];
                    break;
                }
                s++;
                K++;
            }
        }
    }
    cout <<setprecision(10) << fixed << T << endl;
    return 0;
}




Measured memory_bytes: 3292
#include <iostream>

using namespace std;

int main(){
	int day, a, b, a1, b1, x, y;
	cin >> day >> a >> b >> a1 >> b1;

	x = a / a1;
	y = b / b1;

	if (a % a1 != 0) x += 1;
	if (b % b1 != 0) y += 1;

	if (x > y) cout << day - x << endl;
	else cout << day - y << endl;

	return 0;
}

Measured memory_bytes: 2996
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n, a, b = f.read_int_list()
    h = [f.read_int() for _ in xrange(n)]

    def check(num):
        s = 0
        for hi in h:
            s += max(0, (hi-num*b+(a-b-1))/(a-b))
        return s <= num

    ma = 10**10
    mi = 0

    while ma - mi > 1:
        mid = (ma+mi)/2
        if check(mid):
            ma = mid
        else:
            mi = mid

    return ma


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 7324
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<cstring>
using namespace std;
 
int main(){

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

  if((b-a)%2!=0){
    cout << "Borys" << endl;
  } else {
    cout << "Alice" << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
using namespace std;
#define FOR(S,F) for(int i=S;i<F;i++)
#define FOR2(S,F) for(int j=S;j<F;j++)
using ull=long long int;
int main() {
	ull a,b,c,d,Max;
	cin >> a>>b>>c>>d;
	Max = a * c;
	if (a * d > Max)Max = a * d;
	if (b * c > Max)Max = b * c;
	if (b * d > Max)Max = b * d;
	cout << Max << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define fr(i1,m) for(int i1=0;i1<m;i1++)
using namespace std;

int main()
{
    long long  n;
    while(cin>>n)
    {
        long long a[100100]={0};
        long long s=1,i,j,x;
       for(j=1;j<=n;j++)
       {
           x=j;
           if(x%2==0)
           {
               while(x%2==0)
                {
               x=x/2;
               a[2]++;
                }
           }
           for(i=3;i<=sqrt(x);i+=2)
           {
                 if(x%i==0)
           {
               while(x%i==0)
                {
               x=x/i;
               a[i]++;
                }
           }
           }
           if(x>1)
            a[x]++;
       }
       for(i=1;i<=1000;i++)
       {
           if(a[i]>0)
           {
               x=a[i]+1;
               s=s*x;
               s=s%1000000007;
           }
       }
       cout<<s<<"\n";
    }
    return 0;
}


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

using namespace std;
int dp[100005];
int find(int h[],int j,int n)
{
	if(~dp[j]) return dp[j];
  if(j==n-2)
  {
  	return abs(h[j+1]-h[j]);
  }
  else if(j==n-1)
  {
  	return 0;
  }
  else
  {
  	return dp[j] = min((abs(h[j+2]-h[j])+find(h,j+2,n)),(abs(h[j+1]-h[j])+find(h,j+1,n)));
  }
}
int main()
{
	int n;
	cin>>n;
	for(int i = 0; i < n; i++)
		dp[i] = -1;
	int h[n];
	for(int i=0;i<n;i++)
		cin>>h[i];
    int j=0;
	cout<<find(h,j,n);
}

Measured memory_bytes: 8832
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
int main(void){
  int n,i,j,h[5010],p[5010];
  long dp[5010][5010]={};
  const long INF=1e17;
  vector<P> c;
  cin >> n;
  for (i=0;i<n;i++){
    cin >> h[i] >> p[i];
    c.push_back(P(h[i]+p[i],i));
  }
  sort(c.begin(),c.end());
  dp[0][1]=INF;
  for (i=1;i<=n;i++){
    for (j=1;j<=i+1;j++) dp[i][j]=INF;
    for (j=1;j<=i;j++){
      dp[i][j]=dp[i-1][j];
      if (dp[i-1][j-1] <= h[c[i-1].second] && dp[i][j] > dp[i-1][j-1]+p[c[i-1].second])
          dp[i][j]=dp[i-1][j-1]+p[c[i-1].second];
    }
  }
  i=0;
  while (dp[n][i]!=INF) i++;
  cout << i-1 << endl;
  return 0;
}

Measured memory_bytes: 196480
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = list(map(int, readline().split()))
memo = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [''] * (n + 1)
for aa in a:
    if memo[aa] <= n:
        dp[memo[aa]] = max(dp[memo[aa]], str(aa))
for i in range(n):
    if dp[i] == '':
        continue
    for aa in a:
        if i + memo[aa] <= n:
            v = str(aa) + dp[i]
            if len(dp[i + memo[aa]]) < len(v):
                dp[i + memo[aa]] = v
            else:
                dp[i + memo[aa]] = max(dp[i + memo[aa]], v)
print(dp[-1])


Measured memory_bytes: 30836
#include<bits/stdc++.h>
using namespace std;
char c[5];
int main()
{

    int ans=0,m=0;
    cin>>c;
    for(int i=0;i<3;i++)
        if(c[i]=='R') ans++;
    else {
            if(m<ans) m=ans;
            ans=0;}
    if(m<ans) m=ans;
    cout<<m;
}


Measured memory_bytes: 3600
N = int(input())
a = [int(input()) for i in range(N)]
count = [0]*N
i = 0

while(True):
    count[i]+=1
    i = a[i]-1
    if i == 1:
        print(sum(count))
        break
    if count[i] == 1:
        print(-1)
        break

Measured memory_bytes: 13792
#include <stdio.h>

int main (){
	char str[21];
	scanf("%[^\n]", str);
	for (int i= 0; str[i] != '\0'; i++){
		if (str[i] >='a' && str[i]<= 'z'){
			printf("%c", str[i]);
		}else{
			printf(" ");
		}
	}
	puts("");

	return 0;
}

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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define ll long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n, d;
    cin >> n >> d;
    int ans = 0;
    for(int i=0;i<n;i++)
    {
    	int x, y;
    	cin >> x >> y;
    	int a = x*x + y*y;
    	if(a <= d*d)
    		ans++;
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3520
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<cassert>
#include<climits>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)

using namespace std;

// Library - cycoro - begin -7:26

enum FACE {TOP,BOTTOM,FRONT,BACK,LEFT,RIGHT};

template<class T>
class dice{
public:
  dice(){
    //id[FRONT] = 0; id[RIGHT] = 1; id[TOP] = 2;
    //id[BOTTOM] = 3; id[LEFT] = 4; id[BACK] = 5;
    id[TOP] = 0; id[FRONT] = 1; id[LEFT] = 2;
    id[RIGHT] = 3; id[BACK] = 4; id[BOTTOM] = 5;
  }
  T& operator[] (FACE f){ return var[id[f]]; }
  const T& operator[] (FACE f)const { return var[id[f]];}
  bool operator == (const dice<T> &b)const{
    const dice<T> &a = *this;
    return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] && 
      a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
      a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
  }

  void roll_x() { roll(TOP,BACK,BOTTOM,FRONT); }
  void roll_y() { roll(TOP,LEFT,BOTTOM,RIGHT); }
  void roll_z() { roll(FRONT,RIGHT,BACK,LEFT); }

  vector<dice> all_rolls(){
  vector<dice> ret;
  for(int k=0;k<6;(k&1?roll_y():roll_x()),++k)
    for(int i=0;i<4;roll_z(),++i)
      ret.push_back(*this);
  return ret;
  }

  bool equivalent_to(const dice& di){
    for(int k=0;k<6;(k&1?roll_y():roll_x()),++k)
      for(int i=0;i<4;roll_z(),++i)
	if(*this == di)return true;
    return false;
  }

private:
  void roll(FACE a,FACE b,FACE c,FACE d){
    T tmp = id[a];
    id[a] = id[b]; id[b] = id[c];
    id[c] = id[d]; id[d] = tmp;
  }
  T var[6];
  int id[6];
};

FACE face[] = {FRONT,RIGHT,TOP,BOTTOM,LEFT,BACK};

// Library - cycoro - end 07:34

int n,mincost;
vector<dice<int> > ALL[4];
/*
int getCost(int sp,vector<dice<int> >& dices){
  int res = 0;
  rep(i,n){
    if(i == sp)continue;
    rep(j,6){
      if(dices[i][face[j]] != dices[sp][face[j]])res++;
    }
  }
  return res;
}
*/
void dfs(int cur,vector<dice<int> >&tmp){
  if(cur >= n){
    int cost = 0;
    //int counter[6];
    map<int,int> counter;
    rep(fc,6){
      counter.clear();
      //rep(i,6)counter[i] = 0;
      int mex = 0;
      rep(i,n){
	counter[tmp[i][face[fc]]]++;
	mex = max(mex,counter[tmp[i][face[fc]]]);	
      }
      cost += (n - mex);
      assert(n-mex >= 0);
    }
    mincost = min(cost,mincost);
    return;
  }

  rep(i,ALL[cur].size()){
    tmp[cur] = ALL[cur][i];
    dfs(cur+1,tmp);
  }

}

int main(){

  while(cin >> n,n){
    int idx = 0;
    mincost= IINF;
    map<string,int> getIndex;
    vector<dice<int> > dices(n);
    rep(i,n){
      rep(j,6){
	string color;
	cin >> color;
	if(getIndex.find(color) == getIndex.end())getIndex[color] = idx++;
	int index = getIndex[color];
	dices[i][face[j]] = index; 
      }
    }

    rep(i,n)ALL[i] = dices[i].all_rolls();
    vector<dice<int> > tmp(n);

    dfs(0,tmp);


    cout << mincost << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
bingo = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
bingo_tf = [[False]*3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == b:
                bingo_tf[i][j] = True

def c(a, b, c):
    return bingo_tf[a[0]][a[1]] and bingo_tf[b[0]][b[1]] and bingo_tf[c[0]][c[1]]

if c((0, 0), (0, 1), (0, 2)) or c((1, 0), (1, 1), (1, 2)) or c((2, 0), (2, 1), (2, 2)) or c((0, 0), (1, 0), (2, 0)) or c((0, 1), (1, 1), (2, 1)) or c((0, 2), (1, 2), (2, 2)) or c((0, 0), (1, 1), (2, 2)) or c((0, 2), (1, 1), (2, 0)):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include<stdio.h>
#include<string>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include <cmath>
#include <limits>
#include <numeric>
#include <cmath>
#include <limits>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int n;
    scanf("%d",&n);
    int p[200005]={};
    REP(i,n)scanf("%d",&p[i]);
    int min=11451419;
    int count=0;
    REP(i,n){
        if(min>p[i]){
            count++;
            min=p[i];
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		int N;
		int M;
		Scanner scan = new Scanner(System.in);
		String num = scan.nextLine();
		String[] numbers = num.split(" ");
		N = Integer.parseInt(numbers[0]);
		M = Integer.parseInt(numbers[1]);

		int c = (N*(N-1))/2 + (M*(M-1))/2;
		System.out.println(c);
		
	}
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
    int n,tmp,al=0,bo=0;
    cin >>n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<n; i++){
        for(int j= i+1; j<n; j++){
            if( a[i] < a[j]){
                tmp = a[j];
                a[j] = a[i];
                a[i] = tmp;
                }
            }
        }
        for(int k=0; k<n; k++){
        if( k % 2 == 0){
            al += a[k];
        } else {
            bo += a[k];
        }
    }
    cout << al - bo << endl;
    return 0;
}


Measured memory_bytes: 256
a =gets.chomp.to_i
 
arr = []
a.times do 
 arr << gets.chomp
end
 
unless arr.length == arr.uniq.length
  puts "No"
  exit 0
end
 
before = ""
arr.each do |s|
  if before == ""
    before = s
    next
  end
  unless before[-1] == s[0]
    puts "No"
    exit 0
  end
  before = s
end
 
puts "Yes"

Measured memory_bytes: 3836
#include<iostream>

//関数の宣言
void rowSum(int row, int column, int table[101][101]);
void columnSum(int row, int column, int table[101][101]);
void rowSumTotal(int row, int column, int table[101][101]);

int main(){


	int row;
	int column;

	int table[101][101];

	for (int i = 0; i < 101; ++i){
		for (int j = 0; j < 101; ++j){
			table[i][j] = 0;
		}
	}

	std::cin >> row >> column;
	
	for (int i = 0; i < row; ++i){
		for (int j = 0; j < column; ++j){
			std::cin >> table[i][j];
		}
	}

	rowSum(row, column, table);
	columnSum(row, column, table);
	rowSumTotal(row, column, table);

	for (int i = 0; i < row + 1; ++i){
		for (int j = 0; j < column + 1; ++j){
			if (j == column){
				std::cout << table[i][j];
			}
			else{
				std::cout << table[i][j] << ' ';
			}
		}
		std::cout << '\n';
	}
}
//関数の定義
void rowSum(int row, int column, int table[101][101]){
	for (int i = 0; i < row; ++i){
		int ans=0;
		for (int j = 0; j < column; ++j){
			ans += table[i][j];
		}
		table[i][column] = ans;
		ans = 0;
	}
}

void columnSum(int row, int column, int table[101][101]){
	for (int i = 0; i < column; ++i){
		int ans=0;
		for (int j = 0; j < row; ++j){
			ans += table[j][i];
		}
		table[row][i] = ans;
		ans = 0;
	}
}

void rowSumTotal(int row, int column, int table[101][101]){
	int ans = 0;
	for (int i = 0; i < row; ++i){
		table[row][column] += table[i][column];
	}
}


Measured memory_bytes: 3120
import java.util.Scanner;
public class Main{
 
   
  public static void main(String[] args)
  {
     

    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    int arr[]=new int[n];
    for(int i=0;i<n;i++)
    	arr[i]=s.nextInt();
	  
    int dp[]=new int[n];
    
    	
    dp[0]=0;
    dp[1]=Math.abs(arr[0]-arr[1]);
    
    if(n>2) {
    dp[2]=Math.min(Math.abs(arr[2]-arr[1]), Math.abs(arr[1]-arr[0]));
    for(int i=2;i<n;i++)
    {
	   dp[i]=Math.min(dp[i-1]+Math.abs(arr[i]-arr[i-1]), dp[i-2]+Math.abs(arr[i]-arr[i-2]));
	   
    }
    }
    System.out.print(dp[n-1]);
    s.close();
  }
}

Measured memory_bytes: 50848
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll k;
cin >> k;
ll sevens = 7;
set<ll> st;

ll mod = 0;
for(int i = 1; ; i++){
    if(i == 1) {
        mod = sevens % k;
    }else{
        mod = (mod * 10 + 7) % k;
    }
    if(mod == 0){
        cout << i << endl;
        return 0;
    }else{
        if(st.count(mod)){
            cout << -1 << endl;
            return 0;
        }else{
            st.insert(mod);
        }
    }
}
}

Measured memory_bytes: 50504
#
#　　　　　　　　　　　　　　,. -─────────‐- .、
#　　　　　　　　　　　　 ／／￣￣＼　　　　　　／￣￣＼＼
#　　　　　　　　　　　／　　　　　　　　　　　　　　　　　　　　 ＼
#　　　　　　　　　 ／　　　　　　　　::::::::::::::::::::::::::::::::　　　　　　　＼
#　　　　　　　　／ 　　／ ／￣＼＼::::;;;;;;;;;;;;;;;;;:::::／／￣＼＼　　＼
#　　　　　　 ／　　　　|　 |.　┃　.|　| ::::;;;;;;;;;;;;;::::｜ |.　┃　.|　|　　　 ＼　　　　　　　　　　　　　　　　　　　　　
#　　　　　／ 　　　　　＼ ＼＿／／　::::::::::::::::::　＼＼＿／／　　　　　 ＼　　　　
#　　　 ／　　　　　..／￣￣＼　／　　　::｜::　　　＼　／￣￣＼..　　　　　＼
#　　 / 　 　 　 　 :::::　　　　　　|　　　　　 |　　　　　 |　　　　　　 :::::　　　　　 ヽ.　　　
#　　| 　　　　　　　　　　　　　　|　　　　　 |　　　　　 |　　　　　　　　　　　　　　|.
#　　| 　　　　　　　　　　　　　　＼＿＿／＼＿＿／ 　　　　　　　　　　　　　　|　　　　　　　　　　　　　　　　　
#　　| 　　　　　　　　　　　　　　　｜　　　　　　　｜　　　　　　　　　　　　　　　|
#　　| 　　　　　　　　　　　　　　　｜r─‐┬──､|　　　　　　　　　　　　　　　 |
#　　ヽ　　　　　　　　　　　　　　　 |/　　　|　　 　｜　　　　　　　　　　　　　　/
#　　　 ＼　　　　　　　　　　　　　 ＼　　　　　　／　　　　　　　　　　　　　／
#　　　　　＼ 　　　　　　　　　　　　　￣￣￣￣　　　　　　　　　　　　　／
#
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N, A, B, C, D = MI()
    S = "."+ST()
    for i in range(min(A, B), max(C, D) ):
        if S[i] == "#" and S[i - 1] == "#":
            print("No")
            exit()
    
    if (A - B) * (C - D) >= 0:
        print("Yes")
    else:
        #3連続あるか判定
        for i in range(max(A, B) + 1, min(N,min(C, D) + 2)):
            if S[i] == "." and S[i - 1] == "." and S[i - 2] == ".":
                print("Yes")
                exit()
        print("No")

if __name__ == '__main__':
    main()


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

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




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


int n, C;

int a[32][maxn];
int act[maxn];


//note: events trick fails b/c the recorder needs
//to be loaded into the channel 0.5 seconds before it starts recording

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

    cin>>n>>C;
    for (int i=0; i<n; i++) {
	int s,t,c; cin>>s>>t>>c;
	for (int j=s; j<t; j++) {
	    a[c][j]=1;
	}
    }


    for (int i=0; i<=int(1e5); i++) {
	for (int j=1; j<32; j++) {
	    if (a[j][i] || a[j][i+1]) {
		act[i]++;
	    }
	}
    }

    int res = 0;
    for (int i=1; i<=int(1e5); i++) {
	res = max(res, act[i]);
    }

    out(res);
    
    return 0;
}


Measured memory_bytes: 12416
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <climits>
#include <queue>
using namespace std;

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

  map<int, int> cnt;

  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    cnt[a] ++;
  }

  bool ans = true;
  if (cnt.size() == 1) {
    ans = cnt.begin()->first == 0;
  } else {
    if (n % 3) ans = false;
    else {
      int m = n / 3;
      if (cnt.size() == 2) {
        ans = cnt.begin()->first == 0 && cnt.begin()->second % m == 0;
      } else if (cnt.size() == 3) {
        vector<int> x;
        for (auto &p : cnt) {
          x.push_back(p.first);
          if (p.second != m) {
            ans = false;
            break;
          }
        }
        if (ans) {
          ans = (x[0] ^ x[1]) == x[2];
        }
      } else {
        ans = false;
      }
    }
  }

  if (ans) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


Measured memory_bytes: 3840
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<cstring>
typedef long long ll;
typedef long double ld;
using namespace std;
ll dx[] = { 0,0,1,-1 };
ll dy[] = { 1,-1,0,0 };

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll N;
	cin >> N;
	ll a[N + 10];
	for (ll i = 0; i < N; i++) {
		cin >> a[i];
	}
	ll sum = 0;
	ll cnt = 1;
	for (ll i = 0; i<N; i++) {
		if (a[i] == a[i + 1]) {
			cnt++;
		}
		else {
			sum += cnt / 2;
			cnt = 1;
		}
	}
	cout << sum << endl;

}


Measured memory_bytes: 256
#include <stdio.h>

int
main( void ) {
	int L, R;
	
	scanf("%d %d", &L, &R);
	double min = 2e10;
	double max = 0;
	if (R - L > 2019) {
		printf("%d\n", 0);
	}else {
		for (int i = L; i <= R; i++) {
			if (i % 2019 < min) {
				min = i % 2019;
			}
			
			if (i % 2019 > max) {
				max = i % 2019;
			}
		}
		
		//printf("min = %f\tmax = %f\n", min, max);
		double m = 2e10;
		
		for (int i = min; i < max; i++) {
			for (int j = i + 1; j <= max; j++) {
				if ((i * j) % 2019 < m) {
					m = (i * j) % 2019;
				}
			}
		}
		
		printf("%0.f\n", m);
	}
	return 0;
}

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


int solve() {
		
}

int main() {
	int n,command,forb,x;
	deque<int> deq;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> command;
		switch (command) {
			case 0:
				cin >> forb >> x;
				if(forb==0) deq.push_front(x);
				else if(forb==1) deq.push_back(x);
				break;
			case 1:
				cin >> x;
				cout << deq.at(x) << endl;
				break;
			case 2:
				cin >> forb;
				if(forb==1)
				deq.pop_back();
				else if(forb==0) deq.pop_front();
				break;
		}
	}
}



Measured memory_bytes: 4552
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int X, Y;

int main() {
    cin >> X >> Y;
    cout << max(X*2-1, max(X+Y, Y*2-1)) << endl;
    return 0;
}


Measured memory_bytes: 256