akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()

int a, b,c = 1;
string s[40];
int main() {
	REP(i, 20) REP(j, 100)s[i].push_back('#');
	FOR(i, 20, 40) REP(j, 100)s[i].push_back('.');
	cin >> a >> b;
	REP(i, 20) {
		REP(j, 100) {
			if (a > c and i % 2 == 0 and j % 2 == 0) {
				c++;
				s[i][j] = '.';
			}
		}
	}
	c = 1;
	FOR(i, 20, 40) {
		REP(j, 100) {
			if (b > c and i % 2 == 1 and j % 2 == 1) {
				c++;
				s[i][j] = '#';
			}
		}
	}
	cout << 40 << " " << 100 << endl;
	REP(i, 40) cout << s[i] << endl;
}

Measured memory_bytes: 256
/*
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<complex>
*/

#include<bits/stdc++.h>

#define X real()
#define Y imag()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define FastF freopen("in.txt","r",stdin); freopen("out.txt","w",stdout)
#define Fast cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0)
using ll = long long;
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vi::iterator vii;
typedef vector<ll> vl;
typedef vl::iterator vli;
typedef long double C;
typedef complex<C> P;
const int INF = 1e9 + 5;
const ll INFF = 1e18 + 5;
const int M = 1e9 + 7;
const double pi = acos(-1);
int dp[3001][3001];
string s, t, ans;
int LCS(int i, int j) {
	if (s[i] == '\0' || t[j] == '\0') return 0;
	if (dp[i][j] != -1) return dp[i][j];
	if (s[i] == t[j]) return dp[i][j] = 1 + LCS(i + 1, j + 1);
	else return dp[i][j] = max(LCS(i + 1,j), LCS(i,j + 1));
}
void printLCS(int i, int j) {
	if (s[i] == '\0' || t[j] == '\0') {
		cout << ans;
		return;
	}
	if (s[i] == t[j]) {
		ans += s[i];
		printLCS(i + 1, j + 1);
	}
	else {
		if (dp[i + 1][j] > dp[i][j + 1]) printLCS(i + 1, j);
		else printLCS(i, j + 1);
	}
}
int main()
{
	//FastF;
	Fast;
	memset(dp, -1, sizeof(dp));
	cin >> s >> t;
	LCS(0, 0);
	// << LCS(0, 0) << endl;
	printLCS(0, 0);
	return 0;
}

Measured memory_bytes: 35712
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
	string s;
	cin >> s;
	cout << s.substr(0, 3) << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

struct UnionFind{
    vector<ll> par;
    vector<ll> sizes;
    UnionFind(ll n) : par(n), sizes(n, 1) {
        rep(i,n) par[i] = i;
    }
    int find(ll x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }
    void unite(ll x, ll y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(ll x, ll y) {
        return find(x) == find(y);
    }

    ll size(ll x) {
        return sizes[find(x)];
    }
};

ll x[100010];
ll y[100010];
ll z[100010];

bool seen[100010];

int main(){
    int n, m;
    cin >> n >> m;
    rep(i, m) cin >> x[i] >> y[i] >> z[i];
    rep(i, m) x[i]--, y[i]--;

    UnionFind tree(n);
    int cnt = n;
    rep(i, m){
        if (!tree.same(x[i], y[i])) cnt--;
        tree.unite(x[i], y[i]);
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 4224
S=input()
N=len(S)-1
ans=0
if len(S)==1:
    print(S)
    exit()
for i in range(2**N):
    op=["-"]*N
    for j in range(N):
        if ((i>>j)&1):
            op[N-1-j]="+"
    #print(op)
    l=[]
    tmp=""
    for k in range(N):
        tmp=tmp+S[k]
        if k==(N-1):
            if op[k]=="+":
                l.append(tmp)
                l.append(S[-1])
            else:
                tmp=tmp+S[-1]
                l.append(tmp)
            break
        if op[k]=="+":
            l.append(tmp)
            tmp=""
        else:
            pass
    #print(l)
    for k in range(len(l)):
        val=int(l[k])
        ans+=val

print(ans)

Measured memory_bytes: 3064
n, m = map(int, input().split())
mod = 10**9+7

def fact(n, mod):
    ans = 1
    for i in range(2, n + 1):
        ans = ans * i
        ans = ans % mod

    return ans


if abs(n - m) >= 2:
    print(0)
elif abs(n - m) == 1:
    print(fact(n,mod)*fact(m,mod) % mod)
elif abs(n - m) == 0:
    print(2 * fact(n, mod)*fact(m, mod) % mod)


Measured memory_bytes: 9036
# https://atcoder.jp/contests/m-solutions2019/tasks/m_solutions2019_a

import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def main():
    N = int(input())
    print((N - 2) * 180)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
	ll n,ans=0,max=0,num;

	cin >> n;
	
	vecll a(n);

	forll(i, 0, n)
		cin >> a[i];

	vecll b = a;

	sort(b.begin(), b.end(), greater<ll>());

	forll(i, 0, n)
		if (a[i] == b[0])
			cout << b[1] << "\n";
		else
			cout << b[0] << "\n";
}

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

int n;

int maxSum(vector<int> &B) {
    int sum = B.at(0) + B.at(n - 2);
    for (int i = 0; i < n - 2; i++) {
        sum += min(B.at(i), B.at(i + 1));
    }

    return sum;
}

int main() {
    cin >> n;
    vector<int> B(n - 1);
    for (int i = 0; i < n - 1; i++) {
        cin >> B.at(i);
    }

    cout << maxSum(B) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> parent(vector<vector<int>> &E, int r){
	int N = E.size();
	vector<int> p(N, -1);
	queue<int> Q;
	Q.push(r);
	while (!Q.empty()){
		int v = Q.front();
		Q.pop();
		for (int w : E[v]){
			if (p[w] == -1){
				p[w] = v;
				Q.push(w);
			}
		}
	}
	return p;
}
vector<vector<int>> child(vector<int> &p, int r){
	int N = p.size();
	vector<vector<int>> c(N);
	for (int i = 0; i < N; i++){
		if (i != r){
			c[p[i]].push_back(i);
		}
	}
	return c;
}
long long add(long long A, long long B, long long MOD){
  return A * B % MOD;
}
long long root(long long A, long long MOD){
  return (A + 1) % MOD;
}
long long dfs1(vector<long long> &dp, vector<vector<int>> &c, int v, long long MOD){
  dp[v] = 1;
  for (int w : c[v]){
    dp[v] = add(dp[v], root(dfs1(dp, c, w, MOD), MOD), MOD);
  }
  return dp[v];
}
void dfs2(vector<long long> &dp1, vector<long long> &dp2, vector<vector<int>> &c, int v, long long MOD){
  int deg = c[v].size();
  vector<long long> L(deg + 1, 1);
  for (int i = 0; i < deg; i++){
    L[i + 1] = add(L[i], root(dp1[c[v][i]], MOD), MOD);
  }
  vector<long long> R(deg + 1, 1);
  for (int i = deg - 1; i >= 0; i--){
    R[i] = add(R[i + 1], root(dp1[c[v][i]], MOD), MOD);
  }
  for (int i = 0; i < deg; i++){
    //cout << "v=" << v << ", w=" << c[v][i] << endl;
    long long sum = add(L[i], R[i + 1], MOD);
    //cout << "sum=" << sum << endl;
    dp2[c[v][i]] = root(add(dp2[v], sum, MOD), MOD);
    dfs2(dp1, dp2, c, c[v][i], MOD);
  }
}
int main(){
  int N;
  long long M;
  cin >> N >> M;
  vector<vector<int>> E(N);
  for (int i = 0; i < N - 1; i++){
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    E[x].push_back(y);
    E[y].push_back(x);
  }
  vector<int> p = parent(E, 0);
  vector<vector<int>> c = child(p, 0);
  vector<long long> dp1(N, 1);
  dfs1(dp1, c, 0, M);
  vector<long long> dp2(N, 1);
  dfs2(dp1, dp2, c, 0, M);
  for (int i = 0; i < N; i++){
    cout << add(dp1[i], dp2[i], M) << endl;
  }
}

Measured memory_bytes: 26112
// This code is written By Philip Haddad (Philip97hd on codeforces).
// ICPC - One day I'll be there :D
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstring>
#include <algorithm>
#include <set>
#define ll long long
#define ld long double
#define rep(i,j,n) for(int i =j ; i < n ; i++)
#define repi(i,j,n) for(int i =n-1 ; i>=j ; i--)
#define repn for(int i =0 ; i < n ; i++)
#define pf printf
#define sf scanf
#define all(s) s.begin(),s.end()
#define clr(a,b) memset(a,b,sizeof(a))
#define IndxLowr lower_bound(v.begin(),v.end(),n)-v.begin()
#define FIO ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define len(s)	s.length()
#define siz(s)	s.size()
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
using namespace std;
ll const MAXA = (ll)1e9 + 1;
int main()
{
	int x;
	set<int> s;
	rep(i,0,3)cin >> x, s.insert(x);
	cout << s.size() << endl;
}

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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n,q;
    cin>>n>>q;
    ll a[n+2];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    a[0]=-1,a[n+1]=1e18;
    sort(a,a+n+2);
    while(q--){
        ll l,r;
        cin>>l>>r;
        long long low=-1,up=n+2,mid;
        while(up-low>1){
            mid=(up+low)/2;
            if(a[mid] <= r){
                low=mid;
            }
            else{
                up=mid;
            }
        }
        ll cnt = low;
        low=-1,up=n+2;
        while(up-low>1){
            mid = (up+low)/2;
            if(a[mid]<l) low=mid;
            else up=mid;
        }
        //cerr << "a " << cnt << " " << low << endl;
        cnt -= low;
        cout << cnt << "\n";
    }
}


Measured memory_bytes: 3932
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int mex=100005;
#define ll long long 
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int> 
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++) 


ll int power(ll int a,ll int b)
{
    ll int ans=1,f=a;
    while(b)
    {
        if(b&1ll) ans=(ans*f)%mod;
        b=b>>1ll;
        f=(f*f)%mod;
    }
    return ans;
}


int main()
{
  
    int n;
    cin>>n;
    ll int a[n],cf[n]={0},ans=0;
    fo(i,0,n)
    {cin>>a[i];
    cf[i]=a[i];
    }
    rfo(i,n-2,0)
   { cf[i]+=cf[i+1];
   cf[i]%=mod;
   }
    fo(i,0,n-1)
    {
        ans=(ans+(a[i]*cf[i+1])%mod)%mod;
    }
    
    cout<<ans<<endl;

}

Measured memory_bytes: 6796
/* 
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

void test_case();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	int t, x;
	cin >> t >> x;
	db ans = t / (1. * x);
	cout << fixed << setprecision(10) << ans << "\n";
}

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,x;
  cin >> a >> b >> x;
  if(a==0) {
    cout << b/x+1 << endl;
  }
  else {
    cout << b/x-(a-1)/x << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mxN=200005,M=1e9+7;
int n,k,resp;
int mod(int x,int M){int ret=x%M;if(ret<0)ret+=M;return ret;}
int fact[mxN],inv[mxN];
int exp(int a,int b,int M){
    if(b==0LL)return 1LL;
    if(b==1LL)return mod(a,M);

    int t=mod(exp(a,b/2,M),M);
    if(b%2==1)return mod(a*mod(t*t,M),M);
    return mod(t*t,M);
}

int C(int n,int k){
    return mod(fact[n]*mod(inv[k]*inv[n-k],M),M);
}

int32_t main(){
    cin>>n>>k;
    fact[0]=inv[0]=1;
    for(int i=1;i<mxN;i++){
        fact[i]=(fact[i-1]*i)%M;
        inv[i]=exp(fact[i],M-2,M);
    }

    for(int i=0;i<=min(n-1,k);i++){
        resp=mod(resp+mod(C(n,i)*C(n-1,i),M),M);
    }
    cout<<resp;


}

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

using namespace std;

typedef long long int ll;

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

  ll s, w;
  cin >> s >> w;
  if(w >= s) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}


Measured memory_bytes: 3648
from collections import defaultdict
n, m = map(int, input().split())
xs = list(map(int, input().split()))
bcs = [tuple(map(int, input().split())) for _ in range(m)]
ctr = defaultdict(int)
for b, c in bcs:
    ctr[c] += b
for x in xs:
    ctr[x] += 1
sorted_ctr = sorted(ctr.items(), key=lambda t: -t[0])
rem = n
ans = 0
for num, count in sorted_ctr:
    sub = min(rem, count)
    ans += num * sub
    rem -= sub
print(ans)

Measured memory_bytes: 60032
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <string>
#include <list>
#include <bitset>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

const LL mod=1e9+7;
const double PI=acos(-1);
const double EPS=1e-6;
const int INF=0x3f3f3f3f;
inline int readint(){int sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}
inline LL readLL(){LL sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}

int cnt1,cnt2,cnt4;

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    while(n--){
        int x;cin>>x;
        if(x%4==0) cnt4++;
        else if(x%2==0) cnt2++;
        else if(x%2) cnt1++;
    }
    if(cnt1>cnt4+1||(cnt1==cnt4+1&&cnt2)) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


Measured memory_bytes: 256
n = int(input())
length_list = list(map(int, input().split()))

count = 0

def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(0, n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            threenum_list = [length_list[j],length_list[k], length_list[i]]
            if not has_duplicates(threenum_list):

                if (abs(length_list[j]-length_list[k]) < length_list[i]) and (length_list[i] < length_list[j] + length_list[k]):
                    if (abs(length_list[k] - length_list[i]) < length_list[j]) and (length_list[j] < length_list[i] + length_list[k]):
                        if (abs(length_list[i] - length_list[j]) < length_list[k]) and (length_list[k] < length_list[j] + length_list[i]):
                            count += 1


print(count)

Measured memory_bytes: 9252
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a = [int(input()) for _ in range(5)]
    res = 10000000
    for i in permutations(a, 5):
        b = 0
        for j in range(4):
            b += i[j]
            if b%10:
                b = (b//10+1)*10
        res = min(res, b+i[-1])
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

S = sys.stdin.readline().rstrip()

ans = INF
for i in range(len(S) - 2):
    ans = min(ans, abs(int(S[i:i + 3]) - 753))
print(ans)


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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

struct Node {
  ll parent_num = 0;
  ll child_num = 0;
  set<ll> parent;
  set<ll> child;
};

ll N = 0;
Node table[2000000];
ll used[2000000];
ll d[2000000];

ll tmp;
ll ret = 0;

ll dfs(ll x, ll depth) {
  //最大の遷移回数
  if (depth > N*(N-1)/2 + 1) {
    return -1;
  }
  if (used[x]) {
    return d[x];
  }
  Node n = table[x];
  ll m = 0;
  FOREACH(c, n.child) {
    ll val = dfs(c, depth+1);
    if (val == -1) return -1;
    else m = max(m, val + 1);
  }
  used[x] = true;
  d[x] = m;
  return m;
}

void input() {
  IN(N);

  ll former, later;
  FOR(i, 1, N+1) {
    FOR(j, 1, N) {
      IN(tmp);
      ll k = min((ll)i, tmp);
      ll l = max((ll)i, tmp);
      if (j == 1) {
        former = k*(N+1) + l;
        used[former] = false;
      } else {
        later = k*(N+1) + l;
        table[former].child.insert(later);
        table[former].child_num += 1;
        // table[later].parent.insert(former);
        // table[later].parent_num += 1;
        used[later] = false;
        former = later;
      }
    }
  }

  FOR(i, 1, N+1) {
    FOR(j, i+1, N+1) {
      ll k = i * (N+1) + j;
      ll val = dfs(k, 0);
      // DEBUG(i);
      // DEBUG(j);
      // DEBUG("=>");
      // DEBUG(val);
      // LN();
      if (val == -1) {
        PRINT(-1);
        return;
      } else {
        ret = max(ret, val);
      }
    }
  }
  PRINT(ret+1);
}

void solve() {
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 409088
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int r = 0;
    for (int i = 1; i <= n; i += 2) {
        int c = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) c++;
        }
        if (c == 8) r++;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
S = input()

kisuu = S[::2]
gusuu = S[1::2]

flg = False

k_c = kisuu.count('R') + kisuu.count('U') + kisuu.count('D')
g_c = gusuu.count('L') + gusuu.count('U') + gusuu.count('D')

if k_c == len(kisuu) and g_c == len(gusuu):
    flg = True
  
if flg:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for ( k = left; k < right; k++ ) {
    if ( L[i].value <= R[j].value )
      A[k] = L[i++];
    else
      A[k] = R[j++];
  }
}

void mergeSort(struct Card A[], int left, int right) {
  int mid;
  if ( left + 1 < right ) {
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int partition(struct Card A[], int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ )
    if ( A[j].value <= x.value ) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
  return i + 1;
}

void quickSort(struct Card A[], int p, int r) {
  int q;
  if ( p < r ) {
    q = partition(A, p, r);
    quickSort(A, p, q - 1);
    quickSort(A, q + 1, r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, 0, n);
  quickSort(B, 0, n - 1);

  for ( i = 0; i < n; i++ )
    if ( A[i].suit != B[i].suit ) stable = 0;

  if ( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for ( i = 0; i < n; i++ )
    printf("%c %d\n", B[i].suit, B[i].value);

  return 0;
}


Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
 
int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

int main(){
  int n;
  cin >> n;
  vector<double>x(n);
  vector<double>y(n);
  for(int i=0;i<n;i++){
    cin >> x.at(i) >> y.at(i);
  }
  vector<int>in(n);
  for(int i=0;i<n;i++){
    in.at(i)=i;
  }
  double ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      double x_long=pow(x.at(i)-x.at(j),2.0);
      double y_long=pow(y.at(i)-y.at(j),2.0);
      ans+=sqrt(x_long+y_long);
    }
  }
  ans/=facctorialMethod(n);
  ans*=facctorialMethod(n-1);
  cout << fixed << setprecision(10);
  cout << ans << endl;
}

Measured memory_bytes: 256
#ifdef local_mode
    #include <cstdio>
    #include <cassert>
#endif
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
#ifdef local_mode
    //#define FILENAME "test" ← defined via command line
    assert(freopen(FILENAME ".in", "r", stdin));
    assert(freopen(FILENAME ".out", "w", stdout));
#endif
    ios_base::sync_with_stdio(0), cin.tie(0);

    int n, k;
    cin >> n >> k;
    ll cnt = 0;

    for (int b = 1; b <= n; b++) {
        if (b - 1 < k) continue;
        int val = (n - k) / b;
        cnt += (val + 1) * (ll)(b - k); // upperbound
        // x in [k, b)
        // first x : (n-x)/b != val
        // 0000111
        int l = k;
        int r = b;
        if ((n - r) / b == val) {
            continue;
        }
        while (l < r - 1) { // inv: f(l) == 0, f(r) == 1
            int x = l + (r - l) / 2;
            ((n - x) / b == val ? l : r) = x;
        }
        cnt -= b - r;
    }
    if (k == 0) cnt -= n;
    cout << cnt;

    return 0;
}







































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


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

int main() {
	int n,A[100];
	cin >> n;
	for (int t = 0; t < n; t++)cin >> A[t];

	sort(A, A+n);

	int a, b;
	a = b = 0;

	for (int t = 0; t < n; t++) {
		if (t % 2 == 1)a += A[n - 1 - t];
		else b += A[n - 1 - t];
	}

	cout << b-a << "\n";


	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<vector<Pl>> tree(n, vector<Pl>(0));
  rep(i,n-1){
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    tree[a].push_back(make_pair(b,c));
    tree[b].push_back(make_pair(a,c));
  }
  int q, k;
  cin >> q >> k;
  k--;
  vl dist(n, -1);
  dist[k] = 0;
  queue<Pl> que;
  que.push(make_pair(k,0));
  while(!que.empty()){
    Pl now = que.front(); que.pop();
    for(Pl &ne : tree[now.first]){
      if(dist[ne.first] == -1){
        que.push(make_pair(ne.first, now.second + ne.second));
        dist[ne.first] = now.second + ne.second;
      }
    }
  }
  rep(i,q){
    int x, y;
    cin >> x >> y;
    x--; y--;
    ll ans = dist[x] + dist[y];
    cout << ans << endl;
  }
}

Measured memory_bytes: 10736
#include <stdio.h>

int main(void)
{
  int a, b, sum;
  int count=0;

  while (scanf ("%d %d", &a, &b) != EOF)
    {
      sum = a + b;
      
      while (sum != 0)
	{
	  sum = sum/10;
	  count++;
	}
      printf("%d\n", count);
      count = 0;
    }
  
  return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

int main() {
    ll n,m;
    cin>>n>>m;

    ll ans=0;
    if(n*2>=m){
      ans=m/2;
    }
    else {
        ans+=n;
        ans+=(m-n*2)/4;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
H, W = map(int, input().split())

a = [list(input()) for _ in range(H)]
dp = [[0 for _ in range(W)] for _ in range(H)]

# print(a)
# print(dp)

dp[0][0] = 1

for i in range(H): #行
    for j in range(W): #列
        if a[i][j] == "#" or (i == H-1 and j == W-1):
            continue

        if i == H-1:
            if a[i][j+1] != "#":
                dp[i][j+1] += dp[i][j]
        elif j == W-1:
            if a[i+1][j] != "#":
                dp[i+1][j] += dp[i][j]
        else:
            if a[i][j+1] != "#":
                dp[i][j+1] += dp[i][j]
            if a[i+1][j] != "#":
                dp[i+1][j] += dp[i][j]

print(dp[-1][-1]%1000000007)

Measured memory_bytes: 166292
let inputString = '';

process.stdin.on('data', (input) => { inputString += input; });

process.stdin.on('end', () => {
  const arr = inputString.split('\n');
  check(arr[1].split(' ').map((s) => Number(s)), arr[3].split(' ').map((s) => Number(s)));
});

const check = (A, mList) => {
  const solve = (i, m) => {
    if (m === 0) return true;

    if (i >= A.length) return false;

    // solve(i + 1, m) is the case which does not use A[i] in the addition
    // solve(i + 1, m - A[i]) is the case which uses A[i] in the addition
    return solve(i + 1, m) || solve(i + 1, m - A[i]);
  };

  mList.forEach((m) => {
    console.log(solve(0, m) ? 'yes' : 'no');
  });
};




Measured memory_bytes: 20288
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1000000000; //10^9
const ll MX = 1e18;         //1(1倍)e(指数)18(10^18)
const ll MOD = 1e9 + 7;
//加算代入演算子は+=
//int 2^31 10^9まで
//intは10桁、long longは18桁、doubleは308桁、long double は4932桁
//10^10くらいまででdoubleは誤差が発生しちゃう。なるべく整数にすること
//doubleからlong longにキャストするときは、+0.5で切り捨ての誤差を調整
//__int128()で128bit対応の整数（多倍長整数）
int main()
{
    ll a;
    double b;
    cin >> a >> b;
    ll ib = b * 100 + 0.5;
    a *= ib;
    a /= 100;
    cout << a << endl;
    return 0;
}

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

int main() {
  int A, B;
  int M = -1;
  cin >> A >> B;
  for(int i=0;i<10;i++){
    if((10*B+i)*8/100==A){
      M=10*B+i;
      break;
    }
  }
  cout << M << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<int,P> PP;
struct edge { int to, cor; };
int h[100005];
int dp[100005];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> h[i];

	rep(i, n)dp[i + 1] = inf;
	for (int i = 1; i < n; i++) {
		if (i != 1)dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
		dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));

	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)
#define all(a) a.begin(), a.end()
#define gr greater<LL>()

using namespace std;

void solve(long long N, std::vector<long long> a){
    vector<vector<LL>> edges(N);

    rep(i,N-1){
        LL looser=i+1;
        LL winner = a[i]-1;
        edges[winner].emplace_back(looser);
    }

    function<LL(LL)> dfs = [&dfs, &edges](LL curr){
        if(edges[curr].empty())return 0LL;
        LL n = edges[curr].size();
        vector<LL> hs(n);
        rep(i,n)hs[i]=dfs(edges[curr][i])+1;
        sort(all(hs),gr);
        LL max_= 0;
        rep(i,n){
            max_ = max(max_, hs[i]+i);
        }
        return max_;
    };

    cout<< dfs(0) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N-2+1);
    for(int i = 0 ; i < N-2+1 ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 18944
#include <cstdio>
#include <iostream>

using namespace std;

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

int main() {
	int a, b;
	while (scanf("%d%d", &a, &b) != EOF) {
		printf ("%d\n", gcd(a, b));
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------

signed main() {
	int a, b, c, sum = 0;
	cin >> a >> b;
	int d = a / b;
	int r = a % b;
	ld f = (ld)a / b;
	printf("%lld %lld %LF\n", d, r, f);
}


Measured memory_bytes: 3212
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int ans = 0;

		for(int i = a; i <= b; i++){
			if(c%i == 0)ans++;
		}

		System.out.printf("%d\n",ans);
	}
}





Measured memory_bytes: 26392
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    vector<int> bills = {500, 100, 50, 10, 5, 1};
    int n;
    while(cin >> n and n) {
        int change = 1000 - n;
        int ans = 0;
        for(int bill : bills) {
            while(change >= bill) {
                change -= bill;
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define popcnt __builtin_popcount
#define getbit(x, k) ((x >> k) & 1)
#define all(x) (x).begin(),(x).end()
// ---------------------------------

void MAIN() {
  int n; cin >> n;
  vector<int> a(n);
  int s = 0;
  for (auto &i : a) {
    cin >> i;
    s ^= i;
  }
  for (auto &i : a) {
    cout << (s ^ i) << ' ';
  }
  cout << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

vector<int>v;

int main()
{
    int n,x,tot = 0,c = 0;
    cin >> n >> x;

    for(int i = 0; i < n; i++){
        int y;
        cin >> y;
        v.push_back(y);
        tot += y;
    }

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

   for(int i = 0; i < v.size(); i++){

        if(v[i] <= x){
            c++;
            x -= v[i];
            if(i == v.size()-1 && x > 0)c--;
        }
   }

    cout << c << endl;

}


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

void fail() { cout << "No\n"; exit(EXIT_SUCCESS); }
inline int abs(int a) {
    if (a<0) return -a;
    return a;
}
int x, y, t;
int main() {
    int n;
    cin >> n;
    for (int i=0; i < n; i++) {
        int tt, tx, ty;
        cin >> tt >> tx >> ty;
        int dist = abs(tx-x) + abs(ty-y); //manhattan distance
        int t_diff = tt - t;
        t = tt;
        x = tx;
        y = ty;
        if (dist > t_diff) fail();
        // printf("dist: %d\n", dist);
        // printf("t_diff: %d\n", t_diff);
        // printf("t_diff-dist= %d\n", t_diff-dist);
        if ( (t_diff - dist) & 1 ) fail();
    }
    
    cout << "Yes\n";
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

int conv(char c) {
	if (c == 'I') return 1;
	if (c == 'V') return 5;
	if (c == 'X') return 10;
	if (c == 'L') return 50;
	if (c == 'C') return 100;
	if (c == 'D') return 500;
	return 1000;
}

int main() {
	for(string s; cin >> s; ) {
		reverse(all(s));
		int prev = 0, sum = 0;
		rep(i, s.size()) {
			int c = conv(s[i]);
			if(c < prev) sum -= c;
			else sum += c;
			prev = c;
		}
		cout << sum << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#if loc||local
#define _GLIBCXX_DEBUG
#endif

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int r,c,k;
  cin>>r>>c>>k;
  auto dp = vec<ll>(5,r,c);
  auto a = vec<ll>(r,c);
  rep(_,k){
    int i,j,v;
    cin>>i>>j>>v;
    i--;j--;
    chmax<ll>(a[i][j],v);
  }

  rep(i,r){
    rep(j,c){
      if(j-1>=0){
        chmax(dp[1][i][j],max(dp[0][i][j-1]+a[i][j],dp[1][i][j-1]));
        chmax(dp[2][i][j],max(dp[1][i][j-1]+a[i][j],dp[2][i][j-1]));
        chmax(dp[3][i][j],max(dp[2][i][j-1]+a[i][j],dp[3][i][j-1]));
      }
      if(i-1>=0)chmax(dp[0][i][j],max<ll>({dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j]}));
      chmax(dp[1][i][j],dp[0][i][j]+a[i][j]);
    }
  }
  for(auto& ai:a)dump(ai);dump('\n');
  ll ans = 0;
  rep(k,4){
    rep(i,r){
      rep(j,c){
        //cout<<dp[k][i][j]<<" ";
        chmax(ans,dp[k][i][j]);
      }
      //cout<<endl;
    }
    //cout<<endl;
  }
  cout<<(ans)<<endl;

}


Measured memory_bytes: 425732
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const ll INF = (1 << 28);
const ll dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const ll Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    ll to, cost;
};
ll n, k;
struct matrix{
  ll a[70][70];
  matrix(){
      for (ll i = 0; i < n; i++)
    {
        for(ll j=0;j<n;j++){
            a[i][j]=0;
        }
    }
  }
};
matrix mult(matrix a, matrix b){
  matrix c;
  for(ll i=0;i<n;i++){
    for(ll j=0;j<n;j++){
        for(ll k=0;k<n;k++)
        c.a[i][j]=(c.a[i][j]+(a.a[i][k]*b.a[k][j])%mod)%mod;
    }
  }
  return c;
}
matrix binpow(matrix a, ll b){
  matrix res;
  for(ll i=0;i<n;i++)res.a[i][i]=1;
  while(b){
    if(b&1)
      res=mult(res,a);
    b>>=1;
    a=mult(a,a);
  }
  return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>k;
    matrix s;
    for (ll i = 0; i < n; i++)
    {
        for(ll j=0;j<n;j++){
            cin>>s.a[i][j];
        }
    }
    s=binpow(s,k);
    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
        for(ll j=0;j<n;j++){
            ans+=s.a[i][j];
            ans%=mod;
        }
    }
    cout << ans << "\n";
}



Measured memory_bytes: 640
from itertools import product
li = list(map(int, input()))

for ops in product('+-', repeat=3):
    tmp = li[0]
    for o, n in zip(ops, li[1:]):
        if o == '+':
            tmp += n
        else:
            tmp -= n
    if tmp == 7:
        ans = str(li[0])
        for o, n in zip(ops, li[1:]):
            ans += o + str(n)
        ans += '=7'
        break

print(ans)


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

typedef long long ll;

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    if(a*b < n || a+b-1 > n){
        cout << -1 << endl;
        return 0;
    }
    list<int> ans;
    int now = 1;
    for(int i = 0; i < b; i++){
        int len = min(a, (n-now+1)-(b-1-i));	// ?
        for(int j = now+len-1; j >= now; j--)   ans.push_front(j);
        now += len;
    }
    for(auto it = ans.begin(); it != ans.end(); it++){
        cout << *it << " \n"[it==--ans.end()];
    }
    return 0;
}


Measured memory_bytes: 11520
x,n=map(int,input().split())
lis=list(map(int,input().split()))

a,b=x,x

ans=0
while ans==0:
  if n==0:
    ans=x
  elif x not in lis:
    ans=x
  else:
    a=a-1
    b=b+1
    if a not in lis:
      ans=a
      break
    if b not in lis:
      ans=b

print(ans)

Measured memory_bytes: 9192
from collections import deque


# INPUT
n, q = map(int, input().split())

que = deque([])

for _ in range(n):
    name, time = input().split()

    que.append([name, int(time)])

# PROCESS
time_sum = 0

while len(que):

    name, time = que.popleft()

    if time <= q:
        time_sum += time

        print(name, time_sum)
    else:
        time_sum += q

        que.append([name, time - q])



Measured memory_bytes: 13272
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void calc(int[] a) {
    long sum = abs(a[0]) + abs(a[$-1]);
    for (int i = 1; i < a.length; i++)
        sum += abs(a[i] - a[i-1]);

    for (int i = 0; i < a.length; i++) {
        // i を訪れないでスキップした場合の費用

        // i のひとつ前
        int s = i == 0 ? 0 : a[i-1];
        // i のひとつ後
        int t = i+1 == a.length ? 0 : a[i+1];

        long costOld = abs(s - a[i]) + abs(a[i] - t);
        // i をスキップした場合のコスト
        long costNew = abs(s - t);

        long cost = sum - costOld + costNew;
        writeln(cost);
    }
}

void main() {
    readint;
    auto a = readints;
    calc(a);
}


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

int main()
{
    const int SIZE = 26;
    string line;
    int counter[SIZE];

    memset(counter, 0, sizeof(counter));
    while(getline(cin, line))
    {
        for(int i = 0; i < line.length(); i++)
        {
            if(isalpha(line[i]))
            {
                counter[(char)tolower(line[i])-'a']++;
            }
        }
    }

    for(int i = 0; i < SIZE; i++)
    {
        cout << (char)('a' + i) << " : " << counter[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();

		if ((A + B) > (C + D)) {

			System.out.println("Left");

		} else if ((A + B) < (C + D)) {

			System.out.println("Right");

		} else if ((A + B) == (C + D)) {

			System.out.println("Balanced");

		}

	}
}


Measured memory_bytes: 21840
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

signed main(){
    string s;
    while(1){
        cin >> s;
        if(s == "#") break;
        int cnt = 0, now = 0;
        while(s.size()){
            if(s.substr(s.size() - 4, 4) == "west"){
                now = now *2 + 90;
                s = s.substr(0, s.size() - 4);
            }else{
                if(cnt == 0) now = 0;
                else now = now *2 - 90;
                s = s.substr(0, s.size() - 5);
            }
            cnt ++;
        }
        if(cnt >= 2) now /= 2;
        cout << now;
        if(cnt >= 3) cout << "/" << pow(2, cnt - 2);
        cout << endl;
    }
}

Measured memory_bytes: 1320