akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using vi = vector<ll>;
using vv = vector<vi>;
const ll INF = 1001001001001001;
const ll NUM = 1<<15;

//Baby-Step Giant-Step algorithm

ll powmod(ll a, ll n, ll k){
    ll rtn = 1LL;
    
    while(n>0){
        
        vector<ll> p(3,a);
        rep(i,3){
            rep(j,2){
                if(j<i) p[i] /= NUM;
                else    p[i] %= NUM;
            }
        }
        
        if(n&1LL){
            vector<ll> rtn_b(3);
            rep(i,3){
                rtn_b[i] = rtn * p[i] % k;
                rep(j,i)rtn_b[i] = rtn_b[i] * NUM % k;
            }
            
            rtn = 0;
            rep(i,3)rtn += rtn_b[i];
            rtn %= k;
        }
        
        vector<ll> a_b(3);
        rep(i,3){
            a_b[i] = a * p[i] % k;
            rep(j,i)a_b[i] = a_b[i] * NUM % k;
        }
        
        a = 0;
        rep(i,3)a += a_b[i];
        a %= k;
        
        n >>= 1;
    }
    
    return rtn;
}

ll prodmod(ll a, ll b, ll k){
    
    vector<ll> p(3,a);
    rep(i,3){
        rep(j,2){
            if(j<i) p[i] /= NUM;
            else    p[i] %= NUM;
        }
    }
    
    vector<ll> rtn_b(3);
    rep(i,3){
        rtn_b[i] = b * p[i] % k;
        rep(j,i)rtn_b[i] = rtn_b[i] * NUM % k;
    }
    
    ll rtn = 0;
    rep(i,3)rtn += rtn_b[i];
    rtn %= k;
    
    return rtn;
}


ll euler(ll k){
    ll rtn = k;
    
    for(ll i=2; i*i<=k; i++){
        if(k%i==0){
            rtn /= i;
            rtn *= i-1;
            while(k%i==0)
                k /= i;
        }
    }
    
    if(k!=1){
        rtn /= k;
        rtn *= k-1;
    }
    
    return rtn;
}

int main(){
    ll k; cin>>k;
    
    if(k%2==0 || k%5==0){
        cout<<-1<<endl;
        return 0;
    }
    
    if(k%7==0)k /= 7;
    k *= 9;
    
    ll m = sqrt(euler(k))/10 + 1;
    
    //ll m = sqrt(k) + 1;
    unordered_map<ll,int> mp;
    mp[1] = 0;
    
    ll a = 1LL;
    
    for(ll i=0; i<m; i++){
        a = a *10 %k;
        if(a==1){
            cout<<i+1<<endl;
            return 0;
        }
        mp[a] = i+1;
    }
    //Giant-Step
    // r = 10^(-m)
    // 10^-1 = b
    // 10b = 1 (mod k)
    // 10b = qk + 1 (q<10)
    // qk = 10b - 1
    // qk = 9 (mod 10)
    // k%10   q
    // 1   -> 9
    // 3   -> 3
    // 7   -> 7
    // 9   -> 1
    // r  = (k*q+1)/10
    
    ll q = ( 189/(k%10) ) % 10;
    ll r = powmod( (k*q+1)/10, m, k);
    
    ll b = 1;
    for(ll i=0; i<m*200; i++){
        b = prodmod(b, r, k);
        
        if(mp.count(b)){
            cout<< (i+1) * m + mp[b] <<endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string.h>
using namespace std;

int m[21][11024];
int n,s;

void dfs(int b,int d,int s){
    m[d][s]++;
    for(int i=0;i<10;i++)
        if((b>>i)&1)
            dfs(b-(1<<i),d+1,s+(1+d)*i);
}
int main(){
    memset(m,0,sizeof(m));
    dfs(1023,0,0);
    while(cin>>n>>s)
        cout<<m[n][s]<<endl;
}

Measured memory_bytes: 2068
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1; // Initialize result 
  
    // Update x if it is more than or 
    // equal to p 
    x = x % p;  
  
    while (y > 0) { 
        // If y is odd, multiply x with the result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	string s;cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='?'){
			cout<<'D';
		}
		else{
			cout<<s[i];
		}
	}
	cout<<endl;
}

Measured memory_bytes: 3744
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printde(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int a, b;
	cin >> a >> b;
	if(a > 8 || b > 8) cout << ":(" << endl;
	else cout << "Yay!" << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;
public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 26;
	static int MOD = 998244353;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		int maxN = 100010;
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt(), c = in.nextInt();
			long[][] imos = new long[c][2*maxN];
			for (int i = 0; i < n; i++) {
				int s = in.nextInt()*2, t = in.nextInt()*2, ci = in.nextInt()-1;
				imos[ci][s-1]++;
				imos[ci][t+1]--;
			}

			for (int i = 0; i < c; i++) {
				for (int j = 0; j < 2*maxN-1; j++) {
					imos[i][j+1] += imos[i][j];
				}
			}

			int ans = 0;
			for (int i = 0; i < 2*maxN; i++) {
				int tmp = 0;
				for (int j = 0; j < c; j++) {
					if (imos[j][i] > 0) tmp++;
				}
				ans = Math.max(ans, tmp);
			}

			out.println(ans);

		}
	}



	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}
}

Measured memory_bytes: 120040
#!/usr/bin/env python3
import sys


def solve(N: int):
    print(180*(N-2))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 14 11:19:14 2020

@author: ezwry
"""

n = int(input())
xy = [map(int, input().split()) for i in range(n)]
x, y = [list(i) for i in zip(*xy)]

"""
A,Bの場合
"""

maxab = x[0] + y[0]
minab = x[0] + y[0]

for i in range(n):
    xi = x[i]
    yi = y[i]
    mini = xi+yi
    maxi = xi+yi
    if mini < minab:
        minab = mini
    if maxi > maxab:
        maxab = maxi

maxatob = maxab - minab

"""
C,Dの場合
"""

maxcd = y[0]-x[0]
mincd = y[0]-x[0]

for j in range(n):
    maxj = y[j] - x[j]
    minj = y[j] - x[j]
    if maxj > maxcd:
        maxcd = maxj
    if minj < mincd:
        mincd = minj

maxctod = maxcd - mincd

majimax = max(maxatob, maxctod)
print(majimax)

Measured memory_bytes: 153416
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include <bits/stdc++.h> 
using namespace std;

  
int MinimumNumIncreasingSubsequences(int arr[], int n) 
{ 
    multiset<int> last; 
  
    // last element in each  increasing subsequence  
    // found so far 
    for (int i = 0; i < n; i++) { 
  
        // here our current element is arr[i] 
        multiset<int>::iterator it = last.lower_bound(arr[i]); 
  
        // iterator to the first element larger  
        // than or equal to arr[i] 
        if (it == last.begin()) 
  
            // if all the elements in last larger 
            // than or to arr[i] then insert it into last 
            last.insert(arr[i]); 
  
        else { 
            it--; 
  
            // the largest element smaller than arr[i] is the number 
            // before *it which is it-- 
            last.erase(it); // erase the largest element smaller than arr[i] 
            last.insert(arr[i]); // and replace it with arr[i] 
        } 
    } 
    return last.size(); // our answer is the size of last 
} 
  
// Driver program 
int main() 
{ 
    int n,l;
    cin >> n;
    int p = 0;
    int arr[n];
    while(cin>>l){
        arr[p] = l;
        p++;
        if (p >= n) {
            break;
        }
    }

    cout << MinimumNumIncreasingSubsequences(arr, n); 
    return 0; 
} 

Measured memory_bytes: 5376
#include<queue>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;

const int N=200009;
const int M=400009;
const int md=1e9+7;

typedef long long ll;
typedef pair<ll,ll> pr;

int n,m,s,t,a[N],b[N];
ll c[N];
bool on[M<<1];
inline bool chkmin(ll &a,ll b){if(a>b){a=b;return 1;}return 0;}

struct graph
{
	int to[M<<1],nxt[M<<1],frm[M<<1],beg[N],tot;
	int id[N],deg[N];
	bool inq[N];
	ll f[N],dis[N],w[M<<1];

	inline void add(int u,int v,ll c)
	{
		to[++tot]=v;
		nxt[tot]=beg[u];
		frm[tot]=u;
		w[tot]=c;
		beg[u]=tot;
		++deg[v];
	}

	inline void spfa(int s)
	{
		queue<int> q;
		memset(dis,127,sizeof(dis));
		q.push(s);dis[s]=0;
		while(!q.empty())
		{
			int u=q.front();q.pop();inq[u]=0;
			for(int i=beg[u],v;i;i=nxt[i])
				if(dis[v=to[i]]>dis[u]+w[i])
				{
					dis[v]=dis[u]+w[i];
					if(!inq[v])inq[v]=1,q.push(v);
				}
		}
	}

	inline void dp(int s)
	{
		queue<int> q;
		q.push(s);f[s]=1;
		while(!q.empty())
		{
			int u=q.front();q.pop();
			for(int i=beg[u];i;i=nxt[i])
			{
				(f[to[i]]+=f[u])%=md;
				if(!(--deg[to[i]]))
					q.push(to[i]);
			}
		}
	}
}g1,g2,g3,g4;

inline ll sqr(ll a){return a*a%md;}

int main()
{
	if(fopen("vj.in","r"))
	{
		freopen("vj.in","r",stdin);
		freopen("vj.out","w",stdout);
	}

	scanf("%d%d%d%d",&n,&m,&s,&t);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%lld",&a[i],&b[i],&c[i]);c[i]%=md;
		g1.add(a[i],b[i],c[i]);g1.add(b[i],a[i],c[i]);
		g2.add(a[i],b[i],c[i]);g2.add(b[i],a[i],c[i]);
	}
	
	g1.spfa(s);g2.spfa(t);
	for(int i=1;i<=m;i++)
		if(g1.dis[a[i]]+c[i]+g2.dis[b[i]]==g1.dis[t])
		{
			g3.add(a[i],b[i],c[i]);on[i]=1;
			g4.add(b[i],a[i],c[i]);
		}
		else if(g1.dis[b[i]]+c[i]+g2.dis[a[i]]==g1.dis[t])
		{
			swap(a[i],b[i]);on[i]=1;
			g3.add(a[i],b[i],c[i]);
			g4.add(b[i],a[i],c[i]);
		}
	g3.dp(s);g4.dp(t);

	ll ans=sqr(g3.f[t]);
	for(int i=1;i<=m;i++)
		if(on[i] && g1.dis[a[i]]*2ll<g1.dis[t] && g2.dis[b[i]]*2ll<g1.dis[t])
			ans=(ans-sqr(g3.f[a[i]])*sqr(g4.f[b[i]])%md+md)%md;
	
	for(int i=1;i<=n;i++)
		if(g1.dis[i]*2ll==g1.dis[t])
			ans=(ans-sqr(g3.f[i])*sqr(g4.f[i])%md+md)%md;

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


Measured memory_bytes: 79920
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
int main() 
{
    long long n,res=INF;
    cin >> n;

    for(long long i=1;i*i<=n;i++){
      if(n%i ==0)
        res = min(res,i+n/i-2);
    }
  
  cout << res << endl;
        
}

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

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

  ll N, M; cin >> N >> M;
  ll X; cin >> X;
  vector<ll> C(N, 0);
  vector<vector<ll>> A(N, vector<ll>(M, 0));
  for (ll i = 0; i < N; i++) {
    cin >> C[i];
    for (ll j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  ll ans = 1e15;
  ll MAX = (1 << N);
  for (ll i = 0; i < MAX; i++) {
    vector<ll> check(M, 0);
    ll temp = 0;
    for (ll j = 0; j < N; j++) {
      if (i & (1 << j)) {
        temp += C[j];
        for (ll k = 0; k < M; k++) {
          check[k] += A[j][k];
        }
      }
    }
    bool ok = true;
    for (ll k = 0; k < M; k++) {
      if (check[k] < X) ok = false;
    }
    if (ok) ans = min(ans, temp);
  }

  if (ans == 1e15) ans = -1;
  cout << ans << '\n';
  return 0;
}

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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> X(N), Y(N), P(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> X[i] >> Y[i] >> P[i];
    }
    ll INF = 1LL<<60;
    vector<vector<ll>> xd(1<<N,vector<ll>(N,INF));
    vector<vector<ll>> yd(1<<N,vector<ll>(N,INF));
    for ( int b = 0; b < 1<<N; b++ ) {
        for ( int i = 0; i < N; i++ ) {
            xd[b][i] = min(xd[b][i], abs(X[i])*P[i]);
            yd[b][i] = min(yd[b][i], abs(Y[i])*P[i]);
            for ( int ii = 0; ii < N; ii++ ) {
                if ( (b >> ii) & 1 ) {
                    xd[b][i] = min(xd[b][i], abs(X[i]-X[ii])*P[i]);
                    yd[b][i] = min(yd[b][i], abs(Y[i]-Y[ii])*P[i]);
                }
            }
        }
    }

    vector<ll> ans(N+1,INF);
    for ( int i = 0; i < 1<<N; i++ ) {
        int m = ((1<<N) - 1)^i;
        for ( int j = m; ; j=((j-1)&m) ) {
            ll s = 0;
            for ( int k = 0; k < N; k++ ) {
                s += min(xd[i][k],yd[j][k]);
            }
            int b = __builtin_popcount(i) + __builtin_popcount(j);
            ans[b] = min(ans[b], s);
            if ( j == 0 ) break;
        }
    }

    for ( int k = 0; k <= N; k++ ) {
        cout << ans[k] << "\n";
    }
    return 0;
}

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

Measured memory_bytes: 13016
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	long long x;
	vector<long long> prime;

	scanf("%lld", &x);

	if (x == 2)
	{
		printf("2\n");

		return 0;
	}

	prime.push_back(2);

	for (long long i = 3; i < x; i++)
	{
		bool isprime = true;

		for (int j = 0; j < prime.size() && prime[j] * prime[j] <= i; j++)
		{
			if (!(i%prime[j]))
			{
				isprime = false;

				break;
			}
		}

		if (isprime)
		{
			prime.push_back(i);
		}
	}

	for (long long i = x;; i++)
	{
		bool isprime = true;

		for (int j = 0; j < prime.size() && prime[j] * prime[j] <= i; j++)
		{
			if (!(i%prime[j]))
			{
				isprime = false;

				break;
			}
		}

		if (isprime)
		{
			printf("%lld\n", i);

			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= M; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}

long long int N, M, K, Q, W, H;
long long int ans;

int main() {
	ios::sync_with_stdio(false);
	string s[1000];
	cin >> N >> K;
	for (int i = 0; i < N; i++)cin >> s[i];
	sort(s, s + N);
	for (int i = 0; i < N; i++)cout << s[i];
	cout << 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;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int a;
    cin >> a;
    cout << a+a*a+a*a*a << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<char> transform(256);
        for(int i=0; i<256; ++i)
            transform[i] = i;

        for(int i=0; i<n; ++i){
            char a, b;
            cin >> a >> b;
            transform[a] = b;
        }

        int m;
        cin >> m;
        for(int i=0; i<m; ++i){
            char c;
            cin >> c;
            cout << transform[c];
        }
        cout << endl;
    }
}

Measured memory_bytes: 896
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        int[] score = new int[n];
        for (int i = 0; i < q; i++) {
            score[sc.nextInt() - 1]++;
        }

        for (int i = 0; i < n; i++) {
            if (score[i] + (k - q) <= 0){
                System.out.println("No");
            } else{
                System.out.println("Yes");
            }
        }
    }
}


Measured memory_bytes: 78632
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		char[] pm = new char[4];
		int ans = 0;

		for(int i=0; i<4; i++) {
			pm[i] = S.charAt(i);
			if(pm[i] == '+') {
				ans += 1;
			}else {
				ans -= 1;
			}
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 21460
N, M = map(int, input().split())
X = []
Y = []
for _ in range(M):
    X.append(list(map(int, input().split())))
    
    tmp = 0
    for i in list(map(int, input().split())):
        tmp += 2 ** (i - 1)
    Y.append(tmp)

inf = 10 ** 9 + 7
dp = [[inf] * (2 ** N) for _ in range(M + 1)]
dp[0][0] = 0
for i in range(M):
    for j in range(2 ** N):
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
        dp[i + 1][j | Y[i]] = min(dp[i + 1][j | Y[i]],
                                  dp[i][j] + X[i][0])

ans = min(dp[i][-1] for i in range(M + 1))
print(ans if ans < inf else -1)



Measured memory_bytes: 108600
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	monsters := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		monsters[i] = a
	}

	a := monsters[0]
	for _, b := range monsters[1:] {
		a = gcd(a, b)
	}

	fmt.Println(a)
}

func gcd(x, y int) int {
	for y != 0 {
		z := x % y
		x, y = y, z
	}
	return x
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
bool cmp(char a,char b)
{
	return a>b;
}
int main()
{
	string s,t;
	cin>>s>>t;
	if(s<t)
		cout<<"Yes"<<endl;
	else if(s==t)
		cout<<"No"<<endl;
	else
	{
		sort(s.begin(),s.end());
		sort(t.begin(),t.end(),cmp);
		if(s<t)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    S, T = input().rstrip().split()
    A, B = iim()
    U = input().rstrip()

    if S == U:
        A -= 1
    else:
        B -= 1
    print(A, B)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 2940
#include<stdio.h>

int main(){
	int r,c,temp=0;
	int L[105][105]={0};
	scanf("%d%d",&r,&c);
	for(int i=0;i<r;++i)
		for(int j=0;j<c;++j){
			scanf("%d",&temp);
			L[i][j]=temp;
			L[100][j]+=temp,L[i][100]+=temp;}
	for(int i=0;i<r;++i)
		L[100][100]+=L[i][100];

	for(int i=0;i<r;++i){
		int j=0;
		while(j<c){
			printf("%d ",L[i][j]);
			++j;}
		printf("%d\n",L[i][100]);}
	for(int j=0;j<c;++j)
		printf("%d ",L[100][j]);
	printf("%d\n",L[100][100]);
	return 0;
}


Measured memory_bytes: 2032
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : " ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ';
constexpr char newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    t.pop_back();
    if (s == t) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

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

bool adj_matrix[8][8] = {false};
bool visit[8] = {false};
int ans = 0;
int N, M;

void DFS(int node)
{
    bool flag = true;
    for (int i = 0; i < N; i++)
    {
        if (!visit[i])
        {
            flag = false;
            break;
        }
    }
    if (flag)
    {
        ans++;
        return;
    }

    for (int i = 0; i < N; i++)
    {
        if (adj_matrix[node][i] && !visit[i])
        {
            visit[i] = true;
            DFS(i);
            visit[i] = false;
        }
    }

    return;
}

int main()
{

    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        adj_matrix[a - 1][b - 1] = true;
        adj_matrix[b - 1][a - 1] = true;
    }

    visit[0] = true;
    DFS(0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>
#include <utility>


#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int n;
	cin >> n;
	static vector<ll> a(n);

	REP(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());

	double mid_num = a[n - 1] / 2.0;
	int diff = mod;
	REP(i, n) {
		int new_diff = abs((int)(mid_num - a[i]));
		if (diff > new_diff) {
			diff = new_diff;
		}
		else {
			cout << a[n - 1] << " " << a[i - 1];
			break;
		}
	}

	system("pause");
	return 0;
}

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


int main()
{
	int n; cin >> n;
	switch (n%10)
	{
		case 3: cout << "bon" << endl; break;

		case 0:
		case 1:
		case 6:
		case 8: cout << "pon" << endl; break;
		default: cout << "hon" << endl; break;
	}
}



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

int N, L, Q;
int X[100005];

int dp[31][100005]; // dp[d][s] maximum travel given 2^d days and starting from s

int trial(int a, int x) { // maximum hotel starting from a with x days of travel
  int cur = a;
  for (int i = 30; i >= 0; i--) {
    if (x & (1 << i)) {
      cur = dp[i][cur];
    }
  }
  return cur;
}

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

  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> X[i];
  }
  cin >> L >> Q;

  for (int i = 1; i <= N; i++) {
    dp[0][i] = upper_bound(X + 1, X + N + 1, X[i] + L) - X - 1;
  }

  for (int j = 1; j < 31; j++) {
    for (int i = 1; i <= N; i++) {
      dp[j][i] = dp[j - 1][dp[j - 1][i]]; 
    }
  }

  for (int qi = 0; qi < Q; qi++) {
    int a, b;
    cin >> a >> b;
    if (a > b) {
      swap(a, b);
    }
    if (a == b) {
      cout << 0 << "\n";
      continue;
    }

    int lo = 1, hi = N;
    while (lo < hi) {
      int mid = (lo + hi) / 2;
      if (trial(a, mid) >= b) {
        hi = mid;
      } else {
        lo = mid + 1;
      }
    }

    cout << hi << "\n";
  } 

}


Measured memory_bytes: 13312
// C - Many Medians
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	vi X(N), Y(N);
	rpz(i, N) cin>>X[i];
	sort(all(Y = X));
	rpz(i, N) cout<< (X[i]<Y[N/2]? Y[N/2]: Y[N/2-1]) <<endl;
}

Measured memory_bytes: 3712
a,b = gets.chomp.split(" ")
button = [a.to_i, b.to_i]
sum = 0
2.times do |i|
        m = button.max
        indx = button.index(m)[0]
        button.delete_at(indx)
        sum += m
        button.push(m-1)
end
puts sum

Measured memory_bytes: 1788
#include <vector>
#include <map>
#include <iostream>
using namespace std;
typedef pair<
	pair<
		pair<int,int>,
		pair<int,int>
	>,string
>button;
typedef vector<button>buttonlist;

main(){
	int N,n,x1,y1,x2,y2,cur,i;
	string s,t;
	for(;cin>>N>>x1>>y1;){
		map<string,buttonlist>m;
		vector<string>visit;
		for(cur=-1;N;N--){
			buttonlist v;
			for(cin>>s>>n;n;n--){
				cin>>x1>>y1>>x2>>y2>>t;
				v.push_back(make_pair(make_pair(make_pair(x1,x2),make_pair(y1,y2)),t));
			}
			m[s]=v;
			if(cur==-1)visit.push_back(s),cur=0;
		}
		
		for(cin>>N;N;N--){
			cin>>s;
			if(s=="show")cout<<visit[cur]<<endl;
			if(s=="back"){if(cur>0)cur--;}
			if(s=="forward"){if(cur<visit.size()-1)cur++;}
			if(s=="click"){
				cin>>x1>>y1;
				s=visit[cur];
				buttonlist v=m[s];
				for(i=0;i<v.size();i++){
					if(
						v[i].first.first.first<=x1&&x1<=v[i].first.first.second &&
						v[i].first.second.first<=y1&&y1<=v[i].first.second.second
					){
						for(;cur<visit.size()-1;)visit.erase(visit.begin()+cur+1);
						visit.push_back(v[i].second);
						cur++;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        string s;
        in >> s;
        s[3] = '8';
        out << s << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


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

A.sort()

if A[0] == 0:
  print(0)
  exit()

ans = 1
for a in A[::-1]:
  ans *= a
  if ans > 10**18:
    print('-1')
    break
else:
  print(ans)


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

using namespace std;

int main(){
    int h, w, n, sr, sc; cin >> h >> w >> n >> sr >> sc;
    string s, t; cin >> s >> t;
    bool ans=true;
    int c_h, c_w;

    c_h=sr, c_w=sc;
    for(int i=0; i<n; ++i){
        if(s[i]=='U'){
            --c_h;
            if(c_h==0){
                ans=false;
                goto end;
            }
        }
        if(s[i]=='L'){
            --c_w;
            if(c_w==0){
                ans=false;
                goto end;
            }
        }
        if(t[i]=='D'){
            if(c_h<h) ++c_h;
        }
        if(t[i]=='R'){
            if(c_w<w) ++c_w;
        }
    }

    c_h=sr, c_w=sc;
    for(int i=0; i<n; ++i){
        if(s[i]=='D'){
            ++c_h;
            if(c_h==h+1){
                ans=false;
                goto end;
            }
        }
        if(s[i]=='R'){
            ++c_w;
            if(c_w==w+1){
                ans=false;
                goto end;
            }
        }
        if(t[i]=='U'){
            if(c_h>1) --c_h;
        }
        if(t[i]=='L'){
            if(c_w>1) --c_w;
        }
    }

end:
    cout << (ans ? "YES" : "NO") << endl;
    return 0;
}


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

namespace yukicode001
{
    class Program
    {
        static void Main()
        {
            double power = 1;
            double num = double.Parse(Console.ReadLine());
            
            for(int i = 1; i <= num; i++)
            {
                power = (power * i) % (Math.Pow(10, 9) + 7);
                
            }
            power = power % (Math.Pow(10, 9) + 7);

            Console.WriteLine(power);
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5+100;
ll a[maxn];
int main(){
	int n, k;
	cin >> k >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	a[n + 1] = k + a[1];
	n++;
	ll sum = 0, mx = 0;
	for (int i = 2; i <= n; i++){
		sum += a[i] - a[i - 1];
		mx = max(mx, a[i] - a[i - 1]);
	}
	sum -= mx;
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
int main(){
  long long n,a,b;cin>>n>>a>>b;
  vector<long long> A(n);
  long long mn = 0;
  long long mx = 0;
  for(int i = 0; n > i; i++){
    cin>>A[i];
    mx = max(mx,(A[i]-1)/b+1);
  }
  long long ce = (mx+mn)/2;
  while(mx-mn > 1){
    long long wan = 0;
    for(long long i = 0; n > i; i++){
      if(A[i]-(ce*b) > 0){
        wan += ((A[i]-(ce*b))-1)/(a-b)+1;
      }
    }
    if(wan > ce){
      mn = ce;
    }else{
      mx = ce;
    }
    ce = (mx+mn)/2;
  }
  cout << mx << endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			if (n == 1) {
				out.println("Hello World");
				return;
			}

			int a = in.nextInt(), b = in.nextInt();
			out.println(a + b);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21460
#include <iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  
  if(a==b){
    cout<<a*2;
    
  }
  
  else{
    int c=max(a,b);  
    cout<<c+c-1;
    
  }
  return 0;
}


Measured memory_bytes: 3156
#include <stdio.h>
#include <math.h>
int main(void){
  int i,n,tmp;
  double x1,x2,x3,y1,y2,y3,r,xp,yp;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
    xp=((y1-y3)*(y1*y1-y2*y2+x1*x1-x2*x2)-(y1-y2)*(y1*y1-y3*y3+x1*x1-x3*x3))/(2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3));
    yp=((x1-x3)*(x1*x1-x2*x2+y1*y1-y2*y2)-(x1-x2)*(x1*x1-x3*x3+y1*y1-y3*y3))/(2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3));
    r=sqrt((x3-xp)*(x3-xp)+(y3-yp)*(y3-yp));
    xp*=1000;
    yp*=1000;
    r*=1000;
    if(xp-(double)(int)xp<0.5){
      xp=(double)(int)xp;
    }else{
      xp=(double)(int)(xp+0.5);
    }
    if(yp-(double)(int)yp<0.5){
      yp=(double)(int)yp;
    }else{
      yp=(double)(int)(yp+0.5);
    }
    if(r-(double)(int)r<0.5){
      r=(double)(int)r;
    }else{
      r=(double)(int)(r+0.5);
    }
    printf("%1.3lf %1.3lf %1.3lf\n",xp/1000.0,yp/1000.0,r/1000.0);
  }
  return(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <string>

using namespace std;

int main(){
    int a[3];
    int sum = 0;
    cin >> a[0] >> a[1] >> a[2];
    for (int i = 0; i < 3; i++) {
        sum += a[i];
    }
    if (sum > 21) {
        cout << "bust";
    }
    else {
        cout << "win";
    }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+10;
int n,m,col[N],cnt[2],tot,flag; long long res;
vector<int> g[N];
inline void add(int a,int b){g[a].push_back(b),g[b].push_back(a);}
void dfs(int x,int co){
	col[x]=co; cnt[co]++;
	for(int to:g[x]){
		tot++;
		if(col[to]==-1)	dfs(to,co^1);
		else if(col[to]==co)	flag=1;
	}
}
signed main(){
	cin>>n>>m; memset(col,-1,sizeof col);
	for(int i=1,a,b;i<=m;i++)	scanf("%d %d",&a,&b),add(a,b);
	for(int i=1;i<=n;i++)	if(col[i]==-1){
		tot=cnt[0]=cnt[1]=flag=0; dfs(i,1); tot/=2;
		if(flag)	res+=1LL*(cnt[0]+cnt[1])*(cnt[0]+cnt[1]-1)/2-tot;
		else	res+=1LL*cnt[0]*cnt[1]-tot;
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 10388
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int i1 = sc.nextInt();

		int i2 = sc.nextInt();

		if (i1 * i2 % 2 == 0) {

			System.out.println("Even");

		} else {

			System.out.println("Odd");

		}

		sc.close();

	}
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const ll mod = 1000000007;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    ll X;
    cin >> X;
    ll ans = 0;
    ans += (X / 500) * 1000;
    ans += ((X % 500) / 5) * 5;
    cout << ans << endl;

}

Measured memory_bytes: 256
def judge(n, x)
	count = 0
	for a in 1..(x / 3 - 1)	# <=一番小さい数aの最大値は3で割った数から1引いたもの
		for b in (a + 1)..(n - 1) #bはaより大きくcより小さい
			c = x - a - b	
			
			if (c > b) && (c <= n)	#cがbより大きく、nを超えない場合
				count += 1
			end
		end
	end
	
return count
end

imput = gets.chomp.split("\s")
n, x = imput[0].to_i, imput[1].to_i

until (n == 0) && (x == 0)
	puts judge(n, x)
	imput = gets.chomp.split("\s")
	n, x = imput[0].to_i, imput[1].to_i
end

Measured memory_bytes: 6104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

char fi[2020][2020];
int cw[2020][2020],ch[2020][2020];

int main(){
    int h,w;
    cin>>h>>w;
    rep(i,h){
        rep(j,w){
            cin>>fi[i][j];
        }
    }

    rep(i,h){
        int cnt=1;
        rep(j,w){
            if(fi[i][j]=='.'){
                cw[i][j]=cnt;
                cnt++;
            }
            else{
                cnt=1;
            }
        }
        for(int j=w-2;j>=0;j--){
            if(fi[i][j]=='.' && fi[i][j+1]=='.'){
                cw[i][j]=cw[i][j+1];
            }
        }
    }

    rep(j,w){
        int cnt=1;
        rep(i,h){
            if(fi[i][j]=='.'){
                ch[i][j]=cnt;
                cnt++;
            }
            else{
                cnt=1;
            }
        }
        for(int i=h-2;i>=0;i--){
            if(fi[i][j]=='.' && fi[i+1][j]=='.'){
                ch[i][j]=ch[i+1][j];
            }
        }
    }

    int ans=0;
    rep(i,h){
        rep(j,w){
            if(fi[i][j]=='.') ans=max(ans,ch[i][j]+cw[i][j]-1);
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 39028
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		for(;;) {
			int N = sc.nextInt();
			if( N == 0 ) break;
			
			int a[] = new int[N];
			for(int i = 0; i < N; i++) a[i] = sc.nextInt();
			
			System.out.println( mss(a) );
		}
	}
	
	static int mss(int a[]) {
		int best = a[0];
		int tail = a[0];
		for(int i = 1; i < a.length; i++) {
			tail = Math.max(tail + a[i], a[i]);
			best = Math.max(best, tail);
		}
		return best;
	}

}

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

using namespace std;

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

  string s, t, u;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  cin >> u;
  cout << a - (s == u) << ' ' << b - (t == u);

  return 0;
}

Measured memory_bytes: 256
import std;

void main()
{
  const N = readln().chomp().to!long();
  
  ulong sum = 0;
  foreach (i; 1 .. N + 1)
  {
    if (i % 3 == 0) continue;
    if (i % 5 == 0) continue;
    sum += i;
  }
  
  writeln(sum);
}

Measured memory_bytes: 3600
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////


///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	int a, b;
	cin >> a >> b;
	if((a -(2*b)) > 0){
		cout << (a - (2*b)) << endl;
	}
	else cout << "0" << endl;




    
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
  string s;
  cin>>s;
  int i=0,c=0;
  while(i<n-2){
  	if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
    c++;
      i=i+2;
    }
    i++;
  }
  cout<<c<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <cstdio>
#include <bitset>
#include <map>


using namespace std;

typedef vector<int> Rooms;
typedef vector<Rooms> Floors;
typedef vector<Floors> Buildings;

int main()
{

    // vector<vector<vector<int> > > buildings(4, vector<vector<int> >(3, vector<int>(10)));
    Buildings buildings(4, Floors(3, Rooms(10)));

    int n;
    cin >> n;

    int b, f, r, v;
    while (n--)
    {
        cin >> b >> f >> r >> v;
        buildings[b-1][f-1][r-1] += v;
    }

    int i = 0;
    //every time using the index, it should be minused by 1
    while (i++ < 4)
    {
        int j = 0;
        while (j++ < 3)
        {
            int k = 0;
            while (k++ < 10)
            {
                cout << ' ' << buildings[i-1][j-1][k-1];
            }
            cout << endl;
        }
        cout << (i!=4? "####################\n": "");
    }
}


Measured memory_bytes: 3152
import java.util.*;
import java.io.*;
class Main{
    public static void main(String args[]){
	int i,j,k,n,q,count=0;
	int s[] = new int[1000000];
	int t[] = new int[1000000];
	Scanner scan = new Scanner(System.in);
	
	n = scan.nextInt();
	for(i=0;i<n;i++){
	    s[i] = scan.nextInt();
	}
	q = scan.nextInt();
	for(j=0;j<q;j++){
	    t[j] = scan.nextInt();
	}
	
	for(i=0;i<n;i++){
	    for(j=0;j<q;j++){
		if(s[i]==t[j]){
		    if(i!=0){
			for(k=i-1;k>=0;k--){
			    if(s[i]==s[k]){
				count--;
				break;
			    }
			}
		    }
		    count++;
		}
	    }
	}
	System.out.println(count);
    }
}



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

int val;
bool validmonth1;
bool validmonth2;

int main() {
	cin >> val;
	if (val % 100 == 0 || val % 100 > 12) {
		validmonth2 = false;
	}
	else {
		validmonth2 = true;
	}
	if ((val - (val % 100))/100 == 0 || (val - (val % 100))/100 > 12) {
		validmonth1 = false;
	}
	else {
		validmonth1 = true;
	}

	if (validmonth1 == true && validmonth2 == true) {
		cout << "AMBIGUOUS";
	}
	else if (validmonth1 == false && validmonth2 == false) {
		cout << "NA";
	}
	else if (validmonth1 == true && validmonth2 == false) {
		cout << "MMYY";
	}
	else if (validmonth1 == false && validmonth2 == true) {
		cout << "YYMM";
	}
}


Measured memory_bytes: 256
while True:
    try:
        s=raw_input()
    except EOFError:
        break
    flag=False
    a1=s.split("+")[0]
    a2,a3=s.split("+")[1].split("=")
    for i in range(10):
        t1,t2,t3=a1,a2,a3
        if len(t1)>=2 and t1[0]=="X" and i==0:
            continue
        if len(t2)>=2 and t2[0]=="X" and i==0:
            continue
        if len(t3)>=2 and t3[0]=="X" and i==0:
            continue
        t1=int(t1.replace("X",str(i)))
        t2=int(t2.replace("X",str(i)))
        t3=int(t3.replace("X",str(i)))
        if t1+t2==t3:
            print i
            flag=True
            break
    if flag==False:
        print "NA"

Measured memory_bytes: 4300
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  string n;
  cin >> n;
  cout << (n[0] == n[2] ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256