akhauriyash/Code-Regression huggingface dataset:
/* ex5_4
  kt125*/

#include<stdio.h>
#include<string.h>

int main(void){
    int count = 0, ans=0;
    char str[11], *ptr;
    scanf("%s", &str[0]);

    //'A','G','C','T'の全てを'X'に置き換える。
    for(int i= 0; i< strlen(str);i++){
        if(str[i] == 'A' || str[i] == 'C' ||
           str[i] == 'G' || str[i] == 'T'){
               str[i] = 'X';
        }
    }
    ptr = str; //strの先頭アドレスをptrに渡す
    //連続する'X'の最大数ansを求める
    while(*ptr){
        if( *ptr == 'X'){ 
            count++;
            if(ans < count) ans = count;
        }else{ //'X'以外の文字が出たらcountをリセット
            count = 0;
        }
        ptr++;
    }

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll h,w,m;cin>>h>>w>>m;
    vector<P> place(m);
    vector<ll> cnt1(3*100000+10),cnt2(3*100000+10);

    rep(i,m) cin>>place[i].fi>>place[i].se;
    
    map<P,bool> check;

    rep(i,m){
        cnt1[place[i].fi]++;
        cnt2[place[i].se]++;

        check[place[i]]=true;
    }

    vector<P> p1,p2;
    rep(i,3*100000+10){
        if(cnt1[i]!=0) p1.push_back({cnt1[i],i});
        if(cnt2[i]!=0) p2.push_back({cnt2[i],i});
    }

    ll ans=0,num=0;
    sort(p1.begin(),p1.end(),greater<P>());
    sort(p2.begin(),p2.end(),greater<P>());

    rep(i,p1.size()){
        rep(j,p2.size()){
            chmax(ans,p1[i].fi+p2[j].fi-check[{p1[i].se,p2[j].se}]);
            if(num>m*2) break;
            num++;
        }
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 97152
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	int n,q;
	int[] A,m;
	
	public void input() {
		n = sc.nextInt();
		A = new int[n];
		for(int i=0; i<n; i++) A[i] = sc.nextInt();
		
		q = sc.nextInt();
		m = new int[q];
		for(int i=0; i<q; i++) m[i] = sc.nextInt();
	}
	
	//mは作りたい数。ここでは配列mに格納されている値のこと。
	public int solve(int i, int m) {
		if(m == 0) return 1;//true
		if(i >= n) return 0;//false
		if(solve(i+1,m)==1 || solve(i+1,m-A[i])==1) return 1;
		else return 0;
	}
	
	public void answer() {
		for(int i=0; i<q; i++) {
			int k=0;
			if(solve(k,m[i]) == 1) System.out.println("yes");
			else System.out.println("no");
		}
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
		obj.answer();
	}
}



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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<char> c(n);
  int rc = 0;
  rep(i, n) {
    char cc;
    cin >> cc;
    c.at(i) = cc;
    if (cc == 'R') {
      rc++;
    }
  }
  int rc2 = 0;
  rep(i, rc) {
    char cc = c.at(i);
    if (cc == 'R') {
      rc2++;
    }
  }
  int res = rc - rc2;
  cout << res << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

void max_self(int &a, int b){
	a = max(a, b);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s, t;
	cin >> s>>t;
	int n = s.length(), m = t.length();
	vector<vector<int>>dp(n + 1, vector<int>(m + 1,0));
	for(int i = 1; i <= n ;++i){
		for(int j = 1; j <= m; ++j){
			max_self(dp[i][j], dp[i - 1][j]);
			max_self(dp[i][j], dp[i][j - 1]);
			if(s[i - 1] == t[j - 1]){
				max_self(dp[i][j], dp[i - 1][j - 1] + 1);
			}
		}
	}
	string ans = "";
	int i = n, j = m;
	while(i && j){
		if(dp[i][j] == dp[i -1][j - 1] + 1 && s[i - 1] == t[j - 1]){
			ans += s[i - 1];
			i--, j--;
			continue;
		}
		if(dp[i][j] == dp[i - 1][j]){
			i = i - 1;
			continue;
		}
		if(dp[i][j] == dp[i][j - 1]){
			j = j - 1;
			continue;
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
	return 0;
}


Measured memory_bytes: 36480
import std.stdio;
import std.algorithm;
import std.range;
import std.typecons;

void main(){
    int h, w;
    while(~scanf("%d%d", &h, &w)){
        auto g = new int[][](h, w);
        alias Tuple!(int,int) idx;
        idx[] ds;
        foreach(i; 0..h){
            foreach(j; 0..w){
                scanf("%d", &g[i][j]);
                ds ~= idx(i, j);
            }
        }
        ds.sort!((a, b) => g[a[0]][a[1]] < g[b[0]][b[1]]);

        auto to = new int[][](h, w);
        foreach(r; to) r[] = -1;

        foreach(t; ds){
            int i = t[0], j = t[1];
            int[] s = [];
            foreach(d; [[0,1],[0,-1],[1,0],[-1,0]]){
                int ni = i + d[0];
                int nj = j + d[1];
                if(0 <= ni && ni < h && 0 <= nj && nj < w){
                    if(g[ni][nj] < g[i][j]){
                        s ~= to[ni][nj];
                    }
                }
            }
            s = uniq(sort(s)).array;
            if(s.length == 0){
                to[i][j] = g[i][j];
            } else if(s.canFind(-10)){
                to[i][j] = -10;
            } else {
                to[i][j] = s.length == 1 ? s[0] : -10;
            }
        }
        writeln(to.map!((x) => x.count(-10)).sum);
    }
}

Measured memory_bytes: 26456
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;


int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a _ b _ c;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
	}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int n;
	double x,ans=0;
	string u;
	cin >> n;
	rep(i,n){
		cin >> x >> u;
		ans+=(u=="JPY"?x:x*380000);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
def solve():
    n = int(input())
    A = list(map(int, input().split()))
    B = [0] + list(map(int, input().split()))
    C = [0] + list(map(int, input().split()))
    last = -1
    ans = 0
    for i in A:
        ans += B[i]
        if last + 1 == i:
            ans += C[last]
        last = i
    print(ans)
solve()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;

  cin >> n;
  for (int i = 0; i < n; i++) cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;
  return 0;
}


Measured memory_bytes: 3848
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	map<char,int> ct;
	for (const char ch:s)
		ct[ch]++;
	cout<<(ct['1'])<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define sort_v(a) sort(a.begin(), a.end())

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

int main()
{
    int n;
    int l[100];

    cin >> n;
    rep(i, 0, n) cin >> l[i];

    sort(l, l + n);
    int sum = 0;
    rep(i, 0, n - 1) sum += l[i];
    if (l[n - 1] < sum)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
const double PI = 3.1415926535898;
double a, b, x, s, c, ans;
int main()
{
    std::cin>>a>>b>>x;
    s = x/a;
    if(2*s > a*b)
    {
    	s = a*b - s;
        ans = atan(2*s/a/a);
    }
    else if(2*s <= a*b)
    {
        ans = atan(b/2*b/s);
    }
    else
    {
        puts("45.0000000000");
        return 0;
    }
    ans = ans*180/PI;
    printf("%.10lf", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

const int maxn=1e2+10;

const int maxv=1e5+10;

const int maxv1=1e9;

long long int dp[maxn][maxv];


int main()
{
    int n,w1,v1=0;
    cin>>n>>w1;
    int w[n+1],v[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
        v1+=v[i];
    }
    dp[0][0];
    for(int i=1;i<=v1;i++)
    {
         dp[0][i]=maxv1;
     //   cout<<dp[1][i]<<" ";
    }
 //   cout<<endl;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=v1;j++)
        {
            if(v[i]>j)
            {
                dp[i][j]=dp[i-1][j];
            }
            else dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
        //    cout<<dp[i][j]<<" ";
        }
      //  cout<<endl;
    }
    int o;
    for(int i=0;i<=v1;i++)
    {
        if(dp[n][i]<=w1)
            o=i;
    }
    cout<<o;
	return 0;
}


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

class dice {
public:
	int d1, d2, d3, d4, d5, d6, tmp;

	void set(int a1,int a2, int a3, int a4, int a5, int a6) {
		d1 = a1;
		d2 = a2;
		d3 = a3;
		d4 = a4;
		d5 = a5;
		d6 = a6;
	}
	void n(void) {
		tmp = d1;
		d1 = d2;
		d2 = d6;
		d6 = d5;
		d5 = tmp;
	}
	void s(void) {
		tmp = d1;
		d1 = d5;
		d5 = d6;
		d6 = d2;
		d2 = tmp;
	}
	void e(void) {
		tmp = d1;
		d1 = d4;
		d4 = d6;
		d6 = d3;
		d3 = tmp;
	}
	void w(void) {
		tmp = d1;
		d1 = d3;
		d3 = d6;
		d6 = d4;
		d4 = tmp;
	}
};


int main() {

	dice dice1,dice2;
	std::string c;
	int a[7], i,j,f,u,n,found=0;

		for (i = 1; i < 7; i++) {
			std::cin >> a[i];
		}
		dice1.set(a[1], a[2], a[3], a[4], a[5], a[6]);

		for (i = 1; i < 7; i++) {
			std::cin >> a[i];
		}
		dice2.set(a[1], a[2], a[3], a[4], a[5], a[6]);

		
			c = "EEENEEENEEESEEESEEENEEEN";

			for (j = 0; j < c.size(); j++) {

				if ((dice2.d1 == dice1.d1) && (dice2.d2 == dice1.d2) && (dice2.d3 == dice1.d3) && (dice2.d4 == dice1.d4) && (dice2.d5 == dice1.d5) && (dice2.d6 == dice1.d6)) {
					found = 1;
					break;
				}

				if (c[j] == 'N') dice2.n();
				else if (c[j] == 'S')dice2.s();
				else if (c[j] == 'E')dice2.e();
				else if (c[j] == 'W')dice2.w();
				else std::cout << "Error" << std::endl;
			}
						
			if (found==1)std::cout << "Yes" << std::endl;
			else std::cout << "No" << std::endl;

	return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair< int, int > P;
typedef pair< int, P > PP;

//-------------------------------------------------

int r;

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

	cin >> r;
	cout << (r < 1200 ? "ABC" : r < 2800 ? "ARC" : "AGC") << endl;

	return 0;
}



Measured memory_bytes: 256
def func(cur, use):
  
  global counter
  if (cur > N): return 
  if (use == 0b111): counter += 1

  func(cur * 10 + 7, use | 0b001)
  func(cur * 10 + 5, use | 0b010)
  func(cur * 10 + 3, use | 0b100) 

N = int(input())
counter = 0
func(0, 0)
print(counter)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lb long double
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < int , int >
#define pq priority_queue

using namespace std;

const int N = 20;
const int M = 1000000007;
const lb PI = acos(-1);

int n , m , x;
int a[20][20];
int ab[20];

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

    int i , j , t , minprice = INT_MAX , price;

    cin >> n >> m >> x;

    for(i = 0 ; i < n ; i++)
        for(j = 0 ; j <= m ; j++)
            cin >> a[i][j];

    for(i = 1 ; i <= (1 << n) - 1 ; i++)
    {
        price = 0;

        for(j = 1 ; j <= 20 ; j++)
            ab[j] = 0;

        for(j = 0 ; j < n ; j++)
            if((i >> j) & 1)
            {
                price += a[j][0];

                for(t = 1 ; t <= m ; t++)
                    ab[t] += a[j][t];
            }


        for(t = 1 ; t <= m ; t++)
            if(ab[t] < x)
                break;

        if(t == m + 1)
            minprice = min(minprice , price);
    }

    cout << (minprice == INT_MAX ? -1 : minprice);

    return 0;
}


Measured memory_bytes: 3660
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 98765432198765432
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

char s[100][101];
int main() {
  puts("100 100");
	int a,b;
	scanf("%d%d",&a,&b);
	a--,b--;
	fup(i,0,99,1)
	{
		fup(j,0,99,1)
			s[i][j]=(i<50?'#':'.');
	}
	fup(i,1,49,2)
	{
		fup(j,1,99,2)
			if(a>0)s[i][j]='.',a--;
	}
	fup(i,51,99,2)
	{
		fup(j,1,99,2)
			if(b>0)s[i][j]='#',b--;
	}
	fup(i,0,99,1)printf("%s\n",s[i]);
}

Measured memory_bytes: 256
n = int(input())
data = [input() for i in range(n)]
ans = 0
for a in range(n):
    b = 0
    t = True
    for i in range(n):
        for j in range(n):
            if data[(i + a) % n][(j + b) % n] != data[(j + a) % n][(i + b) % n]:
                t = False
                break

    if t:
        ans += n

print(ans)

Measured memory_bytes: 42456
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    
    if (a+b == c || a+c == b || b+c == a)cout << "Yes" <<endl;
    else cout << "No" << endl;
    
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include "stack"
using namespace std;
const int MAXN = 2e5;
const int INF = 1e9 + 7;
/*
void init(int x, int l, int r) {
    if (l == r) {
        tree[x] = INF;
    } else {
        int mid = (l + r) / 2;
        init(x + x, l, mid);
        init(x+x+1, mid + 1, r);
        tree[x] = min(tree[x + x], tree[x + x + 1]);
    }
}
int get(int x, int l, int r, int tl, int tr) {
    if (r < tl || tr < l) {
        return INF;
    }
    if (tl <= l && r <= tr) {
        return tree[x];
    }
    int mid = (l + r) / 2;
    return min(get(x + x, l, mid, tl, tr), get(x+x+1, mid + 1, r, tl, tr));
}
void upd(int x, int l, int r, int pos, int val) {
    if (l == r) {
        tree[x] = min(tree[x], val);
    } else {
        int mid = (l + r) / 2;
        if (pos <= mid) {
            upd(x + x, l, mid, pos, val);
        } else {
            upd(x+x+1, mid + 1, r, pos, val);
        }
        tree[x ] =min(tree[x + x], tree[x + x +1]);
    }
}

*/
int a[200];
int fre;
int main() {
    int n;
    string st;
    cin >> n >> st;
    string ans = "";
    stack <char> s;
    for (int i = 0; i < n; i++) {
        if (st[i] == '(') {
            s.push('(');
        } else if (s.empty()) {
            ans += "(";
        } else {
            s.pop();
        }
    }
    while (!s.empty()) {
        st += ")";
        s.pop();
    }
    cout << ans << st;
    return 0;
}


Measured memory_bytes: 256
//“Failure is unimportant. It takes courage to make a fool of yourself.”
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
#define int long long int
#define P 1000000007
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define bac(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define N 200005
#define PI 3.14159265359
#define inf LLONG_MAX
using namespace __gnu_pbds;
using namespace std;

vl adj[N],par[N];
ll vis[N], indeg[N];

signed main() {
    teevra_gati
    
    ll n,m;
    cin>>n>>m;
    vl dp(n+1,0);
    f(i,0,m){
        ll x,y;
        cin>>x>>y;
        adj[x].pb(y);
        par[y].pb(x);
        indeg[y]++;
    }
    queue<ll> q;
    f(i,1,n+1) if(indeg[i]==0) q.push(i);
    while(!q.empty()){
        ll f = q.front();
        q.pop();
        for(auto u:adj[f]){
                indeg[u]--;
                if(indeg[u]==0) q.push(u);
                dp[u] = max(dp[u], 1 + dp[f]);
        }
    }
    ll ans=0;
    f(i,1,n+1) ans = max(ans, dp[i]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 18560
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n;
  cin>>n;
  vector<long> v(n);
  rep(i,n) cin>>v[i];

  cout << accumulate(all(v), 0L) - *max_element(all(v))/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  ll n, k; cin>>n>>k;
  vector<ll> p(n);
  rep(i, n) cin>>p.at(i);
  sort(p.begin(), p.end());
  ll cnt=0;
  rep(i, k) cnt+=p.at(i);
  cout<<cnt;
}

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

int main(){
    long long a,b,c,d;
    cin>>a;
    vector<vector<long long>>v1(a+1,vector<long long>(3));
    for(long long i=0;i<a;i++){
        vector<long long>v;
        cin>>b>>c>>d;
        v.push_back(b);
        v.push_back(c);
        v.push_back(d);
        for(long long j=0;j<3;j++){
            for(long long k=0;k<3;k++){
                if(j!=k)v1[i+1][j]=max(v1[i+1][j],v1[i][k]+v[j]);
            }
        }
    }
    long long ans=0;
    for(long long i=0;i<3;i++){
        ans=max(ans,v1[a][i]);
    }
    cout<<ans;
}


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

int main() {
    int N,score_A, score_B, def, ans;
    cin >> N;
    vector <int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    
    score_A = 0;
    score_B = 0;
    
    for(int i = 0; i < A.size(); i+=2){
        score_A += A.at(i);
    }
    for(int i = 1; i < A.size(); i+=2){
        score_B += A.at(i);
    }
    def = score_A - score_B;
    ans = abs(def);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second

void solve(){
    int k,n; cin>>k>>n;
    vector<int> v(k);
    for(int i=0;i<k;i++) cin>>v[i];
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<n;i++) ans+=v[i];
    cout<<ans;
}
int main() {
    // int t; cin>>t;
    // while(t--){
        solve();
        // cout<<endl;
    // }
}

Measured memory_bytes: 3616
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,a,n) for(ll i=a;i<(ll)(n);i++)

int main(){
    int s;
    cin>>s;
    vector<int> A;
    int a = s;
    A.push_back(a);
    bool flag = false;
    for(int i=0;;i++){
        if(a%2 == 0){
            a = a/2;
        }else{
            a = 3*a+1;
        }
        A.push_back(a);
        if(a == 1 && flag) break;
        if(a == 1) flag = true;
    }

    rep(i, A.size()){
        FOR(j, i+1, A.size()){
            if(A[i] == A[j]){
                cout << j+1 << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class Program{
  public static void Main(){

    int n = int.Parse(Console.ReadLine());
    
    char[] alph = new char[26]{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    int[,] table = new int[n,26];
    
    for(int i=0; i<n; i++){
      string st = Console.ReadLine();
      for(int j=0; j<st.Length; j++){
        for(int k=0; k<26; k++){
          if(st[j] == alph[k]){
            table[i,k]++;
            break;
          }
        }
      }
    }
    
    for(int i=0; i<26; i++){
      int min = table[0,i];
      for(int j=0; j<n; j++){
        if(min > table[j,i]) min = table[j,i];
      }
      while(min>0){
        Console.Write(alph[i]);
        min--;
      }
    }
  }
}


Measured memory_bytes: 13140
#include <iostream>
#include<string>
#define lli long long int
using namespace std;

int main() {
	// your code goes here
	lli x,k,c,las;
	c=0;
	cin>>k;
	string s;
	cin>>s;
	for(lli i =0;i<s.size();i++){
		// cout<<s[i];
		if('Z'-(s[i]+k)>=0){
			cout<<(char)(s[i]+k);
		}
		else{
			cout<<(char)(s[i]-'Z'+'A'+k-1);
		}
	}
	// x='Z';
	// las=int('Z');
	// if('Z'-(s[0]+k)>=0)cout<<(char)(s[0]+2);
	// cout<<'Z'<<" "<<(s[0]+k);
	// SUN, MON, TUE, WED, THU, FRI, or SAT, 
	return 0;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int a,b;
int main(){
	cin>>a>>b;
	if(a<b)
	swap(a,b);
	rep(i,a)
	cout<<b;
	re 0;
}

Measured memory_bytes: 256
S = input()

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define N 100005
void fastio()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}
int main() {
	fastio();
	string a,b;
	ll cnt=0;
	cin>>a>>b;
	if(a[0]==b[0])
	cnt++;
	if(a[1]==b[1])
	cnt++;
	if(a[2]==b[2])
	cnt++;
	cout<<cnt;
	
	return 0;
}

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

template<class INT>
std::vector<INT> factorize(INT n){
    std::vector<INT> res;
    for (INT i = 1; i * i <= n; i++){
        if (n % i == 0){
            res.push_back(i);
            if (i * i != n)
                res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> A(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    auto F = factorize(accumulate(A.begin(), A.end(), 0));
    sort(F.begin(), F.end(), greater<int>());
    const auto g = [&](const auto &f) -> bool{
        vector<int> B(n);
        int border = 0;
        for (int i = 0; i < n; i++){
            B[i] = A[i] % f;
            border += min(B[i], f - B[i]);
            if (border > k + k)
                return false;
        }
        const auto S = accumulate(B.begin(), B.end(), 0);
        const auto i = S / f;
        nth_element(B.begin(), B.begin() + (n - i), B.end());
        return max(accumulate(B.begin(), B.begin() + (n - i), 0), S - accumulate(B.begin() + (n - i), B.end(), 0)) <= k;
    };

    for (const auto &f: F){
        if (g(f)){
            printf("%d\n", f);
            return 0;
        }
    }

    puts("0");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using edge = int;
using graph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;


int main() {
  ll  n;cin >>n;
  vector<vector<ll>> a(2, vector<ll>(n));
  for(int i = 0; i < 2*n; ++i){
    cin >>a[i/n][i%n];
  }
  vector<vector<ll>> sum(2,vector<ll> (n+1) );
  for(int i = 0; i < 2*n; ++i){
    sum[i/n][i%n+1]=sum[i/n][i%n]+a[i/n][i%n];
  }
  ll ans =0;
  for(int i = 0; i < n; ++i){
    ll tmp=sum[0][i+1]+sum[1][n]-sum[1][i];
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from copy import deepcopy

class Dice():

    def __init__(self):
        self.E = [4,2,1,6,5,3]
        self.N = [2,6,3,4,1,5]
        self.S = [5,1,3,4,6,2]
        self.W = [3,2,6,1,5,4]
        self.number = list(map(int,input().split()))
        ##self.order = "NNNNWNNNWNNNENNNENNNWNNN"

    def rotate(self,order):
        tmp = deepcopy(self.number)
        if order == "E":
            for i in range(6):
                self.number[i] = tmp[self.E[i]-1]
        elif order == "N":
            for i in range(6):
                self.number[i] = tmp[self.N[i]-1]
        elif order == "S":
            for i in range(6):
                self.number[i] = tmp[self.S[i]-1]
        elif order == "W":
            for i in range(6):
                self.number[i] = tmp[self.W[i]-1]
    
    def sidenum(self,x,y):
        for i in self.order:
            if self.number[1] == y and self.number[0] == x:
                print(self.number[2])
                break
            else:
                self.rotate(i)
    
    def check(self,other):
        flag = True
        for i in range(6):
            if self.number[i] != other.number[i]:
                flag = False
        return flag

if __name__ == "__main__":
    flag = False
    dice1 = Dice()
    dice2 = Dice()
    order = "NNNNWNNNWNNNENNNENNNWNNN"
    for i in order:
        dice1.rotate(i)
        if dice1.check(dice2):
            flag = True
            break
    if flag:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 6344
import sys
from collections import deque

sys.setrecursionlimit(10**7)


def BFS(s):
    color=["white" for _ in range(n)]
    D=[float("inf") for _ in range(n)]

    color[s-1]="gray"
    D[s-1]=0
    queue=deque([s-1])

    while len(queue)!=0:
        u=queue.popleft()
        for i in M[u]:
            if color[i]=="white":
                color[i]="gray"
                D[i]=D[u]+1
                queue.append(i)
        color[u]="black"

    return D


n,x,y=map(int,input().split())

M=[[] for _ in range(n)]
for i in range(n-1):
    M[i].append(i+1)
    M[i+1].append(i)
M[x-1].append(y-1)
M[y-1].append(x-1)

C=[0]*n
for i in range(n):
    for j in BFS(i+1)[i:]:
        C[j] +=1

for i in C[1:]:
    print(i)

Measured memory_bytes: 59356
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll X;
  cin >> X;
  bool flag = false;
  for (int A=-118; A<=119; A++) {
    for (int B=-119; B<=118; B++) {
      if (pow(A, 5)-pow(B, 5)==X) {
        cout << A << " " << B << endl;
        flag = true;
        break;
      }
    }
    if (flag) break;
  }
}

Measured memory_bytes: 4064
def is_prime(x):
    if x <= 1:
        return False
    i = 2
    while i * i <= x:
        if x % i == 0:
            return False
        i += 1
    return True

while True:
    try:
        N = int(input())
    except EOFError:
        break
    mx = 0
    mn = 0
    for i in range(N - 1,1,-1):
        if is_prime(i):
            mx = i
            break
    for i in range(N + 1,N * 2):
        if is_prime(i):
            mn = i
            break
    print(mx,mn)

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

using namespace std;

int main(void){
    int H, W;
    cin >> H >> W;
    vector<string> S(H+2);
    for(int i=0;i<W+2;i++){
        S[0] += ".";
        S[H+1] += ".";
    }
    for(int i=0;i<H;i++){
        string a;
        cin >> a;
        S[i+1] += "." + a + ".";
    }
    
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            int ans = 0;
            if(S[i-1][j-1] == '#') ans ++;
            if(S[i-1][j  ] == '#') ans ++;
            if(S[i-1][j+1] == '#') ans ++;
            if(S[i  ][j-1] == '#') ans ++;
            if(S[i  ][j+1] == '#') ans ++;
            if(S[i+1][j-1] == '#') ans ++;
            if(S[i+1][j  ] == '#') ans ++;
            if(S[i+1][j+1] == '#') ans ++;
            if(S[i][j] == '#') cout << "#";
            else cout << ans;
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//P2B
#include <bits/stdc++.h>
using namespace std;
int main(){
	int x;
	bool ok = 0;
	cin >> x;
	for(int i = 1;i <= 9;i++){
		if(!(x%i) and (x/i) >= 1 and (x/i) <= 9)ok = 1;
	}
	if(ok)cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	var s string

	fmt.Scan(&n)
	fmt.Scan(&s)

	r := "No"
	if n%2 == 0 {
		h := n / 2
		str1 := s[h:]
		str2 := s[:h]
		if str1 == str2 {
			r = "Yes"
		}
	}

	fmt.Println(r)
}


Measured memory_bytes: 512
s = input()
str_list = ["dream","dreamer","erase","eraser"]
for i in range(len(s) // 5):
    if s[-7:] == "dreamer":
        s = s[:-7]
    elif s[-6:] == "eraser":
        s = s[:-6]
    elif s[-5:] == "dream" or s[-5:] == "erase":
        s = s[:-5]
ans = "YES" if s == "" else "NO"
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}

mint dp[100005][2];

int main() {
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    rep(i,n) {
        if (s[i] == '1') {
            dp[i+1][0] += dp[i][0]*2;
            dp[i+1][1] += dp[i][0] + dp[i][1]*3;
        }
        else {
            dp[i+1][0] += dp[i][0];
            dp[i+1][1] += dp[i][1]*3;
        }
    }
    mint ans = dp[n][0] + dp[n][1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5332
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
int main(){
    int N,M;
    cin>>N>>M;
    vector<vector<int>> tree(3*N,vector<int>(0));
    for(int i=0;i<M;i++){
        int u,v;//[1,N]
        cin>>u>>v;
        //cout<<" "<<u<<" "<<v<<endl;
        tree.at(u-1).push_back(N+v-1);
        tree.at(N+u-1).push_back(2*N+v-1);
        tree.at(2*N+u-1).push_back(v-1);
    }
    int S,G;
    cin>>S>>G;
    vector<int> dist(3*N,-1);
    queue<int> que;
    dist[S-1]=0;
    que.push(S-1);
    while(!que.empty()){
        int v=que.front();
        que.pop();
        for(int i=0;i<(int)tree.at(v).size();i++){
            int nv=tree.at(v).at(i);
            if(dist[nv]!=-1 && dist[nv]<=dist[v]+1){
                continue;
            }
            dist[nv]=dist[v]+1;
            que.push(nv);
        }
    }
    if(dist[G-1]==-1){
        cout<<dist[G-1]<<endl;
    }
    else{
        cout<<dist[G-1]/3<<endl;
    }
}

Measured memory_bytes: 20904
import math

menu_time = [int(input()) for i in range(5)]
mini_index = -1
mini_val = float('inf')

for i in range(len(menu_time)):
    tmp = menu_time[i] - (menu_time[i] // 10 * 10)

    if (0 < tmp < mini_val):
        mini_index = i
        mini_val = tmp

time = 0

for i in range(len(menu_time)):

    if (i != mini_index):
        t = math.ceil(menu_time[i] / 10) * 10
        time += t
    else:
        time += menu_time[i]

print(time)

Measured memory_bytes: 3188
import Data.List

split :: Int -> [Int] -> [[Int]]
split _ [] = []
split n x = take n x : split n (drop n x)

main = getContents >>= mapM_ (putStrLn . unwords . map show). (\([f,s,t]:xs) -> split t $ [sum $ zipWith (*) x y | x <- take f xs, y <- transpose $ drop f xs]) . map (map read . words) . lines

Measured memory_bytes: 12312
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<sstream>
#include<set>
#include<map>
#include<algorithm>
#include<cassert>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define fr(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair

int n,m,b[200],d[200][200];
int target(int t){
	if(t<n){
		t+=n;
		if(b[t]==0)return t;
		if(b[t]==1){
			for(;t+1<2*n&&b[t+1]==1;t++);
			return t;
		}
		for(;t>n&&b[t]==2;t--);
		return t;
	}
	t-=n;
	if(b[t]==0)return t;
	if(b[t]==1){
		for(;t+1<n&&b[t+1]==1;t++);
		return t;
	}
	for(;t>0&&b[t]==2;t--);
	return t;
}
int main(){
	while(cin>>n,n){
		m=2*n;
		rep(i,m)rep(j,m)d[i][j]=i!=j?1<<29:0;
		rep(i,m)cin>>b[i];
		rep(i,m)for(int j=0;j<3&&i%n+j<n;j++)d[i][target(i+j)]=1;
		
		int s=0;
		for(;s+1<n&&b[s]==1&&b[s+1]==1;s++);
		d[0][s]=0;
		for(s=n;s+1<2*n&&b[s]==1&&b[s+1]==1;s++);
		d[n][s]=0;
		
		rep(k,m)rep(i,m)rep(j,m)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		int ans=min(min(d[0][n-1],d[0][2*n-1]),min(d[n][n-1],d[n][2*n-1]));
		if(ans==1<<29)cout<<"NA"<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

template <class Tp>
constexpr Tp inf = Tp(1) << (8*sizeof(Tp)-3);

int main() {
  size_t N, M, R;
  scanf("%zu %zu %zu", &N, &M, &R);

  std::vector<intmax_t> r(R);
  for (auto& ri: r) {
    scanf("%jd", &ri);
    --ri;
  }

  std::vector<std::vector<intmax_t>> g(N, std::vector<intmax_t>(N, inf<intmax_t>));
  for (size_t i = 0; i < M; ++i) {
    size_t A, B;
    intmax_t C;
    scanf("%zu %zu %jd", &A, &B, &C);
    --A;
    --B;
    g[A][B] = g[B][A] = C;
  }

  for (size_t k = 0; k < N; ++k)
    for (size_t i = 0; i < N; ++i)
      for (size_t j = 0; j < N; ++j)
        g[i][j] = std::min(g[i][j], g[i][k]+g[k][j]);

  std::sort(r.begin(), r.end());
  intmax_t res = inf<intmax_t>;
  do {
    intmax_t cur = 0;
    for (size_t i = 1; i < R; ++i) cur += g[r[i-1]][r[i]];
    res = std::min(res, cur);
  } while (std::next_permutation(r.begin(), r.end()));

  printf("%jd\n", res);
}


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

#define IL __inline__ __attribute__((always_inline))

#define For(i, a, b) for (int i = a, i##end = b; i <= i##end; ++ i)
#define FOR(i, a, b) for (int i = a, i##end = b; i < i##end; ++ i)
#define Rep(i, a, b) for (int i = a, i##end = b; i >= i##end; -- i)
#define REP(i, a, b) for (int i = (a) - 1, i##end = b; i >= i##end; -- i)

typedef long long LL;

template<class T>
IL bool chkmax(T &a, const T &b) {
  return a < b ? ((a = b), 1) : 0;
}

template<class T>
IL bool chkmin(T &a, const T &b) {
  return a > b ? ((a = b), 1) : 0;
}

template<class T>
IL T mymax(const T &a, const T &b) {
  return a > b ? a : b;
}

template<class T>
IL T mymin(const T &a, const T &b) {
  return a < b ? a : b;
}

template<class T>
IL T myabs(const T &a) {
  return a > 0 ? a : -a;
}

const int INF = 0X3F3F3F3F;
const double EPS = 1E-10, PI = acos(-1.0);

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define OK DEBUG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__)
/*------------------------------header------------------------------*/

const int MAXN = 500000 + 5;

struct SegmentTree {
  int max[MAXN * 4];

#define lc (o << 1)
#define rc (o << 1 | 1)
  void push_up(int o) {
    max[o] = mymax(max[lc], max[rc]);
  }

  void modify(int o, int l, int r, int p, int x) {
    if (l == r) {
      max[o] = x;
      return;
    }
    int mid = (l + r) >> 1;
    if (p <= mid) {
      modify(lc, l, mid, p, x);
    } else {
      modify(rc, mid + 1, r, p, x);
    }
    push_up(o);
  }

  int query(int o, int l, int r, int a, int b) {
    if (a > b) {
      return 0;
    }
    if (l >= a && r <= b) {
      return max[o];
    }
    int mid = (l + r) >> 1, answer = 0;
    if (a <= mid) {
      chkmax(answer, query(lc, l, mid, a, b));
    }
    if (b > mid) {
      chkmax(answer, query(rc, mid + 1, r, a, b));
    }
    return answer;
  }
} seg;

int p[MAXN], a[MAXN], deg[MAXN], answer[MAXN];
std::vector<int> edge[MAXN];

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  For(i, 1, n) {
    scanf("%d", &p[i]);
    a[p[i]] = i;
  }
  if (k == 1) {
    For(i, 1, n) {
      printf("%d\n", i);
    }
    puts("");
    exit(0);
  }
  For(i, 1, n) {
    int x = a[i] == n ? 0 : seg.query(1, 1, n, a[i], mymin(a[i] + k - 1, n)),
        y = a[i] == 1 ? 0 : seg.query(1, 1, n, mymax(a[i] - k + 1, 1), a[i]);
    if (x) {
      edge[i].push_back(x);
      ++ deg[x];
    }
    if (y) {
      edge[i].push_back(y);
      ++ deg[y];
    }
    seg.modify(1, 1, n, a[i], i);
  }
  std::priority_queue<int> q;
  For(i, 1, n) {
    if (!deg[i]) {
      q.push(a[i]);
    }
  }
  Rep(i, n, 1) {
    int u = q.top();
    q.pop();
    answer[i] = u;
    for (auto &x : edge[p[u]]) {
      if (!-- deg[x]) {
        q.push(a[x]);
      }
    }
  }
  For(i, 1, n) {
    a[answer[i]] = i;
  }
  For(i, 1, n) {
    printf("%d\n", a[i]);
  }
  return 0;
}

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

using namespace std;
//131073
typedef pair<int, int> pii;
typedef long long ll;

const int maxn = 100000 + 10;
int a[maxn];

int main(){
    //ios_base::sync_with_stdio(0);
//    freopen("input.txt", "r", stdin);
    int n, k;
    cin >> n >> k;
    int idx = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int res = (idx - 1) % (k - 1) == 0 ? (idx - 1)/(k - 1) : (idx - 1)/(k - 1) + 1;
    res += (n - idx) % (k - 1) == 0 ? (n - idx)/(k - 1): (n - idx)/(k - 1) + 1;
//    int ans = (n - 1) %
    if(n == k)res = 1;
    cout << (int)ceil((n - 1) * 1./(k - 1)) << endl;
    return 0;
}


Measured memory_bytes: 640
/************************************/
/* NoobM							*/
/* File Name : at.cpp				*/
/* Date : 21.06.2020 18:00:49 +06	*/
/************************************/

#include <bits/stdc++.h>

#define rr(i, b)    for (int i = 0; i < int(b); i++)
#define vi(n, a) vector <int> a(n); rr(i, n) cin >> a[i]
#define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector <int>

using namespace std;

void solve() {
	char c;
	cin >> c;
	
	if(c >= 'a' && c <= 'z') cout << 'a' << endl;
	else cout << 'A' << endl;
}
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
	
	int t = 1;
	//cin >> t;
	
	while (t--) {
		solve();
	}
    return 0;
}


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

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL<<60;

int main()
{
  int N, x;
  cin >> N >> x;
  vector<int> list(N);
  for (int i = 0; i < N; i++) {
    cin >> list[i];
  }

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (i + 1 < N && (list[i] + list[i + 1]) > x) {
      int diff = (list[i] + list[i + 1]) - x;
      ans += diff;
      list[i + 1] = max(0, list[i + 1] - diff);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
n,a,b=map(int,input().split())
MOD=10**9+7
ans=pow(2,n,MOD)-1
def cmb(x,y):
  X=1
  Y=1
  for i in range(1,y+1):
    X= X*(x+1-i)%MOD
    Y= Y*i%MOD
  return (X*pow(Y,MOD-2,MOD))%MOD
ans-=(cmb(n,a)+cmb(n,b))
ans%=MOD
print(ans)



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

int main(){
  int n, m, l, a[100][100], b[100][100];
  long long c[100][100] = {};
  cin >> n >> m >> l;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){ cin>>a[i][j];
    }
  }

  for(int i=0;i<m;i++)
    for(int j=0;j<l;j++) cin>>b[i][j];

  for(int i=0;i<n;i++)
    for(int j=0;j<l;j++)
      for(int k=0;k<m;k++) c[i][j] += a[i][k] * b[k][j];

  for(int i=0;i<n;i++){
    for(int j=0;j<l;j++){
      if(j) cout<<" ";
      cout<<c[i][j];
    }
    cout<<endl;
  }
  return 0;
}




Measured memory_bytes: 3240
import math
N,M =map(int,input().split())
if abs(N-M)>1:
    print(0)
    exit()
if (N+M)%2 ==0:
    print(2*math.factorial(N)*math.factorial(M)%(10**9+7))
elif (N+M)%2 !=0:
    print(math.factorial(N)*math.factorial(M)%(10**9+7))

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

int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> l(n+1);
  l.at(0) = 2;
  l.at(1) = 1;
  for (int i = 2; i < n + 1; i++) {
    l.at(i) = l.at(i-1) + l.at(i-2);
  }
  cout << l.at(n) << endl;
}
  
      
      

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define mod 10e9+7
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  ll a,b=0,c;
  int n;
  string s,t;
  cin >> n;
   vector<int> v(n);
   vector<int> l(n);
   vector<int> m(n);
   for(int i = 0; i < n; i++) cin>> l[i];
   for(int i = 0; i < n; i++) cin >> m[i];
 for(int i = 0; i < n; i++) v[i] = i + 1;
 int i=0;
 do{
    if(v==l)
    a=i;
    if(v==m)
    b=i;
    i++;
 }
 while(next_permutation(v.begin(), v.end()));
cout << abs(a-b) << endl;

}
   



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


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

	ll N;
	cin >> N;
	vector<pair<string,pair<int,int>>> x;
	FOR(i,0,N){
		string s;
		int a;
		cin >> s >> a;
		x.push_back({s,{-a,i}});
	}
	SORT(x);
	FOR(i,0,N){
		cout << x[i].second.second+1 << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>

int main(){
  int x, y;
  std::cin >> x;
  std::cin >> y;
  
  if(x > y) std::cout << "a > b" << std::endl;
  else if(x < y) std::cout << "a < b" << std::endl;
  else std::cout << "a == b" << std::endl;
  
  return 0;
}

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


using namespace std;

int main()
{
  string s, buf;
  int m, n;

  while(true)
  {
    cin >> s;
    if(s == "-")
      break;
    cin >> m;
    for(int i = 0; i < m; i++)
    {
      buf = "";
      cin >> n;
      for(int i = n; i < s.length(); i++)
      {
        buf[i - n] = s[i];
      }
      for(int i = 0; i < n; i++)
      {
        buf[i + s.length() - n] = s[i];
      }
      for(int i = 0; i < s.length(); i++)
      {
        s[i] = buf[i];
      }
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1208