akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
using namespace std;
int main()
{
    int A,B,K,tmp;
    cin >> A >> B >> K;

    vector<int> divisor;

    if(B > A){
        swap(B,A);
    }
    while(B>0){
        A = A%B;
        swap(A,B);
    }
    
    for(int i=A;i>=0;i--){
        if(A%i==0){
            divisor.push_back(i);
        }
        if(K <= divisor.size()){
            break;
        }
    }

    cout << divisor[K-1] << endl;

    return 0;

}

Measured memory_bytes: 256
s = input()

core = []

for c in s:
    if c != 'x':
        core.append(c)
if core == []:
    print(0)
    exit()
l = 0
r = len(core) - 1

while l <= r:
    if core[l] != core[r]:
        print(-1)
        exit()
    l += 1
    r -= 1

ans = 0
l = 0
r = len(s) - 1

while l <= r:
    lx = 0
    rx = 0
    while s[l] == 'x':
        l += 1
        lx += 1
    while s[r] == 'x':
        r -= 1
        rx += 1
    ans += abs(lx - rx)
    l += 1
    r -= 1
print(ans)


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

struct UnionFind
{
  vector<int> rank, p;

  UnionFind(int n)
  {
    rank.resize(n, 0);
    p.resize(n);
    rep(i, n) p.at(i) = i;
  }

  int find(int x)
  {
    if (x != p.at(x))
    {
      p.at(x) = find(p.at(x));
    }
    return p.at(x);
  }

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

  void link(int x, int y)
  {
    if (rank.at(x) < rank.at(y))
      p.at(x) = y;
    else
    {
      p.at(y) = x;
      if (rank.at(x) == rank.at(y))
      {
        rank.at(x)++;
      }
    }
  }

  void unite(int x, int y)
  {
    link(find(x), find(y));
  }
};

int main()
{
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> edge(M);
  rep(i, M)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge.at(i) = make_pair(a, b);
  }
  int ans = 0;
  rep(i, M)
  {
    UnionFind uf(N);
    int a, b;
    tie(a, b) = edge.at(i);
    rep(j, M)
    {
      if (j == i)
        continue;
      int b, c;
      tie(b, c) = edge.at(j);
      uf.unite(b, c);
    }
    if (!uf.same(a, b))
    {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
int main(void){
    // Your code here!
    long double A, B, H, M;     cin >> A >> B >> H >> M;
    const  long double pi = 3.14159265358979323846264338327950L;
    long double LongRad = 2 * pi * M / 60;                   //M分の時の長針の角度
    long double ShortRad = 2 * pi * (H / 12.0 + M / 720);      //H時M分の時の短針の角度
    cout.precision(21);
    long double Rad = ((LongRad-ShortRad >= 0) ? (LongRad-ShortRad) : (long double)((LongRad-ShortRad)*(-1)));
    long double answer = sqrtl((long double)pow(A, 2) + (long double)pow(B, 2) - 2 * A * B * (long double)cosl(Rad));
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if(A == C || B == D){
        cout << 0 << endl;
        return 0;
    }
    int H = abs(C - A), W = abs(D - B);
    int G = gcd(H, W);
    ll ans = ((ll)H / G + W / G - 1) * G;
    cout << ans << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  char a[h][w+2];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> a[i][j+1];
      //cout << a[i][j+1];
    }
    a[i][0] = '#';
    a[i][w+1] = '#';
  }
  for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
      if(i == 0||i == h+1){
        cout << '#';
      }else{
        cout << a[i-1][j];
      }
    }
    cout << endl;
  }
}
  

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
  ll a,b,c,k; cin>>a>>b>>c>>k;
  ll ans=numeric_limits<ll>::min();
  if(k<=a){
    ans = k;
    cout << ans << endl;
    return 0;
  }
  ans = a;
  k-=a;
  if(k<=b){
    cout << ans << endl;
    return 0;
  }
  k-=b;
  ans -= min(k,c);
  cout << ans << endl;
}

Measured memory_bytes: 3640
a = [1, 3, 5, 7, 8, 10, 12]
b = [2]
c = [4, 6, 9, 11]
x, y = input().split()
x, y = int(x), int(y)
if x in a and y in a:
  print("Yes")
elif x in b and y in b:
  print("Yes")
elif x in c and y in c:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main()
{
  constexpr int Base=10;
  constexpr int Divisor=2019;
  
  std::string S;
  std::cin>>S;
  
  const size_t N=size(S);
  
  auto a=crbegin(S);
  int b=0;
  int c=1;
  std::vector<int> sum;
  sum.reserve(N+1);
  sum.push_back(0);
  for(size_t i=0;i!=N;i++)
  {
    b=((a[i]-'0')*c%Divisor);
    c=c*Base%Divisor;
    sum.emplace_back((sum.back()+b)%Divisor);
  }
  
  int result=0;
  for(int i=0;i!=Divisor;i++)
  {
    int count=0;
    for(size_t j=0;j!=N+1;j++)
    {
      if(sum[j]==i)
      {
        count++;
      }
    }
    if(count>=2)
    {
      result+=count*(count-1)/2;
    }
  }
      
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 4452
C = 0
N = input()
num = N.split()
A = num[0]
B = num[1]
R = int(A) * int(B)
while C != 3:
    result = R * C
    if result % 2 == 0:
        C = C + 1
        if C == 3:
            print("No")
    elif result % 2 == 1:
        C = 3
        print("Yes")


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define int ll
ll a[55]={0},b[55]={0};
ll n;
bool judge(ll num,vector<ll> vec){
  //num以下、または集合bに含まれている数だけで構成できるか？
  ll dp[55][55]={0};
  for(ll i=0;i<n;i++){
    dp[51][a[i]]|=((ll)1<<i);
  }
  ll vpos=0;
  for(ll i=50;i>0;i--){
    for(ll j=0;j<55;j++) dp[i][j]|=dp[i+1][j];
    if((vec.size()>0&&vec[vpos]==i)||i<=num){
      for(ll j=0;j<55;j++){
        dp[i][j%i]|=dp[i+1][j];
      }
    }
    if(vec.size()>0&&vec[vpos]==i) vpos++;
    if(vpos==vec.size()) vpos=0;
  }
  bool f=true;
  for(int i=0;i<n;i++){
    if(((dp[1][b[i]]>>i)&1)!=1){
      f=false;
    }
  }
  return f;
}
signed main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++) cin>>b[i];
  vector<ll> ans_v;
  if(!judge(51,ans_v)){
    cout<<-1<<endl;
    return 0;
  }
  ll ans=0;
  while(!judge(0,ans_v)){
    ll lb=0,rb=55;
    while(rb-lb>1){
      ll mid=(lb+rb)/2;
      if(judge(mid,ans_v)) rb=mid;
      else lb=mid;
    }
    ans_v.push_back(rb);
    ans+=((ll)1<<rb);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
long n,a[31],i,j;
while(cin>>n){
if(n==0)break;
a[0]=1;
a[1]=1;
a[2]=a[1]+a[0];
a[3]=a[2]+a[1]+a[0];
for(i=4;i<=n;i++)a[i]=a[i-1]+a[i-2]+a[i-3];
cout<<(a[n]-1)/3650+1<<endl;
}
return 0;
}

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

int main(){
  int p,q,r;cin >> p>>q>>r;
  cout << p+q+r-max(p,max(q,r));}

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

int main()
{
  int n,i,c,x,j,count=0;
  cin>>n;
  for(i=1;i<=n;i=i+2)
  {
      c=0;
         for(j=1;j<=i;j++)
         {
             if(i%j==0)
             {
                 c++;
             }
         }
         if(c==8)
         {
             count++;
         }
  }
  cout<<count;

}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,m = LI()
    if n == m:
        return 'Yes'

    return 'No'


print(main())





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

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

//partial_permutation nPr 順列
//first・・最初の数
//middle・・r(取り出す数)
//last・・n(全体数)
template<class Iter>
bool next_partial_permutation(Iter first, Iter middle, Iter last) {
    reverse(middle, last);
    return next_permutation(first, last);
}

int main() {

    int N, C;
    cin >> N >> C;

    vector<vector<int>> D(C, vector<int>(C));
    for (int i = 0; i < C; i++) for (int j = 0; j < C; j++) cin >> D[i][j];

    vector<vector<int>> c(N, vector<int>(N));
    for (int i = 0; i < N; i++)for (int j = 0; j < N; j++)cin >> c[i][j], c[i][j]--;

    vector<vector<long long>> dp(3, vector<long long>(C, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < C; k++) {
                dp[(i + j) % 3][k] += D[c[i][j]][k];
            }
        }
    }

    vector<int> order(C);
    for (int i = 0; i < C; i++) order[i] = i;

    long long ans = LONG_LONG_MAX;
    do {
        long long sum = 0;
        for (int i = 0; i < 3; i++) sum += dp[i][order[i]];
        ans = min(ans, sum);
    } while (next_partial_permutation(order.begin(), order.begin() + 3, order.end()));


    cout << ans << endl;
}



























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

int gcd(int x, int y)
{
    int r = x % y;
    if (r == 0)
        return y;
    return gcd(y, r);
}
int main()
{
    int x, y;
    cin >> x >> y;
    if (x < y)
    {
        swap(x, y);
    }
    cout << gcd(x, y) << endl;
}


Measured memory_bytes: 3112
#include<stdio.h>
#include<iostream>
using namespace std;
int p[100][100];
int main() {
	int w, h, i, j;
	char c[201];
	cin >> h >> w;
	for (i = 0; i < h; i++) {
		scanf("%s", c);
		for (j = 0; j < w; j++) {
			if (c[j] == 'c')p[i][j] = 0;
			else p[i][j] = -1;
		}
	}
	for(i=0;i<h;i++){
		for (j = 1; j < w; j++) {
			if (p[i][j - 1] >= 0&&p[i][j]<0)p[i][j] = p[i][j - 1] + 1;
		}
	}
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			cout << p[i][j];
			if (j != w - 1)cout << ' ';
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3248
#include <iostream>
#include <string>
#include <vector>
#include <utility>

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vp;

int main() {
    string s;
    cin >> s;

    vp e;
    bool f = s[0] == '1' && s[s.length()-1] == '0';
    int rt = 1;
    for (int i = 0; i < s.length() - 1; i++) {
        e.push_back(pii(rt, i + 2));
        if (s[i] != s[s.length()-2-i]) {
            f = false;
            break;
        }
        if (s[i] == '1') {  
            rt = i + 2;
        }
    }

    if (!f) {
        cout << -1 << endl;
    } else {
        for (auto p : e) {
            cout << p.first << " " << p.second << endl;
        }       
    }

    return 0;   
}

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

const int N = 20 + 5;
const int M = 20 + 5;
const int INF = 1162167621; // memset 69

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

char g[N][M];
int n, m, dist[N][M];

bool ok(pair<int, int> u) {
    if (u.first >= 0 and u.second >= 0 and u.first < n and u.second < m and g[u.first][u.second] == '.') return true;
    return false;
}

void dijkstra(int i, int j) {
    memset(dist, 69, sizeof dist);
    dist[i][j] = 0;
    priority_queue<pair<int, pair<int, int>>> q;
    q.emplace(dist[i][j], make_pair(i, j));
    while (!q.empty()) {
        auto u = q.top().second;
        q.pop();
        for (int i = 0; i < 4; i++) {
            auto v = make_pair(u.first + dx[i], u.second + dy[i]);
            if (ok(v) and dist[v.first][v.second] > dist[u.first][u.second] + 1) {
                dist[v.first][v.second] = dist[u.first][u.second] + 1;
                q.emplace(dist[v.first][v.second], v);
            }
        }
    }
}

int find_max() {
    int mx = -1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (dist[i][j] == INF) continue;
            mx = max(mx, dist[i][j]);
        }
    }
    return mx;
}

int main() { 
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> g[i][j];
        }
    }
    int cnt = -1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (g[i][j] == '#') continue;
            dijkstra(i, j);
            cnt = max(cnt, find_max());
        }
    }
    cout << cnt << '\n';
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  printf("%f\n", sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
  return 0;
}

Measured memory_bytes: 1228
#include "bits/stdc++.h"
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

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

int main() {
	long n, k;
	cin >> n >> k;
	int count = 1 * k;
	if (n > 1)
		cout << (long)pow((k - 1),(n - 1)) * count << endl;
	else
		cout << count << endl;
}

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    int n, mx = 0, mn = inf;
    cin >> n;
    vector<int> v(n);
    rep(i, n)
    {
        int a;
        cin >> a;
        if (mx < a)
        {
            mx = a;
        }
        if (mn > a)
        {
            mn = a;
        }
    }
    cout << mx - mn << endl;
    return 0;
}

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

using namespace std;

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    vector<int> l;
    cin >> n;
    for(int i = 0; i < n; ++i){
    	int t;
    	cin >> t;
    	l.push_back(t);
    }

    if(n < 3){
    	cout << '0';
    	return 0;
    }
    int ans = 0;
    sort(l.begin(), l.end());

    for(int i = 0; i < n; ++i){
    	for(int j = i + 1; j < n; ++j){
    		if(l[i] == l[j]) continue;
    		for(int k = j + 1; k < n; ++k){
    			if(l[j] == l[k] || l[i] == l[k]) continue;
    			if(l[i] + l[j] <= l[k]) continue;
    			//cout << i << " " << j << " " << k << '\n';
    			ans++;
    		}
    	}
    }

    cout << ans;

    
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    string S,T; cin>>S>>T;
    T+=S;
    cout<< T<<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
double rad(double dg) {
  return dg * M_PI / 180.0;
}
int main() {
  int a,b,c;
  double s,l,h,t,tmp1,tmp2;
  scanf("%d %d %d", &a, &b ,&c);
  double radian = rad(c);
  tmp1 = tan(radian);
  tmp2 = cos(radian);
  h = tmp1 * tmp2 * b;
  t = h / tmp1;
  l = sqrt(pow(h, 2.0) + pow(a-t, 2.0));
  l += a + b;
  s = a * h / 2;
  printf("%lf\n%lf\n%lf\n", s, l ,h); 
  return 0;
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define ll long long
#define NM (int)2e5
using namespace std;

ll v[NM],dp[NM];

int main()
{   int n,k;
    cin>>n>>k;
    for(int i=1; i<=n; i++)
        cin>>v[i];
    /// dp[i]=cost minim din 1 in n
    dp[2]=abs(v[1]-v[2]);
    fill(dp+3,dp+n+3,(ll)1e18);
    for(int i=3; i<=n; i++)
        for(int j=1; j<=k && i-j; j++)
            dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
    cout<<dp[n];
    return 0;
}

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i,n) cin >> a[i];
    ll ans[n];
    ll x1 = 0;
    rep(i,n-1) {
        if (i%2) x1 -= 2 * a[i];
        else x1 += 2 * a[i];
    }
    ans[0] = (x1+2*a[n-1])/2;
    rep(i,n-1) {
        ans[i+1] = 2 * a[i] - ans[i];
    }
    rep(i,n-1) {
        printf("%lld ", ans[i]);
    }
    printf("%lld\n", ans[n-1]);
    return 0;
}


Measured memory_bytes: 5280
#include<cstdio>
#include<cstring>
using namespace std;
const int M=100010;
const int mod=1000000007;
int a[M],b[M];
int main()
{
    int n,f;
    while(~scanf("%d",&n))
    {
        f=1;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            b[a[i]]++;
            if(b[a[i]]>2)
                f=0;
        }
        int  ans=1;
        if(n%2&&f)
        {
            if(b[0]!=1)
            {
                f=0;
            }
            for(int i=1;i<n;i++)
            {
                if(b[i]==2)
                {
                    ans=ans*2%mod;
                }
            }
        }
        if(n%2==0&&f)
        {
            for(int i=1;i<n;i++)
            {
                if(b[i]==2)
                {
                    ans=ans*2%mod;
                }
            }
        }
        if(f==1)
        printf("%d\n",ans%mod);
        else
            printf("0\n");
    }
    return 0;

}


Measured memory_bytes: 896
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    if N == 0:
        print(0)
        return
    ans = []
    i = 0
    while N:
        if N % 2 == 0:
            ans.append(0)
            N //= 2
        else:
            ans.append(1)
            if i % 2 == 0:
                N -= 1
            else:
                N += 1
            N //= 2
        i += 1

    print(*ans[::-1], sep='')

if __name__ == '__main__':
    main()

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

int main(){

    string N;
    cin >> N;

    char n;
    n = N[N.size()-1];
    if (n == '3') cout << "bon" << endl;
    else if (n == '0' || n == '1' || n == '6' || n == '8') cout << "pon" << endl;
    else cout << "hon" << endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

int main(){
  FASTER;
  ll n;
  cin >> n;
  cout << (n * (n - 1)) / 2 << '\n';
  return 0;
}


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

int main() {
  int a, b;
  char op;
  while (cin >> a >> op >> b, op != '?') {
    if (op == '+') {
      cout << a + b << "\n";
    } else if (op == '-') {
      cout << a - b << "\n";
    } else if (op == '*') {
      cout << a * b << "\n";
    } else {
      cout << a / b << "\n";
    }
  }
  return 0;
}


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

vector<int> par(100010, -1);

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

void unite(int x, int y)
{
    x = root(x);
    y = root(y);
    if (x == y)
        return;
    if (par[x] < par[y])
        swap(x, y);
    par[y] += par[x];
    par[x] = y;
}

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

    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    vector<ll> ans(m);
    rep(i, m) cin >> a[i] >> b[i];
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());

    ans[m - 1] = (ll)n * (ll)(n - 1) / 2;

    rep(i, m - 1)
    {
        ans[m - 2 - i] = ans[m - 1 - i];
        if (root(a[i]) == root(b[i]))
            continue;
        ans[m - 2 - i] -= par[root(a[i])] * par[root(b[i])];
        unite(a[i], b[i]);
    }
    for (auto x : ans)
        cout << x << endl;

    return 0;
}


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

int main(){
  long long a,v,b,w,t;
  cin >> a >> v >> b >> w >> t;
  long long d=max(a,b)-min(a,b);
  if(d-(v-w)*t<=0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int a[505][505];
vector<pair<pair<int,int>,pair<int,int>>> ans;

int main(){
    int h,w;
    cin >> h >> w;
    for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin >> a[i][j];
    int i=0; int j=0;
    int solve=0;
        while(i<h && j>=0 && j<w){
            if(i==h-1 && ((i%2==0 && j==w-1) || (i%2==1 && j==0)) )break;
            else if(i%2==0 && j<w-1){
                if(a[i][j]%2==1){
                    solve++;
                    ans.push_back(make_pair(make_pair(i,j),make_pair(i,j+1)));
                    a[i][j+1]++;
                }
                j++;
            }
            else if(i%2==0 && j==w-1){
                if(a[i][j]%2==1){
                    solve++;
                    ans.push_back(make_pair(make_pair(i,j),make_pair(i+1,j)));
                    a[i+1][j]++;
                }
                i++;
            }
            else if(i%2==1 && j>0){
                if(a[i][j]%2==1){
                    solve++;
                    ans.push_back(make_pair(make_pair(i,j),make_pair(i,j-1)));
                    a[i][j-1]++;
                }
                j--;
            }
            else if(i%2==1 && j==0){
                if(a[i][j]%2==1){
                    solve++;
                    ans.push_back(make_pair(make_pair(i,j),make_pair(i+1,j)));
                    a[i+1][j]++;
                }
                i++;
            }            
        }
    cout << ans.size() << endl;
    for(auto u:ans)cout << u.first.first+1 << " " << u.first.second+1 << " " << u.second.first+1 <<" "<< u.second.second+1 << endl;
}

Measured memory_bytes: 5232
#include<bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define bit(idx) idx&(-idx)
#define bin(x, a) bitset<a>(x)
#define all(A) A.begin(), A.end()
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;



int main(){
	ios_base::sync_with_stdio(NULL); cin.tie(); cout.tie();
    string t; cin >> t;
    if(t == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}
/**

*/



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

int main()
{
  int n;
  cin >> n;
  vector<string> s(n);
  int i, j, k;
  for(i = 0; i < n; i++)
  {
    cin >> s.at(i);
  }
  vector<long long> name(5, 0);
  for(i = 0; i < n; i++)
  {
    if(s.at(i).at(0) == 'M') name.at(0)++;
    if(s.at(i).at(0) == 'A') name.at(1)++;
    if(s.at(i).at(0) == 'R') name.at(2)++;
    if(s.at(i).at(0) == 'C') name.at(3)++;
    if(s.at(i).at(0) == 'H') name.at(4)++;
  }
  long long ans = 0;
  for(i = 0; i < 3; i++)
  {
    for(j = i+1; j < 4; j++)
    {
      for(k = j+1; k < 5; k++)
      {
        ans += name.at(i)*name.at(j)*name.at(k);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6652
#include <stdio.h>
#include <string.h>
int main(void) {
    int n, l;
    scanf("%d%d",&n, &l);
    int i;
    int sum = 0;
    for(i=l;i<l+n;i++) {
        sum = sum+i;
    }
    int pick;
    if(l<0){
        l = l*-1;
        if(l>=n){
            pick = -1*l+n-1;
        }else {
            pick = 0;
        }
    } else {
        pick = l;
    }
    sum = sum-pick;
    printf("%d\n",sum);


    return 0;
}

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

int main(){
    ll h,n;
    ll sum = 0;
    ll mem;
    cin >> h >> n;
    for(int i=0;i<n;i++){
        cin >> mem;
        sum = sum + mem; 
    }
    if(sum>=h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main() {
    vector<ll> v(3);
    for(int i=0; i<3; ++i) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    if(all_of(v.begin(), v.end(), [](ll i) { return i % 2 == 1; })) {
        cout << v[0]*v[1] << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;

public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int n = sc.nextInt();
			
			long count = 0;
			for(int i = 0; i <= n; i ++){
				for(int j = 0; j <= n; j++){
					long k = (long)n - (long)i * a - (long)j * b;
					if(k < 0) continue;
					if(k % c == 0){
						count++;
					}
				}
			}
			System.out.println(count);
			
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

}


Measured memory_bytes: 22612
#[allow(dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(dead_code)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(dead_code)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        _n: usize,
        k: usize1,
        mut s: chars
    }
    s[k] = {
        let v = (s[k] as u8) - ('A' as u8);
        let nc = ('a' as u8) + v;
        nc as char
    };

    println!("{}", s.into_iter().collect::<String>());
}


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

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
#define DRT() int t; si(t); while(t--)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//# define M_PI           3.14159265358979323846264338327950288
// DSU
void IO(){
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
}

int main(){
	IO();
	LL n,l;
	cin>>n>>l;
	LL sum = n*l + (n*(n-1))/2;
	if(0 >= l && 0 <= (l + n -1))
		cout<<sum;
	else{
		if(l+n-1 < 0){
			sum -= l+n-1;
		}
		if(l+n-1 > 0){
			sum -= l;
		}
		cout<<sum;
	}
	return 0;
}

Measured memory_bytes: 3588
S = input()
mod = 10**9 + 7
dp = [[0 for i in range(13)] for j in range(len(S)+1)]
dp[0][0] = 1
for i in range(len(S)):
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])
    for j in range(10):
        if c != -1 and c != j:
            continue
        for k in range(13):
            dp[i+1][(k*10+j)%13] += dp[i][k]%mod
    for j in range(13):
        dp[i+1][j] %= 10**9 + 7
print(dp[len(S)][5]%mod)

Measured memory_bytes: 67320
#include<bits/stdc++.h>
using namespace std;
int n,a,ans[202020];
int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		cin>>a;
		ans[a]++;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4376
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}




struct Block{
    int w,s;ll v;
    Block(int w,int s,ll v):w(w),s(s),v(v){}
    Block(){}
};

const int OV=11000;
ll dp[1100][11100];

signed main(){
    int n;cin>>n;
    vector<Block>a(n);
    rep(i,n){
        int w,s;ll v;cin>>w>>s>>v;
        a[i]=Block(w,s,v);
    }

    sort(ALL(a),[](Block lhs,Block rhs){
        return lhs.w+lhs.s<rhs.w+rhs.s;
    });

    rep(i,n){
        rep(j,OV+1){
            if(j<=a[i].s){
                int to=min(OV,j+a[i].w);
                chmax(dp[i+1][to],dp[i][j]+a[i].v);
            }
            chmax(dp[i+1][j],dp[i][j]);
        }
    }
    ll res=0;
    rep(j,OV+1)chmax(res,dp[n][j]);
    cout<<res<<endl;
    return 0;
}



/*
s+wでソートするのが嬉しい証明
今，上に重みWがすでに積まれていて，次にaとbのどっちのBlockを置くか考える
この時，a->bで置くと，両方置けて，b->aで置くと両方置けない．
つまり，aから観たほうが得である状況を考える
(どっちから先に置いたところで片方しか置けない状況，両方置けない状況を考えるのは意味がない．
ソートの順序を考える上でどうでもよい)

a->bで両方置ける．
s_a>=w and s_b>=w+w_a  ... (i)
b->aだと両方置けない．
not(s_b>=w and s_a>=w+w_b) <=> s_b<w or s_a<w+w_b   ...(ii)
(i)よりs_b<wとなることはない．変数全部非負であるため，よって得にの状況に差が出るのは
(i) and s_a<w+w_b
変形すると，
s_a-w_b<w<=s_b-w_a
<=>  s_a+w_a<=s_b+w_b
よってs+wでソートして，小さいほうから見るのがよい
*/

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

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

/*-------------------------------------------*/
int n,q;
string s;
int AC[100009];

int main(){
    cin>>n>>q>>s;
    rep(i,n-1){
        if(s[i]=='A'&&s[i+1]=='C')AC[i+1]=1;
    }
    rep(i,n){
        AC[i+1]+=AC[i];
    }
    rep(i,q){
        int l,r;
        cin>>l>>r;
        cout<<AC[r-1]-AC[l-1]<<endl;
    }
}

Measured memory_bytes: 1408
#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>;
const int INF = 1001001001;

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<char>> f(h, vector<char>(w));
  rep(i, h) {
    rep(j, w) cin >> f[i][j];
  }
  int res = 0;
  for(int i = 0; i < (1 << h); ++i) {
    for(int j = 0; j < (1 << w); ++j) {
      int count = 0;
      for(int ii = 0; ii < h; ++ii) {
        if((1 << ii) & i ) continue;
        for(int jj = 0; jj < w; ++jj) {
          if((1 << jj) & j ) continue;
          if(f[ii][jj] == '#') count++;
        }
      }
      if(count == k) res++;
    }
  }
  cout << res << endl;
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair

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

int main(){
	int n;
	cin >> n;
	int a[n],b[n],c[n];
	FOR(i,n) cin >> a[i] >> b[i] >> c[i];
	int sol[n][3];
	tie(sol[0][0],sol[0][1],sol[0][2])=make_tuple(a[0],b[0],c[0]);
	for (int i = 1; i < n; ++i)
	{
		sol[i][0]=a[i]+max(sol[i-1][1],sol[i-1][2]);
		sol[i][1]=b[i]+max(sol[i-1][0],sol[i-1][2]);
		sol[i][2]=c[i]+max(sol[i-1][1],sol[i-1][0]);
	}
	
	cout << max(max(sol[n-1][0],sol[n-1][1]),sol[n-1][2]);
	


	return 0;
}

Measured memory_bytes: 2560
n, k = gets.split(" ").map(&:to_i)
xs = gets.split(" ").map(&:to_i)

ans = Float::INFINITY
xs.each_with_index do |x,i|
  a = xs[i, k]
  break if a.size < k
  if a[-1] < 0
    ans = [a[0].abs, ans].min
  elsif 0 < a[0]
    ans = [a[-1].abs, ans].min
  elsif a[0] < 0 && 0 < a[-1]
    l = (a[-1] - a[0]) + a[0].abs
    r = (a[-1] - a[0]) + a[-1].abs
    ans = [l, r, ans].min
  end
end

if ans == Float::INFINITY
  ans = 0
end

puts ans

Measured memory_bytes: 11020
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    ma = A[0]
    ans = 0
    for a in A[1:]:
        if ma > a:
            ans += ma - a
        if ma < a:
            ma = a
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 94188
// Author: Wenxing Mei
//   File: d.cpp
//   Date: 2019-04-05 10:22
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define per(i, b, a) for (int i = (int)b; i >= (int)a; --i)
#define repv(ele, cont) for (auto &ele : cont)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<ll> vll;
// END OF TEMPLATE
int a, b, q;
ll s[100010], t[100010];
ll inf = numeric_limits<ll>::max();

pair<ll, ll> cs(ll x) {
    ll *p = lower_bound(s, s + a, x);
    if (p == s + a) return make_pair(*(p - 1), inf);
    if (p == s) return make_pair(*p, inf);
    if (*p == x) return make_pair(*p, inf);
    return make_pair(*p, *(p - 1));
}

pair<ll, ll> ct(ll x) {
    ll *p = lower_bound(t, t + b, x);
    if (p == t + b) return make_pair(*(p - 1), inf);
    if (p == t) return make_pair(*p, inf);
    if (*p == x) return make_pair(*p, inf);
    return make_pair(*p, *(p - 1));
}

ll query(ll x) {
    // goto closest s, then closest t
    ll ret = inf;
    {
        auto p = cs(x);
        // ll p1 = p.first;
        auto doit = [&](ll p1) {
            if (p1 != inf) {
                auto pp = ct(p1);
                if (pp.first != inf) {
                    ll tmp = abs(x - p1) + abs(pp.first - p1);
                    ret = min(ret, tmp);
                }

                if (pp.second != inf) {
                    ll tmp = abs(x - p1) + abs(pp.second - p1);
                    ret = min(ret, tmp);
                }
            }
        };

        doit(p.first);
        doit(p.second);
    }
    // goto closest t, then closest s
    {
        auto p = ct(x);
        auto doit = [&](ll p1) {
            if (p1 != inf) {
                auto pp = cs(p1);
                if (pp.first != inf) {
                    ll tmp = abs(x - p1) + abs(pp.first - p1);
                    ret = min(ret, tmp);
                }

                if (pp.second != inf) {
                    ll tmp = abs(x - p1) + abs(pp.second - p1);
                    ret = min(ret, tmp);
                }
            }
        };

        doit(p.first);
        doit(p.second);
    }
    return ret;
}

int main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
    cin >> a >> b >> q;
    rep(i, 0, a) cin >> s[i];
    rep(i, 0, b) cin >> t[i];
    sort(s, s + a);
    sort(t, t + b);
    rep(i, 0, q) {
        ll x;
        cin >> x;
        cout << query(x) << '\n';
    }
    return 0;
}


Measured memory_bytes: 2944
def zzz(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

x=int(input())
list=zzz(x)
kotae=0
for l in list:
    if l>=2:
        if x%(l-1)==int(x/(l-1)):
            kotae+=(l-1)
            #print(l-1)
print(kotae)

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

using namespace std;

int main() {
	int n;
	cin >> n;
	map<string, int> mp;
	int maxi = 0;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (!mp.count(s)) {
			mp[s] = 0;
		}
		mp[s]++;
		maxi = max(maxi, mp[s]);
	}
	vector<string> res;
	for (auto p: mp) {
		if (p.second == maxi) {
			res.push_back(p.first);
		}
	}
	sort(res.begin(), res.end());
	for (int i = 0; i < res.size(); i++) {
		cout << res[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 26868
#include<stdio.h>

int A[1000000], n;

int binarySearch(int key) {
	int left = 0;
	int right = n;
	int mid;
	while(left < right) {
		mid = (left + right) / 2;
		if(A[mid] == key) return 1;
		if(key < A[mid]) right = mid;
		else if(key > A[mid]) left = mid+1; 
	}
	return 0;	
}

int main() {
	int i, q, key, sum = 0;
	
	scanf("%d", &n);
    for(int i = 0; i < n; i++) { 
        scanf("%d", &A[i]);
    }
    
    scanf("%d", &q);
    for(int i = 0; i < q; i++) {
	    scanf("%d", &key);
		if( binarySearch(key)) sum++; 
	}
	printf("%d\n", sum);
	
	return 0;    
}
  

Measured memory_bytes: 2972
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <list>
#include <bitset>
#include <numeric>
#include <utility>
#define INF 1e9
#define MOD 1000000007
#define ll long long
#define int long long
using namespace std;
typedef unsigned long long ull;
typedef pair<int, int> p;
signed main(){
    int n;
    cin>>n;
    string s;
    int c[5];
    fill(c,c+5,0);
    for(int i=0;i<n;i++){
        cin>>s;
        if(s[0]=='M'){
            c[0]++;
        }
        else if(s[0]=='A'){
            c[1]++;
        }
        else if(s[0]=='R'){
            c[2]++;
        }
        else if(s[0]=='C'){
            c[3]++;
        }
        else if(s[0]=='H'){
            c[4]++;
        }
    }
//    cout<<c[0]<<" "<<c[1]<<" "<<c[2]<<" "<<c[3]<<" "<<c[4]<<endl;
    int ans=0;
    for(int i=0;i<3;i++){
        for(int j=i+1;j<4;j++){
            for(int k=j+1;k<5;k++){
    //            cout<<i<<" "<<j<<" "<<k<<" "<<c[i]*c[j]*c[k]<<endl;
                ans+=c[i]*c[j]*c[k];
            }
        }
    }
    cout<<ans;
    return 0;
}

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

int main() {
	int i, N, dist, dt, T, X, Y;
	vector<int> t, x, y;

	cin >> N;

	for (i = 0; i <= N; ++i) {
		if (i == 0) {
			T = 0;
			X = 0;
			Y = 0;
		}
		else cin >> T >> X >> Y;

		t.emplace_back(T);
		x.emplace_back(X);
		y.emplace_back(Y);
	}

	bool can = true;
	for (i = 0; i < N; ++i) {
		dt = t[i + 1] - t[i];
		dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
		if (dist > dt) can = false;
		if (dist % 2 != dt % 2) can = false;
		if (!can) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1644
fun main(args: Array<String>) {
  val N = readLine()!!.toInt()
  val S = generateSequence { readLine()!! }.take(N).toList()
  val T = Array(2*N) { S[it % N ].repeat(2) }.toList()
  val tb = Array(2*N) { IntArray(2*N) }

  for(i in 0 until 2*N) {
    for(j in 0 until 2*N) {
      if(i == 0 || j == 0) tb[i][j] = 1
      else {
        val k = (0 .. Math.min(i, j)).find { T[i][j-it] != T[i-it][j] } ?: Math.min(i, j)
        tb[i][j] = Math.min(tb[i-1][j-1] + 1, k)
      }
    }
  }

  println((N until 2*N).map{ i -> (N until 2*N).count{ j -> tb[i][j] >= N } }.sum())
}

Measured memory_bytes: 117724
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end
X,A,B=get_i
if A>=B
    puts "delicious"
elsif B-A<=X
    puts "safe"
else
    puts "dangerous"
end


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

int main() {
	cin >> N;
	long long a = N % 11;
	long long b = N / 11 * 2;
	if (a == 0) {
		cout << b << endl;
	}else if( a <= 6){
		cout << b + 1 << endl;
	}else {
		cout << b+ 2 << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main() {
	int d[10];
    for(int i=1;i<=4;i++){
        d[i]=0;
    }
    for(int i=0;i<6;i++){
        int z;
        cin >> z;
        d[z]++;
    }
    if(d[1]<=2&&d[2]<=2&&d[3]<=2&&d[4]<=2){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

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

#define    ll     long long int

vector<int> v;
ll cnt[100005];

int main( )
{
    ll n, a, b, i, j, k;
    cin >> n >> k;
    while (n--) {
        cin >> a >> b;
        if (cnt[a] == 0) {
            v.push_back(a);
        }
        cnt[a] += b;
    }
    sort(v.begin(), v.end());
    j = 0;
    for (i = 0; i < (int) v.size(); i++) {
        if (j + cnt[v[i]] < k) {
            j += cnt[v[i]];
            continue;
        }
        cout << v[i] << '\n';
        return 0;
    }
    return 0;
}

Measured memory_bytes: 1408