akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define int long long

const int N = 1e5 + 100;
const int INF = 1e15;
int dp[N], h[N], n, k;

int sol(int idx) {
    if (idx == n) return 0;
    int &ans = dp[idx];
    if (ans != -1) return ans;
    ans = INF;
    for (int i = 1; i <= k; i++) {
        if (idx + i <= n) {
            ans = min(ans, sol(idx + i) + abs(h[idx + i] - h[idx]));
        }
    }
    return ans;
}

void solve() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> h[i];
    memset(dp, -1, sizeof(dp));
    cout << sol(1) << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin>>t;
    while (t--) {
        solve();
    }
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = long.Parse(Console.ReadLine());
            var n = (long) 100;
            var cnt = (long) 0;
            while (n < k)
            {
                n = (long) (n * 1.01);
                cnt++;
            }
            Console.WriteLine(cnt);
        }
    }
}

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

int main(void)
{
    int N;
    cin >> N;
    int maxA = 0;
    int SecA = 0;
    int tmp;
    int maxNumber;
    for (int i = 0; i < N; i++) {
        scanf("%d", &tmp);
        if (tmp > SecA) {
            if (tmp > maxA) {
                SecA = maxA;
                maxA = tmp;
                maxNumber = i;
            }
            else {
                SecA = tmp;
            }
        }
    }

    for (int i = 0; i < N; i++) {
        if (i == maxNumber) {
            cout << SecA << endl;
        }
        else {
            cout << maxA << endl;
        }
    }
}

Measured memory_bytes: 1664
import java.util.*;

public class Main {

	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		int animal = Integer.parseInt(sc.next());
		int leg = Integer.parseInt(sc.next());

		// 例えばanimal=3, leg=8 なら、つる２かめ１

		for (int turu = 0; turu <= animal; turu++) {

			int kame = animal - turu;

			if ((turu * 2) + (kame * 4) == leg) {
				System.out.println("Yes");
				return;
			}
		}

		System.out.println("No");
	}

}


Measured memory_bytes: 35652
// https://atcoder.jp/contests/abc172/tasks/abc172_f

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

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DEBUG 1
#if DEBUG
  #define _GLIBCXX_DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const int N_MAX = 300;
const ull A_I_MAX = 1e12;

int N;
vector<ull> A;

int main() {
  cin >> N;
  A = vector<ull>(N);
  REP(i, N) cin >> A[i];

  ull X = 0;
  FOR(i, 2, N - 1) X ^= A[i];
  // cout << "X:" << X << endl;

  ull S = A[0] + A[1];
  // cout << "S:" << S << endl;

  if (S < X) {
    // cout << "S < X" << endl;
    cout << -1 << endl;
    return 0;
  }
  ull D = S - X;
  if (D & 1) {
    // cout << "D is odd" << endl;
    cout << -1 << endl;
    return 0;
  }
  D >>= 1;
  // cout << "D:" << D << endl;
  if (D > A[0]) {
    // cout << "D > A[0]" << endl;
    cout << -1 << endl;
    return 0;
  }
  if (X & D) {
    // cout << "X & D > 0" << endl;
    cout << -1 << endl;
    return 0;
  }

  ull a = D;
  for (int i = 39; i >= 0; i--) {
    ull f = 1ULL << i;
    if ((X & f) && ((a | f) <= A[0])) {
      a |= f;
    }
  }
  // cout << "a:" << a << endl;
  if (a == 0) {
    // cout << "a is 0" << endl;
    cout << -1 << endl;
    return 0;
  }

  cout << (A[0] - a) << endl;
}


Measured memory_bytes: 3596
import math
A, B ,H, M = map(int,input().split())
t = M / 60
c = (H * 60 + M)/720
t *= 360
c *= 360
d = abs(t-c)
rad = min(360-d,d)
COS = math.cos(math.radians(rad))
C = A**2 + B**2 - 2*A*B*COS
print(math.sqrt(C))

Measured memory_bytes: 9508
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);
#define PAR(a,b) make_pair(a,b)
#define PFOR(a,b,name) for(int i=a;i<=b;++i){cout<<name[i]<<" ";}cout<<endl;
#define IFOR(a,b,name) for(int i=a;i<=b;++i){cin>>name[i];}
#define ll long long
#define euclid(x1,y1,x2,y2) ((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
using namespace std;

const double pi = 3.141592653589;
const int INF = 1<<30;
const int mod = (1e9)+7;

int main()
{
    IOS
    ///freopen("out.txt","w",stdout);
    ///freopen("in.txt","r",stdin);
    int a,b;
    cin>>a>>b;

    if(b>a)swap(a,b);

    if(a>=0 && b<=0){cout<<"Zero"<<endl;} else
    if(b<0 && a<0 && (abs(a-b)+1)%2!=0){cout<<"Negative"<<endl; }else
    if(b<0 && abs(b)%2!=0){cout<<"Negative"<<endl;}else
    cout<<"Positive"<<endl;


}
/// This code is less virgin than me


Measured memory_bytes: 256
#!/usr/bin/env python


s = input()
#s = "RRLLLLRLRRLL"
n = len(s)

n_R = []
n_L = []
flg_RL = False

i_begin = 0
for i in range(n-1):
    if not flg_RL:
        if s[i] == 'R' and s[i+1] == 'L':
            n_R.append(i-i_begin)
            flg_RL = True
    else:
        if s[i+1] == 'R':
            n_L.append(i-i_begin-n_R[-1]-1)
            i_begin = i + 1
            flg_RL = False

n_L.append(n-i_begin-n_R[-1]-2)
#print (n_R)
#print (n_L)

flg_space = False

for nR, nL in zip(n_R, n_L):
    if flg_space:
        print (' ', end='')

    for i in range(nR):
        print('0 ', end='')

    R = 1
    L = 1
    if nR % 2 == 0:
        R += nR // 2 
        L += nR // 2 
    else:
        R += nR // 2
        L += nR // 2 + 1

    if nL % 2 == 0:
        R += nL // 2 
        L += nL // 2 
    else:
        R += nL // 2 + 1
        L += nL // 2

    print('%i %i' % (R, L), end='')
    for i in range(nL):
        print(' 0', end='')

    flg_space = True

print ('')

Measured memory_bytes: 4976
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

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


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

	vector<int> a(n);
	rep(i,n) cin >> a[i];

	int pre = a[0], ans = 0;
	bool b1 = false, b2 = false;
	rep(i,n){
	  if (!b1 && a[i] < pre) { b1 = true; if (b2) {b1 = b2 = false; ans++;}} 
		if (!b2 && a[i] > pre) { b2 = true; if (b1) {b1 = b2 = false; ans++;}}
		pre = a[i];
	}
	cout << ans+1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
string A,B,C;
  std::cin >> A>>B>>C;
  if(A[A.size()-1]==B[0] && B[B.size()-1]==C[0]){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  return 0;
}


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

int main() {
    string abcd;
    cin >> abcd;
    int a, b, c, d;
    a = abcd.at(0) - '0';
    b = abcd.at(1) - '0';
    c = abcd.at(2) - '0';
    d = abcd.at(3) - '0';
    
    while (true) {
        if (a + b + c + d == 7) {
            cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
            break;
        }
        else if (a + b + c - d == 7) {
            cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
            break;
        }
        else if (a + b - c + d == 7) {
            cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
            break;
        }
        else if (a + b - c - d == 7) {
            cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
            break;
        }
        else if (a - b + c + d == 7) {
            cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
            break;
        }
        else if (a - b + c - d == 7) {
            cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
            break;
        }
        else if (a - b - c + d == 7) {
            cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
            break;
        }
        else if (a - b - c - d == 7) {
            cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 2e5+5, M=2e4+5, oo=0x3f3f3f3f;

ll lcm, n, x, y, a[N], ans;

ll gcd(ll a, ll b)
{
    if(!b)
        return a;
    return gcd(b, a%b);
}

int main()
{
    cin >> n;
    if(n == 1)
    {
        cin >> n;
        cout << n;
        return 0;
    }
    for(int i=0; i<n; i++)
        cin >> a[i];
    lcm = a[0]/gcd(a[0], a[1])*a[1];
    for(int i=2; i<n; i++)
    {
        lcm = a[i]/gcd(a[i], lcm) * lcm;
    }
    for(int i=0; i<n; i++)
    {
        ans+=(lcm/a[i]);
    }
    cout << fixed << setprecision(8) << (1.0*lcm)/(1.00*ans);

    return 0 ;
}


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

int main(){
int A,n,t,a;
   double An,b,c;
   cin>>n>>t>>a;
   vector<double> an(n);
   for(int i=0;i<n;i++){
      cin>>an.at(i);
   }
   for(int j=0;j<n;j++){
     b,c=0;
      b=t-an.at(j)*0.006;
      c=a-b;
      if(c<0){
         c *= -1;}
//cout<<c<<endl;
      if(j==0){
          An=c;
          A=j+1;}
       if(c<An){
          An=c;
          A=j+1;}
      }
   cout <<A<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
			long ans=0;
			int n=sc.nextInt();
			long c=sc.nextLong();
			long []x=new long [n];
			int []v=new int [n];
			for(int i=0;i<n;i++)
			{
				x[i]=sc.nextLong();v[i]=sc.nextInt();
			}
			long []forward=new long [n];
			long []back=new long [n];
			long sum=0;
			for(int i=0;i<n;i++)
			{
				sum+=v[i];
				ans=Math.max(ans, sum-x[i]);
				forward[i]=(sum-x[i]);
				
			}
			sum=0;
			for(int i=n-1;i>=0;i--)
			{
				sum+=v[i];
				ans=Math.max(ans, sum-(c-x[i]));
				back[i]=(sum-(c-x[i]));
			}
			SegmentTree tree=new SegmentTree(back);
			//System.out.println(Arrays.toString(tree.max));
			for(int i=0;i<n;i++)
			{
				long s=forward[i]-x[i];
				long max=0;
				if(i+1<n)
					max=tree.query(1, 0, n-1, i+1, n);
				ans=Math.max(ans, s+max);
			}
			tree=new SegmentTree(forward);
			for(int i=n-1;i>=0;i--)
			{
				long s=back[i]-(c-x[i]);
				long max=0;
				if(i-1>=0)
				max=tree.query(1, 0, n-1, 0, i-1);
				
			
				ans=Math.max(ans, s+max);
			}
			
			System.out.println(ans);
		
	}
	static class SegmentTree
	{
		long []a,max;
		SegmentTree(long []b)
		{
			a=b;
			int size=1;
			while(size<a.length)
				size*=2;
			max=new long[size*2];
			build(1,0,a.length-1);
		}
		void build(int node,int l,int r)
		{
			if(l==r)
			{
				max[node]=a[l];
			}
			else
			{
				int mid=(l+r)/2;
				build(2*node,l,mid);
				build(2*node+1,mid+1,r);
				max[node]=Math.max(max[2*node], max[2*node+1]);
			}
			
		}
		long query(int node,int s,int e,int l,int r)
		{
			if(s>r ||  e<l)
			{
				return 0;
			}
			if(s>=l && e<=r)
				return max[node];
			int mid=(s+e)/2;
			return Math.max(query(2*node,s,mid,l,r),query(2*node+1,mid+1,e,l,r)) ;
			
		}
	}

}
class Scanner 
{
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

	public String next() throws IOException 
	{
		while (st == null || !st.hasMoreTokens()) 
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public int nextInt() throws IOException {return Integer.parseInt(next());}
	
	public long nextLong() throws IOException {return Long.parseLong(next());}

	public String nextLine() throws IOException {return br.readLine();}
	
	public double nextDouble() throws IOException
	{
		String x = next();
		StringBuilder sb = new StringBuilder("0");
		double res = 0, f = 1;
		boolean dec = false, neg = false;
		int start = 0;
		if(x.charAt(0) == '-')
		{
			neg = true;
			start++;
		}
		for(int i = start; i < x.length(); i++)
			if(x.charAt(i) == '.')
			{
				res = Long.parseLong(sb.toString());
				sb = new StringBuilder("0");
				dec = true;
			}
			else
			{
				sb.append(x.charAt(i));
				if(dec)
					f *= 10;
			}
		res += Long.parseLong(sb.toString()) / f;
		return res * (neg?-1:1);
	}
	
	public boolean ready() throws IOException {return br.ready();}


} 

Measured memory_bytes: 48036
#include <stdio.h>

#include <string.h>

char s[1005];

int main(){

	int t;
	scanf("%d",&t);

	scanf(" ");

	scanf("%s",s);

	if(t>=strlen(s)) puts(s);

	else{

		s[t]='\0';

		printf("%s",s);

		puts("...");

	}

	return 0;

}

Measured memory_bytes: 2156
n, w = map(int, input().split())
wv_array = [[int(x) for x in input().split()] for y in range(n)]

dp = [[0 for x in range(w + 1)] for y in range(n+1)]

index = 1
for ww, vv in wv_array:
    for capacity in range(1, w + 1):
        if ww <= capacity:
            dp[index][capacity] = max(dp[index - 1][capacity - ww] + vv, dp[index-1][capacity])
        else:
            dp[index][capacity] = dp[index - 1][capacity]
    index += 1
print(max(dp[n]))

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

int main(){
  int n,q;
  cin >>n>>q;
  string s;
  cin >> s;
  int l,r;
  vector<int> d(n);
  d[0] = 0;
  for (int i=1; i<n; i++){
  	if (s[i]=='C' && s[i-1]=='A'){
      d[i] = d[i-1] + 1;
    }
    else d[i] = d[i-1];
  }
  for (int i=0; i<q; i++){
    cin >> l >> r;
    l--;
    r--;
    cout << d[r] - d[l] << endl;
  }
}

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

#define pb push_back
#define MAX 100005
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

int a,b;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a>>b;
    cout<<a-(b<a)<<"\n";
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
#define N 1000000000
using namespace std;

int main(){
    ll s;
    scanf("%lld",&s);
    if(s==1000000000000000000)
    {
        printf("0 0 1000000000 0 0 1000000000\n");
        return 0;
    }
    ll a=s/N+1,d=N;
    ll b=a*d-s,c=1LL;
    printf("0 0 %lld %lld %lld %lld\n",a,b,c,d);
	return 0;
}


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

#define MAX 10000

int mat[MAX][MAX];

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

	int k = 0;
	for( int i = 1; i <= n; i++ ) {
		if( i * (i - 1) == 2 * n ) {
			k = i;
		}
	}

	if( n == 1 ) {
		cout << "Yes" << endl;
		cout << 2 << endl;
		cout << "1 1" << endl;
		cout << "1 1" << endl;
	}
	else if( k == 0 ) {
		cout << "No" << endl;
	}
	else {
		int num = 1;
		for( int i = 0; i < k - 1; i++ ) {
			for( int j = 0; j <= i; j++ ) {
				mat[i][j] = num++;
			}
		}

		cout << "Yes" << endl;
		cout << k << endl;

		cout << k - 1 << " ";
		for( int i = 0; i < k - 1; i++ ) {
			cout << mat[i][0];
			if( i < k - 1 ) {
				cout << " ";
			}
		}
		cout << endl;

		cout << k - 1 << " ";
		for( int i = 0; i < k - 1; i++ ) {
			cout << mat[i][i];
			if( i < k - 1 ) {
				cout << " ";
			}
		}
		cout << endl;

		cout << k - 1 << " ";
		for( int i = 0; i < k - 1; i++ ) {
			cout << mat[k - 2][i];
			if( i < k - 1 ) {
				cout << " ";
			}
		}
		cout << endl;
		for( int i = 0; i < k - 3; i++ ) {
			cout << k - 1 << " ";
			for( int j = 0; j < i + 2; j++ ) {
				cout << mat[i + 1][j] << " ";
			}
			for( int j = i + 2; j < k - 1; j++ ) {
				cout << mat[j][i + 1];
				if( j < k - 1 ) {
					cout << " ";
				}
			}
			cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 18048
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
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 (b<a) { a=b; return 1; } return 0; }
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll x;
    cin >> x;
    ll ans = 0;
    ans += (x / 11) * 2;
    x %= 11;
    ans += x >= 5;
    if(x >= 5) x = max(x - 6, 0LL);
    ans += x >= 1;
    print(ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


signed main(){
  int n,m;cin>>n>>m;
  ll ans =  100*n + 1800 * m;
  rep(i,m){
    ans *= 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
const int maxn=1e6+10;
ll a[maxn][4];//0 0,1 9,2 x,3 all
const int mod=1e9+7;
int main() {
	int n;
	cin>>n;
	a[1][0]=1;
	a[1][1]=1;
	a[1][2]=8;
	a[1][3]=0;
	for(int i=2;i<=n;i++) {
		a[i][0]=(a[i-1][0]*9+a[i-1][2])%mod;
		a[i][1]=(a[i-1][1]*9+a[i-1][2])%mod;
		a[i][2]=(a[i-1][2]*8)%mod;
		a[i][3]=(a[i-1][0]+a[i-1][1]+a[i-1][3]*10)%mod;
	}
	cout<<a[n][3]<<endl;
}

Measured memory_bytes: 34808
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 100000 + 5;

int n, m;
int c[N], t[N];
char s[N];

int main() {
	read(n);
	for (int i = 0; i < 26; i++) c[i] = INF;
	for (int i = 1; i <= n; i++) {
		scanf("%s", s + 1); m = strlen(s + 1);
		for (int j = 0; j < 26; j++) t[j] = 0;
		for (int j = 1; j <= m; j++) t[s[j] - 'a']++;
		for (int j = 0; j < 26; j++) c[j] = min(c[j], t[j]);
	}
	for (int i = 0; i < 26; i++)
		for (int j = 1; j <= c[i]; j++) printf("%c", 'a' + i);
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define INF 300000000000001
#define ll_max 9000000000000000000
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long int ll;
typedef long double ld;
typedef vector<pair<ll,ll> > vll;
typedef vector<int> vi;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll N = 200001;
const ll M = log2(N);

struct point {
    ll x, y, i;
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cerr << word << " = " << a << endl;
    debug(s, args...);
}

ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    if(n & 1) return fast_exp(x, n - 1) * x % mod;
    else
    {
        ll ans = fast_exp(x, n / 2);
        return ans * ans % mod;
    }
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n, m, x, y, ans = 0, s, l;
        cin >> n;
        m = sqrt(n + 1);
        ll a[n + 1] = {};
        for(ll i = 1; i <= m; i++)
        {
            for(ll j = 1; j <= m; j++)
            {
                for(ll k = 1; k <= m; k++)
                {
                    x = i * i + j * j + k * k + i * j + i * k + j * k;
                    if(x <= n)
                        a[x]++;
                }
            }
        }
        for(int i =1; i <= n; i++) cout << a[i] << "\n";
        //cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 3676
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		int N = S.length();
		String T = sc.next();
		String TT = T.substring(0,N);
		if( S.equals(TT) ){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n; cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    sort(p.begin(), p.end());
    ll ans = 0;
    rep(i, n-1) ans += p[i];
    ans += p[n-1]/2;
    cout << ans << '\n';
    return 0;
}

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


using namespace std;

int main()
{
	int n; cin>>n;
	int pre = int(1e9+5);
	int cur = 0;
	int best = 0;
	int h;
	for(int i = 0; i<n; i++)
	{
		cin>>h;
		if(h>pre)
		{
			cur = 1;
			pre = h;
			best = max(best, cur);
		}
		else
		{
			cur += 1;
			best = max(best, cur);
			pre = h;
		}
	}
	cout<<best-1;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String s1 = scan.next();
		String s2 = scan.next();
		StringBuilder sb1 = new StringBuilder();
		StringBuilder sb2 = new StringBuilder();
		sb2.append(s1);
		sb2.reverse();
		sb1.append(s2);
		sb1.reverse();


		if(s1.equals(sb1.toString()) && s2.equals(sb2.toString())) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 23636
<?php

function input($func = null) {
    if ($func === null) {
        return trim(fgets(STDIN));
    } else {
        return $func(trim(fgets(STDIN)));
    }
}
function input_array($func = null) {
    if ($func === null) {
        return explode(input());
    } else {
        return array_map(function($v) use ($func) {
            return $func($v);
        }, explode(' ', input()));
    }
}

$x = input('intval');

echo in_array($x, [7, 5, 3], true) ? 'YES' : 'NO';
echo "\n";

Measured memory_bytes: 4856
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#include <numeric>

using namespace std;

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

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long mod = 1e9 + 7;

long power(long a, long b) { return b ? power(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, K;
    cin >> N >> K;
    long dp[100100];
    long res = 0;
    for (int k = K; k >= 1; k--)
    {
        dp[k] = power(K / k, N);
        for (int j = 2 * k; j <= K; j += k)
            dp[k] -= dp[j];
        res += k * dp[k] % mod;
    }

    cout << res % mod << "\n";
}

Measured memory_bytes: 4388
#include <iostream>
#include <cstdio>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <numeric>
#include <stack>
#include <deque>
#include <queue>
#include <unordered_map>
#include <bitset>

#define f first
#define s second
#define pplipii pair<pair<long long, int>, pair<int, int> >
#define mp make_pair
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
using namespace std;

typedef long long ll;
#define MAX 200010
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.0000001
#define vvi vector<vector<ll>>
vector<int> v;
int main()
{
    int a, b;
    cin >> a >> b;
    int cnt = 0;
    for (int i = a; i <= b; i++)
    {
        v.clear();
        int k = i;
        while(k != 0)
        {
            v.push_back(k % 10);
            k /= 10;
        }
        bool ok = false;
        for (int i = 0; i < v.size(); i++)
            if (v[i] != v[v.size() - i - 1]) ok = true;
        if (!ok) cnt ++;
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int vis[1010][1010];
inline vector<pair<int,int> > getdistant(int n,int D1,bool hasret=true)
{
	int cnt[2]={0,0};
	vector<pair<int,int> > ret,trans;
	for(int i=0;i<n;i++)
	{
		int v=round(sqrt(D1-i*i));
		if(v*v+i*i==D1)trans.push_back(make_pair(i,v)),trans.push_back(make_pair(i,-v)),trans.push_back(make_pair(-i,v)),trans.push_back(make_pair(-i,-v));
	}
	memset(vis,255,sizeof(vis));
	queue<pair<int,int> > q;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(vis[i][j]==-1)
			{
				// puts("----");
				q.push(make_pair(i,j));
				vis[i][j]=0;
				while(!q.empty())
				{
					pair<int,int> fr=q.front();q.pop();
					// printf("%d %d\n",fr.first,fr.second);
					for(auto &x:trans)
					{
						int nx=fr.first+x.first,ny=fr.second+x.second;
						if(nx>=0&&nx<n&&ny>=0&&ny<n&&vis[nx][ny]==-1)
						{
							vis[nx][ny]=vis[fr.first][fr.second]^1;
							q.push(make_pair(nx,ny));
						}
					}
				}
			}
		}
	}
	if(!hasret)return ret;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cnt[vis[i][j]]++;
		}
	}
	if(cnt[0]>cnt[1])
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(vis[i][j]==0)ret.push_back(make_pair(i,j));
			}
		}
	}
	else
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(vis[i][j]==1)ret.push_back(make_pair(i,j));
			}
		}
	}
	return ret;
}
int vis2[1010][1010];
inline vector<pair<int,int> > solve(int n,int d1,int d2)
{
	vector<pair<int,int> > ret;
	if(n==1)
	{
		ret.push_back(make_pair(0,0));
		return ret;
	}
	if(d1%4&&d2%4)
	{
		for(int i=0;i<n;i+=2)
		{
			for(int j=0;j<n;j+=2)
			{
				ret.push_back(make_pair(i,j));
			}
		}
		return ret;
	}
	if(d2%4==0)swap(d1,d2);
	if(d2%4)
	{
		auto p=getdistant(n/2,d1/4);
		if(d2%4==2)
		{
			for(auto &x:p)
			{
				ret.push_back(make_pair(x.first*2,x.second*2));
				ret.push_back(make_pair(x.first*2,x.second*2+1));
			}
		}
		else
		{
			for(auto &x:p)
			{
				ret.push_back(make_pair(x.first*2,x.second*2));
				ret.push_back(make_pair(x.first*2+1,x.second*2+1));
			}
		}
		return ret;
	}
	else
	{
		getdistant(n,d2,0);
		memcpy(vis2,vis,sizeof(vis));
		getdistant(n,d1,0);
		int cnt[4]={0,0,0,0};
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				cnt[vis[i][j]*2+vis2[i][j]]++;
			}
		}
		int mx=0;
		for(int i=1;i<=3;i++)if(cnt[i]>cnt[mx])mx=i;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(vis[i][j]*2+vis2[i][j]==mx)ret.push_back(make_pair(i,j));
			}
		}
		return ret;
	}
}
int n,D1,D2;
int main()
{
	scanf("%d%d%d",&n,&D1,&D2);
	auto ans=solve(n<<1,D1,D2);
	ans.resize(n*n);
	for(auto &p:ans)printf("%d %d\n",p.first,p.second);
	return 0;
}

Measured memory_bytes: 10408
#include<iostream>
using namespace std ;
int main()
{
	int n=0 ;
	cin >> n ;
	for(int i=1 ; i <= n ; i++)
	{
		int x=i ;
		if(x%3==0)
		{
			cout << " " << i ;
		}
		else
		{
			while(1)
			{
				if(x%10==3)
				{
					cout << " " << i ;
					break ;
				}
				if(x/10==0)
				{
					break ;
				}
				x=x/10 ;
			}
		}
	}
	cout << endl ;
	return 0 ;
}



Measured memory_bytes: 3116
from collections import Counter

N=int(input())
A=list(map(int,input().split()))
c=Counter(A)
commons=c.most_common()

ans=0

dic={}
for common in commons:
    dic[common[0]]=common[1]
    ans+=common[0]*common[1]
# print(dic)
# print(ans)

Q=int(input())
for i in range(Q):
    b,c=map(int,input().split())
    if b not in dic:
        print(ans)
        continue
    else:
        pass
    if c not in dic:
        ans+=(c-b)*dic[b]
        print(ans)
        dic[c]=dic[b]
        dic[b]=0
        continue
    else:
        pass
    ans+=(c-b)*dic[b]
    dic[c]+=dic[b]
    dic[b]=0
    print(ans)


Measured memory_bytes: 25404
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub struct FastPrimeFactor {
    n: usize,
    min_primes: Vec<usize>,
}

impl FastPrimeFactor {
    pub fn new(n: usize) -> Self {
        let mut min_primes = vec![0; n + 1];
        for i in 2..=n {
            if min_primes[i] == 0 {
                let mut j = i;
                while j <= n {
                    min_primes[j] = i;
                    j += i;
                }
            }
        }
        Self { n, min_primes }
    }
    pub fn prime_factor(&self, n: usize) -> HashMap<usize, usize> {
        if n < 2 {
            return HashMap::new();
        }
        if n > self.n {
            panic!("n > self.n");
        }
        let mut res = HashMap::new();
        let mut x = n;
        while x > 1 {
            let y = self.min_primes[x];
            *res.entry(y).or_insert(0) += 1;
            x = x / y;
        }
        res
    }
}

fn solve() {
    input! {
        n: usize,
        av: [usize; n]
    };

    let mut set1 = HashSet::new();
    let pf = FastPrimeFactor::new(10.pow(6));
    let mut is_pairwise = true;
    let mut is_setwise = false;
    let mut b = 0;
    for a in av {
        b = b.gcd(&a);
        if b == 1 {
            is_setwise = true;
        }
        for (k, _) in pf.prime_factor(a as usize) {
            if set1.contains(&k) {
                is_pairwise = false;
            }
            set1.insert(k);
        }
    }
    if is_pairwise {
        println!("pairwise coprime");
    } else if is_setwise {
        println!("setwise coprime");
    } else {
        println!("not coprime");
    }
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 25136
#include<bits/stdc++.h>
#define B2(x) (63-__builtin_clzll(x))
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=100010;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,ans,l[N],r[N],dp[N][2];
int main()
{
	int x;
	file();
	read(n);
	For(i,1,n)
	{
		read(x);
		l[i]=B2(x);
		r[i]=l[i]+((1<<l[i])!=x);
		//printf("%d: %d l:%d r:%d\n",i,x,l[i],r[i]);
		ans+=r[i];
		dp[i][0]=max(dp[i-1][0]+min(r[i-1],l[i]),dp[i-1][1]+min(l[i-1],l[i]));
		dp[i][1]=max(dp[i-1][0]+min(r[i-1],r[i]),dp[i-1][1]+min(l[i-1],r[i]));
	}
	printf("%d\n",ans-max(dp[n][0],dp[n][1]));
	return 0;
}


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

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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for(auto &t : v) cin >> t;
    vector<int> PF(n), SF(n);
    for(int i = 0; i < n; i++) {
        if (!i) PF[i] = gcd(v[i], v[i]);
        else PF[i] = gcd(v[i], PF[i - 1]);
    }
    for(int i = n - 1; i >= 0; i--) {
        if (i == n - 1) SF[i] = gcd(v[i], v[i]);
        else SF[i] = gcd(v[i], SF[i + 1]);
    }
    int ans = max(PF[n - 1], SF[1]);
    for(int i = 0; i < n; i++) {
        ans = max(ans, gcd(PF[i - 1], SF[i + 1]));

    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1408
import math
import itertools
k=0
s=0
R=list()
N,M=map(int,input().split())
for i in range(N):
  L=list(map(int,input().split()))
  R.append(L)
list1 = list(itertools.permutations(R, 2))
for i in range(len(list1)):
  o=list1[i]
  A=list(o)[0]
  B=list(o)[1]
  for j in range(M):
    s+=(A[j]-B[j])**2
  d = int(math.sqrt(s))
  if pow(d,2)==s:
    k+=1
  s=0
print(k//2)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<list>
#include<string>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<functional>
#include <fstream>
using namespace std;



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

Measured memory_bytes: 892
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  ll n,k;cin>>n>>k;

  ll a=0,b=0;
  if(k%2==0){
    rep(i,1,n+1){
      if(i%k==0)a++;
      else if(i%k==k/2)b++;
    }
    ll res1=a*a*a;
    ll res2=b*b*b;

    out(res1+res2);

  }else{
    ll a=n/k;
    out(a*a*a);
  }


  return 0;
}


Measured memory_bytes: 256
use std::io::Read;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();
    let q: usize = iterator.next().unwrap().parse().unwrap();

    let mut queries: Vec<Vec<usize>> = vec![vec![0; 4]; q];
    for i in 0..q {
        let a: usize = iterator.next().unwrap().parse().unwrap();
        let b: usize = iterator.next().unwrap().parse().unwrap();
        let c: usize = iterator.next().unwrap().parse().unwrap();
        let d: usize = iterator.next().unwrap().parse().unwrap();
        queries[i][0] = a;
        queries[i][1] = b;
        queries[i][2] = c;
        queries[i][3] = d;
    }

    let mut ans: usize = 0;

    let mut arrays: Vec<Vec<usize>> = Vec::new();
    let mut buf: Vec<usize> = vec![0; n];
    dfs(0, n, 1, m, &mut buf, &mut arrays);

    for array in arrays.iter() {
        let mut point: usize = 0;
        for query in queries.iter() {
            if array[query[1] - 1] - array[query[0] - 1] == query[2] {
                point += query[3];
            }
        }
        ans = max(ans, point);
    }

    return ans.to_string()
}

fn dfs(i: usize, n: usize, start: usize, end: usize, buf: &mut Vec<usize>, result: &mut Vec<Vec<usize>>) {
    if i == n {
        result.push(buf.clone());
        return;
    } else {
        for j in start..=end {
            buf[i] = j;
            dfs(i + 1, n, j, end, buf, result);
        }
    }
}


Measured memory_bytes: 12680
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

char S[2048];
int A[2048], B[2048];

int input(int* X) {
  scanf("%s", S);
  const int N = strlen(S);
  for (int i = 0; i < N; ++i) {
    X[i] = S[i] - '0';
  }
  return N;
}

vector<int> F[2048];

int main() {
  const int N = input(A);
  input(B);

  bool zero = true, eq = true;
  for (int i = 0; i < N; ++i) {
    zero &= B[i] == 0;
    eq &= A[i] == B[i];
  }
  if (eq) {
    puts("0");
    return 0;
  }
  if (zero) {
    puts("-1");
    return 0;
  }

  for (int i = 0; i < N; ++i) {
    for (int s = 0; s < N; ++s) {
      if (B[(i - s + N) % N] == 1) {
        F[i].push_back(s);
      }
    }
  }

  int res = INF;

  for (int i = 0; i < N; ++i) {
    int t_cost = INF;
    chmin(t_cost, N + i);
    chmin(t_cost, N + (N - i));

    int c_cost = 0;
    for (int j = 0; j < N; ++j) {
      if (A[(i + j) % N] != B[j]) {
        ++c_cost;
      }
    }

    {
      int cost = INF;
      vector<pair<int, int>> I;
      for (int a = 0; a < N; ++a) {
        if (A[a] == B[(a - i + N) % N] || F[a][0] <= i) {
          continue;
        }
        I.emplace_back(F[a][0], F[a].back());
      }
      sort(I.begin(), I.end());

      int mib = N;
      for (int j = (int)I.size() - 1; j >= 0; --j) {
        const int ca = I[j].first;
        chmin(cost, i + 2 * (N - mib) + 2 * (ca - i));
        chmin(mib, I[j].second);
      }
      chmin(cost, i + 2 * (N - mib));
      chmin(t_cost, cost);
    }

    {
      int cost = INF;
      vector<pair<int, int>> I;
      for (int a = 0; a < N; ++a) {
        if (A[a] == B[(a - i + N) % N] || F[a].back() >= i) {
          continue;
        }
        I.emplace_back(F[a][0], F[a].back());
      }
      sort(I.begin(), I.end());

      int mib = i;
      for (int j = (int)I.size() - 1; j >= 0; --j) {
        const int ca = I[j].first;
        chmin(cost, (N - i) + 2 * ca + 2 * (i - mib));
        chmin(mib, I[j].second);
      }
      chmin(cost, (N - i) + 2 * (i - mib));
      chmin(t_cost, cost);
    }

    chmin(res, t_cost + c_cost);
  }

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

  return 0;
}


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

int main() {
	int k=0,ans=0,N,l=0,r=0,K,a[100000]={};
	cin>>N>>K;
	for(int i=0;i<N;i++)
	{
		cin>>a[i];
		if(a[i]==1)
		{
			l=i;
			r=N-i-1;
		}
	}
	for(int i=0;ans<N;i++)
	{
		ans+=((i!=0)?K-1:K);
		k=i+1;
	}
	cout<<k<<endl;
	}

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

using namespace std;

int32_t main()
{
        int n , x;
        int ans = -1;
        for(int i = 1;  i<= 5 ; i++)
        {
            cin >> x;
            if(x == 0)
                ans = i;
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include<bits/stdc++.h>
#include<cmath>
#include <algorithm> 
#include<map>
#include<string>
#include<unordered_map>
#include <set>
#include <unordered_set>

using namespace std;

const long long N = (1e4 + 7);

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	long long ans = 0;
	for (int i = 0; i < s.size(); i++) {
		long long t = s[i] - '0';
		ans += t;
	}
	if (ans % 9 == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

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

int main(){
    int k; cin >> k;
    int a,b; cin >> a >> b;
    for(int i = a; i <= b; ++i){
        if(i%k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,N;
  cin >> K >> N;
  
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];

  int ma = K - A[N-1] + A[0];
  for (int i = 1; i < N; i++) {
    ma = max(ma,A[i] - A[i-1]);
  }
  cout << K - ma << endl;
}

Measured memory_bytes: 1024
#E DPでとく
N = [int(x) for x in input()]
dp = 0,1
for item in N:
    a = min(dp[0] + item, dp[1] + 10 - item)
    b = min(dp[0] + item + 1, dp[1] + 10 - (item + 1))
    dp = a, b
    
print(dp[0])

Measured memory_bytes: 14700
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;

int n;
int w = 0, e = 0;
int l_cnt = 0, r_cnt = 0;
int total = 0;
string s;

struct pos
{
	int m_total;
	int p;
};

pos mem;

void solve()
{
	for(int i = 0; i < n; i++)
		if(s[i] == 'W') w++; 
		else if(s[i] == 'E') e++;

	for(int i = 0; i < n; i++)
	{
		if(i == 0) //初始化
		{
			if(s[0] == 'W') { l_cnt = 0; r_cnt = e; }
			else { l_cnt = 0; r_cnt = e-1; }
			total = l_cnt + r_cnt;
			mem.m_total = total; mem.p = 0;
		}
		else //移到i位置时的情况
		{
			if(s[i-1] == 'W') l_cnt++;

			if(s[i] == 'E') r_cnt--;
			total = l_cnt + r_cnt;
			if(total < mem.m_total) { mem.m_total = total; mem.p = i; }
		}

	}
}

int main()
{
	cin >> n; getchar();
	getline(cin, s);    
	solve();
	cout << mem.m_total << endl;
	return 0;
}

Measured memory_bytes: 900
import sys
sys.setrecursionlimit(10**5)

h,n=map(int,input().split())
magic=[]
for i in range(n):
  magic.append(tuple(map(int,input().split())))

memo={}
def d(hp):
  if hp<=0:
    return 0
  if hp in memo:
    return memo[hp]
  mn=10**10
  for i in magic:
    mn=min(mn,d(hp-i[0])+i[1])
  memo[hp]=mn
  return mn

for i in range(1,h-1):
  d(i)
print(d(h))

Measured memory_bytes: 74632
using System;
using System.Linq;
using static System.Console;

namespace ConsoleAppAtCoderABC172
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = ReadLine();
            var t = ReadLine();

            var d = s.Zip(t, (s, t) => s != t ? 1 : 0).Sum();

            WriteLine(d);
        }
    }
}


Measured memory_bytes: 27964
import java.io.*;
class Main{

    public static void main(String[] args) throws IOException{
	int gcd,lcm;
	BufferedReader br=
	    new BufferedReader (new InputStreamReader(System.in));
	String buf;
	while(true){
	    if((buf=br.readLine())==null)break;
	    if(buf.length()==0)break;
	    String[] data=buf.split(" ");
	    int[] dat =new int[2];
	    for(int i=0;i<2;i++){
		dat[i]=Integer.parseInt(data[i]);
	    }
	    int x=dat[0],y=dat[1];
	    while(true){
		if(x==y)break;
		if(x > y) x-=y;
		else y-=x;
	    }
	    lcm=x;
	    double d=(double)dat[0]*(double)dat[1];
	    d/=(double)lcm;
	    gcd=(int)d;
	    System.out.println(lcm+" "+gcd);
	}
    }
}

Measured memory_bytes: 9184
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<time.h>
#define ll long long
#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define miin(a,b,c) min((a), min((b), (c)))
#define maax(a,b,c) max((a), max((b), (c)))

char s[1111111] = {}, c;
int q, a, b, i = 500000, j, nyan = 0;

int main(){
    scanf("%s", s + i);
    for(j = i;s[j] != NULL;j++);j--;
    scanf("%d", &q);
    while(q--){
        scanf("%d", &a);
        if(a == 1){
            nyan ^= 1;
        }else {
            scanf("%d %c",&b, &c);
            if(b == 1){
                if(nyan == 0){
                    i--;
                    s[i] = c;
                }else {
                    j++;
                    s[j] = c;
                }
            }else {
                if(nyan == 0){
                    j++;
                    s[j] = c;
                }else {
                    i--;
                    s[i] = c;
                }
            }
        }
    }
    if(nyan == 0){
        for(int k=i;k<=j;k++)putchar(s[k]);
    }else{
        for(int k=j;k>=i;k--)putchar(s[k]);
    }
    return 0;
}

Measured memory_bytes: 768
// https://abc103.contest.atcoder.jp/tasks/abc103_a

// Todo
// * [x] 入力をパースする関数
// * [ ] a1, a2, a3から値を求める関数

function parse(input) {
  return input
    .trim()
    .split(" ")
    .map(item => parseInt(item, 10))
}

function f(arr) {
  return arr.sort((a, b) => b - a).reduce((acc, n, i, arr) => acc + (i === 0 ? 0 : arr[i - 1] - arr[i]), 0)
}

module.exports = {
  parse,
  f,
}

function Main(input) {
  const arr = parse(input)

  console.log(f(arr))
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"))



Measured memory_bytes: 7372
N,M=map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]
 
for i in range(N-M+1):
  for j in range(N-M+1):
    t = True
    for k in range(M):
      if B[k] != A[i+k][j:j+M]:
        t = False
    if t:
      print("Yes")
      exit()
print("No")

Measured memory_bytes: 9076
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#define INF 100000000000000
using namespace std;

typedef struct _BLOCK{
    long long x;
    long long y;
    char op;
}BLOCK;

int main() {
    char op;
    long long x;
    long long y;
    vector<BLOCK> block_list;
    BLOCK block;
    while(1){
        cin >> x >> op >> y;
        if(op=='?'){
            break;
        }
        block.x  = x;
        block.y  = y;
        block.op = op;
        block_list.push_back(block);
    }
    for(int i=0; i<block_list.size(); i++){
        x = block_list.at(i).x;
        y = block_list.at(i).y;
        if(block_list.at(i).op=='+'){
            cout << x+y << endl;
        }
        else if(block_list.at(i).op=='-'){
            cout << x-y << endl;
        }
        else if(block_list.at(i).op=='*'){
            cout << x*y << endl;
        }
        else if(block_list.at(i).op=='/'){
            cout << x/y << endl;
        }


    }
}




Measured memory_bytes: 3168
import sys
#DEBUG=True
DEBUG=False
if DEBUG:
    f=open("202007_1st/D_input.txt")
else:
    f=sys.stdin
N=int(f.readline().strip())
A=list(map(int,f.readline().split()))
A.sort(reverse=True)
ans=0
for _ in range(1,N):
    ans+=A[int(_/2)]
print(ans)
f.close()

Measured memory_bytes: 31400