akhauriyash/Code-Regression huggingface dataset:
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    final int N;
    Map<Integer, Long> memo;

    AtCoder(FastScanner sc) {
        N = sc.nextInt();
        memo = new HashMap<>();
    }

    void solve(PrintWriter out) {
        memo.put(0, 2L);
        memo.put(1, 1L);
        out.println(lucas(N));
    }

    long lucas(int n) {
        return memo.computeIfAbsent(n, i -> lucas(i - 1) + lucas(i - 2));
    }
}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 29908
N, K = map(int, input().split())

mod0, mod1 = 0, 0
for i in range(1, N+1):
    if i % K == 0:
        mod0 += 1
    elif i % K == K//2:
        mod1 += 1
        
if K%2 == 0:
    ans = mod0**3 + mod1**3
    print(ans)
else:
    ans = mod0**3
    print(ans)

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

int main(){
	int n;
	cin >> n;
	vector<int> data(n);
	int count = 0;
	for(auto &a:data){
		cin >> a;
	}
	for(int i = 0; i < n; i++){
		for(int j = n - 1; j > i; j--){
			if(data[j] < data[j-1]){
				swap(data[j],data[j-1]);
				count++;
			}
		}
	}
	for(int i = 0; i < n; i++){
		if(i!=0) cout << " ";
		cout << data[i];
	}
	cout << endl;
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3080
N, A, B, C, D = list(map(int, input().split()))
S = input()

A -= 1
B -= 1
C -= 1
D -= 1

right_end = max(C, D)
S = S[A:right_end+1]

ans = True
if A < B < C < D:
    if S.count('##'):
        ans = False
elif A < C < B < D:
    if S[A:C+1].count('##') or S[B:D+1].count('##'):
        ans = False
else:
    if S.count('##'):
        ans = False
    elif S[B:D+2].count('...'):
        pass
    elif S[B-1:B+2] == '...':
        pass
    else:
        ans = False

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

# print(S)
# print(iwaiwa)
# print(S[B-1:B+2])


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

int main() {
    int N;
    cin >> N;
    int maxnum;
    int Max;
    int minnum;
    int Min;

    int a,b;
    cin >> a >> b;
    maxnum = a;
    Max = b;
    minnum = a;
    Min = b;

    for(int i=1; i<N; i++) {
        int a,b;
        cin >> a >> b;
        if(a < maxnum) {
            maxnum = a;
            Max = b;
        } else if(a > minnum) {
            minnum = a;
            Min = b;
        }
    }

    int ans = minnum - maxnum + 1;
    ans += maxnum - 1;
    ans += Min;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
N, D = list(map(int, input().split()))

x = [0 for i in range(N)]
for i in range(N):
    x[i] = np.array(list(map(int, input().split())))

count = 0
for i in range(N):
    t = N - i - 1
    
    for j in range(t):
        vec = np.sqrt(np.power(x[t] - x[j], 2).sum())
        count = count + 1 if vec % 1.0 == 0.0 else count

print(count)

Measured memory_bytes: 12508
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int age = input.nextInt();
        int cost = input.nextInt();
        AtCoder_Beginner_127_Task_A atCode_127_A = new AtCoder_Beginner_127_Task_A();
        System.out.println(atCode_127_A.calFee(age,cost));
    }
}

class AtCoder_Beginner_127_Task_A{
    public int calFee(int age, int cost){
        
        if(age <= 5)
            return 0;
        
        if(age <=12)
            return cost/2;
        
        return cost;
        
    }
}

Measured memory_bytes: 21844
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	while ( stdin.hasNextInt() ) {
	    int[] in = new int[4];
	    int[] think = new int[4];

	    for ( int j = 0; j < 4; j++ ) {
		in[j] = stdin.nextInt();
	    }
	    for ( int j = 0; j < 4; j++ ) {
		think[j] = stdin.nextInt();
	    }
	    
	    int hit = 0;
	    int brow = 0;
	    for ( int i = 0; i < 4; i++ ) {
		if ( in[i] == think[i] ) {
		    hit++;
		} else if ( contains( in[i], think ) ) {
		    brow++;
		}
	    }
	    System.out.printf( "%d %d\n", hit, brow );
	}	   
    }

    static boolean contains( int num, int[] array ) {
	for ( int i : array ) {
	    if ( num == i ) {
		return true;
	    }
	}
	return false;
    }
    
}

Measured memory_bytes: 16320
#include <iostream>

using namespace std;

#define int long long

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

signed main(){
    int X;
    cin >> X;
    for(int A=-1000;A<=1000;A++){
        for(int B=-1000;B<=1000;B++){
            if(pow(A)-pow(B) == X){
                cout << A << " " << B <<endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " = " << x << ", ";
#define ll long long
#define pb push_back
using namespace std;
#define FAST_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
const int INF = 1e9 + 7;

int main()
{
    FAST_IO
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int &a : v)
    {
        cin >> a;
    }
    vector<int> dp(n, INF);
    dp[0] = 0;
    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j <= k && i-j >=0; j++)
        {
            dp[i] = min (dp[i], dp[i-j] + abs(v[i]-v[i-j]));
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
import sys


def input():
    return sys.stdin.readline().rstrip()



def main():
    N = int(input())

    dp = [0] * (N + 1)
    rt = int(N ** 0.5) + 1
    for i in range(1, rt):
        ii = i ** 2
        for j in range(1, rt):
            iji = ii + j **2 + i * j

            if iji + 1 + i + j > N:
                break
            for k in range(1, rt):
                case = iji + k**2 + i * k + j * k
                if case <= N:
                    dp[case] += 1
                else:
                    break

    print(*dp[1:N + 1], sep="\n")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9608
#include<iostream>
#include<fstream>
#include<vector>
#include<initializer_list>
#include<string>
using namespace std;
  int main(){
 int A;
 cin >> A;
 int B;
 cin >>B;
 int C;
 cin >>C;

 if (A==5 && B==7 && C==5) 
 {cout << "YES" << endl;}
 else if (A==7 && B==5 && C== 5)
  {cout << "YES" << endl;}
  else if (A==5 && B==5 && C==7)
   {cout << "YES" << endl;}
   else {cout << "NO"<< endl;}}

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

const int64_t MOD = 1e9 + 7;
struct mint
{
    int64_t x;
    mint(int64_t x = 0) : x((x % MOD + MOD) % MOD) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= MOD)
            x -= MOD;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += MOD - a.x) >= MOD)
            x -= MOD;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(int64_t n) const
    {
        if (n == 0)
            return 1;
        mint t = pow(n >> 1);
        t *= t;
        if (n & 1)
            t *= *this;
        return t;
    }
    mint inv() const { return pow(MOD - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};

bool check(int N, vector<int> cnt)
{
    for (int i = 0; i < N; i++)
    {
        if (N % 2 == 0 && i % 2 == 0)
        {
            if (cnt.at(i) != 0)
                return false;
        }
        else if (N % 2 == 0 && i % 2 != 0)
        {
            if (cnt.at(i) != 2)
                return false;
        }
        else if (N % 2 != 0 && i == 0)
        {
            if (cnt.at(i) != 1)
                return false;
        }
        else if (N % 2 != 0 && i % 2 == 0)
        {
            if (cnt.at(i) != 2)
                return false;
        }
        else
        {
            if (cnt.at(i) != 0)
                return false;
        }
    }
    return true;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }

    vector<int> cnt(N);
    for (auto &&Ai : A)
    {
        cnt.at(Ai)++;
    }
    if (!check(N, cnt))
    {
        cout << 0 << endl;
        return 0;
    }
    cout << mint(2).pow(N / 2).x << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
 
int main(){
int a[7]={1,3,5,7,8,10,12};
int b[4]={4,6,9,11};
int c=2,i;
int x,y,flagx=0,flagy=0;
scanf("%d %d",&x,&y);
for(i=0;i<6;i++){
if(a[i]==x)flagx=1;
if(a[i]==y)flagy=1;
}
for(i=0;i<4;i++){
if(b[i]==x)flagx=2;
if(b[i]==y)flagy=2;
}
if(flagx==flagy){printf("Yes");}
else{printf("No");
}
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long H,W;
    string S[100];
    cin >> H>>W;
    for (int i = 0; i < H; i++) {
        cin >>S[i];
    }
    bool ok=true;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if(S[i][j]=='#'){
                bool ok_tmp=false;
                if(j-1>=0){
                    if(S[i][j-1]=='#'){
                        ok_tmp=true;
                    }
                }
                if(j+1<W){
                    if(S[i][j+1]=='#'){
                        ok_tmp=true;
                    }
                }
                if(i+1<H){
                    if(S[i+1][j]=='#'){
                        ok_tmp=true;
                    }
                }
                if(i-1>=0){
                    if(S[i-1][j]=='#'){
                        ok_tmp=true;
                    }
                }
                if(!ok_tmp){
                    ok=false;
                    i=H;
                    j=W;
                }
            }
        }
    }


    if(ok){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}


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

int main(){
    ll t, m;
    cin>>t>>m;
    ll a[t];
    for(ll i = 0;i<t;i++){
        cin>>a[i];
    }
    sort(a, a+t);
    ll k = 0;
    ll ans = 0;
    for(ll i = 0;i<t;i++){
        if(a[i] <= m){
            m -= a[i];
            ans++;
            k++;
        } else {
            break;
        }
    }
    if(k == t && m != 0){
        cout<<ans -1<<endl;
    } else {
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class UnionFind{
  int n;
  vector<int> data;
public:
  UnionFind(int _n):n(_n),data(_n,-1){}
  bool link(int a, int b){ //if new link, then true.
    int ra=find_root(a);
    int rb=find_root(b);
    if(ra!=rb){
      if(data[rb]<data[ra]) swap(ra,rb);
      data[ra]+=data[rb];
      data[rb]=ra;
    }
    return (ra!=rb);
  }
  bool check(int a, int b){ //if same set, then true.
    return (find_root(a)==find_root(b));
  }
  int find_root(int a){
    return ((data[a]<0)?a:(data[a]=find_root(data[a])));
  }
};

int N, M, K;
vector<int> follow[100005];
vector<int> block[100005];


int main(){
  cin >> N >> M >> K;

  UnionFind uf(N+10);
  
  rep(i,M){
    int a, b;
    cin >> a >> b;
    follow[a].push_back(b);
    follow[b].push_back(a);
    uf.link(a,b);
  }
  rep(i,K){
    int c, d;
    cin >> c >> d;
    block[c].push_back(d);
    block[d].push_back(c);
  }

  unordered_map<int,int> cnt;
  REP(i,1,N+1){
    cnt[uf.find_root(i)]++;
  }

  vector<int> ans;
  REP(i,1,N+1){
    int ret = cnt[uf.find_root(i)] - 1 - follow[i].size();
    rep(j,block[i].size()){
      if(uf.find_root(i) == uf.find_root(block[i][j])) ret--;
    }
    ans.push_back(ret);
  }

  rep(i,ans.size()){
    if(i>0) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  
  return 0;
}


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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

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

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input();
    map< int, int > cnt;
    range(i, 0, N) {
        cnt[input()]++;
    }
    
//    vector< int > A(N);
//    cin >> A;
    
    int ans = 0;
    int even_cnt = 0;
//    for (auto a: A) even_cnt += !(a & 1);
    for (auto p: cnt) {
        ans++;
        even_cnt += !(p.second & 1);
    }
    
    ans -= (even_cnt & 1);

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n, m;
ll a[maxn];

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

  cin>>n>>m;
  for (int i=0; i<n; i++) {
    cin>>a[i];
    a[i] = a[i] / 2;
  }


  
  ll lcm = a[0];
  for (int i=1; i<n; i++) {
    lcm = lcm/__gcd(lcm,a[i])*a[i];
  }

  ll x = 60;
  for (int i=0; i<n; i++) {
    int p = 0;
    while (a[i]%2==0) {
      p++;
      a[i] = a[i]/2;
    }
    x = min(x, 1LL*p);
  }
  assert(x < 60);



  {
    ll lp = 0;
    ll y = lcm;
    while (y%2==0) {
      y=y/2;
      lp++;
    }
    if (lp != x) out(0);
  }


  //odd multiples of lcm
  ll ans = (m / lcm) - (m / (lcm*2));
  cout<<ans<<endl;
  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
vector<int> to[200000];
vector<int> ans;
void dfs(int v,int p=-1){
  for(auto next_v:to[v]){
    if(next_v==p)continue;
    ans[next_v]+=ans[v];
    dfs(next_v,v);
  }
}
int main(){
  int n ,q;
  cin>>n>>q;
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  for(int i=0;i<q;i++){
    int p,x;
    ans.resize(q);
    cin>>p>>x;
    p--;
    ans[p]+=x;
  }
  dfs(0);
  for(int i=0;i<n;i++){
    cout<<ans[i]<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 23552
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <set>
#include <map>
#include <complex>
#include <iostream>
#include <time.h>
#include <stack>
#include <stdlib.h>
#include <memory.h>
#include <bitset>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <vector>

using namespace std;

const int MaxN = 2e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
//  freopen("input.txt", "r", stdin);
  string s;
  cin >> s;
  for (int i = 0; i < 12; ++i) {
    cout << s[i];
    if (i == 3) {
      cout << ' ';
    }
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main(){
	FIO
	
	string s;
	cin >> s;
	if((s[0] == s[1] && s[0] == s[2]) || (s[1] == s[2] && s[1] == s[3]))puts("Yes");
	else puts("No");
 	return 0; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)

void solve(){
    ll n;
    cin>>n;
    string s[n];
    ll c0 = 0, c1 = 0, c2 = 0, c3 = 0;
    loop(i,0,n){
        cin>>s[i];
        if(s[i] == "AC") c0++;
        else if(s[i] == "WA") c1++;
        else if(s[i] == "TLE") c2++;
        else if(s[i] == "RE") c3++;
    }
    print("AC x "<<c0);
    print("WA x "<<c1);
    print("TLE x "<<c2);
    print("RE x "<<c3);
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        start_routine();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
        
    #ifndef ONLINE_JUDGE
        end_routine();
    #endif
}


Measured memory_bytes: 6784
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define N 200001
#define NI NULL

typedef struct node{
	int key;
	int pri;
	struct node *right , *left;
}Node;

Node * Delete(Node **,int);
Node * del(Node **,int);

int find(Node *p,int x)
{
	while(p!=NI)
	{
		if(p->key==x)return 1;
		else if(p->key > x)p = p->left;
		else p = p->right;
	}
	return 0;
}

void inorder(Node *a)
{
	if(a->left!=NI) inorder(a->left);
	printf(" %d",a->key);
	if(a->right!=NI) inorder(a->right);
	return;
}

void preorder(Node *p)
{
	printf(" %d",p->key);
	if(p->left!=NI) preorder(p->left);
	if(p->right!=NI) preorder(p->right);
	return;
}

void print(Node *p)
{
	inorder(p);
	printf("\n");
	preorder(p);
	printf("\n");
	return;
}

Node * makenode(int x , int y)
{
	Node *new = malloc(sizeof(Node));
	new->key = x;
	new->pri = y;
	new->left = NI;
	new->right = NI;
	return new;
}

Node *rightRotate(Node *p)
{
	Node *q = p->left;
	p->left = q->right;
	q->right = p;
	return q;
}

Node *leftRotate(Node *p)
{
	Node *q = p->right;
	p->right = q->left;
	q->left = p;
	return q;
}

Node* insert(Node **t , int key, int pri)
{
	Node *new;
	if((*t)==NI)
	return new = makenode(key,pri);
	if((*t)->key == key)
	return *t;

	if(key < (*t)->key)
	{
		(*t)->left = insert(&(*t)->left,key,pri);
		if((*t)->pri < (*t)->left->pri)
		(*t) = rightRotate(*t);
	}
	else{
		(*t)->right = insert(&(*t)->right,key,pri);
		if((*t)->pri < (*t)->right->pri)
		(*t) = leftRotate((*t));
	}
	return *t;
}

Node * Delete(Node **t , int key)
{
	if((*t)==NI){return NI;}
	if(key < (*t)->key){(*t)->left = Delete(&((*t)->left),key);}
	else if(key > (*t)->key){(*t)->right = Delete(&((*t)->right),key);}
	else{ return del(t,key);}
	return *t;
}

Node * del(Node **t , int key)
{
	if((*t)->left == NI && (*t)->right == NI){return NI;}
	else if((*t)->left == NI){(*t) = leftRotate(*t);}
	else if((*t)->right ==NI){(*t) = rightRotate(*t);}
	else{
		if((*t)->left->pri > (*t)->right->pri){(*t) = rightRotate(*t);}
		else{(*t) = leftRotate(*t);}
	}
	return Delete(t,key);
}

int main(void)
{
	int n,x,y;
	char c[8];
	Node *root = NI;
	scanf("%d",&n);
	for(int i = 0; i < n; i++)
	{
		scanf("%s",c);
		switch(c[0])
		{
			case 'i':scanf("%d %d",&x,&y);
			root = insert(&root,x,y);
			break;
			case 'd':scanf("%d",&x);
			root = Delete(&root,x);
			break;
			case 'f':scanf("%d",&x);
			if(find(root,x))printf("yes\n");
			else printf("no\n");
			break;
			case 'p':print(root);
			break;
		}
	}
	return 0;
}



Measured memory_bytes: 8104
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<map>  
#include<set>
#include<iterator>
#include<list>
#include<utility>
#include<cstdlib>
#include<queue>
#include<stack>
#include<bitset>
//#include<bits/stdc++.h>
#define PI  2*acos(0.0)
#define pb push_back

       
using namespace std;
using ll = long long;
using lli = long long int;
using ld = long double;



int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);


ll d,t,s;
cin>>d>>t>>s;
ll ans=s*t;
if(ans>=d)
{
 cout<<"Yes"<<"\n";
}
else
{
 cout<<"No"<<"\n";
}











	
	
	return 0;
	
	
	       /***Israil Hosen
	            Computer Science & Engineering
	         University Of Rajshahi.
	         ***/
	
	
	
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
void maxHeapify(vector<int32_t>& a, size_t i){
  size_t largest=i;
  if(i*2<a.size()) largest=(a[i*2]>a[largest]?i*2:largest);
  if(i*2+1<a.size()) largest=(a[i*2+1]>a[largest]?i*2+1:largest);
  if(largest!=i){
    swap(a[largest], a[i]);
    maxHeapify(a, largest);
  }
}
void buildMaxHeap(vector<int32_t>& a){
  for(size_t i=a.size()/2; i>=1; --i) maxHeapify(a, i);
}
int32_t main(){
  size_t h; cin>>h;
  vector<int32_t> a(h+1);
  for(size_t i=1; i<=h; ++i) cin>>a[i];
  buildMaxHeap(a);
  for(size_t i=1; i<=h; ++i) cout<<' '<<a[i];
  cout<<'\n';
}


Measured memory_bytes: 4532
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

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

//-------------------ここから回答する-----------------------

void solve(void)
{
    int n, m;
    cin >> n >> m;

    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    vector<int> c(m), d(m);
    rep(i, m) cin >> c[i] >> d[i];

    rep(i, n)
    {
        const int INF = 1e9;
        int dist = INF;
        int x = a[i];
        int y = b[i];
        rep(j, m) dist = min(dist, abs(x - c[j]) + abs(y - d[j]));
        rep(j, m)
        {
            if (dist == abs(x - c[j]) + abs(y - d[j]))
            {
                cout << j + 1 << endl;
                break;
            }
        }
    }
}
int main(void)
{
    solve();
}


Measured memory_bytes: 3632
def examA():
    T = I()
    ans = [inf]*T
    for t in range(T):
        N, A, B, C, D = LI()
        num = [[2,A],[3,B],[5,C]]
        dp = defaultdict(lambda: inf)
        dp[N] = 0
        que = deque()
        que.append(N)
        while(que):
            now = que.pop()
            if now==0:
                continue
            cur = dp[now] + D*now
            if cur<dp[0]:
                dp[0] = cur
            cur = dp[now]
            for n,K in num:
                curn = cur + (now % n) * D + K
                if curn < dp[(now - now % n) // n]:
                    dp[(now - now % n) // n] = curn
                    que.append((now - now % n) // n)
                curn_ = cur + (-now % n) * D + K
                if curn_ < dp[(now + (-now % n)) // n]:
                    dp[(now + (-now % n)) // n] = curn_
                    que.append((now + (-now % n)) // n)
        ans[t] = dp[0]
    for v in ans:
        print(v)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return


import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 93948
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    string s;
    cin >> s;
    s.push_back('$');
    vll a;
    if(s[0] == '>') a.push_back(1);
    char last = s[0];
    ll cnt = 0;
    for(ll i = 0; i < s.size(); i++) {
        if(last == s[i]) cnt++;
        else if(last != s[i]) {
            if(last == '<') a.push_back(cnt);
            else a.push_back(-cnt);
            last = s[i];
            cnt = 1;
        }        
    }
    if(a.back() > 0) a.push_back(-1);
    ll ans = 0;
    for(ll i = 0; i < a.size(); i++) {
        if(a[i] < 0) {
            ans += -a[i] * (-a[i] - 1) / 2;
        }
        else {
            ans += a[i] * (a[i] - 1) / 2;
            ans += max(a[i], -a[i + 1]);
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

using lint = long long;
using ldouble = long double;

using namespace std;

string S;

int rec(int l, int r) {
    static vector<vector<int>> dp(500, vector<int>(500, -1));
    auto& ret = dp[l][r];
    if (ret >= 0) return ret;

    if (r < l) return ret = 1;
    if ((r - l + 1) % 3 != 0 || S[l] != 'm' || S[r] != 'w') return ret = 0;

    ret = 0;
    for (int i = l + 1; i < r; ++i) {
        if (S[i] != 'e') continue;
        if (rec(l + 1, i - 1) && rec(i + 1, r - 1)) ret = 1;
    }
    return ret;
}

int main() {
    cin >> S;
    cout << (rec(0, S.size() - 1) ? "Cat" : "Rabbit") << endl;
    return 0;
}



Measured memory_bytes: 4016
S = input()[::-1]
N = len(S)
T = ""
n = 0
C = ["maerd","remaerd","esare","resare"]
while n<N:
    if S[n]=="m":
        T+=C[0]
        n+=5
    elif S[n]=="e":
        T+=C[2]
        n+=5
    elif S[n]=="r":
        if N-n<6:break
        if S[n+2]=="m":
            T+=C[1]
            n+=7
        elif S[n+2]=="s":
            T+=C[3]
            n+=6
        else:break
    else:break
print("YES" if S==T else "NO")

Measured memory_bytes: 3316
#include "bits/stdc++.h"

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
	int n,m,a;
	while(cin>>n>>m>>a){
		if(n==0 && m==0 && a==0)break;
		int mem[200];
		rep(i,200)mem[i]=i;
		vector<pair<int,pii> > hpq;
		rep(i,m){
			int h,p,q;
			cin>>h>>p>>q;
			hpq.pb(make_pair( 10000-h, make_pair(p,q) ));
		}
		sort(all(hpq));

		rep(i,hpq.size()){

			swap( mem[ hpq[i].second.first ] , mem[ hpq[i].second.second ] );
		}
		for(int i=1;i<=n;i++){
			if(mem[i]==a){
				cout<<i<<endl;
				break;
			}
		}
	}
}

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

int n,m;cin>>n>>m;
vector<string> A(n),B(m);
for(int i=0;i<n;i++){
cin>>A[i];
}
for(int i=0;i<m;i++){
cin>>B[i];
}
for(int i=0;i<n;i++){
  for(int j=0;j<n;j++){
    bool ok=true;
    for(int k=0;k<m;k++){
      if(i+k>=n || j+m>n){
        ok=false;
        break;
      }
      string a = A[i+k].substr(j, m);
      string b = B[k];
      if (a != b)ok=false;
    }
    if(ok){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
}
      cout<<"No"<<endl;
  
  return 0;
}


Measured memory_bytes: 3668
/*
* @Author: _dp95
* @Date:   2019-12-10 11:15:26
*/
#include "bits/stdc++.h"
using namespace std ;
 
#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
typedef long long ll ;
typedef long double ldb ;
 
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl '\n'
 
#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )
 
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
const int MAX = 2*1000*100 + 10 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;
 
int n, m, s[MAX], dp[ MAX ][ 2 ] ;
 
int sol( int val, int flag ){
  if( val < 0 )
    return flag == 0 ;
  if( val == 0 )
    return flag == 1 ;
  if( dp[val][flag] != -1 )
    return dp[val][flag] ;
  int f = 0 ;
  if(flag){
    f = 1 ;
    for( int i = 0 ; i < n ; i++ ){
      f &= sol(val-s[i],flag^1);
    }
  }
  else{
    f = 0 ;
    for( int i = 0 ; i < n ; i++ ){
      f |= sol(val-s[i],flag^1);
    }
  }
  return dp[val][flag] = f ;
}
 
void sol( ){
  cin >> n >> m ;
  for( int i = 0 ; i < n ; i++ )
    cin >> s[i] ;
  mem(dp,-1);
  if(sol(m,0))
    cout << "First" << nl ;
  else
    cout << "Second" << nl ;
}
 
int main( ){
  timesaver ;
  int t(1);
  while( t-- )
    sol();
}

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

int colors[1001];
int N, K;
int cnt;


int main(void)
{
    int i;
    unsigned long long int ret;
    cin >> N >> K;

    ret = K;

    for (i = 1; i < N; i++)
    {
        ret = ret * (K - 1);
    }

    
    cout << ret <<'\n';
    return 0;
}



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

int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int n,m;
    cin>>n>>m;
    vector<int> freq(m+1,0);
    for(int i = 0;i < n;i++) {
        int k;
        cin>>k;
        for(int j = 0;j < k;j++) {
            int x;
            cin>>x;
            freq[x]++;
        }
    }
    int ans = 0;
    for(int i = 1;i <= m;i++) {
        if(freq[i] == n) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>
using namespace std;

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

#define max_n 100

int A,B;


int main() {

	cin >> A >> B;

	B--;

	int ans = 0;
	while(B>0)
	{
		B++;
		ans++;
		B -= A;
	}
	
	

	cout << ans <<endl;

	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <random>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
    ll a,b; cin >> a >> b;
    if ((a+b)%2 == 0) {
        cout << (a+b)/2 << endl;
    } else {
        cout << "IMPOSSIBLE\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    long long int a[n],x=0;
    vector<long long int>v;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=k;i<n;i++)
    {
        if(a[i]>a[i-k])
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
}

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

int main()
{
    
    string res;
    cin>>res;
    reverse(res.begin(),res.end());

    int ans = 0;
    long long int val = 0;

    unordered_map<int,int> hmap;
    hmap[0] = 1;
    long long int fact = 1;
    long long int prev = 0;
    for(int i = 0;i< res.size();i++)
    {
        val = (fact *(res[i] - '0') + prev)%2019;
        prev = val;
        fact = (fact * 10)%2019;

        if(hmap.find(val) != hmap.end())
            ans += hmap[val];
        hmap[val]++;
        //cout<<val<<endl;
    }

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3724
#include<stdio.h>

int main()
{
  int n;
  int arr;
  int count = 0;
  int temp = 0;
  int j;
  scanf("%d", &n);

  while(n--)
    {
      scanf("%d", &arr);
      for( j = 2; j*j <= arr; j++)
	{
	  if(arr%j == 0)
	    {
	      break;
	    }
	}
      if(j*j > arr)
	{
	  count++;
	}
    }
  printf("%d\n", count);
}



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

typedef long long int int64;
static const int64 mod = 1000000007LL;
int64 inv[100003],fac[100003],invfac[100003];
int64 x[100003];

int n;
int64 v[100003];
int main()
{
    scanf("%d",&n);
    int64 base = 1;
    inv[1] = 1;
    for(int i = 2;i <= n;++i) {
        inv[i] = (mod - mod / i) * inv[mod % i] % mod;
        base = base * i % mod;
    }
    for(int i = 1;i <= n;++i) {
        x[i] = (x[i - 1] + base * inv[i]) % mod;
    }
    int64 ans = 0;
    for(int i = 0;i < n;++i) {
        scanf("%lld",&v[i]);
        int64 k = v[i] * (x[i + 1] + x[n - i] - base) % mod;
        ans = ans + k;
    }
    ans = ans % mod;
    if(ans < 0) ans += mod;
    printf("%lld\n", ans % mod);
}


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


int main() {
    int N, A, B;
    while (cin >> N >> A >> B) {
        int num[3] = {0};
        for (int i = 0; i < N; ++i) {
            int p; cin >> p;
            if (p <= A) num[0]++;
            else if (p <= B) num[1]++;
            else num[2]++;
        }
        cout << min(num[0], min(num[1], num[2])) << endl;
    }
}


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

int main() {
  int s;
  int s1, s2, s3;
  
  cin >> s;
  s1 = s/100;
  s2 = (s-100*s1)/10;
  s3 = s-100*s1-10*s2;
  
  cout << s1+s2+s3 << endl;
}


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

int main()
{
    int n, x, t;
    cin >> n >> x >> t;
    int ans = 0;
    while(n > 0){
        ans += t;
        n -= x; 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<vector>
#include<stack>
#include<map>
#include<set>
#define Run(i,l,r) for(int i=l;i<=r;i++)
#define Don(i,l,r) for(int i=l;i>=r;i--)
#define ll long long
#define ld long double
#define inf 0x3f3f3f3f
#define mk make_pair
#define fir first
#define sec second
using namespace std;
int A,B,C;
int main(){
	cin>>A>>B>>C;
	cout<<min(A+B+1,C)+B<<endl;
	return 0;
}//by tkys_Austin;


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    from math import gcd

    k = int(input())
    ans = 0

    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                tmp = gcd(a, b)
                ans += gcd(tmp, c)

    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
	int n,k;cin >> n >> k;
	int cnt=0;
	long long ans;
	if(k%2==0){
		int cnt1=0,cnt2=0;
		for(int i=1;i<=n;++i){
			if(i%k==0) cnt1++;
		}
		for(int i=1;i<=n;++i){
			if(i%k==k/2) cnt2++;
		}
		ans=pow(cnt1,3)+pow(cnt2,3);
	}
	else{
		for(int i=1;i<=n;++i){
			if(i%k==0) cnt++;
		}
		ans=pow(cnt,3);
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
sx,sy,tx,ty = map(int,input().split())

ans = ["U"] * (ty-sy) \
    + ["R"] * (tx-sx) \
    + ["D"] * (ty-sy) \
    + ["L"] * (tx-sx) \
    + ["D"]\
    + ["R"] * (tx-sx+1)\
    + ["U"] * (ty-sy+1)\
    + ["L", "U"]\
    + ["L"] * (tx-sx+1)\
    + ["D"] * (ty-sy+1)\
    + ["R"]

print("".join(ans))

Measured memory_bytes: 3288
#include <stdio.h>
int main(void)
{
  int a,b,c,miss=0,color;
  char str[16];
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d%d%d",&a,&b,&c);
  if(a == b)
  {
    miss++;
  }
  if(b == c)
  {
    miss++;
  }
  if(c == a)
  {
    miss++;
  }
  switch (miss)
  { case 0:
  		color = 3;
  		break;
  	case 3:
  		color = 1;
  		break;
  	default:
  		color = 2;
  		break;
  }
  printf("%d\n",color);
  return 0;
}
  

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if(x<0||y<0) cout<<"No"<<endl;
    else if(x+r<=w&&x-r>=0&&y+r<=h&&y-r>=0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>
int main(){
    int a,b,c,d,e;
    scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
    if(a==0){
        printf("%d",1);
    }
   if(b==0){
        printf("%d",2);
    }
       if(c==0){
        printf("%d",3);
    }
       if(d==0){
        printf("%d",4);
    }
       if(e==0){
        printf("%d",5);
    }
    return 0;
    
}

Measured memory_bytes: 1680
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!


void solve(){
    
    ll n;
    ll A,B;
    cin>>n>>A>>B;
    
    ll full=n/(A+B);
    
    ll cnt=full*A;
    // cout<<cnt<<" ";
    ll rem=n-full*(A+B);
    cnt+=(rem<A)?rem:A;
    cout<<cnt<<endl;
}

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

Measured memory_bytes: 3616
N = int(input())
a = [[0 for i in range(3)] for j in range(N)]
dp = [[0 for i in range(3)] for j in range(N)]
for i in range(N):
    a[i][0], a[i][1], a[i][2] = map(int, input().split())

for j in range(3):  # initialize dp[0]
    dp[0][j] = a[0][j]

for i in range(1, N):
    dp[i][0] = a[i][0] + max(dp[i-1][1], dp[i-1][2])
    dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2])
    dp[i][2] = a[i][2] + max(dp[i-1][0], dp[i-1][1])
print(max(dp[N-1]))

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

int main(){

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

	int data[500][500];
	for(int i = 0; i < h; i++)
	{
		
		for(int j = 0; j < w; j++)
		{
			cin >> data[i][j];
		}
		
	}

	int buff[500*500][4];

	int posh = 0;
	int posw = 0;
	int cnt = 0;
	for(int i = 0; i < h; i++)
	{
		
		for(int j = 0; j < w; j++)
		{
			if (i==h-1 && j == w-1){
				continue;
			}
			int next_posh, next_posw;
			if(i%2==0){
				if(j==w-1){
					next_posh = posh +1;
					next_posw = posw;
				}else{
					next_posh = posh;
					next_posw = posw + 1;
				}
			}else{
				if(j==w-1){
					next_posh = posh + 1;
					next_posw = posw;
				}else{
					next_posh = posh;
					next_posw = posw - 1;
				}
			}

			if(data[posh][posw]%2 != 0){
				cnt ++;
				data[posh][posw]--;
				data[next_posh][next_posw]++;
				buff[cnt-1][0] = posh + 1;
				buff[cnt-1][1] = posw + 1;
				buff[cnt-1][2] = next_posh + 1;
				buff[cnt-1][3] = next_posw + 1;
			}
			posh = next_posh ;
			posw = next_posw;
		}
		
	}
	cout << cnt << endl;
	
	for(int i = 0; i < cnt; i++)
	{
		cout << buff[i][0] << " " << buff[i][1] << " " << buff[i][2] << " " << buff[i][3] << endl;
	}
	
	
	
	return 0;
}

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

int main(){
  string s,t;
  cin>>s>>t;
  
  int c=0;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i])
      c++;
  }
  
  cout<<c;
}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef long double LD;
typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1 << 30;
const int MAXN = 8;

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

	int N, M, A, B;
	cin >> N >> M;
	vector<int> G[MAXN];
	for (int i = 0; i < M; i++) {
		cin >> A >> B;
		G[--A].push_back(--B);
		G[B].push_back(A);
	}
	queue<P> q;
	q.push(P(0, 0));
	int res = 0;
	while(q.size()) {
		int p = q.front().first, c = q.front().second;
		q.pop();
		if (c & (1 << p)) continue;
		c |= (1 << p);
		if (c == (1<<N)-1) {
			res++;
			continue;
		}
		for (int d : G[p]) q.push(P(d, c));
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys


def solve(a: int):
    print(0 if a % 1000 == 0 else 1000-a%1000)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61708
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <stack>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef pair<int,int> P;
typedef pair<P,int> Q;
#define fi first
typedef long long ll;
#define sc second

ll n,m,ans[10005];
int only[10005];
vector<int>vec[10005];

int main(){
	while(1){
		cin>>n>>m;
		if(n==0) return 0;
		for(int i=0;i<1005;i++) vec[i].clear();
		for(int i=0;i<10005;i++) ans[i] = only[i] =0;
		rep(i,m){
			int pt; cin>>pt; int k; cin>>k;
			rep(j,k){
				int a; cin>>a;
				vec[i].push_back(a);
				ans[a] += pt;
			}
			if(k == 1) only[vec[i][0]] += pt;
		}
		vector<P>vec;
		for(int i=1;i<=n;i++){
			vec.push_back(P(ans[i],i));
		}
		sort(vec.begin(),vec.end(),greater<P>());
		int anss = 0;
		for(int i=1;i<=n;i++){
			int x = only[i];
			int y = vec[0].fi; if(vec[0].sc == i) y = vec[1].fi;
			anss = max(anss,y-x+1);
		}
		cout << anss<< endl;
	}
}



Measured memory_bytes: 4912