akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PB push_back
#define PPB pop_back
#define MP make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define loop(i,start,end) for(ll i=start; i<end; i++)
#define rloop(j,start,end) for(ll j=start-1; j>=end; j--)

int main()
{   
    IOS;

    ll n,W;
    cin>>n>>W;

    ll v[n+1],w[n+1],sumV=0;

    loop(i,1,n+1)
    {  
        cin>>w[i]>>v[i];
        sumV+=v[i];
    }

    ll dp[n+1][sumV+1],ans=0;

    loop(i,0,n+1)
        loop(j,0,sumV+1)
            dp[i][j]=INT_MAX;

    loop(i,0,n+1)
        dp[i][0]=0;

    // minimum weight needed with the items to a specified value
    loop(i,1,n+1)
    {
        loop(j,1,sumV+1)
        {
            if(v[i]<=j)
                dp[i][j]=min(dp[i-1][j],w[i]+dp[i-1][j-v[i]]);
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    
    loop(i,1,sumV+1)
        if(dp[n][i]<=W)
            ans=i;

    d1(ans);
}

Measured memory_bytes: 79104
#include <iostream>

using namespace std;
typedef long long ll;

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

int main(void)
{
    ll n,k,s, t;
    cin >> n >> k >> s;
    if(s == 1000000000) {
        t = s - 1;
    } else {
        t = s + 1;
    }
    REP(i, k) cout << s << " ";
    REP(i, n-k) cout << t << " ";
    cout << endl;
}


Measured memory_bytes: 1280
n =int(input())
a = list(map(int,input().split()))
s = sum(a)
x = [0]*1000001
for i in a:
    x[i] +=1

q = int(input())
for i in range(q):
    b,c = map(int,input().split())
    s -= b*x[b]
    s += c*x[b]
    x[c] += x[b]
    x[b] = 0
    print(s)

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

int K,N;
int A[100010];
int main(){
	cin >> N >> K;
	int id;
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	int ans = (N-1+K-2)/(K-1);
	if(K==N) cout << 1 << endl;
	else cout << ans << endl;
}

Measured memory_bytes: 640
# vim: set fileencoding=utf-8:


def main():
    N = raw_input()
    a = N[0] + N[0] + N[0]

    if N == a:
        print(N)
    elif int(N) > int(a):
        b = str(int(N[0]) + 1)
        b = b + b + b
        print(b)
    else:
        print(a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2568
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class ATenki {
public:
void solve(std::istream& cin, std::ostream& cout) {
    string S, T;
    cin >> S >> T;

    int ans = 0;
    for (int i = 0; i < 3; i++){
        if (S[i] == T[i]) ans++;
    }

    cout << ans << endl;
}
};

int main() {
	ATenki solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import heapq

from operator import itemgetter

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

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

info = [0] * m
for i in range(m):
    info[i] = list(map(int,input().split()))

info = sorted(info,key = itemgetter(1),reverse = True)
#print(a)

heapq.heapify(a)
#print(a)

d = 0
count = 0

for j in range(len(info)):
    for k in range(info[j][0]):
        if a[0] > info[j][1]:
            d = 1
            break
        else:
            heapq.heappushpop(a,info[j][1])
            count += 1
        if count >= n:
            d = 1
            break
    if d == 1:
        break

print(sum(a))

Measured memory_bytes: 33860
import Foundation

var N = readLine()!.split(separator: " ").map{Int($0)!}
let m = Int(readLine()!)!
for i in 1...m{
  if(N[0] >= N[1]){
    N[1] *= 2
  }else if(N[1] >= N[2]){
    N[2] *= 2
  }
}
if(N[0] < N[1] && N[1] < N[2]){
  print("Yes")
}else{
  print("No")
}

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

int group(int x) {
  switch(x) {
  case 1:
  case 3:
  case 5:
  case 7:
  case 8:
  case 10:
  case 12:
    return 1;
  case 4:
  case 6:
  case 9:
  case 11:
    return 2;
  case 2:
    return 3;
  default:
    return 0;
  }
}

int main() {
  int a, b;
  cin >> a >> b;
  if(group(a) == group(b)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
while (ln = gets.chomp) != "0 0"
  w,h = ln.split.map(&:to_i)
  lnb = Array.new(h).map{Array.new(w-1)}
  rob = Array.new(h-1).map{Array.new(w)}
  for i in 0..(h-1)
    lnb[i] = gets.split.map(&:to_i)
    rob[i] = gets.split.map(&:to_i) if i < h-1
  end
  
  @vis = Array.new(h).map{Array.new(w,0)}
  @vis[0][0] = 1
  @dpt = Array.new(h).map{Array.new(w,0)}
  @dpt[0][0] = 1
  @lns = [0]
  @ros = [0]
  id = 0
  @maxid = 0
  
  def extd(ln, ro, d)
    @lns.push(ln)
    @ros.push(ro)
    @vis[ln][ro] = 1
    @dpt[ln][ro] = d
    @maxid += 1
  end
  
  while id <= @maxid
    ln = @lns[id]
    ro = @ros[id]
    break if ln == h-1 && ro == w-1
    d = @dpt[ln][ro]
    extd(ln, ro-1, d+1) if ro > 0 && lnb[ln][ro-1] == 0 && @vis[ln][ro-1] == 0
    extd(ln, ro+1, d+1) if ro < w-1 && lnb[ln][ro] == 0 && @vis[ln][ro+1] == 0
    extd(ln-1, ro, d+1) if ln > 0 && rob[ln-1][ro] == 0 && @vis[ln-1][ro] == 0
    extd(ln+1, ro, d+1) if ln < h-1 && rob[ln][ro] == 0 && @vis[ln+1][ro] == 0
    id += 1
  end
  puts @dpt[h-1][w-1]
end


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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int up;
    int down;
    if(n % 2 == 0){
        up = n / 2;
        down = up - 1;
        if(s[up] != s[down]){
            cout << n / 2 << endl;
            return 0;
        }
    } else {
        up = n / 2;
        down = n / 2;
    }
    int moji = s[up];
    while(s[up] == moji && s[down] == moji){
        up++;
        down--;
        if(down < 0){
            break;
        }
    }
    cout << up << endl;
    return 0;
}

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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    if (A + B > C + D){
        cout << "Left\n";
    }
    else if (A + B < C + D){
        cout << "Right\n";
    }
    else{
        cout << "Balanced\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	int ans=INF;
	int cnt=0;
	cin >>s;
	int last=0;
	int at=0;
	for(char ter='a';ter<='z';ter++){
		last=-1;
		cnt=0;
		//clog << ter << endl;
		for(int i=0;i<s.size();i++){
			
			if(s[i]==ter){
				if(i==0){
					chmax(cnt,0);
				}else{
				chmax(cnt,i-last-1);
			//	clog << i - last - 1 << " ";
				}
			
				last=i;
			}
		}
		if(s[s.size()-1]!=ter){
		chmax(cnt,(int)s.size()-last-1);
		//clog<<s.size()-last-1<<" ";
		}
		//clog<<endl;
		chmin(ans,cnt);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using pq = priority_queue<int>;
template<class T>
using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int under = (1 << 31);
int upper = under - 1;
ll UNDER = (1LL << 63);
ll UPPER = UNDER - 1;
const int MOD = 1e9 + 7;
const long double pi = 3.141592653589793;
int main(){
	int a, b;
	cin >> a >> b;
	int now = 1;
	int ans = 0;
	while (1) {
		if (now >= b) {
			cout << ans << endl;
			return 0;
		}
		now--;
		now += a;
		ans++;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mxn(1e5 + 10), mxm(4e5 + 10);
const long long modl(998244353);
int nm, n, m, p, t, k, l, r;
int ans;
int a[mxn], b[mxn];
int fnd(int x) {
  return a[x] = x == a[x] ? x : fnd(a[x]);
}
int main() {
  ios_base::sync_with_stdio(false);
//  freopen("in.txt", "r", stdin);///////////////////////////
//  cin >> nm;
//  string s;
  while (cin >> n >> m) {
    for (int i = 1; i <= n; ++i) a[i] = i;
    ans = n - 1;
    while (m--) {
      cin >> p >> t;
      l = fnd(p);
      r = fnd(t);
      if (l != r) {
        --ans;
        a[l] = r;
      }
    }
    cout << ans;
    cout << endl;
  }
  return 0;
}
////////////////////////////////////////////////////////////////////////////////
//    if (t) cout << "YES";
//    else cout << "NO";


Measured memory_bytes: 4040
N = int(input())
a = []
for i in range(N):
    ai = int(input())
    a.append(ai)
cnt = 1
for i in range(N):
    cnt = a[cnt-1]
    if cnt == 1:
        print(-1)
        exit()
    elif cnt == 2:
        print(i+1)
        exit()
print(-1)

Measured memory_bytes: 7084
#include <algorithm> //STLͨ���㷨
#include <cmath> //������ѧ����
#include <cstdio> //��������/�������
#include <iostream> //����������/���
#include <cstring> //�ַ�������
#include <string> //�ַ�����
#include <ctime> //�������ʱ��ĺ���
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLλ������
#include <cstype> //�ַ�����
#include <cerrno> //���������
#include <complex> //������
#include <clocale> //���屾�ػ�����
#include <cstdlib> //������������ڴ���亯��
#include <deque> //STL˫�˶�������
#include <exception> //�쳣������
#include <fstream> //�ļ�����/���
#include <functional> //STL�������㺯��(���������)
#include <limits> //�����������������ֵ����
#include <list> //STL�����б�����
#include <map> //STLӳ������
#include <iomanip> //����������/���
#include <ios> //��������/���֧��
#include <iosfwd> //����/���ϵͳʹ�õ�ǰ������
#include <istream> //����������
#include <ostream> //���������
#include <queue> //STL��������
#include <set> //STL��������
#include <sstream> //�����ַ�������
#include <stack> //STL��ջ����
#include <stdexcept> //��׼�쳣��
#include <streambuf> //�ײ�����/���֧��
#include <utility> //STLͨ��ģ����
#include <vector> //STL��̬��������
#include <cwchar.h>//���ַ�����������/���
#include <cwctype.h> //���ַ�����*/

using namespace std;

int ans;

int max(int x,int y){return x>y?x:y;}

int min(int x,int y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
	if (iosig) x = -x;
}

char sr[10000000],z[20];int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
	while(z[++Z]=x%10+48,x/=10);
	while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}
int s1,s2,s3;
string s;

int main()
{
	int n;
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>s;
		int len=s.length();
		for (int i=1;i<len;i++)
			if (s[i-1]=='A'&&s[i]=='B') ans++;
		if (s[0]=='B'&&s[len-1]=='A') s3++;
		else
		if (s[0]=='B') s1++;
		else
		if (s[len-1]=='A') s2++;
	}
	
	if (s3)
	{
		ans+=s3-1;
		if (s1) s1--,ans++;
		if (s2) s2--,ans++;
	}
	cout<<ans+min(s1,s2);
	return 0;
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;

int main(void){
    IOS;
    int n; cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; ++i){
        if (i%3 != 0 && i%5 != 0) ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int H, W, N, ans;
  std::cin >> H >> W >> N;
  ans = H;
  vvi bl = vv(N, 2, 0, int);
  for(int i=0;i<N;i++) std::cin >> bl[i][1] >> bl[i][0];
  sort(bl.begin(), bl.end());
  int now = 0;
  for(int i=0;i<N;i++){
    if(bl[i][1]-bl[i][0]-now>0) ans = min(ans, bl[i][1]-1);
    else if(bl[i][1]-bl[i][0]==now) now++;
    //std::cout <<bl[i][0] << " " << bl[i][1] << " " << i+1 << " " << ans  << " " << now << '\n';
  }
  std::cout << ans << '\n';
  return 0;
}


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

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> ai(h);

  for(int i=0;i<h;i++){
    cin >> ai.at(i);
  }

  for(int j=0;j<w+2;j++) cout << '#';
  cout << endl;
  for(int i=0;i<h;i++) cout << '#' << ai.at(i) << '#' << endl;
  for(int j=0;j<w+2;j++) cout << '#';
  cout << endl;
}


Measured memory_bytes: 256
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll N, M;
    cin >> N >> M;
    priority_queue<ll> pq;
    for(ll i = 0; i < N; i++) {
        ll a;
        cin >> a;
        pq.push(a);
    }
    while(M--) {
        ll a = pq.top();
        pq.pop();
        pq.push(a / 2);
    }
    ll ans = 0;
    while(pq.size()) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

      
n,m,k=map(int,input().split())
A=UnionFind(n)
B=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  A.union(a,b)
  B[a].append(b)
  B[b].append(a)
C=[[] for i in range(n)]
for i in range(k):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  C[a].append(b)
  C[b].append(a)
ans=[0]*n
for i in range(n):
  ans[i]=A.size(i)
  a=0
  for j in range(len(B[i])):
    if A.same(i,B[i][j]):
      a=a+1
  b=0
  for j in range(len(C[i])):
    if A.same(i,C[i][j]):
      b=b+1
  ans[i]=ans[i]-a-b
for i in range(n):
  print(ans[i]-1,end=" ")
print()

Measured memory_bytes: 45240
#include<iostream>
using namespace std;
#define ll long long
int has[110];
int a[100010];
bool is[100010];
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		if (a[x] < a[y])is[x] = 1;
		else if (a[x] > a[y])is[y] = 1;
		else is[x] = 1, is[y] = 1;
	}int ans = 0;
	for (int i = 1; i <= n; i++)
		if (!is[i])ans++;
	cout << ans;
}

Measured memory_bytes: 4044
import java.util.*;

class Main{
    //ABC107C
    static final int DIV = 100000007;
    static final int MAX = 2000000000;

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] str = sc.next().toCharArray();
        int ans=0;
        for(int a = 0;a<10;a++){
            for(int b = 0;b<10;b++){
                for(int c = 0;c<10;c++){
                    int i,j,k;
                    for(i=0;i<n;i++){
                        if(str[i]==a+48)break;     
                    }                   
                    for(j=i+1;j<n;j++)if(str[j]==b+48){
                        break;
                    }
                    for(k=j+1;k<n;k++){
                        if(str[k]==c+48){
                            ans++;
                            break;
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22868
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
p = list(map(int, input().split()))
m = 2*n
ans = 0
for i in range(n):
    if m>p[i]:
        ans += 1
    m = min(m, p[i])
print(ans)

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

int main(void)
{
    int N;
    cin >> N;
    int d[N];
    rep(i, N)cin >> d[i];
    int ans = 0;
    rep(i,N){
        for (int j = i+1; j < N;j++){
            ans += d[i] * d[j];
        }
    }

    cout << ans;
    return (0);
}

Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

heapq.heapify(A)

BC = sorted(BC, key = lambda x : x[1], reverse=True)
for b, c in BC:
    for i in range(b):
        a = heapq.heappop(A)
        if a < c:
            heapq.heappush(A, c)
        else:
            heapq.heappush(A, a)
            break

print(sum(A))

Measured memory_bytes: 33784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<char>>s(55,vector<char>(55));
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin >> s[i][j];
        }
    }
    bool judge = true;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'&&s[i+1][j]!='#'&&s[i-1][j]!='#'&&s[i][j-1]!='#'&&s[i][j+1]!='#') judge=false;
        }
    }
    if(judge) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
  int  a, b, c, d, e, f;
  cin >> a >> b >> c >> d;
  e = a + b;
  f = c + d;
  if(e>f){
    cout << "Left" <<endl;
    }
  else if(e<f){
    cout << "Right" << endl;
  }
  else{
    cout << "Balanced" << endl;
  }
}  


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

using namespace std;

int main(){
	int a, b, tc; scanf("%d", &tc);
	int res = 0;
	while(tc--){
		scanf("%d %d", &a, &b);
		res += (b - a + 1);
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;

int N;
ll h[100005];
ll dp[100005];

ll solve(int n) {
	if(n==1) return 0;
	if(n==2) return abs(h[2]-h[1]);
	if(dp[n] < 0) dp[n] = min( solve(n-1)+abs(h[n]-h[n-1]), solve(n-2)+abs(h[n]-h[n-2]) );
	return dp[n];
}

int main() {
	
	cin >> N;
	for(int i=1;i<=N;++i) cin >> h[i];
	for(int i=1;i<=N;++i) dp[i] = -1;
	
	cout << solve(N) << endl;
	
	return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
int main(){
   int N;
   char S[N];
   int count = 0;
   scanf("%d", &N);
   scanf("%s", S);
   for(int i = 0; i < N-2; i++) {
      if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') {
         count++;
      }
   }
   printf("%d\n", count);
   return 0;
}


Measured memory_bytes: 1708
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int q, h, s, d, n;

int64_t solve(int64_t s, int64_t d) {
    if (s * 2 < d) {
        return n * s;
    } else {
        return n % 2 == 0 ? n / 2 * d : n / 2 * d + s;
    }
}

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    int64_t result;
    cin >> q >> h >> s >> d >> n;

    int q_litter = q * 4, h_litter = h * 2;
    if (q_litter < h_litter && q_litter < s) {
        result = solve(q_litter, d);
    } else if (h_litter < q_litter && h_litter < s) {
        result = solve(h_litter, d);
    } else {
        result = solve(s, d);
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vct vector<ll>
#define umap unordered_map<ll,ll>
#define mpp map<ll,ll>
#define stt set<ll>
#define pir pair<ll,ll>
#define vpp vector<pair<ll,ll> >
#define pb push_back
ll poww(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
void prt(vector<ll> v)
{
    for(ll i=0;i<v.size();i++)cout<<v[i]<<" ";
    cout<<"\n";
}
vct siev(ll n)
{
    vct ans;ll ar[n+1];
    memset(ar,-1,sizeof(ar));ar[0]=0;ar[1]=0;
    for(ll i=2;i<=n;i++)
    {if(ar[i]==-1){ans.push_back(i);ar[i]=1;for(ll j=2*i;j<=n;j=j+i)ar[j]=0;}}
    return ans;
}
ll isprime(ll n)
{
    if(n==1||n==0)return 0;
    for(ll i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll etf(ll n) 
{
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)n /= i;
            result -= result / i;
        }
    }
    if(n > 1)result -= result / n;
    return result;
}
vct divsors(ll n)
{
    vct ans;//ans.push_back(1);
    for(ll i=2;i<=sqrt(n);i++)
    {if(n%i==0){ans.push_back(i);if(i!=(n/i))ans.push_back(n/i);}}
    sort(ans.begin(),ans.end());
    return ans;
}
ll cnd(ll n){ll cnt=0;while(n){cnt++;n=n/10;}return cnt;}
ll fc(ll n){ll rs=1;for(ll i=2;i<=n;i++)rs*=i;return rs;}
void prn(ll n){cout<<n<<"\n";}
void pr(ll n){cout<<n<<" ";}
void prs(string n){cout<<n<<"\n";}
ll t,m,n,d,q,p,k;
ll t1,t2;
ll mod=1000000007;
double dist(double a,double b,double c,double d)
{
    double ss=((c-a)*(c-a));
    ss+=((d-b)*(d-b));
    ss=sqrt(ss);
    return ss;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    vector<pair<double,double> > vp;
    for(ll i=0;i<n;i++)
    {
        cin>>t1>>t2;
        vp.pb({1.0*t1,1.0*t2});
    }
    int ar[n];
    for(ll i=0;i<n;i++)ar[i]=i+1;
    ll cn=0;
    double su=0.0;
    do { 
        
        for(ll i=0;i<(n-1);i++)
        {
            su+=dist(vp[ar[i]-1].first,vp[ar[i]-1].second,vp[ar[i+1]-1].first,vp[ar[i+1]-1].second);
        }
        
        cn++;
    } while (next_permutation(ar, ar + n)); 
  
  su=(su/(1.0*cn));
  cout<<fixed<<showpoint<<setprecision(10)<<su<<"\n";
}

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

int main(){
    long long x,k,d;
    cin>>x>>k>>d;
    if(x<0)x=-x;
    long long ans;
    long long z=x/d;
    if(z>k)ans=x-k*d;
    else{
        k-=z;
        x=x%d;
        if(k%2==0)ans=x;
        else ans=d-x;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3620
/*
  Vivek Rathi
  CSE 2nd Year
  MNNIT
*/
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define present(c,x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 1e18
#define flush fflush(stdout);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}
//-------------------------------Template--Above------------------------------------------------


int main()
{
	boost
	string s,t;
	cin>>s>>t;
	ll has[256]={0},has2[256]={0};
	vector<ll> v[256];
	for(ll i=0;i<s.length();i++)
	{
		v[s[i]].pb(i);
	}
	for(ll i=0;i<t.length();i++)
	{
		has2[t[i]]++;
	}
	ll cur=0,prev=-1;
	for(ll i=0;i<t.length();i++)
	{
		if(v[t[i]].size()==0)
		{
			cout<<-1<<endl;
			return 0;
		}
		else
		{
			ll low=0,high=v[t[i]].size()-1,ans=-1;
			while(low<=high)
			{
				ll mid=(low+high)/2;
				if(v[t[i]][mid]>prev)
				{
					ans=v[t[i]][mid];
					high=mid-1;
				}
				else
					low=mid+1;
			}
			if(ans==-1)
			{
				//debug2(ans,prev);
				cur+=s.length()-1-prev;
				cur+=v[t[i]][0]+1;
				prev=v[t[i]][0];
			}
			else
			{
				//debug2(ans,prev);
				cur+=ans-prev;
				prev=ans;
			}
			//debug1(cur);
		}
	}
	cout<<cur<<endl;
	return 0;
}


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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
const int MOD = 1e9 + 7;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main() {
    int h, w;
    cin >> h >> w;
    rep(i,h){
        string s; cin >> s;
        cout << s << '\n' << s << endl;
    }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
/*                   وتزودوا فإن خير الزاد التقوى                    */
/*       وما تدري نفس ماذا تکسب غدا وما تدري نفس باي ارض تموت      */
#include <bits/stdc++.h>
#include<unordered_map>
#include<iomanip>
#include<fstream>
using namespace std;
#include<iostream>
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define dll double
#define PI acos(-1)
#define watch(x) cout<<#x<<" = { "<<x<<" }\n"
#define sz(n) n.size()
#define M_Sayed fast() 
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define RT(v) return cout<<v,0
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
const double EPS = (1e-7);
ll Ceil(ll x, ll y) { return (x + y - 1) / y; }
ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }
ll power(ll x, ll y, ll mod) {
	if (y == 0) return 1;
	if (y == 1) return x % mod;
	ll r = power(x, y >> 1, mod);
	return (((r * r) % mod) * power(x, y & 1, mod)) % mod;
}
void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
int main()
{
	M_Sayed;
	ll n, a, b;
	cin >> a >> b;
	for (ll i = 1 ;; i++) {
		if (i * .08 > a+1) {
			RT(-1);
		}
		ll k = (i * 8)/100;
		ll c= (i )/10;
		if (c ==b&&k==a)RT(i);
	}
	
	
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, C;
	cin >> N >> C;
	vector<vector<int>> D(C, vector<int>(C));
	rep(i,C)rep(j,C) cin >> D[i][j];
	vector<vector<int>> c(N, vector<int>(N));
	rep(i,N)rep(j,N){
		cin >> c[i][j];
		c[i][j]--;
	}
	vector<vector<int>> cost(3, vector<int>(C, 0));
	rep(k,3){
		rep(l,C){
			int tmp = 0;
			rep(i,N)rep(j,N){
				if((i+j)%3 != k) continue;
				tmp += D[c[i][j]][l];
			}
			cost[k][l] = tmp;
		}
	}
	int ans = 1e9;
	rep(i,C)rep(j,C)rep(k,C){
		if(i == j || j == k || k == i) continue;
		int cmp = cost[0][i] + cost[1][j] + cost[2][k];
		chmin(ans, cmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    int r=0;
    int l=0;
    for(int i=0;i<a;i++){
        int c,d;scanf("%d%d",&c,&d);
        b=b+c-d;
        r=max(r,b);
        l=min(l,b);
    }
    if(l<0)printf("0\n");
    else printf("%d\n",r);
}


Measured memory_bytes: 2688
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    ArrayList<Long> xlist = new ArrayList<Long>();
    ArrayList<Long> ylist = new ArrayList<Long>();
    long[][] co = new long[n][2];
    for(int i = 0; i < n; i++) {
      long x = sc.nextLong();
      long y = sc.nextLong();
      xlist.add(x);
      ylist.add(y);
      co[i][0] = x;
      co[i][1] = y;
    }
    Collections.sort(xlist);
    Collections.sort(ylist);
    long ans = Long.MAX_VALUE;
    for(int i = 0; i < n; i++) {
      for(int j = i + 1; j < n; j++) {
        for(int s = 0; s < n; s++) {
          for(int l = s + 1; l < n; l++) {
            long xmin = xlist.get(i);
            long xmax = xlist.get(j);
            long ymin = ylist.get(s);
            long ymax = ylist.get(l);
            int count = 0;
            for(int m = 0; m < n; m++) {
              if((co[m][0] >= xmin) && (co[m][0] <= xmax) && (co[m][1] >= ymin) && (co[m][1] <= ymax)) count++;
            }
            if(count >= k) ans = Math.min(ans, (xmax - xmin) * (ymax - ymin));
          }
        }
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 25368
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

a,b = MAP()
c = [str(a) * b, str(b) * a]
c.sort()
print(c[0])

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

int main(void){
    int h, w;
    char image[100][100];
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> image[i][j];
        }
    }
    for (int i = 0; i < h * 2;i++) {
        for (int j = 0; j < w; j++) {
            cout << image[i / 2][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val ls = in(0).split(' ').map(_.toLong)
  val N = ls(0)
  val A = ls(1)
  val B = ls(2)

  val AB = A + B
  //println(AB)
  val res = N%AB
  //println(res)
  val mod = Math.min(res, A)
  //println(mod)
  val ret = N/AB*A + mod
  println(ret)
}

Measured memory_bytes: 27300
#include <iostream>
#define int long long
using namespace std;

const int mod = 1000000007;
int n;
int dp[1000010];	//dp[i]  = (n=i)のときの答え
int rdp[1000010];	//rdp[i] = dp[0] + … + dp[i - 1]

//[l, r)
int getSum(int l, int r) {
	if (l >= 0) {
		return rdp[r] - rdp[l];
	}
	return rdp[r] - l;
}

signed main() {
	int i, j;
	
	cin >> n;
	
	dp[0] = 1; rdp[1] = dp[0];
	dp[1] = n; rdp[2] = dp[0] + dp[1];
	
	for (i = 2; i <= n; i++) {
		int res = getSum(i - n - 1, i) + mod - getSum(i - 2, i - 1) + (n - 1) * (n - 1);
		dp[i] = res % mod;
		rdp[i + 1] = (rdp[i] + dp[i]) % mod;
	}
	
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 15872
/*#include<iostream>
#include<cstdio>
#include<algorithm>
*/
#include<bits/stdc++.h>
using namespace std;
#define max 200006

int main()
{
    int n,arr[max],i;
    scanf("%d", &n);
    for(i=0; i<n; i++)
    {
        scanf("%d", &arr[i]);
    }

    int ans=__gcd(arr[0],arr[1]);
    for(i=2; i<n; ++i)
    {
        ans=__gcd(ans,arr[i]);
        if(ans==1)
            break;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 4124
def main():
    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, x):
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)
            if x == y:
                return
            if self.parents[x] > self.parents[y]:
                x, y = y, x
            self.parents[x] += self.parents[y]
            self.parents[y] = x

        def size(self, x):
            return -self.parents[self.find(x)]

        def same(self, x, y):
            return self.find(x) == self.find(y)

        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def other_members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root and i != x]

        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]

        def __str__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    import sys
    def input():
        return sys.stdin.readline().rstrip()
    n, m, k = list(map(int, input().split()))
    uf = UnionFind(n)
    counts = [0] * n
    for _ in range(m):
        a, b = list(map(lambda x: int(x) - 1, input().split()))
        uf.union(a, b)
        counts[a] += 1
        counts[b] += 1
    for _ in range(k):
        c, d = list(map(lambda x: int(x) - 1, input().split()))
        if uf.same(c, d):
            counts[c] += 1
            counts[d] += 1
    print(' '.join([str(uf.size(i) - counts[i] - 1) for i in range(n)]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 21312
#include<cstdio>
#include<algorithm>
using namespace std;

int n, m, a[1000], b[1000];

int main() {
  scanf("%d%d", &n, &m);
  int mina = 100000;
  int sum = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a[i], &b[i]);
    mina = min(mina, a[i]);
    if (a[i] < n) sum += n - a[i];
  }
  if (mina < n) sum -= n - mina;
  printf("%d\n", sum);
}



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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

ll mod = 1000000007;

ll modpow(ll a,ll n,ll mod){
  ll res=1;
  while(n>0){
    if(n & 1)res=res*a%mod;
    a =a*a%mod;
    n>>=1;
  }
  return res;
}

int main(){
  ll n,k;
  ll ans=1;
  ll c1=1;
  ll c2=1;
  cin >> n >> k;
  
  k= min(k,n-1);

  reps(i,k){
    c1 = (c1*(n-i+1))%mod;
    c1 = (c1*modpow(i,mod-2,mod))%mod;
    c2 = (c2*(n-i))%mod;
    c2 = (c2*modpow(i,mod-2,mod))%mod;
    ans += (c1*c2)%mod;
    ans %= mod;
  }
  cout << ans;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()

total = 0
for i in range(1, len(N) + 1, 2):
	if i == len(N):
		total += int(N) - 10**(i-1) + 1
	else:
		total += 9*10**(i-1)

print(total)

Measured memory_bytes: 61036
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){

  string X,Y; cin >> X >> Y;
  vector<vector<int>> dp(1010,vector<int>(1010,INF));
  dp[0][0]=0;
  for(int i=-1;i<(int)X.size();i++) for(int j=-1;j<(int)Y.size();j++){
    if(i==-1 && j==-1) continue;
    if(i>=0 && j>=0){
      if(X[i]==Y[j]){
        chmin(dp[i+1][j+1],dp[i][j]);
      }
      else{
        chmin(dp[i+1][j+1],dp[i][j]+1);
      }
    }
    if(i>=0) chmin(dp[i+1][j+1],dp[i][j+1]+1);
    if(j>=0) chmin(dp[i+1][j+1],dp[i+1][j]+1);
  }
  cout << dp[X.size()][Y.size()] << endl;

  return 0;
}



Measured memory_bytes: 10872
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
ll MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    vector<vector<ll>> dp(S.size() + 1, vector<ll>(13, 0));
    dp[0][0] = 1;

    int ketaMod = 1;
    for (int i = S.size() - 1; i >= 0; i--) {
        int keta = S.size() - i;

        if (S[i] == '?') {
            for (int ki = 0; ki <= 12; ki++) {
                for (int k = 0; k <= 9; k++) {
                    dp[keta][(k * ketaMod + ki) % 13] += dp[keta - 1][ki];
                    dp[keta][(k * ketaMod + ki) % 13] %= MOD;
                }
            }
        }

        else {
            int N = S[i] - '0';
            for (int ki = 0; ki <= 12; ki++) {
                dp[keta][(N * ketaMod + ki) % 13] += dp[keta - 1][ki];
                dp[keta][(N * ketaMod + ki) % 13] %= MOD;
            }
        }
        ketaMod *= 10;
        ketaMod %= 13;
    }
    cout << dp[S.size()][5] << endl;
}

Measured memory_bytes: 13696
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <cmath>
using namespace std;

int main()
{   long long n,i;
    cin>>n;
    long long h[n],cost[n];
    for(i=0;i<n;i++){cin>>h[i];}
    cost[0]=0;
    cost[1]=abs(h[1]-h[0]);
    for(i=2;i<n;i++){
        //cost[i]=1000000007;
        cost[i]=min(cost[i-2]+abs(h[i]-h[i-2]),cost[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<cost[n-1];

    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int fa[100010],cnt[100010];
inline int findfa(int x)
{
	if(fa[x]!=x)fa[x]=findfa(fa[x]);
	return fa[x];
}
struct node
{
	int x,y,next;
}a[200010];int len,last[100010];
inline void ins(int x,int y)
{
	len++;
	a[len].x=x;a[len].y=y;
	a[len].next=last[x];last[x]=len;
}
inline void dfs(int x,int f)
{
	for(int k=last[x];k;k=a[k].next)
	{
		int y=a[k].y;
		if(y==f)continue;
		dfs(y,x);
		if(cnt[y]==1)pr1(y),pr2(x);
		else {pr1(x),pr2(y);cnt[x]^=1;}
	}
}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read(),m=read();
    if(m%2==1){pr2(-1);return 0;}
    for(int i=1;i<=n;i++)fa[i]=i;
    for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		int fx=findfa(x),fy=findfa(y);
		if(fx!=fy){fa[fy]=fx;ins(x,y),ins(y,x);}
		else {cnt[x]^=1;pr1(x),pr2(y);}
	}dfs(1,0);
    return 0;
}

Measured memory_bytes: 19456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll A[100005];
int main() {
    init();
    ll N,M;
    ll sum = 0;
    cin >> N >> M;
    rep(i, M){
        ll a;
        cin >> a;
        sum += a;
    }

    cout << (N - sum >= 0 ? N - sum : -1) << endl;


}

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

int main() {
int n,d;
cin>>d>>n;
if(n==100)
 n++;
int ans=1;
 //cout<<"hi"<<endl;
   //
         ans=pow(100,d)*n;
         //cout<<ans<<endl;
     
 
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<set>
#include<cstring>
using namespace std;
typedef long long ll;
int T;
long long int n,m,r;
long long int mark[10];
long long int num[310][310];
const long long int inf=1e9;
int main() {

    //cout<<0x3f3f3f3f<<endl;
    cin>>n>>m>>r;
    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)
        num[i][j]=inf;
    for(int i=0;i<r;i++)
        cin>>mark[i];
    for(int i=0;i<m;i++)
    {
        long long int a,b,c;
        cin>>a>>b>>c;
        //cin>>a>>b>>c;
        num[a][b]=min(num[a][b],c);
        num[b][a]=min(num[b][a],c);
    }
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            num[i][j]=min(num[i][j],num[i][k]+num[k][j]);
    }
    long long int minn=inf*10;
  //  cout<<inf<<endl;
  //  cout<<minn<<endl;
    sort(mark,mark+r);
    do
    {
        long long int sum=0;
        for(int i=1;i<r;i++)
        {
            int a=mark[i-1];
            int b=mark[i];
            sum+=num[a][b];
        }
        minn=min(minn,sum);
    }while(next_permutation(mark,mark+r));
    cout<<minn<<endl;
    return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] l = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = Integer.parseInt(sc.next());
        }
        if (n < 3) {
            System.out.println(0);
            return;
        }
        int ans = 0;
        for (int i = 0; i < n - 2; i++) {
            for (int j = i + 1; j < n - 1; j++) {
                if (l[i] == l[j]) {
                    continue;
                }
                for (int k = j + 1; k < n; k++) {
                    if (l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[j] + l[k] > l[i] && l[i] != l[k] && l[j] != l[k]) {
//                        System.out.println(i + " " + j + " " + k);
                        ans++;
                    }
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 36436
def main():
    A,B,K=list(map(int, input().split()))
    divisors=[]
    count = 0
    for i in range(1,min(A,B)+1):
        if min(A,B)%i==0:
            divisors.append(i)
    divisors.reverse()
    for divisor in divisors:
        if max(A,B)%divisor==0:
            count+=1
            if count==K:
                print(divisor)
if __name__ =='__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int a[101],b[101];
int main()
{
	int n,m=0,c=0;
	cin >> n;
	for (int i = 0;i < n;i++)
	{
		cin >> a[i];
		if (a[i] % 2 == 0) b[m++] = a[i];
	}
	for (int i = 0;i < m;i++)
	{
		if (b[i] % 3 == 0 || b[i] % 5 == 0) c++;
	}
	if (c == m) cout << "APPROVED\n";
	else cout << "DENIED\n";
}

Measured memory_bytes: 256