akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/segtree>
// using namespace atcoder;

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>> &pq) {return (ll)pq.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>, greater<T>> &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); } 
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }

int main(){
    ll n;
    cin >> n;
    ll cnt[n+1] = {};
    rep(i,1,n+1){
        for(ll j = 1; i * j <= n; j++){
            cnt[i*j]++;
            //cout << i << " " << j << endl;
        }
    }

    ll ans = 0;
    rep(i,1,n){
        ans += cnt[n-i];
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 11440
diceA = list(map(int, input().split()))

diceB1 = list(map(int, input().split()))

diceB2 = [diceB1[0],diceB1[1],diceB1[2],diceB1[4],diceB1[3],diceB1[5]]

diceC = [[1,2,3,5,4,2,3,5,6],[2,1,4,6,3,1,4,6,5],[3,1,2,6,5,1,2,6,4],[4,1,5,6,2,1,5,6,3],[5,1,3,6,4,1,3,6,2],[6,2,4,5,3,2,4,5,1]]

for i in range(6):
  if diceB2[0] == diceA[i]:
    for j in range(1,5):
      if diceB2[1] == diceA[diceC[i][j]-1]:
        for k in range(1,4):
          if diceB2[1+k] == diceA[diceC[i][j+k]-1]:
            m = "Yes"
          else:
            m = "No"
            break
        if m == "Yes":
          if diceB2[5] == diceA[diceC[i][8]-1]:
            m = "Yes"

print(m)


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
 
int main() {

int n, a, b;

cin >> n >> a >> b;

int d = n * a;

if (d > b) {
    cout << b << endl;
} else if (d < b) {
    cout << d << endl;
} else {
    cout << b << endl;
}
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

# In[7]:


N = int(input())
A = []
for _ in range(2):
    A.append(list(map(int, input().split())))


# In[8]:


ans = 0
for i in range(N):
    ans = max(ans, sum(A[0][:i+1])+sum(A[1][i:]))
print(ans)


# In[ ]:






Measured memory_bytes: 9004
//check violation of constraints

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	void run() {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		double[] x = new double[N];
		double[] y = new double[N];
		double ans = 0;
		for (int i = 0; i < N; ++i) {
			x[i] = sc.nextDouble();
			y[i] = sc.nextDouble();
		}
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				double dx = x[i] - x[j];
				double dy = y[i] - y[j];
				ans += Math.sqrt(dx * dx + dy * dy);
			}
		}
		ans /= N;
		System.out.println(ans);
	}

	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
typedef long long ll;
ll dp[55][55][55*55*2];
const ll mod=1e9+7;
void add(ll &a,ll b)
{
    a+=b;
    if(a>=mod)a-=mod;
}
int main()
{
    int n,k;scanf("%d%d",&n,&k);int tmp=n*n;
    dp[0][0][tmp]=1;
    rep(i,0,n)rep(j,0,i+1)rep(x,0,n*n*2+1)
    if(dp[i][j][x])
    {
        add(dp[i+1][j][x],dp[i][j][x]);
        add(dp[i+1][j][x],dp[i][j][x]*j%mod);
        add(dp[i+1][j+1][x-2*i-2],dp[i][j][x]);
        add(dp[i+1][j-1][x+2*i+2],dp[i][j][x]*j%mod*j%mod);
        add(dp[i+1][j][x],dp[i][j][x]*j%mod);
    }
    printf("%lld\n",dp[n][0][k+n*n]);
}

Measured memory_bytes: 129280
#include <iostream>
#include <string>
#include <cstring>

using namespace std;
string toLower(string str){
	for (int i = 0; i < str.size(); ++i){
		if (isupper(str[i])) str[i] = tolower(str[i]);
	}
	return str;
}
int main(){
	string str; cin >> str;
	str = toLower(str);
	int sum = 0; string tmp;
	while (true){
		cin >> tmp; if (tmp == "END_OF_TEXT") break;
		tmp = toLower(tmp);
		if (tmp == str) ++sum;
	}
	cout << sum << '\n';
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main()
{
	int flag1=0,flag2=0;
	string s;
	cin>>s;
	int a=((s[0]-'0')*10+(s[1]-'0'));
  	int b=((s[2]-'0')*10+(s[3]-'0'));
  	if(a<13&&a>0)
  		flag1=1;
  	if(b<13&&b>0)
  		flag2=1;
 	if(flag1&&flag2)
 		cout<<"AMBIGUOUS";
 	else if(flag1&&!flag2)
 		cout<<"MMYY";
 	else if(!flag1&&flag2)
 		cout<<"YYMM";
 	else
	 	cout<<"NA";
}

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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    
    int now = 0, ans = 0;
    vector<bool> pushed(n,false);
    
    while(now != 1){
        if(pushed[now]){
            ans = -1;
            break;
        }
        pushed[now] = true;
        ans++;
        now = a[now];
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))

cnt = [False] * 8
free = 0

for a in A:
  c = a // 400
  if c >= 8:
    free += 1
  else:
    cnt[c] = True

max_c = sum(cnt) + free
if sum(cnt) != 0:
  min_c = sum(cnt)
else:
  min_c = 1

print(min_c, max_c)


Measured memory_bytes: 61800
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int>> matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=3e3+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};
pii a[maxn];
int dp[maxn];
int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,t;
    cin>>n>>t;
    for(int i=1;i<=n;i++){
        cin>>a[i].F>>a[i].S;
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        for(int j=t-1;j>=0;j--){
            dp[min(j+a[i].F,t+1)]=max(dp[j]+a[i].S,dp[min(t+1,j+a[i].F)]);
        }
    }
    int mx=0;
    for(int i=1;i<=t+1;i++){
        mx=max(mx,dp[i]);
    }
    cout<<mx;
	exit(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;

struct UnionFind
{
    int n;
    vector<int> parent;
    vector<int> rank;
    UnionFind(int _n) :n(_n)
    {
        parent.assign(n, -1);
        rank.assign(n, 1);
    }

    int find(int i)
    {
        if (parent[i] == -1)
            return i;
        else
            return parent[i] = find(parent[i]);
    }

    void unite(int i, int j)
    {
        i = find(i);
        j = find(j);

        if (i == j) return;

        if (rank[i] == rank[j])
        {
            parent[j] = i;
            ++rank[i];
        }
        else
        {
            if (rank[i] < rank[j]) swap(i, j);
            parent[j] = i;
        }
    }

    bool is_same(int i, int j)
    {
        return find(i) == find(j);
    }
};


int main()
{
    int n;
    cin >> n;
    vector<pii> x, y;
    rep(i, 0, n) 
    {
        int xx, yy;
        cin >> xx >> yy;
        x.emplace_back(xx, i);
        y.emplace_back(yy, i);
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    
    vector<tiii> edges;
    rep(i, 0, n - 1)
    {
        int cost;
        cost = abs(x[i].first - x[i + 1].first);
        edges.push_back(make_tuple(cost, x[i].second, x[i + 1].second));

        cost = abs(y[i].first - y[i + 1].first);
        edges.push_back(make_tuple(cost, y[i].second, y[i + 1].second));
    }

    sort(edges.begin(), edges.end());
    UnionFind uf(n);
    ll ans = 0;
    for (auto edge: edges)
    {
        int cost, i, j;
        tie(cost, i, j) = edge;

        if (uf.is_same(i, j)) continue;

        ans += (ll) cost;
        uf.unite(i, j);
    }

    cout << ans << endl;

    return 0;
}

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

LL k,maxx=9;

void bfs(){
	queue<pair<LL,LL> > q;
	q.push(make_pair(1ll,1ll));
	q.push(make_pair(2ll,2ll));
	q.push(make_pair(3ll,3ll));
    q.push(make_pair(4ll,4ll));
    q.push(make_pair(5ll,5ll));
    q.push(make_pair(6ll,6ll));
    q.push(make_pair(7ll,7ll));
    q.push(make_pair(8ll,8ll));
    q.push(make_pair(9ll,9ll));
    while(!q.empty()){
    	LL djl=q.front().first;
		LL nums=q.front().second;
    	q.pop();
    	if (nums==k){
    		cout<<djl<<endl;
    		exit(0);
		}
    	if ((djl%10)-1>-1){
    		maxx++;
			q.push(make_pair(djl*10+(djl%10)-1,maxx));
		} 
    	maxx++;
		q.push(make_pair(djl*10+(djl%10),maxx));
		if ((djl%10)+1<10){
    		maxx++;
			q.push(make_pair(djl*10+(djl%10)+1,maxx));
		} 
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin>>k;
	bfs();
	return 0;
} 

Measured memory_bytes: 6740
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;

int main() {
  // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  long double a, b;
  cin >> a >> b;
  // long long bb = b * 100.0;
  cout << (long long)(a * b + 0.001) << endl;

  return 0;
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
        int n;
        cin>>n;
        string s;
        cin>>s;
        for(int i=0;i<s.size();i++)
        {
            int k=s[i]-'A'+n;
            //cout<<k<<endl;
            if(k>25)
            {
                int r=k%26;
                //cout<<"R"<<r<<endl;
                cout<<char('A'+r);
            }
            else
            cout<<char('A'+k);
        }
}


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

int main(){
  string S,T;
  cin >> S >> T;
  int n=T.size();
  bool exist=false;
  if(S.size()<T.size()){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for(int i=S.size()-1;i>=n-1;i--){
    if(exist){
      if(S.at(i)=='?'){
        S.at(i)='a';
      }
    }else{
      if(S.at(i)=='?'){
        bool flag=true;
        for(int j=0;j<n;j++){
          if(!((S.at(i-j)==T.at(n-1-j))||(S.at(i-j)=='?'))){
            flag=false;
            break;
          }
        }
        if(flag){
          S.replace(i-n+1,n,T);
          exist=true;
        }else{
          S.at(i)='a';
        }
      }else if(S.at(i)==T.at(n-1)){
        bool flag=true;
        for(int j=0;j<n;j++){
          if(!((S.at(i-j)==T.at(n-1-j))||(S.at(i-j)=='?'))){
            flag=false;
            break;
          }
        }
        if(flag){
          S.replace(i-n+1,n,T);
          exist=true;
        }
      }
    }
  }
  if(exist){
    for(int i=0;i<S.size();i++){
      if(S.at(i)=='?'){
        S.at(i)='a';
      }
    }
    cout << S << endl;
  }else{
    cout << "UNRESTORABLE" << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	ll N, A, B, c;
	cin >> N >> A >> B;
	if( A == 0) cout << 0;
	else if(B == 0) cout << N;
	else{
		c = (N % (A + B)) - A;
		cout << (N/(A+B))*A + (c>0? A:A+c);
	}
			
}


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

int maxof(const int a[]) {
	int i;
	int max = a[0];

	for (i = 1; i < 8; i++) {
		if (a[i] > max) max = a[i];
	}
	return max;
}

int main() {
	int a, b, c, d, e, f;
	int r1, r2, r3,r4,r5, r6, r7, r8;
	cin >> a >> b >> c >> d >> e >> f;
	r1 = a + b + c + e;
	r2 = a + b + c + f;
	r3 = a + b + d + e;
	r4 = a + b + d + f;
	r5 = a + c + d + e;
	r6 = a + c + d + f;
	r7 = b + c + d + e;
	r8 = b + c + d + f;
	int ar[] = { r1, r2, r3,r4,r5, r6, r7, r8 };
	cout << maxof(ar) << endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <deque>

using namespace std;

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

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

	int t = (x - a) / b;
	int ans = x - a - b * t;

	cout << ans << endl;
}

Measured memory_bytes: 256
import kotlin.math.floor

fun main(){
    val (a, b, n) = readLine()!!.split(" ").map { it.toLong() }
    var hikaku = 0.toLong()
    if (n >= b) hikaku = b - 1
    else hikaku = n
    var x = hikaku * a / b
    println(x)

}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> Array;
typedef vector<Array> Graph;
typedef pair<double, double> pdd;
const ull mod = 1000000000 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    int N, W;
    cin >> N >> W;
    int N_MAX = 110;
    int W_MAX = 10010;
    int v[N_MAX];
    int w[N_MAX];
    REP(i, N){
        cin >> v[i] >> w[i];
    }
    int DP[N_MAX][W_MAX];
    REP(i, N){
        REP(j, W+1){
            if(j<w[i]){
                DP[i+1][j] = DP[i][j];
            }else{
                DP[i+1][j] = max(DP[i][j], DP[i][j-w[i]] + v[i]);
            }
        }
    }
    cout << DP[N][W] << endl;
    return 0;
}

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


int main(){
	for(int n;cin>>n,n;){
		string s;cin>>s;
		int h[10]={0};
		int b=0;
		for(int i=0,j=0;i<s.size();i++){
			
			if(s[i]=='M')h[j]++;
			if(s[i]=='S'){
				b++;
				b+=h[j];
				h[j]=0;
			}
			if(s[i]=='L'){
				b++;
				h[j]+=b;
				b=0;
			}
			
			j++;
			if(n==j)j=0;
			
		}
		for(int i=0;i<=n;i++){
			for(int j=1;j<n;j++){
				if(h[j-1]>h[j])swap(h[j-1],h[j]);
			}
		}
		for(int k=0;k<n;k++){
			cout<<h[k]<<" ";
		}
		cout<<b<<endl;
	}
	return 0;
}


Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    int c[101][101],x[N],y[N],h[N];
    for(int i=0;i<N;i++){
        cin>>x[i]>>y[i]>>h[i];
    }
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            bool flag=true;
            int H=1;
            for(int g=0;g<N;g++){
                if(h[g]==0)continue;
                else{
                    H=h[g]+abs(x[g]-j)+abs(y[g]-i);
                    break;
                }
            }
            for(int g=0;g<N;g++){
                if(max(H-abs(x[g]-j)-abs(y[g]-i),0)!=h[g]){
                    flag=false;
                    break;
                }
            }
            if(flag){
                cout<<j<<" "<<i<<" "<<H<<endl;
            }
        }
    }
}


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

using namespace std;

#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define ll long long
#define ull unsigned ll
#define sz(x)          (int)((x).size())

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


typedef pair<int, int> pii;
#define inf 10e9
const int N = (int) 2e5 + 7;


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

    int ans = INT_MIN, c = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'A' || s[i]== 'C' || s[i] == 'G' || s[i] == 'T')
            c++;
        else c = 0;
        ans = max(ans, c);
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
use proconio::{input, marker::Usize1};

fn main() {
    input!(n: usize, friendship: [(Usize1, Usize1)]);

    let mut uf = UnionFind::new(n);
    for (a, b) in friendship {
        uf.unite(a, b);
    }
    let ans = (0..n).map(|i| uf.size(i)).max().unwrap();

    println!("{}", ans);
}

struct UnionFind(Vec<isize>);
impl UnionFind {
    fn new(size: usize) -> Self { Self(vec![-1; size]) }
    fn unite(&mut self, a: usize, b: usize) -> usize {
        let (mut x, mut y) = (self.find(a), self.find(b));
        if x == y {
            return x;
        }
        if -self.0[x] < -self.0[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.0[x] += self.0[y];
        self.0[y] = x as isize;
        x
    }
    fn find(&mut self, a: usize) -> usize {
        if self.0[a] < 0 {
            return a;
        }
        self.0[a] = self.find(self.0[a] as usize) as isize;
        self.0[a] as usize
    }
    fn size(&mut self, a: usize) -> usize {
        let x = self.find(a);
        -self.0[x] as usize
    }
}


Measured memory_bytes: 9244
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k;
        int x;
        k=sc.nextInt();
        x=sc.nextInt();
        if(k*500>=x){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23636
def na(): return map(int, input().split())
n, m = na()
edges = [[False for _ in range(n)] for _ in range(n)]
for i in range(m):
    a, b = na()
    a -= 1
    b -= 1
    edges[a][b] = True
    edges[b][a] = True

pathes = {'0'}#permutationで求めたpath
for i in range(n-1):
    buf = set()
    for pre_path in pathes:
        for v in map(str, range(1, n)):
            if not(v in pre_path):
                buf.add(pre_path + v)
    pathes = buf.copy()
##print(pathes)
##print(edges)

ans = 0
for path in pathes:
    flg = True
    for i in range(1, n):
        a, b = map(int, [path[i-1], path[i]])
##        print(a, b, edges[a][b])
        if not edges[a][b]:
            flg = False
            break
    if flg:
        ans += 1
print(ans)

Measured memory_bytes: 4284
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d[10];
  for(int i=0;i<10;++i){
    cin>>d[i];
  }
  sort(d,d+10,greater<int>());
   for(int i=0;i<3;++i){
     cout<<d[i]<<endl;
  }
  return 0;
}



Measured memory_bytes: 3148
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

bool isPrime[1000000];
int main()
{
	fill(isPrime, isPrime+1000000, true);
	for (int i = 2; i < 1000; ++i)
	{
		if (isPrime[i])
		{
			for (int j = 2*i; j < 1000000; j += i)
				isPrime[j] = false;
		}
	}

	int n;
	while (scanf("%d", &n), n)
	{
		int ans = 0;
		for (int i = 3; i <= n/2; ++i)
			if (isPrime[i] && isPrime[n-i])
				++ans;
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		
		
		
		while(true){
			int n = Integer.parseInt(scan.nextLine());
			if(n == 0) break;
			String str = scan.nextLine();
			String[] points = str.split(" ");
			
			double m = 0.0;
			for (int i = 0; i < n; i++) {
				m += Integer.parseInt(points[i]);
			}
			m /= n;
			
			double num = 0.0;
			for (int i = 0; i < n; i++) {
				num += Math.pow((Integer.parseInt(points[i]) - m ), 2);
			}
			
			System.out.printf("%.8f\n", (Math.sqrt(num / n)));
			
		}
				
	}
}

Measured memory_bytes: 21132
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int  main(){
 int a,b;
 cin >> a>> b;
 if(a>b){
   rep(i,a){
   cout << b;
   }
   cout << endl;
 }else{
   rep(i,b){
   cout << a;
 }
 cout << endl;
 }
 return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *

N, K = MAP()

if K == 0:
	print(N*N)
	exit()

ans = 0

for b in range(K+1, N+1):
	p = N//b
	ans += p * (b-K) + max(0, N%b-K+1)
	#print(b, ans)

print(ans)


Measured memory_bytes: 10424
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <numeric>
#include <queue>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef vector<vector<char>> field_t;
typedef unsigned long long ull;
typedef pair<ll, ll> point_t;

int main()
{
    
    string S;
    ll N,ans,cnt;
    ll re,gr;
    re=0;
    gr=0;
    ans=0;
    cnt=0;
    cin >> N;
    vector<int> r,g;
    map<int,int> mp;
    cin >> S;
    rep(i,N){
        if(S[i]=='R'){
            r.push_back(i);
            re++;
        }else{
            if(S[i]=='G'){
                g.push_back(i);
                gr++;
            }else{
                mp[i]=1;
                cnt++;
            }
        }
    }
    ans+=gr*re*cnt;
    for(int j=0;j<re;j++){
        for(int k=0;k<gr;k++){
            int dy=abs(r[j]-g[k]);
            int ma=max(r[j],g[k]);
            int sum=r[j]+g[k];
            if(mp[ma+dy]){
                ans--;
            }
            int mi=min(r[j],g[k]);
            if(mp[mi-dy]){
                ans--;
            }
            if((sum%2==0)&&mp[sum/2]){
                ans--;
            }
        }
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 4180
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    s = input()
    t = input()

    ans = 0
    for i in range(3):
        if s[i] == t[i]:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}
int main() {
  int N; cin >> N;
  vector<LL> A(N + 2);

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

  LL sum = 0;
  for (int i = 1; i <= N + 1; ++i) {
    sum += abs(A[i]-A[i-1]);
  }

  for (int i = 0; i < N; ++i) {
    LL d1 = abs(A[i + 2] - A[i + 1]) + abs(A[i + 1]-A[i]);
    LL d2 = abs(A[i + 2] - A[i]);
    cout << sum - d1 + d2 << endl;
  }
}


Measured memory_bytes: 3924
// Last Change: 08/04/2019 21:01:52.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll A, B, C;
  cin >> A >> B >> C;
  cout << max(0ll, C - A + B) << endl;
}


Measured memory_bytes: 888
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.stream.Stream;
import java.util.Collection;
import java.util.Scanner;
import java.util.Optional;
import java.util.Comparator;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long N = in.nextLong();
            long A = in.nextLong();
            long B = in.nextLong();
            long C = in.nextLong();
            long D = in.nextLong();
            long E = in.nextLong();

            long min = Arrays.asList(A, B, C, D, E).stream().min(Comparator.naturalOrder()).get();
            // out.println(4L + (long)Math.ceil((double)N / min));
            out.println(4L + (N + (min - 1L)) / min);
        }

    }
}



Measured memory_bytes: 28756
#include<bits/stdc++.h>
using namespace std;
 
int micos(int n ,vector<int>&height)
{
     vector<int>dp(n,0);
     for(int i =1;i<n;i++)
     {    if(i==1)dp[i] = dp[i-1]+abs(height[i]-height[i-1]);
       else
       dp[i] = min(dp[i-1]+abs(height[i]-height[i-1]),dp[i-2]+abs(height[i]-height[i-2]));
     }
    return dp[n-1];
}
int main(){
    int n ;
  cin>>n;
  vector<int>height(n);
  for(int i=0;i<n;i++)
  {  cin>>height[i];
  }
  cout<<micos(n,height)<<endl;
  
  return 0;
}

Measured memory_bytes: 1024
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e5+5;
typedef long long ll;
int d[N],n;ll c[N],res,sum;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d%lld",&d[i],&c[i]),sum+=c[i],res+=d[i]*c[i];
	printf("%lld\n",(res-1)/9+sum-1);
	return 0;
}

Measured memory_bytes: 2560
b = input().strip()
x = ""
for i in range(len(b)):
    if b[i]=="A":
        x += "T"
    elif b[i]=="T":
        x += "A"
    elif b[i]=="C":
        x += "G"
    elif b[i]=="G":
        x += "C"
print(x)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  string s;
  cin >> s;

  string t = s;
  reverse(t.begin(), t.end());
  if(s == t) {
    int x = (s.size() - 1) / 2;
    rep(i, x) {
      if(s[i] != t[x - i - 1]) {
        cout << "No";
        return 0;
      }
    }
    cout << "Yes";
    return 0;
  }
  cout << "No";
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

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

	std::cout << a - b + 1 << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define endl "\n"
#define INT long long int
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n,t,k;
    cin >> n >> t >> k;
    cout << (n+t-1)/t*k <<endl;
}



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

using namespace std;


struct MCMF {
    using F = int; const static F INF = 0x3f3f3f3f;
    // using F = long long; const static F INF = 0x3f3f3f3f3f3f3f3f;
    struct Edge {
        int v, bro;
        F cap, cost;
        Edge() {}
        Edge(int _v, int _bro, F _cap, F _cost) : v(_v), bro(_bro), cap(_cap), cost(_cost) {}
    };
    vector<Edge> e;
    vector<int> pos, pre;
    vector<F> dis;
    vector<bool> trk;
    int n, s, t, m;
    MCMF(int _n, int _s, int _t) : n(_n), s(_s), t(_t), m(0) {
        pos.assign(n, -1);
        pre.resize(n);
        dis.resize(n);
        trk.resize(n);
        e.reserve(4e5);
    }
    void add(int u, int v, F cap = INF, F cost = 0) {
        assert(u < n && v < n);
        e.emplace_back(v, pos[u], cap, cost); pos[u] = m++;
        e.emplace_back(u, pos[v], 0, -cost);  pos[v] = m++;
    }
    bool spfa() {
        queue<int> q;
        fill(pre.begin(), pre.end(), -1);
        fill(dis.begin(), dis.end(), INF);
        fill(trk.begin(), trk.end(), false);
        dis[s] = 0; trk[s] = true; q.push(s);
        while(!q.empty()){
            int u = q.front(); q.pop(); trk[u] = false;
            for (int i = pos[u]; i != -1; i = e[i].bro){
                int v = e[i].v;
                if (e[i].cap > 0 && dis[v] > dis[u] + e[i].cost){
                    dis[v] = dis[u] + e[i].cost;
                    pre[v] = i;
                    if (!trk[v]){
                        trk[v] = true; q.push(v);
                    }
                }
            }
        }
        return pre[t] != -1;
    }
    pair<F,F> mcmf() {
        F flow = 0, cost = 0;
        while (spfa()) {  // (dijkstra()) {
            F f = INF;
            for (int i = pre[t]; i != -1; i = pre[e[i^1].v])
                f = min(f, e[i].cap);
            for (int i = pre[t]; i != -1; i = pre[e[i^1].v]){
                e[i].cap -= f;
                e[i^1].cap += f;
                cost += e[i].cost * f;
            }
            flow += f;
        }
        return {flow, cost};
    }
};
void solve() {
    int n, m;
    cin >> n >> m;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    pair<int, int> Sp, Tp;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i][j] == 'S') Sp = {i,j};
            if (s[i][j] == 'T') Tp = {i,j};
        }
    }
    if (Sp.first == Tp.first || Sp.second == Tp.second) {
        cout << -1; return;
    }

    int S = n+m, T = S+1;
    MCMF mc(T+1, S, T);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i][j] == 'o') {
                mc.add(i, n+j, 1, 0);
                mc.add(n+j, i, 1, 0);
            }
            if (s[i][j] == 'S') {
                mc.add(S, i);
                mc.add(S, n+j);
            }
            if (s[i][j] == 'T') {
                mc.add(i, T);
                mc.add(n+j, T);
            }
        }
    }
    cout << mc.mcmf().first;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  if (s.at(2) == s.at(3))
  {
    if (s.at(4) == s.at(5))
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
n=int(input())
x=[int(x) for x in input().split()]
big=max(x)
small=min(x)
ans=10000000000000000
for i in range(small,big+1):
  samu=0
  for j in range(len(x)):
    samu+=(x[j]-i)*(x[j]-i)
  if samu<=ans:
    ans=samu
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<vector>
#include<set>
#define For(i,j,k)  for(int i=j;i<=k;++i)
#define Dow(i,j,k)  for(int i=k;i>=j;--i)
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const int INF = 0x7fffffff;
const int maxn = 1e5 + 10;
int pre[maxn];
int num[maxn];
int n,m;
int a[maxn];
vector<int>s[maxn];
void init()
{
    for(int i=1; i<=n; i++)
    {
        num[i]=1;
        pre[i]=i;
    }
}
int find(int x)
{
    int r=x;
    while(r!=pre[r])
        r=pre[r];
    int i=x,j;
    while(i!=r)
    {
        j=pre[i];
        pre[i]=r;
        i=j;
    }
    return r;
}
void merge(int x,int y)
{
    int fx=find(x);
    int fy=find(y);
    if(fx!=fy)
    {
        num[fy]+=num[fx];
        pre[fx]=fy;
    }
}
int main()
{
    int ans=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
        init();
        int max=0;
        while(m--)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            s[x].push_back(y);
            s[y].push_back(x);
        }
        for(int i=1;i<=n;i++)
        {
            for(auto t:s[i])
                merge(i,t);
        }
        int max1=0;
        for(int i=1; i<=n; i++) 
           { 
               if(find(a[i])==find(i))
                ans++;
            }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6912
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n; cin >> n;
	int ans = 0;
	int mx = -1;
	int now;
	for (int i = 0; i < n; i++) {
		cin >> now;
		if (now >=mx)ans++;
		mx = max(mx, now);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long K = sc.nextLong();
    long A = sc.nextLong();
    long B = sc.nextLong();
    if(B - A <= 2){
      System.out.println(K + 1);
    }else{
      K -= A - 1;
      long ans = K / 2 * (B - A) + (K % 2) + A;
      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, A, B;
  cin>>N>>A>>B;
  vector<char> vec(N);
  for(int i=0; i<N; i++){
    cin>>vec.at(i);
  }
  int apass=0;
  int bpass=0;
  for(int i=0; i<N; i++){
    if(vec.at(i)=='a'){
      if(apass<A+B&&apass+bpass<A+B){
        cout<<"Yes"<<endl;
        apass++;
      }
      else{
        cout<<"No"<<endl;
      }
    }
    else if(vec.at(i)=='b'){
      if((bpass<B)&&(apass+bpass<A+B)){
        cout<<"Yes"<<endl;
        bpass++;
      }
      else{
        cout<<"No"<<endl;
      }
    }
    else{
      cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 3712
using System;
using System.Collections.Generic;

namespace MyProgram{
    class AtCoder{
        static void Main(){
            int N = int.Parse(Console.ReadLine());
            long[] X = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            long[] A = new long[N];
            for(var i=0;i<N;i++){
                A[i] = X[i];
            } 
            Array.Sort(A);
            long med_1 = A[A.Length/2-1];
            long med_2 = A[A.Length/2];
            for(var i=0;i<N;i++){
                if(X[i]<=med_1){
                    Console.WriteLine(med_2);
                }else{
                    Console.WriteLine(med_1);
                }
            }
            return;
        }
    } 
}

Measured memory_bytes: 35932
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e3+10;
int dp[N][N][5];
int a[N][N];
int n,m;
int go(int i,int j,int last)
{
	if(i==n&&j==m)
	{
		if(last==3)
			return 0;
		return a[i][j];
	}
	int &ans=dp[i][j][last];
	if(ans!=-1)
		return ans;
	ans=0;
	if(a[i][j]>0)
	{
		if(last>=3)
		{
			if(i+1<=n)
			{
				ans=max(ans,go(i+1,j,0));
			}
			if(j+1<=m)
			{
				ans=max(ans,go(i,j+1,last));
			}
		}
		else
		{
			if(i+1<=n)
			{
				ans=max(ans,a[i][j]+go(i+1,j,0));

			}
			if(j+1<=m)
			{
				ans=max(ans,a[i][j]+go(i,j+1,last+1));
			}
		}
	}
			if(i+1<=n)
			{
				ans=max(ans,go(i+1,j,0));

			}
			if(j+1<=m)
			{
				ans=max(ans,go(i,j+1,last));
			}
	
	return ans;
}
int32_t main()
{
	IOS;
	int k;
	cin>>n>>m>>k;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=k;i++)
	{
		int x,y,z;
		cin>>x>>y>>z;
		a[x][y]=z;
	}
	cout<<go(1,1,0)<<endl;

}

Measured memory_bytes: 428512
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int i,j,k,name[1000],b[1000],c[1000],d[1000],e,f,g,h,kl[1000],n,ff;
	while(cin>>n&&n) {
		for(i=0;i<n;i++) {
			cin>>name[i]>>b[i]>>c[i]>>d[i];
			kl[i]=b[i]*4+c[i]*9+d[i]*4;
		}
		cin>>e>>f>>g>>h;
		ff=0;
		for(i=0;i<n;i++) {
			if(b[i]<=e&&c[i]<=f&&d[i]<=g&&kl[i]<=h) {
				cout<<name[i]<<endl;
				ff=1;
			}
		}
		if(ff==0) cout<<"NA"<<endl;
	}
}	

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  REP(i,N)REP(j,D) cin >> X[i][j];

  int ret = 0;
  REP(i,N)for(int j = i + 1; j < N; ++j) {
    int d2 = 0;
    REP(k,D) d2 += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
    int tmp = sqrt(d2);
    if(tmp * tmp == d2) ++ret;
  }

  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
void output(int *,int );
int main(){
  int i,j,n,han=1,hozon,cnt=0;
  scanf("%d",&n);
  int hai[n];
  for(i=0;i<n;i++)
    scanf("%d",&hai[i]);
  
  while(han){
    han=0;
    for(j=n-1;j>0;j--){
      if(hai[j]<hai[j-1]){
	hozon=hai[j-1];
	hai[j-1]=hai[j];
	hai[j]=hozon;
	han=1;
	cnt+=1;
      }
    }
  }
  output(hai,n);
  printf("%d\n",cnt);
  return 0;
}
void output(int *hai,int n){
  int i,j;
  for(i=0;i<n;i++){
    printf("%d",hai[i]);
    if(i==n-1) printf("\n");
    else printf(" ");
  }
  
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int N;
vector<pair<string,P>>vec(N);

int main() {
 
 
 cin >> N;
 

 repn(i,N){
   string S;
   int P;
   cin >> S >> P;
   vec.pb(mp(S,mp(-P,i)));
 }
  SORT(vec);
  rep(i,N)cout<<vec[i].sc.sc<<endl;

}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;

void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int n;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    cin >> n;
    cout << (ll) pow(n, 3);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin>>s;
    int a;
    for(int i=0;i<8;i++){
        a=s[0]-'0';
        for(int j=0;j<3;j++){
            if(i&(1<<j))a+=s[j+1]-'0';
            else a-=s[j+1]-'0';
        }
        if(a==7){
            for(int j=0;j<3;j++){
                cout<<s[j];
                if(i&(1<<j))cout<<'+';
                else cout<<'-';
            }
            cout<<s[3]<<'='<<7<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int k, p;
        cin >> k >> p;
        cout << (k-1)%p+1 << "\n";
    }
    return 0;
}


Measured memory_bytes: 3116
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	n <- readInt
	as <- readIntegers
	let
		s = sum as
		as' = scanl1 (+) as
	print $ minimum $ solve as' s 

solve [] _ = []
solve (a:as) s = abs ( a - ( s - a ) ) : solve as s

Measured memory_bytes: 27388
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int h, w;
    while(cin >> h >> w, h){
        vector<string> v(h);
        for (int i = 0; i < h; ++i) cin >> v[i];
        vector<vector<int>> visited(h, vector<int>(w, 0));
        [&](){
            int a = 0, b = 0;
            while(true){
                if(visited[a][b]){
                    puts("LOOP");
                    return;
                }
                visited[a][b] = 1;
                if(v[a][b] == '>') b++;
                else if(v[a][b] == '^') a--;
                else if(v[a][b] == '<') b--;
                else if(v[a][b] == 'v') a++;
                else break;
            }
            printf("%d %d\n", b, a);
        }();
    }
    return 0;
}


Measured memory_bytes: 3188