akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, K;
  cin >> n >> K;
  string s;
  cin >> s;
  ll ans = 0;
  rep(i,n-1){
    if(s[i] == s[i+1]) ans++;
  }
  ans = min<ll>(n-1,K*2+ans);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;

int main(){
 while(1){ 
 ll n,m,t,s,ans=-1; cin>>n>>m;
   if(n==0&&m==0) break;
 vector<ll>a; rep(i,n){cin>>t; if(t>=m) continue; a.push_back(t);}
   
   sort(a.begin(),a.end());
   if(a.size()<=1){ cout<<"NONE"<<endl; continue;}
   
   rep(i,a.size()-1){
   for(int k=i+1;k<a.size();k++){
     s=a.at(i)+a.at(k);
     if(s<=m&&m-s<m-ans) ans=s;
     else if(s>m) break;
   }
   }
   
   if(ans<0) cout<<"NONE"<<endl;
   else cout<<ans<<endl;
   
 }
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n;
    string s;
    cin>>n>>s;
    int type[2*n];
    int cnt=0;
    rep(i,2*n){
        type[i]=(i+s[i])%2;
        if(type[i])++cnt;
    }
    if(cnt!=n){
        cout<<0<<endl;
        return 0;
    }
    ll ans=1;
    int sum=0;
    rep(i,2*n){
        if(type[i]=='B'%2){
            ++sum;
        }
        else{
            ans*=sum--;
            ans%=mod;
        }
    }
    for(int i=1;i<=n;++i){
        ans=(ans*i)%mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1412
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<iostream>
#define llong long long
using namespace std;

inline int read() {
	int x=0;
	bool f=1;
	char c=getchar();
	for(; !isdigit(c); c=getchar()) if(c=='-') f=0;
	for(; isdigit(c); c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
	if(f) return x;
	return -x;
}

int P;
const int N = 3000;

llong quickpow(llong x,llong y) {
	y%=(P-1);
	llong cur = x,ret = 1ll;
	for(int i=0; y; i++) {
		if(y&(1ll<<i)) {
			y-=(1ll<<i);
			ret = ret*cur%P;
		}
		cur = cur*cur%P;
	}
	return ret;
}
llong mulinv(llong x) {
	return quickpow(x,P-2);
}

namespace Lagrange {
	llong aux[N+3],aux2[N+3];
	llong ax[N+3],ay[N+3],poly[N+3];
	void lagrange(int n) {
		for(int i=0; i<=n+1; i++) poly[i] = aux[i] = aux2[i] = 0ll;
		aux[0] = 1ll;
		for(int i=0; i<=n; i++) {
			for(int j=i+1; j>0; j--) {
				aux[j] = (aux[j-1]-aux[j]*ax[i]%P+P)%P;
			}
			aux[0] = P-aux[0]*ax[i]%P;
		}
		for(int i=0; i<=n; i++) {
			llong coe = 1ll;
			for(int j=0; j<=n; j++) {
				if(j==i) continue;
				coe = coe*(ax[i]-ax[j]+P)%P;
			}
			coe = mulinv(coe)*ay[i]%P;
			for(int j=0; j<=n+1; j++) aux2[j] = aux[j];
			for(int j=n; j>=0; j--) {
				poly[j] = (poly[j]+aux2[j+1]*coe)%P;
				aux2[j] = (aux2[j]+aux2[j+1]*ax[i])%P;
			}
		}
	}
}
int main(){
	scanf("%d",&P);
	for(register int i=0;i<P;++i){
		int a;
		scanf("%d",&a);
		Lagrange::ax[i] = i;
		Lagrange::ay[i] = a;
	}
	Lagrange::lagrange(P-1);
	for(int i=0; i<P; i++) printf("%lld ",Lagrange::poly[i]);
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int sum, back;
		
		sum = n * 800;
		back = (n / 15) * 200;
		
		System.out.println(sum - back);
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
	double n, k; cin >> n >> k;

	double ans = 0;
	for (int i = 1; i <= n; ++i) {
		int cnt = 0;
		while (i * pow(2, cnt) < k) cnt++;
		ans += pow(0.5, cnt);
	}

	printf("%.16f\n", ans * (1 / n));

	return 0;
}

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

using namespace std;

int main(int argc, char** argv){
  
  string S1,S2,S3;
  
  cin >> S1 >> S2 >> S3;
  
  cout << S1[0] << S2[0] << S3[0] << endl;
  
  return 0;
}

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

int main() {
    
	int n, m, x;
	cin >> n >> m >> x;
	int occ = 0, toc = 0;
	for (int i=0; i<m; i++) {
		int k;
		cin >> k;
		if (k >= x) occ++;
		else toc++;
	}
	
	cout << min(occ, toc) << endl;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */

ll n;
vector<ll> a;

/* add your algorithm here */

int main() {
  cin >> n;

  rep(i,n) {
    ll b;
    cin >> b;
    a.pb(b - (i+1));
  }

  sort(a.begin(), a.end());
  ll b;

  if (!a.size() % 2) {
    ll t = a.size() / 2;
    b = (a[t] + a[t + 1]) / 2;
  } else {
    b = a[a.size() / 2];
  }

  ll ans = 0;
  rep(i,n) {
    ll t = abs(a[i] - b);
    ans += t;
  }

  cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;

    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }

    vector<int> l(n);
    int cnt = 0;
    l[0] = 0;
    int t = h[0];
    for (int i = 1; i < n; ++i) {
        if (h[i] > t) {
            cnt = 0;
            l[i] = cnt;
            t = h[i];
        } else {
            ++cnt;
            l[i] = cnt;
            t = h[i];
        }
    }

    int ans = 0;

    for (int i = 0; i < n; ++i) {
        ans = max(ans, l[i]);
    }

    cout << ans << endl;
}

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

int main() {
	int N;
	cin >> N;
	int i = 0;
	int N2 = N;
	while (N2 > 0) {
		i += N2 % 10;
		N2 = N2 / 10;
	}
	string s;
	if (N % i == 0) {
		s = "Yes";
	} else {
		s = "No";
	}
	cout << s << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    String s=sc.next();
    sc.close();
    if(a>=3200){
      System.out.println(s);
    }else{
      System.out.println("red");
    }
  }
}

Measured memory_bytes: 20820
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

int n, s1, s2, a[N];
int main()
{
	int i;
//	freopen ("input.txt", "r", stdin);
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf ("%d", &a[i]);
		if (a[i] % 2 == 0) s1++;
		else s2++;
	}
	if (s2 % 2 == 0) cout << "YES";
	else cout << "NO";
    return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define ll long long
ll gcd(ll a, ll b)
{
    if (a < b)
        swap(a, b);

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



int main()
{
    int n,d,x;
    cin>>n>>d>>x;
    int sum=0;
    sum+=x;
    int temp;
    for(int i=0;i<n;i++){
        cin>>temp;
        for(int j=0;;j++){
            if((j*temp+1)<=d){
                sum++;
            }else{
                break;
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  int max = 0;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int p;
    cin >> p;
    sum += p;
    if (max < p) max = p;
  }
  sum -= max / 2;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())

if a-b==d-e==g-h and b-c==e-f==h-i and a-d==b-e==c-f and d-g==e-h==f-i:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <sstream>	// require stringstream 
//#include <fstream>	// require freopen

using namespace std;

map <vector <int>, int > hand;

void bfs (void )
{
	vector <int> number (8, 0 );
	for (int i = 0; i < 8; ++i ){
		number[i] = i;
	} // end for

	const int dir[][2] = { {-1,0}, {0,1}, {1,0}, {0,-1} };


	queue<vector <int> > que;
	
	que.push (number );

	hand[number] = 0;

	while (!que.empty() ){
		vector <int> curr = que.front(); que.pop();

		int row, col;
		for (int i = 0; i < 8; ++i ){
			if (curr[i] == 0 ){
				row = i/4; col = i%4;
				break;
			} // end if
		} // end for
		for (int k = 0; k < 4; ++k ){		
			int nrow = row + dir[k][0];
			int ncol = col + dir[k][1];
			if (nrow < 0 || nrow >= 2 || ncol < 0 || ncol >= 4 ){
				continue;
			} // end if		
			vector <int> next = curr;
			swap (next[row*4 + col], next[nrow*4 + ncol] );
			if (hand.find (next) == hand.end() ){
				que.push (next );
				hand[next] = hand[curr] + 1;
			} // end if
		} // end for
	} // end while
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.sevenpuzzle", "r", stdin );
	string str = "";

	bfs ();
	while (getline (cin, str ) ){

		vector <int> start (8, 0 );
		stringstream ss(str);

		for (int i = 0; i < 8; ++i ){
			ss >> start[i];
		} // end for
		cout << hand[start] << endl;

	} // end loop
		
	return 0;
}

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

int N;
pair<int,int> A[2000];
int dp[2001][2001];

int happiness(int i, int to) {
  return abs(A[i].second - to) * A[i].first;
}

signed main() {
  cin >> N;
  for(int i=0; i<N; i++) {
    int a; cin >> a;
    A[i] = make_pair(a, i);
  }
  sort(A, A+N, greater<pair<int,int>>());

  int ans = 0;
  for(int sum=1; sum<=N; sum++) for(int x=0; x<=sum; x++) {
    int y = sum - x;
    //cerr << x << " " << y << endl;
    if(x == 0)    dp[x][y] = dp[x][y-1] + happiness(x+y-1, N-1-y+1);
    else if(y==0) dp[x][y] = dp[x-1][y] + happiness(x+y-1, x-1);
    else          dp[x][y] = max(dp[x-1][y] + happiness(x+y-1, x-1), dp[x][y-1] + happiness(x+y-1, N-1-y+1));
    ans = max(ans, dp[x][y]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 26200
/*
 * Author       : YangDavid
 * Created Time : 2019年09月21日 星期六 21时32分40秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 222222;
int n, k, p[maxn], ge[maxn];

int main() {
    scanf("%d%d", &n, &k);
    rep(i, n) scanf("%d", &p[i]);
    for(int i = 2; i <= n; ++i)
        ge[i] = p[i] > p[i - 1], ge[i] += ge[i - 1];
    set<int> st;

    int same = ge[k] == k - 1, tot = 1 - same;
    rep(i, k) st.insert(p[i]);
    for(int i = k + 1; i <= n; ++i) {
        bool ne = false;
        if(*st.begin() != p[i - k]) ne = true;
        st.erase(p[i - k]);
        if(*st.rbegin() > p[i]) ne = true;
        st.insert(p[i]);
        if(ne && ge[i] - ge[i - k + 1] == k - 1) same |= 1, ne = false;
        tot += ne;
    }
    printf("%d\n", tot + same);
    return 0;
}


Measured memory_bytes: 11136
#include <stdio.h>
#include <math.h>
#include <string.h>
int memo[100005][3], arr[100005][3], vis[100005][3];

int max(int a, int b)
{
    return a>b ? a : b;
}

int min(int a, int b, int c)
{
    return a<b ? a : b;
}

int dp(int n, int r)
{
    if(n==0)
        return max(arr[0][0], max(arr[0][1], arr[0][2]));
    if(vis[n][r]==1)
        return memo[n][r];
    vis[n][r]=1;
    if(r==0)
        return memo[n][r] = arr[n][0]+max(dp(n-1, 1), dp(n-1, 2));
    if(r==1)
        return memo[n][r] = arr[n][1]+max(dp(n-1, 0), dp(n-1, 2));
    if(r==2)
        return memo[n][r] = arr[n][2]+max(dp(n-1, 0), dp(n-1, 1));
}

int main()
{
    memset(memo, 0, sizeof(memo));
    memset(arr, 0, sizeof(arr));
    memset(vis, 0, sizeof(vis));
    int n;  scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d %d %d", &arr[i][0], &arr[i][1], &arr[i][2]);
    printf("%d\n", max(dp(n-1, 0), max(dp(n-1, 1), dp(n-1, 2))));
    return 0;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};



int main() {
    while(1){
    ll H;
    cin >>H;
    if(H==0) break;
    vector<vector<ll>> R(H,vector<ll>(5));

    rep(i,H) rep(j,5) cin>>R[i][j];
    ll ans = 0;
    rep(m,H){
        rep(i,H){
            ll cnt=0;
            ll p=-1;
            rep(j,5){
                if(R[i][j] == p && R[i][j] != -1){
                    cnt++;
                    if(j==4){
                        if(cnt>=3){
                            ans += R[i][j-1]*cnt;
                            rep(k,cnt){
                                R[i][j-k] = -1;
                            }
                        }
                    }
                }else{
                    if(cnt>=3){
                        ans += R[i][j-1]*cnt;
                        rep(k,cnt){
                            R[i][j-k-1] = -1;
                        }
                    }
                    cnt = 1;
                }
                

                p = R[i][j];
            }
        }
        rep(j,5){
            vector<ll> tmp;
            rep(i,H){
                if(R[H-1-i][j] != -1){
                    tmp.pb(R[H-1-i][j]);
                }
            }
            rep(i,H){
                if(i<tmp.size()){
                    R[H-1-i][j] = tmp[i];
                }else{
                    R[H-1-i][j] = -1;
                }
            }
        }

        /*rep(i,H){
            rep(j,5){
                cout << R[i][j]<<" ";
            }
            cout <<endl;
        }*/

    }

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

}



Measured memory_bytes: 3024
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main() {
	string s, t; cin >> s >> t;
	int x[101], y[101];
	for(int i=0;i<s.size();i++){
		x[i] = s[i]-'a';
	}
	for(int i=0;i<t.size();i++){
		y[i] = t[i]-'a';
	}
	sort(x, x+s.size());
	sort(y, y+t.size());
	if(x[0]<y[t.size()-1]){
		cout << "Yes" << endl;
		return 0;
	}
	if(x[0]==y[t.size()-1] && x[0]==x[s.size()-1] && s.size()<t.size()){
		cout << "Yes" << endl;
		return 0;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef pair<ll, l_l> lll;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};

priority_queue<lll, vector<lll>, greater<lll>> que;

int main() {
    ll N, Q;
    cin >> N >> Q;
    UnionFind uni(N);
    while(Q--) {
        ll A, B, C;
        cin >> A >> B >> C;
        que.push({C, {A, B}});
        que.push({C+1, {(A+1)%N, B}});
    }
    ll ans = 0;
    while(uni.size(1) != N) {
        lll now = que.top();
        que.pop();
        ll a = now.second.first;
        ll b = now.second.second;
        ll c = now.first;
        if(uni.merge(a, b)) {
            ans += c;
            que.push({c+2, {(a+1)%N, (b+1)%N}});
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

double expect(int d) {
    int sum = 0;
    rep(i, 0, d) { sum += i + 1; }
    return double(sum) / d;
}

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

    queue<double> q;
    double sum = 0.0;
    double ans = 0.0;

    rep(i, 0, n) {
        int d;
        cin >> d;

        double e = expect(d);
        sum += e;
        q.push(e);

        if (int(q.size()) == k) {
            ans = max(ans, sum);
            sum -= q.front();
            q.pop();
        }
    }
    printf("%.5f\n", ans);

    return 0;
}

Measured memory_bytes: 1920
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int M;
int P;
char S[4];
int res1;
int res2;
int ok[100000];
int ng[100000];
int main(){
  int Lj4PdHRW, i;
  rd(N);
  rd(M);
  for(Lj4PdHRW=(0);Lj4PdHRW<(M);Lj4PdHRW++){
    rd(P);P += (-1);
    rd(S);
    if(ok[P]){
      continue;
    }
    if(S[0]=='A'){
      ok[P]++;
    }
    else{
      ng[P]++;
    }
  }
  for(i=(0);i<(N);i++){
    if(ok[i]){
      res1++;
      res2 += ng[i];
    }
  }
  wt_L(res1);
  wt_L(' ');
  wt_L(res2);
  wt_L('\n');
  return 0;
}

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

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

  if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}


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

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

  vector<pair<int, int>> vec(n);
  rep(i,n){
    int a, b;
    cin >> a >> b;
    vec.push_back(make_pair(b, a));
  }
  
  sort(vec.begin(), vec.end());
  ll cnt = 0;
  bool flag = true;
  for (auto p: vec){
    int a, b;
    tie(b, a) = p;
    cnt += a;
    if (cnt > b){
      flag = false;
    }
  }
  cout << (flag? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 6424
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 10000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a, int b){
    int q=a/b,r=a%b;
    if(r==0){
        return b;
    }else{
        return gcd(b,r);
    }
}

int main(){
    int N;
    cin >> N;
    long long K;
    cin >> K;
    
    long long A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    
    
    int temp=A[0];
    for(int i=1; i<N; i++){
        temp=gcd(temp,A[i]);
    }
    
    
    sort(A,A+N);
    
    if(K%temp==0 && K<=A[N-1]){
        cout<<"POSSIBLE"<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }
    
    return 0;
}




Measured memory_bytes: 1024
#include <iostream>
 
using namespace std;
 
int main() {
    int N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;
    
    S = "#" + S + "#";
 
    auto can_reach = [&](int start, int end) {
        for (int i = start; i + 1 <= end; i++) {
            if (S[i] == '#' && S[i + 1] == '#') return false;
        }
        return true;
    };
 
    if (!can_reach(A, C) || !can_reach(B, D)) {
        cout << "No" << endl;
        return 0;
    }
 
    if (C > D) {
        bool snuke_can_over = false;
        for (int i = B; i <= D; i++) {
            if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') {
                snuke_can_over = true;
            }
        }
        if (!snuke_can_over) {
            cout << "No" << endl;
            return 0;
        }
    }
 
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 772
#include<bits/stdc++.h>
using namespace std;
int c=0;
bool comp(int a,int b)
{
    return a>b;
}
void dfs(int node,vector<int>adj[],bool vis[])
{
   vis[node]=true;
   for(int u:adj[node])
   {
       if(vis[u]==false)
       {
           c++;
           dfs(u,adj,vis);
       }
   }
}
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>adj[n+1];
    int u,v;
    for(int i=0;i<m;i++)
    {
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    bool vis[n+1];
    memset(vis,0,sizeof(vis));
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==false)
        {
            c=1;
            dfs(i,adj,vis);
            ans=max(ans,c);
        }
    }
    cout<<ans<<endl;

}

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

long int l[1000][3];

void swap(int a, int b, int c){
	int buf = l[c][a];
	l[c][a] = l[c][b];
	l[c][b] = buf;
}

//bubble
void sort(int c){
	for(int i = 0; i < 2; i++){
		for(int j = i; j < 2; j++){
			if(l[c][j] > l[c][j+1]) swap(j,j+1,c);	
		}
	}
}

int main(){
int buf;

cin >> buf;

for(int i = 0; i < buf; i++){	
	cin >> l[i][0] >> l[i][1] >> l[i][2];
	sort(i);
}

for(int j = 0; j < buf; j++){
	if(l[j][2]*l[j][2] == l[j][0]*l[j][0] +l[j][1]*l[j][1]){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

return 0;
}

Measured memory_bytes: 1176
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    l = LI()
    l.sort()
    ans = 0

    for i in range(n):
        for j in range(i):
            mini = l[i] - l[j]
            if mini < l[j]:
                ans += n-bisect.bisect_right(l, mini) - (n-j)

    print(ans)

main()


Measured memory_bytes: 75480
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    ll a = N/(A+B), b = N%(A+B);
    ll ans = a*A;
    ans += min(A, b);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int n, m, X, Y, x, y, xMax = -100, yMin = 100;
	scanf("%d%d%d%d", &n, &m, &X, &Y);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		if (xMax < x)
			xMax = x;
	}
	for (int i = 0; i < m; i++) {
		scanf("%d", &y);
		if (yMin > y)
			yMin = y;
	}
	if (xMax < yMin && X <= xMax && yMin <= Y) {
		printf("No War\n");
	} else {
		printf("War\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <queue>
#include <algorithm>

using namespace std;

//change

int main(){
	int n;
	int coin[6] = {500, 100, 50, 10, 5, 1};

	while(cin >> n){
		if(!n) return 0;

		int ans=0;
		n = 1000 - n;

		for(int i=0 ; i<6 ; i++){
			int temp = n / coin[i];
			ans += temp;
			n -= temp*coin[i];
		}

		cout << ans << endl;


	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1000000007;
int main(){
  ll n,m;
  cin >> n >> m;
  vector<ll> x(n),y(m);
  for(int i=0;i<n;i++){
    cin >> x[i];
  }
  for(int i=0;i<m;i++){
    cin >> y[i];
  }
  ll sumx=0,sumy=0;
  for(ll i=0;i<n;i++){
    sumx+=(2*i-n+1)*x[i];
    sumx%=mod;
  }
  for(ll i=0;i<m;i++){
    sumy+=(2*i-m+1)*y[i];
    sumy%=mod;
  }
  cout << sumx*sumy%mod << endl;
}

Measured memory_bytes: 1792
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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 dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int N;
	cin >> N;
	vector<int>a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int A, B;
	A = B = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (N % 2 == 0) {
			if (i % 2 == 1) {
				A += a[i];
			}
			else {
				B += a[i];
			}
		}
		else {
			if (i % 2 == 0) {
				A += a[i];
			}
			else {
				B += a[i];
			}
		}
	}
	cout << A - B << endl;
}


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

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

using namespace std;

using ll = long long int;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec)
{
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m, min = 0, max = MOD, tmp_a, tmp_b;
  cin >> n >> m;
  rep(i, m)
  {
    cin >> tmp_a >> tmp_b;
    if (min < tmp_a)
    {
      min = tmp_a;
    }
    if (max > tmp_b)
    {
      max = tmp_b;
    }
  }
  
  if (max >= min)
  {
    cout << max - min + 1 << endl;
  }
  else
  {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
  public static void main(String[] args )
  {
    Scanner scn = new Scanner(System.in) ;
    
    int n = scn.nextInt() ;
    
    int k = scn.nextInt() ;
    
    int[] arr =new int[n] ;
    
    for(int i =0 ; i < n; i++ ) arr[i] = scn.nextInt() ;
    
    
    if( n== 1 )
    {
     System.out.print(0) ; 
    }
    else{
    long[] dp = new long[n];
    
      dp[0] =  0 ; 
      //dp[1] =  (long)Math.abs(arr[1] - arr[0] ) ;
      
      for(int i =1 ; i < n; i++ )
      {
        long ans =  Long.MAX_VALUE ;
          
        
        for(int j = 1  ; j <= k ; j++ )
        {
         if( i-j < 0 ) break ;
          
          else{
           
            ans = Math.min(dp[i-j] + Math.abs(arr[i] - arr[i-j] ) ,ans ) ;
            
            
            }
          
        }
        dp[i] = ans  ;
        
        
     }
      
      System.out.print(dp[n-1]) ;
    
    }
    
    
    
  }
  
  
}


Measured memory_bytes: 59528
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String inputc1 = scanner.nextLine();
		String inputc2 = scanner.nextLine();
		String inputc3 = scanner.nextLine();
		scanner.close();

		System.out.println(inputc1.substring(0, 1) + inputc2.substring(1, 2) + inputc3.substring(2));

	}
}


Measured memory_bytes: 21716
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

h, w = na()
a = nsn(h)

dp = [[0] * (w + 1) for _ in range(h + 1)]
dp[1][1] = 1
for i in range(h):
    for j in range(w):
        if a[i][j] == '.':
            dp[i + 1][j + 1] += dp[i][j + 1] + dp[i + 1][j]

print(dp[h][w] % mod)

Measured memory_bytes: 157532
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

	int result = r;
	if (n < 10)
	{
		result = r + 100 * (10 - n);
	}

	cout << result << endl;
    return 0;
}

Measured memory_bytes: 3140
S_ = list(input())
T = list(input())
ans = []
for i in range(len(S_)-len(T)+1):
    for j in range(len(T)):
        if (T[j] == S_[i+j]) or (S_[i+j] == '?'):
            continue
        else:
            break
    else:
        S = S_[:i] + T + S_[i+len(T):]
        ans.append((''.join(S)).replace('?','a'))

if len(ans)!=0:
    print((sorted(ans))[0])
else:
    print('UNRESTORABLE')
        

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

int main() {
    //freopen("input1.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;
    vector<int> vec(n);
    for (int i=0; i<n; i++)
        cin >> vec[i];
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for (int i=1; i<n; i++){
        for (int j=max(0, i-k); j<i; j++)
            dp[i] = min(dp[i], dp[j] + abs(vec[i]-vec[j]));
    }
    cout << dp[n-1];
    return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p)
{
    return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc)
{
    o << "sz = " << vc.size() << endl
      << "[";
    for (const T& v : vc)
        o << v << ",";
    o << "]";
    return o;
}
using ll = long long;
constexpr ll MOD = 1000000007;

int main()
{
    ll H, W;
    cin >> H >> W;
    if (H % 3 == 0 or W % 3 == 0) {
        cout << 0 << endl;
        return 0;
    }
    long long sq = H * W;
    ll ans = 1000000000000000LL;
    rep(i, 4)
    {
        if (i < 2) {
            ll a = sq / 3 / H;
            if (i % 2 == 0) {
                a++;
            }
            ll sq1 = a * H;
            ll W_ = W - a;
            ll sq2, sq3;
            if (W_ % 2 == 0 or H % 2 == 0) {
                sq2 = (sq - sq1) / 2;
                sq3 = (sq - sq1) / 2;
            } else {
                sq2 = ((sq - sq1) + min(W_, H)) / 2;
                sq3 = ((sq - sq1) - min(W_, H)) / 2;
            }
            ans = min(ans, max({sq1, sq2, sq3}) - min({sq1, sq2, sq3}));
        } else {
            ll a = sq / 3 / W;
            if (i % 2 == 0) {
                a++;
            }
            ll sq1 = a * W;
            ll H_ = H - a;
            ll sq2, sq3;
            if (H_ % 2 == 0 or W % 2 == 0) {
                sq2 = (sq - sq1) / 2;
                sq3 = (sq - sq1) / 2;
            } else {
                sq2 = ((sq - sq1) + min(H_, W)) / 2;
                sq3 = ((sq - sq1) - min(H_, W)) / 2;
            }
            ans = min(ans, max({sq1, sq2, sq3}) - min({sq1, sq2, sq3}));
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F(i,j,k) for(int i=(j);i<=(k);++i)
#define _F(i,j,k) for(int i=(j);i<(k);++i)
#define D(i,j,k) for(int i=(j);i>=(k);--i)
#define _D(i,j,k) for(int i=(j);i>(k);--i)
#define rep(it,s) for(__typeof(s.begin()) it=s.begin();it!=s.end();++it)
#define Rep(a,s) for(auto a:s)
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
template<class Type>ll quick_pow(Type x,Type y,Type Mod){
    ll res=1;
    while(y){
        if(y&1)res=res*x%Mod;
        x=x*x%Mod,y>>=1;
    }
    return res;
}
template<class Type>ll inv(Type x,Type Mod){return quick(x,Mod-2,Mod);}
namespace IO{
    template <class T>
    inline void read(T &x){
        x=0;int f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch<='9'&&ch>='0')x=x*10+ch-'0',ch=getchar();
        x*=f;
    }
};
using namespace IO;
ll solve(ll x,ll y){
    if(x>y)swap(x,y);
    if(y%x==0)return (2*(y/x)-1)*x;
    else return 2*(y/x)*x+solve(y%x,x);
}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    ll n,x;
    cin>>n>>x;
    cout<<n+solve(x,n-x)<<endl;
	return 0;
}


Measured memory_bytes: 3516
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

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

  // vector<int> P(N);
  // set<int, greater<int>> Q;
  // for (int ii=0; ii<N; ++ii) {
  //   Q.insert(ii+1);
  // }

  // uint64_t sumMod = 0;
  // for (int ii=N-1; ii>=0; --ii) {
  //   int maxMod = -1, maxModQ;
  //   for (auto& q : Q) {
  //     int modQ = q%(ii+1);
  //     if (modQ > maxMod) {
  // 	maxMod = modQ;
  // 	maxModQ = q;
  //     }
  //   }
  //   P[ii] = maxModQ;
  //   sumMod += maxMod;
  //   Q.erase(maxModQ);
  // }

  // for (int ii=0; ii<N; ++ii)
  //   cerr << ii+1 << ' ';
  // cerr << endl;
  
  // for (auto p : P)
  //   cerr << p << ' ';
  // cerr << endl;

  cout << (uint64_t)N*(N-1)/2 << endl;

  return 0;
}


Measured memory_bytes: 256
const double = Float64
const int = Int64
const vint = Vector{int}
const vdouble = Vector{double}

int(x) = parse(int,x)
parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  a,b,c,k = readint()
  
  if k <= a
    println(k)
  elseif k <= a + b
    println(a)
  else
    println(a - (k-a-b))
  end
 
end

main()

Measured memory_bytes: 214648
a = input()

plusminus = ['+', '-']

def calc(a, b, op):
    if op == '+':
        return a + b
    elif op == '-':
        return a - b
    else:
        ValueError

def cnt_calc(a, op1, op2, op3):
    return calc(
                int(a[3]),
                calc(
                    int(a[2]),
                    calc(
                        int(a[0]), int(a[1]), op1
                    ),
                    op2
                ),
                op3
            )


for i in plusminus:
    for j in plusminus:
        for k in plusminus:
            if eval(a[0] + i + a[1] + j + a[2] + k + a[3]) == 7:
            # if cnt_calc(a, i, j, k) == 7:
                print(a[0] + i + a[1] + j + a[2] + k + a[3] + '=7')
                exit(0)




Measured memory_bytes: 38384
#include<iostream>

using namespace std;

char mymap[9][9]={0};

void solve(int x,int y){
	
	int tx,ty;
	int dx[12]={0,0,0,1,2,3,0,0,0,-1,-2,-3};
	int dy[12]={-1,-2,-3,0,0,0,1,2,3,0,0,0};
	
	mymap[y][x]='0';
	
	//xy垂直水平方向ループ
	for(int i=0;i<12;i++){
		tx=x+dx[i];
		ty=y+dy[i];
		
		if(0<=tx && tx<8 && 0<=ty && tx<8){
			if(mymap[ty][tx]=='1'){
				solve(tx,ty);
			}
		}
	}
	return ;
}

int main(void){
	int n,x,y;
	
	
	cin>>n;
	for(int i=0;i<n;i++){
		
		for(int j=0;j<8;j++){
			cin>>mymap[j];
		}
		cin>>x>>y;
	
		solve(x-1,y-1);
		
		cout<<"Data "<<i+1<<":"<<endl;
		for(int j=0;j<8;j++){
			cout<<mymap[j]<<endl;
		}
	}	
}

Measured memory_bytes: 1172
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(){
    int n;
    cin >> n;
    vi(x,n);
    rep(i,n){
        cin >> x[i];
    }
    srt(x);
    //cout << x[0] << endl;
    int ans = mod;
    rng(i,x[0],x[n-1]+1){
        int sum=0;
        rep(j,n){
            sum += (i-x[j])*(i-x[j]);
        }
        //cout << i << ":" << sum << endl;
        ans=min(ans,sum);
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    int N, p[51], i, count=0;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> p[i];

        if(p[i] != i){
            count++;
        }
    }

    if(count <= 2){
        cout << "YES" << endl;
    }

    else{
        cout << "NO" << endl;
    }

    return 0;
}

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

int main()
{
    int s, hh, mm, ss;
    cin >> s;
    
     ss = s % 60;
    
     mm = (s / 60) % 60;

     hh = s / 3600;
    
    cout << hh << ":" << mm << ":" << ss << endl;
    
    return 0;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)

int N, tt[22][22], use[22];

int dfs(int v, int p, int ct) {
	int res = ct;
	
	for_(i,0,N) {
		if (i == p || tt[v][i] == -1 || !use[i]) continue;
		res = max(res, dfs(i, v, ct + tt[v][i]));
	}
	
	return res;
}

int main() {
	while (cin >> N, N) {
		memset(tt, -1, sizeof(tt));
		
		for_(i,0,N-1) {
			int a, b, t; cin >> a >> b >> t;
			--a; --b;
			tt[a][b] = tt[b][a] = t;
		}
		
		memset(use, 0, sizeof(use));
		for_(i,0,N) {
			int cnt = 0;
			for_(j,0,N) if (tt[i][j] != -1) ++cnt;
			if (cnt > 1) use[i] = 1;
		}
		use[0] = 1;
		
		int ans = 0;
		for_(i,0,N) for_(j,i+1,N) if (use[i] && use[j] && tt[i][j] > 0) ans += tt[i][j];
		
		cout << 2 * ans - dfs(0, -1, 0) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>
int CAKE(int Sum, int n)
{
    int ret;
    ret=Sum/n;
	if(Sum%n!=0)
	{ 
		ret++;
	}
	return ret;
}

int main(void)
{
	int N,C,Sum=0,p,i,Cake;
	
	scanf("%d %d",&N,&C);
	for(i=0;i<C;i++)
	{
		scanf("%d",&p);
		Sum+=p;
	}
	N++;//自分プラス
	Cake=CAKE(Sum,N);

	printf("%d\n",Cake);
	return 0;
}



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

int main(){
  int n;
  string s;
  int cnt=0;
  
  cin >> n >> s;
  rep(i, n-2){
    if(s.substr(i, 3) == "ABC") cnt++;
  }
  
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int main(void){
  int a=0,b,c;
  string s;
 cin >> s;
  for(int i =0;i < s.size();i++){
    if(s.at(i) == '+'){
      a++;
    }else if(s.at(i) == '-'){
      a--;
    }
  }
  cout << a;
}

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

int main() {

    vector<vector<int>> C(3, vector<int>(3));

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

    vector<int> a(3);
    vector<int> b(3);

    a[0] = 0;
    b[0] = C[0][0];
    b[1] = C[0][1]; 
    b[2] = C[0][2];
    a[1] = C[1][0] - b[0];
    a[2] = C[2][0] - b[0];

    int cnt = 0;

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (C[i][j] == a[i] + b[j])
                cnt ++;
        }
    }

    cout << ((cnt == 9) ? "Yes" : "No") << endl;

    return 0;

}


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

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

    vector<int> a, b;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;

        if(x < 0)
            b.Pb(-x);
        else
            a.Pb(x);
    }

    reverse(All(b));

    int la = a.size(), lb = b.size();

    int ans = INT_MAX;
    for(int i = 0; i < la; i++){
        int x = i + 1;
        if(x > k)
            break;
        if(k - x > lb)
            continue;
        if(k == x){
            ans = min(ans, a[i]);
            break;
        }

        x = k - x - 1;
        ans = min(ans, 2 * a[i] + b[x]);
    }

    for(int i = 0; i < lb; i++){
        int x = i + 1;
        if(x > k)
            break;
        if(k - x > la)
            continue;
        if(k == x){
            ans = min(ans, b[i]);
            break;
        }

        x = k - x - 1;
        ans = min(ans, 2 * b[i] + a[x]);
    }

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


Measured memory_bytes: 3924
#include <iostream>
#include <algorithm>
#include <set>

int main(void){
    int N, ans = 0;
    std::string S;
    std::cin >> N >> S;

    for (int i = 1; i < N; ++i){
        std::set<char> lst, rst, st;
        std::string ls, rs;
        ls = S.substr(0, i);
        rs = S.substr(i, N - i);
        for (char c: ls){
            lst.insert(c);
        }
        for (char c: rs){
            rst.insert(c);
        }
        std::set_intersection(lst.begin(), lst.end(), rst.begin(), rst.end(), std::inserter(st, st.end()));
        ans = std::max(ans, (int)st.size());
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f40;
const long long mod=2e9+7;
const long double PI = acos(0);
// }}} End Header
int main() {
	ll R, G, B, n, ans=0;
	cin >> R >> G >> B >> n;
	for(ll r=0; r<=n; r++){
		for(ll g=0; g<=n; g++){
			if((n-R*r-G*g)%B == 0 && (n-R*r-G*g)/B >= 0) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a=0, b=0;
    while(n) {
      string str1, str2;
      cin >> str1>>str2;
      if (str1==str2) {
        a++;
        b++;
      } else if(str1>str2) {
        a+=3;
      } else {
        b+=3;
      }
      n--;
    }

    cout << a <<' '<< b << endl;
    return 0;
}



Measured memory_bytes: 3160
N = int(input())
A = list(map(int, input().split()))
B = [0]*N
for i in range(N):
    B[i] = A[i] - i
B.sort()

res = 0
x = B[N//2]

for i in range(N):
    res += max(x - B[i], -x + B[i])

print(res)

Measured memory_bytes: 26836