akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
	char s[20];
}a[200005];
bool cmp1(struct node a1,struct node a2)
{
	return strcmp(a1.s,a2.s)<0;
}
int main(void)
{
	ll n;
	scanf("%lld",&n);
	char s[20];
	for(ll i=0;i<n;i++)
	{
		scanf(" %s",a[i].s);
	}
	sort(a,a+n,cmp1);
	ll ma=1,nu=1;
	for(ll i=0;i<n-1;i++)
	{

		if(strcmp(a[i].s,a[i+1].s)==0)
		{
			nu++;
		}
		else
		{
			nu=1;
		}
		ma=max(ma,nu);
	}
	nu=1;
	for(ll i=0;i<n-1;i++)
	{
		if(strcmp(a[i].s,a[i+1].s)==0)
		{
			nu++;
		}
		else
		{
			nu=1;
		}
		if(nu==ma)
		{
			printf("%s\n",a[i].s);
		}
	}
	if(strcmp(a[n-2].s,a[n-1].s)!=0&&ma==1)
	{
		printf("%s",a[n-1].s);
	}
}

Measured memory_bytes: 5888
N = int(input())
M = 10**9 + 7
dp = [[[[0] * 4 for _ in range(4)] for _ in range(4)] for _ in range(N + 1)]

dp[0][3][3][3] = 1

for l in range(N):
    for i in range(4):
        for j in range(4):
            for k in range(4):
                if dp[l][i][j][k] == 0:
                    continue
                for a in range(4):
                    if j == 0 and k == 1 and a == 2:
                        continue
                    if j == 0 and k == 2 and a == 1:
                        continue
                    if j == 1 and k == 0 and a == 2:
                        continue
                    if i == 0 and j == 1 and a == 2:
                        continue
                    if i == 0 and k == 1 and a == 2:
                        continue
                    dp[l + 1][j][k][a] += dp[l][i][j][k]
                    dp[l + 1][j][k][a] %= M
ans = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans += dp[N][i][j][k]
print(ans%M)

Measured memory_bytes: 48496
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int n;
 
void compute(int depth,double x1,double y1,double x2,double y2){
  double si60 = sqrt(3.0)/2.0;
  double co60 = 0.5;
   
  double sx = (x1+x1+x2)/3.0;
  double sy = (y1+y1+y2)/3.0;
  double tx = (x1+x2+x2)/3.0;
  double ty = (y1+y2+y2)/3.0;
   
  double vx = tx-sx;
  double vy = ty-sy;
   
  double ux = sx + co60*vx - si60*vy;
  double uy = sy + si60*vx + co60*vy;
   
  if(depth>=n)return;
   
  compute(depth+1,x1,y1,sx,sy);
  printf("%.8f %.8f\n",sx,sy); 
  compute(depth+1,sx,sy,ux,uy);
  printf("%.8f %.8f\n",ux,uy);
  compute(depth+1,ux,uy,tx,ty);
  printf("%.8f %.8f\n",tx,ty);   
  compute(depth+1,tx,ty,x2,y2);
 
   
}
 
int main(){
  cin>>n;
  printf("%.8f %.8f\n",0.0,0.0);
  compute(0,0.0,0.0,100.0,0.0);
  printf("%.8f %.8f\n",100.0,0.0);
  return 0;
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
#define ll long long
#define pa pair<int,int>
#define db double
#define mo 1000000007
using namespace std;
char s[305];
int f[305][305][305];
int K,ans;
int main(){
	scanf("%s%d",s+1,&K);
	int n=strlen(s+1);
	for (int i=0;i<=K;i++)
		for (int j=1;j<=n;j++)
			for (int k=n;k>j;k--){
				if (i!=0) f[i][j][k]=f[i-1][j-1][k+1]+1;
				f[i][j][k]=max(f[i][j][k],max(f[i][j-1][k],f[i][j][k+1]));
				if (s[j]==s[k]) f[i][j][k]=max(f[i][j][k],f[i][j-1][k+1]+1);
			}
	for (int i=1;i<=n;i++)
		ans=max(ans,2*f[K][i-1][i+1]+1);
	for (int i=0;i<=n;i++)
		ans=max(ans,2*f[K][i][i+1]);
	printf("%d",ans);
}

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

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

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

	ll stock = 0;
	ll money = 1000;

	for (int i = 0; i < N - 1; i++) {
		ll max_j = i;
		ll max_price = A[i];
		for (int j = i + 1; j < N; j++) {
			if (max_price > A[j]) {
				break;
			} else if (A[j] > max_price) {
				max_price = A[j];
				max_j = j;
			}
		}
		stock = money / A[i];
		money -= stock * A[i];
		money += stock * A[max_j];
		stock = 0;
		// cout << i << " " << max_j << " " << money << endl;
		i = max_j;
	}

	cout << money << endl;

	return 0;
}

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

using namespace std;

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

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

  vector<string> Strings={"dream", "dreamer", "erase", "eraser"};

  reverse(S.begin(), S.end());
  rep(i, 4){
    string &tmp = Strings.at(i);
    reverse(tmp.begin(), tmp.end());
  }

  bool can = true;
  for(int i = 0; i < (int)S.size();){
    bool can2 = false;
    for(string d : Strings){
      if(S.substr(i, d.size()) == d){
        can2 = true;
        i += d.size();
        break;
      }
    }
    if (!can2){
      can = false;
      break;
    }
  }

  if(can) cout << "YES" << endl;
  else cout << "NO" << endl;

}


Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>
using namespace std;

typedef long long ll;
int main()
{
        int N;
        cin >> N;
        vector<ll> A(N);
        ll All = 0;
        ll MinasCount=0;
        ll MinNum = 1000000001;
        for(int i=0; i<N; i++){
                cin >> A[i];
                if(A[i] < 0){
                         All += -A[i];
                        MinasCount ++;
                }
                else
                        All += A[i];
                if(MinNum > labs(A[i])) MinNum = labs(A[i]);
        }
        if(MinasCount % 2 == 0) cout << All;
        else cout << All - 2*MinNum;

}

Measured memory_bytes: 1024
def main():
    a, b = map(int, input().split())
    
    h = ((max(a, b) - 1) // 16 + 1) * 3
    w = 96 # 3 * 32

    print(h, w)

    ans = []
    line1 = ['.', '.', '.', '#', '#', '#'] * 16
    line2 = ['#', '#', '#', '.', '.', '.'] * 16

    for i in range(h//3):
        if i % 2 == 0:
            ans.append(line1.copy())
            ans.append(line1.copy())
            ans.append(line1.copy())
        else:
            ans.append(line2.copy())
            ans.append(line2.copy())
            ans.append(line2.copy())

    if a <= b:
        a, b = b, a
        flag = True
    else:
        flag = False

    if a % 16 > 0:
        for i in range(6 * (16 - a % 16) + 3):
            ans[-1][i] = '.'

    if h == 3:
        for i in range(6 * (16 - b) + 3):
            ans[0][i] = '#'
    else:
        num = h//3 * 16 - b
        for i in range(num // 16):
            if ans[2 + 3*i][0] == '.':
                for j in range(16):
                    ans[2 + 3*i][2 + 6*j] = '#'
            else:
                for j in range(16):
                    ans[2 + 3*i][3 + 6*j] = '#'

        if ans[-3][0] == '.':
            for i in range(num % 16):
                ans[-3][6 + 6*i] = '#'
        else:
            for i in range(num % 16):
                ans[-3][5 + 6*i] = '#'

    if flag:
        for i in range(h):
            for j in range(w):
                if ans[i][j] == '.':
                    ans[i][j] = '#'
                else:
                    ans[i][j] = '.'

    for i in ans:
        print(''.join(i))

main()

Measured memory_bytes: 9328
function main(t){t=t.split("\n");var n=parseInt(t[0].split(" ")[0]),a=parseInt(t[0].split(" ")[1]);A=new Array,P2=Math.sqrt(a);var e=-1,r=0;for(i=2;i<P2&&(a%i==0?(0==r&&e++,r++,A[e]=[i,r],a/=i):(i++,r=0),1!=a);i)a==a&&(A[e+1]=[a,1]);var o=1;for(i=0;i<A.length;i++)o*=Math.max(Math.pow(A[i][0],Math.floor(A[i][1]/n)),1);console.log(o)}function debug(){var i=document.getElementById("input").value;Main(i)}main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 10060
#include<iostream>
using namespace std;
int main () {
  int N;
  cin >> N;
  char a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i = 0; i < N - 2; i ++) {
    char c;
    cin >> c;
    if (a == 'A' && b == 'B' && c == 'C') ans ++;
    a = b;
    b = c;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    int a, b;
    cin>>a>>b;
    if(b%a==0){
        cout<<a+b<<endl;
    }else{
        cout<<b-a<<endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        public static List<long> GeneratePrime(long max)
        {
            long prime;
            double sqrtMax = Math.Sqrt(max);
            var primeList = new List<long>();

            List<long> searchList = new List<long>();
            for (long i = 2; i <= max - 1; i++)
            {
                searchList.Add(i);
            }

            do
            {
                prime = searchList.First();
                primeList.Add(prime);
                searchList.RemoveAll(n => n % prime == 0);
            } while (prime < sqrtMax);

            primeList.AddRange(searchList);

            return primeList;
        }

        void Omame()
        {
            cin = new Scanner();
            long A = cin.nextLong();
            long B = cin.nextLong();
            long C = cin.nextLong();

            Console.WriteLine(Math.Max(0,C - (A - B)));
        }

    }
}


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

int a, b, c, k;

int main()
{
    cin >> a >> b >> c >> k;

    if (k < a)
        cout << k << endl;
    else if (k < a + b)
        cout << a << endl;
    else
        cout << a * 2 - k + b << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main() {
	cin.tie(0); cin.sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> k(m);
	vector<vector<int>> s(m);
	for (int i = 0; i < m; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			int x;
			cin >> x; x--;
			s[i].push_back(x);
		}
	}
	vector<int> p(m);
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}
	const int bsm = 1 << n;
	int ret = 0;
	for (int bs = 0; bs < bsm; bs++) {
		bool flg = false;
		for (int i = 0; i < m; i++) {
			int tmp = 0;
			for (int j = 0; j < k[i]; j++) {
				tmp ^= (bs >> s[i][j]) & 1;
			}
			if (tmp != p[i]) {
				flg = true;
				break;
			}
		}
		if (!flg) ret++;
	}
	cout << ret << endl;
	return 0;
}


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

using namespace std;

struct CLASS{
  string s;
  int number;
  int sum;
};

int main(){
  int i, n, m;
  string str;
  CLASS data[9];

  for(i=0; i<9; ++i){
    cin >> str >> n >> m;
    data[i].s = str;
    data[i].number = n + m;
    data[i].sum = 200*n + 300*m;
  }

  for(i=0; i<9; ++i)
    cout << data[i].s << " " << data[i].number << " " << data[i].sum << endl;

  return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W; cin >> H >> W;
	vector<vector<int>>G(H, vector<int>(W));
	vector<vector<int>>dp(G);
	int ans(0);
	rep(i, 0, H)rep(j, 0, W)cin >> G[i][j];
	rep(i, 0, H)rep(j, 0, W) {
		dp[i][j] = (G[i][j] + 1) % 2;
		chmax(ans, dp[i][j]);
	}
	
	rep(i, 1, H)rep(j, 1, W) {
		if (G[i][j])dp[i][j] = 0;
		else dp[i][j] = min(dp[i - 1][j], min(dp[i][j - 1], dp[i - 1][j - 1])) + 1;
		chmax(ans, dp[i][j]);
	}
	cout << ans*ans << endl;
	return 0;
}

Measured memory_bytes: 18396
n=int(input())
a=list(map(int,input().split()))
b=[(-1)**i*a[i] for i in range(n)]
ans=[sum(b)//2]
for i in range(n-1):
    ans.append((a[i]-ans[i]))
print(' '.join(map(lambda x:str(x*2),ans)))


Measured memory_bytes: 23112
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc088.contest.atcoder.jp/tasks/arc088_a>
問題文============================================================
 高橋君は、日頃の感謝を込めて、お母さんに数列をプレゼントすることにしました。
 お母さんにプレゼントする数列 A は、以下の条件を満たす必要があります。
 
 A は X 以上 Y 以下の整数からなる
 すべての 1≤i≤|A|−1 に対し、Ai+1 は Ai の倍数であり、かつ Ai+1 は Ai より真に大きい
 
 高橋君がお母さんにプレゼントできる数列の長さの最大値を求めてください。
=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll X,Y; cin >> X >> Y;
    ll ans = 0;
    while(X <= Y){
        ans++; X*=2;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main()
{
    int n, ans = 0;;
    cin >> n;
    vector<int> v(n);
    rep(i, n)cin >> v[i];
    for(int  i = 1; i < n-1; i++){
        int ma = max(v[i-1], max(v[i], v[i+1]));
        int mi = min(v[i-1], min(v[i], v[i+1]));
        if(v[i] != ma & v[i] != mi)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
int main(){
    int n;
    long long d;
    cin >> n >> d;
    int count=0;
    rep(i,n){
        long long x,y;
        cin>> x >>y ;
        if(x*x+y*y<=d*d) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3636
n = int(input())
s = input()

w = [0] * n
e = [0] * n

cnt_w = 0
cnt_e = 0
for i in range(n):
  if s[i] == "W":
    cnt_w += 1
    w[i] = cnt_w
    e[i] = cnt_e
  else:
    w[i] = cnt_w
    cnt_e += 1
    e[i] = cnt_e
    
ch = n - 1
for i in range(n):
  if i >= 1:
    ch = min(ch, w[i - 1] + e[-1] - e[i])
  else:
    ch = min(ch, e[-1] - e[0])
print(ch)

Measured memory_bytes: 17568
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdlib>
using namespace std;

int n,m,W,k,kt,w;
int weight[17];
int load[10001];
int memo[1<<17];

void memoize() {
    for(int i=1; i<(1<<k); ++i) {
        memo[i] = 1<<29;
        int sumw = 0;
        for(int j=0; j<k; ++j)
            if((i>>j)&1) sumw += weight[j];
        if(sumw <= W) {
            memo[i] = 1;
            continue;
        }

        for(int T=i&-i; T; T = (T-i)&i) {
            memo[i] = min(memo[T]+memo[i-T],memo[i]);
        }
    }
    memo[0] = 0;
    return;
}

int main() {
    cin>>n>>m>>W; m--;
    k = 0;
    for(int i=0; i<n; ++i) {
        cin>>kt;
        for(int j=0; j<kt; ++j) {
            cin>>weight[k+j];
            load[i] |= 1<<(k+j);
        }
        k += kt;
    }
    memoize();

    int have = 0,ans = 0,maxfloor = 0;
    for(int i=0; i<n; ++i)
        if(load[i] > 0) maxfloor = i;
    if(maxfloor == 0 ) {
        cout<<0<<endl;
        return 0;
    }

    ans += abs(m-maxfloor);
    for(int i=maxfloor; i>0; --i) {
        have |= load[i];
        ans += memo[have]*2-1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define mxn 200005
using namespace std;
int pos[mxn], cnt[mxn];
int main()
{
    int n, x;
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
    scanf("%d", &x), pos[x]= i;
    int res= n;
    for(int i=n-1; i>=0; i--)
    {
        int rem= (n-i);
        cnt[i+1]= 1;
        if(pos[i+2]>pos[i+1])cnt[i+1]+= cnt[i+2];
        res= min(res, i+(rem-cnt[i+1]));
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int N, temp, S1 = 0, S2 = 0, ans = -1;
	vector<int> W;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> temp;
		W.push_back(temp);
	}
	for (int T = 1; T < N; T++) {
		S1 = S2 = 0;
		for (int i = 0; i < N; i++) {
			if (i + 1 <= T) {
				S1 += W[i];
			}
			else {
				S2 += W[i];
			}
		}
		if (S2 > S1) {
			temp = S2 - S1;
		}
		else {
			temp = S1 - S2;
		}
		if (ans == -1) {
			ans = temp;
		}
        else if (ans > temp) {
			ans = temp;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# AGC022A - Diverse Word
def main():
    S = input().rstrip() + "`"  # add "`" to get full S when S[:-1]
    for i in range(len(S)):
        P = S[:~i]  # partial string
        # get possible letters after S[~i]
        R = set(chr(i) for i in range(ord(S[~i]) + 1, 123)) - set(P)
        if R:
            print(P + min(R))
            break
    else:
        print(-1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
//-std=c++11
#define print(x) printf("%.12f",x);
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define repr(i, n) for(int i=n-1;i>=0;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Repr(i,a,b) for(int i=a;i>=b;i--)
#define pii pair < int, int >
#define iter ::iterator
#define forit(a) for(it=a.begin();it!=a.end();it++)
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod = 998244353;
const int N = (int)2e5 + 5;

char fun(char c,int n){
	if((int)(+c+n)<=int('Z'))return char(+c+n);
	return char(+c+n-(int)'Z'+'A'-1);
}


void solve(){
	int n;
	string s;
	cin>>n>>s;
	rep(i,sz(s)){
		s[i]=fun(s[i],n);
	}
	cout<<s;


} 


int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 256
from math import sqrt

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

def getDivisors(a , b):
    a1 = set()
    a2 = set()
    for i in range(1,int(sqrt(a)+1)):
        if a%i == 0:
            a1.add(i)
            a1.add(a//i)
    for j in range(1,int(sqrt(b)+1)):
        if b%j == 0:
            a2.add(j)
            a2.add(b//j)
    return sorted(a1.intersection(a2))


print(getDivisors(x, y)[-k])


Measured memory_bytes: 3064
#include <stdio.h>

int main(void){

  int n;
  int a[100000];
  int two=0;
  int four=0;
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",a+i);
    if(a[i]%4==0)four++;
    if(a[i]%2==0)two++;
  }

  if( (n-two)+(two-four)%2 <= four+1)puts("Yes");
  else puts("No");
  
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,inf=1e9,ans=inf;
    cin>>n;
    vec X(n),Y(n);
    vector<char> U(n);
    rep(i,n) cin>>X[i]>>Y[i]>>U[i];
    vector<P> A;
    rep(i,n) A.push_back(P(X[i],i));
    sort(all(A));
    int a=0;
    rep(i,200001){
        vec u,d;
        while(a<n&&A[a].first==i){
            if(U[A[a].second]=='U') u.push_back(Y[A[a].second]);
            if(U[A[a].second]=='D') d.push_back(Y[A[a].second]);
            a++;
        }
        sort(all(u)),sort(all(d));
        rep(i,u.size()) if(d.size()&&u[i]<d[d.size()-1]) ans=min(ans,(*upper_bound(all(d),u[i])-u[i])*5);
    }
    A.clear();
    rep(i,n) A.push_back(P(Y[i],i));
    sort(all(A));
    a=0;
    rep(i,200001){
        vec r,l;
        while(a<n&&A[a].first==i){
            if(U[A[a].second]=='R') r.push_back(X[A[a].second]);
            if(U[A[a].second]=='L') l.push_back(X[A[a].second]);
            a++;
        }
        sort(all(r)),sort(all(l));
        rep(i,r.size()) if(l.size()&&r[i]<l[l.size()-1]) ans=min(ans,(*upper_bound(all(l),r[i])-r[i])*5);
    }
    A.clear();
    rep(i,n) A.push_back(P(Y[i]-X[i],i));
    sort(all(A));
    a=0;
    for(int i=-200000;i<=200000;i++){
        vec u,d,r,l;
        while(a<n&&A[a].first==i){
            if(U[A[a].second]=='U') u.push_back(X[A[a].second]);
            if(U[A[a].second]=='D') d.push_back(X[A[a].second]);
            if(U[A[a].second]=='R') r.push_back(X[A[a].second]);
            if(U[A[a].second]=='L') l.push_back(X[A[a].second]);
            a++;
        }
        sort(all(u)),sort(all(d)),sort(all(r)),sort(all(l));
        rep(i,u.size()) if(l.size()&&u[i]<l[l.size()-1]) ans=min(ans,(*upper_bound(all(l),u[i])-u[i])*10);
        rep(i,r.size()) if(d.size()&&r[i]<d[d.size()-1]) ans=min(ans,(*upper_bound(all(d),r[i])-r[i])*10);
    }
    A.clear();
    rep(i,n) A.push_back(P(Y[i]+X[i],i));
    sort(all(A));
    a=0;
    for(int i=0;i<=400000;i++){
        vec u,d,r,l;
        while(a<n&&A[a].first==i){
            if(U[A[a].second]=='U') u.push_back(X[A[a].second]);
            if(U[A[a].second]=='D') d.push_back(X[A[a].second]);
            if(U[A[a].second]=='R') r.push_back(X[A[a].second]);
            if(U[A[a].second]=='L') l.push_back(X[A[a].second]);
            a++;
        }
        sort(all(u)),sort(all(d)),sort(all(r)),sort(all(l));
        rep(i,r.size()) if(u.size()&&r[i]<u[u.size()-1]) ans=min(ans,(*upper_bound(all(u),r[i])-r[i])*10);
        rep(i,d.size()) if(l.size()&&d[i]<l[l.size()-1]) ans=min(ans,(*upper_bound(all(l),d[i])-d[i])*10);
    }
    if(ans==inf) cout<<"SAFE\n";
    else cout<<ans;
}

Measured memory_bytes: 12440
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;

int main(){
   string s;   cin >> s;
   int n = s.size();
   int i=0;
   for(int i=0;i<n;i++){
      
      if(i % 2 == 0 && s.at(i) == 'L'){
         cout << "No" << endl;
         return 0;
      }

      if(i % 2 == 1 && s.at(i) == 'R'){
         cout << "No" << endl;
         return 0;
      }

   }

    cout << "Yes" << endl;
}



Measured memory_bytes: 256
from networkx import Graph,predecessor

G = Graph() #無効グラフ生成
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(m)]
G.add_edges_from(ab) #辺リスト生成
preds = predecessor(G,source=1)  #sourceはstart node
print("Yes")
for i in range(2,n+1):
    print(preds[i][0])

#描画
#import matplotlib.pyplot as plt
#import networkx as nx
#nx.draw_networkx(G)
#plt.show()

Measured memory_bytes: 222476
/*************************************************************************
    > File Name: e.cpp
    > Author: Amano Sei
    > Mail: amano_sei@outlook.com 
    > Created Time: 2019年12月22日 星期日 21时19分59秒
 ************************************************************************/

#include <cstdio>

int main(){
    long long n, ans = 0, cten = 10;
    scanf("%lld", &n);
    if((n&1) == 0){
        while(cten <= n){
            ans += n/cten;
            register long long ften = 5*cten;
            while(ften <= n){
                ans += (n/ften/2 + n/ften%2);
                ften *= 5;
            }
            cten *= 10;
        }
    }
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int dp[10000001];
int arr[10000001];
int n;
int solve(int ind)
{
	if(ind==n-1)
	{
		return 0;
	}
	if(dp[ind]!=-1)
	{
		return dp[ind];
	}
	int ans=solve(ind+1)+abs(arr[ind+1]-arr[ind]);
	if(ind+2<n)
	{
		ans=min(ans,solve(ind+2)+abs(arr[ind+2]-arr[ind]));
	}
	return dp[ind]=ans;


}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	cout<<solve(0)<<"\n";
	return 0;
}

Measured memory_bytes: 47708
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = Integer.parseInt(in.next());
            int B = Integer.parseInt(in.next());
            if (B % A == 0) {
                out.println(B + A);
            } else {
                out.println(B - A);
            }
        }
    }
}



Measured memory_bytes: 23636
#include <iostream>

using namespace std;

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

    int a, b, k;

    cin >> k >> a >> b;

    for (int i = a; i <= b && i <= a + k - 1; ++i) {
        if (i % k == 0) {
            cout << "OK";
            return 0;
        }
    }

    cout << "NG";
    return 0;
}


Measured memory_bytes: 3608
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

a,b = I()
sa = abs(a-b)
if sa % 2 == 0:
    print((a+b)//2)
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 10096
s = int(input())

mod = 10**9 + 7
dp = [0]*(s+1)
dp[0] = 1
x = 0
for i in range(1,s+1):
    if i-3 >=0:
        x += dp[i-3]
        x %=mod
    dp[i] = x
        
print(dp[s])

Measured memory_bytes: 63580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define vec(x) vector<x>
#define IINF INT_MAX
#define LLINF LLONG_MAX
ll gcd(ll a,ll b){while(b){ll tmp = a % b;a = b;b = tmp;}return a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define out(x) for(auto i : x) cout << i << " "; cout << endl;
#define outln(x) for(auto i : x) cout << i << " " << endl;
#define vec_cpy(to,from) copy(all(to),back_inserter(from))
#define ary_cpy(to,from) memcpy(to, from, sizeof from)
#define MOD 1000000007
#define DEBUG true

int main(){
  int a,b,c;cin >> a >> b >> c;
  cout << a + b + c << endl;
  return 0;
}

Measured memory_bytes: 3092
#include<stdio.h>
int main(void)
{
	int n,i,a[6]={500,100,50,10,5,1},sum;
	
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		n=1000-n,sum=0;
		for(i=0;i<6;i++){
			sum+=n/a[i];
			n=n%a[i];
		}
		printf("%d\n",sum);
	}
	return 0;
}	


Measured memory_bytes: 2760
module A = Array
module C = Char
module I = Int64
module L = List
module Q = Queue

let pf = Printf.printf
let sf = Scanf.scanf
let ssf = Scanf.sscanf

let read_int () = sf "%d " (fun x -> x)
let read_float () = sf "%f " (fun x -> x)
let read_str () = sf "%s " (fun x -> x)
let read_array n read () = A.init n (fun _ -> read ())
let err s = raise (Failure s)

let range s t = A.init (t - s) @@ (+) s
let foreach fold_f init s t map_f =
  range s t |> A.map map_f |> A.fold_left fold_f init

let inf = int_of_float 1e18
let eps = 1e-11

module S = struct
  include String
  let of_array a = String.init (A.length a) (A.get a)
  let to_array s = A.init (String.length s) (String.get s)
end;;

let rec sum_of_digit n =
  if n = 0
  then 0
  else sum_of_digit (n / 10) + n mod 10

let () =
  let n = read_int () in
  let res =
    if n mod sum_of_digit n = 0
    then "Yes"
    else "No" in
  pf "%s\n" res


Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
queue< ii > q;
int vis[100005][5]=  {};
vector< vi > graph(100005);
int n, m;
int dis = 0;
void kenkenpa(int i, int val)
{
    //cout<<i<<" "<<val<<endl;
    vis[i][val] = 1;
    if(val == 3)
    {
        q.push(ii(i, dis));
        return;
    }
    int j, si = graph[i].size();
    FOR0(j, si)
    {
        int v = graph[i][j];
        int nval = (val+1)%3;
        if(vis[v][nval]) continue;
        kenkenpa(v, val+1);
    }
}
int main()
{
    she_told_me_dont_worry
    cin>>n>>m;
    int i;
    FOR0(i, m)
    {
        int u, v;
        cin>>u>>v;
        u--;v--;
        graph[u].pb(v);
    }
    int s , t;
    cin>>s>>t;
    s--;t--;
    int cur = 0;
    q.push(ii(s, 0));
    int ans = -1;
    while(q.size())
    {
        ii u = q.front();
        //cout<<u.ff<<endl;
        if(u.ff == t)
        {
            ans = u.ss;
            break;
        }
        dis = u.ss+1;
        q.pop();
        kenkenpa(u.ff, 0);
    }
    cout<<ans;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 7680
#include<stdio.h>
#define N 2100000000
#define M 100000

struct pair{
  char al;
  int num;
};

void merge(struct pair a[], int left, int mid, int right){
  int i, j, k, n1=mid-left, n2=right-mid;
  struct pair L[n1+1], R[n2+1];

  for(i=0;i<n1;i++) L[i]=a[left+i];
  for(i=0;i<n2;i++) R[i]=a[mid+i];
  L[n1].num=R[n2].num=N;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i].num<=R[j].num){
        a[k]=L[i++];
    }
    else{
      a[k]=R[j++];
    }
  }
}

void sort(struct pair a[], int left, int right){
  if(left+1<right){
    int mid=(left+right)/2;
    sort(a,left,mid);
    sort(a,mid,right);
    merge(a,left,mid,right);
  }
}

int partition(struct pair b[], int p,int r){
  struct pair x=b[r],n;
  int j,i=p-1;

  for(j=p;j<r;j++){
    if(b[j].num<=x.num){
      i++;
      n=b[i]; b[i]=b[j]; b[j]=n;
    }
  }
  n=b[i+1]; b[i+1]=b[r]; b[r]=n;

  return i+1;
}

void quicksort(struct pair b[], int p, int r){
  int  q;
  if(p<r){
    q=partition(b,p,r);
    quicksort(b,p,q-1);
    quicksort(b,q+1,r);
  }
}

int main(){
  int n,i,f=1;
  char c[5];
  struct pair a[M],b[M];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %d",c,&b[i].num);
    b[i].al=a[i].al=c[0];
    a[i].num=b[i].num;
  }

  sort(a,0,n);
  quicksort(b,0,n-1);

    for(i=0;i<n;i++){
      if(a[i].al != b[i].al) f=0;
    }

  if(f==1) printf("Stable\n");
  else printf("Not stable\n");

  for(i=0;i<n;i++) printf("%c %d\n",b[i].al,b[i].num);

    return 0;
}


Measured memory_bytes: 5012
#include "stdio.h"

int main()
{

  int  n,x,i,j,k;

  for (;;)
  {
    int m=0;
    scanf("%d %d\n",&n,&x );
    if (n==0 && x==0) break;


    for (i = 1; i <= n-2; i++)
    {
      for (j = i+1;  j<=n-1 ; j++)
      {
        for (k = j+1; k <= n; k++)
        {
          if ((i+k+j)==x)
          {
            m++;
          }
        }
      }
    }

    printf("%d\n",m );

  }



  return 0;
}



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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

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

    string s;
    int k;
    cin >> s >> k;
    vector<string> ss;
    REP(i, s.size()) {
        for(int j = 1; j <= k /* && i + j < s.size()*/; ++j) {
            ss.push_back(s.substr(i, j));
        }
    }
    sort(ss.begin(), ss.end());
    unique(ss.begin(), ss.end());
    cout << ss[k -1] << endl;

    return 0;
}

Measured memory_bytes: 1660
#include<stdio.h>
int main()
{   int N,sum,i;
    scanf("%d",&N);
    sum=0;
    if(1<=N&&N<=100)
    {for(i=1;i<=N;i++)
        { sum=sum+i;
    	}
     printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,a[102],ans;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i){
		m-=a[i];
		if(m>=0)ans++;
		else break;
	}
	if(m>0)ans--;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

vector<ll> ab;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,y,z,k;cin>>x>>y>>z>>k;
    // priority_queue<ll> pq;
    vector<ll> a(x),b(y),c(z);
    rep(i,x) cin>>a[i];
    rep(i,y) cin>>b[i];
    rep(i,z) cin>>c[i];
    rep(i,x){
        rep(j,y){
            ab.emplace_back(a[i]+b[j]);
        }
    }
    sort(ab.rbegin(), ab.rend());
    vector<ll> zz;
    for(ll i=0; i<k && i<ab.size(); i++){
        rep(j, z){
            zz.emplace_back(ab[i]+c[j]);
        }
    }
    sort(zz.rbegin(), zz.rend());
    rep(i,k){
        cout<<zz[i]<<endl;
    }
    return 0;
    
}

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

/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

using namespace std;

typedef long long ll;

string s;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
        cout << "3\n";
    else if(s[0] == 'R' && s[1] == 'R')
        cout << "2\n";
    else if(s[1] == 'R' && s[2] == 'R')
        cout << "2\n";
    else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R')
        cout << "1\n";
    else
        cout << "0\n";
    return 0;
}



Measured memory_bytes: 3648
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=500;

int n;
char g[MAXN][MAXN+1];

void run() {
	scanf("%d",&n); REP(x,n) scanf("%s",g[x]);
	bool any=false; REP(x,n) REP(y,n) if(g[x][y]=='#') any=true; if(!any) { printf("-1\n"); return; }
	bool all=true; REP(x,n) REP(y,n) if(g[x][y]=='.') all=false; if(all) { printf("0\n"); return; }
	
	int ret=INT_MAX;
	int cleft=0; REP(y,n) { bool cur=false; REP(x,n) if(g[x][y]=='.') cur=true; if(cur) ++cleft; }
	REP(x,n) {
		int rleft=0; REP(y,n) if(g[x][y]=='.') ++rleft;
		bool ok=false; REP(xx,n) if(g[xx][x]=='#') ok=true;
		int cur=rleft+cleft;
		if(rleft>0&&!ok) ++cur;
		if(cur<ret) ret=cur;
	}
	printf("%d\n",ret);
}

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


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;

int main(){
	int n1,n2;
	cin>>n1>>n2;
	if(n1>n2){
		for(int i=0;i<n1;i++){
			cout<<n2;
		}
	}else{
		for(int i=0;i<n2;i++){
			cout<<n1;
		}
	}
}
//int main(){
//	int n;
//	int t;
//	cin>>n;
//	int sum=0,ss=0x3f;
//	for(int i=0;i<n;i++){
//		cin>>t;
//		if(t<ss){
//			sum++;
//		}
//		ss=t;
//	}
//	cout<<sum;
//	return 0;
//}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include <iostream>
#include<stdlib.h>
//#include <algorithm>
#include <limits>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
int main(void){
	ll N,C;
  cin >> N >> C;
  ll x[N+2],v[N];
  rep(i,N){
    cin >> x[i+1] >> v[i];
  }
  x[0]=0;
  x[N+1]=C;
  ll v1[N+1];
  ll v2[N+1];
  v1[0]=0;
  v2[0] =0;
  rep(i,N){
    v1[i+1]=v1[i]+v[i];
    v2[i+1]=v2[i]+v[N-1-i];
  }
  ll maxcost = 0;
  ll tmp;
  ll f[N+1];
  f[0]=0;
  rep(i,N){
    f[i+1]=max(v1[i+1]-x[i+1],f[i]);
  }
  ll g[N+1];
  g[0]=0;
  rep(i,N){
    g[i+1]=max(v2[i+1]-((C-x[N-i])%C),g[i]);
  }
  for(int i=0;i<N+1;i++){
        tmp = v2[i] - ((C-x[N+1-i])%C)*2;
        maxcost=max(maxcost,f[N-i]+tmp);
        //cout << maxcost << " " << x[N+1-i] << " " << f[N-i] << " " << v2[i]<<"a"<< endl;
  }
  for(int i=0;i<N+1;i++){
        tmp = v1[i] - (x[i])*2;
        maxcost=max(maxcost,g[N-i]+tmp);
        //cout << maxcost << " " << x[i] << " " << g[N-i] << " " << v1[i]<<"b" << endl;
  }
  cout << maxcost << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#define MAX 200002
#define fi first
#define se second
typedef long long ll;
 
using namespace std;
 
vector<vector<int>> graph(MAX);
 
long long cnt[MAX];
long long ans[MAX];
bool visited[MAX];
void dfs(int st){
	fill(visited, visited + MAX, 0);
	vector<pair<int, long long>> stack = vector<pair<int, long long>>{pair<int, long long>{st, cnt[st]}};
	while(stack.size()){
		pair<int, long long> elem = stack.back();
		stack.pop_back();
		if(visited[elem.fi]){
			continue;
		}
		visited[elem.fi] = 1;
		ans[elem.fi] = elem.se;
		for(auto i:graph[elem.fi]){
			stack.push_back(pair<int, long long>{i, cnt[i] + elem.se});
		}
	}
}
 
int main(){
	fill(cnt, cnt+MAX, 0); 
	int n, q;
	cin >> n >> q;
	for(int i=0;i<n-1;i++){
		int ai, bi;
		cin >> ai >> bi;
		graph[ai].push_back(bi);
		graph[bi].push_back(ai);
	}
	for(int i=0;i<q;i++){
		int k, p;
		cin >> k >> p;
		cnt[k] += p;
	}
	dfs(1);
	for(int i=1;i<=n;i++){
		cout << ans[i] << ' ';
	}
	return 0;
}

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

ll calc(const vector<ll>& f) {
  int n = f.size();
  vector<ll> g(n);
  g[1] = (f[1] - f[0] + mod) % mod;
  for (int i = 2; i < n; i++) {
    g[i] = 2 * g[i-1] - g[i-2] + i * (f[i] - f[i-1]);
    g[i] %= mod; if (g[i] < 0) g[i] += mod;
  }
  return g[n-1];
}

int main() {
  int n, m; cin >> n >> m;
  vector<ll> x(n), y(m);
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < m; i++) cin >> y[i];
  cout << calc(x) * calc(y) % mod << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
    for (int i=0;i<9;i++) {
        string t;
        cin >> t;
        if ( t !="-" ) {
            int r;
            cin >> r;
            for (int j=0;j<r;j++) {
                int c;
                cin >> c;
                string T = t.substr(0,c);   //シャッフルするカードを選択
                t = t.erase(0,c);      //シャッフルするカードを取り出す
                t = t + T;      //取り出したカードを上に置く
            }
            cout << t << endl;
        } else {
            break;
        }
    }
}


Measured memory_bytes: 3176
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

//_(＾～＾ ｣ ∠)_

using LL = long long;

int main() {

    int N, M;
    cin >> N >> M;

    vector<int> A(M);
    for (int i = 0; i < M; i++) cin >> A[i];
    sort(A.begin(), A.end());

    map<int, int> m;
    m[1] = 2;
    m[2] = 5;
    m[3] = 5;
    m[4] = 4;
    m[5] = 5;
    m[6] = 6;
    m[7] = 3;
    m[8] = 7;
    m[9] = 6;

    vector<int> use;
    for (int i = 0; i < A.size(); i++) use.push_back(m[A[i]]);
    sort(use.begin(), use.end());
    use.erase(unique(use.begin(), use.end()), use.end());

    SHOW_VECTOR(use);

    vector<int> dp(N + 100, -1);
    dp[0] = 0;
    for (int i = 0; i <= N; i++) {
        if (dp[i] >= 0) {
            for (int j = 0; j < use.size(); j++) {
                dp[i + use[j]] = max(dp[i + use[j]], dp[i] + 1);
            }
        }
    }
    SHOW_VECTOR(dp);

    string ans = "";
    int remain = N;
    int digit = dp[N];
    while (remain > 0) {
        for (int i = M - 1; i >= 0; i--) {
            if (remain - m[A[i]] >= 0 && digit - dp[remain - m[A[i]]] == 1) {
                ans += (char) ('0' + A[i]);
                remain -= m[A[i]];
                digit--;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}



























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

int main(){

	int lcount = 0;
	string s;

	cin >> s;

	for (int i = 0; i < s.length(); i++)
	{
		if(s[i] == 'x') lcount++;
	}
	
	cout << (lcount < 8? "YES": "NO") << endl;
	return 0;
}

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

using ll=long long;
int main(){
    int n;
    cin>>n;
    ll x;
    cin>>x;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a.begin(),a.end());
    int res=0;
    for(int i=0;i<n;i++){
        if(a[i]<=x){
            x-=a[i];
            res++;
        }
    }
    if(x==0) cout<<res<<endl;
    else cout<<min(res,n-1)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int p[100][100];
int m;
int dp[100][100];
int calc(int a,int b,int c){
	if(~dp[b][c])return dp[b][c];
	if(b==c){
		int ret=p[a][b];
		if(b==0)ret=!ret;
		if(b==m-1)ret=!ret;
		return dp[b][c]=ret;
	}
	return dp[b][c]=max(calc(a,b+1,c)+(((b==0&&p[a][b]==1)||(b!=0&&p[a][b]==0))?1:0),calc(a,b,c-1)+(((c==m-1&&p[a][c]==1)||(c!=m-1&&p[a][c]==0))?1:0));
}
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	m=b;
	for(int i=0;i<a;i++)
		for(int j=0;j<b;j++)
			scanf("%d",&p[i][j]);
	for(int i=1;i<a;i++)
		for(int j=0;j<b;j++)
			p[i][j]=!p[i][j];
	int ret=0;
	for(int i=0;i<a;i++){
		for(int k=0;k<100;k++)
			for(int j=0;j<100;j++)
				dp[k][j]=-1;
		ret+=calc(i,0,b-1);
	//	printf("%d\n",calc(i,0,b-1));
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 1112
N,T = input().split(" ")
N,T = int(N),int(T)

time = dict()
for i in range(N):
	c,t = input().split(" ")
	time[int(c)] = int(t)
cost = 10000
# print(sorted(time.items(), key=lambda item: item[1]))
for key, value in sorted(time.items(), key=lambda item: item[1]):
	if value <= T:
		if cost > key:
			cost = key
			# print(cost)

if cost ==10000:
	print("TLE")
else:
	print(cost)

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

int main(){
  
  string s, t;
  
  cin >> s >> t;
  
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  
  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n,k;
vector<int>a,b;

int main(){
	cin >> n >> k;
	rep(i,n){
		int aa; cin >> aa;
		if(aa >= 0) a.pb(aa); else b.pb(-aa);
	}
	SORT(a); SORT(b);
	int ans = INF;
	rep(i,k+1){
		if(a.size() < i) continue;
		if(b.size() < k-i) continue;
		
		int L,R;
		if(i) L = a[i-1]; else L = 0;
		if(k-i>0) R = b[k-i-1]; else R = 0;
		ans = min(ans,L+R+min(L,R));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int main()
{
	fast;
	double a,b,h,m,hr,min,ha,ma;
	double phx,phy,pmx,pmy,dist;
	cin>>a>>b>>h>>m;
	hr=h;
	min=m;
	ha=hr*30 + m/2;
	ma=min*6;
	// cout<<ha<<ma<<endl;
	phy=a*cos(ha*pi/180);
	phx=a*sin(ha*pi/180);
	pmy=b*cos(ma*pi/180);
	pmx=b*sin(ma*pi/180);
	// cout<<phx<<phy<<endl;
	// cout<<pmx<<pmy<<endl;
	dist=sqrt((phx-pmx)*(phx-pmx) + (phy-pmy)*(phy-pmy));
	cout.precision(25);
	cout<<dist;
	return 0;
}

//0,7569








Measured memory_bytes: 4180