akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
static long factMax = 200000;//nCkにおけるnの最大値
static long[] factorials = new long[factMax+1];//i!(mod p)をO(n)で先にメモ。
static long[] factorialRs = new long[factMax+1];//i!^-1(mod p), pは素数でO(n)。

	static void Main()
	{
    string[] input = Console.ReadLine().Split(' ');
    long n = long.Parse(input[0]);
    long k = long.Parse(input[1]);
    long p = 1000000007;
  
    factorials[0] = 1;
    factorialRs[factMax] = DivideModFactorial(factMax,p);
    for(long i = 1; i <= factMax; i++)
    {
      factorials[i] = (factorials[i-1]*i)%p;//i!(mod p)
      factorialRs[factMax-i] = (factorialRs[factMax+1-i]*(factMax+1-i))%p;//逆元も先にメモ
    }

    Console.WriteLine(BellNumber(n,k,p));
	}

  static long BellNumber(long n, long k, long mod)
  {//n個の区別する玉をk個の区別しない箱に入れる方法(mod)の個数をO(klogn)で求める。
    long answer = 0;
    long[] subMemo = new long[k+1];
    subMemo[0] = factorialRs[0];
    for(long i = 1; i <= k; i++)
    {
      if(i % 2 == 0) subMemo[(int)i] = subMemo[(int)i-1] + factorialRs[(int)i];
      else subMemo[(int)i] = subMemo[(int)i-1] - factorialRs[(int)i];

      subMemo[(int)i] %= mod;
    }

    for(long i = 1; i <= k; i++)
    {
      long answerSub = DivideMod(i,n,mod);
      answerSub *= factorialRs[i];
      answerSub %= mod;
      answerSub *= subMemo[k-i];
      answerSub %= mod;

      answer += answerSub;
      answer %= mod;
    }
    return answer;
  }

  static long MathPow(long x, long a)//戻り値はx^a。O(loga)
  {
    long num = 2;
    long answer = 1;
    long check = a;
    long memo = x;
  
    while(check > 0)
    {
      if(check % num == num / 2)
      {
        check -= num / 2;
        answer *= memo;
      }
    memo *= memo;
    num *= 2;
    }
    return answer;
  }

  static long DivideMod(long x, long a, long p)//戻り値はx^a(mod p)。O(loga)
  {
    long num = 2;
    long answer = 1;
    long check = a;
    long memo = x%p;
    
    while(check > 0)
    {
      if(check % num == num / 2)
      {
        check -= num / 2;
        answer *= memo;
        answer %= p;
      }
    memo *= memo;
    memo %= p;
    num *= 2;
    }
    return answer;
  }

  static long DivideModReverse(long x, long p)//戻り値はx^-1(mod p), pは素数。O(logp)
  {
    long answer = DivideMod(x, p-2, p);
    return answer;
  }

  static long ModFactorial(long x, long p)//戻り値はx!(mod p)
  {
    long answer = 1;
    for(int i = 2; i <= x; i++)
    {
      answer *= i;
      answer %= p;
    }
    return answer;
  }

  static long DivideModFactorial(long x, long p)//戻り値はx!^-1(mod p), pは素数
  {
    long answer = 1;
    for(long i = x; i >= 2; i--)
    {
      answer *= DivideModReverse(i, p);
      answer %= p;
    }
    return answer;
  }

  static long Comb(long a, long b, long p)//組み合わせC(a,b)(mod p)をO(1)で返す
  {
    if(a-b < 0) return 0;//引数a-bが負なら0を返す
    long answer = 1;
    answer *= factorials[a];
    answer %= p;
    answer *= factorialRs[a-b];
    answer %= p;
    answer *= factorialRs[b];
    answer %= p;
    return answer;
  }
  
}



Measured memory_bytes: 19144
#include<stdio.h>
#include<string.h>
 
#define M 1000005
#define L 14
 
char HS[M][L]; 
 
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}
 

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
 
int h1(int key){ return key % M; }
int h2(int key){ return 1 + key % (M-1); }
 
int find(char str[]){

  long long fin;
  int i = 0;
  long long sum = getKey(str); 

  while(1){
    fin = (h1(sum) + h2(sum)*i) %M;
    if(strcmp(HS[fin],str) == 0) return 1;
    if(HS[fin][0] == '\0') return 0;
    i++;
  }

  return 0;

}
 
void insert(char str[]){
 
 int  i = 0;
  long long ser;
  long long sum = getKey(str);
  
  while(1){
    ser = (h1(sum) + h2(sum) *i) %M;
    if(HS[ser][0] == '\0' || strcmp(HS[ser],str) == 0){
      strcpy(HS[ser],str);
      break;
    }

    i++;
  }

}
 
int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) HS[i][0] = '\0';
     
    scanf("%d", &n);
     
    for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
     
    if ( com[0] == 'i' ){
        insert(str);
    } 
    else {
        if (find(str)){
        printf("yes\n");
        } else {
        printf("no\n");
        }
    }
 }
 
    return 0;
}

Measured memory_bytes: 14280
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int c = scanner.nextInt();
    int d = scanner.nextInt();
    
    int area1 = a * b;
    int area2 = c * d;
    if(area1 >= area2) {
      System.out.println(area1);
    } else {
      System.out.println(area2);
    }
  }
}

Measured memory_bytes: 35772
n, k, q = map(int, input().split())
a = [0 for i in range(q)]

line = q - k + 1
point = [0 for i in range(n)]
for i in range(q):
    ai = int(input()) - 1
    point[ai] += 1

for i in range(n):
    if point[i] >= line:
        print('Yes')
    else:
        print('No')

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

int main(){
  int h,w,n;
  int cont=0;
  int m=0;
  cin>>h>>w>>n;
  
  while(cont<n){
    if(h==1){
      cont+=w;
      m++;
      break;
    }else if(w==1){
      cont+=h;
      m++;
      break;
    }
      
    if(h>=w){
      cont+=h;
      w--;
      m++;
    }else{
      cont+=w;
      h--;
      m++;
    }
  }
  cout<<m<<endl;
}

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

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    if (s == "Sunny")
        cout << "Cloudy" << endl;
    else if (s == "Cloudy")
        cout << "Rainy" << endl;
    else if (s == "Rainy")
        cout << "Sunny" << endl;

    return 0;
}


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

int main() {
  int N; cin >> N;
  for (int i = 0; i < N; i++) {
    int K, P; cin >> K >> P;
    if (K % P == 0) cout << P << endl;
    else cout << K % P << endl;
  }
  return 0;
}


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

int main(void){
	int q;
	string a,b;
	cin>>q;
	while(q--){
		cin>>a>>b;
		int dp[1010][1010] = {0};
		for(int j = 0 ; j < a.size() ; j ++){
			for(int i = 0 ; i < b.size() ; i ++){
				if(a[j] == b[i]){
					dp[j+1][i+1] = dp[j][i]+ 1;
				}else{
					dp[j+1][i+1] = max(dp[j][i+1],dp[j+1][i]);
				}
			}
		}
		cout<<dp[a.size()][b.size()]<<endl;
	}
}

Measured memory_bytes: 5196
n = int(input())
a = list(map(int, input().split()))
l = [[] for i in range(n+1)]
l[-1].append(a[-1])
for i in range(n):
    l[-2-i].append(((l[-1-i][0]+1)//2)+a[-2-i])
    l[-2-i].append((l[-1-i][-1])+a[-2-i])

ans = 1
if l[0][0] == 1:
    num = [1]
    for i in range(n):
        num.append(
            min(
                l[i+1][-1], 
                (num[i]-a[i])*2
                
                )
            )
        ans += num[i+1]

    print(ans)
else:
    print(-1)

Measured memory_bytes: 34976
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,x;
	cin>>n>>m>>x;
	int i,a[m],u=0,v=0;
	for(i=0;i<m;i++)
	{
		cin>>a[i];
		if(a[i]>x)
		{
			u++;
		}
		else
		{
			v++;
		}
	}
	if(v>u)
	{
		cout<<u;
	}
	else
	{
		cout<<v;
	}
		
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<tuple<string,int,int>> R(N);
  string S;
  int P;
  for (int i = 0; i < N; i++){
    cin >> S >> P;
    R[i] = make_tuple(S,-P,i + 1);
  }
  sort(R.begin(),R.end());
  for (int i = 0; i < N; i++){
    cout << get<2>(R[i]) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n); rep (i, n) cin >> a[i];
    vector<int> b(9); rep (i, n) b[min(8, a[i] / 400)]++;
    int ans = 0; rep (i, 8) ans += (!!b[i] ? 1 : 0);
    if (ans == 0) cout << 1 << " " << b[8] << "\n";
    else cout << ans << " " << ans + b[8] << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

void solve(int n, map<int, int> &m) {
    while (n != 1) {
        repd(i, 2, n + 1) {
            if (n % i == 0) {
                if (m[i] == 0) {
                    m[i] = 1;
                } else {
                    m[i]++;
                }
                n /= i;
                break;
            }
        }
    }
    return;
}

int main() {
    // source
    int n;
    map<int, int> m;
    cin >> n;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }

    rep(i, n) { solve(i + 1, m); }

    ll ans = 1;
    ll mod = pow(10, 9) + 7;
    for (auto iter = m.begin(); iter != m.end(); iter++) {
        ans *= iter->second + 1;
        if (ans > mod) {
            ans %= mod;
        }
    }

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

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,j,N,o=0;
    double h,w,n;
    while(~scanf("%d",&N))
    {
        for(i=1; i<=3500; i++)
        {
            for(j=1; j<=3500; j++)
            {
                h=i;
                w=j;
                n=N*h*w/(4*h*w-N*w-N*h);
                if((int)n==n&&n>0&&j>0&&i>0)
                {
                    if(4*h*w*n==N*(w*n+h*w+n*h))
                    {
                        o++;
                        printf("%.f %.f %.f\n",h,w,n);
                    }

                }
                if(o==1)
                    break;

            }
            if(o==1)
            {
                o=0;
                break;
            }
        }
    }
}

Measured memory_bytes: 256
# unionfind


class UnionFind(object):

    def __init__(self, n):
        self.n = n
        self.parent = list(range(self.n))
        self.rank = [0]*n

    def find_parent(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find_parent(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find_parent(x)
        y = self.find_parent(y)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


N, M = map(int, input().split())
uf = UnionFind(N+1)

for _ in range(M):
    xx, yy, zz = map(int, input().split())
    uf.unite(xx, yy)

res = [0] * (N + 1)
res_c = 0
for i in range(1, N + 1):
    j = uf.find_parent(i)
    if res[j] == 0:
        res_c += 1
    res[j] += 1

print(N - (sum(res) - res_c))


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

using namespace std;

int main(void) {
    string S;
    cin >> S;
    int del = 0;
    stack<char> stk;
    for (int i = 0; i < S.size(); i++) {
        if (!stk.empty() && stk.top() != S[i]) {
            stk.pop();
            del++;
        } else {
            stk.emplace(S[i]);
        }
    }
    cout << del * 2 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define st first
#define nd second
#define INF 1000000007LL
using namespace std;

int main(){
#ifndef LOCAL
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
  ll n; cin >> n;
  string ans = "";
  while(n > 0){
    ans += char('a' + ((n - 1) % 26));
    n = (n - 1) / 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << '\n';  
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<string> w(n); rep(i, n) cin >> w[i];
  set<string> st;
  bool ok = true;
  rep(i, n) {
    if(st.count(w[i])) ok = false;
    if(i && *w[i-1].rbegin() != *w[i].begin()) ok = false;
    st.insert(w[i]);
  }
  cout << (ok ? "Yes" : "No") << "\n";
  return 0;
}


Measured memory_bytes: 3652
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    a = list(map(int,input().split()))
    su = c
    for j in range(len(a)):
        su += a[j]*b[j]
    if(su > 0):
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include<iomanip>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int inf = 1000000;

int main(int argc, const char * argv[]) {
  int N;
  cin >> N;
  int a[N];
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + N);
  
  if (a[N - 1] < sum - a[N - 1]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// AtCoder Beginner Contest 100
// B - Ringo's Favorite Numbers
#include <bits/stdc++.h>
using namespace std;

#define IEF(i, s, t)    for(int i=s; i<t; i++)
#define NEF(i, s, t)    for(int i=s; i>=t; i--)
#define MAXN 100005

int main(){
    ios_base::sync_with_stdio(false);
    int D, N;
    cin >> D >> N;
    int ans = 1;
    IEF(i, 0, D)    ans *= 100;
    if(N == 100)
    {
        cout << ans * (N+1);
    } else 
    {
        cout << ans * N;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>
#include <atcoder/all>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD[4] = {998244353, 1000000007, 1000000009, 6700417};
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    atcoder::dsu d(n);
    int a, b;
    for(int i=0;i<m;++i) {
        cin >> a >> b;
        --a; --b;
        d.merge(a, b);
    }

    set<int> roots;
    for(int i=0;i<n;++i) {
        roots.insert(d.leader(i));
    }

    cout << int(roots.size()) - 1 << endl;
}

Measured memory_bytes: 7724
//I am so vegetable
//#define _LOCAL_
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define PB push_back
#define IN insert
#define ER erase
#define CT count
#define EP empty
#define _for(i,a,b) for(ll i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll N = 2e5 + 5;
const int MOD = 998244353;
const double eps = 1e-6;
const double pi = acos(-1);
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
int a[N];
int main() {
	FIO;
	int k,n;cin>>k>>n;
	int ma = -INF;
	cin>>a[0];
	_for(i,1,n){
		cin>>a[i];
		ma = max(ma,a[i]-a[i-1]);
	}
	ma = max(ma,a[0] + (k -a[n - 1]));
	cout<<k - ma;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n==25)cout<<"Christmas"<<endl;
    else if(n==24) cout<<"Christmas Eve"<<endl;
    else if(n==23)cout<<"Christmas Eve Eve"<<endl;
    else {
        cout<<"Christmas Eve Eve Eve"<<endl;
    }

}


Measured memory_bytes: 3564
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		var march = new long[5];
		for (int i = 0; i < N; i++)
		{
			char c = Console.ReadLine()[0];
			switch (c)
			{
				case 'M':
					march[0]++;
					break;
				case 'A':
					march[1]++;
					break;
				case 'R':
					march[2]++;
					break;
				case 'C':
					march[3]++;
					break;
				case 'H':
					march[4]++;
					break;
			}
		}
		int[,] pattern = new int[,]
		{
			{0, 1, 2},
			{0, 1, 3},
			{0, 1, 4},
			{0, 2, 3},
			{0, 2, 4},
			{0, 3, 4},
			{1, 2, 3},
			{1, 2, 4},
			{1, 3, 4},
			{2, 3, 4}
		};
		long ans = 0;
		for (int i = 0; i < 10; i++)
		{
			ans += march[pattern[i, 0]] * march[pattern[i, 1]] * march[pattern[i, 2]];
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13268
using System;
using System.IO;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve());
        Console.Out.Flush();
    }

    static object Solve() {
        var N = int.Parse(Console.ReadLine());
        var txy = new (int t, int x, int y)[N];
        for (int i = 0; i < N; i++) {
            var p = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            txy[i] = (p[0], p[1], p[2]);
        }
        if (txy[0].t - txy[0].x - txy[0].y < 0 || (txy[0].t - txy[0].x - txy[0].y) % 2 != 0) return "No";
        for (int i = 0; i < N - 1; i++) {
            var t = txy[i + 1].t - txy[i].t;
            var x = Math.Abs(txy[i + 1].x - txy[i].x);
            var y = Math.Abs(txy[i + 1].y - txy[i].y);
            if (t - x - y < 0 || (t - x - y) % 2 != 0) return "No";
        }
        return "Yes";
    }
}

Measured memory_bytes: 47500
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

// 約数の列挙O(√n)
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  return res;
}

int main() {
  ll N;
  cin >> N;
  auto divs = divisor(N);
  ll ans = 0;
  for (int i = 0; i < divs.size(); i++) {
    ll x = N / divs[i] - 1;
    if (x != 0 && N / x == N % x) ans += x;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
template<int mod>
struct ModInt{
    int x;
    ModInt():x(0){}
    ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
    ModInt &operator+=(const ModInt &p){
        if((x+=p.x)>=mod)x-=mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p){
        if((x+=mod-p.x)>=mod)x-=mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p){
        x=(int)(1LL*x*p.x%mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p){
        *this*=p.inverse();
        return *this;
    }
    ModInt operator-()const{return ModInt(-x);}
    ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
    ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
    ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
    ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
    bool operator==(const ModInt &p)const{return x==p.x;}
    bool operator!=(const ModInt &p)const{return x!=p.x;}
    ModInt inverse()const{
        int a=x,b=mod,u=1,v=0,t;
        while(b>0){
            t=a/b;
            a-=t*b;
            swap(a,b);
            u-=t*v;
            swap(u,v);
        }
        return ModInt(u);
    }
    friend ostream &operator<<(ostream &os,const ModInt<mod> &p){
        return os<<p.x;
    }
    friend istream &operator>>(istream &is,ModInt<mod> &a){
        long long x;
        is>>x;
        a=ModInt<mod>(x);
        return (is);
    }
};

const int mod=1e9+7;
using mint=ModInt<mod>;
int main(){
    string st;
    cin>>st;
    int n=st.size();
    vi dig(n);
    REP(i,n){
        dig[i]=stoi(st.substr(i,1));
    }
    int d;
    cin>>d;
    mint dp[n+1][d][2];
    dp[0][0][1]=1;
    REP(i,n){
        REP(j,d){
            dp[i+1][(j+dig[i])%d][1]+=dp[i][j][1];
            REP(k,10){
                dp[i+1][(j+k)%d][0]+=dp[i][j][0];
                if(k<dig[i]){
                    dp[i+1][(j+k)%d][0]+=dp[i][j][1];
                }
            }
        }
    }
    cout<<dp[n][0][0]+dp[n][0][1]-1<<endl;
    return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int a[3];
	for(int i=0;i<3;i++){
		cin >> a[i];
	}
	sort(a,a+3);
	if(a[0]==a[1]&&a[1]!=a[2]){
		cout << "Yes" << endl;
	}
	else if(a[1]==a[2]&&a[1]!=a[0]){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int H,W,D;
int Q,L,R;
map<int,pair<int,int>>m;
int d[90001];
int main(void)
{
    cin>>H>>W>>D;
    int t;
    for(int i=1;i<=H;++i)
    {
        for(int j=1;j<=W;++j)
        {
            cin>>t;
            m[t].first=i;
            m[t].second=j;
        }
    }
    cin>>Q;
    int sum;
    for(int i=D+1;i<=H*W;i++)
    {
    	d[i]=d[i-D]+(abs(m[i].first-m[i-D].first)+abs(m[i].second-m[i-D].second));
	}
    for(int i=0;i<Q;++i)
    {
        sum=0;
        cin>>L>>R;
        cout <<d[R]-d[L]<<endl;
    }
    return 0;
}


Measured memory_bytes: 8064
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 10055;

string s[3];
int can[3][3][N];

void calc(int i, int j) {
  string& a = s[i];
  string& b = s[j];
  for(int k = 0 ; k < sz(a) ; k++) {
    can[i][j][k] = true;
    for(int l = k ; l < sz(a) && l - k < sz(b) ; l++) {
      can[i][j][k] &= a[l] == '?' || b[l - k] == '?' || a[l] == b[l - k];
    }
  }
  for(int k = sz(a) ; k < N ; k++)
    can[i][j][k] = true;
}

int solve(vector<int>& idx) {
  int a = sz(s[idx[0]]);
  int b = sz(s[idx[1]]);
  int c = sz(s[idx[2]]);
  int ans = 1e9;
  for(int i = 0 ; i <= a ; i++) {
    if(can[idx[0]][idx[1]][i]) {
      for(int j = 0 ; j <= b || i + j <= a ; j++) {
        if(can[idx[1]][idx[2]][j] && can[idx[0]][idx[2]][i + j]) {
          ans = min(ans, max(a, max(b + i, c + i + j)));
        }
      }
    }
  }
  return ans;
}

int main()
{
  for(int i = 0 ; i < 3 ; i++)
    cin >> s[i];
  for(int i = 0 ; i < 3 ; i++)
    for(int j = 0 ; j < 3 ; j++)
      if(i != j)
        calc(i, j);
  vector<int> idx = {0, 1, 2};
  int best = 1e9;
  do {
    best = min(best, solve(idx));
  }while(next_permutation(all(idx)));
  cout << best << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>

using namespace std;

int main(){
    int i, x, l, max;
    x = 0;
    max = 0;
    std::string a;
    cin >> a;
    l = (int)(a.size());

    for(i=0; i<l; i++){
        
        if(a[i] == 'A'){
            x += 1;
            if(x > max) max = x;
        }
        else if(a[i] == 'T'){
            x += 1;
            if(x > max) max = x;
        }
        else if(a[i] == 'C'){
            x += 1;
            if(x > max) max = x;
        }
        else if(a[i] == 'G'){
            x += 1;
            if(x > max) max = x;
        }
        else x = 0;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int dp[100010];
int n;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	dp[0]=a[1];
	int len=1;
	for(int i=2;i<=n;i++){
		if(a[i]>dp[len-1]){
			dp[len++]=a[i];
		}
		else{
			*lower_bound(dp,dp+len,a[i])=a[i];
		}
	}
	cout<<len<<endl;
	return 0;
} 



Measured memory_bytes: 3788
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<unordered_map>

#define inf 0x3f3f3f3f
#define ii pair<int,int>
#define iii pair<int, ii>
#define ic pair<int, char>
#define icii pair<ic,ii>

#define pb push_back

using namespace std;
const int maxn = 5e3 + 10;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long i64;
 
int n;
int v[maxn]; 
using namespace std;

int main(){
	//~ freopen("in","r",stdin);
 
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin >> n;
	
	for(int i =0;i < n;i++)cin >> v[i];
	
 
	sort( v, v + n);
	int a = 0, b =0;
	--n;
	while(n>=0){
		if( n>=0 )a += v[n--];
		else break;
		if( n>=0) b += v[n--];
		else break;
	}
	cout << a - b<< '\n';
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================

	ll N;
	cin >> N;

	ll ans = 0;

	for (int i = 1; i <= N; i++)
	{

		if (i % 3 != 0 && i % 5 != 0)
		{
			ans += i;
		}



	}

	cout << ans;



}





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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_V = int(1e3) + 3;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

int main() {
    int n;
    cin >> n;
    if(n<1200)cout << "ABC" << endl;
    else if(n<2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;

    return 0;
}


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

int a;
int main() {
  cin >> a ;
  if(a%1110 <= 9){
    cout << "Yes" << endl;
  }
  else if((a%1000)%111 == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  }

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

#define ul unsigned long int
#define ull unsigned long long
#define li long long int

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

  while (s!="0") {
    a=0;
    for (ul i=0;i<s.length();i++) a+=(ul)s[i]-(ul)'0';
    cout << a << endl;
    cin>>s; 
  }

  return 0;
}



Measured memory_bytes: 3224
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
  ll a,b,c,x,y;
  cin >> a>>b>>c;
  cin >>x>>y;
  ll t=(a+b),sum=0;
  if(t>c*2) {
   if(x<y) {
     sum+=(c*2*x);
     sum+=min((y-x)*b,c*2*(y-x));
   }
   else{
     sum+=(c*2*y);
     sum+=min((x-y)*a,c*2*(x-y));
   }
   cout <<sum<<endl;
  }
  else{
    cout << a*x+b*y<<endl;
  }
}


Measured memory_bytes: 256
n,ma,mb=map(int,input().split())
el=[list(map(int,input().split())) for i in range(n)]
sa=sum(i[0] for i in el)
sb=sum(i[1] for i in el)
sa1=sa+1
sb1=sb+1

inf=1000000
x=[[inf]*(sb1) for i in range(sa1)]
x[0][0]=0
for i in range(n):
    now=el[i]
    x_sub=[[0]*(sb1) for i in range(sa1)]
    for k in range(sa1):
        for l in range(sb1):
            if x[k][l]!=inf:
                if k+now[0]<sa1:
                    if l+now[1]<sb1:
                        x_sub[k+now[0]][l+now[1]]=x[k][l]+now[2]
    for k in range(sa1):
        for l in range(sb1):
                if x_sub[k][l]!=0:
                    x[k][l]=min(x[k][l],x_sub[k][l])
mi=min(sa//ma,sb//mb)
ans=inf
for i in range(1,mi+1):
    ans=min(ans,x[ma*i][mb*i])
if ans==inf:
    print(-1)
else:
    print(ans)


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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int N;
	
	cin >> N;
	
	for(int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			if(i * j == N){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	
	cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
cnt = 0
abcount = 0
acount = 0
bcount = 0

for i in range(N):
	s = input()
	cnt += s.count('AB')
	if s.startswith('B') and s.endswith('A'):
		abcount += 1
	if s.startswith('B'):
		bcount += 1
	if s.endswith('A'):
		acount += 1

if acount == 0 and bcount == 0 and abcount == 0:
	print(cnt)
elif abcount == acount and abcount == bcount:
	print(cnt + abcount -1)
else:
	print(cnt + min(acount, bcount))

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
//    return *(int*)a - *(int*)b;
    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

int main()
{
 
  int a, b, c, d, e, X, Y;
  //  double  c;
//  long long  A[100003]={};
  int  B[100003]={};
  int  C[100003]={};

  int  flag[103]={};

//  long long  a, b, c, d, X, Y;
char s[101]={};
char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
//  int flag=0;
  int tmp=0;
//  int min=1000000;
  long long min=100000001;
  int len=0;
  int cnt=0;
  int num=0;
  double ans=1000;
  int max=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%s", &s);
//  cnt = strlen(t);
  t[0]=s[0];  
  t[1]=s[1];  
  t[2]=s[2];  
  t[3]=s[3];
  t[4]="\0";
   cnt=atoi(t);
  
  if(cnt<2019){
    printf("Heisei\n");
    return 0;
  }
  t[0]=s[5];  
  t[1]=s[6];  
  t[2]="\0";
   cnt=atoi(t);
 //     printf("%d\n", cnt);
  if(cnt<5){
    printf("Heisei\n");
    return 0;
  }
  
    printf("TBD\n");
  
  /*
  for(i=0;i<a;i++){
    scanf("%lld", &A[i]);
//    printf("%lld ",A[i]);
    if(A[i]==1) {
      printf("1\n");
      return 0;
    }
  }    

  qsort(A, a, sizeof(long long), compare_int);  
  
  for(i=0;i<a;i++){
    printf("%lld ",A[i]);

  
  
  } 
*/
  //  //  if(flag==0)   printf("TLE\n");
//    if(max < cnt - max)  printf("Yes\n");
//    else  printf("No\n");
  
return 0;
}


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

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int a,b,h,ans;
	cin>>a>>b>>h;
	ans=(h/2)*(a+b);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3644
mod=10**9+7
N,K=map(int,input().split())
ans=0
for i in range(K,N+2):
    MIN=(i*(i-1))//2
    MAX=((N+1)*N)//2-((N-i+1)*(N-i))//2
    ans+=MAX-MIN+1
    ans%=mod
    #print(i,MIN,MAX)
print(ans)

Measured memory_bytes: 63964
#include<stdio.h>
 
int main(void){
  int x[5];
  scanf("%d%d%d%d%d",&x[0],&x[1],&x[2],&x[3],&x[4]);
  for(int i=0;i<5;i++){
    if(x[i]==0){
      printf("%d\n",i+1);
      return 0;
    }
  }
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N, M; cin >> N >> M;
    priority_queue<ll> pq;
    ll sum = 0;
    for(int i = 0; i < N; i++) {
        ll A; cin >> A;
        pq.push(A);
        sum += A;
    }
    for(int i = 0; i < M; i++) {
        ll n = pq.top(); pq.pop();
        sum -= (n + 1) / 2;
        pq.push(n / 2);
    }
    cout << sum << endl;
    return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

ll bin_pow(ll x, ll n, ll mod){
	ll res = 1LL;
	for(; n > 0; n >>=1, x = x*x %mod) if(n & 1) res = res * x %mod;
	return res;
}
int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll n;
	cin >>n;
	ll ans = bin_pow(10, n, MD) +2*MD - 2* bin_pow(9, n, MD) + bin_pow(8, n, MD);
	cout << ans %MD <<"\n";
	return 0;
}



Measured memory_bytes: 3648
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        char[] s = sc.next().toCharArray();
        char[] key = {'k', 'e', 'y', 'e', 'n', 'c', 'e'};
        
        int preCount = 0;
        for (int i = 0; i < key.length; i++) {
            if (s[i] != key[i]) {
                break;
            }
            preCount++;
        }

        int sufIndex = 0;
        for (int i = 0; i < key.length; i++) {
            if (s[s.length - 1 - i] != key[key.length - 1 - i]) {
                break;
            }
            sufIndex++;
        }

        if (preCount + sufIndex >= key.length) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 23764
from collections import defaultdict as dd
N,C=map(int,input().split())
d=[list(map(int,input().split())) for i in range(C)]
c=[list(map(int,input().split())) for i in range(N)]
table=[dd(int) for i in range(3)]

for i in range(N):
    for j in range(N):
        k=(i+j)%3
        table[k][c[i][j]-1]+=1

ans=10**10
for i in range(C):
    t1=0
    for x in table[0]:
        t1+=d[x][i]*table[0][x]
    for j in range(C):
        if i==j:continue
        t2=0
        for x in table[1]:
            t2+=d[x][j]*table[1][x]
        for k in range(C):
            if i==k or j==k:continue
            t3=0
            for x in table[2]:
                t3+=d[x][k]*table[2][x]
            
            ans=min(ans,t1+t2+t3)
print(ans)




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

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

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

int main() {

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

	int N;
	vector<int> G(3);
	cin >> N >> G[0] >> G[1] >> G[2];

	vector<int> len(N);
	for (int i = 0; i < N; i++) cin >> len[i];

	int cnt, tmp, bit, bitmp;
	int out = INF;
	for (int ran = 0; ran < 20; ran++) {

		random_shuffle(G.begin(), G.end());
		vector<int> ans(3, INF);
		bit = (1 << N) - 1;

		for (int k = 0; k < 3; k++) {

			for (int i = 1; i < (1 << N); i++) {

				cnt = -1, tmp = 0;
				for (int j = 0; j < N; j++) {
					if (i & (1 << j) & bit) {
						cnt++;
						tmp += len[j];
					}
				}

				if (!tmp) continue;

				if (ans[k] > abs(tmp - G[k]) + cnt * 10) {
					ans[k] = abs(tmp - G[k]) + cnt * 10;
					bitmp = ~i;
				}

			}
			bit &= bitmp;
		}
		out = min(out, ans[0] + ans[1] + ans[2]);
	}
	cout << out << "\n";

	return 0;
}


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

struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007



int main() {
    int N; cin >> N;
    ll dp[105][5][5][5] = {};
    dp[0][0][0][0] = 1;
    rep(i, N) {
        rep(a, 5) {
            rep(b, 5) {
                rep(c, 5) {
                    for (int d = 1; d <= 4; d++) {
                        if (b == 1 && c == 3 && d == 2) continue;
                        if (a == 1 && c == 3 && d == 2) continue;
                        if (b == 3 && c == 1 && d == 2) continue;
                        if (b == 1 && c == 2 && d == 3) continue;
                        if (a == 1 && b == 3 && d == 2) continue;
                        dp[i + 1][b][c][d] = (dp[i + 1][b][c][d] + dp[i][a][b][c]) % MOD;
                    }
                }
            }
        }
    }
    ll ans = 0;
    rep(a, 5) {
        rep(b, 5) {
            rep(c, 5) {
                ans = (ans + dp[N][a][b][c]) % MOD;
            }
        }
    }
    cout << ans << endl;
    return 0;
}






Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
#define cu cout<<
#define en endl
#define sp " "
#include<cstdio>
#include<cstring>
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
/*#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                pe[j] = false;
        }
    }
}*/
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
bool isprime(ll n)
{
    if(n<2) return 0;
    if(n==2) return 1;
    else
    {
        for(int i=2; i*i<=n; i++)
            if(n%i==0) return 0;
    }
    return 1;
}
map<int , int >mp;
set<int  > st;
multiset<string> :: iterator it;
deque <char> q ;
int vis [10000000];
pair<int,int> a[2020];
int main()
{
    fast ;
     ll n,x;
    cin >> n >> x;
    vector <ll> ar(n);
    ll ans=0,prev=0;
    for ( int i=0; i<n; i++)
    {
        cin >> ar[i];
        ll  allowed = x - prev;
        if (ar[i]> allowed)
        {
            ans += ar[i] - allowed;
            prev = allowed;
        }
        else
        {
            prev = ar[i];
        }

    }
    cout  << ans <<endl;
}




Measured memory_bytes: 3972
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0), ios::sync_with_stdio(false);
	int n; cin >> n;
	string ans = "";
	while(n != 0){
		if(n%2 != 0){
			ans = "1"+ans;
			n--;
		}else{
			ans = "0"+ans;
		}
		n /= -2;
	}
	if(ans == "") ans = "0";
	cout << ans;
	cout << "\n";
	return 0;
}


Measured memory_bytes: 3616
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def POW(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x
    elif y % 2 == 0:
        return POW(x, y // 2) ** 2 % MOD
    else:
        return POW(x, y // 2) ** 2 * x % MOD
def mod_factorial(x, y): return x * POW(y, MOD - 2) % MOD
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from functools import reduce

def main():
    N = II()
    x = 800 * N
    y = 200 * (N // 15)
    ans = x - y
    return ans

print(main())

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

vector<bool> IsPrime;

void sieve(size_t max) {
    if (max+1 > IsPrime.size()) {
        IsPrime.resize(max+1, true);
    }
    IsPrime[0] = false;
    IsPrime[1] = false;

    for (size_t i = 2; i*i <= max; i++) {
        if (IsPrime[i]) {
            for (size_t j = 2; i*j <= max; j++) {
                IsPrime[i*j] = false;
            }
        }
    }
}

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

    ll X;
    cin >> X;

    ll N = 100100;
    sieve(N);

    for (ll i = 0; i < IsPrime.size(); i++) {
        if (IsPrime[i]) {
            if (i >= X) {
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <queue>
 
using namespace std;
 
struct edge{
  int to;
  int cost;
};
 
int d[2001][6011];
vector<edge> G[6011];
bool isGas[10001];
map<string,int> m;
int idx;
int st,gl;
 
int N,M,cap;
const int INF=1<<30;
typedef pair<int,int> pii;
typedef pair<int,pii> Sit;
 
int dijkstra(){
  for(int i=0;i<2001;i++)
    for(int j=0;j<6011;j++)
      d[i][j]=INF;
  priority_queue<Sit,vector<Sit>,greater<Sit> > pq;
  pq.push(make_pair(0,pii(cap*10,st)));
  d[cap*10][st]=0;
  while(pq.size()){
    Sit p=pq.top();pq.pop();
    int ccost=p.first;
    int ccap=p.second.first;
    int cnode=p.second.second;
    if(d[ccap][cnode]<ccost)continue;
    for(int i=0;i<(int)G[cnode].size();i++){
      edge &e=G[cnode][i];
      int ncap=ccap-e.cost;
      if(ncap<0)continue;
      int nnode=e.to;
      int ncost=ccost+e.cost;
      if(isGas[nnode])ncap=cap*10;
      if(d[ncap][nnode]>ncost){
    d[ncap][nnode]=ncost;
    pq.push(make_pair(ncost,pii(ncap,nnode)));
      }
    }
  }
  int res=INF;
  for(int i=0;i<2001;i++)
    res=min(res,d[i][gl]);
  return res;
}
 
int main(){
  while(cin>>N>>M>>cap&&(N|M|cap)){
    memset(isGas,0,sizeof(isGas));
    for(int i=0;i<6011;i++)G[i].clear();
    m.clear();
    idx=0;
    string s,t;
    cin>>s>>t;
    if(m.count(s)==0)m[s]=idx++;
    if(m.count(t)==0)m[t]=idx++;
    st=m[s];gl=m[t];
    for(int i=0;i<N;i++){
      string a,b;
      int c;
      cin>>a>>b>>c;
      if(m.count(a)==0)m[a]=idx++;
      if(m.count(b)==0)m[b]=idx++;
      int x,y;
      x=m[a];y=m[b];
      edge e;
      e.to=y;
      e.cost=c;
      G[x].push_back(e);
      e.to=x;
      G[y].push_back(e);
    }
    for(int i=0;i<M;i++){
      string s;
      cin>>s;
      if(m.count(s)==0)m[s]=idx++;
      isGas[m[s]]=true;
    }
    int res=dijkstra();
    if(res==INF)cout<<-1<<endl;
    else cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 60000