akhauriyash/Code-Regression huggingface dataset:
//Created by Aminul on 7/25/2020.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int x = in.nextInt();
        for (int i = 1800, j = 1; i >= 400; i -= 200, j++) {
            if (i <= x) {
                pw.println(j);
                break;
            }
        }

        pw.close();
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}

Measured memory_bytes: 27056
def gcd(x, y):
  b = max(x, y)
  s = min(x, y)
  r = b % s
  while r != 0:
    b = s
    s = r
    r = b % s
  return s

def lcm(x, y):
  return (x * y) // gcd(x,y)

import math
def prime(x):
  p = {}
  last = math.floor(x ** 0.5)
  if x % 2 == 0:
    cnt = 1
    x //= 2
    while x & 1 == 0:
      x //= 2
      cnt += 1
    p[2] = cnt
  for i in range(3, last + 1, 2):
    if x % i == 0:
      x //= i
      cnt = 1
      while x % i == 0:
        cnt += 1
        x //= i
      p[i] = cnt
  if x != 1:
    p[x] = 1
  return p

N = int(input())
A = list(map(int, input().split()))

R = {}
F = True
for i in A:
  p = prime(i)
  for j in p.keys():
    if j in R:
      F = False
      break
    else:
      R[j] = 1
  else:
    continue
  break

if F:
  print("pairwise coprime")
  exit()

t = A[0]
for i in range(1, N):
  t = gcd(t, A[i])

if t == 1:
  print("setwise coprime")
else:
  print("not coprime")


Measured memory_bytes: 197740
def kaijo(num, mod):
    now_num = 1
    for i in range(1, num + 1):
        now_num *= i
        now_num %= mod
    return now_num

def main():
    dog, monky = map(int, input().split())
    mod = 10 ** 9 + 7

    if abs(dog - monky) > 1:
        print(0)
    else:
        dog_num = kaijo(dog, mod)
        monky_num = kaijo(monky, mod)

        if dog == monky:
            ans = dog_num * monky_num * 2
        else:
            ans = dog_num * monky_num
        print(ans % mod)




if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
from collections import deque
s = deque(input())
q = int(input())
lis = [list(input().split()) for _ in range(q)]
rev = 0
z = 0

for i in lis:
    if i[0] == "2":
        if (rev + int(i[1])) % 2 == 1:
            s.appendleft(i[2])
        else:
            s.append(i[2])
        z = 1
    else:
        if z == 1:
            rev += 1
        
if rev % 2 == 1:
    s = reversed(s)
print("".join(s))
    

Measured memory_bytes: 35444
N=int(input())

A= list(map(int,input().split()))

B= list(map(int,input().split()))

C= list(map(int,input().split()))

sum=0
for i in B:
    sum+=i

for j in range(len(A)-1):
    if (A[j+1]-A[j])==1:
        sum+=C[A[j]-1]

print(sum)


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


int main(){
        int a,b,c;
        while(scanf("%d%d%d",&a,&b,&c) != EOF){
                if(a+c == 2*b) printf("YES\n");
                else printf("NO\n");
        }
        return 0;
}

Measured memory_bytes: 256
n,q=map(int, input().split())
s=input()
lr = [list(map(int,input().split())) for _ in range(q)]

cum = [0]*(n+1)
pre = s[0]
cnt=0
for i in range(1,n):
    now = s[i]
    if pre=="A" and now=="C":
        cnt+=1
    cum[i+1] = cnt
    pre = now
for l,r in lr:
    print(cum[r]-cum[l])

Measured memory_bytes: 29640
import collections

def check(A):
    count = 0
    for j in A:
        n = A[j]
        if n > 1:
            count += n * (n - 1) / 2
            
    return int(count)


N = int(input())
A = list(map(int, input().split(" ")))
A2 = collections.Counter(A)
# print(A2)
Nsum = check(A2)
# print(Nsum)
for i in range(0,N):
    num = A[i]
    count = A2[num]
    out = Nsum - ( count - 1 )
    print(out)

Measured memory_bytes: 26780
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    else:
        for i in range(0, h):
            if i == 0 or i == h-1:
                print("#" * w)
            else:
                print("#" + "." * (w-2) + "#")
        print("")

Measured memory_bytes: 5616
from decimal import Decimal
import math
for _ in range(int(input())):
    x1,y1,x2,y2,x3,y3=list(map(Decimal,input().split()))
    a=x1-x3
    b=y2-y3
    c=x2-x3
    d=y1-y3
    e=y1-y2
    f=x1+x3
    g=x2+x3
    X=(b*d*e+a*b*f-c*d*g)/2/(a*b-c*d)
    try:
        Y=-(a/d)*(X-f/2)+(y1+y3)/2
    except:
        Y=-(c/b)*(X-g/2)+(y2+y3)/2
    R=math.sqrt((x1-X)**2+(y1-Y)**2)
    print(" ".join(["{:.3f}".format(i) for i in [X,Y,R]]))


Measured memory_bytes: 6480
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double ld;

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


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

    bool ans=false;
    for(ll i=1;i<=1000;i++){
        if(100*i <= X && X <= 105*i){
            ans = true;
            break;
        }
    }

    if(ans){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}




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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

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

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

  int h, w, n;
  cin >> h >> w >> n;

  int ans = INT_MAX;
  for (int a = 0; a <= h; a++) {
    for (int b = 0; b <= w; b++) {
      int x = h * w - (h - a) * (w - b);
      if (x >= n) {
        UpdateMin(ans, a + b);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
#include <stdbool.h>
using namespace std;

class Point {
    public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) { return Point(x+p.x, y+p.y); }
    Point operator - (Point p) { return Point(x-p.x, y-p.y); }
    Point operator * (double a) { return Point(a*x, a*y); }
    Point operator / (double a) { return Point(x/a, y/a); }

    double abs() {return sqrt(norm()); }
    double norm() {return x*x + y*y; }
};

typedef Point Vector;


double dot(Vector a, Vector b) {
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
    return a.x*b.y - a.y*b.x;
}

Point projection(Point p1, Point p2, Point p) {
    Vector v = p2 - p1;
    Vector u = p - p1;
    Point t = p1 + v*dot(u,v)/v.norm();
    return t;
}

//2つのベクトルが平行かどうか
bool isParallel(Vector u, Vector v){
    double Cross = cross(u,v);
    bool out = (Cross==0)? true : false;
    return out;
}

//ポイントp2が線分p0p1上にいるかどうか
bool isOn(Point p0, Point p1, Point p2){
    Vector v01 = p1 - p0;
    Vector v02 = p2 - p0;
    Vector v10 = p0 - p1;
    Vector v12 = p2 - p1;

    return cross(v01,v02)==0 && dot(v01,v02)>=0 && dot(v10,v12)>=0;
}

//ポイントp2がベクトルp1-p0からみて反時計回りにいるかどうか
//CCW: 1, CW: -1, ON:0
int isCCW(Point p0, Point p1, Point p2){
    Vector v01 = p1 - p0;
    Vector v02 = p2 - p0;

    double Cross = cross(v01, v02);
    
    int out = 2;
    if (Cross>0){out = 1;}
    else if(Cross<0){out = -1;}
    else{out = 0;}

    return out;
}

bool isIntersect(Point p0, Point p1, Point p2, Point p3){
    Vector s1 = p1-p0;
    Vector s2 = p3-p2;
    bool out;
    //平行な場合
    if(isParallel(s1,s2))
    {
        out = isOn(p0,p1,p2) || isOn(p0,p1,p3) || isOn(p2,p3,p0) || isOn(p2,p3,p1);
    }
    //平行でない場合
    else     
    {
        out = ( ( isCCW(p0,p1,p2)*isCCW(p0,p1,p3) ) <= 0 ) && ( ( isCCW(p2,p3,p0)*isCCW(p2,p3,p1) ) <= 0 );
    }
    return out;
}

int main(){
    #if 0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    #endif

    int q;
    cin >> q;

    for(int i=0; i<q; i++){
        Point p0, p1, p2, p3;
        cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;

        bool out = isIntersect(p0, p1, p2, p3);

        cout << int(out) << "\n";
    }
    
    return 0;
}



Measured memory_bytes: 3232
n= int(input())
a=[int(i) for i in input().split()]
b=[0]
k=0
for i in a:
  k+=i
  b.append(k)
c={}
for i in b:
  if i in c:
    c[i]+=1
  else:
    c[i]=1
k=0
for i in c:
  k+=c[i]*(c[i]-1)//2
print(k)

Measured memory_bytes: 41108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++)cin >> A[i];
  double a=0;
  for(int i=0;i<N;i++){a+=1.0/A[i];}
  printf("%.7f",1.0/a);
}

Measured memory_bytes: 256
n=int(input())
a_list=[int(i) for i in input().split()]
odd=[a_list[i] for i in range(n) if i%2==1]
even=[a_list[i] for i in range(n) if i%2==0]

ans=[]
if n%2==1:
    even.reverse()
    ans=even+odd
else:
    odd.reverse()
    ans=odd+even
print(' '.join(map(str, ans)))


Measured memory_bytes: 31296
open System
let R T = stdin.ReadLine()|> T
let RS T = stdin.ReadLine().Split()|>Array.map T
let Mod = (1e9|>int64)+7L
[<EntryPoint>]
let main argv =
    let S = R string
    [0..(S.Length/2 - 1)]
    |>Seq.sumBy(fun c -> if (S.[c]=S.[S.Length-1-c]) then 0 else 1)
    |>stdout.WriteLine
    0


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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

//#define int int64_t
int a[N+2];
bool chk(int n){
  if(n==1)return false;
  for(int i=2;i*i<=n;++i)if(n%i==0)return false;
  return true;
}
int32_t  main(){
	IOS;
  memset(a,0,sizeof(a));
  for(int i=1;i<=N;++i){
    if(i%2==1 && chk(i) && chk((i+1)/2))a[i]=1;
    a[i]+=a[i-1];
  }  
  int q;cin>>q;
  while(q--){
    int l,r;cin>>l>>r;
    cout<<a[r]-a[l-1]<<endl;
  }

  return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9 +7;
ll Power(ll x,ll k)
{
	x%=mod;
	ll sss=1;
	while (k)
	{
		if (k%2) sss=sss*x%mod;
		x=x*x%mod;
		k/=2;
	}
	return sss;
}
ll ny(ll x){return Power(x,mod-2);}
int n,q;
ll f[4030][4030];
ll ans;
ll a[5030],b[5][5030];
int main()
{
	scanf("%d%d",&n,&q);
	for (int i=1;i<=n;++i) scanf("%lld",&a[i]);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=n;++j) if (a[i]>a[j]) f[i][j]=1;

	int x,y; ll doe=ny(2);
	for (int i=1;i<=q;++i)
	{
		scanf("%d%d",&x,&y);
		if (x==y) continue;
		for (int j=1;j<=n;++j)
		{
			b[0][j]=f[j][x];
			b[1][j]=f[x][j];
			b[2][j]=f[j][y];
			b[3][j]=f[y][j];
		}

		for (int j=1;j<=n;++j)
		{
			if (j!=x) (f[j][y]+=b[0][j])%=mod;
			if (j!=x) (f[y][j]+=b[1][j])%=mod;
			if (j!=y) (f[j][x]+=b[2][j])%=mod;
			if (j!=y) (f[x][j]+=b[3][j])%=mod;
		}
		for (int j=1;j<=n;++j)
		{
			if (j!=x) f[j][y]=f[j][y]*doe%mod;
			if (j!=x) f[y][j]=f[y][j]*doe%mod;
			if (j!=y) f[j][x]=f[j][x]*doe%mod;
			if (j!=y) f[x][j]=f[x][j]*doe%mod;
		}
		ll A=f[x][y],B=f[y][x];
		f[y][x]+=A; f[x][y]+=B;
		f[x][y]=f[x][y]*doe%mod;
		f[y][x]=f[y][x]*doe%mod;
	}
	for (int i=1;i<=n;++i)
		for (int j=i+1;j<=n;++j) (ans+=f[i][j])%=mod;
	ans=ans*Power(2,q)%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 96128
if __name__ == "__main__":
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    budget = 0
    if A > B:
        budget += B
    else:
        budget += A
    if C > D:
        budget += D
    else:
        budget += C
    print(budget)

Measured memory_bytes: 3060
def bfs(n, m, v):
    if n == 0:
        return f(v)
    return max(f(bfs(n-1, x, [x]+v)) for x in range(1, m+1))

def solve(n, m, q, a, b, c, d):
    def f(v):
        return sum(d[i] for i in range(q) if v[b[i]-1] - v[a[i]-1] == c[i])
    def bfs(n, m, v):
        if n == 0:
            return f(v)
        return max(bfs(n-1, x, [x]+v) for x in range(1, m+1))
    return bfs(n, m, [])

n, m, q = map(int, input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())
print(solve(n, m, q, a, b, c, d))

Measured memory_bytes: 9212
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <tuple>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REPEAT(i) FOR(counter1234,0,i)
#define iter(el, arr) for(auto& el : arr)
#define ALL(a) a.begin(), a.end()

#define ld long double
#define ll long long
#define pii pair<int, int>
#define pll pair<ll,ll>
#define MP make_pair
#define MT make_tuple
#define SZ(a) ll((a).size())
#define X first
#define Y second

#define endl '\n'
#define PB push_back
#define has(i, m) (m.find(i) != m.end())

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define vch vector<char>
#define vvi vector<vi>
#define vvll vector<vll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vb vector<bool>
#define vvb vector<vb>
#define vs vector<string>
#define pdd pair<ld, ld>
#define vpll vector<pll>
#define vpdd vector<pdd>
#define pq priority_queue
#define mod 1000000007
using namespace std;

const ll INF = 1e18;
const ll MAXN = 100001;

ll power(ll n, ll to, ll m = mod)
{
	ll res = 1;
	while (to)
	{
		if (to & 1)
			res = (res*n) % m;
		n = (n*n) % m;
		to >>= 1;
	}
	return res;
}

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);	
	//freopen("Out.txt", "w", stdout);

	int n;
	cin >> n;
	vll a(n);
	FOR(i, 0, n)
		cin >> a[i];
	
	sort(ALL(a));
	reverse(ALL(a));

	ll a1 = -1, a2 = -1;
	int ind = -1;
	FOR(i, 0, n - 1)
		if (a[i] == a[i + 1])
		{
			a1 = a[i], ind = i + 1;
			break;
		}

	FOR(i, ind + 1, n - 1)
		if (a[i] == a[i + 1])
		{
			a2 = a[i];
			break;
		}

	if (a2 == -1)
		cout << 0;
	else
		cout << a1*a2;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)


int main(){
	int n;
	cin >> n;
	vector<int>p(n);
	rep(i, n)cin >> p[i];
	int ans = 0;
	rep(i, n-2) {
		if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2]) || (p[i + 2] < p[i + 1] && p[i + 1] < p[i])) {
			ans++;

		}

	}
	cout << ans;
}
	



Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
/**
*超时有可能是输入的问题
*注意边界
*仔细读题
*没思路试试逆向思维
**加油，奥利给！！！ 
**/
map<int,int>p;
int a[200000];
int gcd(int x,int y,int z)
{
	int i;
	for(i=z;i>=1;i--)
	{
		if(x%i==0&&y%i==0&&z%i==0)
		return i;
		
	}
}
int main()
{
	ll m,n,i,j,t,s=0,k;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			for(k=1;k<=n;k++)
			{
				s+=gcd(i,j,k);
			}
		}
	}
	cout<<s;
 } 

Measured memory_bytes: 3640
#pragma GCC optimize(2,3,"Ofast","unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
	char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
	in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
	in ll read()
	{
		ll x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
		x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
	}
	in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
	in int gs(char *s) {char c,*t=s;while(c=gc(),c<=32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
	in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
	in void flush() {if(C>1<<22) ot();}
	template <typename T>
	in void write(T x,char t)
	{
		int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
		if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
	}
	in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
#define pb push_back
const int N=1e6+5;
char s[N],t[N];
int main()
{
	int n=gs(s+1);gs(t+1);int ans=0;
	for(int i=1;i<=n;i++) ans+=s[i]!=t[i];
	cout<<ans;
	return ot(),0;
}
//Author: disangan233

Measured memory_bytes: 4024
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#define LL long long
#define LD long double
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;

int main()
{
	FIO;
	LD a, b, x; cin>>a>>b, x=(a*b)+0.0001;
	LL i=x;
	cout<<i<<"\n";
}

Measured memory_bytes: 3748
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll dp[250][250];
int main(){
    int n,m,r;
    cin>>n>>m>>r;
    vector<int> root(r);
    for(int i=0;i<r;i++){
        cin>>root[i];
        root[i]--;
    }
    sort(all(root));
       for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(i!=j)dp[i][j]=inf;
    for(int i=0;i<m;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        dp[a][b]=c;
        dp[b][a]=c;
    }
     int V=n;
     for(int k=0;k<V;k++)
                for(int i=0;i<V;i++)
                   for(int j=0;j<V;j++)
                   dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
    ll ans=inf;
    do{
        ll res=0;
        for(int i=0;i<r-1;i++){
       res+=dp[root[i]][root[i+1]];
      }
          ans=min(res,ans);
    }while(next_permutation(all(root)));
   //辞書順生成なので最初に辞書順が一番小さいものからやらないとうまく行きません💩
   cout<<ans<<endl;
}  

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

void swap(int& a,int& b){
	int work;
	work = a;
	a = b;
	b = work;
}

int Partition(std::vector<int>& v,int p, int r){
	int x = v[r];
	int i;
	i = p-1;
	for(int j=p;j<r;j++){
		if(v[j]<=x){
			i++;
			swap(v[i],v[j]);
		}
	}
	swap(v[i+1],v[r]);
	return i+1;
}

int main(){
	int n,in;
	std::vector<int> v;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> in;
		v.push_back(in);
	}

	int q;
	q = Partition(v,0,n-1);

	for(int i=0;i<n;i++){
		if(i) cout <<" ";
		if(i==q){
			cout <<"[";
		}
		cout << v[i];
		if(i==q){
			cout << "]";
		}
	}
	cout << endl;
	return 0;
}

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

int main(){
  string s;
  cin>>s;
  int scount=0,ans=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='S')++scount;
    else if(scount>0){
      scount--;
      ans+=2;
    }
  }
  cout<<s.size()-ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <map>
using namespace std;
int main(void){
    int N;
    cin >> N;
    
    map<string, int> usedWord;
    string pre, nxt, ans = "Yes";
    
    cin >> pre;
    usedWord[pre] = 1;
    for ( int i = 0; i < N-1; i++ ) {
        cin >> nxt;
        if ( pre[pre.size()-1] != nxt[0] || usedWord[nxt] > 0) {
            ans = "No";
            break;
        }
        usedWord[nxt] = 1;
        pre = nxt;
    }
    cout << ans << endl;
}


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

using namespace std;

int main() {
	
	int pasta[3], juice[2];

	while (cin >> pasta[0]) {

		cin >> pasta[1] >> pasta[2] >> juice[0] >> juice[1];
		sort(pasta, pasta + 3);
		sort(juice, juice + 2);

		cout << pasta[0] + juice[0] - 50 << "\n";

	}

	return 0;

}


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

int main() {
    struct UnionFind {
        vector<int> par, s;
    
        UnionFind(int n) : par(n), s(n, 1) {
            for(int i = 0; i < n; i++) par[i] = i;
        }
    
        int root(int n) {
            return par[n] == n ? n : root(par[n]);
        }
    
        void unite(int n, int m) {
            n = root(n);
            m = root(m);
            if (n == m) return;
            if (s[n] < s[m]) swap(n, m);
            s[n] += s[m];
            par[m] = n;
        }
    
        int size(int n) {
            return s[root(n)];
        }
    
        bool same(int n, int m) {
            return root(n) == root(m);
        }
    };
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind can(n);
    vector<int> friends(n);
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b, a--, b--;
        can.unite(a, b);
        friends[a]++, friends[b]++;
    }
    vector<int> block(n);
    for (int i = 0; i < k; i++){
        int c, d;
        cin >> c >> d, c--, d--;
        if(can.same(c, d)) block[c]++, block[d]++;
    }
    for (int i = 0; i < n; i++)
    {
        cout << (i == 0 ? "" : " ") << can.size(i) - friends[i] - block[i] - 1;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2432
r=lambda x:p[x]>=0and r(p[x])or x
(n,m,k),*t=[map(int,t.split())for t in open(0)]
p,s=[-1]*-~n,[-1]*-~n
for a,b in t[:m]:
  x,y=r(a),r(b)
  if x!=y:
    if x>y:x,y=y,x
    p[x]+=p[y]
    p[y]=x
  s[a]-=1
  s[b]-=1
for i in range(n+1):s[i]-=p[r(i)]
for c,d in t[m:]:
  if r(c)==r(d):
    s[c]-=1
    s[d]-=1
print(*s[1:])

Measured memory_bytes: 97624
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}





int main() {
    int D;
    cin >> D;
    vector<int>c(26);
    rep(i,26) cin >> c[i];
    vector<vector<ll>>s(D,vector<ll>(26));
    rep(i,D) {
        rep(j,26) cin >> s[i][j];
    }
    vector<ll>last(26);
    ll score = 0;
    ll tmp = 0;
    vector<ll>ans;
    ll init_score = 0;
    rep(i,D) {
        ll contest = -1;
        for(int t = 1;t<=26;t++) {
            score += s[i][t-1];
            last[t-1] = i+1;
            rep(j,26) {
                score -= c[j]*((i+1)- last[j]);
                if(tmp<=score) {
                    tmp = score;
                    contest = t;
                }
            }
            score = init_score;
        }
        ans.push_back(contest);
        init_score = tmp;
        score = init_score;
    }
    rep(i,D) cout << ans[i] << endl;
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 2e5+1;
int x[N], n, dp[N];
vector <int> a[N];
stack <int> memo[N];

struct SegmentTree{
#define lc i * 2
#define rc i * 2 + 1
#define m (l + r) / 2

  int mx[4 * N];

  void Update(int u, int val, int i = 1, int l = 1, int r = n){
    if (l == r){
      mx[i] = val;
      return;
    }
    if (u <= m) Update(u, val, lc, l, m); 
    else Update(u, val, rc, m + 1, r);
    mx[i] = max(mx[lc], mx[rc]);  
  }

  int Get(int u, int v, int i = 1, int l = 1, int r = n){
    if (u > v) return 0;
    if (v < l || r < u) return 0;
    if (u <= l && r <= v) return mx[i];
    return max(Get(u, v, lc, l, m), Get(u, v, rc, m + 1, r));  
  }

#undef lc
#undef rc
#undef m
} seg;


void dfs(int p, int u){
  for (int v : a[u]){
    if (v == p) continue;
    int pre = memo[x[v]].top();
    memo[x[v]].push(seg.Get(1, x[v] - 1) + 1);
    memo[x[v]].top() = max(pre, memo[x[v]].top());
    seg.Update(x[v], memo[x[v]].top());
    dp[v] = max(dp[u], memo[x[v]].top()); dfs(u, v);
    memo[x[v]].pop(); seg.Update(x[v], memo[x[v]].top());
  }   
}


void compress(){
  set <int> S;
  for (int i = 1; i <= n; i++) S.insert(x[i]);
  vector <int> F(all(S));
  for (int i = 1; i <= n; i++) x[i] = lower_bound(all(F), x[i]) - F.begin() + 1;
}

int main()
{
  fastio;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> x[i];
  compress();
  for (int i = 1; i <= n; i++) memo[x[i]].push(0);
  for (int i = 1; i < n; i++){
    int u, v; cin >> u >> v;
    a[u].push_back(v); a[v].push_back(u);
  }
  dp[1] = 1; memo[x[1]].push(1);
  seg.Update(x[1], 1);  dfs(0, 1);
  for (int i = 1; i <= n; i++) cout << dp[i]  << '\n';
  return 0;
}


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

class P
{
    static void Main()
    {
        Console.ReadLine();
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int oddcount = a.Count(x => x % 2 == 1);
        if (oddcount % 2 == 0)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

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

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

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

    long long ans = 0;
    for(int i = 1; i < n; i++){
        long long c = (A[i] - A[i - 1]) * a;
        long long d = b;
        ans += min(c, d);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3936
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main( )
{
    int cnt=0;
    int l,w,n;
    cin>>l>>w>>n;
    for(int i=l;i<=w;i++)
    {
        if(i%n==0) ++cnt;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3588
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);

    let mut count = 0;

    // 範囲 x..y は h 桁の整数全体
    let mut h = 1;
    let mut x = 1;
    let mut y = 10;

    while x <= N {
        if h % 2 == 1 {
            count += min(y, N + 1) - x;
        }

        x *= 10;
        y *= 10;
        h += 1;
    }

    println!("{}", count)
}


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

char N[55][55],M[55][55];

bool same(int row,int col,int m)
{
	for(int i=1;i<=m;i++)
		for(int j=1;j<=m;j++)
			if(M[i][j]!=N[i+row-1][j+col-1])
				return 0;
	return 1;
}

int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>N[i][j];
	for(int i=1;i<=m;i++)
		for(int j=1;j<=m;j++)
			cin>>M[i][j];

	for(int i=1;i<=n-m+1;i++)
		for(int j=1;j<=n-m+1;j++)
			if(same(i,j,m))
			{
				printf("Yes\n");
				return 0;
			}

	printf("No\n");
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(M):
    L, R, D = map(int, input().split())
    L -= 1
    R -= 1
    G[L].append((R, D))
    G[R].append((L, -D))

visited = [False] * N
dist = [float('inf')] * N
for i in range(N):
    if not visited[i]:
        dist[i] = 0
        stack = [i]
        while stack:
            v = stack.pop()
            visited[v] = True
            for u, d in G[v]:
                if dist[u] == float('inf'):
                    dist[u] = dist[v] + d
                elif dist[u] != dist[v] + d:
                    print('No')
                    exit()
                if not visited[u]:
                    stack.append(u)
print('Yes')


Measured memory_bytes: 80288
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define clr(s, x) memset(s, x, sizeof(s))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
inline int read(){int r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll readll(){ll r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
inline ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const double eps = 1e-8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 1e6+100;
const int MAXM = 1e5;
int ind[5];int a[3],b[3];
int main(){
	for(int i=0;i<3;i++){
		cin>>a[i]>>b[i];
		ind[a[i]]++;ind[b[i]]++;
	}
	int ans1=0;
	int ans2=0;
	for(int i=1;i<=4;i++){
		if(ind[i]==2) ans1++;
		if(ind[i]==1) ans2++;
	}
	if(ans1==ans2&&ans1==2) puts("YES");
	else puts("NO");
	return 0;
}



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

int main() {
  int N, X;
  cin >> N >> X;
  vector <int> l(N);
  for (int i = 0; i < N; i++) cin >> l.at(i);
  
  int ans = 1;
  int total = 0;
  for (int i = 0; i < N; i++){
    total += l.at(i);
    if (total <= X) ans++;
  }
  cout << ans << endl;
}

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

while True:
    alpha = int(n % 26)
    if alpha == 0:
     result += "z"
     n -= 1
    else:
     result += chr(alpha + 96)
    if n/26 < 1:
        break
    n /= 26
rslt = result[::-1]
print(rslt)



Measured memory_bytes: 9076
require 'prime'

N = gets.to_i

factors = N.prime_division

S = {}
S[0] = 0

1.upto(N) do |i|
  s = S[i] = S[i-1] + i

  break if s > N
end

T = S.invert

c = 0

factors.each do |(_, n)|
  j = n

  while T[j].nil?
    j -= 1
  end

  c += T[j]
end

p c


Measured memory_bytes: 113580
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Y = sc.nextInt();

        for (int i = 0 ; i <= N ; i++ ) {
            for (int j = 0; j <= N ; j++ ) {
                if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y && N - i - j >= 0) {
                    System.out.println(i + " " + j + " " + (N - i - j));
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }

}

Measured memory_bytes: 22996
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.nextLine());
        String[] a1 = scan.nextLine().split(" ");
        String[] a2 = scan.nextLine().split(" ");

        int max = 0;
        for(int i=0; i<n; i++){
            int cnt = 0;
            for(int j=0; j<=i; j++){
                cnt += Integer.parseInt(a1[j]);
            }
            for(int j=i; j<n; j++){
                cnt += Integer.parseInt(a2[j]);
            }
            if(cnt > max) max = cnt;
        }

        System.out.println(max);

        scan.close();
    
    }

}

Measured memory_bytes: 24020
#include <stdio.h>
#include <string.h>

int main(){
  char s[11], t[11], u[11];
  int i, a, b;
  scanf("%s",s);
  scanf("%s",t);
  scanf("%d %d",&a,&b);
  scanf("%s",u);
  if(strcmp(s,u)==0) printf("%d %d",a-1,b);
  else if(strcmp(t,u)==0) printf("%d %d",a,b-1);
  else printf("%d %d",a,b);
}
  

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b,x;
    cin>>a>>b>>x;
    if(x>=a&&x<=a+b)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}

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

int main(){
  int n;
  int count=0;
  cin >> n;
  vector<int> h(n);
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  for(int i=1;i<n;i++){
    for(int j=0;j<i;j++){
      if(h[i]<h[j]){
       break;
      }else{
        if(i-1==j){
          count++;
        }
      }
    }
  }
  cout << count+1 << endl;
}

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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

const int MAX_H = 100, MAX_W = 100;
const int MAX_N = MAX_H*MAX_W;
int h,w,n;
int a[MAX_N];
int c[MAX_H][MAX_W];

int main()
{
  cin >> h >> w >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int k = 0;
  for (int i = 0; i < h; i++) {
    if (i % 2 == 0) {
      for (int j = 0; j < w; j++) {
        if (a[k] == 0) k++;
        c[i][j] = k+1;
        a[k]--;
      }
    } else {
      for (int j = w-1; j >= 0; j--) {
        if (a[k] == 0) k++;
        c[i][j] = k+1;
        a[k]--;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++)
      cout << c[i][j] << (j+1==w?'\n':' ');
  }

  return 0;
}


Measured memory_bytes: 384
/*
*
*Problem Link : https://atcoder.jp/contests/dp/tasks/dp_n
*Platform: atcoder
*Status: correct
*Author: Mayukh Chakrabarti
*
*/

#include<bits/stdc++.h>
#define speed ios_base::sync_with_stdio(false)
#define boost cin.tie(NULL)
#define booster cout.tie(NULL)
#define endl "\n"
typedef long long int ll;

#define F(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n) for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n) for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n) for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;

using namespace std;


const int ma = 500;
const ll INF = 1e18L + 5; // 10^18+5
ll dp[ma][ma];

ll sum(vector<int>& a, int Left, int Right) {
    ll sum = 0;
    for(int i = Left; i <= Right; ++i) {
        sum += a[i];
    }
    return sum;
};

int main() {
	//speed;boost;
	
    int n;
    cin>>n;
    vector<int> a(n);
    
    
    F(a,n); //taking array inputs
    
    
    for(int i = n-1; i >= 0; i--) {
        for(int j = i; j < n ; j++) {
            if(i == j) {
                dp[i][j] = 0;
            }
            else {
                dp[i][j] = INF;
                ll s = sum(a, i, j);
                for(int k = i; k <= j-1; k++) {
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + s);
                }
            }
        }
    }
    
    cout<<dp[0][n-1];
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			string[] s = Console.ReadLine().Split(' ');
			int[] S = new int[n];
			for (int i = 0; i < n; i++)
			{
				S[i] = int.Parse(s[i]);
			}
			int q = int.Parse(Console.ReadLine());
			string[] t = Console.ReadLine().Split(' ');
			int[] T = new int[q];
			for (int i = 0; i < q; i++)
			{
				T[i] = int.Parse(t[i]);
			}
			int count = 0;
			int now;
			int first, last;
			for (int j = 0; j < q; j++)
			{
				first = 0;
				last = n - 1;
				while (first != last && first + 1 != last)
				{
					now = (last + first) / 2;

					if (S[now] == T[j] || S[first] == T[j] || S[last] == T[j])
					{
						count++;
						break;
					}
					if (S[now] > T[j])
					{
						last = now;
					}
					else if (S[now] < T[j])
					{
						first = now;
					}

				}
			}
			Console.WriteLine(count);
		}
	}
}

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

int main(){
  string S, a;
  cin >> S;
  int m = 0, count;
  for(int i = 0; i < S.size(); i++){
    count = 0;
    for(int j = i; j < S.size(); j++){
      if(S.at(j) == 'A' || S.at(j) == 'C' || S.at(j) == 'G' || S.at(j) == 'T'){
      count++;
      }
      else if(count >= 1) break;
    }
    m = max(count, m);
  }
  cout << m << endl;
}


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


int main()
{
    string str;
    cin>> str;
    string result;
    char temp = str[str.size()-1];

    if(temp == 'e' || temp !='s' ) result = string(str) + 's';
    else  result = string(str) + "es";

    cout<<result;
}


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

P = [0]
p = 1
for i in range(10**3):
    P.append(P[-1] + p)
    p += 1

i = 1
while P[i] < n:
    i += 1
if P[i] > n:
    print("No")
else:
    print("Yes")
    m = i+1
    S = [[] for i in range(m)]
    for i in range(m):
        s = 1 if i==0 else 1+P[i-1]
        for j in range(m-1):
            S[i].append(s)
            if j < i-1:
                s += 1
            elif j == i-1:
                s += i+1
            else:
                s += j+1
    print(m)
    for i in range(m):
        print(m-1, " ".join([str(j) for j in S[i]]))

# print(S)

Measured memory_bytes: 44252
let inp = readLine()!.split(separator: " ").map { Int($0)! }

let N = inp[0]
let X = inp[1]

let L = readLine()!.split(separator: " ").map { Int($0)! }

var current = 0

var d = 0
var i = 0
while i < L.count {
  if d + L[i] > X {
    break
  }
  d += L[i]
  i += 1
}
print(i + 1)

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

int main(int argc, const char * argv[]) {
    string s;
    string a, b;
    
    int ans;
    
    ans = -1;
    
    cin >> s;
    for (int i = 0; ans==-1; i++) {
        s.pop_back();
        if (s.size() % 2 == 0) {
            //初期化
            a.clear();
            b.clear();
            
            a = s.substr(0, s.size()/2);
            b = s.substr(s.size()/2, s.size()/2);

            if (a == b) {
                ans = s.size();
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
import collections
import bisect
n,m=map(int,input().split())
p=[[int(j) for j in input().split()] for i in range(m)]
a=collections.defaultdict(list)
for x,y in sorted(p):
    a[x]+=[y]
for x,y in p:
    z=bisect.bisect(a[x],y)
    print("%06d%06d"%(x,z))

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

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

void f(UnionFind &uf,int offset,int l){
	for(int i = 0 ; i < l / 2 ; i++)
		uf.unite(offset+i,offset+l-i-1);
}

int main(){
	int N,M;
	cin >> N >> M;
	vector<int> A,B;
	UnionFind uf(N);
	int od = 0;
	for(int i = 0 ; i < M ; i++){
		int x;
		cin >> x;
		A.push_back(x);
		od += x % 2;
	}
	if( od >= 3 ) {
		cout << "Impossible" << endl;
		return 0;
	}
	sort(A.begin(),A.end(),[&](int a,int b){
		return a % 2 > b % 2;
	});
	if( A.size() >= 3 and A[0] % 2 and A[1] % 2 and A[2] % 2 ){
		cout << "Impossible" << endl;
		return 0;
	}
	reverse(A.begin()+1,A.end());
	int o = 0;
	for(int i = 0 ; i < A.size() ; i++){
		f(uf,o,A[i]);
		o += A[i];
	}
	if( A.size() == 1 ){
		if( A[0] == 1 ){
			B.push_back(1);
		}else{
			B.push_back(A[0]-1);
			B.push_back(1);
		}
	}else{
		if( A[0] > 1 ){
			B.push_back(A[0]-1);
		}
		for(int i = 1 ; i+1 < A.size() ; i++){
			B.push_back(A[i]);
		}
		B.push_back(A.back() + 1);
		
	}
	int a = 0;
	o = 0;
	for(int i = 0 ; i < B.size() ; i++){
		// cout << B[i] << endl;
		a += B[i];
		// assert(B[i]);
		f(uf,o,B[i]);
		o += B[i];
	}
	// assert( a == N);
	for(int i = 0 ; i < N ; i++)
		assert(uf.root(0) == uf.root(i));
	
	for(int i = 0 ; i < A.size() ; i++)
		cout << A[i] <<  " ";
	cout << endl;
	cout << B.size() << endl;
	for(int i = 0 ; i < B.size() ; i++)
		cout << B[i] << " ";
	cout << endl;
	
}

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

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

	int n = S.length();
	for (int i = 0; i < n; i++) {
		string temp = S;
		S = temp.substr(1, n - 1) + temp.substr(0, 1);
		if (S == T) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using ll = long long;
int main()
{
    int N;
    std::cin >> N;
    std::vector<ll> a(N);
    for (int i = 0; i < N; i++) { std::cin >> a[i], a[i] += (i == 0 ? 0LL : a[i - 1]); }
    std::vector<std::vector<ll>> memo(N, std::vector<ll>(N + 1, -1));
    auto dp = [&](auto&& self, const int l, const int r) -> ll {
        if (r - l == 1) { return 0LL; }
        if (memo[l][r] != -1) { return memo[l][r]; }
        ll ans = 1LL << 60;
        for (int m = l + 1; m < r; m++) { ans = std::min(ans, self(self, l, m) + self(self, m, r)); }
        return memo[l][r] = ans + a[r - 1] - (l == 0 ? 0LL : a[l - 1]);
    };
    std::cout << dp(dp, 0, N) << std::endl;
    return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> v;
	v.reserve(n *= 2);
	for (int i = 0; i < n; ++i) {
		int l;
		cin >> l;
		v.push_back(l);
	}

	sort(v.begin(), v.end());
	int cnt = 0;
	for (int i = 0; i < n; i += 2) cnt += v[i];
	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readInt
  val a = StdIn.readLine.split(" ").map(_.toLong)

  val (odd, even, mlt4) = a./:(0,0,0)((cnt,i) => {
    val odd = if((i&1) == 1) 1 else 0
    val even = if((i&1) == 0) 1 else 0
    val mlt4 = if((i&3) == 0) 1 else 0
    (cnt._1+odd, cnt._2+even, cnt._3+mlt4)
  })

  val ans = if(odd == mlt4+1) {
    if(even == mlt4) "Yes"
    else "No"
  }
  else if(odd <= mlt4) "Yes" else "No"

  println(ans)
}

Measured memory_bytes: 42488
/**
*   @Author : MeGA
*   @InitTime :02/08/20 16:33:57
*   @Idea : 
*
*
*
*
*
*
*
**/
#include <bits/stdc++.h>
using namespace std;

int a[15][25];
int n,d;
bool is_cool(int idx1,int idx2){
   long long ret=0;
   for(int i=0;i<d;i++){
        ret+=pow(a[idx1][i]-a[idx2][i],2);
   }
   return ceil(sqrt(ret))==floor(sqrt(ret));
}
int main(){
#ifndef ONLINE_JUDGE
  // freopen("in","r",stdin);
  // freopen("out","w",stdout);
#endif

     ios::sync_with_stdio(false);
     cin.tie(0);
     cin>>n>>d;

     int ans=0;
     for(int i=0;i<n;i++){
     	for(int j=0;j<d;j++){
     		cin>>a[i][j];
     	}
     }
     for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if((is_cool(i,j))){
            	ans++;
            }
        }
     }
     cout<<ans<<endl;
}

Measured memory_bytes: 256