akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	
	int n;
	cin>>n;
	long long x;
	long long ans = 1LL;
	for(int i=1;i<=n;i++){
		cin>>x;
		ans=(x/__gcd(x,ans)*ans);
	}	
	cout<<ans<<'\n';
	return 0;
}

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

namespace Template
{
    public static class Scan
    {
        public static string NextLine => Console.ReadLine();
        public static int NextInt => int.Parse(NextLine);
        public static long NextLong => long.Parse(NextLine);
        public static double NextDouble => double.Parse(NextLine);

        public static string[] StrAry(char separator = ' ') => Console.ReadLine().Split(separator);
        public static int[] IntAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), int.Parse);
        public static long[] LongAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), long.Parse);
        public static double[] DoubleAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), double.Parse);
    }

    internal class Template
    {
        public static void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
        private static void Fill<T>(T[] src, T value, int len) { for (int i = 0; i < len; i++) { src[i] = value; } }

        static void Solve() 
        {
            var vowels = new[] { 'a', 'e', 'i', 'o', 'u' };
            var c = Scan.NextLine;            
            Console.WriteLine(vowels.Contains(c[0]) ? "vowel" : "consonant");            
        }
        private static void Main()
        {
            Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Console.Out.Flush();
        }
    }
}


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

int main() {
    int cnt[26]{}, ans = 0;
    string s;
    cin >> s;
    for(auto c : s){
        cnt[c-'a']++;
    }
    REP(i,26){
        ans += cnt[i]%2;
    }
    cout << ans/2 << endl;
    return 0;
}


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

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

int a,b,c,d,e,f;


int main(){
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;
    cin >> f;
    a*=100;
    b*=100;

    int water=0;
    int sugar=0;

    for(int i=0; a*i<=f; i++){
        for(int j=0; a*i+b*j<=f; j++){
            int x=a*i+b*j;
            for(int k=0; c*k<=f; k++){
                for(int l=0; c*k+d*l<=f; l++){
                    int y=c*k+d*l;
                    if(x+y>f || x*e < 100*y){
                        continue;
                    }
                    if(sugar*x<=y*water){
                        water=x;
                        sugar=y;
                    }
                }
            }
        }
    }

    cout << (water+sugar) << " " << sugar << endl;
    return 0;
}


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

char s[200010];

int main() {
    scanf("%s", s);
    int sum = 0;
    int n = strlen(s);
    for(int i = 0; i < n; i++) {
        sum += (s[i] - '0');
    }
    if(sum % 9) {
        printf("No\n");
    } else {
        printf("Yes\n");
    }

    return 0;
}


Measured memory_bytes: 3876
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<tuple>
#include<utility>
#include <cctype>
using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define enter "\n"

typedef long long ll;


int abc105_b(){
    //入力
    string s;
    cin >> s;
    bool ans = true;
    
    //処理
    if(s[0]!='A') ans = false;
    bool tmp=false;
    for(int i=2 ; i<s.length()-1 ; ++i){
        if(s[i]=='C') tmp = true;
    }
    if(!tmp) ans = false;
    int cnt=0;
    REP(i,s.length()){
        if(isupper(s[i])) cnt++;
    }
    if(cnt!=2) ans =false;
    
    //出力
    if(ans) cout << "AC" << enter;
    else cout << "WA" << enter;
    return 0;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n; sc(n)
    vector<int> a(n);
    for (int i = 0; i < n; i++) sc(a[i])
    for (int i = 0; i < n; i++) a[i] = a[i] - (i+1);
    sort(a.begin(), a.end());
    ll ans = 0, b, mid = a.size()/2;
    if (a.size() % 2 == 0){
        b = (a[mid] + a[mid-1]) / 2;
        if ((a[mid] + a[mid-1]) % 2 != 0){
            if (a[mid] + a[mid-1] > 0) b += 1;
            else b -= 1;
        }
    }else b = a[mid];
    for (int i = 0; i < n; i++) ans += abs(a[i] - b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>


using namespace std;

int main(int argc, char const *argv[])
{
    int A, B;

    cin >> A >> B;

    for (int i = 1; i < 4; i++)
    {
        if (i!=A&&i!=B)
        {
            cout << i << endl;
            return 0;
        }
        
    }
    

    return 0;
}


Measured memory_bytes: 256
s = list(input())
t = list(input())

for i in range(len(t) - 1, len(s))[-1::-1]:
    if s[i] == "?" or t[-1]:
        jud = True
        for j in range(len(t)):
            if s[i - j] == t[-1 - j] or s[i - j] == "?":
                continue
            jud = False
            break
        if jud:
            for j in range(len(t)):
                s[i - j] = t[-1 - j]
            for j in range(len(s)):
                if s[j] == "?":
                    s[j] = "a"
            print("".join(s))
            exit()

print("UNRESTORABLE")

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

template <typename A, typename B>
string to_string(pair<A, B> p){
    return "(" + to_string(p.fi) + ", " + to_string(p.se) + ")";
}

template <typename T>
string to_string(T v){
    string s = "{";
    bool first = true;
    for(const auto & x : v){
        if(!first) s += ", ";
        first = false;
        s += to_string(x);
    }
    return s + "}";
}

void debug_out(){ cerr << endl;}
template <typename First, typename... Next>
void debug_out(First F, Next... N){
    cerr << " " << to_string(F);
    debug_out(N...);
}

#ifdef LOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 1
#endif

int main(){
    fcin;
    string s;
    cin >> s;
    int ans = 0;
    int n = s.size();
    for(int i = 0, j = n - 1; i < j; i++, j--){
        if(s[i] != s[j]) ans++;
    }
    cout << ans << endl;
    return 0;
}



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

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

  for(int i = a; i <= min(b, a + k - 1); i++){
    cout << i << endl;
  }
  for(int i = max(a + k, b - k + 1); i <= b; i++){
    cout << i << endl;
  }



}


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

using namespace std;

int dp[100001][3];
int dfs(vector<vector<int>>& arr,int index,int t)
{
  
  if(index >= arr.size())
    return 0;
  
  if(dp[index][t] != -1)
    return dp[index][t];
  
  if(index == 0)
    return dp[index][t] = max(arr[index][0]+dfs(arr,index+1,0),max(arr[index][1]+dfs(arr,index+1,1),arr[index][2]+dfs(arr,index+1,2)));
  
  if(t==0)
    return dp[index][t] = max(arr[index][1]+dfs(arr,index+1,1),arr[index][2]+dfs(arr,index+1,2));
  
  else if(t==1)
    return dp[index][t] = max(arr[index][0]+dfs(arr,index+1,0),arr[index][2]+dfs(arr,index+1,2));
  
  else
    return dp[index][t] = max(arr[index][0]+dfs(arr,index+1,0),arr[index][1]+dfs(arr,index+1,1));
  
}

int main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin>>n;
  vector<vector<int>> arr;
  for(int i=0;i<n;i++)
  {
    vector<int> v;
    for(int j=0;j<3;j++)
    {
      int x;
      cin>>x;
      v.push_back(x);
    }
    arr.push_back(v);
  }
  memset(dp,-1,sizeof(dp));
  int ans = dfs(arr,0,0);
  cout<<ans<<endl;
    
}

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

const int MaxN = 100 + 5;
const int MaxP = 22;

int N, A, B;
int P[MaxN], buc[MaxP];

void init() {
  cin >> N >> A >> B;
  for (int i = 1; i <= N; ++i) scanf("%d", &P[i]);
}

void solve() {
  for (int i = 1; i <= N; ++i) buc[P[i]]++;

  int ans = 0, sum = 0;
  for (int i = 1; i <= A; ++i) ans += buc[i];
  for (int i = A + 1; i <= B; ++i) sum += buc[i];
  ans = min(ans, sum); sum = 0;
  for (int i = B + 1; i < MaxP; ++i) sum += buc[i];
  ans = min(ans, sum);

  cout << ans << endl;
}

int main() {
  init();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if (x >= 0+r && x <= W-r && y >= 0+r && y <= H-r) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {
	ll n;
	cin>>n;
	ll p[n],a[n];
	for(int i=0;i<n;i++){
	    cin>>p[i];
	    a[i]=p[i];
	}
	sort(p,p+n);
	for(int i=0;i<n;i++){
	    if(a[i]==p[n-1])cout<<p[n-2]<<endl;
	    else cout<<p[n-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4736
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;

	REP(i, h) {
		REP(j, w) {
			int t = j < a;
			int s = i < b;
			cout << (t ^ s);
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3604
fun main(args: Array<String>) {
  val (H,W) = readLine()!!.split(" ").map{it.toInt()}
  var rows  = (1..H).map{readLine()!!.toString()}.filter{it.contains('#')}
  val height = rows.size - 1

  val colums = (0 until W).filter{x ->
    (0..height).any{y ->
      rows[y].get(x) == '#'
    }
  }

  for(h in 0 .. height){
    //出力文字列を作ってる
    val newRow = colums.map{y -> rows[h].get(y)}
    for(n in newRow) {
      print(n)
    }
    println()
  }
}

Measured memory_bytes: 38624
#include<bits/stdc++.h>
char s[5];
int a, b, ans;
int main(){
    scanf("%s", s);
    a = (s[0] - '0') * 10 + (s[1] - '0');
    b = (s[2] - '0') * 10 + (s[3] - '0');
    if(0 < a && a <= 12) ans += 2;
    if(0 < b && b <= 12) ans += 1;
    puts(ans == 3 ? "AMBIGUOUS" : ans == 2 ? "MMYY" : ans == 1 ? "YYMM" : "NA");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Maxn 400007
int last[Maxn],pre[Maxn],other[Maxn],cnt=0;
int dis[Maxn];
bool vis[Maxn];
void insert(int u,int v)
{
    other[++cnt]=v,pre[cnt]=last[u],last[u]=cnt;
}
void dfs(int u)
{
    vis[u]=true;
    for (int q=last[u];q;q=pre[q])
    {
        int v=other[q];
        if (!vis[v])
        {
            dis[v]=dis[u]+1;
            dfs(v);
        }
    }
}
int n;
int main()
{
    scanf("%d",&n);
    for (int i=1;i<n;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        insert(u,v),insert(v,u);
    }
    memset(vis,false,sizeof(vis));
    dis[1]=0;
    dfs(1);
    int id=1;
    for (int i=1;i<=n;i++)
        if (dis[i]>dis[id]) id=i;
    memset(vis,false,sizeof(vis));
    dis[id]=0;
    dfs(id);
    int ans=0;
    for (int i=1;i<=n;i++)
        ans=max(ans,dis[i]);
    if (ans%3==1) printf("Second\n"); else printf("First\n");
    return 0;
}

Measured memory_bytes: 21184
a, b, h, m = gets.split.map(&:to_i)
ra = 2 * Math::PI * (60 * h + m) / (12.0 * 60)
rb = 2 * Math::PI * m / 60.0
xa = a * Math.cos(ra)
ya = a * Math.sin(ra)
xb = b * Math.cos(rb)
yb = b * Math.sin(rb)
puts Math.sqrt((xa - xb) ** 2 + (ya - yb) ** 2)

Measured memory_bytes: 14824
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pb push_back
#define N 300003
#define inf (ll)1e9+11
#define warmup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll mod=1e9+7;   

signed main()
{
    warmup
    
    int n;
    cin>>n;
    pii p[n+1];
    int i,j,x,l;
    for(i=1;i<=n;++i)
        cin>>x>>l, p[i].first=x-l, p[i].second=x+l;
    sort(p+1,p+n+1);
    j=1;
    int cnt=1;
    for(i=2;i<=n;++i)
    {
        if(p[i].first>=p[j].second)
        {
            ++cnt;
            j=i;
        }   
        else if(p[i].second<p[j].second)
            j=i;
    }   
    cout<<cnt;
    
    return 0;
}


Measured memory_bytes: 1024
n,m,s,t=map(int,input().split())
uvab=[map(int,input().split()) for i in range(m)]
inf=10**20
c1=[[] for i in range(n)]
c2=[[] for i in range(n)]
for u,v,a,b in uvab:
    c1[u-1].append((v-1,a))
    c1[v-1].append((u-1,a))
    c2[u-1].append((v-1,b))
    c2[v-1].append((u-1,b))
from heapq import heappop,heappush
def dij(c,N,start):
    d=[inf]*N
    d[start]=0
    prev=[-1]*N
    q=[]
    heappush(q,(0,start))
    while len(q)>0:
        u=heappop(q)[1]
        for v,w in c[u]:
            if w<inf:
                temp=d[u]+w
                if d[v]>temp:
                    d[v]=temp
                    prev[v]=u
                    heappush(q,(d[v],v))
    return d
d1=dij(c1,n,s-1)
d2=dij(c2,n,t-1)
r=[0]*n
for i in range(n):
    r[-i-1]=max(r[-i],10**15-int(d1[-i-1])-int(d2[-i-1]))
print(*r,sep='\n')

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

int main()
{   int a[10005];
    int n;
    while(cin>>n)
    {   for(int i=1;i<=n;i++)
        cin>>a[i];
        sort(a+1,a+1+n);

        cout<<a[n]-a[1]<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#coding:utf-8
import numpy as np
import collections
N = int(input())
arr = []
for n in range(N):
    arr.append(list(map(int,input().split())))
narr = np.array(arr)
x_min  = narr[:,0].min()
x_max = narr[:,0].max()
y_min = narr[:,1].min()
y_max =  narr[:,1].max()
mx = narr[:,2].max()
for k in range(mx+100,mx-1,-1):
    for i in range(x_min,x_max+1):
        for j in range(y_min,y_max+1):
            for x,y,h in arr:
                h_ = max(k-abs(i-x)-abs(j-y),0)
                if h_ != h:
                    break
            else:
                print (i,j,k)
                exit()


Measured memory_bytes: 12496
N, C = map(int, input().split())

su = [0]*(10**5+1)
Q = [[] for i in range(C)]
for i in range(N):
    s, t, c = map(int, input().split())
    Q[c-1].append([s, t])
R = [[] for i in range(C)]
for i in range(C):
    q = Q[i]; q.sort()
    r = R[i]
    if len(q) == 0:
        continue
    r.append(q[0])
    for j in range(1, len(q)):
        if r[-1][1] == q[j][0]:
            r[-1][1] = q[j][1]
        else:
            r.append(q[j])
    for a, b in r:
        su[a-1] += 1
        su[b] -= 1
ans = 0; tmp = 0
for i in range(10**5+1):
    tmp += su[i]
    ans = max(ans, tmp)
print(ans)



Measured memory_bytes: 21420
S = list(input())

d = {}
for s in S:
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

def check(d):
    for k,v in d.items():
        if v != 2:
            return False
        
    return True
    

if check(d):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
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; }
 
int main () {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = x2 - x1;
  int dy = y2 - y1;
  int x3 = x2 - dy;
  int y3 = y2 + dx;
  int x4 = x3 - dx;
  int y4 = y3 - dy;
  cout << x3 SP y3 SP x4 SP y4 << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <string>
#include <deque>
#include <stack>
#include <cmath>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (LL i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<LL> VI;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000;
const LL LINF = 1LL * INF*INF;
const int MAX = 400040	;
const long double PI = acos(-1.);
const double EPS = 1e-6;
LL mod = 1000LL * 1000 * 1000 + 7;

int n,k;
LL arr[3007];
LL dpT[3007][3007][2];
LL dp(int l, int r, int turn)
{
	if(l>r)
		return 0;
	if(dpT[l][r][turn]!=-1LL)
		return dpT[l][r][turn];
	if(turn)
		return dpT[l][r][turn]=min(dp(l+1,r,0)-arr[l],dp(l,r-1,0)-arr[r]);
	else
		return dpT[l][r][turn]=max(dp(l+1,r,1)+arr[l],dp(l,r-1,1)+arr[r]);
}



int main()
{
	//freopen("input.tXXt", "r", stdin);
	ios_base::sync_with_stdio(0);
	FILL(dpT,-1);
	cin >> n;
	FOR(i,0,n)
		cin >> arr[i];
	cout<<dp(0,n-1,0);
	return 0;
}


Measured memory_bytes: 141696
x,y = gets.chomp.split(" ").map(&:to_i)
p = gets.chomp.split(" ").map(&:to_i)
q = gets.chomp.split(" ").map(&:to_i)
r = gets.chomp.split(" ").map(&:to_i)
A = p.max(x)+q.max(y)+r
p A.max(x+y).reduce(:+)

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

int main(){

    int x[4],y[4];

    cin >> x[0] >> y[0] >> x[1] >> y[1];

    int a=x[1]-x[0];
    int b=y[1]-y[0];

    x[2]=x[1]-b;
    y[2]=y[1]+a;
    x[3]=x[2]-a;
    y[3]=y[2]-b;

    cout << x[2] << " " << y[2] << " " << x[3] << " " << y[3] << endl;

    return 0;
}

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

    typedef long long int ll;
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize ("-ffloat-store")
    #pragma GCC optimize ("-fno-defer-pop")

    ll h,w;
    vector <string> vec;


    int main()
    {

        std::ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);

        cin>>h>>w;

        for(ll i=0;i<h;i++)
        {
            string s;
            cin>>s;
            vec.push_back(s);
        }


        ll down[h+1][w+1];
        memset(down,0,sizeof(down));
        for(ll j=0;j<w;j++)
        {
            ll c = 0;
            for(ll i=h-1;i>=0;i--)
            {
                c++;
                if(vec[i][j]=='#'){
                    c = 0;
                }
                down[i][j] = c;
            }
        }

        ll up[h+1][w+1];
        memset(up,0,sizeof(up));

        for(ll j=0;j<w;j++)
        {

            ll c = 0;
            for(ll i=0;i<h;i++){
                c++;
                if(vec[i][j]=='#'){
                    c = 0;
                }
                up[i][j] = c;
            }

        }

        ll left[h+1][w+1];
        memset(left,0,sizeof(left));

        for(ll i=0;i<h;i++){
            ll c = 0;
            for(ll j=0;j<w;j++){
                c++;
                if(vec[i][j]=='#'){
                    c = 0;
                }
                left[i][j] = c;
            }
        }

        ll right[h+1][w+1];
        memset(right,0,sizeof(right));

        for(ll i=0;i<h;i++)
        {
            ll c = 0;
            for(ll j=w-1;j>=0;j--)
            {
                c++;
                if(vec[i][j]=='#')
                {
                    c = 0;
                }
                right[i][j]=c;
            }

        }
        ll ans = 0;
        for(ll i=0;i<h;i++)
        {
            for(ll j=0;j<w;j++)
            {
                if(vec[i][j]=='#')
                {

                }
                else{

                    ans = max(ans,left[i][j]+right[i][j]+up[i][j]+down[i][j]-3);

                }
            }
        }

        cout<<ans<<endl;







    }










Measured memory_bytes: 129664
def roll(dice,dir)
  case dir
  when "N" then dice[0],dice[1],dice[5],dice[4] = dice[1],dice[5],dice[4],dice[0]
  when "S" then dice[0],dice[1],dice[5],dice[4] = dice[4],dice[0],dice[1],dice[5]
  when "E" then dice[0],dice[2],dice[5],dice[3] = dice[3],dice[0],dice[2],dice[5]
  when "W" then dice[0],dice[2],dice[5],dice[3] = dice[2],dice[5],dice[3],dice[0]
  end
  dice
end

d1 = gets.split(" ").map{|i| i.to_i}
d2 = gets.split(" ").map{|i| i.to_i}

yn = false    
for i in 1..6
  d = Marshal.load(Marshal.dump(d2))
  case i
  when 2 then d = roll(d,"S")
  when 3 then d = roll(roll(d,"W"),"S")
  when 4 then d = roll(d,"N")
  when 5 then d = roll(roll(d,"E"),"S")
  when 6 then d = roll(roll(d,"S"),"S")
  end
  for j in 0..4
    d = roll(d,"W")
    yn = (yn || d == d1)
  end
end

puts(yn ? "Yes" : "No")

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

    // 降順ソート
    sort(B, B + N, greater<int>());
    int max = B[0], max2 = B[1];
    if(max == max2){
        for(int i=0;i<N;i++)
            cout << max << endl;
        return 0;
    }
    for(int i=0;i<N;i++){
        if(A[i] == max)
            cout << max2 << endl;
        else
            cout << max << endl;
    }

}

Measured memory_bytes: 3200
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int MOD = 26;

int main(void){
    int n; cin >> n;
    cin.ignore();

    while(n--){
        string cipher;
        getline(cin, cipher);

        string plain = cipher;
        bool ok = false;

        rep(a, 100){
            rep(b, 100){
                if(ok) break;

                plain = cipher;
                rep(i, cipher.size()){
                    if(plain.at(i) != ' ') plain[i] = ((a * (cipher[i] - 'a') + b) % MOD) + 'a';
                }

                if(plain.find("that") != -1 || plain.find("this") != -1) ok = true;
            }
        }

        cout << plain << endl;
    }

	return 0;
}

Measured memory_bytes: 1212
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  for(int i=0;i<k;i++){
    vector<int> imos(n+10);
    for(int j=0;j<n;j++){
      int l=max(0,j-a[j]);
      int r=min(n,j+a[j]);
      imos[l]++;
      imos[r+1]--;
    }
    a[0]=imos[0];
    for(int j=0;j<n;j++){
      a[j]=a[j-1]+imos[j];
    }
    bool all_n=true;
    for(int j=0;j<n;j++){
      if(a[j]!=n){
        all_n=false;
        break;
      }
    }
    if(all_n){
      OutVec(a);
      return 0;
    }
  }
  OutVec(a);




  return 0;
}




Measured memory_bytes: 4936
class Factorial:
    def __init__(self, max_fact, mod):
        #mod should be prime number
        #using homogeneous_product(n,r), max_fact ≧ max(n+r-1)
        f = [1] * (max_fact + 1)
        for idx in range(2, max_fact + 1):
            f[idx] = f[idx - 1] * idx
            f[idx] %= mod
        if mod > max_fact:
            fi = [pow(f[-1], mod - 2, mod)]
            for idx in range(max_fact, 0, -1):
                fi += [fi[-1] * idx % mod]
            fi = fi[::-1]
        else:
            fi = [pow(n, mod - 2, mod) for n in f]
        self.mod = mod
        self.f = f
        self.fi = fi

    def factorial(self, n):
        return self.f[n]

    def factorial_inverse(self, n):
        return self.fi[n]

    def combination(self, n, r):
        f = self.f
        fi = self.fi
        return f[n] * fi[r] * fi[n - r] % self.mod

    def permutation(self, n, r):
        return self.f[n] * self.fi[n - r] % self.mod

    def homogeneous_product(self, n, r):
        f = self.f
        fi = self.fi
        return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod


max_fact = 10**6
mod = 10**9 + 7
fact_instance = Factorial(max_fact, mod)
comb = fact_instance.combination
perm = fact_instance.permutation
combrep = fact_instance.homogeneous_product

X, Y = [int(_) for _ in input().split()]
i = X - (X + Y) // 3
j = Y - (X + Y) // 3
if (X + Y) % 3 or i < 0 or j < 0:
    ans = 0
else:
    ans = comb(i + j, i)
print(ans)


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long h, c = 1;
  cin >> h;
  long long res = 0;
  while (h) {
    res += c;
    h /= 2;
    c *= 2;
  }
  cout << res << '\n';
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

int main() {
    string N;
    cin >> N;
    ll cnt = 0;

    rep(i, N.length()) {
        if (N[i] == '2') cnt++;
    }

    cout << cnt << endl;
    return 0;
}


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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;

  map<int, bool> m;  
  int ans = 0;
  for ( int i = 0; i < N; i++ ) {
    int a;
    cin >> a;
    m[a] = !m[a];
    ans += m[a] ? 1 : -1;    
  }

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


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

using namespace std;
using lint = long long;

bool isOK(vector<lint> v, lint index, lint key)
{
    if(v[index] >= key)
        return true;
    else   
        return false;
}
int binary_search(vector<lint> v, lint key)
{
    int ng = -1;
    int ok = (int)v.size();

    while(abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        if(isOK(v, mid, key))
            ok = mid;
        else 
            ng = mid;
    } 
    return ok;
}

lint calc_distance(lint q, lint t, lint s)
{
    if(q <= t && q <= s){
        return max(t, s) - q;
    }else if(q >= t && q >= s){
        return q - min(t, s);
    }else{
        lint minabs = min(abs(q - t),abs(q - s));
        return abs(q - t) + abs(q - s) + minabs; 
    }
}
int main(void)
{
    lint A, B, Q;
    cin >> A >> B >> Q;
    vector<lint> s(A);
    vector<lint> t(B);
    for(auto &x: s){
        cin >> x;
    }
    for(auto &x: t){
        cin >> x;
    }
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    
    for(int i = 0; i < Q; i++){
        lint q;
        cin >> q;
        lint i_sh = lower_bound(s.begin(), s.end(), q) - s.begin();
        //lint i_sh = binary_search(s, q);
        //cout << i_sh << endl;
        lint i_sl = i_sh -1;
        if(i_sl < 0) i_sl = 0;
        lint s_h = s[i_sh];
        lint s_l = s[i_sl];

        lint i_th = lower_bound(t.begin(), t.end(), q) - t.begin();
        //lint i_th = binary_search(t, q);
        lint i_tl = i_th -1;
        if(i_tl < 0) i_tl = 0;
        lint t_h = t[i_th];
        lint t_l = t[i_tl];

        lint dist1 = calc_distance(q, t_h, s_h);
        lint dist2 = calc_distance(q, t_h, s_l);
        lint dist3 = calc_distance(q, t_l, s_h);
        lint dist4 = calc_distance(q, t_l, s_l);
        lint dist = min({dist1, dist2, dist3, dist4});
        cout << dist << endl;

    }

}

Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        String s = sc.next();
        int[] mod = new int[2019];
        mod[0] = 1;
        int[] sums = new int[s.length() + 1];
        int idx = 1;
        int count = 0;
        for (int i = s.length() - 1; i >= 0; i--) {
            int num = ((s.charAt(i) - '0') * idx + sums[i + 1]) % 2019;
            sums[i] = num;
            count += mod[num];
            mod[num]++;
            idx = idx * 10 % 2019;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 40932
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		long[] a = new long[6];

		for(int i=0; i<6; i++){
			a[i] = Long.parseLong(sc.next());
		}
		
		long max = 0L;
		long max_i = 1L;
		for(int i=1; i<6; i++){
			long tmp_max;
			
				tmp_max = a[0]/a[i] ;
			
			if (tmp_max > max){
				max = tmp_max;
				max_i = i;
			}
		}
		long ans;
		if(max == a[0]){
			ans = max + 4;
		}else{
			ans = max + 5;
		}
		
		
		System.out.println(ans);

		sc.close();
	}
	
}


Measured memory_bytes: 21972
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<iostream>
#include <stdlib.h>
#include<ctime>
#include <string>
#include<string.h>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
	int a, b, k;
	int cnt = 0;

	cin >> a >> b >> k;
	if (a < b)swap(a, b);
	for (int j = b; j > 0; j--)
	{
		if (a%j == 0 && b%j == 0)cnt++;
		if (cnt == k)
		{
			cout << j << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <array>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <random>
#include <bitset>
#include <cassert>
#include <tuple>
#include <list>
#include <iterator>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;
typedef long double ld;

template<class htpe, class cmp>
using heap = priority_queue<htpe, vector<htpe>, cmp>;

template<class htpe>
using min_heap = heap<htpe, greater<htpe> >;

template<class htpe>
using max_heap = heap<htpe, less<htpe> >;

#define mp make_pair
#define pb push_back
#define mt make_tuple
#define ff first
#define ss second

#define forn(i, n) for (int i = 0; i < ((int)(n)); ++i)
#define forrn(i, s, n) for (int i = (int)(s); i < ((int)(n)); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define PYMOD(a, m) ((((a) % (m)) + (m)) % (m))

const int INF = 1791791791;
const ll INFLL = 1791791791791791791ll;


int main() {
    // Code here:

    string sn;
    cin >> sn;

    ll n;
    stringstream ss;
    ss << sn;
    ss >> n;

    if (n < 1e6) {
        int ans = 0;
        forrn(i, 1, n + 1) {
            string s;
            ss.clear();
            ss << i;
            ss >> s;
            int w = 0;
            for (char c : s) {
                w += c - '0';
            }
            ans = max(ans, w);
        }
        cout << ans << endl;
        return 0;
    }

    int ans = 9 * (sn.size() - 1);
    forn(i, sn.size()) {
        if (sn[i] != '0' + (i == 0)) {
            int w = 0;
            forn(j, i) {
                w += sn[j] - '0';
            }
            w += sn[i] - '0' - 1;
            w += 9 * (sn.size() - i - 1);
            ans = max(ans, w);
        }
    }
    int w = 0;
    forn(i, sn.size())
        w += sn[i] - '0';
    ans = max(ans, w);

    cout << ans << endl;

    return 0;
}


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

string letter;
string letter2;
int N,NN;
int main(){
	cin >> letter;
  	N = letter.size();
	for(int i = 0; i<N;i+=2){
        	letter2+=letter[i];
    }
  cout << letter2 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    ll a; cin >> a;
    cout << a + a*a + a* a*a << endl;
}


Measured memory_bytes: 3636
n,m=map(int,input().split())
a = list(map(int, input().split()))
bc=[list(map(int,input().split())) for _ in range(m)]
#print(bc)
bc=sorted(bc,key= lambda x:x[1],reverse=True)
#print(bc)

bc2=[]
for i in range(m):
    bc2.extend([bc[i][1]]*bc[i][0])
    if len(bc2)>n: break
#print(bc2)
a.extend(bc2)
a.sort(reverse=True)

print(sum(a[:n]))

Measured memory_bytes: 36728
#include <bits/stdc++.h>
#define N 100010
using namespace std;
typedef long long ll;
inline ll read()
{
  ll p=0; ll f=1; char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
  while(ch>='0' && ch<='9'){p=p*10+(ch-'0'); ch=getchar();}
  return p*f;
}
struct node
{
  ll x,y,d;
  node(){}
  node(ll _x,ll _y,ll _d){x=_x; y=_y; d=_d;}
}edge[N],a[N]; ll len;
bool cmp(const node &x,const node &y)
{
  return x.d<y.d;
}
ll val[N],fa[N],siz[N];
ll ffind(ll x){return (fa[x]==x) ? fa[x] : ffind(fa[x]);}
int main()
{
  ll n=read(),m=read();
  for(ll i=1;i<=n;i++) val[i] = read() , fa[i] = i , siz[i] = 1;
  for(ll i=1;i<=m;i++){a[i].x = read(); a[i].y = read(); a[i].d = read();}
  len = 0; sort(a+1,a+m+1,cmp);
  for(ll i=1;i<=m;i++)
  {
    ll x = ffind(a[i].x); ll y = ffind(a[i].y);
    if(x!=y)
    {
      if(siz[x] < siz[y]) swap(x,y);
      len++; edge[len] = node(x,y,a[i].d);
      val[x] += val[y]; siz[x] += siz[y]; fa[y] = x;
    }
  }
  for(ll i=len;i>=1;i--)
  {
    ll x = edge[i].x; ll y = edge[i].y;
    if(edge[i].d > val[ffind(x)])
    {
      fa[y] = y;
      while(x!=fa[x]) val[x] -= val[y],x=fa[x]; val[x] -= val[y];
    }
  }ll s = 0;
  for(ll i=1;i<=m;i++)
  {
    ll x = ffind(a[i].x); ll y = ffind(a[i].y);
    if(x==y && val[x]>=a[i].d) s++;
  }
  return printf("%lld\n",m-s),0;
}

Measured memory_bytes: 7296
def resolve():
    n,k,q=map(int, input().split())
    l=[int(input()) for i in range(q)]
    a=[k-q for i in range(n)]
    for i in l:
        a[i-1]+=1
    for i in range(n):
        if a[i]<=0:
            print('No')
        else:
            print('Yes')
resolve()

Measured memory_bytes: 57432
def main():
    
    s = input()[::-1]
    mod = 10**9+7
    dp = [[0 for j in range(13)] for i in range(len(s)+1)]
    dp[0][0] = 1
    ten = 1


    for i in range(len(s)):
        if s[i] == "?":
            for k in range(10):
                x = k*ten%13
                for j in range(13):
                    dp[i+1][(j+x)%13] = (dp[i][j]+dp[i+1][(j+x)%13])%mod
        
        else:
            x = int(s[i])*ten%13
            for j in range(13):
                dp[i+1][(j+x)%13] = (dp[i][j]+dp[i+1][(j+x)%13])%mod

        ten = (ten*10)%13

    print(dp[-1][5]%mod)

if __name__ == "__main__":
    main()

Measured memory_bytes: 66976
#include <iostream>

using namespace std;

int main(void)
{
	int a, b;
	char op;

	while (1) {
		cin >> a >> op >> b;

		if (op == '+')
			cout << a + b << endl;
		else if (op == '-')
			cout << a - b << endl;
		else if (op == '*')
			cout << a * b << endl;
		else if (op == '/')
			cout << a / b << endl;
		else if (op == '?')
			break;
	}
}

Measured memory_bytes: 3088
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
pre = -1
for a in A:
  ans += B[a-1]
  if a - 1 == pre:
    ans += C[a-2]
  pre = a

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
  long long d;
  while(cin>>d,d){
    int n,m;
    long long ans=0;
    cin>>n>>m;
    vector<long long> s(n),k(m);
    s[0]=0;
    for(int i=1;i<n;++i)cin>>s[i];
    for(int i=0;i<m;++i)cin>>k[i];
    
    sort(s.begin(),s.end());
    vector<long long> div(n+1);
    div[0]=-1;
    for(int i=0;i<n;++i){
    	div[i+1]=(((i+1==n)?d:s[i+1])-s[i])/2+s[i];
    }
    
    for(int i=0;i<m;++i){
    	for(int j=n;j>=0;--j){
    		if(k[i]>div[j]){
    			//cerr<<abs(k[i]-s[j%n])<<" ";
    			ans+=abs(s[j%n]+((j==n)?d:0)-k[i]);
    			break;
    		}
    		//cerr<<endl;
    	}
    }
    
    cout<<ans<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 2656
[<EntryPoint>]
let main argv =
    let rint () = stdin.ReadLine() |> int
    let n = rint ()
    let k = rint ()
    let a = rint ()
    let b = rint ()
    n * a - (a - b) * (max (n - k) 0)
    |> stdout.WriteLine
    0

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

const int N = 100005;

int head[N], tot, ans = 0, n;
struct edge { int to, nxt; } e[N << 1];

void link(int x, int y) {
	e[++tot] = (edge) { y, head[x] }, head[x] = tot;
	e[++tot] = (edge) { x, head[y] }, head[y] = tot;
}
int dfs(int x, int f = 0) {
	int ret = 0, max = 0;
	for (int i = head[x]; i; i = e[i].nxt) if (e[i].to != f) {
		int v = dfs(e[i].to, x);
		max = std::max(max, std::__lg(ret & v)), ret |= v;
	}
	int b = __builtin_ctz(~ret & (-1 << max));
	ans = std::max(ans, b);
	return (ret &= (-1 << b)) |= 1 << b;
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1, x, y; i < n; ++i)
		std::cin >> x >> y, link(x, y);
	dfs(1), std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
long long n,z,a[100005],c;
struct haha//结构体
{
    long long s,gs;
}f[100005];
void quchong()//去重过程
{
    f[1].s=a[1];f[1].gs=1;c=1;
    for(int i=2;i<=n;i++)//去重
    {
        if(a[i]!=a[i-1])//如果不相等便新开一个数组装下，否则便个数++
        f[++c].s=a[i],f[c].gs=1;
        else f[c].gs++;
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    sort(a+1,a+n+1);
    quchong();//调用过程
    for(int i=1;i<=c;i++)
    if(f[i].gs%2==1)z++;//如果出现奇数次便统计
    cout<<z<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <map>
#include <string>
using namespace std;
#define L(x) (1 << (x))
typedef long long ll;

const int Maxn = 1010;
struct Per
{
	string name;
	int deep;
	int fa;
	void out()
	{
		cout << name <<" " << deep <<" " << fa << endl;
	}
}per[Maxn];
int n, m;
char str[Maxn + 100];
map<string, int>mp;
pair<int, string> fenjie(char str[])
{
	int ret1 = 0;
	for (ret1 = 0; str[ret1] == ' '; ++ret1);
	string ret2= "";
	for (int i = ret1; str[i]; ++i)
		ret2 += str[i];
	return make_pair(ret1, ret2);
}
int id[Maxn];
bool isChild(string a, string b)
{
	int k1 = mp[a], k2 = mp[b];
	return per[k1].fa == k2;
}
bool isAncestor(string a, string b)
{
//cout << a <<" " << b << endl;
	int k1 = mp[a], k2 = mp[b];
	//cout <<k1 <<" " << k2 << endl;
	while (k2 != -1 && per[k2].deep >= per[k1].deep)
	{
	
		if (k1 == k2) return true;
		k2 = per[k2].fa;
	}
	return false;
}
bool isSibling(string a, string b)
{
	int k1 = mp[a], k2 = mp[b];
	return per[k1].fa == per[k2].fa;
}
bool isParent(string a, string b)
{
	int k1 = mp[a], k2 = mp[b];
	return per[k2].fa == k1;
}
bool isDescendant(string a, string b)
{
	return isAncestor(b, a);
}

int main()
{
	while (scanf("%d%d", &n, &m) != EOF)
	{
		if (n == 0 && m == 0) break;
		gets(str);
		mp.clear();
		
		for (int i = 0; i < n; ++i)
		{
			gets(str);
			pair<int, string> res = fenjie(str);
			if (res.first == 0) 
				per[i].fa = -1;
			else per[i].fa = id[res.first - 1];
			id[res.first] = i;
			mp[res.second] = i;
			per[i].name = res.second;
			per[i].deep = res.first;
		//	per[i].out();
		}
		for (int i = 0; i < m; ++i)
		{
			char a[100], re[100], b[100];
			scanf("%s%*s%*s%s%*s%s", a, re, b);
			b[strlen(b) - 1] = 0;
			bool ret;
			if (strcmp(re, "child") == 0)
				ret = isChild(a, b);
			else if(strcmp(re, "ancestor") == 0)
				ret = isAncestor(a, b);
			else if(strcmp(re, "sibling") == 0)
				ret = isSibling(a, b);
			else if (strcmp(re, "parent") == 0)
				ret = isParent(a, b);
			else if (strcmp(re, "descendant") == 0)
				ret = isDescendant(a, b);
			else assert(0);
			puts(ret ? "True" : "False");
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1364
#if 0
N戸の家が存在するとき、N-1個の家と家の間が存在する。
K個の発電機が存在するため、K-1個の家の間だけは電線で繋がなくて良いことになる。
すなわち、家と家の間の長さが大きい順にK-1個だけ選び
このときN<=Kであれば、全ての家の前に発電機をおき、電線の長さは0になる。
#endif

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int T, N, K, MAX;
vector<int> DIFF;
int main()
{
    cin >> T; // データセットの数
    for (int i = 0; i < T; i++)
    {
        cin >> N; // 家の戸数
        cin >> K; // 発電機の個数

        int first;
        cin >> first;     // 最初の座標
        int prev = first; // 初期値の代入
        for (int j = 0; j < N - 1; j++)
        {
            int temp;
            cin >> temp;                 // 家の座標
            DIFF.push_back(temp - prev); // 家の間隔
            prev = temp;                 // prevの更新
            if (j == N - 2)
            {
                MAX = temp - first; // 最大値
            }
        }
        if (N <= K)
        {
            // 発電機の数の方が多い場合
            cout << 0 << endl;
            DIFF.clear();
            continue;
        }
        sort(DIFF.begin(), DIFF.end());
        int sum = 0;
        for (int j = 0; j < K - 1; j++)
        {
            sum = sum + DIFF.back();
            DIFF.pop_back();
        }
        cout << MAX - sum << endl;
        DIFF.clear();
    }
}



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

int main()
{
    int A, B, X;
    cin >> A >> B >> X;
    if( (0 <= (X - A)) && ((X - A) <= B) ) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO"  << endl;
    }

    return 0;
}


Measured memory_bytes: 256