akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


int t[100010], x[100010], y[100010];

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

    int n;
    cin >> n;
    reps(i, 1, n+1){
        cin >> t[i] >> x[i] >> y[i];
    }

    rep(i, n){
        int time = t[i+1] - t[i];
        int deltax = abs(x[i+1] - x[i]);
        int deltay = abs(y[i+1] - y[i]);
        if(time >= deltax + deltay && time%2 == (deltax+deltay)%2){
            continue;
        }else{
            ans(false);
            return 0;
        }
    }

    ans(true);

    return 0;
}

Measured memory_bytes: 1408
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

int main()
{
	int n, l;

	int app[201];
	int sum = 0;

	scanf("%d %d", &n, &l);

	for (int i = 1; i <= n; i++)
	{
		app[i] = l + i - 1;
		sum += app[i];
	}

	if (app[1] > 0)
		sum -= app[1];
	else if (app[n] < 0)
		sum -= app[n];

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 128
/*  ex9_1
    B30095    */
#include <stdio.h>
#include <stdlib.h>

// stack size
#define SIZE 1000

// definition of stack
typedef struct stack{
    int size;  // stack size
    int count; // number of data
    char data[SIZE];
    char *top;
} stack;

void print_stack_from_bottom(stack *stk);
void initialize_stack(stack *stk);
char pop(stack *stk);
void push(stack *stk, char elem);



int main(void){
    stack stk;
    char ch;

    initialize_stack(&stk);
    
    // process input with stack
    while(1){
        ch = getchar();
        if(ch == '\n' || ch == EOF || ch == '\0') break;  /// end loop if the end of input is reached

        if(ch == 'B'){
            if(stk.count > 0){
                pop(&stk);  // pop an element if backspace is entered and stack is not empty
            }
        }
        // push to stack if character other than backspace is entered
        else{
            push(&stk, ch);
        }
    }

    // print out the stack
    print_stack_from_bottom(&stk);

    return 0;
}

void print_stack_from_bottom(stack *stk){
    int i;
    for(i = 0; i < stk->count; i++){
        putchar(stk->data[stk->size - i - 1]);
    }
}

// initialize a stack to be empty
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);  // top is at the end of the array
}

// stack push operation
void push(stack *stk, char elem){
    if(stk->count >= stk->size){  // stack overflow
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{  // push an element
        stk->top--;
        *(stk->top) = elem;
        stk->count++;
    }
}

// stack pop operation
char pop(stack *stk){
    char latest;
    if(stk->count <= 0){  // stack underflow
        fprintf(stdout, "Error: stack underflow.\n");
        exit(1);
    }
    else{  // pop an element
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return latest;
    }
}

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


void solve(long long X){
    int dir = 0, cnt = 0;
    do
    {
        dir += X;
        cnt++;
    } while (dir % 360 != 0);
    cout << cnt << endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
#define pb push_back
#define int long long
//#define M 998244353
#define M 1000000007
using namespace std;
const int inf=4e18;
const int MX=100;
const int MN=-100;
const double pi=3.14159265358979;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int n;cin>>n;
	double dp[n+1][n+1];dp[0][0]=1;
	int i,j;
	for(i=1;i<=n;i++)
	{
		double p;cin>>p;
		for(j=0;j<=i;j++)
			dp[i][j]=(j==0?0:dp[i-1][j-1]*p)+(i==j?0:dp[i-1][j]*(1-p));
	}
	int k=n/2+1;
	double o=0;
	for(i=k;i<=n;i++)
		o+=dp[n][i];
	printf("%.15lf\n",o);
}

Measured memory_bytes: 70016
#include<bits/stdc++.h>
using namespace std;
vector<int>profit;
int w;
vector<int>*dp;
int knapsack(int w,vector<int>weight,vector<int>profit,int curr,int n)
{
    if(curr>=n||w==0)return 0;
    if(weight[curr]<=w)
    {
        //if(dp[w-weight[curr]]<profit[curr]+dp[w])
        if(dp[curr][w]==0)
        {
            int ans1=profit[curr]+knapsack(w-weight[curr],weight,profit,curr+1,n);
            int ans2=knapsack(w,weight,profit,curr+1,n);
            return dp[curr][w]=max(ans1,ans2);
        }
        else return dp[curr][w];
        
    }
    if(dp[curr][w]!=0) return dp[curr][w];
    else return dp[curr][w]=knapsack(w,weight,profit,curr+1,n);

}

int main()
{
    int n,w; 
    cin>>n>>w;
    dp=new vector<int>[n];
    vector<int>weight(n),profit(n);
    for(int i=0;i<n;i++)
    {
        cin>>profit[i];
        cin>>weight[i];
    }
    //cin>>w;
    ::w=w;
    dp=new vector<int>[n+1];
    for(int i=0;i<=n;i++)
    dp[i].resize(w+1);
    cout<<knapsack(w,weight,profit,0,n)<<endl;
    // for(int i=0;i<=n;i++)
    // {
    //     dp[i][0]=0;
    // }
    // for(int i=0;i<=w;i++)
    // {
    //     dp[0][i]=0;
    // }
    // for(int i=1;i<=n;i++)
    // {
    //     for(int j=1;j<=w;j++)
    //     {
    //         if(weight[i-1]<=j)
    //         {
    //             dp[i][j]=max(profit[i-1]+dp[i][j-weight[i-1]],dp[i-1][j]);
    //         }
    //         else 
    //         {
    //             dp[i][j]=dp[i-1][j];
    //         }
    //     }
    // }
    // cout<<dp[n][w]<<endl;
    // for(int i=0;i<=n;i++)
    // {
    //     for(int j=0;j<=w;j++)
    //     cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }

}


Measured memory_bytes: 7228
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i = 0; i < int(n); ++i)
#define ll long long int
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define MAX 100000000
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pl;
typedef vector<int>             vi;
typedef vector<ll>              vl;
typedef vector<pii>             vpii;
typedef vector<pl>              vpl;
typedef vector<vi>              vvi;
typedef vector<vl>              vvll;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
//=====================================================================================================
// CODE

int main() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        srand(chrono::high_resolution_clock::now().time_since_epoch().count());
        char c; cin >> c;
        if (c >= 65 && c <= 90)cout << 'A';
        else if (c >= 97 && c <= 122)cout << 'a';
        return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <queue>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    int n, m, a[310][310];

    cin >> n >> m;
    REP(i, n)
    REP(j, m)
    cin >> a[i][j];

    bool usin[310];
    fill(usin, usin + m + 1, false);
    bool used[310];
    fill(used, used + m + 1, false);
    int ind[310];
    fill(ind, ind + n, 0);

    priority_queue<P> q;

    int res = 1e9;

    map<int, int> mp;

    REP(i, m)
    {
        mp.clear();
        REP(j, n)
        {
            while (used[a[j][ind[j]]])
                ind[j]++;
            mp[a[j][ind[j]]]++;
            usin[a[j][ind[j]]] = true;
        }

        int ma = 0;
        int man = 0;

        int mas = 0;

        for (int j = 1; j <= m; j++)
        {
            if (!usin[j])
                continue;

            mas = max(mp[j], mas);

            if (ma < mp[j])
            {
                ma = mp[j];
                man = j;
            }
        }

        used[man] = true;
        usin[man] = false;

        res = min(res, mas);

        //cout << "#" << mas << " " << man << endl;
    }

    cout << res << endl;

    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    string a[n];
    set<string>s;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        s.insert(a[i]);
    }
    cout<<s.size()<<endl;
}


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

int main() {
    int N, Q; cin >> N >> Q;
    vector<vector<int>> adjlist(N, vector<int>());
    for (int i=0; i<N-1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }
    vector<int> counter(N, 0);
    for (int i=0; i<Q; i++) {
        int p, x;
        cin >> p >> x;
        counter[p-1] += x;
    }
    // dfs
    vector<bool> visited(N, false);
    queue<int> que;
    que.push(0);
    visited[0] = true;
    while (!que.empty()) {
        int node = que.front();
        que.pop();
        for (int child: adjlist[node]) {
            if (visited[child]) continue;
            counter[child] += counter[node];
            que.push(child);
            visited[child] = true;
        }
    }
    for (int i=0; i<N-1; i++) cout << counter[i] << " ";
    cout << counter[N-1] << endl;
}

Measured memory_bytes: 16600
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	int n;
	cin >> n;
	FOR(i, n + 1, 1)
	{
		if (i % 3 == 0)
		{
			cout << " " << i;
		}
		else
		{
			int k = i;
			while (k > 0)
			{
				if (k % 10 == 3)
				{
					cout << " " << i;
					break;
				}
				k /= 10;
			}
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3136
import sys
import queue


class MaxFlow:
    class Edge:
        def __init__(self, to, cap, rev):
            self.to, self.cap, self.rev = to, cap, rev

    def __init__(self, node_size, inf):
        self._node = node_size
        self._inf = inf
        self._level = [-1]*self._node
        self._iter = [0]*self._node
        self._graph = [[] for _ in range(self._node)]

    def add_edge(self, from_, to, cap):
        self._graph[from_].append(self.Edge(to, cap, len(self._graph[to])))
        self._graph[to].append(self.Edge(from_, 0, len(self._graph[from_])-1))

    def bfs(self, start):
        self._level = [-1]*self._node
        que = queue.Queue()
        self._level[start] = 0
        que.put(start)
        while not que.empty():
            cur_vertex = que.get()
            for e in self._graph[cur_vertex]:
                if e.cap > 0 > self._level[e.to]:
                    self._level[e.to] = self._level[cur_vertex] + 1
                    que.put(e.to)

    def dfs(self, cur_vertex, end_vertex, flow):
        if cur_vertex == end_vertex:
            return flow
        for e in self._graph[cur_vertex][self._iter[cur_vertex]:len(self._graph[cur_vertex])]:
            if e.cap > 0 and self._level[cur_vertex] < self._level[e.to]:
                flowed = self.dfs(e.to, end_vertex, min(flow, e.cap))
                if flowed > 0:
                    e.cap -= flowed
                    self._graph[e.to][e.rev].cap += flowed
                    return flowed
        return 0

    def solve(self, source, sink):
        flow = 0
        while True:
            self.bfs(source)
            if self._level[sink] < 0:
                return flow
            self._iter = [0]*self._node
            while True:
                f = self.dfs(source, sink, self._inf)
                if f == 0:
                    break
                flow += f

if __name__ == '__main__':
    n, m = map(int, sys.stdin.readline().split())
    mf = MaxFlow(n, 10**10)
    for _ in range(m):
        u, v, c = map(int, sys.stdin.readline().split())
        mf.add_edge(u, v, c)
    print(mf.solve(0, n-1))



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

using i64 = long long;
using u64 = unsigned long long;

const int mod = (int) 1e9+7;

void __print() {cerr << "]\n";}

template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}

#define dbg(x...) cerr << "[" << #x << "] = [", __print(x)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)

int main()
{
    int n;
    int a, b;
    int r = 0;
    scanf("%d", &n);
    while(n--) {
        cin >> a >> b;
        if(a == b) r++;
        else {
            if(r < 3) r = 0;
        }
    }
    if(r >= 3) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 3756
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		long[]A = new long[N];
		string[] str = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			A[i] = long.Parse(str[i]);
		}
		Array.Sort(A);
		string ans = "No";
		if(A[N-1]==0){
			ans = "Yes";
		} else if(N%3==0){
			if(A[N/3-1]==0 && A[N/3] == A[N-1]){
				ans = "Yes";
			} else if(A[0]==A[N/3-1] && A[N/3]==A[N*2/3-1] && A[N*2/3]==A[N-1]){
				long c = 1;
				long a1 = A[0];
				long a2 = A[N/3];
				long a3 = A[N*2/3];
				bool flag = true;
				for(var i=0;i<40;i++){
					if((a1/c%2+a2/c%2+a3/c%2)%2!=0){
						flag = false;
						break;
					} else {
                      	c *= 2;
                    }
				}
				if(flag){
					ans = "Yes";
				}
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 22496
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<vector<pair<int,int>>> v(n);
  int ai, xi, yi;
  for(int i=0; i<n; i++){
    cin >> ai;
    for(int j=0; j<ai; j++){
      cin >> xi >> yi;
      v[i].push_back(make_pair(xi,yi));
    }
  }

  vector<int> x(n);
  int ans = 0;
  int cor = 0;
  bool res;
  vector<bool> t(n);
  for(int i=0; i<pow(2,n); i++){
    
    for(int j=0; j<n; j++){
      if(((i>>j)&1) == 1){
        x[j] = 1;
      }else{
        x[j] = 0;
      }
    }
    res = true;  
    for(int j=0; j<n; j++){
      if(x[j]==1){
        for(vector<pair<int, int>>::iterator it = v[j].begin(); it != v[j].end(); it++){
          if(x[(*it).first-1] != (*it).second){
            res = false;
          }
        }
      }
    }

  
    if(res){
      cor = 0;
      for(int j=0; j<n; j++){
        if(x[j] == 1){
          cor += 1;
        }
      }    
    }
    ans = max(ans, cor);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
alpha2num = lambda c: ord(c) - ord('a') + 1
num2alpha = lambda c: chr(c+96)

s = input()
K = int(input())

N = len(s)
apos = [alpha2num(i) for i in s]

a = []
for i in apos[:-1]:
  diff = 27 - i
  if K >= diff and i != 1:
    K -= diff
    a.append(num2alpha(1))
  else:
    a.append(num2alpha(i))

# 残りのKを消化
lastw = (K + apos[-1] - 1) % 26 + 1
a.append(num2alpha(lastw))
print("".join(a))

Measured memory_bytes: 5748
package main
import "fmt"
func main(){
  var a, b, c, d int
  fmt.Scan(&a, &b, &c, &d)
  if abs(a, b) <= d && abs(b, c) <= d {
    fmt.Println("Yes")
  } else if(abs(a, c) <= d) {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}

func abs(a int, b int) int {
  if a - b < 0 {
    return b-a
  }else{
    return a-b
  }
}

Measured memory_bytes: 512
s=input()
a=s[0]
b=s[1]
c=s[2]
d=s[3]
if a==b and a!=c and c==d:
  print("Yes")
elif a!=b and a==c and b==d:
  print("Yes")
elif a!=b and a==d and b==c:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

typedef int itn;
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

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

    int n;
    cin >> n;
    ull pwr = 1;
    for (int i = 1; i <= n; ++i)
    {
        pwr *= i;
        pwr %= 1000000007;
    }
    cout << pwr << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

d = {}
zeros = 0

def gcd(a, b):
    while b != 0:
        a, b = b, a % b

    return a

MOD = int(1e9) + 7
p = [1] * (N + 1)
for i in range(N):
    p[i + 1] = p[i] * 2 % MOD
    a, b = map(int, input().split())
    if a == b == 0:
        zeros += 1
        continue
    a, b = a // abs(gcd(a, b)), b // abs(gcd(a, b))

    if a == 0:
        f, s = d.get((a, abs(b)), (0, 0))
        d[(a, abs(b))] = (f + 1, s)

    elif b == 0:
        f, s = d.get((b, abs(a)), (0, 0))
        d[(b, abs(a))] = (f, s + 1)

    elif (a < 0) ^ (b < 0):
        if a < 0:
            a, b = -a, -b
        f, s = d.get((abs(b), a), (0, 0))
        d[(abs(b), a)] = (f, s + 1)
    else:
        f, s = d.get((abs(a), abs(b)), (0, 0))
        d[(abs(a), abs(b))] = (f + 1, s)

ans = 1
for _, (f, s) in d.items():
    cnt = p[f] - 1
    cnt += p[s] - 1
    cnt += 1
    cnt %= MOD
    ans *= cnt
    ans %= MOD

ans -= 1
ans += MOD
ans += zeros
ans %= MOD
print(ans)


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


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

    int n; cin >> n;
    ll a,b;
    vector<pair<ll,ll>> p1(n), p2(n); rep(i,n){
        cin >> a >> b;
        p1[i] = make_pair(a,b);
        p2[i] = make_pair(a,b);
    }
    sort(p1.begin(), p1.end());
    sort(p2.begin(), p2.end(), [](pair<ll,ll> a, pair<ll,ll> b){
        if(a.second == b.second){
            return a.first < b.first;
        }else{
            return a.second < b.second;
        }
    });
    if(n%2){
        cout << p2[n/2].second - p1[n/2].first + 1 << endl;
    }else{
        cout << (p2[n/2].second + p2[n/2-1].second) - (p1[n/2].first + p1[n/2-1].first) + 1 << endl;
    }
}

Measured memory_bytes: 9524
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;

const int MAX_N=1e5+5;
int n,m;
int a[MAX_N];

int main()
{
	ios::sync_with_stdio(false);
	while(cin>>n){
		if(n==3||n==5||n==7)	cout<<"YES"<<endl;
		else	cout<<"NO"<<endl;
	}
	
	
	return 0;
}

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

using namespace std;

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

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

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

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

int main(void){
	ll n;
	cin >> n;
	int ans;
	for(ans=1;ans<=20;++ans) if(n<=pow(3,ans)) break;
	cout << ans << endl;
	return 0;
}

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

double x[3],y[3],xp,yp;
double EPS=1e-8;
int main(){
    while(scanf("%lf%lf",&x[0],&y[0])!=EOF){
        for(int i=1;i<3;i++)scanf("%lf%lf",&x[i],&y[i]);
        scanf("%lf%lf",&xp,&yp);

        double S=fabs((x[1]-x[0])*(y[2]-y[0])-(x[2]-x[0])*(y[1]-y[0]))/2;

        for(int i=0;i<3;i++){
            S-=fabs((x[i]-xp)*(y[(i+1)%3]-yp)-(x[(i+1)%3]-xp)*(y[i]-yp))/2;
        }

        if(fabs(S)<EPS)puts("YES");
        else puts("NO");
    }
    return 0;
}

Measured memory_bytes: 1200
while True :
    H, W = map(int, input().split())
    if H == 0 and W == 0 :
        break
    else :
        for i in range(H):
            if i%2 ==  0 :
                for j in range(W) :
                    if j == 0 :
                        a = "#"
                    elif j%2 == 0 :
                        a += "#"
                    else :
                        a += "."
                if i == H-1 :
                    print(a + "\n")
                else :
                    print(a)
            else :
                for j in range(W) :
                    if j == 0 :
                        a = "."
                    elif j%2 == 0 :
                        a += "."
                    else :
                        a += "#"
                if i == H-1 :
                    print(a + "\n")
                else :
                    print(a)



Measured memory_bytes: 5612
N=int(input())
NN=N//2
L=list(map(int,input().split()))
L.sort()
L+=[L[-1]+111]
j=-1
K=0
ans=0
for K in range(1,L[-2]+1):
  while L[j+1]<=K:
    j+=1
    
  if j+1==NN:
    ans+=1
print(ans)

Measured memory_bytes: 53020
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define mod 1000000007
#define eps 0.000000001
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define dbg(x) cout<<#x<<": "<<x<<endl;
const double PI = acos(-1.0);
using namespace std;

void cp()
{
    ll n,k;
    cin>>n>>k;
    ll rem = n%k;
    ll mi = min(rem, abs(k-rem));
    cout<<mi;
}

int main()
{
    FASTIO;
    int t;
    t=1;
    // cin>>t;
    while(t--)
    {
        cp();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long gcd(long long a, long long b){
    if(a%b == 0)return b;
    return gcd(b, a%b);
}
bool is_(long long x){
    for(long long i = 2; i*i <= x; i++){
        if(x%i == 0)return false;
    }
    return true;
}
int main(void){
    long long a, b, g, ans = 0;
    cin >> a >> b;
    g = gcd(a, b);
    for(long long i = 1; i*i <= g; i++){
        if(g%i == 0){
            if(is_(i))ans++;
            if(i*i != g && is_(g/i))ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(a) cout<<#a<<":"<<a<<endl;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll N=1e6+7;
const ll mod=1e9+7;
ll maxn,minn;
ll T,n,m;
ll arr[N];
ll sum[N];
ll dp[500][500];

int main(){
	ll a,len,flag;
	ll ans=0;
	memset(dp,INF,sizeof(dp));
	cin>>n;
	sum[0]=0;
	for(int i=1;i<=n;i++){
		scanf("%lld",arr+i);
		sum[i]=sum[i-1]+arr[i]; 
		dp[i][1]=0;
	}
	for(int i=2;i<=n;i++){
		for(int j=1;j<=n-i+1;j++){
			for(int k=1;k<i;k++){
				dp[j][i]=min(dp[j][i],dp[j][k]+dp[j+k][i-k]+sum[j+i-1]-sum[j-1]);
			}
		}
	}
	cout<<dp[1][n]<<endl;
	
	
	

	return 0;
}





Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod=1000000007;
constexpr ll INF=(1ll<<60);
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}

int main(){
    ll x;cin>>x;
    if(x>=30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
#include<cmath>
#define rep(i,j,k) for(register int i = j; i <= k; i++)
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define ll long long
using namespace std;

inline int read() { 
	int s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;
}

const int N = 1e5+5;
int n, k;
struct edge{ int to, nxt; } e[N<<1];
int ans = 0, head[N], cnt = 0;
inline void add(int x,int y) { 
	e[++cnt].to = y, e[cnt].nxt = head[x], head[x] = cnt;
	e[++cnt].to = x, e[cnt].nxt = head[y], head[y] = cnt;
}

int q[N], l = 0, r = 0, f[N], L[N], R[N], ti = 0, fa[N][20], dep[N], Log[N] = {-1}; 
#define ez(i,j) for(register int i = head[j]; i; i=e[i].nxt)
#define to e[i].to
inline void dfs(int x) { 
	L[x] = ++ti;
	ez(i,x) if( to != fa[x][0] ) dfs(to);
	R[x] = ti;
}
#define lower(x) (x & -x)
inline void upd(int x,int d) { 
	while( x <= n ) f[x] += d, x += lower(x);
}
inline int query(int x) { 
	int ret = 0;
	while( x ) ret += f[x], x -= lower(x);
	return ret;
}

inline void In(int x,int d) { ans += d; upd(L[x],1), upd(R[x]+1,-1); }
inline int Fa(int x,int y) { 
	while( y ) x = fa[x][Log[y]], y ^= (1<<Log[y]);
	return x;
}
inline bool check(int x,int y) { return query(L[x]) - query(L[y]); }

int main() { 
//	freopen("in.txt","r",stdin);
	n = read(), k = read();
	ans += (read() != 1);
	if( k > n ) return printf("%d\n", ans), 0;
	rep(i,2,n) add(i,read());
	rep(i,1,n) Log[i] = Log[i>>1] + 1;
	q[++r] = 1;
	int x;
	while( l < r ) { 
		x = q[++l];
		for(register int i = 1; dep[x] >= (1<<i); i++) fa[x][i] = fa[fa[x][i-1]][i-1];
		ez(i,x) if( to != fa[x][0] ) fa[q[++r] = to][0] = x, dep[to] = dep[x] + 1;
	}
	dfs(1);
	In(1,0);
	ez(i,1) In(to,0);
	dow(i,n,1) { 
		int x = q[i], y = Fa(x,k-1);
		if( check(x,fa[y][0]) ) continue;
		else In(y,1);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14976
R=3002
f=range(1,R)
G,*F=eval("eval('[0]*R,'*R),"*5)
for t in[*open(0)][1:]:r,c,v=map(int,t.split());G[r][c]=v
for r in f:
 for x in 1,2,3:
  for c in f:F[x][r][c]=max(F[x-1][r][c],max(F[x-1][r][c-1],(x<2)*F[3][r-1][c])+G[r][c],F[x][r][c-1])
print(F[3][-1][-1])

Measured memory_bytes: 445804
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = str(input())
i = 0
point = 0
L = [""]*N
for i in range(N):
  if T[i] == "r": 
    if i >= K and L[i-K] == "p":
      pass
    else:
      point += P
      L[i] = "p"
  elif T[i] == "s":
    if i >= K and L[i-K] == "r":
      pass
    else:
      point += R
      L[i] = "r"
  elif T[i] == "p":
    if i >= K and L[i-K] == "s":
      pass
    else:
      point += S
      L[i] = "s"
  else:
    break
print(point)

Measured memory_bytes: 4084
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N,M,X = LI()

    c = []
    s = []
    for _ in range(N):
        x = LI()
        c.append(x[0])
        s.append(x[1:])


    ans = INF
    for i in range(1,2**N):
        t = [0] * M
        b = 1
        cost = 0
        for j in range(N):
            if i & b:
                for k in range(M):
                    t[k] += s[j][k]
                cost += c[j]
            b <<= 1
        for x in t:
            if x < X: break
        else:

            ans = min(ans,cost)
    if ans < INF:
        print(ans)
    else:
        print(-1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 70652
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 1e6 +9;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf= 1e14;
ll mod = 1e9+7;
ll powm(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }

int main() {   
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
     
     ll q = 1;
     // cin>>q;
 
     while(q--){
          string s,t;cin>>s>>t;
          cout<<t+s;

     }
}         

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main() {
  int L;
  cin >> L;
  double sum=L*1.0/3.0;
  if(L%3==0){
    cout << setprecision(20) << sum*sum*sum << ".0000000000" <<endl;
  }
  else{
    cout << setprecision(20) << sum*sum*sum <<endl;
  }
  return 0;
}


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

int main()
{
    int X, N;
    cin >> X >> N;
    vector<bool> in(105, false);
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        in[a] = true;
    }
    int min = 10000000;
    int ans = 0;
    for (int num = 0; num <= 105; num++)
    {
        if (!in[num] && abs(num - X) < min)
        {
            min = abs(num - X);
            ans = num;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Programminng
{
    class AOJ_Volume0032
    {
        public static void Main(string[] args)
        {
            int count_1 = 0, count_2 = 0;

            while (true)
            {
                string s = Console.ReadLine();
                if (string.IsNullOrEmpty(s)) break;

                string[] _s = s.Split(',');
                int len1 = int.Parse(_s[0]);
                int len2 = int.Parse(_s[1]);
                int len3 = int.Parse(_s[2]);

                if (len3 * len3 == len1 * len1 + len2 * len2) count_1++;
                if (len1 == len2) count_2++;
            }

            Console.WriteLine(count_1);
            Console.WriteLine(count_2);
            
        }
    }
}

Measured memory_bytes: 5600
import java.io.*;
import java.util.*;
import java.awt.Point;
public class Main {
	static Scanner sc;
	static PrintWriter out;
	static final int uncal = -1;
	static final int mod = (int) (1e9)+7;
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in); 
		out = new PrintWriter(System.out);
		int n = sc.nextInt()%1000;
		if(n > 0)
			n = 1000-n;
		out.println(n);
		out.close();
	}
}

Measured memory_bytes: 35772
//=================================
// Created on: 2018/09/19 15:36:13
//=================================
#include <bits/stdc++.h>
using ld = long double;
constexpr ld PI = 3.14159265359;
int main()
{
    ld a, b;
    std::cin >> a >> b;
    std::cout << std::fixed << std::setprecision(15) << b * b * b * 4 / 3 * PI << std::endl;
    return 0;
}



Measured memory_bytes: 3292
program train;
var 
    n, i : longint;
    sum : Int64;
begin
    read(n);
    sum := 0;
    for i := 1 to n do 
        if not ((i mod 3) = 0) and not ((i mod 5) = 0)
            then sum := sum + i;
    write(sum);
end.    

Measured memory_bytes: 1344
package main

import "fmt"

var N, A, B, C int
var ls []int

func main() {
	fmt.Scan(&N, &A, &B, &C)
	ls = make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&ls[i])
	}
	fmt.Println(dfs(0, 0, 0, 0))
}

func dfs(i, a, b, c int) int {
	if i == N {
		if a*b*c == 0 {
			return 3000
		}
		return Abs(A-a) + Abs(B-b) + Abs(C-c) - 30
	}
	return Min(
		10+dfs(i+1, a+ls[i], b, c),
		10+dfs(i+1, a, b+ls[i], c),
		10+dfs(i+1, a, b, c+ls[i]),
		dfs(i+1, a, b, c),
	)
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}


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

W, H, x, y = MAP()

print(W*H/2, end="")
print(" ", end="")

if x == W/2 and y == H/2:
	print(1)
else:
	print(0)


Measured memory_bytes: 5144
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using Point = std::pair<double, double>;

double dist(const Point& a, const Point& b) {
  double x_diff = a.first - b.first;
  double y_diff = a.second - b.second;
  return std::sqrt(x_diff * x_diff + y_diff * y_diff);
}

int main() {
  uint32_t A = 0, B = 0, H = 0, M = 0;
  std::cin >> A >> B >> H >> M;

  const double PI = std::acos(-1);
  double theta_h = -2 * PI / 12 * H;
  double theta_m = -2 * PI / 60 * M;
  Point hour(A * std::cos(theta_h + theta_m / 12),
             A * std::sin(theta_h + theta_m / 12));
  Point min(B * std::cos(theta_m), B * std::sin(theta_m));

  std::cout << std::fixed << std::setprecision(20) << dist(hour, min)
            << std::endl;

  return 0;
}

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

#define ll long long
#define rep(i,N) for(ll i=0; i<N; i++)
const int mx = 2e5;

int main(void){
  ll N,M;
  cin >> N >> M;
  ll A[M];
  rep(i,M){
    cin >> A[i];
  }
  
  ll sum = 0;
  rep(i,M){
    sum += A[i];
  }
  
  if(sum > N){
    cout << -1;
  }else{
    cout << N-sum;
  }
  

  return 0;
}

Measured memory_bytes: 3712
let inputs = readLine()!.split(separator: " ").map { Int($0)! }
var (A, B, C, D) = (inputs[0], inputs[1], inputs[2], inputs[3])

while true {
    C -= B
    if C <= 0 {
        break
    }
    
    A -= D
    if A <= 0 {
        break
    }
}

print(A <= 0 ? "No" : "Yes")


Measured memory_bytes: 8216
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> isPair;
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
#define Pll pair<ll,ll>
#define vpll vector<pll>
#define sll set<ll>
#define mll map<ll,ll>

const ll inf=(ll)1e18;
const ll maxs = (ll)50;
const ll mod = (ll)1e9+7;
const ll oo = (ll) 1e18;

#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define LB lower_bound
#define UB upper_bound
#define line cout<<endl;
#define fr(i,a,b) for(int i=a;i<=b;++i)
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mst(x,a) memset(x,a,sizeof(x))

ll getPow(ll num, ll pow) {
    ll res = 1;
    num %= mod;
    while(pow) {
        if(pow & 1)
            res = (res * num) % mod;
        num = (num * num) % mod;
        pow >>= 1;
    }
    return res;
}

ll INV(ll num) {
    num %= mod;
    return getPow(num, mod - 2);
}

ll n;
ll a[maxs][maxs];
ll dp[(1<<21)+5][22];
ll mask_all;

ll go(ll mask,ll pos)
{
    if(pos==n&&mask==mask_all)
     {
         return 1;
     }
    if(pos==n+1)
        return 0;
    if(mask==mask_all)
        return 0;
    if(dp[mask][pos]!=-1)
        return dp[mask][pos];
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        //cout<<(!(mask&(1<<i)));
        if(a[pos][i]&&(!(mask&( 1<<i))))
        {
            ans = (ans + go(mask|(1<<i),pos+1))%mod;
        }    
    }
    //cout<<ans<<" ";
    return dp[mask][pos] = ans;
    
}

int main() 
{
    fastio();
	ll t=1;
    //cin>>t;
    while(t--)
	{
        cin>>n;
        for(ll i=0;i<n;i++)
            for(ll j=0;j<n;j++)
                cin>>a[i][j];
        mask_all = (1<<n) -1 ;
        memset(dp,-1,sizeof dp);
        cout<<go(0,0);        
    }
	
	return 0;
}

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

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

    char c[2][3];
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 3; j++) cin >> c[i][j];
    }

    if (c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
  int n, m, ans = 0;
  cin >> n >> m;
  vector<int> x(m);
  vector<int> len(m);

  for(int i = 0; i < m; ++i){
    cin >> x.at(i);
  }
  if(n >= m){
    cout << 0 << endl;
    return 0;
  }

  sort(x.begin(), x.end());
  for(int i =0; i < m -1; ++i){
    len.at(i) = x.at(i + 1) - x.at(i);
  }
  sort(len.begin(), len.end());
  reverse(len.begin(), len.end());


  ans = x.at(m - 1) - x.at(0);


  for(int i = 0; i < n - 1; ++i){
    ans -= len.at(i);
  }

  cout << ans << endl;

}


Measured memory_bytes: 1024
n, q = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)

class FeTree
    def initialize(n)
        @n = n
        @f = Array.new(@n+1,0)
    end

    def add1(i)
        while i <= @n
            @f[i] += 1
            i += i & -i
        end
    end

    def sum(i)
        s = 0
        while i > 0
            s += @f[i]
            i &= i-1
        end
        s
    end
end

klr = q.times.map {|i| [i] + gets.split.map(&:to_i)}.sort_by!{|k,l,r| r}
f = FeTree.new(n)
m = Array.new(n)
ans = Array.new(q)
i = 0
klr.each do |k,l,r|
    while i < r
        f.add1(m[c[i]]) if m[c[i]]
        m[c[i]] = i += 1
    end

    ans[k] = r - l + 1 - f.sum(r) + f.sum(l-1)
end

puts ans

Measured memory_bytes: 68528
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(
			new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		int k = Integer.parseInt(input[0]);
		int s = Integer.parseInt(input[1]);
		int x=0;
		int y=0; 
		int z=0;
		int count = 0;

		for(int i = 0; i <= k;i++){
			x = i;
			for(int j = 0; j <= k; j++){
				y = j;
				int rest = s-x-y;
				if(rest >= 0 && rest <= k){
					count++;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21332
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion

//ABC  103-C Modulo summation

int main(void) {
	int     i,n,a;
	long    sum=0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a);
		sum += a;
	}
	printf("%d\n",sum - n);
    
	return 0;
}


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

int main(){
  int n,m,x;
  cin>>n>>m>>x;
  int y=x;
  vector<int> a(m);
  for(int i=0;i<m;i++){
    cin>>a[i];
  }
  int cost=0;
  for(int i=0;i<n-x;i++){
    y++;
    for(int j=0;j<m;j++){
    if(y==a[j]) cost++;
    }
  }
  int sum=0;
  y=x;
  for(int i=0;i<x;i++){
    y--;
    for(int j=0;j<m;j++){
    if(y==a[j]) sum++;
    }
  }
  cout<<min(sum,cost)<<endl;
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 1e6+20;
ll a[maxn],b[maxn],c[maxn];

int main()
{
    ll n;
    scanf("%lld",&n);
    for(int i = 0 ; i < n ; i ++) scanf("%lld",&a[i]);
    for(int i = 0 ; i < n ; i ++) scanf("%lld",&b[i]);
    for(int i = 0 ; i < n ; i ++) scanf("%lld",&c[i]);
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    ll ans = 0;
    ll numa = 0,numc = 0;
    for(int i = 0 ; i < n ; i ++)
    {
        for(int j = 0 ; a[numa] < b[i] && numa < n ; j ++) numa ++;
        for(int j = 0 ; c[numc] <= b[i] && numc < n ; j ++) numc ++;
        ans += numa*(n-numc);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 9088
N, M = map(int, input().split())
A = set(i//2 for i in map(int, input().split()))
B = []
for i in A:
	B = B + [0]
	while i % 2 == 0:
		i //= 2
		B[-1] += 1
if len(set(B)) == 1:
	m = max(A)
	A.remove(m)
	base = 0
	for i in range(m,M+1,2*m):
		semi = True
		for j in A:
			if i % j != 0 or (i // j) % 2 == 0:
				semi = False
				break
		if semi:
			base = i
			break
	if base == 0:
		print(0)
	else:
		print(((M // base) + 1)//2)
else:
	print(0)

Measured memory_bytes: 11508
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

ll wa(ll n, ll d){
    return (n*(2*d+(n-1)*d))/2;
}

int main(){
    int n; cin >> n;
    ll ans=0;
    rep(i,n){
        ll matu=n/(i+1);
        ans+=wa(matu,i+1);
    }
    cout << ans << endl;
return 0;
}


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

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

ll dp[100005][13];

int main()
{
    string s; cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        if(s[i] != '?'){
            int tmp = s[i] - '0';
            for(int j = 0; j < 13; j++){
                dp[i+1][(10*j+tmp)%13] += dp[i][j];
                dp[i+1][(10*j+tmp)%13] %= mod;
            }
        }else{
            for(int j = 0; j < 13; j++){
                for(int k = 0; k < 10; k++){
                    dp[i+1][(10*j+k)%13] += dp[i][j];
                    dp[i+1][(10*j+k)%13] %= mod;
                }
            }
        }
    }
    cout << dp[n][5] << endl;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
 
using namespace std;
 
#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
 
 
 
 
int main(){
	int a, b;
	cin >> a >> b;
	if(b == 100) b++;
	if(a == 0) cout << b << endl;
	else if(a == 1) cout << b*100 << endl;
	else cout << b*10000 << endl; 
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int number[26];
int main() {
	string s;
	cin>>s;
	for(int i=0;i<4;i++)
		number[s[i]-'A']++;
	int num=0;
	for(int i=0;i<26;i++) {
		if(number[i]!=0)
			if(number[i]!=2) {
				cout<<"No"<<endl;
				return 0;
			}
			else num++;
	}
	if(num==2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    int sum = 0;
    int cnt = 0;
    vint a(n);
    REP(i,n){
        cin >> a[i];
        sum+=a[i];
    }
    REP(i,n){
        if(a[i]*4*m>=(sum))cnt++;
    }
    if(cnt>=m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,c,aa,bb,cc;
ll k;
int main(){
	scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
	if(abs(a-b)>1e18){
		puts("Unfair");
		return 0;
	}
	if(k&1){
		printf("%lld",b-a);
		return 0;
	}
	printf("%lld",a-b);
	return 0;
}

Measured memory_bytes: 256
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque


def main():
    s = list(input())
    aaa = ['R', 'U', 'D']
    bbb = ['L', 'U', 'D']

    flg = 1
    for i in range(len(s)):
        if i % 2:
            if s[i] not in bbb:
                flg = 0
        else:
            if s[i] not in aaa:
                flg = 0

    if flg:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384