akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int R,C,k;cin>>R>>C>>k;
    vector<vector<ll>> t(R,vector<ll>(C,0));
    rep(i,k){
        int r,c;ll v;cin>>r>>c>>v;r--;c--;
        t[r][c]=v;
    }
    vector<vector<vector<ll>>> dp(R,vector<vector<ll>>(C,vector<ll>(4,0)));
    rep(i,R)rep(j,C){
        if(i!=R-1){
            rep(l,4)chmax(dp[i+1][j][0],dp[i][j][l]);
            rep(l,3)chmax(dp[i+1][j][0],dp[i][j][l]+t[i][j]);
        }
        if(j!=C-1){
            rep(l,4)chmax(dp[i][j+1][l],dp[i][j][l]);
            rep(l,3)chmax(dp[i][j+1][l+1],dp[i][j][l]+t[i][j]);
        }
    }
    rep(i,3)chmax(dp[R-1][C-1][3-i],dp[R-1][C-1][2-i]+t[R-1][C-1]);
    ll res=0;
    rep(i,4)chmax(res,dp[R-1][C-1][i]);
    cout<<res<<endl;
}

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

void solve(){


}
int cnt[100009];
const ll mod=998244353;
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n;cin>>n;
	int x;cin>>x;
	if(x==0){
		vi v(n-1);
		rep(i,n-1) cin>>v[i];
		sort(all(v));
		ll ans = 1;
		cnt[0]=1;
		trav(i,v){
			if(i==0) ans=0;
			else{
				ans=ans*cnt[i-1]%mod;
				cnt[i]++;
			}
		}
		cout<<ans;
	}
	else cout<<0;
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <map>

using namespace std;

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

  multimap<int, int> s;

  for ( int i = 0; i < n; i++ ) {
    int a, b;
    cin >> a >> b;
    s.insert( make_pair( a, b ) );
  }

  for ( auto it = s.begin(); it != s.end(); it = next( it ) ) {
    k -= it->second;
    if ( k <= 0 ) {
      cout << it->first << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 4992
import Text.Printf

solve1 :: (Double, Double, Double, Double, Double, Double) -> (Double, Double)
solve1 (_, b, c, d, e, f) = (x, y)
    where y = c / b
          x = (f - e * y) / d

solve2 :: (Double, Double, Double, Double, Double, Double) -> (Double, Double)
solve2 (a, b, c, d, e, f) = (x, y)
    where y = (a * f - c * d) / (a * e - b * d)
          x = (c - b * y) / a

solve :: [Double]-> (Double, Double)
solve xs
    | a == 0    = solve1 (a, b, c, d, e, f)
    | otherwise = solve2 (a, b, c, d, e, f)
        where a = xs !! 0
              b = xs !! 1
              c = xs !! 2
              d = xs !! 3
              e = xs !! 4
              f = xs !! 5

format :: (Double, Double) -> String
format (x, y) = printf "%.3f %.3f" x y

main :: IO ()
main = interact (unlines . map (format . solve . map read . words) . lines)

Measured memory_bytes: 4532
X = int(input())

if X >= 400 and X <= 599:
    print(8)
elif X >= 600 and X <= 799:
    print(7)
elif X >= 800 and X <= 999:
    print(6)
elif X >= 1000 and X <= 1199:
    print(5)
elif X >= 1200 and X <= 1399:
    print(4)
elif X >= 1400 and X <= 1599:
    print(3)
elif X >= 1600 and X <= 1799:
    print(2)
else:
    print(1)


Measured memory_bytes: 9180
def main():
    N = int(input())
    a = [[0]*3 for _ in range(N)]
    for i in range(N):
        a[i][0], a[i][1], a[i][2] = map(int, input().split())
    
    DP = [[0]*3 for _ in range(N+1)]
    
    for i in range(N):
        for j in range(3):
            for k in range(3):
                if(j == k):
                    continue
                DP[i+1][k] = max(DP[i][j]+a[i][k], DP[i+1][k])
                
    ans = 0
    for m in range(3):
        ans = max(ans, DP[N][m])
    
    print(ans)
    
main()

Measured memory_bytes: 42572
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 200003
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define sumall(v) accumulate(all(v),(ll)0)
#define suma accumulate
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define br "\n"
#define spac " "
#define zero (ll)0
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<tuple<ll,ll,ll> >vtll;
typedef vector<bool>vbool ;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<"\n" ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double p , ll t){db q = 1;while(t){if(t%2){q*=p;}p*=p;t/=2;}return(q);}
ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
void call(){dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1));}
ll n,m,k;
bool ok = false;
int main()
{
    FastIO ;
    PRECISION(20) ;
    ll a,b,c,d,i,j,t,x,y,z,x1,y1,z1,e,f;
    db p,q,r,u,w ;
    char ch,chr ;
    string str,st,str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //call();
    //Constructive is Weak!!
    cin>>n;
    a = 100;
    b = 0;
    while(a<n)
    {
        a+=(ll)(a*0.01);
        b++;
    }
    cout<<b;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
int absolute(int n){
    return n<0?-n:n;
}
int main(){
    int N,X,Y;
    cin >> N >> X >> Y;
    X--;
    Y--;
    int d[N]={0};
    int mindist=0;
    for(int i=1; i<N; i++){
        for(int j=0; j<i; j++){
            if(i==j) continue;
            
            mindist=min(
                absolute(i-j),
                min(absolute(i-X)+absolute(j-Y)+1,absolute(j-X)+absolute(i-Y)+1)
            );
            d[mindist]++;
        }
    }
    for(int i=1; i<N; i++){
        cout << d[i] << endl;
    }
    return 0;
}


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

int main(){
        ll n,i,j,ans=0;
        cin >> n;
        for(i=1;i<n+1;++i){
                for(j=1;i*j<n+1;++j){
                        ans += i*j;
                }
        }
        cout << ans << endl;
        return 0;
}

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


int N;
vector<int> a, b;
vector<int> nxt, vt, vp;


vector<int> kmp()
{
    int i, q, k;
    vector<int> res;

    nxt[0] = 0;
    for (q = 1, k = 0; q < N; ++q) {
        while (k > 0 && vp[q] != vp[k])
            k = nxt[k - 1];
        if (vp[q] == vp[k])
            k++;
        nxt[q] = k;
    }

    for (i = 0, q = 0; i < 2*N-1; ++i) {
        while (q > 0 && vp[q] != vt[i])
            q = nxt[q - 1];
        if (vp[q] == vt[i])
            q++;
        if (q == N) {
            res.push_back(i - N + 1);
            q = nxt[q - 1];
        }
    }
    return res;
}


void solve()
{
    vector<int> pos;
    vector<int> m1(N), m2(N);

    nxt.resize(N);
    vt.resize(2*N-1);
    vp.resize(N);
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());

    for (int e = 0; e < 30; e++) {
        fill(m2.begin(), m2.end(), -1);
        for (int i = 0; i < 2*N; i++) {
            if (i < N) {
                vt[i] = b[i] & 1;
                b[i] >>= 1;
            } else {
                vt[i] = vt[i - N];
            }
        }
        for (int i = 0; i < N; i++) {
            vp[i] = a[i] & 1;
            a[i] >>= 1;
        }
        pos = kmp();
        for (int k : pos) {
            if (m1[k] >= 0)
                m2[k] = m1[k];
        }
        for (int i = 0; i < N; i++)
            vp[i] = 1 - vp[i];
        pos = kmp();
        for (int k : pos) {
            if (m1[k] >= 0)
                m2[k] = m1[k] + (1 << e);
        }
        swap(m1, m2);
    }

    for (int i = 0; i < N; i++) {
        if (m1[i] >= 0)
            cout << i << " " << m1[i] << endl;
    }
}


int main()
{
    cin >> N;
    a.resize(N);
    b.resize(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];
    for (int i = 0; i < N; i++)
        cin >> b[i];
    solve();
    return 0;
}


Measured memory_bytes: 11572
#include <iostream>
 
typedef unsigned int ui;
 
void swap(ui & a, ui & b)
{
    unsigned int tmp = a;
    a = b;
    b = tmp;
}
 
ui gcd(ui a, ui b)
{
    if (a < b) swap(a, b);
 
    ui c = a % b;
    while (c != 0) {
        a = b;
        b = c;
        c = a % b;
    }
 
    return b;
}
 
int main() {
    using namespace std;
 
    ui a, b;
    while (cin >> a >> b) {
        const ui GCD = gcd(a, b);
        const ui LCM = a * (b / GCD);
        cout << GCD << ' ' << LCM << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;
typedef pair<int, string> P;

void solve()
{
	bool first = true;
	int n;
	while(cin >> n, n)
	{
		vector<P> data;
		set<int> point;
		for(int i = 0; i < n; ++i)
		{
			string str;
			cin >> str;
			int a, b, c;
			cin >> a >> b >> c;
			int sum = 0;
			sum += a * 3 + c;
			data.push_back(P(sum, str));
			point.insert(sum);
		}
		if(!first)
		{
			cout << endl;
		}
		first = false;
		set<int>::reverse_iterator rit = point.rbegin();
		int pos = 0;
		while(rit != point.rend())
		{
			for(int i = 0; i < n; ++i)
			{
				if(*rit == data[i].first)
				{
					cout << data[i].second << "," << data[i].first << endl;
				}
			}
			++rit;
		}
	}
}

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

Measured memory_bytes: 1216
#include <iostream>
#include <map>
#include <string>
using namespace std;
string march="MARCH";
int bit[10];
map<char,int> combination;
long long int recursion(int now){
        if(now==march.size()){
                long long int counter=1;
                int c=0;
                for(int i=0 ; i<march.size() ; i++ ){
                        if(bit[i]){
                                c++;
                                counter*=combination[march[i]];
                        }
                }
                if(c!=3)return false;
                return counter;
        }long long int response=0;
        for(int i=0 ; i<=1 ; i++ ){
                bit[now]=i;
                response+=recursion(now+1);
        }
        return response;
}
int main(){
        int N;
        cin >> N;
        for(int i=0 ; i<N ; i++ ){
                string name;cin >> name;
                combination[name[0]]++;
        }
        cout << recursion(0)<<endl;
        return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int kari,i;
	static int a[30];
	for(i = 0;i < 28;i++) {
		scanf("%d",&kari);
		a[kari] = 1;
	}
	for(i = 1;i < 31;i++) {
		if(a[i] == 0) printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 592
import math

def isOK(lis,attack):
    count = 0
    for i in lis:
        hp = i - B * attack
        if hp > 0:
            count += math.ceil(hp/(A - B))
    return count <= attack

def binary_search(lis):
    ng = -1
    ok = 10**10

    while(abs(ok-ng)>1):
        mid = int((ok+ng)/2)
        if isOK(lis,mid):
            ok = mid
        else:
            ng = mid
    return ok

N,A,B = [int(s) for s in input().split()]
lis = []

for i in range(N):
    lis.append(int(input()))

ans = binary_search(lis)
print(ans)

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

bool mySort(string s1, string s2){
	if(s1.size()<s2.size())
		return true;
	else if(s1.size()==s2.size() && s1<s2)
		return true;
	else
		return false;
}

vector<string> s;
int flag=0;

void util(int num, string str, int k){
	if(s.size()>=k){
		flag=1;
		return;
	}
	if(str.size()==num){
		s.push_back(str);
		return;
	}
	char ch=str.back();
	if(ch>'0'){
		str+=(char)(ch-1);
		util(num, str, k);
		str.pop_back();
	}
	str+=ch;
	util(num, str, k);
	str.pop_back();
	if(ch<'9'){
		str+=(char)(ch+1);
		util(num, str, k);
		str.pop_back();
	}
}

int main() {
	// your code goes here
	int k;
	cin >> k;
	for(int i=1; i<=9; i++)
		s.push_back(to_string(i));
	if(s.size()>=k)
		flag=1;
	for(int num=2; flag==0; num++){
		string str="";
		for(int dig=1; dig<=9 && flag==0; dig++){
			str=to_string(dig);
			util(num, str, k);
		}
	}
	sort(s.begin(), s.end(), mySort);
	cout << s[k-1] << endl;
	return 0;
}

Measured memory_bytes: 6900
# -*- coding: utf-8 -*-
"""

"""
import sys
from datetime import datetime
from time import perf_counter


def identify_class(weight):
    if weight <= 48.0:
        return 'light fly'
    elif weight <= 51.0:
        return 'fly'
    elif weight <= 54.0:
        return 'bantam'
    elif weight <= 57.0:
        return 'feather'
    elif weight <= 60.0:
        return 'light'
    elif weight <= 64.0:
        return 'light welter'
    elif weight <= 69.0:
        return 'welter'
    elif weight <= 75.0:
        return 'light middle'
    elif weight <= 81.0:
        return 'middle'
    elif weight <= 91.0:
        return 'light heavy'
    else:
        return 'heavy'


def main(args):
    for line in sys.stdin:  # ??????????????\???
        weight = float(line.strip())
        boxing_class = identify_class(weight)
        print(boxing_class)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7828
#include <stdio.h>

int main(){
    int n;
    unsigned long long int k;
    if(scanf("%d %llud", &n, &k) == -1){
        return 0;
    }
    unsigned long long int answer = k;
    int i;
    if(n != 2){
        for(i = 1; i < n; i++){
            answer = answer * (k - 1);
        }
    }
    printf("%llu", answer);
}

Measured memory_bytes: 128
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt()

  val seq = Range(0, n).map(_ => sc.nextLong())
    .groupBy(i => i)
    .toStream
    .sortWith((t1, t2) => t1._1 > t2._1)
    .filter(t => t._2.size > 1)
    .toSeq

  if (seq.size == 1) {
    println(if (seq(0)._2.size > 3) seq(0)._1 * seq(0)._1 else 0)
  }else if (seq.size > 1) {
    println(if (seq(0)._2.size > 3) seq(0)._1 * seq(0)._1 else seq(0)._1 * seq(1)._1)
  } else {
    println(0)
  }
}


Measured memory_bytes: 138784
import math
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
mp = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
dp = [''] * (N+1)
for i in range(1, N+1):
    cand = []
    for x in A:
        if i - mp[x] < 0:
            continue
        if dp[i-mp[x]] == '' and mp[x] != i:
            continue
        if dp[i-mp[x]] == '':
            cand.append(x)
        else:
            before = dp[i - mp[x]]
            pre = (int(math.log10(before)) + 1) * 10 * x + before
            suf = before * 10 + x
            cand.append(max(pre, suf))
    if cand:
        dp[i] = max(cand)
    else:
        dp[i] = ''
print(dp[N])

Measured memory_bytes: 52444
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int r; scanf("%d", &r);
	
	printf("%.12lf\n", 2. * r * 3.141592653589793238);
	return 0;
}


Measured memory_bytes: 3772
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define pc(x) __builtin_popcount(x)
typedef long long lnt;
const int INF = (~0U) >> 2;
const lnt INFLL = (~0ULL) >> 2;
int n;
lnt ans, f[20][40][40];
char buf[40], tmp1[40], tmp2[40];
int main() {
	scanf("%d", &n);
	scanf("%s", buf);
	for (int i = 0; i < (1 << n); i++) {
		int len1 = 0, len2 = 0;
		for (int j = 0; j < n; j++) {
			if ((i >> j) & 1) {
				tmp1[++len1] = buf[j];
			} else {
				tmp2[++len2] = buf[j];
			}
		}
		std::reverse(tmp1 + 1, tmp1 + len1 + 1);
		std::reverse(tmp2 + 1, tmp2 + len2 + 1);
		f[0][0][0] = 1;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= len1; j++) {
				for (int k = 0; k <= len2; k++) {
					if (j < len1 && buf[i + n] == tmp1[j + 1])
						f[i + 1][j + 1][k] += f[i][j][k];
					if (k < len2 && buf[i + n] == tmp2[k + 1])
						f[i + 1][j][k + 1] += f[i][j][k];
				}
			}
		}
		ans += f[n][len1][len2];
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= len1; j++) {
				for (int k = 0; k <= len2; k++) {
					f[i][j][k] = 0;
				}
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
n = int(input().split()[0])
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

all_mons_n = sum(a_list)
mons_list = []

for i, b in enumerate(b_list):
    mons_n = a_list[i]
    next_mons_n = a_list[i+1]
    can_hit_n = b

    if mons_n <= can_hit_n:
        a_list[i] = 0
        can_hit_n = can_hit_n - mons_n
    elif mons_n > can_hit_n:
        a_list[i] -= can_hit_n
        can_hit_n = 0

    if can_hit_n > 0:
        if next_mons_n <= can_hit_n:
            a_list[i+1] = 0
            can_hit_n = can_hit_n - next_mons_n
        elif next_mons_n > can_hit_n:
            a_list[i+1] -= can_hit_n

total = all_mons_n - sum(a_list)
print(total)


Measured memory_bytes: 18752
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
struct RollingHash{
    static constexpr int SZ = 323456;
    static constexpr int mod = 1e9+7;
     int basemod[2] = {1007, 1000000021};
     int basepow[2][SZ];
    vector<int> pre[2];
    const string s;
    const int n;
    void make(){
        rep(i,2){
            basepow[i][0] = 1;
            rep(j,SZ-1){
                basepow[i][j+1] = (long long)basepow[i][j] * basemod[i] % mod;
                assert(basepow[i][j+1]>=0);
            }
        }
    }
    RollingHash(const string &_s) : s(_s),n((int)s.size()){
        if(!basepow[0][0])make();
        pre[0].resize(n + 1);
        pre[1].resize(n + 1);
        rep(i,2){
            rep(j,n){
                pre[i][j+1] =((long long)pre[i][j] * basemod[i] % mod + (int)s[j]) % mod;
                assert(pre[i][j+1]>=0);
                
            }
        }
    }
    // [l,r)
    ll cal_hash(int l, int r){
        ll a = (pre[0][r] - (long long)pre[0][l] * basepow[0][r-l] % mod + mod) % mod;
        ll b = (pre[1][r] - (long long)pre[1][l] * basepow[1][r-l] % mod + mod) % mod;
        show(a,b);
        return (ll)(a<<30) + b;
    }
};
int n;
string s;
bool ok(int k,RollingHash &rh){
    map<ll,int> mp;
    bool f = false;
    for(int i = 0; i < n - k + 1; i++){
        show(i,k);
        ll h = rh.cal_hash(i,i+k);
        if(mp.count(h)){
            if(mp[h] <= i - k)return true;
        }else{
            mp[h] = i;
        }
    }
    return false;
}
int main(){
    cin >> n >> s;
    int l = 0;
    int r = n;
    RollingHash rh(s);
    while(r - l >1){
        int mid = (l + r) / 2;
        if(ok(mid,rh)){
            l = mid;
        }else{
            r = mid;
        }
    }
    cout << l << endl;
}

Measured memory_bytes: 3072
import sys
input=sys.stdin.readline

n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))

ans=-10**20
m=[]
cycle=[0]*n
for i in range(n):
    now=i
    temp=[]
    s=0
    while True:
        now=p[now]-1
        s+=c[now]
        if temp==[]:
            temp.append(s)
        else:
            temp.append(max(temp[-1],s))
        if now==i:
            cycle[i]=s
            m.append(temp)
            break

for i in range(n):
    t=len(m[i])
    if cycle[i]<=0:
        if k>=t:
            ans=max(ans,m[i][t-1])
        else:
            ans=max(ans,m[i][k-1])

    else:
        x=k//t
        y=k%t
        if x>=1:
            temp=(x-1)*cycle[i]+m[i][t-1]
            ans=max(ans,temp)
            if y!=0:
                temp=x*cycle[i]+m[i][y-1]
                ans=max(ans,temp)
        else:
            ans=max(ans,m[i][k-1])

print(ans)

Measured memory_bytes: 279328
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

typedef struct{
    int num;
    int year;
    int prefecture;
    int city_num;

}CITY;
bool sort_state(CITY a, CITY b){
    if( a.year < b.year  || ( a.year == b.year && a.prefecture < b.prefecture) ){
        return true;
    }else{
        return false;
    }
}
bool sort_yaer( CITY a, CITY b){
    if( a.year < b.year ){
        return true;
    }else{
        return false;
    }
}
bool sort_prefectre( CITY a, CITY b){
    if( a.prefecture < b.prefecture){
        return true;
    }else{
        return false;
    }
}
bool sort_num(CITY a, CITY b){
    if( a.num < b.num){
        return true;
    }else{
        return false;
    }
}
int main(){
    int i;
    int N,M;
    int p,y;

    int id_pre, id_num;
    CITY *city;

    cin >> N >> M;

    city = new CITY[M];

    for(i=0;i<M;i++){
        cin >> p >> y;
        city[i].num = i;
        city[i].prefecture = p;
        city[i].year = y;
    }
    sort(city,city+M,sort_yaer);
    stable_sort(city,city+M,sort_prefectre);
    id_pre = -1;
    id_num = -1;
    for(i=0;i<M;i++){
        if( id_pre !=  city[i].prefecture ){
            id_pre = city[i].prefecture;
            id_num = 1;
        }else{
            id_num++;
        }
        city[i].city_num = id_num;
        //sprintf(city[i].id,"%06d%06d",id_pre,id_num);
    }
    sort(city,city+M,sort_num);
    for(i=0;i<M;i++){
        printf("%06d%06d\n",city[i].prefecture,city[i].city_num);
    }
    
    return 0;
}


Measured memory_bytes: 3064
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n = int(input())
ans = 0
for i in range(1, n+1):
    if len(make_divisors(i)) == 8 and i%2 == 1:
        ans += 1

print(ans)
    

Measured memory_bytes: 9348
n = int(input())
A = list(map(int,input().split()))
m = int(input())
Q = [list(map(int,input().split())) for _ in range(m)]
L = [0 for _ in range(10**5+1)]
for a in A:
    L[a]+=1
ans = sum(A)

for q in Q:
    num_b = L[q[0]]
    L[q[0]] -= num_b    
    L[q[1]] += num_b
    ans -= (num_b)*q[0]
    ans += (num_b)*q[1]
    print(ans)

Measured memory_bytes: 97380
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n
l1 ... ln
 */
int n,l[10];

int main(){
  cin>>n;
  REP(i,n)
    cin>>l[i];

  sort(l,l+n);
  int s=0;
  REP(i,n-1)
    s+=l[i];

  if(l[n-1] < s)
    cout<<"Yes\n";
  else
    cout<<"No\n";

  return 0;
}


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll n; cin >> n;
  str s, t; cin >> s >> t;
  ll flag = 0;
  for(ll i = 0;i < n;i++)
  {
    str a, b;
    a = s.substr(i);
    b = t.substr(0, a.size());
    if(a == b)
    {
      flag = a.size();
      break;
    }
  }
  fin(n * 2 - flag)
  return;
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
   
    int N;

    int x[100005], y[100005], t[100005];
    int dist, time;
    x[0] = 0;
    y[0] = 0;
    t[0] = 0;
    
    cin >> N;
    
    for(int i = 1; i <= N; i++){
        cin >> t[i] >> x[i] >> y[i];
    }
    for(int i = 1; i <= N; i++){
        dist = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
        time = t[i] - t[i - 1];
        if(dist > time){
            cout << "No" << endl;
            return 0;
        }
        if(dist % 2 != time % 2){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1408
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1

c = [0 for _ in range(100005)]

for i in range(n):
    val = a[i]
    c[val - 1] += 1
    c[val] += 1
    c[val + 1] += 1

ans = 0
for i in range(100005):
    ans = max(ans, c[i])

print(ans)

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

int main() {
  int N;
  cin >> N;
  
  unordered_set<string> S;
  for (int i=0; i < N; i++) {
    string s;
    cin >> s;
    S.insert(s);
  }
  
  cout << S.size() << endl;
  return 0;
}

Measured memory_bytes: 17688
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char const *argv[])
{
	int len;
	char S[3];
	scanf("%s",S);
	if(strlen(S) == 2)	printf("%s\n",S);
	else printf("%c%c%c\n",S[2],S[1],S[0]);
	return 0;
}

Measured memory_bytes: 128
N = int(input().strip())
L_list = list(map(int, input().strip().split()))

ans=0
for i in range(N):
    for j in range(i,N):
        for k in range(j,N):
            e1 = L_list[i]
            e2 = L_list[j]
            e3 = L_list[k]
            if e1 != e2 and e2 != e3 and e1 != e3:
                edge_list = sorted([e1,e2,e3])
                if edge_list[2] - edge_list[1] < edge_list[0]:
                    ans += 1
print(ans)

Measured memory_bytes: 9208
#include <iostream>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>

using namespace std;

int main(int argc, const char * argv[]) {
	int N, M;
	long int sum = 0;
	long int tmp;

	cin >> N >> M;
	priority_queue<long int> A;

	for(int i=0; i<N; i++){
		cin >> tmp;
		A.push(tmp);
	}

	for(int i=0; i<M; i++){
		A.push(A.top() / 2);
		A.pop();
	}

	while (!A.empty()) {
		sum += A.top();
		A.pop();
	}
	cout << sum << endl;

	return 0;
}


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


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

   long long n,k;
   cin>>n>>k;

   long long a[n];
   for(long long i=0; i<n; i++)
   	cin>>a[i];
   sort(a,a+n);

   long long sum=0;

   for(long long i=0; i<k; i++)
     sum+=a[i];

   cout<<sum<<endl;

 }

Measured memory_bytes: 3684
#include <stdio.h>
int A[50];
int solve(int i,int m,int n){
  if(m==0) return 1;
  if(i>=n) return 0;
  int res=solve(i+1,m,n) || solve(i+1,m-A[i],n);
  return res;
}
int main(){
  int i,q,M,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M);
    if(solve(0,M,n)) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

Measured memory_bytes: 580
//
//  main.cpp
//  ABC_064_C
//
//  Created by Joe Mori on 2020/06/05.
//  Copyright © 2020 Joe Mori. All rights reserved.
//

#include<bits/stdc++.h>
int main() {
    // insert code here...
    int N,min_color=0,max_color=0;
    std::cin>>N;
    std::vector<int> a(N),count(9,0);
    for(int i=0;i<N;i++){
        std::cin>>a[i];
        if(0<a[i]&&a[i]<400){
            count[0]++;
        }else if(399<a[i]&&a[i]<800){
            count[1]++;
        }else if(799<a[i]&&a[i]<1200){
            count[2]++;
        }else if(1199<a[i]&&a[i]<1600){
            count[3]++;
        }else if(1599<a[i]&&a[i]<2000){
            count[4]++;
        }else if(1999<a[i]&&a[i]<2400){
            count[5]++;
        }else if(2399<a[i]&&a[i]<2800){
            count[6]++;
        }else if(2799<a[i]&&a[i]<3200){
            count[7]++;
        }else if(3199<a[i]){
            count[8]++;
        }
    }
    for(int i=0;i<8;i++){
        if(count[i]!=0)min_color++;
    }
    max_color=count[8]+min_color;
    if(min_color==0)min_color=1;
    std::cout<<min_color<<" "<<max_color<<std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  while (N) {
    N /= K;
    ++ans;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3616
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

s = list(input())

s[3] = "8"

print("".join(s))





Measured memory_bytes: 9076
fn main() {
    proconio::input! {
        n: i64,
        x: i64,
        y: i64,
    }
    let mut hm = std::collections::HashMap::new();
    for i in 1..n {
        for j in i + 1..=n {
            let not_use_xy = j - i;
            let use_x_y = (x - i).abs() as i64 + 1 + (j - y).abs() as i64;
            let use_y_x = (y - i).abs() as i64 + 1 + (j - x).abs() as i64;
            let min = [not_use_xy, use_x_y, use_y_x]
                .iter()
                .cloned()
                .min()
                .unwrap();
            *hm.entry(min).or_insert(0) += 1;
        }
    }
    for k in 1..n {
        println!("{}", hm.get(&k).or(Some(&0)).unwrap());
    }
}


Measured memory_bytes: 2268
#include<iostream>
#include<algorithm>


using namespace std;

int main(void){
    
    int line[12];
    
    for(int i = 0;i < 12;i++){
        
        cin >> line[i];
        
    }
    
    sort(line,line+12);
    
   
    
    for(int i = 0;i < 3;i++){
        
        for(int j = 1;j < 4;j++)
            
            if(line[4 * i ] != line[4 * i + j ]){ cout << "no" << endl; return 0;}
            
        
            
        }
            
            
      cout << "yes" << endl;


return 0;

}
         
    


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

int main() {
  int n; cin >> n;
  string s; cin >> s;
  map<char,int> l,r;
  int ans = 0, cnt = 0;
  rep(i,n) r[s[i]]++;
  rep(i,n-1) {
    if (!l.count(s[i])) cnt++;
    l[s[i]]++;
    r[s[i]]--;
    if (r[s[i]] == 0) cnt--;
    ans = max(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

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

int dp[3001][3001];
int par[3001][3001];
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  string a, b;
  cin >> a >> b;
  par[0][0] = 1;
  for (int i = 0; i < a.size(); i++)
    for (int j = 0; j < b.size(); j++) {
      if (a[i] == b[j]) {
	dp[i][j] = (i&&j ? dp[i-1][j-1] : 0)+1;
	par[i][j] = 3;
      }
      if (i && dp[i-1][j] >= dp[i][j]) {
	dp[i][j] = dp[i-1][j];
	par[i][j] = 1;
      }
      if (j && dp[i][j-1] >= dp[i][j]) {
	dp[i][j] = dp[i][j-1];
	par[i][j] = 2;
      }
    }
  int i = a.size()-1, j = b.size()-1;
  //cout << dp[i][j] << endl;
  string ans;
  while (i >= 0 && j >= 0) {
    if (par[i][j] == 3)
      ans += a[i];
    int icp = i;
    i -= par[i][j]%2;
    j -= par[icp][j]/2;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}


Measured memory_bytes: 70656
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		var m = sc.nextInt();
		var h = new int[n];
		var a = new int[m];
		var b = new int[m];
		for (var i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		for (var i = 0; i < m; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		sc.close();

		var set = new HashSet<Integer>();
		for (var i = 0; i < m; i++) {
			int ai = a[i] - 1;
			int bi = b[i] - 1;
			if (h[ai] > h[bi]) {
				set.add(b[i]);
			} else if (h[ai] < h[bi]) {
				set.add(a[i]);
			} else {
				set.add(a[i]);
				set.add(b[i]);
			}
		}

		System.out.println(n - set.size());
	}
}

Measured memory_bytes: 61984
#include <stdio.h>

int main() {
  char ans, temp;
  scanf("%c", &temp);
  switch(temp) {
    case 'A':
      ans = 'T';
      break;
    case 'T':
      ans = 'A';
      break;
    case 'C':
      ans = 'G';
      break;
    case 'G':
      ans = 'C';
      break;
  }
  printf("%c\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
#include <cstdint>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
#define mod 1000000007
typedef long long ll;

unsigned gcd(int a, int b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}


ll comb(int n, int r) {
	if (r * 2 > n) r = n - r;
	uintmax_t dividend = 1;
	uintmax_t divisor = 1;
	for (unsigned int i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}

int compare_char(const void* left, const void* right) {
	char *left_char = (char *)left;
	char *right_char = (char *)right;

	return strcmp(left_char, right_char);
}

int main(){

	//int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
	ll i, j, k, l, m, n, len, a, b, c;
	ll A, B, C, D, Ntemp, M, K,num_R,num_G,num_B;
	ll sum = 0, sum_B = 0, sum_C = 0, max, min, count=0, N, W;
	ll **dp;
	char S[200000];
	int ans;

	int X, Y, Z;
	cin >> X >> Y >> Z;
	swap(X, Y);
	swap(X, Z);
	cout << X << " " << Y << " " << Z << endl;
	return 0;


}
    

Measured memory_bytes: 256
// Copyright 2020 yaito3014
#include <iostream>
#include <string>
#include <map>

int main() {
  int N;
  std::cin >> N;
  std::map<std::string, int> m;
  for (int i = 0; i < N; ++i) {
    std::string S;
    std::cin >> S;
    ++m[S];
  }
  std::cout << "AC x " << m["AC"] << '\n';
  std::cout << "WA x " << m["WA"] << '\n';
  std::cout << "TLE x " << m["TLE"] << '\n';
  std::cout << "RE x " << m["RE"] << '\n';
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>

using namespace std;

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

struct edge{int to, cost;};

int per[8];
int dp[201][200][200];
int n, m, R;
int r[8];


int func(){
    int res = 0;
    for (int i = 0; i < R - 1; i++){
        res += dp[n][r[per[i]]][r[per[i+1]]];
    }
    return res;
}



int main(){
    int const INF = 1000000000;
    
    cin >> n >> m >> R;
    rep(i, R) {cin >> r[i]; r[i]--;}
    int a, b, c;
    
    rep(i, n)rep(j, n) dp[0][i][j] = INF;
    rep(i, n) dp[0][i][i] = 0;
    rep(i, m){
        cin >> a >> b >> c;
        a--; b--;
        dp[0][a][b] = c;
        dp[0][b][a] = c;
    }

    rep(k, n)rep(i, n)rep(j, n){
        dp[k+1][i][j] = min(dp[k][i][j], dp[k][i][k] + dp[k][k][j]);
    }
    
    int ans = INF;
    rep(i, R) per[i] = i;
    do{
        ans = min(ans, func());
    }while(next_permutation(per, per + R));

    cout << ans << endl;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
string mp[20],str;
int dir[256],h,w,m;
char ch[4]={'^','>','v','<'};
int dx[]={0,1,0,-1},dy[]={-1,0,1,0};
 
int get_d(char a){
  if(a=='U') return 0;
  if(a=='R') return 1;
  if(a=='D') return 2;
  if(a=='L') return 3;
  return -1;
}
 
void shoot(int x,int y,int d){
  while(1){
    x+=dx[d],y+=dy[d];
    if(x<0||y<0||x>=w||y>=h||mp[y][x]=='#')return;
    if(mp[y][x]=='*'){
      mp[y][x]='.';
      return;
    }
  }
 
}
 
void update(int x,int y,int d){
  mp[y][x]='.';
  for(int i=0;i<m;i++){
    int pd=d,nx,ny;
    d=get_d(str[i]);
    if(d==-1){d=pd,shoot(x,y,d);continue;}
 
    nx=x+dx[d],ny=y+dy[d];
    if(nx<0||ny<0||nx>=w||ny>=h||mp[ny][nx]!='.')nx=x,ny=y;
    y=ny,x=nx;
  }
  mp[y][x]=ch[d];
}
 
int main(){
  memset(dir,-1,sizeof(dir));
  dir['^']=0,dir['>']=1,dir['v']=2,dir['<']=3;
 
  int q;
  cin>>q;
  while(q--){
    cin>>h>>w;
    for(int i=0;i<h;i++) cin>>mp[i];
    cin>>m>> str;
 
    for(int i=0;i<h;i++){
      int f=0;
      for(int j=0;j<w;j++) 
    if(dir[mp[i][j]]!=-1) {
      update(j,i,dir[mp[i][j]]);
      f=1;
      break;
    }
      if(f)break;
    }
 
    for(int i=0;i<h;i++)cout <<mp[i]<<endl;
    if(q) cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
/*input
2 1 2
1 2
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

vector<vector<int>> adj;
vector<int> distu;
vector<int> distv;
vector<bool> leaf;

void dfs(int v, int p, bool flag)
{
	if(adj[v].size() == 1) leaf[v] = 1;
	for(int i = 0; i < adj[v].size(); i++) if(adj[v][i] != p)
	{
		if(!flag) distu[adj[v][i]] = distu[v] + 1;
		else distv[adj[v][i]] = distv[v] + 1;
		dfs(adj[v][i], v, flag);
	}
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, u, v; cin >> n >> u >> v;
    u--; v--;
    adj.resize(n);
    distu.resize(n);
    distv.resize(n);
    leaf.resize(n);
    distu[u] = 0;
    distv[v] = 0;
    for(int i = 0; i < n; i++) leaf[i] = 0;
    for(int i = 0; i < n - 1; i++)
    {
    	int a, b; cin >> a >> b;
    	a--; b--;
    	adj[a].push_back(b);
    	adj[b].push_back(a);
    }
    dfs(u, -1, 0);
    dfs(v, -1, 1);
    int best = 0;
   	for(int i = 0; i < n; i++) if(leaf[i] && (distu[i] < distv[i]))
   		best = max(best, distv[i] - 1);
   	cout << best;

    return 0;
}

Measured memory_bytes: 12928
#include<bits/stdc++.h>
#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 EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
typedef long long ll;

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    for(int i = 0; i < s.length(); i++) {
        if(i%2==1){
            if(s[i]=='R'){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else if(i%2==0){
            if(s[i]=='L'){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>

using namespace std;

int main() {
    long int n, max = 0, min = 0, sum = 0;
    long int *a = new long int[n];
    
    cin >> n;
    
    for(int i = 0; i < n; i++) cin >> a[i];
    
    for(int i = 0; i < n; i++) {
        if(i == 0) {
            min = a[i];
            max = a[i];
            sum = a[i];
        } else {
            if(a[i] < min) min = a[i];
            if(a[i] > max) max = a[i];
            
            sum += a[i];
        }
    }
    cout << min << " " << max << " " << sum << endl;
}

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

int main(){
  int a,b,k,j=0;cin>>a>>b>>k;
  vector<int> x(100,0);
  for(int i=1;i<=min(a,b);i++) if((!(a%i))&&(!(b%i))){
    x.at(j)=i;
    j++;
  }
  sort(x.begin(),x.end(),greater<int>());
  cout<<x.at(k-1);
}

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

int main(){
 
  string s;
  
  cin>>s;
  
 if(s=="SUN")cout<<7<<endl;
          
   if(s=="MON")cout<<6<<endl;
         
 if(s=="TUE")cout<<5<<endl;
         
  if(s=="WED")cout<<4<<endl;
         
  if(s=="THU") cout<<3<<endl;
         
  if(s=="FRI") cout<<2<<endl;
          
  if(s=="SAT")  cout<<1<<endl;
   
  return 0;
}


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

int main() {
    
    

    vector<int> BingoCard(9);
    for (int i = 0; i < 9; i++) {
        cin >> BingoCard.at(i);
    }
  
    int N;
    cin>>N;

    vector<int> atari(N);
    for (int i = 0; i < N; i++) {
      cin >> atari.at(i);
    }

    for(int i=0;i<N;i++){
        for(int j=0;j<9;j++){
            if(atari.at(i) == BingoCard.at(j)){
                BingoCard.at(j)=0;
            }
        }
    }

    if(BingoCard.at(0)==0 && BingoCard.at(1)==0 && BingoCard.at(2)==0){
        cout<<"Yes"<<endl;
    }
    else if(BingoCard.at(3)==0 && BingoCard.at(4)==0 && BingoCard.at(5)==0){
        cout<<"Yes"<<endl;
    }
    else if(BingoCard.at(6)==0 && BingoCard.at(7)==0 && BingoCard.at(8)==0){
        cout<<"Yes"<<endl;
    }
    else if(BingoCard.at(0)==0 && BingoCard.at(3)==0 && BingoCard.at(6)==0){
        cout<<"Yes"<<endl;
    }
    else if(BingoCard.at(1)==0 && BingoCard.at(4)==0 && BingoCard.at(7)==0){
        cout<<"Yes"<<endl;
    }
    else if(BingoCard.at(2)==0 && BingoCard.at(5)==0 && BingoCard.at(8)==0){
        cout<<"Yes"<<endl;
    }
    else if(BingoCard.at(0)==0 && BingoCard.at(4)==0 && BingoCard.at(8)==0){
        cout<<"Yes"<<endl;
    }
    else if(BingoCard.at(2)==0 && BingoCard.at(4)==0 && BingoCard.at(6)==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N=int(input())
l=[["a",-1] for i in range(N)]

for i in range(N):
    a,b=map(str,input().split())
    b=int(b)
    l[i]=[a,200-b,i+1]

l.sort()

for i in range(N):
    print(l[i][2])

Measured memory_bytes: 3060
class Dice:
    def __init__(self,a,b,c,d,e,f):
        self.face1 = a
        self.face2 = b
        self.face3 = c
        self.face4 = d
        self.face5 = e
        self.face6 = f

    def above_face(self):
        return self.face1

    def roll(self, order):
        if order == 0:
            tmp = self.face1
            self.face1 = self.face2
            self.face2 = self.face6
            self.face6 = self.face5
            self.face5 = tmp
        elif order == 1:
            tmp = self.face1
            self.face1 = self.face5
            self.face5 = self.face6
            self.face6 = self.face2
            self.face2 = tmp
        elif order == 2:
            tmp = self.face1
            self.face1 = self.face3
            self.face3 = self.face6
            self.face6 = self.face4
            self.face4 = tmp
        else:
            tmp = self.face1
            self.face1 = self.face4
            self.face4 = self.face6
            self.face6 = self.face3
            self.face3 = tmp

a,b,c,d,e,f = map(int,input().split())
dice1 = Dice(a,b,c,d,e,f)
q = int(input())
import random
for i in range(q):
    A,B = map(int,input().split())
    while True:
        dice1.roll(random.randint(0, 3))
        if dice1.face1 == A and dice1.face2 == B:
            break
    print(dice1.face3)



Measured memory_bytes: 8184