akhauriyash/Code-Regression huggingface dataset:
/*  ex6_2
    yy8332  */

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

int main(void){

  int len_w;
  char word[100];

  //入力読み取り
  scanf("%s", word);

  //要素数の取得
  len_w = strlen(word);

  //出力
  printf("%c%d%c", word[0], len_w - 2, word[len_w - 1]);


  return 0;
}


Measured memory_bytes: 128
n=input()
K=int(input())
m=len(n)

DP=[[[0]*(K+2) for _ in range(2)] for _ in range(m+1)]
DP[0][0][0]=1

for i in range(1,m+1):
    for flag in range(2):
        num=9 if flag else int(n[i-1])
        for j in range(K+1):
            for k in range(num+1):
                if k==0:DP[i][flag or k<num][j] +=DP[i-1][flag][j]
                else:DP[i][flag or k<num][j+1] +=DP[i-1][flag][j]

print(DP[-1][0][K]+DP[-1][1][K])

Measured memory_bytes: 40944
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    tn = xn = yn = 0
    for i in range(n):
        t, x, y = list(map(int, input().rstrip('\n').split()))
        d = abs(xn - x) + abs(yn - y)
        td = t - tn
        if d - td > 0:
            print("No")
            exit()
        elif (d - td) % 2 != 0:
            print("No")
            exit()
        xn = x
        yn = y
        tn = t
    print("Yes")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 41836
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

#define ll long long

string a, b;

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

    int N = stoi(a+b);

    int buff = sqrt(N);

    if(N == buff*buff)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
}


Measured memory_bytes: 256
def main():
    n, k = (int(i) for i in input().split())

    # min_sum = sum([0, k)) = (k-1)(k-2) // 2
    # max_sun = sum([n-k+1, n+1))  = min_sum + (n-k+1)*k
    # total_sums = (n-k+1)*k + 1

    num_sums = sum((n-j+1)*j + 1 for j in range(k, n+2)) 
    print(num_sums % (10**9 + 7))


main()


Measured memory_bytes: 9104
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

////////////////////////////////////////////////////////


int main() {
    ll h, m, H, M, k;
    cin >> h >> m >> H >> M >> k;

    if(h > H) H += 24;
    ll ans = (H-h)*60 + M-m;
    ans -= k;
    if(ans < 0) co(0);
    else co(ans);

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>//cout
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <list>
#include <utility>//swap
using namespace std;
static const int MAX = 200000;
#define rep(i,n) for(int i=0;i<n;i++)
#define GET_ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
 
int main() {
  long long int n, h;
  int x=0, y=0, x2, y2,t=0,t2;
  cin >> n;
  //z = x + y;
  //int num = std::atoi(z.c_str());
  for (int i = 0; i < n; i++) {
    cin >>t2 >> x2 >> y2;
    if (t2-t < abs(x2-x) + abs(y2-y) || (t2-t)%2 != (abs(x2-x) + abs(y2-y))%2) {
      cout << "No" << endl;
      return 0;
    }
    t = t2;
    x = x2;
    y = y2;
  }
    cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
public class Main {
  private static void solve() {
    int n = ni();
    int m = ni();
    int k = ni();
    
    for (int i = 0; i <= m; i ++) {
      for (int j = 0; j <= n; j ++) {
        int s = i * j + (m - i) * (n - j);
        if (k == s) {
          System.out.println("Yes");
          return;
        }
      }
    }
    System.out.println("No");
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




Measured memory_bytes: 24660
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF = 1e11;
vector<ll> s,t;

int main()
{
	int A,B,Q;
	cin >> A >> B >> Q;
	s.push_back(-INF);
	ll c;
	rep(i,A)
	{
		cin >> c;
		s.push_back(c);
	}
	s.push_back(INF);
	t.push_back(-INF);
	rep(i,B)
	{
		cin >> c;
		t.push_back(c);
	}
	t.push_back(INF);
	rep(i,Q)
	{
		ll x;
		cin >> x;
		ll ans = INF;
		auto sit = lower_bound(s.begin(), s.end(), x), tit = lower_bound(t.begin(), t.end(), x);
		ll sright = *sit, tright = *tit;
		sit--; tit--;
		ll sleft = *sit, tleft = *tit;
		ans = min(ans, x - min(sleft,tleft));
		ans = min(ans, max(sright,tright) - x);
		ans = min(ans, (tright - x) + (tright - sleft));
		ans = min(ans, (sright - x) + (sright - tleft));
		ans = min(ans, (x - tleft) + (sright - tleft));
		ans = min(ans, (x - sleft) + (tright - sleft));
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include<iostream>
#include<vector>

int main(){
	//入力機構
	size_t T;
	std::cin>>T;
	std::vector<long long> A(T,0),B(T,0),C(T,0),D(T,0);//long longは10^18を表せる
	for(size_t i=0;i<T;i++){
		std::cin>>A[i]>>B[i]>>C[i]>>D[i];
	}

	for(size_t i=0;i<T;i++){
		//処理機構
		bool ans=false;
		//D>=B,A>=Bを調べる
		if(A[i]>=B[i]){
			if(D[i]%B[i]==0){
				//B*n==Dなら、はじめの1回仕入れが起これば永遠に買える
				ans=(A[i]%B[i]<=C[i]);
			}else if(D[i]>B[i]){
				const long long p0=A[i]%B[i];
				//この処理はp0に(D-B)をCより大きくなるまで加え、加え終わったらBを引いてp1として同じ処理をする。というのを繰り返す。
				//p0,p1,...のどれもが0未満になってはいけない。
				//(違う)D-BとBの最大公約数をEとすれば、pとして出現する数値の候補はp0%E+jE(jは整数)で表せるC-Bより大きくC以下の全ての値である。
				//D-BとBの最大公約数をEとすれば、pとして出現する数値の候補はp0%E+jE(jは整数)で表せるC以下のCから近い順にB/E個の整数である。
				//この候補の全てが0以上かどうかを判定すればよい。
				//(違う)つまり、(p0+jE(mod B)の最大値)<=Cなら永遠に買えるのでは？
				//つまり、((切り下げ)((C-p0%E)/E))*E-(B-E)>=0なら永遠に買えるのでは？
				//ユークリッドの互除法でEを求める
				long long E=B[i],f=D[i];
				while(true){
					long long tmp=f%E;
					if(tmp==0){
						break;
					}
					f=E;
					E=tmp;
				}
				//条件式に当てはめる
				//ans=((p0%E+B[i]-E)<=C[i]);
				ans=(((C[i]-p0%E)/E)*E-(B[i]-E)>=0);
			} 
		}

		//出力機構
		std::cout<<(ans?"Yes":"No")<<std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
n = int(input())
H = list(map(int, input().split()))
L = [H[0]-1]
if n == 1:
  print("Yes")
else:
  i=0
  while H[i+1] - L[i] >= 0:
    if i == n-2:
      print("Yes")
      break
    elif H[i+1] - L[i] == 0:
      L.append(H[i+1])
      i += 1
    elif H[i+1] - L[i] >= 1:
      L.append(H[i+1] - 1)
      i += 1
  else:
    print("No")
    
  

Measured memory_bytes: 14396
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>

using namespace std;

#define x first
#define y second
#define NMAX 100005
#define INF 1000000007

int n, viz[NMAX], subTree[NMAX]; 
vector<int> graph[NMAX];

void dfs(int node) {
    viz[node] = 1;
    subTree[node] = 1;
    
    int lim = graph[node].size(), sum = 0;
    for(int i = 0; i < lim; i++) {
        int neigh = graph[node][i];
        if(!viz[neigh]) {
            dfs(neigh);
            subTree[node] = (subTree[node] + subTree[neigh]) %  2;
            sum += subTree[neigh];
        }
    }
    sum += (n - subTree[node]) % 2;
    if(sum != 1) {
        printf("First\n");
        exit(0);
    }
}

int main (){
    int a, b;
    
    scanf("%d",&n);
    for(int i = 1; i < n; i++) {
        scanf("%d%d",&a,&b);
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(1);
    printf("Second\n");
    return 0;
}



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

int main(){
  vector<vector<int>> C(3,vector<int>(3));
  int count=0;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> C.at(i).at(j);
    }
  }
  for(int i=1;i<3;i++){
    if(C.at(i).at(0)-C.at(0).at(0)==C.at(i).at(1)-C.at(0).at(1)
       && C.at(i).at(1)-C.at(0).at(1)==C.at(i).at(2)-C.at(0).at(2)){
      count++;
    }
  }
  if(count==2){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

#define fi first
#define se second

const int N = 300300;
const int MAGIC = 1000;
const long long mod = 998244353;

using namespace std;

int n;
char c[N];

bool go(int x, int y)
{
        while(x < y){
                if(c[x + 1] == '.'){
                        x += 1;
                } else if(c[x + 2] == '.'){
                        x += 2;
                } else{
                        return false;
                }
        }
        return x == y;
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        int A, B, C, D;
        cin >> n >> A >> B >> C >> D;
        for(int i = 1; i <= n; i++){
                cin >> c[i];
        }
        if(!go(A, C) || !go(B, D)){
                cout << "No" << "\n";
                return 0;
        }
        bool res = 1;
        if(C > D){
                res = 0;
                while(B <= D){
                        if(c[B - 1] == '.' && c[B + 1] == '.'){
                                res = 1;
                                break;
                        }
                        if(c[B + 1] == '.'){
                                B += 1;
                        } else{
                                B += 2;
                        }
                }
        }
        if(res){
                cout << "Yes" << "\n";
        } else{
                cout << "No" << "\n";
        }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

bool bipartite_coloring(int now, int col, Graph &G, vector<int> &mark){
    //vector<int> mark(N, -1) を渡す！
    if(mark[now] != -1) return (mark[now] == col);
    mark[now] = col;
    bool ok = true;
    for(auto next: G[now]){
        ok &= bipartite_coloring(next, 1-col, G, mark);
    }
    return ok;
}

// https://atcoder.jp/contests/code-festival-2017-qualb/tasks/code_festival_2017_qualb_c
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, M;
    cin >> N >> M;    
    Graph G(N);
    REP(i, M){
        ll u, v;
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    vector<int> mark(N, -1);
    if(bipartite_coloring(0, 0, G, mark)){
        ll res = 0;
        int black = 0;
        REP(i, N) black += mark[i];
        res += black*(N-black);
        REP(now, N){
            for(auto next: G[now]){
                if(now>next and mark[now]!=mark[next]) res--;
            }
        }
        cout << res << endl;
    }else{
        cout << N*(N-1)/2 - M << endl;
    }


    return 0;
}

Measured memory_bytes: 7808
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	bool t[3]={};
	REP(i, 2){
		cin >> tmp;
		t[tmp-1] = true;
	}
	REP(i, 3) if(!t[i]) cout << i+1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ACC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mod 1000000007
#define MAXN 10000001
//string alpha="abcdefghijklmnopqrstuvwxyz";
//int dx[]={1,-1,0,0};
//int dy[]={0,0,1,-1};
//int dx8[]={1,-1,0,0,1,1,-1,-1};
//int dy8[]={0,0,1,-1,1,-1,1,-1};
/*int spf[MAXN];
void sieve()
{
	int i,j;
	for(i=0;i<MAXN;i++)
	spf[i]=i;
	for(i=4;i<MAXN;i+=2)
	spf[i]=2;
	for(i=3;i*i<MAXN;i++)
	{
		if(spf[i]==i)
		{
			for(j=i*i;j<MAXN;j+=i)
			{
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}*/
/*bool isvowel(char c)
{
    switch(c)
    {
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':return true;
        default : return false;
    }
}*/
/*bool isValid(int x,int y,int n,int m)
{
    if(x<0||x>n-1||y<0||y>m-1)return false;
    return true;
}*/
/*
bool comp(pair<int,int> x,pair<int,int> y)
{
    if(x.first==y.first)
        return x.second<y.second;
    return x.first>y.first;
}*/

int32_t main()
{
    ACC
    int T;
    T=1;
    //cin>>T;
    //sieve();
    while(T--)
    {
        string s,t;
        cin>>s;
        cin>>t;
        int i,j;
        int mn=INT_MAX;
        for(i=0;i<s.length()-t.length()+1;i++)
        {
            string x=s.substr(i,t.length());
            int c=0;
            for(j=0;j<t.length();j++)
            {
                if(x[j]!=t[j])c++;
            }
            mn=min(mn,c);
        }
        cout<<mn<<"\n";
    }
    return 0;
}


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

#define int long long

using namespace std;

const int N = 2e5 + 5;

int n;
pair <int, int> a[N];

bool cmp (pair <int, int> &p1, pair <int, int> &p2) {
    return p1.first < p2.first;
}

bool cmp2 (pair <int, int> &p1, pair <int, int> &p2) {
    return p1.second < p2.second;
}

signed main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max(a * c, a * d), max(b * c, b * d));
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define sz(v) (int)v.size()
#define F first 
#define S second 
#define lc "\n"
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
ll MAX=1e18 , MIN=-1e18 , MOD=1000000007;
int main() 
{
    fastio
    int n,i,j,k,x; cin>>n; int a[10005]={0};
    for(i=1;i<=100;i++)
    {
        for(j=1;j<=100;j++)
        {
            for(k=1;k<=100;k++)
            {
                x=i*i+j*j+k*k+i*j+j*k+i*k;
                if(x<10005) a[x]++;
            }
        }
    }
    for(i=1;i<=n;i++) cout<<a[i]<<lc;
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)

int main() {
    string s; cin >> s;
    int n = s.size();
    int ans = 999;
    rep(i,n-2){
        int a = stoi(s.substr(i,3));
        ans = min(ans,abs(a-753));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = line[0];
            int B = line[1];
            int C = line[2];
            Console.WriteLine(A + B >= C ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 11092
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int H, W;
vector<string> grid;
int K;
int gx, gy; // 目的地
int sx, sy;
vector<vector<bool>> visited; 
vector<vector<int>> qed;

void input(void){
    cin >> H >> W >> K;
    cin >> sx >> sy >> gx >> gy;
    --sx, --sy, --gx, --gy;
    grid.resize(H);
    for (auto& gi : grid)
        cin >> gi;
    visited.resize(H, vector<bool>(W, false));
    qed.resize(H, vector<int>(W, (1 << 30)));
}

void bfs(){
    queue<tuple<int, int, int>> q;
    visited[sx][sy] = true;
    q.push(make_tuple(sx, sy, 0));
    qed[sx][sy] = 0;
    while (!q.empty()){
        auto tmp = q.front();
        q.pop();
        int x = get<0>(tmp);
        int y = get<1>(tmp);
        int d = get<2>(tmp);
        if (x == gx && y == gy){
            cout << d << endl;
            return;
        }
        for (int i = 1; i <= K; ++i){
            if (y - i < 0) break;
            if (grid[x][y - i] == '@') break;
            if (visited[x][y - i]){
                if (qed[x][y - i] == d + 1) continue;
                break;
            }
            visited[x][y - i] = true;
            q.push(make_tuple(x, y - i, d + 1));
            qed[x][y - i] = d + 1;
        }
        for (int i = 1; i <= K; ++i){
            if (y + i >= W) break;
            if (grid[x][y + i] == '@') break;
            if (visited[x][y + i]){
                if (qed[x][y + i] == d + 1) continue;
                break;
            }
            visited[x][y + i] = true;
            q.push(make_tuple(x, y + i, d + 1));
            qed[x][y + i] = d + 1;
        }
        for (int i = 1; i <= K; ++i){
            if (x - i < 0) break;
            if (grid[x - i][y] == '@') break;
            if (visited[x - i][y]){
                if (qed[x - i][y] == d + 1) continue;
                break;
            }
            visited[x - i][y] = true;
            q.push(make_tuple(x - i, y, d + 1));
            qed[x - i][y] = d + 1;
        }
        for (int i = 1; i <= K; ++i){
            if (x + i >= H) break;
            if (grid[x + i][y] == '@') break;
            if (visited[x + i][y]){
                if (qed[x + i][y] == d + 1) continue;
                break;
            }
            visited[x + i][y] = true;
            q.push(make_tuple(x + i, y, d + 1));
            qed[x + i][y] = d + 1;
        }
    }
    cout << -1 << endl;
}

int main(void){
    input();
    bfs();
    return 0;
}

Measured memory_bytes: 12440
#include <algorithm>
#include <cstdio>

const int N=100005;
int X[N],Y[N],fst[N],id1[N],id2[N],n,D,tot=0;
bool u[N];
long long ans=0;
struct Edge{int to,nxt;}e[N*8];

void addedge(int x,int y){
	e[++tot].to=y;e[tot].nxt=fst[x];fst[x]=tot;
	e[++tot].to=x;e[tot].nxt=fst[y];fst[y]=tot;
}

bool cmp(int i,int j){
	return X[i]!=X[j]?X[i]<X[j]:Y[i]<Y[j];
}

bool check(int i,int j,int x){
	return X[i]<X[j]+D || (X[i]==X[j]+D && Y[i]<Y[j]+x);
}

void work1(int *id){
	for (int i=1;i<=n;i++) id[i]=i;
	std::sort(id+1,id+n+1,cmp);
	for (int i=1,l=1,r=1;i<=n;i++){
		for (;l<=n && check(id[l],id[i],-D);l++);
		for (;r<=n && check(id[r],id[i],D+1);r++);
		if (l==r) continue;
		addedge(id[i],id[l]);
		for (;l+1<r;l++) addedge(id[l],id[l+1]);
	}
	for (int i=1;i<=n;i++) std::swap(X[i],Y[i]);
}

void work2(int *id,int d){
	for (int i=1,l=1,r=1;i<=n;i++){
		for (;l<=n && check(id[l],id[i],-d);l++);
		for (;r<=n && check(id[r],id[i],d+1);r++);
		if (u[id[i]]) ans+=r-l;
	}
	for (int i=1;i<=n;i++) std::swap(X[i],Y[i]);
}

void dfs(int x){
	if (u[x]) return;
	u[x]=1;
	for (int i=fst[x];i;i=e[i].nxt) dfs(e[i].to);
}

int main(){
	int a,b;
	scanf("%d%d%d\n",&n,&a,&b);
	for (int i=1;i<=n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		X[i]=x+y;Y[i]=x-y;
	}
	D=std::max(abs(X[a]-X[b]),abs(Y[a]-Y[b]));
	work1(id1);work1(id2);
	for (int i=1;i<=n;i++) u[i]=0;
	dfs(a);
	work2(id1,D);work2(id2,D-1);
	printf("%lld\n",ans);
}

Measured memory_bytes: 9856
import java.util.*
import java.math.*;
fun main(args: Array<String>) {

    val N = readLine()!!.split(" ").map{it.toInt()}[0]
    val S = readLine()!!
    val K = readLine()!!.split(" ").map{it.toInt()}[0]
    val ch = S[K-1]
    var ans = ""
    for (c in S) {
        if (c != ch) ans+="*"
        else ans+=c
    }
    println(ans)
}


Measured memory_bytes: 35952
#include <iostream>
#include <string>
#include <vector>
#include<limits>
#include<stack>
#include<queue>
#include<math.h>
#include <iomanip>

#define rep(i,n) for(auto i=0;i<(n);i++)
#define all(vs) (vs).begin(),(vs).end()
#define roundup(A,B) (A)/(B)+(A%B==0?0:1)
#define maximize(A,B) A=max((A),(B))
#define read(type,name) type name;cin>>name
#define ll long long

using namespace std;
template<typename T>
T MAX() { return numeric_limits<T>::max(); }

//二次元テーブル
template<typename T>
class Table {
public:
	Table(int height, int width, T value) {
		if (width < 0)throw out_of_range("Width should be >=0");
		if (height < 0)throw out_of_range("Height should be >=0");
		this->wid = width;
		this->hgt = height;
		vs = new T[width * height];
		for (auto i = 0; i < width * height; i++)vs[i] = value;
	}
	Table(const Table& table) {
		hgt = table.hgt;
		wid = table.wid;
		vs = new T[hgt * wid];
		for (size_t i = 0; i < table.size(); i++) {
			vs[i] = table.vs[i];
		}
	}
	Table(Table&& table) {
		hgt = table.hgt;
		wid = table.wid;
		swap(vs, table.vs);
	}
	~Table() {
		if (vs)delete[] vs;
	}
	Table& operator=(const Table& table) {
		if (table == *this)return *this;
		this->wid = table.wid;
		this->hgt = table.hgt;
		if (vs)delete[] vs;
		vs = new T[wid * hgt];
		for (auto i = 0; i < wid * hgt; i++)vs[i] = table.vs[i];
	}
	Table& operator=(Table&& table) {
		wid = table.wid;
		hgt = table.hgt;
		swap(vs, table.vs);
	}
	inline T& at(int y, int x) {
		if (wid > x)throw out_of_range("x>width.");
		if (hgt > y)throw out_of_range("y>height.");
		return vs[x + y * wid];
	}
	int size()const { return wid * hgt; }
	int width()const { return wid; };
	int height()const { return hgt; };
	T* begin() { return vs; }
	T* end() { return vs + wid * hgt; }
	T& operator()(int y, int x) { return vs[x + y * wid]; }
	const T& operator()(int y, int x)const { return vs[x + y * wid]; }
private:
	int wid, hgt;
	T* vs;
};//周期的に変化する。ループは剰余の環でうまく表せる。
void A() {
	string weather[]{ "Sunny","Cloudy","Rainy" };
	read(string, s);
	for (auto i = 0; i < 3; i++) {
		if (weather[i] == s) {
			cout << weather[(i + 1) % 3] << endl;
			return;
		}
	}
}
//全てが満たさねばならない条件の検査は、
//間違いを探す方が簡潔になる。
void B() {
	read(string, s);
	for (auto i = 0; i < s.length(); i++) {
		if (i % 2 == 0 && s[i] == 'L') {
			cout << "No" << endl;
			return;
		}
		if (i % 2 != 0 && s[i] == 'R') {
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
}
void C() {}
void D() {}
void E() {}
void F() {}

int main(){
	B();
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N,T;cin >> N >> T;
    vector<int> t(N);
    rep(i,N)cin >> t[i];
    ll res = 0;
    for(int i=0;i<N-1;i++){
        res+=min(T,t[i+1]-t[i]);
    }
    res+=T;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<vector<int>> x(N, vector<int>(0)), y(N, vector<int>(0));
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
    for(int j = 0; j < A.at(i); j++){
      int p, q;
      cin >> p >> q;
      p--;
      x.at(i).push_back(p);
      y.at(i).push_back(q);
    }
  }
  
  int result = 0;
  for(int tmp = 0; tmp < (1 << N); tmp++){
    bitset<15> bit(tmp);
    bool flag = true;
    int counter = 0;
    for(int i = 0; i < N; i++){
      //bitの右からi番目が1ならば正直者とする。それで矛盾があるかをチェック。
      if(bit.test(i)){
        counter++;
        for(int j = 0; j < A.at(i); j++){
          if(bit.test(x.at(i).at(j)) != y.at(i).at(j)) flag = false;
        }
      }
    }
    if(flag && counter > result) result = counter;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
    while (true) {
        int m, f, r;
        scanf("%d %d %d", &m, &f, &r);
        if (!~m && !~f && !~r) return 0;

        if (!~m || !~f) {
            printf("F\n");
        } else if (m+f >= 80) {
            printf("A\n");
        } else if (m+f >= 65) {
            printf("B\n");
        } else if (m+f >= 50) {
            printf("C\n");
        } else if (m+f >= 30) {
            if (r >= 50) {
                printf("C\n");
            } else {
                printf("D\n");
            }
        } else {
            printf("F\n");
        }
    }
}

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

#define INF 1e9

using namespace std;

// 各コインの価値
int c[21];
// dp[v] := 価値 v 円を支払うときに使用するコインの最小枚数
int dp[50001];

int main() {
    // n 円を m 種類のコインで支払う
    int n, m;

    cin >> n >> m;

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

    fill(dp, dp + 50001, INF);

    dp[0] = 0;

    for (int i = 0; i < m; i++) {
        for (int j = 0; j + c[i] <= n; j++) {
            dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1);
        }
    }

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 3308
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    vi a(n);
    rep(i, n){
        string in; cin >> in;
        a[i] = (in == "A");
    }

    auto f = [&]{
        int cnt = 0;
        rep(i, n){
            if(a[i]) cnt++;
            else {
                if(cnt-- == 0) return false;
            }
        }
        return cnt == 0;
    };

    cout << (f() ? "YES":"NO") << endl;

    return 0;
}

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

int main() {
    string s;
    cin >> s;
    bool isSeven = false;
    for(char c : s){
        if(c == '7') isSeven = true;
    }
    if(isSeven) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define watch(x) std::cout << (#x) << " is " << (x) << std::endl
#define print(x) std::cout << (x) << std::endl
using LL = long long;
const  LL M = 1e9 + 7;

int main() {
	//freopen("in","r",stdin);
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n;
	std::cin >> n;
	int x[n], y[n];
	for (int i = 0; i < n; ++i) {
		std::cin >> x[i] >> y[i];
	}
	int xx[2] = {0, 0}, yy[2] = {0, int(1e9)};
	int t[2][n];
	for (int id = 0 ; id < 2; ++id) {
		for (int i = 0; i < n; ++i) {
			t[id][i] = abs(x[i] - xx[id]) + abs(y[i] - yy[id]);
		}
	}
	int r0 = *std::max_element(t[0], t[0] + n) - *std::min_element(t[0], t[0] + n);
	int r1 = *std::max_element(t[1], t[1] + n) - *std::min_element(t[1], t[1] + n);
	print(std::max(r0, r1));
	return 0;
}


Measured memory_bytes: 6760
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}


 main()

{
    fast
    int h1,s1,h2,s2;
    cin>>h1>>s1>>h2>>s2;
    int turn=0;
     while(1)
     {

         if(turn==0)
         {
             h2-=s1;
             if(h2<=0)
             {
                 cout<<"Yes\n";
                 return 0;
             }
         }
          else
          {
              h1-=s2;
              if(h1<=0)
              {
                  cout<<"No\n";
                  return 0;
              }
          }
          turn=1-turn;

     }
    return 0;

}
















Measured memory_bytes: 3636
# これは逆元を用いてやる？
# この問題の場合、逆元をうまく設定するのが難しいので
# 左右からのmergeになりそう
from collections import deque
import sys

input = sys.stdin.buffer.readline


n, m = map(int, input().split())
# 各々の頂点の次数
deg = [0] * (n + 1)
# 隣接リストにグラフをまとめる
graph = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    x, y = map(int, input().split())
    graph[x].append(y)
    graph[y].append(x)
    deg[x] += 1
    deg[y] += 1

# dp1は葉向きに見たときの塗り方
# 自身が黒い時、下の候補はどうなるか？
dp1 = [0] * (n + 1)

# dp2は根向きに見たときの塗り方
# 自身が黒い時、親側の候補はどうなるか？
dp2 = [0] * (n + 1)

# 1回目
start = 1
par = [-1] * (n + 1)
que = deque([start])
topo = []
while que:
    v = que.popleft()
    topo.append(v)
    for i in range(deg[v]):
        u = graph[v][i]
        if par[v] == u:
            continue
        par[u] = v
        que.append(u)

# dpするついでにi=0からの積とi=deg[v]-1からの積を取っておくか。
dpl = [[] for _ in range(n + 1)]
dpr = [[] for _ in range(n + 1)]

# 頂点番号から何番目かがわかるようにしたいから辞書で持っておく？
edge_num = [{} for _ in range(n + 1)]

for v in topo[::-1]:
    temp = 1
    for i in range(deg[v]):
        u = graph[v][i]
        edge_num[v][u] = i  # edge_num[v]で頂点vに関する辞書。頂点uからidxが欲しいので記録
        if u == par[v]:
            dpl[v].append(temp)
            continue
        temp *= dp1[u] + 1
        temp %= m
        dpl[v].append(temp)
    dp1[v] = temp
    temp = 1
    for i in range(deg[v] - 1, -1, -1):
        u = graph[v][i]
        if u == par[v]:
            dpr[v].append(temp)
            continue
        temp *= dp1[u] + 1
        temp %= m
        dpr[v].append(temp)
# これで普通の木DPに加えて
# 左右からの累積積
# 頂点番号からidxへの辞書
# を獲得したはず

# dpは欲しい答えとしておく
# dp1とdp2から求める
dp = [0] * (n + 1)

for v in topo:
    # dp2の計算
    p = par[v]
    if p == -1:  # 例外、親がいない
        dp[v] = dp1[v]
        dp[v] %= m
        continue
    # 根側の処理
    # 自分以外の積を作りたい
    idx = edge_num[p][v]
    num = deg[p]
    dp2[v] = 1
    if idx - 1 >= 0:
        dp2[v] *= dpl[p][idx - 1]
        dp2[v] %= m
    if num - 2 - idx >= 0:
        dp2[v] *= dpr[p][num - 2 - idx]
        dp2[v] %= m
    # 根側の根側の処理
    pp = par[p]  # 親の親
    if pp != -1:  # 親の親がいるならば
        dp2[v] *= dp2[p] + 1  # 白=1か黒=dp2[pp]か
        dp2[v] %= m
    # dpの計算
    dp[v] = dp1[v] * (dp2[v] + 1)
    dp[v] %= m
print(*dp[1:], sep="\n")


Measured memory_bytes: 129200
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

n=i1()
k=i1()
x=i2()
c=0
for i in x:
    if i>abs(k-i):
       c+=abs(k-i)
    else:
       c+=i
print(c*2)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod 1000000007
int main() {
    fio;
    ll x, k, d;
    ll ans = LONG_MAX;
    cin >> x >> k >> d;
    if (x < 0)
    {
        ll n = (-1 * x) / d;
        ll temp = k - n;

        if (temp <= 0)
        {
            cout << labs(x + k * d) << endl;
            return 0;
        }
        x = x + n * d;
        k = k - n;
    }
    if (x < d)
    {
        x = x + d;
        k--;
    }
    ll steps = x / d;
    ll rem = k - steps;
    if (rem > 0 and rem % 2 == 0) {
        ans = labs(x % d);
    }
    else if (rem > 0 and rem % 2 != 0) {
        ans = labs((x % d) - d);
    }
    else if (rem <= 0) {
        ans = labs(x - k * d);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3556
import numpy as np
N = int(input())
p = input().split()
p = np.array(p).astype(type(N))

sorted_list = [i for i in range(1,N+1)]
sorted_list = np.array(sorted_list).astype(type(N))

OK_list =   np.uint8(sorted_list != p)

if(np.sum(OK_list) <= 2):
    print('YES')
else:
    print('NO')


Measured memory_bytes: 21668
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,x,y,ans=0;
  cin>>n>>k>>x>>y;
  for(int i=1;i<=n;i++){
    if(i<=k)
      ans+=x;
    else
      ans+=y;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない


int main() {

	int a;
	cin >> a;
	if (a == 3 || a == 5 || a == 7) {
		YES;
	}
	else {
		NO;
	}


	return 0;
}

Measured memory_bytes: 764
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define DEBUG
#undef DEBUG

using ll  = long long;
using ull = unsigned long long;

int N, K;
ll A[5001];

bool dp[5001][5001]; // i枚目まで使ったとき総和をjにできるか

bool is_needed(int k)
{
    bool need = false;

    if(A[k] >= K) return true; // 集合 {k} が存在するためkは必要

    // 一時的にカードkを取り除く
    ll tmp = A[k];
    A[k] = 0;

    // DP
    FOR(i, 1, N+1) {
        FOR(j, 1, K) {
            // i枚目を使うか使わないかの2択
            // 使う場合、dp[i-1][j-A[i]]
            // 使わない場合、dp[i-1][j]
            // ただし j-A[i] < 0 ならば使えない
            if(j-A[i] < 0) {
                dp[i][j] = dp[i-1][j];
            }
            else {
                dp[i][j] = dp[i-1][j-A[i]] || dp[i-1][j];
            }
        }
    }
    // N枚目まで使って総和を [K-tmp, K-1] にできるならkは必要
    FOR(j, K-tmp, K) {
        if(dp[N][j]) need = true;
    }

    // カードkを戻す
    A[k] = tmp;

    return need;
}

void solve()
{
    // ソートを忘れずに!!
    sort(A+1, A+N+1);

    FOR(i, 0, N+1) {
        dp[i][0] = true;
    }
    FOR(j, 1, K+1) {
        dp[0][j] = false;
    }

    // iが不要であるとき、A[j] <= A[i] なるjも不要
    // もしjが必要だったとすると、jが必須であるようなよい集合がとれる
    // が、その中のjをiに置き換えたものもiが必須であるようなよい集合だ
    // から矛盾する。
    //
    // よって単調性が成り立ち、二分探索できる
    // 不明なカードの範囲を狭めていく
    // 最初は [1,N] が不明
    int cnt;
    int kmax = N;
    int kmin = 1;
    for(;;) {
        int k = (kmax+kmin) / 2;
        if(is_needed(k)) {
            if(kmax == kmin) {
                cnt = k-1;
                break;
            }
            kmax = k;
        }
        else {
            if(kmax == kmin) {
                cnt = k;
                break;
            }
            kmin = k+1;
        }
    }

    cout << cnt << "\n";
}

int main()
{
    cin >> N >> K;
    FOR(i, 1, N+1) {
        cin >> A[i];
    }

    solve();

    return 0;
}


Measured memory_bytes: 24704
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import Data.Maybe (fromJust)

getInts::IO[Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

main = do
  n <- readLn
  a1n <- getInts
  a2n <- getInts
  let a1nv = VU.fromList a1n
      a2nv = VU.fromList a2n
  print $ VU.maximum . VU.map (\x -> VU.sum (VU.take x a1nv) + VU.sum (VU.drop (x-1) a2nv)) $ VU.fromList [1..n]


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

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

  int N; cin >> N;
  vector<int> A(3 * N, 0);
  for (int i = 0; i < 3 * N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  ll ans = 0;
  for (int i = 0; i < 2 * N; i++) {
    if (i % 2 == 1) ans += A[i];
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(void){
  int up=0,down=0;
  int t,n,h,for_h;
  cin>>t;
  for(int i=0;i<t;i++){
    cin>>n;
    up=0;
    down=0;
    h=0;
    for_h=0;
    for(int j=0;j<n;j++){
      for_h=h;
      cin>>h;
      if(j==0) continue;
      if(h>for_h) up=(up<h-for_h)?h-for_h:up;
      else if(h<for_h) down=(down<-h+for_h)?-h+for_h:down;
    }
    cout<<up<<' '<<down<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  scanf("%d",&n);
  int a[n];
  REP(i, n) scanf("%d",&a[i]);

  sort(a, a+n);
  double ans = ((double)a[0] + a[1])/2.0;
  FOR(i, 2, n) ans = (ans + (double)a[i])/2.0;

  printf("%f\n",ans);
  
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    idx=[[] for _ in range(max(A)+1)]
    for i,a in enumerate(A):
        idx[a].append(i)

    # いくつ先に移動するかを求める
    next=[None]*n
    for I in idx:
        if(not I): continue
        s=len(I)
        I.append(I[0]+n)
        for i in range(s):
            next[I[i]]=I[i+1]-I[i]+1

    # doubling
    M=10**18 # n*k より大きな数で抑えておく
    nexts=[next]
    for _ in range(60):
        next=nexts[-1]
        nnext=[min(M,next[i]+next[(i+next[i])%n]) for i in range(n)]
        nexts.append(nnext)

    now=0
    for next in nexts[::-1]:
        if(now+next[now%n]<=n*k):
            now+=next[now%n]
    if(now==n*k):
        return

    # A[now%n:] に対してシミュレーションする
    ans=[]
    have=[0]*(max(A)+1)
    for a in A[now%n:]:
        if(not have[a]):
            ans.append(a)
            have[a]=1
        else:
            while(1):
                x=ans.pop()
                have[x]=0
                if(x==a): break

    print(*ans)
resolve()

Measured memory_bytes: 211572
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main(){
	int N;
	cin >> N;
	map<int,LL> m;
	int number[200010];
	rep(i,N){
		int A;
		cin >> A;
		m[A]++;
		number[i]=A;
	}
	LL num[200010]={0};
	LL sum=0;
	rep(i,N+1){
		num[i]=m[i]*(m[i]-1)/2;
		sum+=num[i];
	}
	rep(i,N){
		LL j=number[i];
		LL k=m[j];
		cout << sum-k*(k-1)/2+(k-1)*(k-2)/2 << endl;
	}

	return 0;
}

Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

int equal(int x, int y, int z) {
  int res = 0;
  if (x == y) res++;
  if (y == z) res++;
  if (z == x) res++;
  return res;
}

void solve(istream& cin, ostream& cout) {
  int K, S;
  cin >> K >> S;
  ll ans = 0;
  REP(x, K + 1) {
    if (x + 2 * K < S) continue;
    FOR(y, x, K + 1) {
      if (x + y + K < S) continue;
      FOR(z, y, K + 1) {
        if (x + y + z == S) {
          switch (equal(x, y, z))
          {
          case 0:
            ans += 6;
            break;
          case 1:
            ans += 3;
            break;
          case 2:
            ans += 3;
            break;
          case 3:
            ans += 1;
            break;
          }
        }
      }
    }
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
using namespace std;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
template<class T> void print(const T& x){cout << x << endl;}
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;

int main(){
    int N; cin >> N;
    string s; cin >> s;
    int n = s.length() - 2;
    int cnt = 0;
    rep(i, 0, n){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') cnt += 1;
    }
    cout << cnt << endl;
    return 0;
}




Measured memory_bytes: 3520