akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();

        var x = sc.nextInt();
        var a = sc.nextInt();

        if (x < a) Console.WriteLine(0);
        else Console.WriteLine(10);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

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

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

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

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

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

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

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

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

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13140
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  ll A,B,m;
  cin>>A>>B>>m;
  vector<ll>a(A);
  vi b(B);
  rep(i,A)cin>>a[i];
  rep(i,B)cin>>b[i];
  vi x(m),y(m),c(m);
  rep(i,m)cin>>x[i]>>y[i]>>c[i];
  ll MIN=INF;
  
  rep(i,m){
    ll d=a[x[i]-1]+b[y[i]-1]-c[i];
    MIN=min(d,MIN);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  MIN=min(MIN,a[0]+b[0]);
  cout<<MIN<<endl;
}
                
    

Measured memory_bytes: 2560
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <bitset>
#include <queue>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x)*(x)
typedef long long ll;

int main() {
    int a, b;
    cin >> a >> b;
    if(b == 1) {
        cout << 0 << endl;
        return 0;
    }
    int i = 0;
    int count = 0;
    while(count < b) {
        if(i == 0) count += a;
        else count += a-1;
        i++;
    }
    cout << i;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] d = new int[n];
		for (int i = 0; i < n; i++) {
			d[i] = scanner.nextInt();
		}
		int sum = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				sum += d[i] * d[j];
			}
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> s(n);
  rep(i,n){
    if(i) s[i] = s[i-1] + a[i];
    else s[0] = a[0];
  }
  vector<ll> d(n-1);
  for(int i=1;i<n;i++){
    d[i-1] = abs(s[n-1] - 2*s[i-1]);
  }
  ll ans = *min_element(d.begin(),d.end());
  cout << ans << endl;
}

Measured memory_bytes: 4992
import sys
INF = 1e9 + 5
def solve(n, arr):
    dp = [INF] * n
    dp[0] = 0
    for i, _ in enumerate(arr):
        for j in range(i+1, i+3):
            if j < n:
                dp[j] = min(dp[j], dp[i] + abs(arr[j]-arr[i]))
    return dp[-1]

if __name__ == "__main__":
    f = sys.stdin
    fo = sys.stdout
    n = int(f.readline())
    arr = list(map(int, f.readline().split()))
    result = solve(n, arr)
    print(result)
        

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  string s;
  cin >> N >> K >> s;
  int RL = 0;
  for (int i = 0; i < N - 1; ++i) {
    if (s[i] == 'R' && s[i + 1] == 'L') ++RL;
  }
  int ans = 0;
  if (s.front() == 'L') ++ans;
  if (s.back() == 'R') ++ans;
  ans += 2 * RL;
  ans = N - ans;
  if (K <= RL) ans += 2 * K;
  else ans = N - 1;
  cout << ans << endl;
}

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(int.Parse).Select(s => s - 1).ToList();
            var B = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var C = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

            var pre = -10;
            var sum = 0;
            for (int i = 0; i < N; i++)
            {
                var a = A[i];
                sum += B[a];
                if (a - pre == 1) sum += C[pre];
                pre = a;
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

// int frog(vector<int> h, int i, int n)
// {
//     if (i == n - 1)
//         return 0;
//     if (i > n)
//         return INT_MAX;
//     // (abs(h[i + 1] - h[i]) + frog(h, i + 1, n), abs(h[i + 2] - h[i]) + i + 2 < n ? frog(h, i + 2, n) : INT_MAX);

//     int l = abs(h[i] - h[i + 1]) + frog(h, i + 1, n);
//     int r = INT_MAX;
//     if (i + 2 < n)
//         r = abs(h[i] - h[i + 2]) + frog(h, i + 2, n);

//     return min(l, r);
// }

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> dp(n + 1, INT_MAX);
    dp[0] = 0;
    vector<int> h;

    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        h.push_back(t);
    }
    // dp[1] = abs(h[1] - h[0]);
    // dp[2] = min(h[0], h[1]);
    for (int i = 0; i < n; i++)
    {
        for (int j = 1; j <= k && (i + j < n); j++)
        {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }
    // for (auto i : h)
    //     cout << i << " ";
    cout << dp[n - 1];
}

Measured memory_bytes: 3904
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll L, R;
  ll ans = 99999999;
  std::cin >> L >> R;
  if(R/2019!=L/2019){
    std::cout << 0 << '\n';
  }else if((R%673==0||L%673==0||R/673!=L/673)&& (R%3==0||L%3==0||R/3!=L/3)){
    std::cout << 0 << '\n';
  }else{
    for(ll i=L;i<R;i++){
      for(ll j=i+1;j<=R;j++){
        ans = min(ans, (i*j)%2019);
      }
    }
    std::cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int to,cost;};
typedef long long ll;

int ans;
signed main()
{
    int n,m;
    cin>>n>>m;
    int k[111],s[111][111],p[111];
    rep(i,m){
        cin>>k[i];
        rep(j,k[i])cin>>s[i][j];
    }
    rep(i,m)cin>>p[i];
    for(int bit=0;bit<(1<<n);bit++){
        int f[11]={0};
        for(int i=0;i<n;i++){
            if(bit & (1<<i))f[i]=1;
        }
        int flag=1;
        for(int j=0;j<m;j++){
            int co=0;
            for(int l=0;l<k[j];l++){
                co+=f[s[j][l]-1];
            }
            if(co%2!=p[j]){
                flag=0;
                break;
            }
        }
        if(flag)ans++;
    }
    cout<<ans<<endl;
 
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
# 木グラフなので各プレイヤから近い点の個数を比べればよい

N = int(input())

edge = [[] for _ in range(N)]

for _ in range(N-1):
  a,b = map(int,input().split())
  edge[a-1].append(b-1)  
  edge[b-1].append(a-1)  

INF = 10**18

d_fe = [INF]*N
d_sn = [INF]*N

d_fe[0] = 0
d_sn[N-1] = 0

def f(d,x):
  dx = d[x]
  for v in edge[x]:
    if d[v] == INF:
      d[v] = dx+1
      f(d,v)
      
f(d_fe,0)
f(d_sn,N-1)

black = 0
white = 0

for x in range(N):
  if d_fe[x] <= d_sn[x]:
    black += 1
  else:
    white += 1

answer = 'Fennec' if black > white else 'Snuke'
print(answer)

Measured memory_bytes: 117372
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define N 100000
#define INF 1000000000
using namespace std;

typedef long long ll;

int main()
{
    int a,b;
    cin >> a >> b;
    cout << a*b/2 << "\n";
    return 0;
}

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

int Gcd(int a, int b) {
  if (b == 0)
    return a;
  return Gcd(b, a % b);
}

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

  vector<int> L(N), R(N);
  L[1] = A[0], R[N - 2] = A[N - 1];
  for (int i = 2; i < N; i++)
    L[i] = Gcd(L[i - 1], A[i - 1]);
  for (int i = N - 3; i >= 0; i--)
    R[i] = Gcd(R[i + 1], A[i + 1]);
  L[0] = R[0], R[N - 1] = L[N - 1];

  int ans = 0;
  for (int i = 0; i < N; i++)
    ans = max(Gcd(L[i], R[i]), ans);

  cout << ans << endl;
}

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

#define MOD 1000000007
typedef unsigned long long ull;

ull h;
vector<ull> sq;
int main() {
  for (int i = 1; i < 41; i++) {
    sq.push_back(pow(2, i));
  }

  cin >> h;

  for (int i = 0; i < 40; i++) {
    if (h < sq[i]) {
      cout << sq[i] - 1;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;
using mat2d_t = std::vector<std::vector<int64_t>>;


int main(int argc, char **argv) {
    long double a,b,c;
    cin >> a >> b >> c;
    long double eps = 1e-14;
    bool ans = sqrt(a) + sqrt(b) + eps < sqrt(c);
    cout << (ans? "Yes": "No")<< endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int Q;
	cin >> Q;
	priority_queue<ll> L;
	priority_queue<ll,vector<ll>,greater<ll>> R;
	ll mn = 0;
	rep(_,Q){
		int t;
		cin >> t;
		if(t == 1){
			ll a,b;
			cin >> a >> b;
			if(L.empty()){	//first
				L.push(a);
				R.push(a);
			}else{
				ll l = L.top(), r = R.top();
				if(a < l){
					L.push(a);L.push(a);
					R.push(l);
					L.pop();
					mn += abs(a-l);
				}else if(l <= a && a <= r){
					L.push(a);
					R.push(a);
				}else{
					R.push(a);R.push(a);
					L.push(r);
					R.pop();
					mn += abs(a-r);
				}
			}
			mn += b;
		}else{
			cout << L.top() << " " << mn << endl;
		}
	}
}


Measured memory_bytes: 4588
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define mex 1000005
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//vector<int> adj[mex];
//a+b=a^b+2*(a&b)

int main(){
	fast
	string s,t;
	cin>>s>>t;
	int n=s.size(),cc=0;
	for(int i=0;i<n;i++){
		if(s[i]!=t[i])
		 cc+=1;
	}
	cout<<cc;
	
}


Measured memory_bytes: 3800
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [isize; n],
    }

    let b = a.iter();
    let mut c: Vec<(&isize, usize)> = b.enumerate().map(|(a, b)| (b, a)).collect();
    c.sort();
    let d: Vec<usize> = c.iter().rev().map(|(_, index)| *index).collect();

    let mut hash = vec![0; n];
    for i in 0..n {
        hash[i] = d[i];
    }

    let mut dp = vec![vec![0 as isize; n + 1]; n + 1];
    for d in 1..=n {
        let i = hash[d - 1];
        for l in 0..=d {
            let r = d - l;
            if l > 0 {
                dp[l][r] = dp[l - 1][r] + a[i] * ((l as isize - 1) - i as isize).abs() as isize;
            }
            if r > 0 {
                dp[l][r] = max(
                    dp[l][r],
                    dp[l][r - 1] + a[i] * ((n - r) as isize - i as isize).abs(),
                );
            }
        }
    }

    let mut ans = 0;
    for l in 0..=n {
        let r = n - l;
        ans = max(ans, dp[l][r])
    }
    println!("{}", ans);
}


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

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

    int p[N + 1] = {};
    int root[N + 1] = {};
    for (int i = 1; i <= N; i++)
    {
        cin >> p[i];
        root[i] = i;
    }

    for (int i = 0; i < M; i++)
    {
        int x, y;
        cin >> x >> y;
        x = root[x];
        while (x != root[x])
        {
            x = root[x];
        }

        y = root[y];
        while (y != root[y])
        {
            y = root[y];
        }

        if (x != y)
        {
            root[x] = y;
        }
    }

    for (int i = 1; i <= N; i++)
    {
        int parent = root[i];
        while (parent != root[parent])
        {
            parent = root[parent];
        }
        root[i] = parent;
    }

    int ans = 0;
    for (int i = 1; i <= N; i++)
    {
        if (root[p[i]] == root[i])
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int i,j,k,n,m,x[210001],y[210001],t[210001];
bool check(int x,int y,int t){
	int k;
	x=max(x,-x);y=max(y,-y);
	k=x+y;
	if (t<k) return 0;
	if ((t-k)&1) return 0;
	return 1;
}
int main(){
	scanf("%d",&n);x[0]=y[0]=t[0]=0;
	for (i=1;i<=n;i++) scanf("%d%d%d",&t[i],&x[i],&y[i]);
	for (i=1;i<=n;i++)
	 if (!check(x[i]-x[i-1],y[i]-y[i-1],t[i]-t[i-1])){
	 	puts("No");return 0;
  	 }
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1280
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	long long n, a, b;
	cin >> n >> a >> b;

	if(a == 0 and b == 0) {
		cout << 0 << '\n';
		return 0;
	}
	long long res = 0;
	res += (n / (a + b)) * a;

	n %= (a + b);
	res += min(a, n);


	cout << res << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<stack>
#include<cstdio>
using namespace std;

int n;
vector<int> G[100001];
int vis[100001];
int re[100001];

void dfs( int u, int key){
    if(vis[u]) return;
    re[u] =key;
    vis[u] = 1;
    int num = G[u].size();
    for( int i = 0; i < num; i++ ){
        int v = G[u][i];
        dfs(v,key);
    }
}


int main(){
    int i,j,k,m;
    scanf("%d %d",&n,&m);
    while(m--){
        cin >> j >> k;
        G[j].push_back(k);
        G[k].push_back(j);
    }
    for( i = 0; i < n; i++ ){
        dfs(i,i+1);
    }
    int q;
    cin >> q;
    for( i = 0; i < q; i++ ){
        cin >> j >> k;
        cout << ((re[j]==re[k])? "yes":"no") << endl;
    }
}



Measured memory_bytes: 14076
fun main(args: Array<String>) {
    class Coordinate(var x: Int, var y: Int)
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextInt()
    val red = arrayOfNulls<Coordinate>(n)
    val blue = arrayOfNulls<Coordinate>(n)
    for (i in 0 until n) {
        red[i] = Coordinate(sc.nextInt(), sc.nextInt())
    }
    for (i in 0 until n) {
        blue[i] = Coordinate(sc.nextInt(), sc.nextInt())
    }
    java.util.Arrays.sort(red, { pt1, pt2 -> pt2!!.y - pt1!!.y })
    java.util.Arrays.sort(blue, { pt1, pt2 -> pt1!!.x - pt2!!.x })

    var count = 0
    for (i in 0 until n) {
        for (j in 0 until n) {
            if (red[j] == null) continue
            if (red[j]!!.x < blue[i]!!.x && red[j]!!.y < blue[i]!!.y) {
                red[j] = null
                count++
                break
            }
        }
    }
    println(count)
}

Measured memory_bytes: 31264
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
using namespace std;

struct UnionFind{
    vector <int> par;
    vector <int> height;
    vector <int> set_size;

    UnionFind(int N){
        par.assign(N, 0);
        height.assign(N, 0);
        set_size.assign(N, 1);
        for(int i = 0; i < N; i++){
            par[i] = i;
        }
    }

    int root(int x){
        if(x == par[x]){
            return x;
        }
        par[x] = root(par[x]);
        return par[x];
    }

    int same(int x, int y){
        return root(x) == root(y);
    }

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y){
            return;
        }
        if(height[x] >= height[y]){
            par[y] = x;
            if(height[x] == height[y]){
                height[x] ++;
            }
            set_size[x] += set_size[y];
        } else {
            par[x] = y;
            set_size[y] += set_size[x];
        }
    }
};

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

    UnionFind un_road(N);
    for(int i = 0; i < K; i++){
        int p;
        int q;
        cin >> p >> q;
        un_road.unite(p - 1, q - 1);
    }

    UnionFind un_train(N);
    for(int i = 0; i < L; i++){
        int r;
        int s;
        cin >> r >> s;
        un_train.unite(r - 1, s - 1);
    }

    map < pair <int, int>, int> pair_map;
    for(int i = 0; i < N; i++){
        int road_root = un_road.root(i);
        int train_root = un_train.root(i);
        if(pair_map.find(make_pair(road_root, train_root)) == pair_map.end()){
            pair_map[make_pair(road_root, train_root)] = 1;
        } else {
            pair_map[make_pair(road_root, train_root)] ++;
        }
    }

    for(int i = 0; i < N; i++){
        cout << pair_map[make_pair(un_road.root(i), un_train.root(i))];
        if(i < N - 1){
            cout << " ";
        } else {
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 16640
#include <stdio.h>

#define MOD (100000)

int s[100001];

int main(void)
{
    int n, m, a;
    int k;
    int i, j;
    int p;
    int d;
    
    scanf("%d%d", &n, &m);
    
    s[0] = s[1] = 0;
    for (i = 2; i <= n; i++){
        scanf("%d", &k);
        s[i] = s[i - 1] + k;
        s[i] %= MOD;
//printf("[%d=%d]", i, s[i]);
    }
    
    p = 1;
    d = 0;
    for (i = 1; i <= m; i++){
        scanf("%d", &a);
        if (a > 0){
            d += (s[p + a] - s[p] + MOD);
        }
        else {
            d += (s[p] - s[p + a] + MOD);
        }
        
        d %= MOD;
// printf("<%d %d D=%d SUM=%d>", p, a, s[p + a] - s[p], d);
        p += a;
    }
    
    printf("%d\n", d);
    
    return (0);
}

Measured memory_bytes: 984
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

//
var (
	N int
	M int
	R int
	r []int
	d [][]int
)

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func fill(a []int, x int) {
	for i := 0; i < len(a); i++ {
		a[i] = x
	}
}

func warshallFloyd(n int, d [][]int) {
	for k := 0; k < n; k++ {
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				d[i][j] = min(d[i][j], d[i][k]+d[k][j])
			}
		}
	}
}

func permtationsImpl(a []int, i int, f func(a []int)) {
	if i == len(a)-1 {
		f(a)
		return
	}
	permtationsImpl(a, i+1, f)
	for j := i + 1; j < len(a); j++ {
		a[i], a[j] = a[j], a[i]
		permtationsImpl(a, i+1, f)
		a[i], a[j] = a[j], a[i]
	}
}

func permtations(a []int, f func(a []int)) {
	permtationsImpl(a, 0, f)
}

func main() {
	defer flush()

	N = readInt()
	M = readInt()
	R = readInt()
	r = make([]int, R)
	for i := 0; i < R; i++ {
		r[i] = readInt()
	}

	d = make([][]int, N+1)
	for i := 0; i < N+1; i++ {
		d[i] = make([]int, N+1)
		fill(d[i], math.MaxInt32)
		d[i][i] = 0
	}

	for i := 0; i < M; i++ {
		A := readInt()
		B := readInt()
		C := readInt()
		d[A][B] = C
		d[B][A] = C
	}
	warshallFloyd(N+1, d)

	result := math.MaxInt64
	permtations(r, func(a []int) {
		t := 0
		for i := 0; i < R-1; i++ {
			t += d[a[i]][a[i+1]]
		}
		result = min(result, t)
	})
	println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdoutWriter, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 2772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100010;
const int inf=1e9;
int dp[N];
int main(){
    int n;
    cin>>n;
    int a[n+5];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++) dp[i]=inf;
    dp[0]=0;
    for(int i=0;i<n;i++){
        if(i>=1) dp[i]=min(dp[i],dp[i-1] + abs(a[i]-a[i-1]));
        if(i>=2) dp[i]=min(dp[i],dp[i-2] + abs(a[i]-a[i-2]));
    }
    cout<<dp[n-1]<<'\n';
    
}
  


Measured memory_bytes: 4412
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (ll i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int X, Y;
    cin >> X >> Y;
    rep(i, X+1){
        if(i*2+(X-i)*4==Y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n,m;
  cin >> n >> m;
  vector<ll> c(m);
  rep(i,m) {
    cin >> c[i];
  }

  // dp[j] .. using [0,i), min cost to make j.
  vector<ll> dp(n+1, INF);
  dp[0] = 0;
  rep(i,m)rep(j,n+1) {
    if (j-c[i]>=0) {
      chmin(dp[j], dp[j-c[i]] + 1);
    }
  }
  cout << dp[n] << endl;
}



Measured memory_bytes: 3336
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n:usize, k:i64,
        l:[(usize1, usize1); n-1]
    };
    let lto: Vec<Vec<usize>> = (0..n)
        .map(|i| {
            l.iter()
                .filter_map(|&(f, t)| {
                    if f == i {
                        Some(t)
                    } else if t == i {
                        Some(f)
                    } else {
                        None
                    }
                }).collect()
        }).collect();

    let mut dist = vec![vec![-1i64; n]; n];
    for i in 0..n {
        let mut q = vec![];
        q.push((0, i));
        dist[i][i] = 0;
        while let Some((d, s)) = q.pop() {
            for &e in &lto[s] {
                if dist[i][e] < 0 {
                    dist[i][e] = d + 1;
                    q.push((d + 1, e));
                }
            }
        }
    }

    if k % 2 == 0 {
        let res = (0..n)
            .map(|i| dist[i].iter().filter(|&&d| d <= k / 2).count())
            .max()
            .unwrap();
        println!("{}", n - res);
    } else {
        let hf = k / 2;
        let res = l
            .iter()
            .map(|&(f, t)| {
                (0..n)
                    .filter(|&i| dist[f][i] <= hf || dist[t][i] <= hf)
                    .count()
            }).max()
            .unwrap();
        println!("{}", n - res);
    }
}


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

using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//#define int long long
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; }
template<class T>void println(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
//lambda: [](int x, int y){return x<y;}

const int MOD = 1e9+7;

signed main(void){
    int n;cin>>n;
    string s;cin>>s;
    vint cnt(26,1);
    rep(i,26){
        rfor(c,s){
            if(c=='a'+i)cnt[i]++;
        }
    }
    ll ans=1;
    rfor(x,cnt){
        ans = ans*x%MOD;
    }

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


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

int main(){
  int H,W,N;
  cin>>H>>W>>N;
  int M=max(H,W);
  
  int x;
  if(N%M==0){
    x=N/M;
  }else{
    x=N/M+1;
  }
  cout<<x<<endl;
}

Measured memory_bytes: 256
n = int(input())

def makediv(n):
	lower_divisors , upper_divisors = [], []
	i = 1
	while i*i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n//i)
		i += 1
	return lower_divisors + upper_divisors[::-1]

ans = 10**18
divn = makediv(n)
for i in divn:
	if i*i <= n:
		ans = min(max(len(str(n//i)), len(str(i))), ans)
print(ans)

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

int main(){
  int N,L;
  cin >> N >> L;
  int sum= N*(L-1) + N*(N+1)/2;
  if(0<L){
    cout << sum - L << endl;
    return 0;
  }else if(1-N <= L){
    cout << sum << endl;
    return 0;
  }else{
    cout << sum - (L + N - 1) << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define ll long long
#define int long long
using namespace std;
const int maxn = 500010, inf = 1e9 + 233;
int n, K, x;
int f[233][2], digit[233], sum[233];

template<typename T>
inline void read(T &k)
{
    int f = 1; k = 0; char c = getchar();
    while (c < '0' || c > '9') c == '-' && (f = -1), c = getchar();
    while (c <= '9' && c >= '0') k = k * 10 + c - '0', c = getchar();
    k *= f;
}

signed main()
{
    read(n); read(K);
    for (int i = 1; i <= n; i++) 
    {
        read(x);
        for (int j = 1; j <= 40; j++)
            sum[j] += x & 1, x >>= 1;
    }

    memset(f, 200, sizeof(f));

    int cnt = 0;
    while (K)
        digit[++cnt] = K & 1,  K >>= 1;

    f[40][1] = 0;
    for (int i = 40; i; i--)
    {
        // printf("i:%lld f0:%lld f1:%lld\n", i, f[i][0], f[i][1]);
        f[i - 1][0] = f[i][0] + (max(sum[i], n - sum[i]) << (i - 1));
        if (digit[i]) f[i - 1][0] = max(f[i - 1][0], f[i][1] + (sum[i] << (i - 1)));
        f[i - 1][1] = f[i][1] + ((digit[i] ? (n - sum[i]) : sum[i]) << (i - 1));
    }

    printf("%lld\n", max(f[0][0], f[0][1]));
}

Measured memory_bytes: 256
<?php
	$n = explode(" ",trim(fgets(STDIN)));
	$a = explode(" ",trim(fgets(STDIN)));

	rsort($a);
	$sum = 0;
	for($t=0;$t < $n[1];$t++){
		$sum = $a[$t] + $sum;
	}
	echo $sum;
?>

Measured memory_bytes: 3576
#include <iostream>
#include <stdlib.h>
typedef long long ll;
using namespace std;
#define REP(i,n) for(int i=0; i<n;i++)

int main(void)
{
    int n,d,x,a[101],b[101]={0},count=0;
    
    cin >> n >> d >> x;
    REP(i,n)
    {
        cin >> a[i];
    }
    REP(i,n)
    {
        
        do
        {
            //cout << "b[" << i << "] = " << b[i] << "  ";
            b[i]+=a[i];
            count++;
            //cout << "count = " << count << endl;
        }while(b[i]<d);
    }
    
    cout << count+x << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
	int N, M;
	while(cin >> N >> M && N > 0){
		long long int cnt=0;
		vector<int> h(N);
		vector<int> w(M);
		for(int i=0;i<N;i++){
			cin >> h[i];
		}
		for(int i=0;i<M;i++){
			cin >> w[i];
		}
		vector<int> freq(N*1000, 0);
		for(int i=0;i<N;i++){
			int sum=0;
			for(int j=i;j<N;j++){
				sum += h[j];
				freq[sum]++;
			}
		}
		for(int i=0;i<M;i++){
			int sum=0;
			for(int j=i;j<M;j++){
				sum += w[j];
				if (sum < freq.size()){
					cnt += freq[sum];
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 12536
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long
#define ld long double
#define PI 3.14159265358979l
unsigned gcd(unsigned a, unsigned b) {
	if (a < b) gcd(b, a);
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}


int main() {
	int n;
	ll a[100000];
	cin >> n;
	cin >> a[0];
	ll ans = a[0];
	for (int i = 1; i < n;i++) {
		cin >> a[i];
		ans = gcd(ans, a[i]);
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := NewScanner()
	s := sc.Next()
	K := sc.NextInt()
	r := make([]string, 0)
	mp := map[string]bool{}
	for i := 0; i < len(s); i++ {
		for j := 1; j <= K && i+j <= len(s); j++ {
			mp[s[i:i+j]] = true
		}
	}
	for k, _ := range mp {
		r = append(r, k)
	}

	sort.Strings(r)

	fmt.Println(r[K-1])

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 3200
#include<stdio.h>
int main(){

  int n;
  int v[52];
  int c[52];
  int i;
  int s[52];
  int k=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&v[i]);
  }
  for(i=0;i<n;i++){
    scanf("%d",&c[i]);
  }


  for(i=0;i<n;i++){

    s[i]=v[i]-c[i];

  }

  for(i=0;i<n;i++){

    if(s[i]>0){
    k+=s[i];
  }
  }

  printf("%d",k);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
using ll = long long;

ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b);
}
int field[100010];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
    int N, K; cin >> N >> K;
    string s; cin >> s;
    
    queue<pair<int, int>> que;
    vector<pair<int, int>> v;
    bool stmt = false;
    int cnt=0;
    
    int head=0, tail = 0;
    for(int i=0; i<N; ++i){
        if(stmt == true && s[i]=='1'){
            que.push({tail, i-1});
            v.push_back({tail, i-1});
            field[i-1]=1;
            stmt = false;
        }
        if(stmt == false && s[i]=='0'){
            stmt = true;
            tail = i;
        }
        
    }
    
    if(stmt == true){
        que.push({tail, N-1});
        v.push_back({tail, N-1});
        field[N-1]=1;
    }
    
    /*while(!que.empty()){
        cout << que.front().first << " " << que.front().second << endl;
        que.pop();
    }*/
    cnt=0;
    head = 0, tail = 0;
    int ans=0;
    int idx=0;
    int i=-1;
    for(int head=0; head<N; ++head){
        
        while(tail<N ){
            if(s[tail]=='0'){
                if(cnt<K){
                    tail = que.front().second;
                    cnt++;
                    if(que.empty()) break;
                    que.pop();
                }else{
                    break;
                }
            }
            tail++;
        }
        ans = max(ans, tail-head);
        
        if(tail==head) tail++;
        
        if(idx<v.size()) {
            head = v[idx].second;
            idx++;
            cnt--;
        }
        
            //cout << head << endl;
    }
    cout << ans << endl;
	return 0;

}

Measured memory_bytes: 1608
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		long[] h = new long[n];
		for (int i = 0; i < n; i++) {
			h[i] = scanner.nextLong();
		}
		String result = "Yes";
		for (int i = n - 1; i > 0; i --) {
			if (h[i - 1] <= h[i]) {
				continue;
			}
			h[i - 1] = h[i - 1] - 1;
			if (h[i - 1] <= h[i]) {
				continue;
			}
			result = "No";
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 63296
/** Bismillahir Rahmanir Rahim **/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define Fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define print(x) cout << "x " << " ";

int main()
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    if (a[0] == a[1] and a[2] != a[1]) {
        cout << "Yes\n";
    } else if (a[1] == a[2] and a[0] != a[1]) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

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

int main(){
  string a, b, c;
  cin >> a;
  cin >> b;
  cin >> 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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 A
"""

import fractions

n, m = map(int, input().split())
s = input()
t = input()

g = fractions.gcd(n, m)
lcm = (n*m//g)

flag = True
for i in range(g):
    if s[i*lcm//m] != t[i*lcm//n]:
        flag = False
        break

if flag:
    print(lcm)
else:
    print(-1)






Measured memory_bytes: 5436
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll maxn=1e5+10;
ll s[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    for(ll i=0;i<n;++i)cin>>s[i];
    ll ans=0;
    for(ll step=1;step<n;++step){
        ll l=0,r=n-1;
        ll sum=0;
        while(r>step&&(r%step||l<r)){
            sum+=s[l]+s[r];
            ans=max(ans,sum);
            l+=step;
            r-=step;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep01(i, n) for(int i = 0; i < (n) + 1; i++)
#define rep10(i, n) for(int i = 1; i < (n); i++)
#define rep11(i, n) for(int i = 1; i < (n) + 1; i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
typedef struct { int x; int y; } Pos;
using namespace std;

const int dx[] = { 1,-1,0,0 }, dy[] = { 0,0,1,-1 };
int time_ = 0;
int H, W;
bool cont = false;
vector<vector<char>> a;
queue<Pos> remq;
queue<Pos> nxtq;
int main() {
    cin >> H >> W;
    a = vector<vector<char>>(W + 1, vector<char>(H + 1));
    rep11(y, H) rep11(x, W) {
        cin >> a[x][y];
        if (a[x][y] == '#') nxtq.push(Pos{ x, y });
    }
    while (0 < nxtq.size()) {
        remq = queue<Pos>(nxtq);
        nxtq = queue<Pos>();
        cont = false;
        while (0 < remq.size()) {
            Pos ref = remq.front();
            remq.pop();
            rep(i, 4) {
                Pos chk = Pos{ ref.x + dx[i], ref.y + dy[i] };
                if (chk.x <= 0 || chk.x > W || chk.y <= 0 || chk.y > H) continue;
                if (a[chk.x][chk.y] == '.') {
                    a[chk.x][chk.y] = '#';
                    nxtq.push(Pos{ chk.x, chk.y });
                    cont = true;
                }
            }
        }
        if (cont) time_++;
    }  
    cout << time_ << endl;
    return 0;
}

Measured memory_bytes: 20432
#include <iostream>

using namespace std;
int y[100],m[100],d[100];
int main()
{
	int M = 20 * 10;
	int N = 39*5;
	int n,ans;
	cin >> n;
	for(int i = 0; i < n;++i){
		ans = 0;
		cin >> y[i] >> m[i] >> d[i];
		for(int j = 999; j > y[i]; --j){
			if(j % 3 ) ans += N;
			else ans+= M;
		}
		if(y[i] % 3){
			for(int j = 10; j > m[i];--j){
				if(j % 2){
					ans += 20;
				}
				else ans += 19;
			}
			if(m[i] % 2){
				ans += 20-d[i];
			}
			else ans += 19 - d[i];
		}
		else{
			ans += (10 - m[i])*20;
			ans += 20-d[i];
		}
		cout << ans +1<< endl;
	}
	return 0;
}

Measured memory_bytes: 3080
def main():
    x = int(input())
    hund = x//100
    ans = 0
    a = x-hund*100
    als = [0,1,2,3,4]
    if a <= hund*5:
        while hund > 0:
            if a >= 5:
                a -= 5
                hund -= 1
                if a == 0:
                    ans = 1
                    break
            elif a in als:
                ans = 1
                break 
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 90000000000000000
signed main(){
    int n;cin>>n;cout<<n*n<<endl;
}
        

Measured memory_bytes: 256
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();
        if(Math.abs(a - c) <= d){
            System.out.println("Yes");
        }else if(Math.abs(a - b) <= d && Math.abs(b - c) <= d){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        scan.close();
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 35816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxM = 31;
const int maxV = 90010;

 
const int maxN = 1e6+8;
const ll INF = 1000000000000000010LL;
const int MOD = 1e9+7;

int a[maxN];
int b[maxN];
char s[maxN];
int main() {
	int n;
	scanf("%d",&n);
	multiset<int> H;
	for(int i=1;i<=(1<<n);i++)
	{
		scanf("%d",&a[i]);
		H.insert(a[i]);
	}
	vector<int> v;
	int x = *H.rbegin();
	v.push_back(x);
	H.erase(H.lower_bound(x));
	for(int i=0;i<n;i++)
	{
		int m = (1<<i);
		
		for (int j=0;j<m;j++)
		{
			auto it = H.lower_bound(v[j]);
			if (it == H.begin())
			{
				puts("No");
				return 0;
			}
			-- it;
			v.push_back(*it);
			H.erase(it);
		}
	}
	puts("Yes");
    return 0;
}

Measured memory_bytes: 15740
import math
N=int(input())
l=[1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]
dp=[100000 for _ in range(N+1)]
dp[0] = 0
for i in l:
    if i > N:
        break
    for j in range(i,N+1):
        dp[j] = min(dp[j],dp[j-i]+1)
print(dp[-1])

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const ll mod = 1e9 + 7;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;
  cin >> n >> m;
  VLL x(n);
  VLL y(m);
  rep(i,n) cin >> x[i];
  rep(i,m) cin >> y[i];

  sort(all(x));
  ll xsum = 0;
  rep(i,n){
    xsum += i * x[i];
    //cout << "i " << i << ": +"<< i * x[i] << endl;
    if(xsum < 0) xsum += mod;
    xsum %= mod;
    xsum -= (n-1-i) * x[i];
    //cout << "i " << i << ": -"<< (n-1-i) * x[i] << endl;
    if(xsum < 0) xsum += mod;
    xsum %= mod;
  }

  sort(all(y));
  ll ans = 0;

  rep(i,m){
    ans += ((xsum * i)%mod) * y[i];
    if(ans < 0) ans += mod;
    ans %= mod;
    ans -= ((xsum * (m-1-i))%mod) * y[i];
    if(ans < 0) ans += mod;
    ans %= mod;
  }

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	long long N;
	cin >> N;

	long long n = N;
	map<long long, int> mp;
	for( long long i = 2; i * i <= n; i++ ) {
		while( n % i == 0 ) {
			mp[i]++;
			n /= i;
		}
	}
	if( n != 1 ) mp[n]++;
	long long ans = 0;
	for( auto it = mp.begin(); it != mp.end(); it++ ) {
		long long e = it->second;
		long long n = 0;
		while( e > n ) {
			n++;
			e -= n;
		}
		ans += n;
	}
 
	cout << ans << endl;
}

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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;
int main(int argc, char const *argv[])
{
	int n , tot = 0 ,flag = false;
	scanf("%d",&n);
	for(register int i = 1;i <= n;i++)
	{
		int x , y;
		scanf("%d%d",&x,&y);
		if(x == y)
		{
			tot++;
			if(tot >= 3)	flag = true;
		}
		else
			tot = 0;
	}
	puts(flag?"Yes":"No");
	return 0;
}

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

int main()
{
    int N, X, m, m_min = 10000, ans = 0;
    cin >> N >> X;

    for (int i = 0; i < N; i++)
    {
        cin >> m;
        X -= m;
        ans++;
        m_min = min(m_min, m);
    }

    ans += X / m_min;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256