akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

class Node {
public:
	int ID;
	int child1; 
	int child2;
public:
	Node() {}
	Node(int ID, int child1, int child2) { this->ID = ID; this->child1 = child1; this->child2 = child2; }
	bool operator<(const Node& rhs) { return this->ID < rhs.ID; }
	bool operator<=(const Node& rhs) { return this->ID <= rhs.ID; }
	bool operator>(const Node& rhs) { return this->ID > rhs.ID; }
	bool operator>=(const Node& rhs) { return this->ID >= rhs.ID; }
	bool operator==(const Node& rhs) { return this->ID == rhs.ID; }
	bool operator!=(const Node& rhs) { return this->ID != rhs.ID; }
	~Node(){}
};

void walk(Node* tree, int index_of_node, std::string order)
{
	if (order == "Preorder") std::cout << " " << index_of_node;
	
	int c1 = tree[index_of_node].child1;
	if (c1 >= 0) walk(tree, c1, order);
	
	if (order == "Inorder") std::cout << " " << index_of_node;
	
	int c2 = tree[index_of_node].child2;
	if (c2 >= 0) walk(tree, c2, order);
	
	if (order == "Postorder") std::cout << " " << index_of_node;
}

int main()
{
	int n;
	std::cin >> n;
	
	Node* bintree = new Node[n];
	
	for (int i=0; i<n; i++) {
		int ID;
		int c1, c2;
		std::cin >> ID >> c1 >> c2;
		bintree[i] = Node(ID, c1, c2);
	}
	
	std::sort(bintree, bintree + n);
	
	bool* isRoot = new bool[n];
	for (int i=0; i<n; i++) isRoot[i] = true;
	
	for (int i=0; i<n; i++) {
		if (bintree[i].child1 >= 0) isRoot[bintree[i].child1] = false;
		if (bintree[i].child2 >= 0) isRoot[bintree[i].child2] = false;
	}
	
	// search the index of the root node
	int index_of_root = -1;
	for (int i=0; i<n; i++) {
		if (isRoot[i]) { index_of_root = i; break; }
	}
	std::cout << "Preorder" << std::endl;
	walk(bintree, index_of_root, "Preorder"); std::cout << std::endl;
	std::cout << "Inorder" << std::endl;
	walk(bintree, index_of_root, "Inorder"); std::cout << std::endl;
	std::cout << "Postorder" << std::endl;
	walk(bintree, index_of_root, "Postorder"); std::cout << std::endl;
	
	delete[] isRoot;
	delete[] bintree;
	
	return 0;
}




Measured memory_bytes: 3216
def solve():
    n,d = map(int, input().split())
    l = [[int(x) for x in input().split()] for _ in range(n)]
    count = 0
    for i in range(n):
        Y = l[i]
        for Z in l[i+1:]:
            total = 0
            for y,z in zip(Y,Z):
                total += (y-z)**2
            d = total**0.5
            if d == int(d):
                count += 1
    return count

if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 3188
#include <bits/stdc++.h>
typedef long long int ll;
#define MOD 1000000007
#define MAXN 200001
#define f(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rf(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);i--)
using namespace std;


int main() {
    ll a,b,c;
  	cin >> a >> b >> c;
  	cout << c <<" "<<a<<" "<<b;
}

Measured memory_bytes: 256
A, B = map(int, input().split())
def f(n):
  if n % 2 == 0:
    if n % 4 == 0:
      return n
    else:
      return 1 ^ n
  else:
    if (n+1) % 4 == 0:
      return 0
    else:
      return 1
A = f(A-1)
B = f(B)
print(A^B)


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var n = br.readLine().toCharArray();
      for (char c : n) {
        if (c == '7') {
          System.out.println("Yes");
          return;
        }
      }

      System.out.println("No");
    }
  }
}


Measured memory_bytes: 32652
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> a,a2;
  int n,q,b,m,e;
  int pos1,pos2,tmp;
  cin >> n;
  a.resize(n);

  a2.resize(n);
  for(ii=0;ii<n;ii++){
    cin >> a[ii];
  }


  cin >> q;
  
  for(ii=0;ii<q;ii++){
    cin >> b >> m >> e;


    copy(a.begin(),a.end(),a2.begin());    
    for(jj=0;jj<e-b;jj++){

      pos1 = b + jj;
      //pos2 = m + jj;
      pos2 = b + ((jj + (e - m )) % (e - b));
      

      //cout << "pos1:" << pos1 << "pos2:" << pos2 << endl;
      
//      tmp = a[pos1];
//      a[pos1] = a[pos2];
//      a[pos2] = tmp;
      a2[pos2] = a[pos1];
    }
    copy(a2.begin(),a2.end(),a.begin());    
  }
  vector<int>::iterator it = a.begin();

  while(it != a.end()){
    cout << *it;
    it++;
    if(it != a.end()){
      cout << " ";
    }
    else{
      cout << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3128
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

ll ans;
char info[10][10];
ll selected[20];
ll h;
ll w;
ll k;
void dfs(ll level){
    ll blknum=0;;
    if(level == 0){
        // 計算
        REP(hi,h){
            REP(wi,w){
                if(selected[hi] == 1){
                    continue;
                }
                if(selected[wi + h] == 1){
                    continue;
                }
                if(info[hi][wi] == '#'){
                    blknum++;
                }
            }
        }

        if(blknum == k){
            ans++;
        }
        return;
    }

    selected[ (h+w) -level ] = 1;
    dfs(level-1);
    selected[ (h+w) -level ] = 0;
    dfs(level-1);

    return;
}

int main(void){
    cin >> h >> w >> k;
    REP(i, h){
        REP(j,w){
            char tmp;
            cin >> tmp;
            info[i][j] = tmp;
        }
    }
    dfs(h+w);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <math.h>

using namespace std;


int main() {

	double mul_l = 0;
	long long ans = 1;
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		long long a; cin >> a;
		mul_l += log10l(a);
		ans *= a;
	}
	if (mul_l > 18 || ans > 1000000000000000000)
		cout << -1;
	else
		cout << ans;
	cout << endl;

	return 0;
}

Measured memory_bytes: 3704
n,c=map(int,input().split())
D=[[0]*c for i in range(c)]
for i in range(c):
  D[i]=list(map(int,input().split()))
C=[[0]*n for i in range(n)]
for i in range(n):
  C[i]=list(map(int,input().split()))
  for j in range(n):
    C[i][j]=C[i][j]-1
A=[[0]*c for i in range(3)]
for i in range(n):
  for j in range(n):
    A[(i+j)%3][C[i][j]]+=1
ans=0
e=10**20
for i in range(c):
  for j in range(c):
    if j==i:
      continue
    for k in range(c):
      if k==i:
        continue
      if k==j:
        continue
      f=0
      for u in range(c):
        f=f+A[0][u]*D[u][i]+A[1][u]*D[u][j]+A[2][u]*D[u][k]
      if e>f:
        e=f
print(e)

Measured memory_bytes: 5492
import java.util.Scanner;

public class Main {
    static int N, M, R;
    static int INF = 1<<29;
    static int[][] d = new int[201][201];
    static int[] r = new int[9];
    static int res;
    static boolean used[] = new boolean[9];

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        int A,B,C;
        N = sc.nextInt();
        M = sc.nextInt();
        R = sc.nextInt();
        for(int i = 1; i <= N; i++) {
            for(int j = 1; j <= N; j++) {
                if(i != j) d[i][j] = INF;
            }
        }
        for(int i = 1; i <= R; i++) {
            r[i] = sc.nextInt();
        }
        for(int i = 1; i <= M; i++) {
            A = sc.nextInt();
            B = sc.nextInt();
            C = sc.nextInt();
            if(d[A][B] > C) d[A][B] = d[B][A] = C;
        }
        //ワーシャルフロイド
        for(int k = 1; k <= N; k++) {
            for(int i = 1; i <= N; i++) {
                for(int j = 1; j <= N; j++) {
                    if(d[i][j] > d[i][k] + d[k][j]) {
                        d[i][j] = d[i][k]+d[k][j];
                    }
                }
            }
        }
        res = INF;
        dfs(1, -1, 0);
        System.out.println(res);
    }
    public static void dfs(int c, int las, int dist) {
        if(c==R+1) {
            if(res > dist) res = dist;
            return;
        }
        for(int i = 1; i <= R; i++) {
            if(!used[i]) {
                used[i] = true;
                if(las==-1) dfs(c+1, i, 0);
                else dfs(c+1, i, dist+d[r[las]][r[i]]);
                used[i] = false;
            }
        }
    }
}

Measured memory_bytes: 46528
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=100+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
int n,h[N];
void input()
{
	n=read<int>();
	For(i,1,n)h[i]=read<int>();
}
int q[N],top;
void init()
{
	For(i,1,n)q[++top]=h[i];
	sort(q+1,q+top+1);
	top=unique(q+1,q+top+1)-q-1;
	For(i,1,n)h[i]=lower_bound(q+1,q+top+1,h[i])-q;
}
const int mo=1e9+7;
int dp[N][N];
ll power(ll x,int y)
{
	ll res=1;
	for(;y;x=x*x%mo,y>>=1)if(y&1)res=res*x%mo;
	return res;
}
void add(int &x,int y)
{
	x+=y;x-=(x>=mo?mo:0);
}
void work()
{
	dp[0][0]=1;	
	For(i,1,n)
	{
		add(dp[i][0],dp[i-1][0]*2%mo);
		For(j,h[i]+1,h[i-1])add(dp[i][0],dp[i-1][j]*2%mo);
		int d=(h[i]>h[i-1]?power(2,q[h[i]]-q[h[i-1]]):1);
		For(j,1,min(h[i-1],h[i]))dp[i][j]=1ll*dp[i-1][j]*d%mo;
		For(j,h[i-1]+1,h[i])
		{
			if(j>1)dp[i][j]=1ll*dp[i-1][0]*power(2,q[h[i]]-q[j])%mo*(power(2,q[j]-q[j-1])-1)%mo*2%mo;
			else dp[1][1]=1ll*(power(2,q[1])-2)*power(2,q[h[1]]-q[1])%mo;
		}
	}
	int ans=0;
	For(i,0,h[n])add(ans,dp[n][i]);
	write(ans,'\n');
}
int main()
{
//	file();
	input();
	init();
	work();
	return 0;
}


Measured memory_bytes: 256
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10**9 + 7
N = 10**5  # 出力の制限
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


N, K = map(int, input().split())

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

A_array.sort()

ans = 0

for i in range(N - K):
    count = (cmb(N - i, K, mod) + mod - cmb(N - i - 1, K, mod)) % mod
    ans = (ans + A_array[-(i + 1)] * count % mod) % mod
    ans = (ans + mod - A_array[i] * count % mod) % mod
ans = (ans + A_array[K - 1] - A_array[-K]) % mod
print(ans)


Measured memory_bytes: 67428
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define NUM 100001
int N;
typedef struct _robot {
  int l, r, flag;
} Robot;
Robot rs[NUM];

int c(const void *a, const void *b) {
  Robot *ra = (Robot *)a;
  Robot *rb = (Robot *)b;
  return (ra->r - rb->r);
}
int main() {
  int i, num = 0, preR;

  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    int X, L; scanf("%d %d", &X, &L);
    rs[i].l = X - L; rs[i].r = X + L;
  }
  qsort(rs, N, sizeof(Robot), c);
  preR = rs[0].r;
  for (i = 1; i < N; i++) {
    if (rs[i].l < preR) { num++; } else {
      preR = rs[i].r;
    }
  }
  printf("%d\n", N-num);
}


Measured memory_bytes: 2556
#include<bits/stdc++.h>
using namespace std;
int n;
long long f[87];
int main()
{
	cin>>n;
	f[0]=2;
	f[1]=1;
	for(int i=2;i<=n;i++)
		f[i]=f[i-1]+f[i-2];
	cout<<f[n];
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

// Data structures.
struct Point {
    double x, y;
    Point(double x = 0, double y = 0) : x(x), y(y) {}
    Point(const Point& p) : x(p.x), y(p.y) {}

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

    bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; }
    bool operator==(const Point& p) const { return fabs(x - p.x) < 1e-10 && fabs(y - p.y) < 1e-10; }

    static double norm(const Point& p) { return sqrt(p.x * p.x + p.y * p.y); }
    static double dot(const Point& p1, const Point& p2) { return p1.x * p2.x + p1.y * p2.y; }
    static double cross(const Point& p1, const Point& p2) { return p1.x * p2.y - p1.y * p2.x; }
};

struct Segment {
    Point s, t;
};

int ccw(const Point& p1, const Point& p2, const Point& p) {
    double cr = Point::cross(p2 - p1, p - p1);
    if (cr > 0) return 1;
    if (cr < 0) return -1;
    // p, p1, p2.
    if (Point::dot(p2 - p1, p - p1) < 0) { return 2; }
    // p1, p2, p.
    if (Point::dot(p - p2, p1 - p2) < 0) { return -2; }
    // p is in [p1, p2].
    return 0;
}

bool intersect(const Segment& s1, const Segment& s2) {
    bool ok1 = ccw(s1.s, s1.t, s2.s) * ccw(s1.s, s1.t, s2.t) <= 0;
    bool ok2 = ccw(s2.s, s2.t, s1.s) * ccw(s2.s, s2.t, s1.t) <= 0;
    return ok1 && ok2;
}

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

    int q;
    cin >> q;

    rep(i, 0, q) {
        Segment s1, s2;
        cin >> s1.s.x >> s1.s.y >> s1.t.x >> s1.t.y;
        cin >> s2.s.x >> s2.s.y >> s2.t.x >> s2.t.y;
        cout << (intersect(s1, s2) ? 1 : 0) << endl;
    }

    return 0;
}


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

int main()
{
    int n = 0;
    std::cin >> n;
    std::vector<int> values(n);
    
    int input = 0;
    for(int i = 0; i < n; ++i)
    {
        std::cin >> input;
        values.at(i) = input;
    }
    int ans = 0;
    for(int i = 0; i < n; ++i)
    {
        std::cin >> input;
        ans += (std::max)(0, values.at(i) - input);
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll k;
    string s;
    cin >> k >> s;
    if(s.size() <= k){
        cout << s << endl;
    }
    else
    {
        cout << s.substr(0,k) << "..." << endl;
    }
    
}

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



int main(){
    int a,b,ans =0;
    cin >> a >> b;
    while(a<=b){
    int q ,w,e,r;
    q = a/10000;
    w=a%10;
    e =a/1000%10;
    r =a/10%10;
        if(q ==w && e ==r){
            ans++;
        }
        a++;
    }
    cout << ans << endl;
}    


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

using namespace std;

//#define FILE_IO

typedef pair<int, int> pii;

int N;

int v[55];
vector<pii> op;

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d", &N);
    int mx = int(-(1e6)), mn = int(1e6);
    for(int i = 1; i <= N; i++)
    {
        scanf("%d", &v[i]);
        mx = max(mx, v[i]);
        mn = min(mn, v[i]);
    }

    if(mx >= abs(mn))
    {
        int pos = 0;
        for(int i = 1; i <= N; i++)
            if(v[i] == mx)  pos = i;
        for(int i = 1; i <= N; i++)
            if(i != pos)
            {
                op.push_back({pos, i});
                v[i] += v[pos];
            }
        for(int i = 2; i <= N; i++)
            {
                op.push_back({i - 1, i});
                v[i] += v[i - 1];
            }

        printf("%d\n", op.size());
        for(auto x: op)
            printf("%d %d\n", x.first, x.second);
    }
    else
    {
        int pos = 0;
        for(int i = 1; i <= N; i++)
            if(v[i] == mn)  pos = i;
        for(int i = 1; i <= N; i++)
            if(i != pos)
            {
                op.push_back({pos, i});
                v[i] += v[pos];
            }
        for(int i = N - 1; i >= 1; i--)
            {
                op.push_back({i + 1, i});
                v[i] += v[i + 1];
            }

        printf("%d\n", op.size());
        for(auto x: op)
            printf("%d %d\n", x.first, x.second);
    }

    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <fstream>
#include <cassert>

using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, b, a) for(int i = b - 1; i >= a; --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)

#define ALL(V) V.begin(), V.end()
#define SIZE(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define EPS 1e-7
#define Pi 3.14159265358979
#define FILL(a,v) memset(a,v,sizeof(a))

using namespace std;


typedef long long Long;
typedef unsigned long long ULong;
typedef unsigned int Uint;
typedef unsigned char Uchar;
typedef vector <int> VI;
typedef pair <int, int> PII;

Long gcd (Long a, Long b) {
    while (b) {
        a %= b;
        swap (a, b);
    }
    return a;
}

bool can(Long a, Long b, Long c, Long d) {
    if (a < b)
        return false;

    if (b > d)
        return false;

    if (c > b)
        return true;

    if (a <= c)
        a = a-b;
    else {
        auto k = (a-c)/b;
        a -= k*b;
    }

    while (a > c)
        a -= b;

    if (a < 0)
        return false;

    if (d == b)
        return true;

    d%=b;

    Long g = gcd(d,b);

    Long s = (c - c%g) + a%g;;
    while (s <= c)
        s += g;
    if (s < b)
        return false;

    return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    int T;
    cin >> T;
    REP(i,T) {
        Long a,b,c,d;
        cin >> a >> b >> c >> d;
//        cout << i << " " << b << " " << c << " "<< d << endl;
        if (can(a,b,c,d))
            cout << "Yes" << endl;
        else
            cout << "No" << endl;

    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
unordered_map<string,int> m;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		if(s=="insert"){
			cin>>s;
			m[s]=1;
		}else{
			cin>>s;
			if(m[s])cout<<"yes"<<"\n";
			else cout<<"no"<<"\n";
		}
	}

	return 0;
}


Measured memory_bytes: 46020
N=int(input())
A=list(map(int,input().split()))

if 0 in A:
    S=0
    for a in A:
        S+=abs(a)
    print(S)
else:
    X=0
    S=0
    for a in A:
        X+=(a<0)
        S+=abs(a)

    if X%2==0:
        print(S)
    else:
        b=abs(min(A,key=lambda x:abs(x)))
        print(S-2*b)

Measured memory_bytes: 85524
import numpy as np

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

ac = [0]*(n+1)
wa = [0]*(n+1)

for _ in range(m):
  p,s = map(str,input().split())
  if s == "AC" and ac[int(p)] == 0:
    ac[int(p)] = 1
  if s == "WA" and ac[int(p)] == 0:
    wa[int(p)] += 1
print(sum(ac),sum(np.array(ac)*np.array(wa)))

Measured memory_bytes: 30112
#include <stdio.h>
int main() {
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if(x - r < 0 || y - r < 0 || x + r > W || y + r > H) printf("No\n");
  else printf("Yes\n");
  return 0;
}



Measured memory_bytes: 2696
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int A[]=new int [N];
		for(int i=0;i<N;i++) {
			A[i]=sc.nextInt();
		}
		int d;
		int ans=Integer.MAX_VALUE;
		for(int i=0;i<=N-K;i++) {
			int b=Math.abs(A[i])+Math.abs(A[i+K-1]-A[i]);
			int c=Math.abs(A[i+K-1])+Math.abs(A[i+K-1]-A[i]);
			d=Math.min(b,c);
			if(ans>d) {
				ans=d;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 51096
from collections import deque

N, M = map(int, input().split())

room_reached = [False] * (N + 1)
room_clue = [-1] * (N + 1)

room_path_list = [[] for _ in range(N + 1)]

for _ in range(M):
    A, B = map(int, input().split())
    room_path_list[A].append(B)
    room_path_list[B].append(A)

q = deque()
q.append(1)

while len(q) > 0:
    start = q.popleft()
    for next_room in room_path_list[start]:
        if not room_reached[next_room]:
            room_reached[next_room] = True
            room_clue[next_room] = start
            q.append(next_room)

print("Yes")
for i in room_clue[2:]:
    print(i)


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int n, x, t; cin >> n >> x >> t;
        cout << t * ((n + x - 1) / x);
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3608
#include <iostream>

int main()
{
    int n, k, pat;
    std::cin >> n >> k;
    pat = k;
    for (int i = 0; (i < (n - 1)); ++i) {
        pat *= (k - 1);
    }
    std::cout << pat << std::endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')

def main():
  s = input()
  if s=='Sunny':
    print('Cloudy')
  elif s=='Cloudy':
    print('Rainy')
  else:
    print('Sunny')
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 5052
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string.h>
#include <cassert>
#include <string.h>
#include <tuple>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  rrep(i,n) for(int i=n-1;i>=0;i--)///n-1番目からn回
#define  REP(i,a,b) for(int i=a;i<=b;i++) ///a番目からb回
#define  RREP(i,a,b) for(int i=a;i<b;i--)
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pair_t;
#define MOD 1000000007

//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());
///*min_element(hoge.begin(),hoge.end();　最小値　　　最大値はmax_element();
///(10-(n%10))%10  10-(1桁目)取得 12->8 20->0

#define Ru(n)  ( ((n)+9)/10*10  ) //切りあげ
#define Rd(n)  ( ((n)-10)/10*10 +10 )	切り捨て


int gcd(int a,int b);
size_t length(const std::string& str) {
	return str.length();
}
bool comp(const pair_t &a, const pair_t &b) {
	return a.first < b.first;
}

int main() {
	int N;
	double ans;
	cin>>N;
	if(N%2==0)
		ans=1.0/2;
	else
		ans=((N+1)/2.0)/N;
	cout<<ans<<endl;

	return 0;

}


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


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7
S = sum(A)
S %= MOD
S2 = (S**2)%MOD 
M = 0
for i in range(N):
    M += A[i]**2
    M %= MOD
print((S2-M)*pow(2,MOD-2,MOD) %MOD)

Measured memory_bytes: 105284
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

struct Solver
{
	const int N;
	VI xs, ys, rs, cs;

	Solver( int n ) : N( n ), xs( n ), ys( n ), rs( n ), cs( n )
	{
		return;
	}

	operator int()
	{
		REP( i, 0, N )
		{
			cin >> xs[i] >> ys[i] >> rs[i] >> cs[i];
		}

		vector<bool> dp( 1 << N, false );
		dp[0] = true;

		int res = 0;
		REP( s, 0, dp.size() )
		{
			if ( !dp[s] )
			{
				continue;
			}

			res = max( res, bitCount( s ) );

			REP( i, 0, N )
			{
				if ( s & 1 << i )
				{
					continue;
				}
				REP( j, 0, i )
				{
					if ( ( s & 1 << j ) || cs[i] != cs[j] || covered( s, i ) || covered( s,j ) )
					{
						continue;
					}
					dp[ s | ( 1 << i ) | ( 1 << j ) ] = true;
				}
			}
		}

		return res;
	}

	bool covered( int s, int p )
	{
		REP( i, 0, p )
		{
			if ( s & 1 << i )
			{
				continue;
			}
			if ( sq( xs[i] - xs[p] ) + sq( ys[i] - ys[p] ) < sq( rs[i] + rs[p] ) )
			{
				return true;
			}
		}
		return false;
	}

	int sq( int n )
	{
		return n * n;
	}

	int bitCount( int bits )
	{
		int res = 0;
		REP( i, 0, 30 )
		{
			res += ( bits & 1 << i ) ? 1 : 0;
		}
		return res;
	}
};

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

	for ( int n; cin >> n, n; )
	{
		cout << Solver( n ) << endl;
	}

	return 0;
}

Measured memory_bytes: 3252
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] numbers = new long[n];
        
        int negativeNumberCount = 0;
        boolean zeroExists = false;
        long minNumber = 0;
        
        for (int i = 0; i < n; i++) {
            long num = sc.nextLong();
            
            if (i == 0) {
                minNumber = num;
            }
            if (num == 0) {
                zeroExists = true;
            } else if (num < 0) {
                negativeNumberCount++;
            }
            
            minNumber = Math.min(Math.abs(minNumber), Math.abs(num));
            numbers[i] = num;
        }
        
        if (minNumber > 0) {
            minNumber *= -1;
        }
        
        long answer = 0;
        for (long num : numbers) {
            answer += Math.abs(num);
        }
        
        if (!zeroExists && negativeNumberCount % 2 == 1) {
            answer += minNumber * 2;
        }
        
        System.out.println(answer);
    }
}

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

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	int mna = (A * 25 + 1) / 2, mnb = B * 10, mxa = ((A + 1) * 25 + 1) / 2, mxb = (B + 1) * 10;
	int mn = max(mna, mnb), mx = min(mxa, mxb);
	if(mn < mx)
		cout << mn << '\n';
	else
		cout << -1 << '\n';
}


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

ll Pow(ll a, ll b, ll c){
    ll ans = 1;
    a %= c;
    while (b){
        if (b & 1) ans = (ans * a) % c;
        a = (a * a) % c;
        b >>= 1;
    }
    return (ans % c);
}

bool cmp(const int &a, const int &b){
    return abs(a) < abs(b);
}

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

int main(){
    int n, l;
    scanf("%d%d", &n, &l);
    int a[205];
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i++)
        a[i] = l + i - 1;
    sort(a + 1, a + n + 1, cmp);
    int ans = 0;
    for (int i = 2; i <= n; i++)
        ans += a[i];
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))

d.sort()
t.sort()

flag = 0
ans = ["NO", "YES"]

lp = 0

for i in range(len(t)):  # 要求
    for j in range(lp, len(d)):  # 供給
        if (d[j] > t[i]):
            break
        elif (d[j] == t[i]):
            lp = j+1
            flag += 1
            break

print(ans[flag == len(t)])


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

int k;
int seq[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> k;
    cout << seq[k - 1];
    cin >> k;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    int N , M , C ;
    cin >> N >> M >> C ;
    int b[M] ;
    int a[M] ;

    for(int i =0 ; i < M ; i++){
        cin >> b[i] ;
    }
    
    int sum = 0;
    int count = 0;

    for(int j = 0; j < N ; j++){
        for(int k = 0; k < M ; k ++){
            cin >> a[k];
            sum += a[k]*b[k];
        }

        sum += C;
        if(sum > 0){
            count++;
        }

        sum = 0;
    }

    cout << count << endl;

    return 0;
}

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

long long MOD = 1e9+7;
int MAX_INT = 1e9;

long long H, W;
vector<vector<long long>> cost_map(1000+1, vector<long long>(1000+1, 0));

// 最大公約数
long long gcd(long long a, long long b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
// 最小公倍数
long long lcm(long long a, long long b) {
  return a / gcd(a, b) * b;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

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

  reverse(A.begin(), A.end());
  for(int i = 0; i < N; ++i) {
    sum_A[i+1] = sum_A[i] + A[i];
  }

  long long sum = 0;
  for(int i = 0; i < A.size()-1; ++i) {
    sum += (A[i+1]%MOD)*(sum_A[i+1]%MOD)%MOD;
    sum %= MOD;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 14292
n,k=gets.chomp.split.map(&:to_i)
h=gets.chomp.split.map(&:to_i)
dp=[]
dp[0]=0
for i in 1...n
  dp[i]=dp[i-1]+(h[i]-h[i-1]).abs
  for j in [i-k,0].max..i-2
    cost = dp[j]+(h[i]-h[j]).abs
    dp[i] = cost if dp[i] > cost
  end
end
puts dp[n-1]


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

int main() {
	int n,s;
	cin >> n;
	s=n%10+n/10%10+n/100%10+n/1000%10+n/10000%10
	  +n/100000%10+n/1000000%10+n/10000000%10+n/100000000%10
	  +n/1000000000%10;
	  if(n%s==0)
	  cout << "Yes" << endl;
	  else 
	  cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
 
using namespace std;
const int MOD = 1000000007;

struct UnionFind{
    vector<int> par;  // par[x] := x の親
    vector<int> rank; // rank[x] := x の ランク
    vector<int> size; // x 木のサイズ (x が根の時のみ)
private:
    void init(int n = 1){
        par.resize(n);
        rank.resize(n);
        size.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
 
public:
    UnionFind(int n = 1){
        init(n);
    }
    int Find(int x){
        if(par[x] == x) return x;
        int r = Find(par[x]);    //pathcompression
        return par[x] = r;
    }
    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    bool Union(int x, int y){
        x = Find(x);
        y = Find(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y);  // union by rank
        if(rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        size[x] = size[x] + size[y];
    }
    int getSize(int x){
        return size[Find(x)];
    }
};

int main(){

    int n, m; cin >> n >> m;
    UnionFind uf(n);
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
    }
    for(int i = 0; i < m; i++){
        int x, y; cin >> x >> y;
        x--;
        y--;
        uf.Union(p[x], p[y]);
    }
    
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(uf.same(i, p[i])) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
import bisect
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  S = input()[:-1]

  R = []
  G = []
  B = []
  for i in range(N):
    if S[i] == 'R':
      R.append(i+1)
    elif S[i] == 'G':
      G.append(i+1)
    elif S[i] == 'B':
      B.append(i+1)

  Rset = set(R)
  Gset = set(G)
  Bset = set(B)

  sum_ = 0
  for ri in R:
    for gi in G:
      if ri >= gi:
        continue
      idx = bisect.bisect_right(B, gi)
      if idx == len(B): continue
      sum_ += (len(B) - idx)
      if (2*gi - ri) in Bset:
        sum_ -= 1

  for ri in R:
    for gi in B:
      if ri >= gi:
        continue
      idx = bisect.bisect_right(G, gi)
      if idx == len(G): continue
      sum_ += (len(G) - idx)
      if (2*gi - ri) in Gset:
        sum_ -= 1

  for ri in G:
    for gi in R:
      if ri >= gi:
        continue
      idx = bisect.bisect_right(B, gi)
      if idx == len(B): continue
      sum_ += (len(B) - idx)
      if (2*gi - ri) in Bset:
        sum_ -= 1

  for ri in G:
    for gi in B:
      if ri >= gi:
        continue
      idx = bisect.bisect_right(R, gi)
      if idx == len(R): continue
      sum_ += (len(R) - idx)
      if (2*gi - ri) in Rset:
        sum_ -= 1

  for ri in B:
    for gi in R:
      if ri >= gi:
        continue
      idx = bisect.bisect_right(G, gi)
      if idx == len(G): continue
      sum_ += (len(G) - idx)
      if (2*gi - ri) in Gset:
        sum_ -= 1

  for ri in B:
    for gi in G:
      if ri >= gi:
        continue
      idx = bisect.bisect_right(R, gi)
      if idx == len(R): continue
      sum_ += (len(R) - idx)
      if (2*gi - ri) in Rset:
        sum_ -= 1

  print(sum_)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 75312
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  n %= 10;
  string ans = "hon";
  if(n==3) ans = "bon";
  else if(n==0||n==1||n==6||n==8) ans = "pon";
  cout << ans << endl;
}


Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <map>
#include <set>

int main()
{
  std::string S, T;
  std::cin >> S >> T;
  std::map<char, char> ST;
  std::set<char> check_double;
  bool can_make_T = true;
  for (int i = 0; i < S.size(); i++)
  {
    if (ST.count(S[i]))
    {
      if (ST.at(S[i]) != T[i])
      {
        can_make_T = false;
        break;
      }
    }
    else
    {
      ST[S[i]] = T[i];
      if (check_double.count(T[i]))
      {
        can_make_T = false;
        break;
      }
      check_double.insert(T[i]);
    }
  }
  if (can_make_T) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
}


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

using namespace std;

typedef long long ll;

const ll INF = 1e9;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	if (H % h == 0 && W % w == 0) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	int p = (H / h) * (W / w);
	int q = (H % h) * W + (W % w) * H - (H % h) * (W % w);
	int x = p / q + 1;
	vector< vector<ll> > a(H, vector<ll>(W, x));
	for (int i = h - 1; i < H; i += h) {
		for (int j = w - 1; j < W; j += w) {
			a[i][j] = -(h * w - 1) * x - 1;
		}
	}
	for (int i = 0; i < H; i++) {
		cout << a[i][0];
		for (int j = 1; j < W; j++) {
			cout << " " << a[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3328
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


n = int(input())
if n == 1:
    print(0)
    exit()

a = factorization(n)

ans = 0
for _, c in a:
    i = 1
    while True:
        if c >= i:
            ans += 1
            c -= i
            i += 1
        else:
            break
print(ans)


Measured memory_bytes: 63360
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int A, P;
	cin >> A >> P;

	cout << (A * 3 + P)/2 << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n,m;
    cin >> n >> m;
    vi a(n+1,0);
    while(m--){
        int t;
        cin >> t;
        a[t]++;
    }
    vi dp(n+1,0);
    dp[0] = 1;
    rep(i,n)loop(j,1,3){
        if(i+j > n || a[i+j])continue;
        dp[i+j] += dp[i];
        dp[i+j] %= MOD;
    }
    //rep(i,n+1)cout << " " << dp[i];cout << endl;
    cout << dp[n] << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, x, a, g = 0;
    cin >> n >> x;
    for (int i = 0; i < n; ++i)
    {
        cin >> a;
        g = __gcd(g, a - x);
    }
    cout << abs(g);
}


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

int main() {
    int n;
    while(cin >> n, n) {
        vector <bool> card(2 * n, false);
        rep (i, n) {
            int a;
            cin >> a;
            card[--a] = true;
        }

        vector <int> hanako, taro;
        rep (i, 2 * n) card[i] ? taro.push_back(i) : hanako.push_back(i);

        bool turn = true;
        int va = -1;
        while(!taro.empty() && !hanako.empty()) {
            vector <int> & dasuhou = turn ? taro : hanako;
            auto itr = upper_bound(dasuhou.begin(), dasuhou.end(), va);
            if (itr == dasuhou.end()) {
                va = -1;
            }
            else {
                va = *itr;
                dasuhou.erase(itr);
            }
            turn = !turn;
        }
        cout << hanako.size() << endl << taro.size() << endl;
    }
    return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> A(n);
    rep(i, n) cin >> A[i];
    bool dp[201010] = {0};
    for (int i = 0; i < k + 1; i++) {
        if(dp[i]) continue;
        for (int j = 0; j < n; j++) {
            dp[i + A[j]] = 1;
        }
    }
    cout << (dp[k] ? "First" : "Second") << endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

char str0[3005];
char str1[3005];
ll   dp[3005][3005];
int previ[3005][3005];
int prevj[3005][3005];

int main(int argc, char* argv[])
{
    scanf("%s%s", str0, str1);

    int len0=strlen(str0), len1=strlen(str1);
    int i,j;
    for(i=0; i<=len0; i++) dp[i][0]=1;
    for(j=1; j<=len1; j++) dp[0][j]=1;

    for(i=1; i<=len0; i++) {
        for(j=1; j<=len1; j++) {
            if(str0[i-1]==str1[j-1]) {
                dp[i][j]=1+dp[i-1][j-1];
                previ[i][j]=i-1;
                prevj[i][j]=j-1;
            }
            else {
                dp[i][j]=dp[i-1][j];
                previ[i][j]=i-1;
                prevj[i][j]=j;
                if(dp[i][j-1]>dp[i][j]) {
                    dp[i][j]=dp[i][j-1];
                    previ[i][j]=i;
                    prevj[i][j]=j-1;
                }
            }
        }
    }
    
    vector<char> z;
    i=len0, j=len1;
    while(i>0 && j>0) {
        int p = previ[i][j], q=prevj[i][j];
        if(p==i-1 && q==j-1) {
            z.push_back( str0[i-1] );
        }
        i=p, j=q;
    }
    reverse(z.begin(),z.end());
    z.push_back('\0');

    printf("%s\n", &z[0]);

    return 0;
}


Measured memory_bytes: 141312
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  int n, k;cin>>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int ans=INF;
  for(int i=0;i<n-k+1;i++){
    int r=a[i], l=a[i+k-1];
    if(r<0&&l<0){
      ans=min(ans, abs(r));
    }else if(r>0&&l>0){
      ans=min(ans, abs(l));
    }else{
      ans=min(ans, min(2*abs(l)+abs(r), 2*abs(r)+abs(l)));
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;

int main(){
	int R,G,B,N;
	cin >> R >> G >> B >> N;
	int k =0;
	for(int x=0;x<N+1;x++){
		if (R*x > N) break;
		for(int y=0;y<N+1;y++){
			if (R*x+G*y> N) break;
			if((N-R*x-G*y)%B==0){
				int z = (N-R*x-G*y)/B;
				if(R*x+G*y+B*z==N){
					k++;
				}
			}
		}
	}
	cout << k;
	cin >> k;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }

long long k;

int main() {
    cin >> k;
    int n = 50;
    vector<long long> a(50, 0);

    long long cnt = k/50;
    if(cnt == 0) {
        long long amari = k%50;
        for(int i = 0; i < amari; ++i) a.at(i) = 50;
    }else {
        int amari = k%50;
        for(int i = 0; i < 50; ++i) a.at(i) = 50+cnt-(amari+1);
        for(int i = 0; i < amari; ++i) a.at(i) += 51;
    }

    cout << 50 << endl;
    for(int i = 0; i < 50; ++i) {
        if(i == 49) cout << a.at(i) << endl;
        else cout << a.at(i) << " ";
    }
}

Measured memory_bytes: 256
x = str(input())
n = len(x)
stack = []
for i in range(n):
    if x[i] == 'S':
        stack.append('S')
    elif len(stack) == 0 or stack[len(stack) - 1] == 'T':
        stack.append('T')
    else:
        stack.pop()
print(len(stack))


Measured memory_bytes: 5092
W,H,x,y,r=map(int,raw_input().split())
if not(-100<=x and y<=100 and 0<W<=100 and 0<H<=100 and 0<r<=100):
    print("Constraits Errand")
    exit()
#elif x<=0 or y<=0 or  y-r<=H<=y+r or x-r<=W<=x+r or  y-r<=0<=y+r or x-r<=0<=x+r:
elif r<=x<=W-r and r<=y<= H-r:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 6432