akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool> vecbool;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<string> vecstr;
typedef vector<vecint> vec2int;
typedef vector<vecbool> vec2bool;
int dx[4]{-1, +1, 0, 0};
int dy[4]{0, 0, -1, +1};
set<ll> lun;
void dfs(ll i, ll last) {
  if (i > 3234566667) return;
  if (lun.find(i) != lun.end()) return;
  lun.insert(i);
  if (last == 0) {
    dfs(10 * i + last, last);
    dfs(10 * i + last + 1, last + 1);
  } else if (last < 9) {
    dfs(10 * i + last - 1, last - 1);
    dfs(10 * i + last, last);
    dfs(10 * i + last + 1, last + 1);
  } else {
    dfs(10 * i + last - 1, last - 1);
    dfs(10 * i + last, last);
  }
}
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
int main() {
  init();
  int k;
  cin >> k;
  // int cnt = 0;
  // for (ll i = 1; i < 3234566668; i++) {
  //   string str = to_string(i);
  //   bool ok = true;
  //   REP(j, str.size() - 1) {
  //     int x = str[j] - '0';
  //     int y = str[j + 1] - '0';
  //     if (abs(x - y) > 1) {
  //       ok = false;
  //       break;
  //     }
  //   }
  //   if (ok) {
  //     cnt++;
  //   }
  //   if (cnt == k) {
  //     cout << i << endl;
  //     return 0;
  //   }
  // }
  for (ll i = 1; i <= 9; i++) {
    dfs(i, i);
  }
  int cnt = 0;
  REPvec(itr, lun) {
    cnt++;
    if (cnt == k) {
      cout << *itr << endl;
    }
  }
}


Measured memory_bytes: 4992
n = input()
if n[0] == "S":
    if n[1] == "S":
        if n[2] == "S":
            print("0")
        else:
            print("1")
    else:
        if n[2] == "S":
            print("1")
        else:
            print("2")
else:
    if n[1] == "S":
        print("1")
    else:
        if n[2] == "S":
            print("2")
        else:
            print("3")

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

int arr[3005];
int memo[3005];
vector<int> adjl[3005];

int dp(int node){
if (memo[node]!=-1) return memo[node];
for (int x : adjl[node]){
    if (arr[x]<arr[node]){
        if (dp(x)==0) return memo[node] = 1;
    }
}
return memo[node] = 0;
}

int main(){
int n;
memset(memo,-1,sizeof(memo));
scanf("%d",&n);
for (int x = 0; x<n; x++){
    scanf("%d",&arr[x]);
}
for (int x = 0; x<n-1; x++){
    int a,b;
    scanf("%d%d",&a,&b);
    a--;b--;
    adjl[a].push_back(b);
    adjl[b].push_back(a);
}
for (int x = 0; x<n; x++){
    if (dp(x)==1) printf("%d ",x+1);
}
}


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

int main(){
  int i,N,K=1,k,A[3],a[3],ans=10000,st,now;
  cin>>N>>A[0]>>A[1]>>A[2];
  vector<int> v(N);
  rep(i,N){cin>>v[i];K*=4;}
  while(K--){
    k=K;
    now=N*10-30;
    rep(i,3)a[i]=0;
    rep(i,N){
      st=k%4;
      k/=4;
      if(st==0){now-=10;continue;}
      a[st-1]+=v[i];
    }
    rep(i,3){
      if(a[i]==0)now=100000;
      now+=abs(a[i]-A[i]);
    }
    if(ans>now)ans=now;
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N + 1);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    A[N] = A[0];


    if (accumulate(A.begin(), A.end() - 1, 0LL) % (((N + 1) * N) / 2) != 0) {
        puts("NO");
        return 0;
    }

    ll q = accumulate(A.begin(), A.end() - 1, 0LL) / (((N + 1) * N) / 2);

    vector<ll> diff(N);
    for (int i = 0; i < N; ++i) {
        diff[i] = A[i + 1] - A[i];
        if (diff[i] > q) {
            puts("NO");
            return 0;
        }
    }


    for (int i = 0; i < N; ++i) {
        if (abs(q - diff[i]) % N != 0) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");

    return 0;
}

Measured memory_bytes: 1792
n = int(input()) 

num = len(str(n))
if num==1:
    print(n)
elif num==2:
    print(9)
elif num==3:
    print(n-99+9)
elif num==4:
    print(900+9)
elif num==5:
    print(n-9999+900+9)
else:
    print(90909)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

char s[12],t[12];
int n,ans;

void solve(int idx,int cost){
	if(idx == n) ans = cost;
	if(cost >= ans) return;

	int i,j,r;

	if(s[idx] == t[idx]){
		solve(idx+1,cost);
	}
	else{
		for(i=idx;i<n;i++){
			r = t[idx] - s[idx];
			for(j=idx;j<=i;j++) s[j] = (s[j] + 10 + r) % 10;
			solve(idx+1,cost+1);
			for(j=idx;j<=i;j++) s[j] = (s[j] + 10 - r) % 10;
		}
	}
}

int main(void){
	int i,j,d,x;

	while(scanf("%d",&n),n){
		scanf("%s%s",s,t);
		for(i=0;i<n;i++){
			s[i] -= '0';
			t[i] -= '0';
		}

		ans = 999999999;
		solve(0,0);
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 412
#include<stdio.h>
int main(void)
{
	int d;
	scanf("%d",&d);
	if(d==22){
		printf("Christmas Eve Eve Eve\n");
	}
	if(d==23){
		printf("Christmas Eve Eve\n");
	}
	if(d==24){
		printf("Christmas Eve\n");
	}
	if(d==25){
		printf("Christmas\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


int x[100005],y[100005],mm[100005];
signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
   
 #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
 #endif

// -------------------------------------Code starts here---------------------------------------------------------------------     

   int a,b,m;
   cin>>a>>b>>m;
   int mn1=1e9,mn2=1e9;
   for(int i=1;i<=a;i++)
   {
      cin>>x[i];
      mn1=min(mn1,x[i]);
   }
   for(int i=1;i<=b;i++)
   {
      cin>>y[i];
      mn2=min(mn2,y[i]);
   }
   int ans=mn1+mn2;
   int xx,yy,zz;
   for(int i=1;i<=m;i++)
   {
      cin>>xx>>yy>>zz;
      ans=min(ans,x[xx]+y[yy]-zz);
   }
   cout<<ans;

// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }

Measured memory_bytes: 1792
const CHARS_753: [char; 3] = ['7', '5', '3'];

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn count(s: &String, c: char) -> i32 {
    let chars_vec: Vec<char> = s.chars().collect();
    chars_vec.iter().filter(|cmp_c| **cmp_c == c).count() as i32
}

fn dfs(s: String, n: i32) -> i32 {
    let num: i32 = match s.parse::<i32>() {
        // match &str
        Err(e) => match &*e.to_string() {
            "number too large to fit in target type" => { (10 as i32).pow(9) },
            _ => { 0 },
        },
        Ok(num) => { num },
    };
    if num > n {
        0
    }
    else {
        let is_753   = CHARS_753.iter().all(|c| count(&s, *c) > 0);
        let sum: i32 = CHARS_753.iter().map(|c| {
            let mut new_string = s.clone();
            new_string.push(*c);
            dfs(new_string, n)
        }).sum();
        sum + if is_753 { 1 } else { 0 }
    }
}

fn main() {
    let n: i32 = read();
    println!("{}", dfs("".to_string(), n));
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
    int X;  cin>>X;
    if(X==1){
        cout<<"1"<<endl;
        return 0;
    }
    for(int i=X;i>1;--i){
        for(int b=2;;++b){
            if(b>pow(i,0.5)){
                break;
            }
            for(int p=2;;++p){
                if(i==pow(b,p)){
                    cout<<i<<endl;
                    return 0;
                }
                if(i<pow(b,p)){
                    break;
                }
            }
        }
    }
}

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

int main()
{
        char str1[22],str2[22];
        int l;

        scanf("%s",str1);

        l = strlen(str1);

        for(int i=0;i<l;i++){
                str2[i] = str1[l-i-1];
        }
        str2[l] = '\0';

        printf("%s\n",str2);

        return 0;
}

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

int main(){
  string s,t;
  cin >> s;
  t=s;
  for(int i=0;i<t.size()/2;i++){
    s=s.substr(0,s.size()-2);
    if(s.substr(0,s.size()/2)==s.substr(s.size()/2)){
      break;
    }
  }
  cout << s.size() << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    long long  n,m,A[100000];
    cin>>n>>m;
    for(int i=0;i<n;i++) cin>>A[i];
    long long B[100000];
    B[0]=0;
    for(int i=0;i<n;i++) B[i+1]=B[i]+A[i];
    for(int i=1;i<=n;i++) B[i]=B[i]%m;
    long long ans;
    for(int i=1;i<=n;i++){
        if(B[i]==0) ans++;
    }
    sort(B+1,B+n+1);
      long long ptr = 1;
	long long cc;
	while (ptr < n+1) {
		cc = B[ptr];
		long long e = 0;
		while (ptr < n+1&&B[ptr] == cc) e++, ptr++;
		ans += e*(e-1)/2;
	}
    cout<<ans;
}

Measured memory_bytes: 1792
#include<stdio.h>
   
int main(void){
    int k,count=0;
    long long x=1,n=1;
    scanf("%d",&k);
    printf("1\n");
    for (int i=1; i<k; i++){
        long long m=x+n,s=0;
        while(m!=0){
            s+=m%10;
            m/=10;
        }
        if((i-count)%9==0){
            if(x+n>n*s){
                n=n*10;
                count=0;
            } else {
                count++;
            }
        }
        x+=n;
        printf("%lld\n",x);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val w = readLine()!!
    val arr = IntArray(26)
    for (i in w.indices) {
        arr[w[i]-'a']++
    }
    var ans = true
    arr.forEach {
        if(it % 2 != 0) ans = false
    }
    if (ans) println("Yes")
    else println("No")
}


Measured memory_bytes: 34512
X,K,D = map(int,input().split())

ma = D * K
ans = 0
if abs(X) >= ma:
    ans = abs(X) - ma
    print(ans)
else:
    div,mod = divmod(X,D)
    if (div - K) % 2 == 0:
        print(mod)
    else:
        tmp = (div + 1) * D
        print(abs(X - tmp))

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e9 + 1;

// 座標圧縮 vector a の要素を圧縮して d に変換
struct Compress{
    vector<int> d, unzip;
    map<int, int> zip;        
    Compress(vector<int> a){
        vector<int> b = a;
        d.resize(a.size());
        sort(b.begin(), b.end());
        b.erase(unique(b.begin(), b.end()), b.end());
        unzip.resize(b.size());
        for(int i = 0; i < b.size(); i++){
            zip[b[i]] = i;
            unzip[i] = b[i];
        }
        for(int i = 0; i < a.size(); i++){
            d[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
        }
    }
};

// build を忘れない！！！！！
struct CumulativeSum2D{
    vector<vector<int> > data;
    CumulativeSum2D(int H, int W) : data(H + 1, vector<int>(W + 1, 0)) {}
    //要素(x,y)に値zを加える
    void add(int x, int y, int z){
        ++x, ++y;
        if(x >= data.size() || y >= data[0].size()) return;
        data[x][y] += z;
    }
    void build(){
        for(int i = 1; i < data.size(); i++) {
        for(int j = 1; j < data[i].size(); j++) {
            data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
            }
        }
    }
    //左上[sy, sx], 右下(gx, gy)の矩形内の和を求める(半開区間) (0-index)
    int query(int sx, int sy, int gx, int gy){
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }
};

/*
verified
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2426&lang=jp
*/

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> x(n), y(n);
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    x.push_back(-MAX);
    y.push_back(-MAX);
    x.push_back(MAX);
    y.push_back(MAX);
    Compress cx(x), cy(y);
    CumulativeSum2D cs(n + 2, n + 2);
    for(int i = 0; i < x.size(); i++){
        if(i < n) cs.add(cx.d[i], cy.d[i], 1);
        // cout << " " << cx.d[i] << ' ' << cy.d[i] << endl;
    }
    cs.build();
    // for(int ii = 0; ii < cx.unzip.size(); ii++){
    //     if(ii) cout << ' ';
    //     cout << cx.unzip[ii];
    // }
    // cout << endl;    
    // for(int ii = 0; ii < cy.unzip.size(); ii++){
    //     if(ii) cout << ' ';
    //     cout << cy.unzip[ii];
    // }
    // cout << endl;
    for(int i = 0; i < m; i++){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        x1 = lower_bound(cx.unzip.begin(), cx.unzip.end(), x1) - cx.unzip.begin();
        y1 = lower_bound(cy.unzip.begin(), cy.unzip.end(), y1) - cy.unzip.begin();
        x2 = upper_bound(cx.unzip.begin(), cx.unzip.end(), x2) - cx.unzip.begin() - 1;
        y2 = upper_bound(cy.unzip.begin(), cy.unzip.end(), y2) - cy.unzip.begin() - 1;
        // cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
        if(x1 > x2 || y1 > y2){
            cout << 0 << endl;
            continue;
        }
        int tmp = cs.query(x1, y1, x2 + 1, y2 + 1);
        cout << tmp << endl; 
    }
}


Measured memory_bytes: 101624
#include<iostream>
#include<vector>

using namespace std;

int main(){
	int H, W, K; cin >> H >> W >> K;
	vector<string> s(H);
	vector<vector<int> > ans(H, vector<int>(W, 0));
	vector<int> num(H);

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

	int cake = 1;
	for(int i = 0; i < H; ++i){
		int cnt = 0;
		for(int j = 0; j < W; ++j){
			if(s[i][j] == '#') {
				cnt++;
				ans[i][j] = cake;
				cake++;
			}
		}
		num[i] = cnt;
	}
	
	// 右探索
	for(int i = 0; i < H; ++i){
		int now = 0;
		if(num[i] == 0) continue;
		for(int j = 0; j < W; ++j){
			if(ans[i][j] > 0) now = ans[i][j];
			if(now == 0) continue;
			else{
				if(ans[i][j] == 0) ans[i][j] = now;
			}
		}
	}

	// 左探索
	for(int i = 0; i < H; ++i){
		int now = 0;
		if(num[i] == 0) continue;
		for(int j = W-1; j >= 0; --j){
			if(ans[i][j] > 0) now = ans[i][j];
			if(now == 0) continue;
			else{
				if(ans[i][j] == 0) ans[i][j] = now;
			}
		}
	}

	// 下探索
	for(int j = 0; j < W; ++j){
		int now = 0;
		for(int i = 0; i < H; ++i){
			if(ans[i][j] > 0) now = ans[i][j];
			if(now == 0) continue;
			else{
				if(ans[i][j] == 0) ans[i][j] = now;
			}
		}
	}

	// 上探索
	for(int j = 0; j < W; ++j){
		int now = 0;
		for(int i = H-1; i >= 0; --i){
			if(ans[i][j] > 0) now = ans[i][j];
			if(now == 0) continue;
			else{
				if(ans[i][j] == 0) ans[i][j] = now;
			}
		}
	}
	for(int i = 0; i < H; ++i){
		cout << ans[i][0];
		for(int j = 1; j < W; ++j){
			cout << " " << ans[i][j];
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 1280
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	while(1) {

		bool isfirst = true;
		int M, N, L, S = 0;

		cin >> L;
		if( L == 0 )
			break;
		
		for( int i = 0; i < 12; i++ ) {

			cin >> M >> N;

			S += M - N;

			if( L <= S && isfirst ) {
				cout << i+1 << endl;
				isfirst = false;
			}
		}

		if( isfirst ) {
			cout << "NA" << endl;
		}
		
	NEXT:;	

	}

    return 0;
}

Measured memory_bytes: 3016
#include <iostream>
using namespace std;
int main(){
	int n,p=0,maxp=0;
	char c;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>c;
		if(c=='I') p++;
		if(c=='D') p--;
		maxp=max(maxp,p);
	}
	cout<<maxp<<endl;
	return 0;
}

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

int main(){
  int N,M;
  cin >>N>>M;
  char A[N][N];
  char B[M][M];
  string temp;
  
  //A入力
  for(int i=0;i<N;i++){
    cin>>temp;
    for (int j=0;j<N;j++){
      A[i][j]=temp.at(j);
    }
  }
  //B入力
  for(int i=0;i<M;i++){
    cin>>temp;
    for (int j=0;j<M;j++){
      B[i][j]=temp.at(j);
    }
  }  
  
  //判定
  for(int k=0;k<=N-M;k++){
    for(int l=0;l<=N-M;l++){
      bool flag=0;
      
      for(int i=0;i<M;i++){
        for(int j=0;j<M;j++){
          if(B[i][j]!=A[i+k][j+l]){
            //cout<<B[i][j]<<A[j+k][j+l]<<i<<j<<k<<l<<"#"<<flag<<endl;
            flag=1;
          }
        }
        
        if(flag){
          break;
        }
      }
      if(flag){
        continue;
      }
      else {
      cout<<"Yes"<<endl;
      return 0;
      }
    }
  }
  cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
if __name__ == "__main__":
    n, y = map(int, input().split())

    # 10000円の数を決め打ちしてつるかめ

    for i in range(n+1):
        for j in range(n-i + 1):
            k = n - i - j
            if n == i + j + k and y == i * 10000 + j * 5000 + k * 1000:
                print(str(i) + ' ' + str(j) + ' ' + str(k))
                exit()

    print('-1 -1 -1')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
string s,t;
int ans=100000;
int main(){
	cin>>s>>t;
	for (int i=0;i<s.size();i++)
		if (i+t.size()<=s.size()){
			int x=0,y=t.size();
			for (int j=0;j<t.size();j++) if (s[i+j]==t[j]) x++;
			ans=min(ans,y-x);
		}
	cout<<ans<<endl;
	return 0;
}

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

const int MAX_N = 100000;
int n;
int h[MAX_N];

void solve() {
    int ans = 0;
    int temp = 0;
    for (int i = 1; i < n; i++) {
        if (h[i] <= h[i - 1]) {
            temp++;
        } else {
            if (ans < temp) {
                ans = temp;
            }
            temp = 0;
        }
    }
    if (ans < temp) {
        ans = temp;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
#define ll long long 

ll min(ll a, ll b)
{
        return (a>b)?b:a;
}

int main()
{
        ll n;
        scanf("%lld", &n);
        ll a[n+1], dp[n+10], i;
        for(i = 0; i < n; i++)
        {
                scanf("%lld", a+1+i);
        }
        ll cost = 0;
        dp[0] =dp[1] = 0;
        dp[2] = abs(a[2]-a[1]);

        for(i = 3; i <= n; i++)
        {
                dp[i] = min(dp[i-2] + abs(a[i]-a[i-2]), dp[i-1]+abs(a[i]-a[i-1]));
        }

        printf("%lld\n", dp[n]);
        return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>

using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;

int main(){

    string s;
    cin >> s;

    if(s=="AAA" || s=="BBB"){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

     return 0;
}

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

using namespace std;

bool palindrome(int l, int h, const string& s){

	//l--, h--;

	int mid = (l+h)/2;

	for(int i=l; i<mid; i++)
		if(s[i] != s[h-1-i])
			return false;

	return true;

}

int main(){

	string s;

	cin >> s;

	int i, n = s.size();

	if( !palindrome(0, n, s) || !palindrome(0, (n-1)/2, s) || !palindrome((n+1)/2, n, s))
		cout<<"No";
	else
		cout<<"Yes";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+100;
int arr[N];
char str[N],res[N];
bool solve(int n){
	bool flag=0;
	for(int i=1;i<=n;i++){
			int l=i-1,r=i+1;
			if(l==0)l=n;
			if(r==n+1)r=1;
			
			bool tmp=(str[i]=='o');
			if(res[i]=='W')tmp=!tmp;
			if(tmp){
				if(res[l]!='0'&&res[r]!='0'&&res[r]!=res[l]){
					flag=1;
					break;
				}else if(res[l]!='0'&&res[r]!='0'&&res[r]==res[l]){
					continue;
					
				}else{
					if(res[r]=='0')res[r]=res[l];
					else if(res[l]=='0')res[l]=res[r];
					else res[r]=res[l]='S';
				}
			}else{
				if(res[r]!='0'&&res[l]!='0'&&res[r]==res[l]){
					flag=1;
					break;
				}else if(res[r]!='0'&&res[l]!='0'&&res[r]!=res[l]){
					continue;
				}else{
					if(res[r]=='0')res[r]=(res[l]=='S'?'W':'S');
					else if(res[l]=='0')res[l]=(res[r]=='S'?'W':'S');
					else res[l]='S',res[r]='W';	
				}
			}
		}
	return flag;
}
int main() {
	int n;
	while(scanf("%d",&n)!=EOF){
		
		scanf("%s",str+1);
		bool flag=0;
		memset(res,'0',sizeof(res));
		res[1]='S';
		res[2]='W';
		flag=solve(n);
		if(!flag){
			goto fun;
		}
		
		memset(res,'0',sizeof(res));
		res[1]='S';
		res[2]='S';
		flag=solve(n);
	
		if(!flag){
			goto fun;
		}
		
		memset(res,'0',sizeof(res));
		res[1]='W';
		res[2]='W';
		flag=solve(n);
		if(!flag){
			goto fun;
		}
		
		memset(res,'0',sizeof(res));
		res[1]='W';
		res[2]='S';
		flag=solve(n);
		if(!flag){
			goto fun;
		}
		
		fun:
		if(flag)printf("-1\n");
		else{
			for(int i=1;i<=n;i++)printf("%c",res[i]);
			printf("\n");
		} 	
	}

	return 0;
}


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

using namespace std;

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, n) for(int i=0; i<(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair

typedef long long int ll;
typedef long long unsigned int llu;


int main(){
  int N,M;
  ll in;
  cin >> N;
  multiset<ll> d;
  rep(i,N) {
    scanf("%lld",&in);
    d.insert(in);
  }
  cin >> M;
  multiset<ll> t;
  rep(i,M) {
    scanf("%lld",&in);
    t.insert(in);
  }
  int flag;
  auto itr3 = d.begin();
  for(auto itr = t.begin(); itr != t.end(); ++itr) {
    flag = 0;
    for(auto itr2 = itr3; itr2 != d.end(); ++itr2) {
        if(*itr==*itr2) {
          itr3 = itr2;
          itr3++;
          flag =1;
          break;
        }
    }
    if(flag==0) break;

  }
  if(flag==0) printf("NO");
  else printf("YES");
  return 0;
}


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

vector<int> children[100010];

int dfs(int par) {
    if (children[par].empty()) return 0;
    vector<int> v;
    for (auto ch : children[par]) {
        v.push_back(dfs(ch) + 1);
    }
    sort(v.begin(), v.end());
    REP(i, 1, v.size()) {
        if (v[i - 1] >= v[i]) v[i] = v[i - 1] + 1;
    }
    return *v.rbegin();
}

int main() {
    int n;
    cin >> n;
    for (int i = 2; i <= n; i++) {
        int par;
        cin >> par;
        children[par].push_back(i);
    }
    cout << dfs(1) << endl;
    return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
//#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
#define int long long
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}

ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

int32_t main(){
  fastio;
  int k;
  cin>>k;
  string s;
  cin>>s;
  if(s.size()<=k){
    cout << s << endl;
  }else{
    string t="";
    for(int i=0;i<k;i++){
      t+=s[i];
    }
    t+="...";
    cout << t << endl;
  }
  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (ll)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// ll        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n;
  cin >> n;
  vector<ll> x(n), y(n);
  rep(i, n) { cin >> x[i] >> y[i]; }
  vector<ll> route(n);
  iota(ALL(route), 0);
  ll baai = 0;
  ld temp = 0;
  do {
    baai++;
    repz(i, 1, n) {
      ll now = route[i], bef = route[i - 1];
      ll tempx = x[now] - x[bef];
      ll tempy = y[now] - y[bef];
      tempx *= tempx;
      tempy *= tempy;
      temp += sqrt(tempx + tempy);
    }
  } while (next_permutation(ALL(route)));
  cout << fixed << setprecision(15) << temp / baai << endl;
  return 0;
}


Measured memory_bytes: 384
// Elementary Number Theory - Power
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_B
using System;
using System.Linq;
using System.Collections.Generic;

namespace NTL_1_B {
	class Program {
        const ulong mod = 1000000007;
		public Program() {}
		
		public static void Main() {
			new Program().Calc();
		}
		
		void Calc() {
			var n = Input.Split(' ')
                            .Select(i => ulong.Parse(i))
			                .ToArray();
			Output(power(n[0], n[1]).ToString());
		}
		
		String Input {
			get {
				return Console.ReadLine();
			}
		}
		
		void Output(String str) {
			Console.WriteLine(str);
		}
		
		ulong power(ulong n, ulong m) {
            if(m == 0) return 1;
            ulong tmp = power(n, m / 2) % mod;
            if(m % 2 == 0) return (tmp * tmp) % mod;
            return (((tmp * tmp) % mod) * n) % mod;
		}
	}
}

Measured memory_bytes: 9596
N = int(input())
A = list(map(int, input().split()))

ans = float('inf')
s = sum(A)

x = A[0]
ans = min(ans, abs(2*A[0]-s))

for i in range(1, N-1):
    x += A[i]
    ans = min(ans, abs(2*x-s))

print(ans)

Measured memory_bytes: 24812
import math
a,b = map(int, input().split())
i = 1
while True:
  if math.floor(i*0.08) == a and math.floor(i*0.1) == b:
    print(i)
    break
  if math.floor(i*0.08) > a or math.floor(i*0.1) > b:
    print(-1)
    break
  i += 1

Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int b[n];
    for(int i=0;i<n-1;i++){
        scanf("%d",&b[i]);
    }
    b[n-1]=0;
    int a[n];
    a[0]=b[0];
    int ans=a[0];
    for(int i=1;i<n-1;i++){
        if(b[i-1]<b[i]){
            a[i]=b[i-1];
        }else{
            a[i]=b[i];
        }
        //printf("a[i]->%d\n",a[i]);
        ans += a[i];
    }
    a[n-1]=b[n-2];
    printf("%d\n",ans+a[n-1]);
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

constexpr int Mod = 1000000007;

constexpr int Fma(int a, int b, int c) {
  return (int) (((long long) a * b + c) % Mod);
}

constexpr int Add(int a, int b) { return (a + b) % Mod; }

int N;

struct Mat {
  int A[50][50];
  constexpr int* operator [](int i) { return A[i]; }
  constexpr const int* operator [](int i) const { return A[i]; }
  friend Mat operator *(const Mat& A, const Mat& B) {
    Mat C{};
    for (auto i = 0; i < N; ++i)
      for (auto j = 0; j < N; ++j)
        for (auto k = 0; k < N; ++k)
          C[i][k] = Fma(A[i][j], B[j][k], C[i][k]);
    return C;
  }
};

int main() {
  long long K;
  scanf("%d%lld", &N, &K);
  static Mat A;
  for (auto i = 0; i < N; ++i)
    for (auto j = 0; j < N; ++j)
      scanf("%d", &A[i][j]);
  static Mat X{};
  for (auto i = 0; i < N; ++i)
    X[i][i] = 1;
  while (K) {
    if (K & 1)
      X = X * A;
    A = A * A;
    K >>= 1;
  }
  auto res = 0;
  for (auto i = 0; i < N; ++i)
    for (auto j = 0; j < N; ++j)
      res = Add(res, X[i][j]);
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
int n,m;
int i;
int j=0;
char a[100][10];
char b[105][11];
char c[105][11];
char tmps[10];
int max=0,tmp;
scanf("%d",&n);
for(i=0;i<n;i++)
{scanf("%s",a[i]);};
scanf("%d",&m);
for(i=0;i<m;i++)
{scanf("%s",b[i]);}
for(i=0;i<n;i++)
{tmp=0;
for(j=0;j<n;j++)
{if(strcmp(a[i],a[j])==0)
{tmp+=1;}}
for(j=0;j<m;j++)
{if(strcmp(a[i],b[j])==0)
{tmp-=1;}}
if(tmp>max)
{max=tmp;}}
printf("%d\n",max);
return 0;}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(int argc, char** argv){
    int N;
    string S;
    cin >> N >> S;

    int ans = 1;
    bool flag = false;
    for (int i=1; i<N; i++){
        if (S[i] == S[i-1]){
            if (!flag)
                flag = true;
        } else {
            ++ans;
            if (flag)
                flag = false;
        }
    }

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


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

using namespace std;
using ll = long long;

ll ipow(ll x) {
    return x * x * x;
}

int main() {
    ll N, K; cin >> N >> K;

    if (K > 2 * N) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = ipow(N / K);
    if (K % 2LL == 0) {
        ans += ipow(((N - K / 2LL) / K) + 1LL);
    }

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

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

struct guard {
	vector<bool> cycle;
	int cnt;
};

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

	int g, d;
	while(cin >> g >> d, g|d) {
		vector<guard> v(g);
		REP(i, g) {
			int in, in2 = 1;
			while(cin >> in, in) {
				REP(j, in)
					v[i].cycle.pb(in2);
				in2 = (in2 + 1) % 2;
			}
		}

		queue<int> q;
		set<int> s;
		REP(i, d) {
			REP(j, g) {
				if(v[j].cycle[v[j].cnt % v[j].cycle.size()])
					v[j].cnt++;
				else {
					if(!s.count(j)) {
						q.push(j);
						s.insert(j);
					}
				}
			}
			if(q.size()) {
				int top = q.front();
				v[top].cnt++;
				if(v[top].cycle[v[top].cnt % v[top].cycle.size()]) {
					q.pop(); s.erase(top);
				}
			}
		}
		int ans = 0;
		REP(i, g)
			ans += d - v[i].cnt;
		cout << ans << endl;
	}
	return 0;
}

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

int main(void) {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end(), greater<long long>());

  long long ans = A[0];
  for (long long i = 1, j = 1; i < N - 1; j++) {
    ans += A[j];
    i++;
    if (i < N - 1) {
      ans += A[j];
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4772
#include<stdio.h>
int main() {
  int mat[31][31];
  int k[31];
  int total[31];
  int t;
  int n,m;
  int i,j;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++) {
    scanf("%d",&(k[i]));    
    for(j=0;j<k[i];j++) {
      scanf("%d",&(mat[i][j]));
    }
    for(j=k[i];j<m;j++) {
      mat[i][j]=0;
    }
  }
  for(i=0;i<31;i++) {
    total[i]=0;
  }
  for(i=0;i<n;i++) {
    for(j=0;j<k[i];j++) {
      (total[(mat[i][j])])++;
    }
  }
  t=0;
  for(i=0;i<31;i++) {
    if(n==total[i]) t++;
  }
  printf("%d\n",t);
  return 0;
}


Measured memory_bytes: 128
class Point2d:
    
    def __init__(self, x, y):
        self.x, self.y = x, y

def get3rd(p0, p1):
    return Point2d(p1.x + p0.y - p1.y, p1.y + p1.x - p0.x)

def solution(p0, p1):
    p2 = get3rd(p0, p1)
    p3 = get3rd(p1, p2)
    return p2, p3

def main():
    raw = [int(i) for i in raw_input().strip().split()]
    p2, p3 = solution(Point2d(raw[0], raw[1]), Point2d(raw[2], raw[3]))
    print '%d %d %d %d' % (p2.x, p2.y, p3.x, p3.y)

if __name__ == '__main__':
    main()

Measured memory_bytes: 2568
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
using namespace std;
int a[500010];
int main()
{     long long n,k,i,j,s=0;
      cin>>n>>k;
      for(i=1;i<=n;i++)cin>>a[i];
      sort(a+1,a+n+1);
      for(i=n;i>n-k;i--)s+=a[i];
      cout<<s<<endl;
	  return 0;
}


Measured memory_bytes: 256
$a, $b, $c, $d, $e, $f = gets.split.map(&:to_i)
$a *= 100
$b *= 100

def noudo(water, sugar)
  if sugar.zero?
    0
  else
    Rational(sugar, (water + sugar))
  end
end

$dfshash = {}

def dfs(water, sugar, max)
  return $dfshash[[water, sugar]] if $dfshash[[water, sugar]]
  mn = noudo(max.first, max.last)
  n = noudo(water, sugar)
  max = [water, sugar] if n > mn
  if water + sugar == $f
    return $dfshash[[water, sugar]] = max
  end

  if !sugar.zero? && water / 100 * $e == sugar
    puts "#{water + sugar} #{sugar}"
    exit
  end
  d1 = d2 = d3 = d4 = [water, sugar]
  if water + $c + sugar <= $f && water/100 * $e >= sugar + $c
    d3 = dfs(water, sugar + $c, max.dup)
  end
  if water + $d + sugar <= $f && water/100 * $e >= sugar + $d
    d4 = dfs(water, sugar + $d, max.dup)
  end
  if water + $a + sugar <= $f
    d1 = dfs(water + $a, sugar, max.dup)
  end
  if water + $b + sugar <= $f
    d2 = dfs(water + $b, sugar, max.dup)
  end
  [d1, d2, d3, d4].each do |d|
    max = d if noudo(d.first, d.last) > noudo(max.first, max.last)
  end
  $dfshash[[water, sugar]] = max
end

max = [0, 0]
ans = dfs(0, 0, max)

ans[0] = $a if ans.first.zero?
puts "#{ans.first + ans.last} #{ans.last}"


Measured memory_bytes: 3836
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var r = cin.ReadInt;
            var g = cin.ReadInt;
            var b = cin.ReadInt;
            if((g * 10 + b) % 4 == 0)
            {
                WriteLine("YES");
            }
            else
            {
                WriteLine("NO");
            }
        }
        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

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

int main(){
    int n,k;cin>>n>>k;
    vector<int> dp(k+1,0);
    set<int> s;
    for(int i=0,x;i<n;i++){
        cin>>x;
        s.insert(x);
    }
    for(int i=1;i<=k;i++){
        for(auto j : s){
            if(i-j<0) break;
            if(dp[i-j]==0) {dp[i]=1;break;}
        }
    }
    if(dp[k]==0) cout<<"Second\n";
    else cout<<"First\n";
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int a[210000],l[210000],r[210000];
int n;
long long ans;
int main(void)
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        l[i]=i+a[i];
        r[i]=i-a[i];
    }
    sort(l+1,l+1+n);
    sort(r+1,r+1+n);
    int head1=1,head2=1,x=0;
    while(head1<=n)
    {
        if(l[head1]==l[head1-1])
        {
            ans+=x;
            head1++;
            continue;
        }
        else x=0;
        while(r[head2]<=l[head1]&&head2<=n)
        {
            if(r[head2]==l[head1])x++;
            head2++;
        }
        ans+=x;
        head1++;
    }
    cout<<ans<<endl;
    return 0;
}

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

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

    int s10 = 0;
    for (int i = 0; i < S.size(); ++i)
    {
        if(i%2 ==0 and S[i]=='0'){
            ++s10;
        }else if(i%2 == 1 and S[i] =='1'){
            ++s10;
        }
    }

    int s01=0;
    for (int i = 0; i < S.size(); ++i)
    {
        if (i % 2 == 0 and S[i] == '1')
        {
            ++s01;
        }
        else if (i % 2 == 1 and S[i] == '0')
        {
            ++s01;
        }
    }

    cout << min(s10, s01) << endl;

    return 0;
}

Measured memory_bytes: 512
N, K = [int(elem) for elem in input().split()]

if K > (N - 2) * (N - 1) // 2:
    print(-1)
    exit(0)

num_edges_to_delete = K
available_edges = N * (N - 1) // 2 - K

center_node = N
trivial_edges = [(i, j) for i in range(1, N) for j in range(i + 1, N)]

print(available_edges)
for u, v in trivial_edges[num_edges_to_delete:]:
    print(u, v)

for u in range(1, N):
    print(u, center_node)


Measured memory_bytes: 43504
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;

int N;
string S;
vector<int> B;
int MOD = 1e9 + 7;

void solve() {
	cin >> N >> S;
	B.resize(2 * N);
	if (S[0] == 'W') {
		cout << 0 << endl;
		return;
	}
	B[0] = 1;
	long long lc = 1;
	for (int n = 1; n < 2 * N; n++) {
		if (S[n] == S[n - 1])B[n] = 1 - B[n - 1];
		else B[n] = B[n - 1];
		lc += B[n];
	}
	if (lc != N) {
		cout << 0 << endl;
		return;
	}
	lc = 0;
	long long ans = 1;
	for (int n = 0; n < 2 * N; n++) {
		if (B[n] == 1)lc++;
		else {
			ans *= lc;
			ans %= MOD;
			lc--;
		}
	}
	for (int n = 2; n <= N; n++) {
		ans *= n;
		ans %= MOD;
	}
	cout << ans << endl;
	return;
}

//////////////////////////////
//////////////////////////////

int main() {
#ifdef DEBUGTIME
	for (int time = 0; time < DEBUGTIME; time++) {
		solve();
		cout << "####################" << endl;
	}
#else
	solve();
#endif
	return 0;
}

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

using namespace std;

const double Pi = acos(-1);

int main(){
    double a,b,c;
    double S,L,h;
    cin >> a >> b >> c;
    S = 0.5 * a * b * sin(c/180*Pi);
    double d = sqrt(a*a+b*b-2*a*b*cos(c/180*Pi));
    L = a+b+d;
    h= 2*S/a;
    printf("%.8f\n",S);
    printf("%.8f\n",L);
    printf("%.8f\n",h);
    
}


Measured memory_bytes: 3468
n=int(input())

lim_keta=len(str(n))

def dfs(keta,num):
  global cnt
  if keta==lim_keta:
    if int(num)<=n and len(set(num))==3:
      cnt+=1
    return
  if len(set(num))==3:
    cnt+=1
  for i in '753':
    dfs(keta+1,num+i)

cnt=0
for i in '753':
  dfs(1,i)

print(cnt)

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

#define clr(i, j)     memset(i, j, sizeof(i))
#define pb            push_back
#define mp            make_pair
typedef long long     ll;
bool kk=true;
//map<int,int>r;int arr[100000];
bool rr[3];
int main()

{
   /*
int n,m,k;   cin>>n>>m>>k;

for(int r=0;r<n;r++){

       cin>>a[r];

}
for(int r=0;r<n;r++){
for(int dd=0;dd<n;dd++){


       }

}*/
int n,m;
cin>>n>>m;
if(max(n,m)>8){cout<<":(";}else{

    cout<<"Yay!";
}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
const int N = 1000000;

template<typename T> inline void chmin(T& t, T f){if(t > f)t = f;}

vector<int> mem1, mem2;

void calc(vector<int>& v, vector<int>& mem){
    mem.resize(N); iota(all(mem), 0);
    rep(i, N)for(auto j: v){
        if(i < j)break;
        chmin(mem[i], mem[i-j]+1);
    }
}

void init(){
    vector<int> num, odd;
    for(int i=1, x=1; x<N; ++i, x=i*(i+1)*(i+2)/6){
        num.push_back(x);
        if(x&1)odd.push_back(x);
    }
    calc(num, mem1);
    calc(odd, mem2);
}

int main(){
    init();
    int n;
    while(cin >> n, n)cout << mem1[n] << ' ' << mem2[n]<< '\n';
    return 0;
}

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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    int z = sc.nextInt();
    int k = sc.nextInt();
    long[] a = new long[x];
    long[] b = new long[y];
    long[] c = new long[z];
    for (int i = 0; i < x; i++) {
      a[i] = sc.nextLong();
    }
    for (int i = 0; i < y; i++) {
      b[i] = sc.nextLong();
    }
    for (int i = 0; i < z; i++) {
      c[i] = sc.nextLong();
    }
    Main abc123D = new Main();
    for (long i : abc123D.solve(a, b, c, k)) {
      System.out.println(i);
    }
  }

  public long[] solve(long[] a, long[] b, long[] c, int k) {
    Arrays.sort(a);
    Arrays.sort(b);
    Arrays.sort(c);
    int index = 0;
    long[] ab = new long[Math.min(k, a.length) * Math.min(k, b.length)];
    for (int i = Math.max(0, a.length - k); i < a.length; i++) {
      for (int j = Math.max(0, b.length - k); j < b.length; j++) {
        ab[index] = a[i] + b[j];
        index += 1;
      }
    }
    Arrays.sort(ab);
    index = 0;
    long[] abc = new long[Math.min(k, ab.length) * Math.min(k, c.length)];
    for (int i = Math.max(0, ab.length - k); i < ab.length; i++) {
      for (int j = Math.max(0, c.length - k); j < c.length; j++) {
        abc[index] = ab[i] + c[j];
        index += 1;
      }
    }
    Arrays.sort(abc);
    long[] ans = new long[k];
    index = 0;
    for (int i = abc.length - 1; i >= Math.max(abc.length - k, 0); i--) {
      ans[index] = abc[i];
      index += 1;
    }
    return ans;
  }
}


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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


int main() {
    int n;
    cin >> n;
    vector<ll> numbers(n);
    rep(i, n) cin >> numbers[i];

    vector<ll> ps(n);
    {
        int t = 2;
        ps[0] = 1;
        for (int i = 1; i < n; i++) {
            ps[i] = t;
            if (numbers[i] == t) {
                t++;
            }
        }
    }

    vector<ll> ans_list(n);
    rep(i, n) {
        if (numbers[i] % ps[i] == 0) ans_list[i] = numbers[i] / ps[i] - 1;
        else ans_list[i] = numbers[i] / ps[i];
    }

    ll ans = accumulate(ans_list.begin(), ans_list.end(), 0ll);
    cout << ans << endl;

}


Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>
#define Max(x,y) ((x>y)?x:y)
int a[105],b[105],c[105],d[105],w[105];

int gcd(int x,int y){
	return (y==0)?(x):(gcd(y,x%y));
}
int lcm(int x,int y){
	return x/gcd(x,y)*y;
}

int func(int n){
	if(w[n]>0)return w[n];
	//int x=gcd(func(c[n])*a[n],func(d[n])*b[n]);
	//w[n]=func(c[n])*func(d[n])*(a[n]+b[n])/x;
	
	int x=lcm(func(c[n])*a[n],func(d[n])*b[n]);
	//w[n]=func(c[n])*func(d[n])*a[n]/x+func(c[n])*func(d[n])*b[n]/x;
	w[n]=x/a[n]+x/b[n];
	
	return w[n];
}
int main(){
	int i,j,n,ans=0;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		memset(w,-1,sizeof(w));
		w[0]=1;
		for(i=1;i<=n;i++)
			scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
		ans=0;
		for(i=1;i<=n;i++)ans=Max(ans,func(i));
		printf("%d\n",ans);
	}
	
	return 0;
}

Measured memory_bytes: 0