akhauriyash/Code-Regression huggingface dataset:
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int M = nextInt();
		int X = nextInt();

		int[] A = nextInts();

		long l=0,r=0;
		for(int i=0;i<A.length;i++){
			if(A[i] < X){
				l++;
			}else{
				r++;
			}
		}

		System.out.println(Math.min(l, r));
	}

	public static boolean isExpN(long a,int base){
		int x=1;
		while((int)Math.pow(x, 2) <= a){
			if((int)Math.pow(x, 2) == a){
				return true;
			}
			x*=base;
		}
		return false;
	}
	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21332
/n,a,b=gets.split.map(&:to_i)/
/.sort/
/S = gets.chomp.chars/
n,k=gets.split.map(&:to_i)
s=gets.to_s
if(s[k-1]=='A')
  s[k-1]='a'
elsif(s[k-1]=='B')
  s[k-1]='b'
else
  s[k-1]='c'
end
puts s
  

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define debugv(v) for (auto& x: v) cerr << x << " "; cerr << '\n';
#define debug2v(v) for (auto& x: v) cerr << x.fi << " - " << x.se << '\n';
using namespace std;
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
 
using ll = long long;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  
 
int main(void) {
  FAST
  int a, b;
  cin >> a >> b;
  int x = min(a, b);
  int y = max(a, b);
  for (int i = 0; i < y; i++) {
    cout << x;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
using ll = long long;

using namespace std;

const double PI = acos(-1);

//ans = sqrt(a*a + b*b);

int main()
{
	int a, b, h, m;
	cin >> a >> b >> h >> m;

	// 0時0分からのthetaを求める
	double th, tm;

	// もとがintなので，小数型にしないと割れない
	th = double(h*60+m)/720 * 2*PI;
	tm = double(m)/60 * 2*PI;

	// 座標を求める
	double xh, yh,  xm, ym;
	xh = a*cos(th);
	yh = a*sin(th);
	xm = b*cos(tm);
	ym = b*sin(tm);

	// 点a,bを対称にした四角形を作る，その辺の長さ(差)を求める
	double dx, dy;
	dx = xh-xm; 
	dy = yh-ym;

	double ans;
	ans = sqrt(dx*dx + dy*dy);

	cout << fixed << setprecision(10) << ans << endl;

	return 0;
}

Measured memory_bytes: 4104
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------
const int INF = 1 << 29;
// d[u][v]は辺e = (u, v)のコスト（存在しない場合はINF、ただしd[i][i] = 0とする。）
// Vは頂点数
void warshall_floyd(vector<vector<int>> &d, int V)
{
    for (int k = 0; k < V; k++)
    {
        for (int i = 0; i < V; i++)
        {
            for (int j = 0; j < V; j++)
            {
                chmin(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> d(n, vector<int>(n, INF));
    for (int i = 0; i < n; i++)
    {
        d[i][i] = 0;
    }
    vector<int> a(m), b(m), c(m);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        d[a[i]][b[i]] = c[i];
        d[b[i]][a[i]] = c[i];
    }
    warshall_floyd(d, n);
    int ans = 0;
    for (int i = 0; i < m; i++)
    {
        if (d[a[i]][b[i]] < c[i])
        {
            ans++;
        }
    }
    cout << ans << endl;
}

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

int N, M, Q;
int cnt[505][505];

int main() {
  cin >> N >> M >> Q;
  for (int i = 0; i < M; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    cnt[l][r]++;
  }

  for (int len = 2; len <= N; len++) {
    for (int i = 0; i + len <= N; i++) {
      int j = i + len;
      cnt[i][j] += cnt[i + 1][j] + cnt[i][j - 1] - cnt[i + 1][j - 1];
    }
  }

  while (Q--) {
    int a, b;
    cin >> a >> b;
    a--;
    cout << cnt[a][b] << endl;
  }
  return 0;
}


Measured memory_bytes: 4624
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#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 INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n; cin >> n;
  vector<ll> h(n);
  REP(i,n){
      cin >> h[i];
  }
  ll dp[n];
  REP(i,n){
      dp[i] = LINF;
  }
  dp[0] = 0;
  REP(i,n-1){
      dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
      if(i!=n-2){
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
      }
  }
  cout << dp[n-1] << endl;

}

Measured memory_bytes: 1792
#include<cstdlib>
#include<map>
#include<stdio.h>
#include<string>
#include<string.h>
#include<math.h>
#include<algorithm>
#include <iostream>
#define ll long long
using namespace std;
int main()
{
    string str;
    int n;
    int tl=0,tr=0;
    cin>>n;
    cin>>str;
    for(int i=0; i<n; i++)
    {
        if(str[i]=='(')
            tl++;
        else
        {
            if(tl>0)
                tl--;
            else
                tr++;
        }
    }
    for(int i=0;i<tl;i++)
        str=str+')';
    for(int i=0;i<tr;i++)
        str='('+str;
    cout<<str<<endl;
    return 0;
}


Measured memory_bytes: 256
/*input
100000 100000 0
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int v[maxn];

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

	REP(i,n) v[i]=m;

	REP(i,k){
		int x,y;
		cin>>x>>y;
		x--;y--;
		v[x]=min(v[x],y);
	}
	int r=0;
	for(int i=1;i<n;i++){
		if(v[i]<=r){
			cout<<i<<'\n';
			return 0;
		}
		if(v[i]!=r+1) r++;
	}
	cout<<n<<'\n';

	return 0;
}


Measured memory_bytes: 1024
import sys
t = [0 for i in range(10000)]
c = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            for l in range(10):
                t[c] = i + j + k + l
                c += 1
for line in sys.stdin:
    n = int(line)
    print(t.count(n))

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

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

typedef long long LL;

int main(){
  LL a,b,c;
  cin >> a >> b >> c;
  if(!(a%2&b%2&c%2)){
    cout << 0 << endl;
  }else{
    LL mi=1000000000000000000;
    if(a%2){
      mi=min(mi,b*c);
    }
    if(b%2){
      mi=min(mi,c*a);
    }
    if(c%2){
      mi=min(mi,a*b);
    }
    cout << mi << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/********************************************************
     Failing doesn’t give you a reason to give up,
     as long as you believe.
                                  - Seventh Hokage
********************************************************/

#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <set>

using namespace std;

#define int long long int
typedef vector< int >        vi;
typedef set< int >           si;
typedef pair< int, int >     pii;
typedef map< int, int >      mii;
#define sz(a)           (int)((a).size())
#define pb              push_back
#define mp              make_pair
#define all(c)          (c).begin(),(c).end()
#define rall(c)         (c).rbegin(),(c).rend()
#define ub(c,k)         (upper_bound(all(c),k)-(c).begin())
#define lb(c,k)         (lower_bound(all(c),k)-(c).begin())
#define inf             LLONG_MAX
#define _inf            LLONG_MIN
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define fr(n)           for(int i=0;i<n;i++)
#define tr(a)           for(auto it=a.begin();it!=a.end();it++)
#define trr(a)          for(auto it=a.rbegin();it!=a.rend();it++)
#define find(c, x)      (c.find(x) != c.end())
#define M               1000000007
#define PI              3.1415926535897932384
#define F               first
#define S               second
#define accuracy(x)     cout<<fixed<<setprecision(x);
#define fuck            {cout<<-1;return;}
#define fasterBaby      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define elasped_time	1.0 * clock() / CLOCKS_PER_SEC
#define N               200005

void basEkBaarAur()
{
	int n,ans=inf;
	string s;
	cin>>n>>s;
	int cnt[n];

	fr(n)
	{
		if(i) cnt[i]=cnt[i-1]+ (s[i]=='R');
		else cnt[i]= (s[i]=='R');
	}
	rep(i,0,n+1)
	{
		if(i) 
		{
			ans=min(ans,abs((i-cnt[i-1])-(cnt[n-1]-cnt[i-1])) + min((i-cnt[i-1]),(cnt[n-1]-cnt[i-1])));
			//if(abs((i-cnt[i-1])-(cnt[n-1]-cnt[i-1]))==0) cout<<i;
		}

		else ans=min(ans,cnt[n-1]);
	}
	cout<<ans;
}

signed main()
{
	accuracy(15)
	fasterBaby
	int TESTS=1,i=1;
	//cin>>TESTS;
	while(TESTS--)
	{
		//cout<<"Case#"<<i++<<endl;
		basEkBaarAur();
		cout<<endl;
	}
	cerr<<endl<<"समय गुज़रा : "<<elasped_time<<endl;
	return 0;
}

Measured memory_bytes: 5452
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int a, b;
    cin >> a >> b;

    int res = 0;

    for (int i = a; i <= b; i++) {
        string s = to_string(i);
        int n = s.size();
        bool f = true;
        for (int i = 0, j = n-1; i < j; ++i, --j) {
            if (s[i] != s[j]) f = false;
        }
        if (f) res++;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;


int main(){

	int X;
	cin >> X;

	int tmp = X / 100;
	int tmp_2 = X % 100;

	if (tmp * 5 >= tmp_2){
		cout << 1;
	}
	else{
		cout << 0;
	}

	return 0;
}

Measured memory_bytes: 384
import bisect

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# print(N, M, K)
# print(A)
# print(B)

def cuml(li):
    rlis = [0]

    for i in range(len(li)):
        rlis.append(rlis[-1] + li[i])

    return rlis


A_cuml = cuml(A)
B_cuml = cuml(B)

res = 0

for a in range(len(A_cuml)):
    rest = K - A_cuml[a]
    if rest < 0:
        break
    # for b in range(len(B_cuml)):
    #     if A_cuml[a] + B_cuml[b] > K:
    #         break

    # bisect search
    b = bisect.bisect_right(B_cuml, K - A_cuml[a])

    res = max(res, a + b - 1)

print(res)

Measured memory_bytes: 47528
//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
#include<cstring>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define P pair<int,int>
#define ll __int64

int m,n;
int table[100][100];
bool used[100][100];
int  u[100][100];
int ans=0;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int dfs(set<P>jo,int y,int x){
	if(y<0||x<0||y>=n||x>=m||table[y][x]==0)return 0;
	if(u[y][x]==1)return 0;

	//cout<<y<<" "<<x<<" "<<jo.size()<<endl;
	int ma=0;
	jo.insert(mp(y,x));
	int ny,nx;
	rep(i,4){
			ny=y+dy[i];
			nx=x+dx[i];
			if(jo.find(mp(ny,nx))==jo.end()){

				ma=max(dfs(jo,ny,nx)+1,ma);
			}
		//ma=max(dfs(y+dy[i],x+dx[i])+1,ma);
	}

	return ma;
}


int main(){
while(cin>>m>>n,n||m){
rep(i,100)memset(used[i],0,sizeof used[i]);
rep(i,100)memset(u[i],0,sizeof u[i]);
rep(i,100)memset(table[i],0,sizeof table[i]);

rep(i,n){
	rep(j,m)cin>>table[i][j];
}
int ans=0;

for(int i=0;i<n;i++){
	for(int j=0;j<m;j++){
			if(table[i][j]==0)continue;
			set<P>jo;
			jo.clear();
			int now=dfs(jo,i,j);
			ans=max(ans,now);
			//cout<<i<<" "<<j<<" "<<now<<endl;

	}
}
cout<<ans<<endl;
}

	return 0;
}




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

int main()
{
	int n,m;
	int a[50],b[50];
	int ans[50] = {0};

	cin >> n >> m;
	for(int i = 0; i < m; i++)
	{
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i < m; i++)
	{
		ans[a[i]]++;
		ans[b[i]]++;
	}
	for(int i = 1; i <= n; i++)
	{
		printf("%d\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int temp=n, ans=0;
    while(temp>0){
        ans += temp%10;
        temp/=10;
    }
    if(n%ans==0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

struct mint {
  ll x;
  mint(ll x = 0) : x(x % MOD) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  //
  ll n, m;
  cin >> n >> m;
  vl x(n), y(m);
  rep(i, n) { cin >> x[i]; }
  rep(i, m) { cin >> y[i]; }
  sort(ALL(x));
  sort(ALL(y));
  vector<mint> s;
  s.emplace_back(n - 1);
  mint totalx(n - 1);
  vector<mint> xapp, yapp;
  ll cur = n - 3;
  xapp.emplace_back(n - 1);
  while (cur > 0) {
    totalx = totalx + cur;
    cur -= 2;
    xapp.emplace_back(totalx);
  }
  // cerr << xapp.size();
  mint totaly(m - 1);
  yapp.emplace_back(m - 1);
  cur = m - 3;
  while (cur > 0) {
    totaly = totaly + cur;
    cur -= 2;
    yapp.emplace_back(totaly);
  }

  mint xsum(0);
  rep(i, n - 1) {
    mint len(x[i + 1] - x[i]);
    if (i < n / 2) {
      // cerr << "a";
      xsum = xsum + len * xapp[i];
    } else {
      // cerr << "b";
      xsum = xsum + len * xapp[n - 2 - i];
    }
  }
  // cerr << xsum.x << endl;

  mint ysum(0);
  rep(i, m - 1) {
    mint len(y[i + 1] - y[i]);
    if (i < m / 2) {
      ysum = ysum + len * yapp[i];
    } else {
      ysum = ysum + len * yapp[m - 2 - i];
    }
  }

  mint ans = xsum * ysum;
  cout << ans.x << endl;
  return 0;
}


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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

i64 solve(const vi &L, const vi &R, const vi &K) {
  i64 N = sz(L), i;
  set<pi, greater<pi>> vals; // {delta, l or r}, position
  REP(0, N, i){
    // perfer left
    vals.insert({L[i]-R[i], i});
  }
  
  i64 ans = 0;
  set<i64> positions;
  REP(0, N, i) {
    positions.insert(i);
  }

  for(auto it=vals.begin();it!=vals.end();++it) {
    i64 idx = it->second;
    // perfer left
    //cerr << "process K " << K[idx] << endl;
    auto bound = positions.upper_bound(K[idx]);
    if(bound == positions.begin()) {
      ans += R[idx];
    }
    else {
      bound--;
      ans += L[idx];
      //cerr << "insert " << idx << " to position " << *bound << endl;
      positions.erase(bound);
    }
  }
  return ans;
}

int main(int argc, char *argv[]) {
  i64 T, t;
  cin >> T;
  REP(0, T, t) {
    i64 N, i;
    cin >> N;
    set<pi, greater<pi>> vals; // {delta, l or r}, position, index
    vi K(N), L(N), R(N);
    REP(0, N, i) {
      cin >> K[i] >> L[i] >> R[i];
    }

    i64 ans = 0;
    vi K0, L0, R0, L1, K1, R1;
    REP(0, N, i) {
      if(K[i] == N || L[i] == R[i]) {
	ans += L[i];
      }
      else if(L[i] > R[i]) {
	L0.pb(L[i]); R0.pb(R[i]); K0.pb(K[i]-1);
      }      
      else {
	L1.pb(R[i]); R1.pb(L[i]), K1.pb(N-1-K[i]);
      }
    }
    //cerr << solve(L0, R0, K0) << " " << solve(L1, R1, K1) << endl;
    ans += solve(L0, R0, K0);
    ans += solve(L1, R1, K1);

    cout << ans << endl;
    
  }

  return 0;
}


Measured memory_bytes: 23440
<?php
$input = explode(' ', trim(fgets(STDIN)));

$a = (int)$input[0];
$b = (int)$input[1];
$c = (int)$input[2];

$check = $c - $a - $b;
if ($check <= 0) {
	echo 'No';
} elseif ( pow($check, 2) > 4 * $a * $b ){
	echo 'Yes';
} else {
	echo 'No';
}

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


const int MAXN = 1005;

int main() {
  double n,k;
  cin>>n>>k;
  double ans=0;

  double score;
  for(double i=1;i<=n;i++){
    double temp=1/n;
    score=i;
    while (score<=k-1){
      score*=2;
      temp/=2;
    }
    //cout<<temp<<endl;
    ans+=temp;
  }
  cout<<setprecision(10)<<ans;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int loop;
	int N;
	int sum = 0;
	int max;
	scanf("%d", &N);

	for (loop = 0;; loop++){
		sum += loop;
		if (sum >= N){
			max = loop;
			break;
		}
	}
	for (loop = 1; loop < sum - N; loop++)printf("%d\n", loop);
	for (loop = sum - N + 1; loop <= max; loop++)printf("%d\n", loop);

	return 0;
}

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

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x);       cout << "\n" <<  #x << " is: " << x << "\n";
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd(a,b)
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (int i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)

int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        int n;
        cin >> n;
        int x = 0;
        int flag = -1;
        for (int i = 1; i <=1e6; i++)
        {
            x = (x * 10 + 7) % n;
            if (x == 0)
            {
                flag = i;
                break;
            }
        }
        cout << flag << endl;


    }
    return 0;
}


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

int main(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++)
                if(500*i+100*j+50*k==x){
                    ans++;
                }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int a[M],b[M];
  rep(i,M){
      cin>>a[i];
      cin>>b[i];
  }
  int maxl = 0;
  int minl = N;
  rep(i,M) {
    maxl = max(maxl,a[i]);
    minl = min(minl,b[i]);
  }
int ans = minl - maxl+1 ;
  ans = max(0,ans);
cout << ans << endl;
return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
using namespace std;
int n,top;
const int N=200010;
int len[N];
struct wei{int pos,val;}zhan[N];
void Insert(int l,int mid)
{
	while(zhan[top].pos>l)--top;
	if(zhan[top].pos==l)++zhan[top].val;
	else zhan[++top]=(wei){l,1};
	if(top>1&&zhan[top].val==mid)--top,Insert(l-1,mid);
}
int check(int mid)
{
	zhan[top=1]=(wei){0,0};
	for(int i=2;i<=n;++i)
		if(len[i]<=len[i-1])Insert(len[i],mid);
	return zhan[1].val==0;
}
int pan(){for(int i=2;i<=n;++i)if(len[i]<=len[i-1])return 0;return 1;}
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)scanf("%d",&len[i]);
	if(pan())return puts("1")==2333;
	int l=2,r=n,mid,ans=1;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(check(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans;
	return 0;
}

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

using Graph=vector<vector<int>>;

int grundy(int v,int pre,Graph& g){
    vector<int> gs;
    for(auto to:g[v]){
        if(to!=pre) gs.push_back(grundy(to,v,g)+1);
    }
    int res=0;
    for(auto g:gs) res^=g;
    return res;
} 
int main(){
    int n;
    cin>>n;
    Graph g(n);
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        x--,y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    cout<<(grundy(0,-1,g) ? "Alice" : "Bob")<<endl;
    return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <iomanip>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef long long ll;

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// セグ木
// seg.size() = 2*N, [N,2*N)に列を格納
vector<int> seg;

void seg_add(int i, int a)
{
    i += seg.size() / 2;
    seg[i] += a;
    while (i > 1)
    {
        i /= 2;
        seg[i] = seg[2 * i] + seg[2 * i + 1];
    }
}

int seg_sum(int l, int r)
{
    l += seg.size() / 2;
    r += seg.size() / 2;
    int ret = 0;
    while (l < r)
    {
        if (l & 1)
        {
            ret += seg[l];
            l++;
        }
        if (r & 1)
        {
            r--;
            ret += seg[r];
        }
        l /= 2;
        r /= 2;
    }
    return ret;
}

// 閉区間[left,right](0-indexed), index番目(0-indexed)のクエリ
struct interval
{
    int left;
    int right;
    int index;
};

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    int n, q;
    cin >> n >> q;
    seg.resize(2 * n);
    vector<int> col_s(n);
    FOR(pos, 0, n)
    {
        cin >> col_s[pos];
        col_s[pos]--;
    }
    vector<interval> intervals(q);
    rep(i_q, q)
    {
        int l, r;
        cin >> l >> r;
        intervals[i_q] = { l - 1, r - 1, i_q };
    }
    sort(intervals.begin(), intervals.end(), [](interval x, interval y) {
        return x.right < y.right;
    });

    // pos_ball[color] : 一番右のcolor(0-indexed)の場所pos(0-indexed)
    vector<int> pos_ball(n, -1);
    vector<int> ans(q);
    int ii_q = 0;
    FOR(pos, 0, n)
    {
        // pos_ball の更新
        if (pos_ball[col_s[pos]] >= 0)
        {
            seg_add(pos_ball[col_s[pos]], -1);
        }
        pos_ball[col_s[pos]] = pos;
        seg_add(pos, 1);

        // ansに格納
        while (ii_q < q and intervals[ii_q].right == pos)
        {
            ans[intervals[ii_q].index] = seg_sum(intervals[ii_q].left, intervals[ii_q].right + 1);
            ii_q++;
        }
    }

    rep(i_q, q)
    {
        cout << ans[i_q] << '\n';
    }

    return 0;
}


Measured memory_bytes: 19396
N = int(input())
abcs = list( list(map(int,input().split())) for _ in range(N))
dp = [[0]*3 for _ in range(N)]

dp[0] = abcs[0]
# print(dp)

for n in range(1,N):
    for i in range(3):
        for j in range(3):
            if i == j:
                continue
            else:
                if dp[n][i] < dp[n-1][j] + abcs[n][i]:
                    dp[n][i] = dp[n-1][j] + abcs[n][i]
                    
print(max(dp[N-1]))

Measured memory_bytes: 47308
#include <iostream>
typedef long long ll; 
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;



void solve() {
    int n, k; scanf("%d %d", &n, &k);
    ll sum = 0;
    for (int i = k; i <= n+1; i++) {
        ll minimum = ((ll)(i)*(i-1))/2;
        ll maximum = ((ll)(2*n-i+1)*(i))/2;
        sum += (maximum-minimum+1);
    }
    printf("%I64d", sum%mod);
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

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

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buf;
    while(getline(ss, buf, sep)){
        v.push_back(buf);
    }
    return v;
}

#define heisei cout << "Heisei" << endl; return 0;
#define tbd cout << "TBD" << endl; return 0;

int main(){
    string s; cin >> s;
    vector<string> splited = split(s, '/');
    int year; istringstream(splited[0]) >> year;
    int month; istringstream(splited[1]) >> month;
    int day; istringstream(splited[2]) >> day;

    if(year < 2019){
        heisei
    }else if(year == 2019){
        if(month <= 4) {
            heisei
        }else{
            tbd
        }
    }else{
        tbd
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

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


ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}


int main(){
    vector<ll>x(2);
    vector<ll>y(2);

    cin >> x[0] >> x[1] >> y[0] >> y[1];

    ll ans = x[0]*y[0];

    rep(i,2){
        rep(j,2){
            ll can = x[i]*y[j];
            ans = max(can,ans);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}


 main()

{
    fast
    int n,m;
    cin>>n>>m;
    int a[n+3];
    f(i,1,n)
    {
        cin>>a[i];
    }
    vector<int>adj[n+4];
    f(i,1,m)
    {   int u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    int cnt=0;
    f(i,1,n)
    {
        int val=a[i];
        int mx=0;
        for(auto v:adj[i])
        {
            mx=max(mx,a[v]);
        }
        if(val>mx)
            cnt++;
    }

    cout<<cnt<<endl;
















    return 0;

}













Measured memory_bytes: 10276
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    string r,g,b;
    cin>>r>>g>>b;
    string ans=r+g+b;
    int x=stoi(ans);
    if(x%4==0)cout<<"YES\n";
    else cout<<"NO\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=1<<18;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int n;
int a[maxn];
vector<int> v[maxn];
int main()
{
	IOS;
    int n;
    cin>>n;
    REP(i,(1<<n)) cin>>a[i];
    REP(i,(1<<n)) v[i].pb(a[i]);
    REP(i,n) for(int j=0;j<(1<<n);j+=(1<<(i+1))){
        for(int k=j;k<j+(1<<i);k++){
            for(int meow:v[k]) v[k+(1<<i)].pb(meow);
            sort(ALL(v[k+(1<<i)]),greater<int>());
            if(SZ(v[k+(1<<i)])>2) v[k+(1<<i)].resize(2);
        }
    }
    /*for(int i=1;i<(1<<n);i++){
        cout<<v[i][0]<<' '<<v[i][1]<<'\n';
    }*/
    
    int ans=-1;
    for(int i=1;i<(1<<n);i++){
        if(SZ(v[i])<2);
        else{
            ans=max(ans,v[i][0]+v[i][1]);
        }
        cout<<ans<<'\n';
    }
}


Measured memory_bytes: 18432
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n);
    vector<ll> v2(n);
    rep(i,n){
        ll a;
        cin>>v[i];
        v2[i]=v[i];
    }
    int ans=0;

    for(int i=0;i<n;i++){
        for(int j=n-1;j>i;j--){
            if(v2[j]<v2[j-1]){
                ans++;
                ans%=MOD;
                ll tmp=v2[j];
                v2[j]=v2[j-1];
                v2[j-1]=tmp;
            }
        }
    }
    ans=(ans*k)%MOD;

    sort(v.begin(),v.end());
    ll jk=0;

    for(int i=0;i<n;i++){
        auto itr=upper_bound(v.begin(),v.end(),v[i]);
        ll c=v.size()-(itr-v.begin());
        jk+=c;
        jk%=MOD;
    }


    ll s=k%MOD;
    s*=(s-1)%MOD;
    s/=2;
    s%=MOD;
    s*=jk;
    s%=MOD;
    ans+=s;

    ans%=MOD;

    cout<<ans<<endl;









    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env fsharpi

open System;

let ParseIntN ( str : string ) =
    str.Split(' ')
    |> Array.map System.Int32.Parse

let ParseInt1 ( str : string ) =
    ParseIntN str |> fun arr -> arr.[0]

let ParseInt2 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1])

let ParseInt3 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1],arr.[2])

let ReadLinesN ( n : int ) =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.take n

let ReadLines =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.takeWhile ((<>) null)

module String =
    /// Converts a string into a list of characters.
    let explode (s:string) =
        [for c in s -> c]

    /// Converts a list of characters into a string.
    let implode (xs:char list) =
        let sb = System.Text.StringBuilder(xs.Length)
        xs |> List.iter (sb.Append >> ignore)
        sb.ToString()

Console.ReadLine().Split(' ')
|> Array.map (String.explode >> List.head)
|> Array.toList
|> String.implode
|> Console.WriteLine


Measured memory_bytes: 11348
solve _ [] = 1
solve [] _ = 0
solve (x:xs) (y:ys)
  | x == y = solve xs ys
  | x /= y = solve xs (y:ys)

main = do
  n <- readLn :: IO Int
  xs <- getLine 
  print $ sum [solve xs [i,j,k] | i <- ['0'..'9'], j <- ['0'..'9'], k <- ['0'..'9']]
  
  


Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i,n) for (int i = 0; i < (int) (n); ++ i)
#define foreach(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++ it)
 
inline int read() {
	int x = 0, f = 1, c = getchar();
	for (;!isdigit(c);c = getchar()) if (c == '-') f ^= 1;
	for (; isdigit(c);c = getchar()) x = x * 10 + c - '0';
	return f ? x : -x;
}

char ans[1005][1005];
int main() {
	int h = read(), w = read(), a = read(), b = read();
	rep(i, h) rep(j, w) ans[i][j] = '0';
	rep(i, b) rep(j, a) ans[i][j] = '1';
	rep(i, h - b) rep(j, w - a) ans[i + b][j + a] = '1';
	rep(i, h) puts(ans[i]);
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
using namespace std;
using ll = long long;

int main()
{

  int N;

  cin >> N;

  ll A[N];
  ll acc = 0;

  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
    acc += A[i] - 1;
  }

  cout << acc;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by Sohail on 9/7/2019.
 */

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        long[] b = new long[x];
        for(int i = 0; i < x-1; i++){
            b[i] = sc.nextInt();
        }
        long tot = b[0];
        for(int i = 0; i < x-1; i++){
            tot += Math.min(b[i],b[i+1]);
        }
        System.out.println(tot+b[x-2]);
    }
}



Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define inchar			getchar
#define outchar(x)		putchar(x)
#define ll long long 
#define int long long //
#define all(v) v.begin(), v.end()
#define SP outchar(' ')
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
#define LN outchar('\n')
#define endl '\n'
using namespace std;

template<typename T> void inpos(T &x){x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=0; if(c=='-')neg=1;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}
template<typename T> void outpos(T n){if(n<0){outchar('-');n*=-1;}char snum[65];int i=0;do{snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);}
inline void instr(char *str){register char c=0;register int i=0;while(c<33)c=inchar();while(c!='\n'&&c!=' '&&c!=EOF){str[i]=c;c=inchar();++i;}str[i]='\0';}
typedef vector <int> vi;
typedef vector <vi> Graph;
const int mod = 1e9+7;

int32_t main () {
	int n, m;
	cin >> n >>m;
	vector <string> arr(n);
	vector < vi> dp(n+1, vector <int> (m+1,0) );

	for(int i = 0; i<n;i++) {
		cin >> arr[i];
	}
	for (int i = 0; i<n;i++) {
		for (int j = 0; j<m;j++) {
			if(arr[i][j] == '#') {continue;}
			if (i==0 && j == 0) {dp[i][j] = 1;continue;}
			int A = (i-1>=0 && arr[i-1][j]!='#')?dp[i-1][j]:0;
			int B = (j-1>=0 && arr[i][j-1]!='#')?dp[i][j-1]:0;
			dp[i][j] = (A +B)%mod;
			// cout << dp[i][j] << " ";
		}
		// cout<<endl;
	}
	cout << dp[n-1][m-1] <<endl;

}

Measured memory_bytes: 9216
#include <iostream>
#include <vector>

bool is_GoodDist (int const& val_dist)
{
	for (int itr = 0; itr <= val_dist; itr++)
	{
		if (itr *itr == val_dist) {return true;}
	}

	return false;
}

int calculate_distance2 (int const& val_dimension, std::vector<int> const& point_orign, std::vector<int> const& point_target)
{
	// return value of this function
	int distance2;
	int difference;

	distance2 = 0;

	for (int itr = 0; itr < val_dimension; itr++)
	{
		difference  = point_target.at(itr) - point_orign.at(itr);
		difference *= difference;
		distance2  += difference;
	}

	return distance2;
}

int calculate_num_GoodDist (int const& num_points, int const& val_dimension, std::vector<std::vector<int>> const& coordinate)
{
	// variables for this function
	int num_GoodDist;

	// STEP.01
	// initialize the variable
	num_GoodDist = 0;

	for (int itr_orign  = 0;             itr_orign  < num_points - 1; ++itr_orign ) {//
	for (int itr_target = itr_orign + 1; itr_target < num_points;     ++itr_target) {//
		if ( is_GoodDist( calculate_distance2(val_dimension, coordinate.at(itr_orign), coordinate.at(itr_target)) ) ) { num_GoodDist++; }
	}
	}

	return num_GoodDist;
}

int main (void)
{
	// variables for main process
	int num_points;
	int val_dimension;

	// STEP.01
	// read out the given data
	std::cin >> num_points >> val_dimension;

	// STEP.02
	// declare the <vector> object to store the given data
	std::vector<std::vector<int>> coordinate(num_points, std::vector<int>(val_dimension)); ;

	// STEP.03
	// read out the given data
	for (int itr_point = 0; itr_point < num_points;    itr_point++) {//
	for (int itr_dmsn  = 0; itr_dmsn  < val_dimension; itr_dmsn++ ) {//
		std::cin >> coordinate[itr_point][itr_dmsn];
	}
	}

	std::cout << calculate_num_GoodDist (num_points, val_dimension, coordinate) << std::endl;

	// STEP.END
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        int[] results = new int[50];
        int lastLength = 0;
        while ((line = reader.readLine()) != null) {
            if (line.isEmpty()) {
                continue;
            }
            String[] values = line.split(",");
            if (values.length > lastLength) {
                for (int i = values.length - 1; i >= 0; i--) {
                    int left = i > 0 ? results[i - 1] : 0;
                    int top = results[i];
                    results[i] = Math.max(left, top)
                            + Integer.parseInt(values[i]);
                }
            } else {
                for (int i = 0; i < values.length; i++) {
                    int top = results[i];
                    int right = results[i + 1];
                    results[i] = Math.max(top, right)
                            + Integer.parseInt(values[i]);
                }
            }
            lastLength = values.length;
        }
        out.println(results[0]);
    }
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, H[100000];

bool tourist() {
	--H[0];
	for (int i = 1; i < N; ++i) {
		if (H[i - 1] < H[i])--H[i];
		if (H[i - 1] > H[i])return false;
	}
	return true;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> H[i];
	}
	if (tourist()) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

const long long INF = 1e18;

long long ans = INF;

long long a, b, c, d, n;

bool judge(long long a, long long b, long long c) {
    if (b && LLONG_MAX / b < a) return false;
    if (a * b > LLONG_MAX - c) return false;
    return true;
}

map <long long, long long> mp;

long long dfs(long long x) {
    if (x == 0) return 0;
    if (x == 1) return d;
    if (mp.count(x))    return mp[x];
    long long res = INF;
    if (res / d > x)    res = d * x;
    long long L2 = x / 2 * 2, R2 = (x + 1) / 2 * 2;
    res = min(res, dfs(L2 / 2) + a + abs(x - L2) * d);
    res = min(res, dfs(R2 / 2) + a + abs(R2 - x) * d);
    
    long long L3 = x / 3 * 3, R3 = (x + 2) / 3 * 3;
    res = min(res, dfs(L3 / 3) + b + abs(x - L3) * d);
    res = min(res, dfs(R3 / 3) + b + abs(R3 - x) * d);
    
    long long L5 = x / 5 * 5, R5 = (x + 4) / 5 * 5;
    res = min(res, dfs(L5 / 5) + c + abs(x - L5) * d);
    res = min(res, dfs(R5 / 5) + c + abs(R5 - x) * d);

    return mp[x] = res;
}

int main() {
    int T;  scanf("%d", &T);
    while (T--) {
        mp.clear();
        ans = INF;
        scanf("%lld", &n);
        scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
        printf("%lld\n", dfs(n));
    }
#ifndef ONLINE_JUDGE
    system("pause");
#endif
    return 0;
}

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

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

    int i = 0;
    int moves = 0;
    while (s[i])
    {
        if (s[i] != t[i])
        {
            moves++;
        }
        i++;
    }
    cout << moves << endl;
}

Measured memory_bytes: 3848
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.ST                 as ST
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Foldable                  ( toList )
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import qualified Data.Sequence                 as SQ
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
readInts n = replicateM n readInt
readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n readString
toPair [x, y] = (x, y)

main = do
  [s] <- readString
  putStrLn $ solve s

solve s | f s       = "Yes"
        | otherwise = "No"

f []  = True
f [_] = False
f (s : s' : ss) | [s, s'] == "hi" = f ss
                | otherwise       = False


Measured memory_bytes: 380
def partition(A, p, r):
    i = p - 1
    for j in range(p, r + 1):
        if A[j][1] <= A[r][1]:
            i += 1
            A[i], A[j] = A[j], A[i]

    return i


def quick_sort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quick_sort(A, p, q - 1)
        quick_sort(A, q + 1, r)


n = int(raw_input())
A = []

for i in range(n):
    char, num = raw_input().split()
    num = int(num)
    A.append([char, num])

B = list(A)

quick_sort(A, 0, n-1) 
B.sort(key=lambda x: x[1])

for i in range(n):
    if A[i][0] != B[i][0]:
        print "Not stable"
        break
else:
    print "Stable"

for i in range(n):
    print A[i][0], A[i][1]

Measured memory_bytes: 26732