akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


int main() {
  ll a, b, n; cin >> a >> b >> n;

  ll x = min(n, b-1);
  ll ans = (a*x)/b - a*(x/b);

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3660
#!/usr/bin/env python
# -*- coding: utf-8 -*-
n=int(input())
dp=[[0]*10 for x in [0]*10]
ans=0
for i in range(1,n+1):
    start,end=int(str(i)[0]),int(str(i)[-1])
    dp[start][end]+=1
for i in range(10):
    for j in range(10):
        ans+=dp[i][j]*dp[j][i]
        # if dp[i][j]*dp[j][i] > 0:
            # print(i,j,dp[i][j]*dp[j][i])
print(ans)

Measured memory_bytes: 40428
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll N,a;
ll inf = 1e9+7;

int main(){
	cin >> N;
	vector<P> v(2*N);
	for(int i=0;i<2*N;i++){
		if(i<N){
			cin >> a;
			v[i] = P(a,1);
		}else{
			cin >> a;
			v[i] = P(a,-1);
		}
	}
	sort(v.begin(),v.end());
	ll  c = 0;
	ll ans = 1;
	for(int i=0;i<2*N;i++){
		if(c*v[i].second>=0){
			c += v[i].second;
		}else{
			ans = (ans*abs(c))%inf;
			if(c>0) c--;
			else c++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

ll n, c;
ll x[100000], v[100000];
ll f[100010], g[100010];
int main()
{
    cin >> n >> c;

    rep(i, n) cin >> x[i] >> v[i];

    ll ans = 0;
    {
        rep(i, n+1) f[i] = 0;
        rep(i, n) f[i+1] = f[i] + v[i];
        rep(i, n) f[i+1] -= x[i];

        rep(i, n+1) g[i] = 0;
        rep(i, n) g[i+1] = max(g[i], f[i+1]);

        ans = max(ans, g[n]);
        ll cal = 0;
        irep(i, n) {
            cal += v[i];
            ans = max(ans, cal - 2*(c - x[i]) + g[i]);
        }
    }
    {
        rep(i, n+1) f[i] = 0;
        rep(i, n) f[i+1] = f[i] + v[n-i-1];
        rep(i, n) f[i+1] -= (c - x[n-i-1]);

        rep(i, n+1) g[i] = 0;
        rep(i, n) g[i+1] = max(g[i], f[i+1]);
        
        ans = max(ans, g[n]);
        ll cal = 0;
        rep(i, n) {
            cal += v[i];
            ans = max(ans, cal - 2*x[i] + g[n-i-1]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
// author: lkx
// Problem:
// ID:
#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back
#define MP make_pair
#define PH push
#define ll long long
#define ull unsigned long long
#define debug(x) cerr<<#x<<"="<<x<<'\n'
//#define DEBUG

const int MOD=1e9+7;

int n;
int a[200100];
ll res=0;

int main()
{
	#ifdef DEBUG
	clock_t tStart = clock();
	#endif
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	if(a[0]!=0) 
	{
		puts("-1");
		return 0;
	}
	int mx=0;
	for(int i=n-1;i>=0;i--)
	{
		mx=max(mx,a[i]);
		if(mx>a[i])
		{
			puts("-1");
			return 0;
		}
		mx--;
	}
	int i;
	for(i=n-1;i>0;i--)
	{
		res+=a[i];
		while(a[i-1]==a[i]-1) i--;
	}
	printf("%lld",res);
	#ifdef DEBUG
	cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1e3<<"ms.\n";
	#endif
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef map<ll,ll> mll;
typedef vector<bool> vb;

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define endl "\n"
#define prina(arr,dau,cuoi) FTB(mmczmp,dau,cuoi)cout<<arr[mmczmp]<<" ";cout<<endl;
#define debug cout<<"debug\n"
#define DEBUG(x) { cout << #x << " = "; cout << (x) << endl; }
#define pb push_back
#define pbg(ke,u,v) ke[u].pb(v);ke[v].pb(u);
#define fi first
#define se second
#define pi acos(-1.0)
#define lbnd(f,s,gt) lower_bound(f,s,gt)
#define ubnd(f,s,gt) upper_bound(f,s,gt)
#define all(s) s.begin(),s.end()
#define bitcount(n) __builtin_popcountll(n)
#define REP(N) for(ll asgardhaha=1;asgardhaha<=N;asgardhaha++)
#define FTB(i,a,b) for(ll i=a,_b=b;i<=_b;i++)
#define FT(i,a,b) for(ll i=a,_b=b;i<_b;i++)
#define FGB(i,a,b) for(ll i=a,_b=b;i>=_b;i--)
#define FG(i,a,b) for(ll i=a,_b=b;i>_b;i--)
/////////////////////////////////////////////

ll n,d[100005],q,k;

void Solve(){
    cin>>n>>k>>q;
    FTB(i,1,q){
        ll x;cin>>x;
        d[x]++;
    }
    FTB(i,1,n) if(k-(q-d[i])>0) cout<<"Yes\n"; else cout<<"No\n";
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);
//     freopen("1.inp","r",stdin);
 //    freopen("1.out","w",stdout);




    int Test_numbers=1;
    //cin>>Test_numbers;

    while(Test_numbers--) Solve();

    //cerr << "\nTime run: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

	return 0;
}


Measured memory_bytes: 1408
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* ]]] */

int n, a;
int x[50];
ll dp[60][2600];

int main(){
  cin >> n >> a;
  rep(i, n) cin >> x[i];
  dp[0][0] = 1;
  rep(i, n) rrep(j, n) rep(k, 2500){
    dp[j + 1][k + x[i]] += dp[j][k];
  }
  ll res = 0;
  rep(i, 1, n + 1) res += dp[i][i * a];
  cout << res << endl;
}



Measured memory_bytes: 1280
//package abc119_B;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		double ans = 0.0;
		
		for (int i = 0; i < n; i++) {
			double x = sc.nextDouble();
			String u = sc.next();
			if (u.equals("JPY")) ans += x;
			else ans += 380000.0 * x;
		}
		
		System.out.println(ans);
	}

}

Measured memory_bytes: 23124
//0005 GCD and LCM
//üÍ³ê½2ÌÅåöñÆÅ¬ö{ðoÍ¹æ
//½¾µAÅåö{Í20­ð´¦È¢

#include<iostream>
using namespace std;

template<class T>
inline T GCD(T a, T b)
{
	T c;
	while( (c = a%b) != 0)
	{
		a = b;
		b = c;
	}
	return b;
}

template<class T>
inline T LCM(T a, T b)
{
	return (a / GCD(a, b) * b);
}

int main(void)
{
	int a, b;
	while( cin >> a >> b)
	{
		cout << GCD(a, b) << ' ' << LCM(a, b) << endl;
	}
	return 0;
}

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

using namespace std;

int a[200000];

int main() {
  int n; scanf("%d", &n);
  for(int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  unordered_set<int> prev;
  int ans = n;
  for(int i = 0; i < n; ++i) {
    bool ettara7et = false;
    for(int j = 1; j * j <= a[i]; ++j) {
      if(a[i] % j == 0) {
        if(prev.count(j)) {
          ans--;
          ettara7et = true;
          break;
        }
        if(prev.count(a[i] / j)) {
          ans--;
          ettara7et = true;
          break;
        }
      }
    }
    if(!ettara7et && i + 1 < n && a[i + 1] == a[i]) {
      ans--;
    }
    prev.insert(a[i]);
  }
  cout << ans << endl;
  return 0;
}


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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N=1e5+5;
vi adj[N];
vi adj1[N];
int cc=0;
bool vis[N];

void dfs(int u){
	vis[u]=true;
	adj1[cc].pb(u);
	for(auto v: adj[u]){
		if(!vis[v])
			dfs(v);
	}
}

void solve(){
	int n,m;
	cin>>n>>m;
	int u,v;
	vi arr(n+1);
	fr(i,1,n+1)
	cin>>arr[i];
	fr(i,0,m){
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	fr(i,1,n+1){
		if(!vis[i]){
			dfs(i);
			cc++;
		}
	}
	fr(i,0,cc)
		sort(all(adj1[i]));
	int cnt=0;
	fr(i,0,cc){
		for(auto x: adj1[i]){
			if(binary_search(all(adj1[i]),arr[x]))
				cnt++;
		}
	}
	cout<<cnt<<endl;
	return;
}

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

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

using namespace std;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

template <typename T>
vec1<T> cin2vec(size_t size)
{
    vec1<T> vec1(size);
    for (auto& v : vec1) {
        v = cin2var<T>();
    }
    return vec1;
}

using AB = tuple<int64_t, int64_t>;
using BA = tuple<int64_t, int64_t>;

void sub()
{
    const auto N(cin2var<size_t>());

    vec1<AB> abs;
    vec1<BA> bas;
    vec1<AB> cs;
    for (size_t i = 0; i < N; ++i) {
        const auto ab(cin2vec<int64_t>(2));
        if (ab[0] > ab[1]) continue;  // 絶対に負ける
        abs.push_back(make_tuple(ab[0], ab[1]));
        bas.push_back(make_tuple(ab[1], ab[0]));
        cs.push_back(make_tuple(ab[0], ab[1]));
    }

    sort(abs.begin(), abs.end());
    sort(bas.begin(), bas.end());
    sort(cs.begin(), cs.end(), [](const auto& l, const auto& r) {
            const auto& la(get<0>(l));
            const auto& lb(get<1>(l));
            const auto& ra(get<0>(r));
            const auto& rb(get<1>(r));
            const auto lab(la + lb);
            const auto rab(ra + rb);
            if (lab != rab) return lab < rab;
            if (lb != rb) return lb < rb;
            return la < rb;
    });

    // プランA
    int64_t winA = 0;
    {
        int64_t time = 0;
        for (const auto& ab : abs) {
            if (time + get<0>(ab) <= get<1>(ab)) {
                time += get<0>(ab);
                ++winA;
            }
        }
    }
    // プランB
    int64_t winB = 0;
    {
        int64_t time = 0;
        for (const auto& ba : bas) {
            if (time + get<1>(ba) <= get<0>(ba)) {
                time += get<1>(ba);
                ++winB;
            }
        }
    }
    // プランC
    int64_t winC = 0;
    {
        int64_t time = 0;
        for (const auto& c : cs) {
            if (time + get<0>(c) <= get<1>(c)) {
                time += get<0>(c);
                ++winC;
            }
        }
    }

    cout << max({winA, winB, winC}) << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    sub();
    return 0;
}


Measured memory_bytes: 3180
def main():
	N, K= map(int, input().split())
	A = list(map(int, input().split()))

	dev = (N-1)//(K-1)
	mod = (N-1)%(K-1)
	ans = dev
	if mod != 0:
		ans += 1

	print(ans)


if __name__ == '__main__':
    main()

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), DP(N, 1e9);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  DP.at(0) = 0;
  DP.at(1) = abs(A.at(1) - A.at(0));
  for (int i = 2; i < N; i++) {
    int tmp1 = DP.at(i - 2) + abs(A.at(i - 2) - A.at(i));
    int tmp2 = DP.at(i - 1) + abs(A.at(i - 1) - A.at(i));
    DP.at(i) = min(tmp1, tmp2);
  }
  cout << DP.at(N - 1) << "\n";
}

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

using namespace std;

#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int n,a,ret=0;
map<int,int> m;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++) {
		cin>>a;
		if(m[a]==0) {
			m[a]++;
			ret++;
		}
		else {
			m[a]--;
			ret--;
		}
	}
	cout<<ret<<endl;
}

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

#define INF 1e9
using namespace std;

int main() {

    int N, M; cin >> N >> M;

    vector<int> k(M);
    vector<vector<int>> s(M);
    vector<int> p(M);

    for (int i = 0; i < M; ++i) {
        cin >> k[i];

        for (int j = 0; j < k[i]; ++j) {
            int S;
            cin >> S;

            s[i].push_back(S);
        }
    }

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

    int ans = 0;

    for (int bit = 0; bit < (1 << N); ++bit) { //2^Nのbit全探索

        bool ok = true;

        for (int i = 0; i < M; ++i) {

            int on = 0;

            for (int j = 0; j < N; ++j) {
                if (bit & (1 << j)) {
                    for (int l = 0; l < k[i]; ++l) {
                        if (s[i][l] == j + 1) {
                            ++on;
                        }
                    }
                }
            }

            if (on % 2 != p[i]) {
                ok = false;
            }
        }

        if (ok) {
            ++ans;
        }
    }

    cout << ans << endl;
}

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

struct graph {
  int n;
  vector<vector<int>> g;
  vector<int> len;

  graph(int _n) {
    n = _n;
    g.resize(n);
    len.resize(n, -1);
  };
  void add_edge(int a, int b) { g[a].push_back(b); }

  int get_len(int i) {
    if (len[i] != -1) return len[i];
    int res = 0;
    for (auto&& w : g[i]) {
      res = max(res, get_len(w) + 1);
    }
    return len[i] = res;
  }

  int maxlen() {
    for (int i = 0; i < n; i++) {
      get_len(i);
    }
    return *max_element(begin(len), end(len));
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  graph gr(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    gr.add_edge(x, y);
  }
  cout << gr.maxlen() << endl;
}

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

signed main(){
  lint N; cin >> N;
  lint ans = 0, ca = 0, cb = 0, cab = 0;
  for(lint i = 0; i < N; i++){
    string s; cin >> s;
    for(lint i = 1; i < s.size(); i++){
      if(s[i - 1] == 'A' && s[i] == 'B') ans++;
    }
    if(s[0] == 'B') cb++;
    if(s[s.size() - 1] == 'A') ca++;
    if(s[0] == 'B' && s[s.size() - 1] == 'A') cab++;
  }
  if(cab == ca && cab == cb && cab != 0) ans--;
  ans += min(ca, cb);
  cout << ans << endl;
}


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

int main() {
  ll N, M; cin >> N >> M;
  ll a[N];
  for (ll i = 0; i < N; i++) {
    cin >> a[i];
  }
  ll sum[N+1];
  sum[0] = 0;
  for (ll i = 1; i < N+1; i++) {
    sum[i] = sum[i-1]+a[i-1];
  }
  map<ll,ll> count;
  set<ll> mod;
  for (ll i = 0; i < N+1; i++) {
    count[sum[i]%M]++;
    mod.insert(sum[i]%M);
  }
  ll res = 0;
  for (auto it = mod.begin(); it != mod.end(); it++) {
    if (count[*it] > 0) res+=count[*it]*(count[*it]-1)/2;
  }
  cout << res << endl;
}

Measured memory_bytes: 8704
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

int main() {
	vpint a;
	while (1) {
		int x, y;
		cin >> x >> y;
		if (x == 0 && y == 0)break;
		a.push_back({ x,y });
	}
	rep(i, a.size()) {
		rep(j, a[i].first) {
			rep(k, a[i].second) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    count = 0
    alice = 0
    bob = 0
    while len(a) > 0:
        a.sort()
        if count%2:
            bob += a.pop()
        else:
            alice += a.pop()
        count += 1
    else:
        print(alice - bob)

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

using namespace std;
typedef long long ll;
#define MOD 1000000007

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

    int B[N-1];
    for(int i=0; i<N-1; i++) cin >> B[i];

    int ans = 0;
    ans += B[0];

    for(int i=1; i<N-1; i++) {
        ans += min(B[i-1], B[i]);
    }

    ans += B[N-2];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define test(t) int t; cin>>t; while(t--)
#define p1(x) { cout << " [" << #x << ": " << x << "]\n"; }
#define p2(x) { cout << " [" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]\n"; }
#define pb push_back
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
 
int countOrderedPairs(int N) 
{ 
    int count_pairs = 0;
    for (int i = 1; i <= sqrt(N - 1); ++i) { 
        for (int j = i; j * i < N; ++j) 
            ++count_pairs; 
    }
    count_pairs *= 2; 
    count_pairs -= int(sqrt(N - 1)); 
    return count_pairs; 
} 

void solve()
{
	int n, ans=0;
	
	cin>>n;
	cout<<countOrderedPairs(n)<<endl;
}
 
int main() {
	// your code goes here
	// test(t)
		solve();
	return 0;
}
 

Measured memory_bytes: 3656
n = int(input())
# {0:"A", 1:"C", 2:"G", 3:"T"}
dp = [[[[0] * 4 for _ in range(4)] for _ in range(4)] for _ in range(n + 1)]
dp[0][3][3][3] = 1
mod = 10 ** 9 + 7

for i in range(n):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                for m in range(4):
                    if m == 1 and l == 0 and k == 2: continue
                    if m == 2 and l == 1 and k == 0: continue
                    if m == 1 and l == 2 and k == 0: continue
                    if m == 1 and k == 2 and j == 0: continue
                    if m == 1 and l == 2 and j == 0: continue
                    
                    dp[i+1][k][l][m] += dp[i][j][k][l]
                    
ans = 0
for j in range(4):
    for k in range(4):
        for l in range(4):
            ans += dp[n][j][k][l]

print(ans % mod)

Measured memory_bytes: 3444
fun main(args:Array<String>):Unit {
    while(true){
        val (n, m) = readLine()!!.split(' ').map(String::toInt)
        if (n == 0 && m == 0) return
        val pair = Array(n){
            val (d, p) = readLine()!!.split(' ').map(String::toInt)
            Pair(d, p)
        }.sortedByDescending{it.second}.toTypedArray()
        var money = m
        loop@for (i in 0 until pair.size){
            if (money == 0) break@loop
            if (money > pair[i].first){
                money -= pair[i].first
                pair[i] = Pair(0, 0)
            }else{
                pair[i] = Pair(pair[i].first - money, pair[i].second)
                money = 0
            }
        }
        println(
                pair.sumBy { (d, p) -> d * p }
        )
    }
}


Measured memory_bytes: 74580
n, k = map(int, input().split())
A = list(map(int, input().split()))
B = [(1+i)/2 for i in A]
t = sum(B[:k])
ans = [t]
for i in range(n-k):
    t-=B[i]
    t+=B[i+k]
    ans.append(t)
print(max(ans))


Measured memory_bytes: 25060
import java.util.Arrays;
import java.util.Scanner;

class Main {

	
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int a[] = new int[n];
		
		for(int i=0;i<n;i++) {
			a[i] = s.nextInt();
		}
		
		Arrays.sort(a);
		double sum = (a[0]+a[1])/2.0;
		for(int i=2;i<n;i++) {
			
			sum = (sum+a[i])/2;
		}
		System.out.println(sum);
		
		
		
		
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) ;for (int i = 0; i <(int)(n); i++)
int main(){
int N, Y, x, y, z;
  cin >> N >> Y;
  rep(i,N+1){
    x = N-i;
  rep(j,i+1){
    y = i-j;
    z = j;
    if(10000*x+5000*y+1000*z==Y )
      break;
  }
    if(10000*x+5000*y+1000*z==Y)
      break;
  }
  if(10000*x+5000*y+1000*z==Y)
    cout << x << " " << y << " " << z << endl;
  else
    cout<< "-1 -1 -1"<< endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n, x = 0, max = 0;
    string s;
    cin >> n >> s;
    for ( int i = 0; i <= n - 1; i++ )
    {
        if ( s[i] == 'I' )
        {
            x++;
        }
        else
        {
            x--;
        }
        if ( x >= max )
        {
            max = x;
        }
    }
    cout << max;
}

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

int main(void)
{
    int A, B, C;
    cin >> A >> B >> C;

    if (A == B && A != C) {
        cout << "Yes" << endl;
    }
    else if (A == C && A != B) {
        cout << "Yes" << endl;
    }
    else if (B == C && B != A) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int main(){
    Hello
    int a, b, k, ans = 0;
    cin >> a >> b >> k;
    for(int i = 200; i >= 1; i--){
        if(a % i == 0 && b % i == 0){
//            cout << "   " << i << endl;
            ans ++;
            if(ans == k)
                return cout << i, 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3600
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  int N,M;
  cin>>N>>M;
  string A[100],B[100];
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  for(int i=0;i<M;i++){
    cin>>B[i];
  }
  bool flag=true;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++,flag=true){
      if(i+M-1<N && j+M-1<N){
        for(int k=0;k<M;k++){
          for(int l=0;l<M;l++){
            if(A[i+k][j+l]!=B[k][l]) flag=false;
          }
        }
        if(flag){
          cout<<"Yes"<<endl;
          return 0;
        }
      }
    
    }
  }
  cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define li(x) x.size()-1
#define oo 1000000000
#define inf 1000000000000000000
#define M 1000000007
#define M2 1000000009
#define pii pair<ll,ll>
using namespace std;
typedef long long ll;
const int N = 2e5+100;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);

int n;
int m;
int dp[1003][1003];
char g[1003][1992];
int calc(int i , int j){
	if(i==n-1&&j==m-1)
		return 1;
	if(i>n||j>m)
		return 0;
	if(g[i][j]=='#')
		return 0;

	int&ret =dp[i][j];
	if(ret!=-1)return ret;
	ret = calc(i+1,j)+calc(i,j+1);
	ret = ret%M;
	return ret;
}

int main() {
	cin >> n >> m ;
	for(int i = 0 ; i < n ; i++){
		scanf(" %s",g[i]);
	}
	setDP(dp);
	cout << calc(0,0) << endl;


    return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

// head

const int M = 100010;

int main(){

  ll n = in();
  ll m = in();
  vector<ll> w(n);
  vector<ll> v(n);
  REP(i, n){
    w[i] = in();
    v[i] = in();
  }
  vector<ll> dp(2 * M, INFLL);
  dp[0] = 0;
  REP(i, n){
    for(int j = M; j >= 0; j--){
      chmin(dp[j + v[i]], dp[j] + w[i]);
    }
  }
  ll ans = 0;
  REP(i, M){
    if(dp[i] <= m){
      ans = i;
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec) {
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

#define solvsh
//#define multi
#ifdef solvsh

void prec(){

}

const int MAXN = 2e5;

vector<int> g[MAXN];
ll mod = 1e9 + 7;

ll pows[MAXN];

int to[MAXN];

int comp[MAXN];

map<int ,int> mins_comp;

int inp[MAXN];

void dfs(int ver, int color) {
    if (comp[ver] != 0)
        return;

    comp[ver] = color;
    if (inp[ver] == -1)
        mins_comp[color] ++;

    for (auto out : g[ver]) {
        dfs(out, color);
    }
}

ll ml(ll a, ll b) {
    return (a * b) % mod;
}

ll add(ll a, ll b) {
    return (a + b) % mod;
}


void solve() {
    int a, b;
    cin >> a >> b;

    cout << a * b;

}

#else

void solve() {

}

#endif

void multisolve() {

    int t;
    cin >> t;

    int i = 1;
    while (t--) {
//        cout << "Case " << (i++) << ": ";
        solve();
        cout << "\n";
    }
}


#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);


#ifdef multi
    multisolve();
#else
    solve();
    //    gen();
#endif

}


Measured memory_bytes: 8316
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n),b(n),c(n);
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  for(int i=0; i<n; i++) {
    cin >> b[i];
  }
  for(int i=0; i<n; i++) {
    cin >> c[i];
  }
  sort(c.begin(),c.end());
  long long ans=0;
  for(int i=0; i<n; i++) {
    long long m=lower_bound(a.begin(),a.end(),b[i])-a.begin();
    long long M=c.end()-upper_bound(c.begin(),c.end(),b[i]);
    ans+=m*M;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;

int main() {
  int n,m,a;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> a; n -= a;
  }
  cout << (n<0?-1:n) << endl;
}


Measured memory_bytes: 3612
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long N, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
  ll ans = 0;
  rep(i,N) ans += B[i];
  rep(i,N-1) if(A[i+1]==A[i]+1) ans += C[A[i]-1];
  cout << ans << endl;
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  std::vector<long long> B(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&B[i]);
  }
  std::vector<long long> C(N-1);
  for(int i = 0 ; i < N-1 ; i++){
    scanf("%lld",&C[i]);
  }
  solve(N, std::move(A), std::move(B), std::move(C));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll x;
  cin>>x;
  ll ans=1;
  while(x*ans%360!=0){
    ans++;
  }
  print(ans);
}

Measured memory_bytes: 3632
import copy
H,W,K = map(int,input().split())
C = []
for i in range(H):
  temp = str(input())
  temp = list(temp)
  C.append(temp)
#print(C)
#p,qを答えとする
def count(X):
  ret = 0
  for i in range(H):
    for j in range(W):
      if X[i][j] == "#":
        ret +=1
  return ret
ans = 0
for p in range(2**H):
  for q in range(2**W):
    D = copy.deepcopy(C)
    for i in range(H):
      if(p>>i)&1==1:
        D[i] = ["1" for _ in range(W)]
    for j in range(W):
      if(q>>j)&1==1:
        for t in range(H):
          D[t][j] = "1"
    #print(D,p,q,count(D))
    if count(D) == K:
      ans += 1
print(ans)      


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

typedef long long ll;

int n,k;
vector<ll> A,B;

int main(){
	cin >> n >> k;
	
	for(int i=0;i<n;i++){
		int x;
		cin >> x;

		if(x<=0)
			A.push_back(x);
		else
			B.push_back(x);
	}

	ll tmp=0,ans=INT_MAX;

	for(int i=A.size()-1;i>=0;i--){
		int cc=A.size()-i;
		tmp=abs(A[i]);

		if(cc<k && cc+B.size()>=k){
			int r=k-cc-1;
			tmp*=2;
			tmp+=B[r];
			ans=min(ans,tmp);
		}else if(cc==k){
			ans=min(ans,tmp);
		}
	}

	for(int i=0;i<B.size();i++){
		int cc=i+1;
		tmp=B[i];

		if(cc<k && cc+A.size()>=k){
			int l=A.size()-(k-cc);
			tmp*=2;
			tmp+=abs(A[l]);
			ans=min(ans,tmp);
		}else if(cc==k)
			ans=min(ans,tmp);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1656
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int d(int a){
    if(a >= 0){
        return a;
    }else{
        return -a;
    }
}

int main(){
    int A, B, tmp, K,flag=0;
    scanf("%d %d", &A, &B);
    if(A % 2 == 1 && B % 2 == 0)flag = 1;
    if(A % 2 == 0 && B % 2 == 1)flag = 1;

    if(flag == 0){
        if(A > B){
            tmp = (A - B) / 2;
            K = A - tmp;
        }else{
            tmp = (B - A) / 2;
            K = B - tmp;
        }
    }

    if(flag == 1){
        printf("IMPOSSIBLE\n");
    }else{
        printf("%d\n",K);
    }
}

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

int main() {
	string N;
	cin >> N;
	string res = "No";
	if (N[0]=='7') res = "Yes";
	if (N[1]=='7') res = "Yes";
	if (N[2]=='7') res = "Yes";
	cout << res << "\n";
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>

using namespace std;

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

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

    sort(A, A+M);

    long dp[N+1];
    fill(dp, dp+N+1, 0);

    for(int i=0; i<M; i++){
        dp[A[i]] = -1;
    }
    dp[0] = 1;

    for(int i=1; i<=N; i++){
        if(dp[i] == -1) continue;

        if(i-2 >= 0  && dp[i-2] != -1){
            dp[i] += dp[i-2];
        }

        if(dp[i-1] != -1){
            dp[i] += dp[i-1];
        }
        dp[i] = dp[i] % 1000000007;
    }

    cout << dp[N] % 1000000007;

    return 0;

}

Measured memory_bytes: 1408
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <utility>

using namespace std;

int main()
{
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//freopen("input.in", "r", stdin);
	int n; cin >> n;
	bool bol = 0;
	for(int i = 0; i < n; i++)
	{
		char c; cin >> c;
		if(c == 'Y')
			bol = 1;
	}
	if(bol) cout << "Four\n";
	else cout << "Three\n";
}






Measured memory_bytes: 256
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
P = [i - 1 for i in P]

ans = -10**18
for si in range(N):
    x = si
    s = []
    total = 0
    while True:
        x = P[x]
        s.append(C[x])
        total += C[x]
        if x == si: break
    l = len(s)
    t = 0
    for i in range(l):
        t += s[i]
        if i + 1 > K: break
        now = t
        if total > 0:
            e = (K - (i + 1)) // l
            now += total * e
        ans = max(ans, now)
print(ans)


Measured memory_bytes: 81164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(ll i=0;i<N;++i)
const ll INF = 1LL<<60;

int main(){
    ll N; cin >> N;
    ll A[2][N];
    ll B[N],C[N];
    rep(i,2){
        rep(j,N){
            cin >> A[i][j];
        }
    }
    ll sum = 0;
    rep(i,N){
        sum += A[0][i];
        B[i] = sum;
    }
    sum = 0;
    for(int i=N-1;i>=0;i--){
        sum += A[1][i];
        C[i] = sum;
    }
    ll ans = 0;
    rep(i,N){
        ans = max(ans , B[i] + C[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

int main( void ) {

    string s;
    cin >> s;

    cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;

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

char mp[20][20];
int dist[20][20];
bool seen[20][20];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
const int inf = 1<<29;

void rec(vector< vector<int> > &Y, int i, int S, vector<int> &path) {
  if(S != 0) rec(Y, Y[i][S], S& ~(1<<i), path);
  path.push_back(i);
}

int tsp(int start,vector< vector<int> > G) {
  const int n = G.size(), N = 1<<n;
  int i,j;
  vector< vector<int> > X(n, vector<int>(N, inf));
  vector< vector<int> > Y(n, vector<int>(N, -1));
  vector<int> result;
  rep(i,n) {
    X[i][1<<i] = G[start][i];
    Y[i][1<<i] = start;
  }

  for(int S = 1; S < N; ++S) {
    rep(i,n) {
      if(!(S & (1<<i))) continue;
      rep(j,n) {
	if(S & (1<<j)) continue;
	if(X[j][S|(1<<j)] > X[i][S]+G[i][j]) {
	  X[j][S|(1<<j)] = X[i][S]+G[i][j];
	  Y[j][S|(1<<j)] = i;
	}
      }
    }
  }


  result.clear();
  if(X[start].back() >= inf) return -1;
  rec(Y, start, (1<<n)-1, result);
  int mm = inf;
  rep(i,n) {
    mm = min(X[i].back(), mm);
  }
  return mm;
  //return X[start].back() - mm;
}

int main() {
  int w,h,i,j,k,l,objnum;
  string s;
  while(cin>>w>>h, w|h) {
    objnum = 1;
    rep(i,h) {
      cin>>s;
      rep(j,w) {
	mp[i][j] = s[j];
	if(s[j] == 'o') mp[i][j] = 0;
	if(s[j] == '*') mp[i][j] = objnum++;
      }
    }

    vector<vector<int> > G(objnum, vector<int>(objnum, inf));
    rep(i,objnum) G[i][i] = 0;
    rep(i,objnum) {
      int sx,sy;
      rep(j,h) rep(k,w) if(mp[j][k] == i) sx = k, sy = j;
      memset(dist, -1, sizeof(dist));
      memset(seen, false, sizeof(seen));
      queue<pair<int,int> > Q;
      Q.push(make_pair(sy,sx));
      seen[sy][sx] = true;
      dist[sy][sx] = 0;
      while(!Q.empty()) {
	int x = Q.front().second,y = Q.front().first; Q.pop();
	rep(l,4) {
	  int nx = x+dx[l],ny = y+dy[l];
	  if(nx < 0 || nx >= w || ny < 0 || ny >= h || seen[ny][nx]) continue;
	  if(mp[ny][nx] == 'x') continue;
          if(dist[ny][nx] == -1) dist[ny][nx] = dist[y][x]+1;
	  else dist[ny][nx] = min(dist[ny][nx],dist[y][x]+1);
	  seen[ny][nx] = true;
	  Q.push(make_pair(ny,nx));
	}
      }

      rep(j,h) rep(k,w) {
	if(0 <= mp[j][k] && mp[j][k] <= objnum) {
	  if(dist[j][k] == -1) continue;
	  G[mp[j][k]][i] = G[i][mp[j][k]] = dist[j][k];
	}
      }
    }

      long long ans = tsp(0,G);
      if(ans >= inf) cout<<-1<<endl;
      else cout<<ans<<endl;
  }
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  int n,m,k;
  cin>>n>>m>>k;
  bool f=0;
  fr(i,n+1) fr(j,m+1) if(i*(m-j)+j*(n-i)==k) f=1;
  cout<<(f?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
/**********************************************************************/
/********                                                      ********/
/********                     Writer:孙~~                      ********/
/********                       Lang:C++                       ********/
/********                     Status:Accepted                  ********/
/********                                                      ********/
/**********************************************************************/
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <list>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <cstring>
#include <cmath>
//#include<bits/stdc++.h>
using namespace std;

const int INF=0x3f3f3f3f;
const int SIZE=100005;

int n,m;
vector<pair<int,int> > mp[SIZE];
bool vis[SIZE];
long long val[SIZE];

bool bfs(int i){
	queue<int> que;
	que.push(i);
	val[i]=0;
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(int i=0;i<mp[v].size();i++){
			pair<int,int> u=mp[v][i];
			int to=u.first;
			if(val[to]==INF){
				val[to]=val[v]+u.second;
				que.push(to);
			}
			else if(val[to]!=val[v]+u.second){
				return false;
			}
		}
	}
	return true;
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int l,r,d;
		scanf("%d%d%d",&l,&r,&d);
		l--;
		r--;
		mp[l].push_back(make_pair(r,d));
		mp[r].push_back(make_pair(l,-d));
	}
	for(int i=0;i<n;i++) val[i]=INF;
	for(int i=0;i<n;i++) if(val[i]==INF) if(!bfs(i)){
		puts("No");
		return 0;
	}
	puts("Yes");
	return 0;
}




Measured memory_bytes: 9728
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int lim=200000000;
struct data{
	int v,n;
}a[210001];
int i,j,k,n,r,c,m,t1,t2,t3,t4,flag,b[210001],q[210001];
bool cmp(data a,data b){
	return a.v<b.v;
}
int calc(int x,int y){
	if (!y) return 1+x;
	if (x==r) return lim+y;
	if (y==c) return 2*lim+r-x;
	if (!x) return 3*lim+c-y;
	return 0;
}
int main(){
	scanf("%d%d%d",&r,&c,&n);memset(b,0,sizeof(b));
	for (i=1,m=0;i<=n;i++){
		scanf("%d%d%d%d",&t1,&t2,&t3,&t4);
		j=calc(t1,t2);k=calc(t3,t4);
		if (!j||!k) continue;
		a[++m].v=j;a[m].n=i;a[++m].v=k;a[m].n=i;
	}
	if (m) sort(a+1,a+1+m,cmp);
	for (q[0]=0,i=flag=1;i<=m;i++){
		if (!b[a[i].n]){
			b[a[i].n]=1;q[++q[0]]=a[i].n;
		}else{
			if (q[q[0]]!=a[i].n){
				flag=0;break;
			}
			q[0]--;
		}
	}
	puts(flag?"YES":"NO");
	return 0;
}

Measured memory_bytes: 2688