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

using namespace std;

#define pb push_back
#define int long long


int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int now = 0;
    for (int i = 0; i < 1e7; i++){
        now = (now * 10 + 7) % n;
        if (now == 0){
            cout << i + 1;
            return 0;
        }
    }
    cout << -1;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d, e;
  cin >> a;
  b = a/1000;
  c = (a - 1000*b)/100;
  d = (a - 1000*b - 100*c)/10;
  e = (a - 1000*b - 100*c - 10*d);
  if (b == c || c == d || d == e) {
    cout << "Bad" << endl;
  }
  else {
    cout << "Good" << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k,d=1001001001; cin>>n>>k;
  vector<int> h(n); for(int i=0;i<n;i++) cin>>h[i];
  sort(h.begin(),h.end());
  for(int i=0;i<=n-k;i++) d=min(d,h[i+k-1]-h[i]);
  cout<<d;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(ALL(A),greater<>());
    vector<ll> e;
    rep(i,N){
        if(A[i]==A[i+1]&&i+1<N){
            e.push_back(A[i]);
            i++;
        }
    }
    if(e.size()>1)cout << e[0]*e[1] << endl;
    else cout << "0" << endl;
}


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

#define Ff(i,a,b) for(i=a;i<b;i++)
#define Fb(i,a,b) for(i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define mp make_pair
#define PI 2*asin(1)
#define all(x) x.begin(),x.end()
#define trav(x) for(auto& i:x)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define spc ' '

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<long long> vll;
typedef map<int, int> mi;
typedef map<long long, long long> mll;
typedef unordered_map<int, int> umi;
typedef unordered_map<long long, long long> umll;
typedef set<int> si;
typedef set<long long> sll;
typedef unordered_set<int> usi;
typedef unordered_set<long long> usll;

#define int long long

void sub() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
}


void solve() {
	int x, k, d;
	cin >> x >> k >> d;
	int i = 0;
	i = abs(x) / d;
	if (i > k) {
		cout << abs(x) - k*d << endl;
		return;
	}
	x = abs(x) - i * d;

	if ((k - i) & 1)
		k = d - x;
	else k = x;
	cout << k << endl;

}



int32_t main() {
	FIO
	sub();
	int t = 1;
	// cin >> t;
	while (t--)
		solve();

	return 0;
}




Measured memory_bytes: 3576
/* c */
#include <bits/stdc++.h>
#define Fail puts("NO"), exit(0);
#define eps 1e-10
#define maxn 100010
#define maxm 4010
#define inf 1000000007
#define mod 1000000007
#define G 3
#define pi acos(-1)
#define mp(x, y) make_pair(x, y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef bitset<maxn> bit;
int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch - '0' < 0 || ch - '0' > 9) {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch - '0' >= 0 && ch - '0' <= 9) {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
int n;
int gcd(int x, int y) {
    if (!y)
        return x;
    return gcd(y, x % y);
}
int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            for (int k = 1; k <= n; k++)
                ans = ans + gcd(gcd(i, j), k);
    cout << ans << endl;
    return 0;
}


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

int main() {
	int n,sum=0; cin>>n;
	vector<int> b(n);
	for(int i=1; i<n; i++)
		cin>>b[i];
	sum+=b[1]+b[n-1];
	for(int i=1; i<n-1; i++)
		sum+=min(b[i],b[i+1]);
	cout<<sum<<"\n";
	return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
//ll MOD = 1000000007;
ll MOD = 998244353;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

bool check(string s,string s1){
    int n = s.size();
    rep(i,n){
        if(s[i] != s1[i])return false;
    }
    return true;
}
signed main()
{   
  gearup;
  string s; cin >> s;
  int n = s.size();
  rep1(i,n){
      string t = s.substr(0,n-i);
      int m = t.size();
      //out(t);
      if(m&1)continue;
      string t1 = t.substr(0,m/2);
      string t2 = t.substr(m/2);
      
      if(check(t1,t2)){
          out(m);
          return 0;
      }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>

using namespace std;

int main() {
	int n, k;
	string s;

	cin >> n >> k;
	cin >> s;

	transform(s.begin() + k - 1, s.begin() + k, s.begin() + k - 1, ::tolower);

	cout << s << endl;

	return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':
	n,m,x,y = map(int,input().split())
	X = list(map(int,input().split()))
	Y = list(map(int,input().split()))
	X.sort()
	Y.sort()

	flg = False
	#xの場所がYのFROM-に入っていないこと
	if (Y[0] <= x):
		flg = True
	#yの場所がXのFROM-に入っていないこと
	elif (y <= X[n-1]):
		flg = True
	#Xの右端とYの左端が交わらないこと
	elif (X[n-1] >= Y[0]):
		flg = True
 
	if flg:
		print("War")
	else:
		print("No War")


Measured memory_bytes: 9056
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define int long long

using namespace std;
const int MOD=1000000007;
const int INF=1000000000;
const double eps=1e-10;

signed main(){
  int h,w;
  cin>>h>>w;
  if(h%3==0||w%3==0){
    cout<<0<<endl;
  }else{
    int ans=INF;
    LOOP(i,1,w){
      int a=h*i,b=(w-i)*(h/2),c=(w-i)*(h-h/2);
      int ma=max(a,max(b,c)),mi=min(a,min(b,c));
      ans=min(ans,ma-mi);

      a=h*i,b=h*((w-i)/2),c=h*((w-i)-(w-i)/2);
      ma=max(a,max(b,c)),mi=min(a,min(b,c));
      ans=min(ans,ma-mi);
    }
    LOOP(i,1,h){
      int a=w*i,b=w*((h-i)/2),c=w*((h-i)-(h-i)/2);
      int ma=max(a,max(b,c)),mi=min(a,min(b,c));
      ans=min(ans,ma-mi);

      a=w*i,b=(h-i)*(w/2),c=(h-i)*(w-w/2);
      ma=max(a,max(b,c)),mi=min(a,min(b,c));
      ans=min(ans,ma-mi);
    }
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using P = pair<int,int>;
class UnionFind {
public:
    vector < ll > par; // 各元の親を表す配列
    vector < ll > siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};
int main()
{
  int N,M;
  cin >> N >> M;
  vector<int> A(N);
  UnionFind UF(N);
  REP(i, N){
    cin >> A[i];
    A[i]--;
  }
  vector<P> B(M);
  REP(i,M){
    cin >> B[i].first >> B[i].second;
    B[i].first--;
    B[i].second--;
    UF.merge(B[i].first,B[i].second);
  }
  
  int cnt = 0;
  REP(i,N){
    if(UF.issame(i,A[i])){
      cnt++;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 5780
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n';
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << endl;
}


Measured memory_bytes: 256
import itertools

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

ab_list = []

for _ in range(0, m):
    a, b = list(map(int, input().split()))
    ab_list.append((a, b))
    ab_list.append((b, a))

# 全探索で解く場合
l = range(1, n+1)
count = 0
roots = [v for v in itertools.permutations(l, n) if v[0] == 1]

for v in roots:
    is_ok = True
    for i, _ in enumerate(list(v)[:-1]):
        # 探索対象となるエッジ
        target_edge = (list(v)[i], list(v)[i+1])
        if (target_edge not in ab_list):
            is_ok = False

    if is_ok:
        count += 1

print(count)


Measured memory_bytes: 3572
#include       <set>
#include       <map>
#include     <queue>
#include     <cmath>
#include    <cstdio>
#include    <cctype>
#include    <vector>
#include   <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int maxn = 1e5+5;

ll fast_pow(ll a,ll b,ll mod){
    ll ans = 1;
    while(b){
        if(b&1)
            ans = ans*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return ans;
}
int a[127];
int c[127];
int main(){
    int n;
    char str[55];
    scanf("%d",&n);
    memset(c,0x3f,sizeof(c));
    for(int i=0;i<n;i++){
        scanf("%s",str);
        memset(a,0,sizeof(a));
        for(int j=0;str[j];j++)
            a[str[j]]++;
        for(int j='a';j<='z';j++)
            c[j] = min(c[j],a[j]);
    }
    for(int j='a';j<='z';j++)
        while(c[j])putchar(j),c[j]--;
}

/*

1592794101
989097785


232162543

*/


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		

		Scanner sc=new Scanner(System.in);
		String suu=sc.next();
		String[] array=suu.split("");
		int[] colorArray=new int[array.length];
		int colorCangeCnt=0;
		
		for(int i=0;i<array.length;i++) {
			colorArray[i]=Integer.parseInt(array[i]);
		}
		
		for(int i=0;i<colorArray.length-1;i++) {
			if(colorArray[i]==colorArray[i+1]) {
				if(colorArray[i+1]==0) {
					colorArray[i+1]=1;
					colorCangeCnt++;
				}else {
					colorArray[i+1]=0;
					colorCangeCnt++;
				}
			}
		
		}

		System.out.println(colorCangeCnt);
	}

}


Measured memory_bytes: 33188
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    //    ifstream in("input.txt");
    //    cin.rdbuf(in.rdbuf());
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    string s = to_string(n);
    
    int sn = 0;
    rep(i, s.size())
    {
        sn += int(s[i] - '0');
    }
    
    if (n % sn == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 380
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a = sorted(a)
f = sorted(f, reverse = True)

def solve(mid):
    tmp = [0]*n
    for i in range(n):
        tmp[i] = mid // f[i]
    res = 0
    for i in range(n):
        if tmp[i] < a[i]:
            res += a[i] - tmp[i]
    #print(tmp, a)
    if res <= k:
        return True
    else:
        return False
     
ok = 10**12 + 1
ng = 0

if solve(0):
    print(0)
    exit()
    
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid
print(ok)
    
  
    

Measured memory_bytes: 123212
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#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; }
typedef long long ll;

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


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  char c; std::cin >> c;
  if ( c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o' ) std::cout << "vowel" << std::endl;
  else std::cout << "consonant" << std::endl;
  return 0;
}


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

int main(){
    string s;
    int k, num;
    cin >> k >> s;
    num=s.size();
    if(num<=k) cout << s << endl;
    else{
        s.erase(k+1);
        s.replace(k, 1, "...");
        cout << s << endl;
    }
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (b < a) {
			System.out.println(a - 1);
		} else {
			System.out.println(a);
		}
	}
}


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

using namespace std;

int main() {
    char c;
    cin>>c;
    if(c=='A')
        cout<<"T";
    else if(c=='T')
        cout<<"A";
    else if(c=='G')
        cout<<"C";
    else if(c=='C')
        cout<<"G";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()

int n, mod = 1e9 + 7;; 
vector<vector<int>> graph;
ll dp[100003][2];
// B -- W
// W -- B/W

ll solve(int u, int p, bool p_black){
	if(dp[u][p_black] != -1) return dp[u][p_black];
	ll ways_white = 1;
	for(int v : graph[u]){
		if(v == p) continue;
		ways_white *= solve(v,u,0);
		ways_white %= mod;
	}
	ll ways_black = 0;
	if(!p_black){
		ways_black = 1;
		for(int v : graph[u]){
			if(v == p) continue;
			ways_black *= solve(v,u,1);
			ways_black %= mod;
		}
	}
	return dp[u][p_black] = (ways_black + ways_white) % mod;
}


void solution(){
	cin >> n;
	graph = vector<vector<int>>(n);
	for(int i = 0; i < n-1; i++){
		int u, v; cin >> u >> v;
		u--; v--;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	memset(dp,-1,sizeof(dp));
	cout << solve(0,-1,0) << endl;

}	


int main(){ 

	fio;
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// cout << "Case #" << i << ": ";
		solution();
	} 
	return 0;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
const int MOD=1000000007;
const int INF=LLONG_MAX/2;

signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    if(n<10){
        cout<<n<<endl;
    }else if(n<100){
        cout<<9<<endl;
    }else if(n<1000){
        cout<<n-90<<endl;
    }else if(n<10000){
        cout<<909<<endl;
    }else if(n<100000){
        cout<<n-9090<<endl;
    }else{
        cout<<90909<<endl;
    }
    return 0;
}


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

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>

i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

i64 cup(i64 xxx, i64 yyy) {//切り上げ
	return (xxx + yyy - 1) / yyy;
}

//メモリ置き場
int n;
vector<int> dat;

//inputします
void input() {
	cin >> n;
	dat.resize(n);
	ff(i, 0, n) {
		cin >> dat[i];
	}
}

//ライブラリ置き場



//main
int main() {
	input();
	ff(i, 0, n) {
		if (dat[i] % 2 == 0) {
			if (dat[i] % 3 != 0 && dat[i] % 5 != 0) {
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}
	cout << "APPROVED" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
using matrix = vector<vector<uint>>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    char c[4];
    cin >> c;
    cout << (c[0] == '7' || c[1] == '7' || c[2] == '7' ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using P = pair<int,int>;
using Graph =vector<string>;
Graph field;
queue<P> q;

int main() {
  ll c=1000000007;
  ll ans,n,ans1,an;
  ans=0;
  ans1=0;
  cin>>n;
  rep(i,n){
    ll a;
    cin>>a;
    ans=(ans+a)%c;
    ans1=(ans1+(a*a)%c)%c;
  }
  an=((ans*ans)%c-ans1);
  if(an<0)an=an+c;
  an *= (c + 1) / 2;
  cout<<an%c<<endl;
}



Measured memory_bytes: 3588
M = []
A = []
R = []
C = []
H = []
ans = 0
n = int(input())
for _ in range(n):
    tmp = input()
    if tmp[0] == "M":
        M.append(tmp)
    elif tmp[0] == "A":
        A.append(tmp)
    elif tmp[0] == "R":
        R.append(tmp)
    elif tmp[0] == "C":
        C.append(tmp)
    elif tmp[0] == "H":
        H.append(tmp)
if len(M) == 0 and len(A) == 0 and len(R) == 0 and len(C) == 0 and len(H) == 0:
    print(ans)
else:
    lenM = len(M)
    lenA = len(A)
    lenR = len(R)
    lenC = len(C)
    lenH = len(H)

    ans += lenM * lenA * lenR
    ans += lenM * lenA * lenC
    ans += lenM * lenA * lenH
    ans += lenM * lenR * lenC
    ans += lenM * lenR * lenH
    ans += lenM * lenC * lenH
    ans += lenA * lenR * lenC
    ans += lenA * lenR * lenH
    ans += lenA * lenC * lenH    
    ans += lenR * lenC * lenH

    print(ans)

Measured memory_bytes: 55768
#define _USE_MATH_DEFINES
#include <sstream> //string stream its useful!
#include<string>
#include<iostream>
#include<utility> //pair
#include <vector> // vector
#include <algorithm>    // swap,sort,binary_search
#include <functional>   // std::greater
#include <map> //map
#include<set> //set
#include<queue> //queue
#include<list> //list
#include<cmath>
#include<numeric>
#include<cassert>
#include <iomanip> //cout<<setprecision
#include <regex>



typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
ll W = 1000000007;


using namespace std;
void omajinai() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(15);
    //freopen("txt.csv","r",stdin);
}


class Main{
public:
    Main(){
        
    }
    
    
    void run(){
        vector<ll> X(100001,0);
        int N; ll K; cin>>N>>K;
        REP(i,N){
            int a, b; cin>>a>>b;
            X[a]+=b;
        }
        int ans = 0;
        while(K>0){
            ans++;
            K-=X[ans];
        }
        cout<<ans<<endl;
    }
};

int main(){
    omajinai();
    Main().run();
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		// 入力値
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		sc.close();
		//char[] abc = {'A','B','C'};
		int cnt = 0;
		//int abccnt = 0;
		for(int i=0;i<n-2;i++){
			if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') cnt++;
			/*
			if(s[i]==abc[abccnt]){
				abccnt++;
			}else{
				abccnt=0;
			}
			if(abccnt==3){
				abccnt=0;
				cnt++;
			}
			*/
		}
		System.out.println(cnt);
    }
}

Measured memory_bytes: 22612
import java.util.*;

public class Main{
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int cnt = 0;
        for (int i=0;i<=a;i++) {
            for (int j=0;j<=b;j++) {
                for (int k=0;k<=c;k++) {
                    if ((i*500 + j*100 + k*50) == x)
                        cnt++;
                }
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
  int a, b, c, x;
  int cnt = 0;
  cin >> a >> b >> c >> x;
  for (int i=0; i<=a; i++){
    for (int j=0; j<=b; j++){
      if ( ( (x - 500*i - 100*j) / 50 <= c) && (x - 500*i - 100*j >= 0 ) )
        cnt++;
    }
  }
  cout << cnt;
  return 0;
}

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

int N;

int main() {
	cin >> N;
	int ans = 30;
	for (int i = 0; i < N; i++) {
		int a, buf = 0;
		cin >> a;
		while ((a & 1) == 0) {
			a = (a >> 1);
			buf++;
		}
		ans = min(buf, ans);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

    int N; scanf("%d", &N);

    int a[N];
    for(int i = 0; i < N; i++) scanf("%d", &a[i]);

    int j, key;

    
    for(int p = 0; p < N; p++) {
        if(p < N-1) {
            printf("%d ", a[p]);
        }else{
            printf("%d\n", a[p]);
        }
    }

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

        key = a[i];

        j = i-1;

        while(j >=0 && a[j] > key) {

            a[j+1] = a[j];
            j--;            
            
        }

        a[j+1] = key;

        
        for(int p = 0; p < N; p++) {
            if(p < N-1) {
                printf("%d ", a[p]);
            }else{
                printf("%d\n", a[p]);
            }
        }
        
    }


    return 0;
}


Measured memory_bytes: 2100
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            double a = in.nextDouble();
            double b = in.nextDouble();

            out.print((int) Math.ceil((a + b) / 2));
        }

    }
}



Measured memory_bytes: 23124
s = input()
num = int(input())
t = "X"
reverse = False

for _ in range(num):
    row = input().split()
    if len(row) == 1:
        if reverse == False:
            reverse = True
        else:
            reverse = False
    else:
        x = row[1]
        y = row[2]
        if x == "1" and reverse:
            t += y
        elif x == "1" and not reverse:
            t = y + t
        elif x == "2" and reverse:
            t = y + t
        else:
            t += y

if reverse:
    t = t.replace("X", s)
    print(t[::-1])
else:
    t = t.replace("X", s)
    print(t)

Measured memory_bytes: 4384
import numpy as np
s=input()
n=len(s)
MOD=1000000007
wayA=np.array([0,0,0,0])
wayB=np.array([0,0,0,0])
wayC=np.array([0,0,0,0])
hatena=0
for c in s:
	if c=="A":
		wayA[0]+=1
	if c=="B":
		wayB+=wayA
	if c=='C':
		wayC+=wayB
	if c=='?':
		wayC[1]=wayC[1]+wayB[0]
		wayC[2]=wayC[2]+wayB[1]
		wayC[3]=wayC[3]+wayB[2]
		wayB[1]=wayB[1]+wayA[0]
		wayB[2]=wayB[2]+wayA[1]
		wayA[1]=wayA[1]+1
		hatena+=1
ans=0
for i in range(0,4):
	ans+=pow(3,hatena-i)*wayC[i]
print(int(ans%MOD))

Measured memory_bytes: 21500
#include<stdio.h>
#include<string.h>
int Y[]={-1,0,1,0,0 ,0,0,0,-1,0};
int X[]={0,1,0,-1,-1,0,1,0,0, 0};
int main(){
  int h,w,i,j,ny,nx,t,r,min,my,mx,y[1000],x[1000],yy,yx,l;
  char m[20];
  while(scanf("%d %d",&h,&w),h||w){
    char d[30][30]={0};
    int c[30][30]={0};
    for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
	scanf(" %c",&d[i][j]);
	if(d[i][j]=='A')d[y[0]=i][x[0]=j]='.';
	if(d[i][j]=='B')d[yy=i][yx=j]='.';
      }
    }
    c[y[t=0]][x[0]]=1;
    for(r=1;r-t;t++){
      for(i=0;i<4;i++){
	ny=y[t]+Y[i];
	nx=x[t]+X[i];
	if(d[ny][nx]-'.'||c[ny][nx])continue;
	c[y[r]=ny][x[r]=nx]=c[y[t]][x[t]]+1;
	r++;
      }
    }
    /*for(i=0;i<h;i++){
      for(j=0;j<w;j++)printf("%2d ",c[i+1][j+1]);printf("\n");
      }*/
    scanf("%s",m);
    l=strlen(m);
    min=10000;
    for(i=0;i<10000;i++){
      if(c[yy][yx]&&c[yy][yx]<=i+1){
	if(min>i){
	  min=i;
	  my=yy;
	  mx=yx;
	}
      }
      ny=yy+Y[m[i%l]-'0'];
      nx=yx+X[m[i%l]-'0'];
      if(d[ny][nx]){
	yy=ny;
	yx=nx;
      }
    }
    if(min-i)printf("%d %d %d\n",min,my-1,mx-1);
    else     printf("impossible\n");
  }
  return 0;
}
    

Measured memory_bytes: 620
#include <bits/stdc++.h>
 #include <string> 
 #include <math.h>
 #include <bitset>
 using namespace std;
 
 int main(){
    int i;
    int N;
    int V[25];
    int C[25];
    int ans = 0;

    cin >> N;

    for(i=0; i<N; i++){
        cin >> V[i];
        }

    for(i=0; i<N; i++){
        cin >> C[i];
        }

    for(i=0; i<N; i++){
        if (V[i]-C[i] > 0)
            ans = ans + V[i]-C[i];
        }

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



Measured memory_bytes: 256
D=int(input())
c=list(map(int,input().split()))
last=[0 for i in range(26)]
cost=[0 for i in range(26)]
degree=[0 for i in range(26)]
s=[]
for _ in range(D):
  s.append(list(map(int,input().split())))

for d in range(D):
  for i in range(26):
    cost[i]=c[i]*(d-last[i])
    degree[i]=s[d][i]-cost[i]
  k=degree.index(max(degree))
  last[k]=d
  print(k+1)

Measured memory_bytes: 9428
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<31-1;
const int MOD = 1000000007;

char maze[MAX][MAX];

void solve(void){
    int H, W;
    cin >> H >> W;

    rep(H, i) {
        rep(W, j) cin >> maze[i][j];
    }

    bool f = true;
    rep(H, i) {
        rep(W, j) {
            if (maze[i][j] == '.') continue;
            bool iso = true;
            if (i != 0) iso = iso && maze[i-1][j] == '.';
            if (i != H-1) iso = iso && maze[i+1][j] == '.';
            if (j != 0) iso = iso && maze[i][j-1] == '.';
            if (j != W-1) iso = iso && maze[i][j+1] == '.';
            if (iso) f = false;
        }
    }

    cout << (f?"Yes":"No") << '\n';
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    int n; cin >> n;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        while (a % 2 == 0) {
            sum++;
            a /= 2;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
t = input()
temp = s[:]
cnt = 0
strmax = len(t)
ans = 0
flag = True

while cnt<strmax:
	num = temp.find(t[cnt])
	if num != -1:
		ans+=num+1
		temp = temp[num+1:]
		cnt+=1
		flag = False
	else:
		if flag:
			print("-1")
			exit(0)
		ans+=len(temp)
		temp = s[:]
		flag = True

print(ans)


Measured memory_bytes: 3456
N,M=map(int,input().split())
G=[]
for i in range(0,N):
    G.append([])

for i in range(0,M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

q=[]
sign=[-1]*N
sign[0]=0
q.append(0)
while q:
    x=q.pop(0)
    for nv in G[x]:
        if sign[nv]==-1:
            sign[nv]=x
            q.append(nv)

print("Yes")
for i in range(1,N):
    print(sign[i]+1)


Measured memory_bytes: 33864
def main():
    n = int(input())
    s = input()
    j = 0
    ans = 0
    firsts = set(["0","1","2","3","4","5","6","7","8","9"])
    while len(firsts)>0 and j < len(s)-2:
        if s[j] in firsts:
            seconds = set(["0","1","2","3","4","5","6","7","8","9"])
            firsts.remove(s[j])
            k = j+1
            while len(seconds) > 0 and k < len(s)-1:
                if s[k] in seconds:
                    thirds = set(["0","1","2","3","4","5","6","7","8","9"])
                    seconds.remove(s[k])
                    t = k+1
                    while len(thirds) > 0 and t < len(s):
                        if s[t] in thirds:
                            thirds.remove(s[t])
                            ans += 1
                        t += 1
                k += 1
        j += 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b ,&c, &d);

  int ans = min(a, b) + min(c, d);
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<long long>
#define FOR(n) for(int i=0;i<n;i++)
#define till(n) for(int i=1;i<=n;i++)
#define mod 1000000007
using namespace std;

ll a[100005][4];

ll dp[100005][4];

ll getAns(int n, int chosen = 0){
    if(n==0) return 0;

    if(dp[n][chosen] != -1) return dp[n][chosen];

    ll ans = -1;
    for(int i=1;i<=3;i++)
        if(i!=chosen)
            ans = max(ans, getAns(n-1, i) + a[n][i]);


    return dp[n][chosen] = ans;
}

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

    int n;cin>>n;

    for(int i=0;i<=n;i++){
        for(int j=0;j<=3;j++){
            dp[i][j] = -1;
        }
    }

    for(int i=1;i<=n;i++)cin >>a[i][1]>>a[i][2]>>a[i][3];

    cout << getAns(n) << endl;

	return 0;
}


Measured memory_bytes: 12800
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int N;
    int x;
    int ser, ler;
    vector<int> v;
    vector<int> nosort;
    scanf("%d",&N);
    for(int i = 0; i < N; i++){
        scanf("%d", &x);
        v.push_back(x);
        nosort.push_back(x);
    }
    sort(begin(v),end(v));
    ser = v[N/2-1];
    ler = v[N/2];

    int i = 0;
    for(int elem : nosort){
        if(elem <= ser) printf("%d\n", ler);
        else printf("%d\n", ser);
    }

    return 0;
}


Measured memory_bytes: 3948
a, b, ab, x, y = map(int, input().split())

na = 0
nb = 0
nab = 0

if a+b >= 2*ab:
  nab += 2*min(x, y)
  if x > y:
    if ab*2 >= a:
      na += x - int(nab/2)
    else:
      nab += 2*(x - int(nab/2))
  else:
    if ab*2 >= b:
      nb += y - int(nab/2)
    else:
      nab += 2*(y - int(nab/2))
else:
  na += x
  nb += y

print(na*a + nb*b + nab * ab)

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

using namespace std;

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

typedef pair<int, int> pii;
typedef pair<int, pii> pip;

int n;
int maps[10][10];
int cnt; // ???????????????????¨?
int m[4] = {0, 5, 9, 13};
int dx[13] = {0,1,0,-1,0,1,1,-1,-1,2,0,-2,0};
int dy[13] = {0,0,-1,0,1,-1,1,1,-1,0,-2,0,2};
stack<pip> ans; // x, y, size

bool ismap(int x, int y) {
	return x >= 0 && x < 10 && y >= 0 && y < 10;
}

// (x, y) ??? ????????? ?????¨???????????§?????§??????
int sim(int x, int y) {
	int res = 0;
	REP(i, 3) {
		FOR(j, m[i], m[i + 1]) {
			int nx = x + dx[j], ny = y + dy[j];
			if (!ismap(nx, ny) || !maps[ny][nx]) return res;
		}
		res++;
	}
	return res;
}

// (x, y)?????????????????????s????????????k?¶????
void sum(int x, int y, int s, int k) {
	REP(i, m[s]) {
		int nx = x + dx[i], ny = y + dy[i];
		maps[ny][nx] += k;
	}
}

// (x, y) ????????¢?´¢ ?????? k ???
bool dfs(int x, int y, int k) {
	if (y == 10 && cnt == 0) return true;
	if (k < 0) return false;
	if (!ismap(x, y)) return false;
	
	if (ismap(x - 2, y - 2) && maps[y - 2][x - 2]) return false;
	
	int ms = sim(x, y);
	REP(i, ms) {
		sum(x, y, i + 1, -1);
		cnt -= m[i + 1];
		
		if (dfs(x, y, k - 1)) {
			ans.push(pip(x, pii(y, i + 1)));
			return true;
		}
		
		cnt += m[i + 1];
		sum(x, y, i + 1, 1);
	}
	
	int tmp = y * 10 + x + 1;
	if (dfs(tmp % 10, tmp / 10, k)) return true;
	
	return false;
}

int main() {
	cin >> n;
	REP(i, 10) REP(j, 10) {
		scanf("%d", &maps[i][j]);
		cnt += maps[i][j];
	}
	
	dfs(0, 0, n);
	
	
	while(!ans.empty()) {
		pip p = ans.top(); ans.pop();
		printf("%d %d %d\n", p.first, p.second.first, p.second.second);
	}
	
	
	return 0;
}

Measured memory_bytes: 1236
#include<stdio.h>
#include<algorithm>
#include<set>
using namespace std;
set<int>s;
struct ship
{
	int x,y;
}a[200005];
int main()
{
	s.clear();
	int N,M,flag=0;
	scanf("%d%d",&N,&M);
	for(int i=1;i<=M;i++)
	{
		scanf("%d%d",&a[i].x,&a[i].y);
		if(a[i].x==1)
		{
			flag++;
			s.insert(a[i].y);
		}
		if(a[i].y==N)
		{
			flag++;
			s.insert(a[i].x);
		}
	}
	if(s.size()<flag)
		printf("POSSIBLE\n");
		else
		printf("IMPOSSIBLE\n");
	return 0;
}


			
        	
		

Measured memory_bytes: 11136
#include<stdio.h>
int main(){
  int c,n;
  for(;;){
    scanf("%d",&n);
    if(n==0)
      break;
    for(c=0;n!=1;c++){
      if(n%2)
	n=n*3+1;
      else
	n/=2;
    }
    printf("%d\n",c);
  }
  return 0;
}

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

int main()
{
    int n;
    cin >> n;

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

    int ans = b[a[n - 1] - 1];
    rep (i, n - 1)
    {
        ans += b[a[i] - 1];
        if (a[i + 1] - a[i] == 1)
            ans += c[a[i] - 1];
    }

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
struct l
{
    int v;
    l* prv;
    l* next;
};
void DeleteNode(l* del, l** first, l** last)
{
    if (del->prv != NULL)
        del->prv->next = del->next;
    else
        *first = del->next;
        
    if (del->next != NULL)
        del->next->prv = del->prv;
    else
        *last = del->prv;

    delete del;
    del = NULL;
}
int main()
{
    l* t;
    l* first = NULL;
    l* last = NULL;
    int n;
    cin >> n;
    long v; char s[12];
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        if (s[0] == 'i')
        {
            l* t = new l();
            t->prv = NULL;
            t->next = NULL;
            cin >> t->v;
            if (last == NULL)
            {
                last = t;
            }
            else
            {
                first->prv = t;
            }
            t->next = first;
            first = t;
            continue;
        }

        if (first == NULL)
            continue;

        if (s[6] == 'F')
        {
            DeleteNode(first, &first, &last);
        }
        else if (s[6] == 'L')
        {
            DeleteNode(last, &first, &last);
        }
        else
        {
            long a;
            cin >> a;

            for (l* t = first; t != NULL; t = t->next)
            {
                if (t->v == a)
                {
                    DeleteNode(t, &first, &last);
                    break;
                }
            }
        }
    }

    t = first;
    while (t != NULL)
    {
        l* old = t;
        cout << t->v << (t->next != NULL ? " " : "\n");
        t = t->next;
        delete old;
    }
}



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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

int dp[1005][1005];
bool visi[1005][1005];
string f[1005];
int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    string s,t;
    cin>>s>>t;
    int num = (int)t.size();
    int n = (int)s.size();
    int ret = inf;
    for(int i=0;i+num-1<n;++i){
        int tmp = 0;
        for(int j=0;j<num;++j){
            if(s[i+j] != t[j])tmp++;
        }
        ret = min(ret,tmp);
    }
    cout << ret << endl;
    return 0;
    
}


Measured memory_bytes: 3676
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cnt = sc.nextInt();

		int[] josi = new int[cnt-1];

		for(int i= 0; i< cnt-1; i++) {
			josi[i] = sc.nextInt();
		}

		int[] bukas = new int[cnt];
		for(int i = 0; i< cnt-1; i++) {
			bukas[josi[i]-1]++;
		}

		for(int buka : bukas) {
			System.out.println(buka);
		}
	}
}

Measured memory_bytes: 60704
#include<bits/stdc++.h>
#define ll 				long long
#define ld 				long double
#define fastio 			ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) 		cerr<<#x<<" "<<x<<endl
#define cina(a,n) 		for(ll i = 0;i<n;i++)	cin>>a[i];
#define couta(a,n) 		for(ll i = 0;i<n;i++) cout<<a[i]<<" ";
#define fauto(ar)		for(auto x : ar)	cout<<x<<" ";
#define mod 			1000000007
#define inf				100100100100100
#define siz 			100005
#define f 				first
#define s 				second
#define pb 				push_back
#define endl 			"\n"
#define ci 				cin.ignore()
using namespace std;
int main()
{
	ll n,w,i,j;
	cin>>n>>w;
	ll weight[n],value[n];
	for(i = 0;i<n;i++)	cin>>weight[i]>>value[i];
	
	ll dp[n+1][siz],ans = -1;
	for(i = 0;i<=n;i++)	dp[i][0] = 0;
	for(i = 0;i<siz;i++)	dp[0][i] = inf;
	dp[0][0] = 0;
	
	for(i = 1;i<=n;i++)
	{
		for(j = 1;j<siz;j++)
		{
			// not take the current item
			dp[i][j] = dp[i-1][j];
			
			// take current if possible
			if(j >= value[i-1])
			dp[i][j] = min(dp[i][j],dp[i-1][j-value[i-1]]+weight[i-1]);
			
			if(i == n)
			{
				if(dp[i][j] <= w)
				ans = j;
			}
			
		}
	}
	cout<<ans;
}

Measured memory_bytes: 82496
N = int(input())
tree = [list() for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    tree[u-1].append((v-1, w))
    tree[v-1].append((u-1, w))
stack = [0]
ans = [0] * N
searched = [False] * N
while stack:
    node = stack.pop()
    searched[node] = True
    for v, w in tree[node]:
        if searched[v]:
            continue
        if w % 2 != 0:
            ans[v] = ans[node] ^ 1
        else:
            ans[v] = ans[node]
        stack.append(v)
print(*ans, sep='\n')


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll n;
	string s;
	ll x = 0;
	ll ans = 0;

	cin >> n >> s;

	REP(i, n) {
		if (s[i] == 'I') {
			x++;
		}
		else if (s[i] == 'D') {
			x--;
		}

		ans = max(x, ans);
	}

	cout << ans << endl;
}

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

struct Ans {
  deque<char> s;
  bool isStraight;

  Ans(string str) : s(), isStraight(true) {
    for(int i = 0; i < str.size(); ++i) {
      s.push_back(str[i]);
    }
  }

  void reverse() { isStraight = !isStraight; }
  void push_front(char c) {
    if(isStraight) {
      s.push_front(c);
    } else {
      s.push_back(c);
    }
  }
  void push_back(char c) {
    if(isStraight) {
      s.push_back(c);
    } else {
      s.push_front(c);
    }
  }
  void dump_result() {
    if(!isStraight) {
      for(auto itr = s.rbegin(); itr != s.rend(); ++itr) {
        cout << *itr;
      }
      cout << endl;
    } else {
      for(auto itr = s.begin(); itr != s.end(); ++itr) {
        cout << *itr;
      }
      cout << endl;
    }
  }
};

int main() {
  string s;
  cin >> s;
  auto ss = Ans(s);
  int N;
  cin >> N;
  int t, f;
  char c;
  for(int i = 0; i < N; ++i) {
    cin >> t;
    if(t == 1) {
      ss.reverse();
    } else if(t == 2) {
      cin >> f >> c;
      if(f == 1) {
        ss.push_front(c);
      } else if(f == 2) {
        ss.push_back(c);
      }
    }
  }
  ss.dump_result();
  return 0;
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 1000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

string D[7]{"SUN","MON","TUE","WEN","THU","FRI","SAT"};

int main(){
   int N;
   string S;
   cin >> N >> S;
   N %= 26;
   int n = S.size();
   for(int i = 0;i < n;i++){
       int b = 0;
       for(int j = 0;j < 26;j++){
           char a = 'A' + j;
           if(S[i] == a){
               b = j;
               break;
           }
       }
       char C = 'A' + (b+N) % 26;
       S[i] = C;
   }
   cout << S << endl;
}

Measured memory_bytes: 256
N = int(input())
primes = set([2])
mod5_1 = []
for i in range(3, 55555+1):
    if len(mod5_1)==N: 
        break
    for p in primes:
        if i%p==0: 
            break
    else:
        primes.add(i)
        if i%5==1:
            mod5_1.append(i)
            
print(*mod5_1)

Measured memory_bytes: 3060
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
N=int(input())
print(A[N-1])


Measured memory_bytes: 3064
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Char
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as BS

readIntPair :: BS.ByteString -> (Int, Int)
readIntPair s = let Just (a, s') = BS.readInt s
                    Just (b, _) = BS.readInt $ BS.dropWhile isSpace s'
                in (a, b)

main = do
  (n,k) <- readIntPair <$> BS.getLine
  -- 2 <= n <= 10^5, 1 <= k <= 100
  h <- V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  -- 1 <= hi <= 10^4
  let dp = V.constructN n $ \dp ->
        if V.null dp
        then 0
        else let !i = V.length dp
                 !h_i = h V.! i
             in V.minimum $ V.map (\(dp_j, h_j) -> dp_j + abs (h_i - h_j)) $ V.drop (i-k) $ V.zip dp h
  print (V.last dp :: Int)


Measured memory_bytes: 3708