akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int N;

int main(void) {
    cin>>N;

    string s;
    int A = 0;
    int B = 0;
    int d = 0;

    Int sum = 0;
    for(int i = 0;i < N;i++) {
        cin>>s;
        for(int j = 0;j < s.size()-1;j++) {
            if(s[j]=='A' && s[j+1] == 'B')
                sum++;
        }
        if(s[s.size()-1] == 'A' && s[0] != 'B')
            A++;
        if(s[0] == 'B' && s[s.size()-1] != 'A')
            B++;

        if(s[s.size()-1] == 'A' && s[0] == 'B')
            d++;
    }

    int ans = 0;
    if(d == 0) {
        ans = min(A,B);
    } else if(A+B > 0) {
        ans = d + min(A,B);;
    } else {
        ans = d - 1;
    }


    cout<<sum+ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define LI long int
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
using namespace std;
//
const int INF=1e9+7;
const int LINF=1e18;
const int MOD=1e9+7;
//
int main(){
    int n; cin>>n;
    int k=n%8;
    int d[8][4]={{1,1,1,1},{1,0,1,0},{1,0,1,0},{0,0,1,1},{0,1,1,0},{0,1,1,1},{1,1,1,0},{1,1,1,0}};
    //int a[8]={0,2,2,2,1,1,1,1};
    //n-=a[k];
    int s[4]={2,3,4,6};
    int p=0;
    if(n==3){
        cout<<"2 5 63";
        exit(0);
    }
    FOR(i,0,4){
        if(d[k][i]){
            cout<<s[i]<<" ";
            p++;
        }
    }
    FOR(i,0,n/4+1){
        FOR(j,0,4){
            if(p>=n){
                break;
            }else{
                p++;
                cout<<s[j]+6*(i+1)<<" ";
            }
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define INFTY 1 << 21
int x[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int y[8] = {1, 0, -1, 1, -1, 1, 0, -1};

int main() {
  int h, w;
  cin >> h >> w;
  char board[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> board[i][j];
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int cnt = 0;
      if (board[i][j] == '.') {
        for (int n = 0; n < 8; n++) {
          if (((i + y[n] >= 0 && i + y[n] < h) &&
               (j + x[n] >= 0 && j + x[n] < w)) &&
              board[i + y[n]][j + x[n]] == '#') {
            cnt++;
          }
        }
        cout << cnt;
      } else {
        cout << '#';
      }
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#define INF 1001001001001001001
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;


int main() {
	int n;
	long long int k;
	cin >> n >> k;
	vector<long long int>a(n + 1);
	a[0] = 0;
	long long int x;
	rep(i, 0, n) {
		cin >> x;
		a[i + 1] = (a[i] + x) % k;
	}
	long long int uns_i;
	rep(i, 0, n + 1) {
		uns_i = i % k;
		a[i] = (a[i] - uns_i + k) % k;
	}
	long long int ans = 0;
	map<int, int>m;
	rep(i, 0, n + 1) {
		if (i >= k) m[a[i - k]]--;
		ans += m[a[i]];
		m[a[i]]++;
	}
	cout << ans << endl;
}


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

int main() {
  int N;
  std::cin >> N;
  std::vector<char> c(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> c[i];
  }

  int count = 0;
  int w = 0, r = N - 1;
  while(true) {
    for (int i = w; i < N; ++i) {
      w = i;
      if (c[i] == 'W') {
        break;
      }
    }
    for (int j = r; j >= 0; --j) {
      r = j;
      if (c[j] == 'R') {
        break;
      }
    }
    if (w >= r) break;
    else {
      // c[i] = 'R';
      // c[j] = 'W';
      w++;
      r--;
      count++;
    }
  }

  std::cout << count << std::endl;
  return 0;
}


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

int A[5050];
int L[5050][5050];
int R[5050][5050];

int main(){
    
    int N, K;
    cin >> N >> K;
    for(int i = 1; i <= N; i++)cin >> A[i];
    L[0][0] = 1;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= 5000; j++){
            L[i][j] |= L[i - 1][j];
            if(j - A[i] >= 0)L[i][j] |= L[i - 1][j - A[i]];
        }
    }
    R[N + 1][0] = 1;
    for(int i = N; i >= 1; i--){
        for(int j = 0; j <= 5000; j++){
            R[i][j] |= R[i + 1][j];
            if(j - A[i] >= 0)R[i][j] |= R[i + 1][j - A[i]];
        }
    }
    int ans = 0;
    for(int i = 1; i <= N; i++){
        if(A[i] >= K)continue;
        int f = 1;
        set<int>S;
        for(int r = 0; r < K; r++)if(R[i + 1][r])S.insert(r);
        S.insert(K);
        for(int l = 0; l < K; l++){
            if(L[i - 1][l] == 0)continue;
            int mn = *S.lower_bound(K - A[i] - l);
            if(mn < K - l){
                f = 0;
                break;
            }
        }
        if(f)ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 199168
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    char a[] = new char[100];
    int count = 0;
    for(int i=0 ; i<s.length() ; i++){
      a[i] = s.charAt(i);
    }
    for(int i=0 ; i<s.length()/2 ; i++){
      if(a[i]==a[s.length()-1-i]){
        continue;
      }else{
        count++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 23636
// fuck rating
// experience matters

#include <bits/stdc++.h>

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

#define ll long long
#define ld long double
#define pb push_back
#define mkpr make_pair
#define fi(i,a,b) for (int i=a;i<b;i++)
#define vll vector<ll>
#define vch vector<char>
#define vst vector<string>
#define vpll vector<pll>
#define vii vector<int>
#define vvl vector<vector<ll>>
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(), v.rend())
#define mxe(v) *max_element(v.begin(),v.end())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define mll map<ll, ll>
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)
#define nl "\n"
#define sp " "
#define sz(x)  (int)x.size()

using namespace std;

double PI = (acos(-1));
ll md = 1000000007;
//ll md = 998244353;
ll pw(ll a, ll b){ll c=1,m=a;while (b){if (b&1)c=(c*m);m=(m*m);b/=2;}return c;}
ll pwmd(ll a, ll b){ll c = 1, m = a;while (b){if (b & 1)c = ((c * m)) % md;m = (m * m) % md;b /= 2;}return c;}
ll modinv(ll n){return pwmd(n, md - 2);}
ll nc2(ll n){return (1ll * n * (n - 1)) / 2;}
ll nsum(ll n){return (1ll * n * (n + 1)) / 2;}
bool prime(ll a){for(int i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ceel(ll a,ll b){if(a%b==0) return a/b;else return a/b+1;}


#define MAX_SIZE 1005
void Sieve(vector<int> &primes){bool IsPrime[MAX_SIZE];memset(IsPrime, true, sizeof(IsPrime));
for (int p = 2; p * p < MAX_SIZE; p++){if (IsPrime[p] == true){
            for (int i = p * p; i < MAX_SIZE; i += p)IsPrime[i] = false;}}
    for (int p = 2; p < MAX_SIZE; p++)if (IsPrime[p])primes.push_back(p);}
        


vector<char> sml={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char> cap={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};



//---------VIPUL SHARMA----------\\


void solve(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(max(a*d,a*c),max(b*c,b*d));
}



int main(){
    //vector<int> primes;
    //Sieve(primes);

    fast
    ll tests=1;
    //cin>>tests;
    while(tests--){
        solve();
    }
    
    return 0;
}










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

int main() {
    ll h,w;cin>>h>>w;
    ll ans=1e9;
    for (int i=0;i<2;i++) {
        for (int j=1;j<h;j++) {
            int hh=h-j;
            int hhh=hh/2;
            int hhhh=hh-hhh;
            ll mx=max(j,max(hhh,hhhh));
            ll mn=min(j,min(hhh,hhhh));
            ans=min(ans,mx*w-mn*w);
            ll ww=w/2;
            ll www=w-ww;
            mx=max(j*w,max(ww*hh,www*hh));
            mn=min(j*w,min(ww*hh,www*hh));
            ans=min(ans,mx-mn);
        }
        swap(h,w);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n+2, 0);
    for (int i = 0; i < m; ++i) {
        int l, r;
        cin >> l >> r;
        a[l]++;
        a[r+1]--;
    }

    int x = 0;
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        x += a[i];
        if (x == m) ans++;
    }

    cout << ans << endl;

    return 0;
}


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

struct UnionFind{
  vector<int> par;

  UnionFind(int N) : par(N){
    for(int i=0;i<N;i++) par[i] = i;
  }

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

  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

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

  vector<int> count(N);
  for(int i=0;i<N;i++) count[i] = 1;
  UnionFind road(N);
  UnionFind train(N);

  for(int i=0;i<K;i++){
    int p,q;
    cin >> p >> q;
    road.unite(p-1,q-1);
  }
  for(int i=0;i<L;i++){
    int r,s;
    cin >> r >> s;
    train.unite(r-1,s-1);
  }

  map<pair<int, int>, int> cnt;
  for(int i=0;i<N;i++){
    cnt[make_pair(road.root(i),train.root(i))] += 1;
  }
  for(int i=0;i<N;i++){
    if(i) printf(" ");
    printf("%d",cnt[make_pair(road.root(i),train.root(i))]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set;

#define     int                 ll
#define     pb                  push_back
#define     mp                  make_pair
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     init(x, a)          memset(x, a, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     cpy(a,b)            memcpy(a,b,sizeof(b))
#define     is(a)               to_string(a)
#define     ci(a,c)             a-c
#define     db(i)               cout<<"point :"<<i<<'\n';
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

const int MAXN = 2e5+10;
int adj[MAXN];
vi path;
int loop=-1;
bool f = 0;

void dfs(bool vis[], int v){
	path.pb(v);
	vis[v]=1;
	if(adj[v]==v){
		f=1;
		return;
	}
	if(!vis[adj[v]]){
		dfs(vis,adj[v]);
	}
	else{
		loop=adj[v];
	}
}

void solve(){
    int n,k,val; cin>>n>>k;
    for(int i = 1; i <= n; ++i){
    	cin>>adj[i];
    }
    bool vis[n+1];
    clr(vis);
    dfs(vis, 1);
    if(k<path.size()){
    	cout<<path[k]<<'\n';
    }
    else{
    	if(f){
    		cout<<path[path.size()-1]<<'\n';
    	}
    	else{
    		int loop_ind;
    		for(int i = 0; i < path.size(); ++i){
    			if(path[i]==loop){
    				loop_ind=i;
    				break;
    			}
    		}
    		k-=path.size()-1;
    		k%=(path.size()-loop_ind);
    		if(k==0){
    			cout<<path[path.size()-1]<<'\n';
    		}
    		else{
    			cout<<path[loop_ind+k-1]<<'\n';
    		}
    	}
    }
}

signed main() { 
    IO();
    
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0; 
}

Measured memory_bytes: 12736
import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
n=int(input())
a= list(map(int, input().split()))
ans=1
if 0 in a:
    print(0)
    sys.exit()
for i in range(n):
    ans*=a[i]
    if ans>10**18:
        print(-1)
        sys.exit()

print(ans)

Measured memory_bytes: 87732
#include <stdio.h>

int neighbors[105][105];
int times[105][2];
int n;

int dfs(int curTime, int node) {
  int i, j;

  times[node][0] = curTime;
  neighbors[node][0] = 0;

  for (i = 1; i < n + 1; i++) {
    if (neighbors[node][i] && neighbors[i][0]) {
      curTime = dfs(curTime + 1, i);
    }
  }

  times[node][1] = ++curTime;
  return curTime;
}


int main() {
  int i, u, k, j, num, timestamp = 0;

  memset(neighbors, 0, sizeof(neighbors));
  memset(times, 0, sizeof(times));

  scanf("%d", &n);

  for (i = 1; i < n + 1; i++) {
    neighbors[i][0] = 1;
  }


  for (i = 1; i < n + 1; i++) {
    scanf("%d %d", &u, &k);

    for (j = 0; j < k; j++) {
      scanf("%d", &num);
      neighbors[i][num] = 1;
    }
  }

  for (i = 1; i < n + 1; i++) {
    if (neighbors[i][0])
      timestamp = dfs(timestamp + 1, i);
  }

  for (i = 1; i < n + 1; i++)
    printf("%d %d %d\n", i, times[i][0], times[i][1]);
}



Measured memory_bytes: 2124
n = int(input())
d = input().split()
m = int(input())
t = input().split()

dic = dict()

for di in d:
    if di in dic:
        dic[di] += 1
    else:
        dic[di] = 1

ans = "YES"
for ti in t:
    if ti not in dic or dic[ti] == 0:
        ans = "NO"
        break
    else:
        dic[ti] -= 1

print(ans)

Measured memory_bytes: 53604
#include<stdio.h>
int main(void)
{
	int a,b,x,y,z,k;
	scanf("%d %d",&a,&b);
	x=a+b;
	y=a-b;
	z=a*b;
	k=x;
	if(y>k)k=y;
	if(z>k)k=z;
	printf("%d\n",k);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    int n, x;
    int i, j, k;
    int time = 0;
    
    while(1){
        time = 0;
      cin >> n >> x ;
      if (n == 0 && x == 0) {
        return 0;
      }
      
      for(i = 1; i < n - 1; i++) {
        for(j = i+1; j < n; j++) {
          for(k = j+1; k < n + 1; k++) {
            if(i+j+k == x){
                time++;
            }
          }
        }
      }
      cout << time << endl;
    }
}


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

int main(){
  string S;
  cin >> S;
  set<char> s;
  for(int i=0;i<S.size();i++){
    s.insert(S.at(i));
  }
  if(s.size()==26){
    set<char> b;
    for(int i=S.size()-1;i>=0;i--){
      for(char j=S.at(i)+1;j<='z';j++){
        if(b.count(j)){
          S.at(i)=j;
          S.erase(S.begin()+i+1,S.end());
          cout << S << endl;
          return 0;
        }
      }
      b.insert(S.at(i));
    }
    cout << -1 << endl;
    return 0;
  }
  for(char i='a';i<='z';i++){
    if(!s.count(i)){
      S+=i;
      break;
    }
  }
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

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

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef pair<int, ii> edge;


#define sc(x)  scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i,end) for(int i=0; i<end; i++)
#define rlop(i,start) for(int i=start-1; i>=0; i--)
#define loop(i,start,end) for(int i=start; i<end; i++)
#define rloop(i,start,end) for(int i=start-1; i>=end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second

const ll OO = (4e18) + 9;
const int MOD = (1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);

//enum dir { r, d, l, u };
int dx[] = { 0, 1, 0,-1 };
int dy[] = { 1, 0,-1, 0 };

//enum diR { d, r, u, l , dr, ur, dl, ul };
int dX[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dY[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiou"; //and sometimes "aeiouy"

int dcmp(ld d1, ld d2) { return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1; } //Compare Double Numbers
ll gcd(ll x, ll y) { return !y ? x : gcd(y, x%y); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
//convert index from 2D matrix to 1D array. (Zero-indexed)
int ord(int r, int c, int nCol) { return (nCol*r) + c + 1; }
//convert index from 1D array to 2D matrix . (One-indexed)
ii rord(int n, int nCol) {
	int r = n%nCol, c = n / nCol;
	if (n%nCol == 0) c--, r = nCol;
	return ii(r, c);
}

ll poww(ll num, ll p, ll md = MOD) {
	num %= md;
	ll ret = 1;
	while (p > 0) {
		if (p & 1) ret = (ret * num) % md;
		num = (num * num) % md;
		p >>= 1;
	}
	return ret;
}

ll nCr(ll n, ll r) {
	if (n < r)
		return 0;
	if (r == 0)
		return 1;
	return n * nCr(n - 1, r - 1) / r;
}

const int N = 1e5 + 10;
ll dp[N], h[N];
int n, k;
ll solve(int idx) {
	if (idx == n-1) return 0;
	if (dp[idx] != -1) return dp[idx];
	dp[idx] = OO;
	for (int i = 1; i <= min(k, n - idx-1); i++) {
		dp[idx] = min(dp[idx], abs(h[idx] - h[idx + i]) + solve(idx + i));
	}
	return dp[idx];
}


int main()
{
#ifndef ONLINE_JUDGE

#else
	//freopen("pyramid.in", "r", stdin);
#endif
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> k;
	lop(i, n) cin >> h[i];
	mem(dp, -1);
	cout << solve(0) << endl;



	return 0;
}


Measured memory_bytes: 6528
n = int(input())
a = list(map(int, input().split()))

last  = 0
count = 0
flag  = True

while flag:
    flag = False
    for i in range( n-1, last, -1 ):
        if a[i] < a[i-1]:
            t = a[i]
            a[i] = a[i-1]
            a[i-1] = t
            count += 1
            flag = True
    last += 1

print(*a)
print(count)

Measured memory_bytes: 7724
using System;
class Program {
    static void Main (string[] args) {
        string[] input = Console.ReadLine ().Split (' ');
        int k = int.Parse(input[0]);
        int n = int.Parse(input[1]);
        string[] input2 = Console.ReadLine ().Split (' ');
        int max = 0;
        for (int i = 0; i < n - 1; i++) {
            if (max < int.Parse(input2[i + 1]) - int.Parse(input2[i])) {
                max = int.Parse(input2[i + 1]) - int.Parse(input2[i]);
            }
        }
        if (max < k - int.Parse(input2[n - 1]) + int.Parse(input2[0])) {
            max = k - int.Parse(input2[n - 1]) + int.Parse(input2[0]);
        }
        Console.WriteLine(k - max);
    }
}


Measured memory_bytes: 30940
s = list(str(input()))

count_0 = 0
count_1 = 0
for i in range(0, len(s)):
    if s[i] == "0":
        count_0 += 1
    if s[i] == "1":
        count_1 += 1

if count_0 >= count_1:
    print(count_1*2)
else:
    print(count_0*2)

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;


int main() {
    int N; cin >> N ;
    vi b(N);
    rep(i, N) cin >> b[i];
    list<int> l;
    bool f;

    while (!b.empty()) {
        f = false;
        int n = b.size();
        for (int i = n - 1 ; i >= 0; i--) {
            if (b[i] == i + 1) {
                l.push_front(b[i]);
                b.erase(b.begin() + i);
                f = true;
                break;
            }
        }
        if (!f) break;
    }

    if (!b.empty()) cout << -1 << endl;
    else {
        for (auto x : l) {
            cout << x << endl;
        }
    }



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}
void solve(){
    int n;
    read(n);
    vi a(n);
    REP(i,n) cin >> a[i];
    ll sum = 0;
    for(int i = 1; i < n ; i++){
        if( a[i] < a[i-1]){
            sum += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }
    cout << sum << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}


Measured memory_bytes: 3988
use proconio::input;
use proconio::marker::Chars;
use std::collections::HashMap;
use std::cmp::min;

fn main() {
    input! {
        n: usize,
        s: [Chars; n],
    }
    let a_z = "abcdefghijklmnopqrstuvwxyz";
    let mut counts = vec![a_z.chars().map(|c| (c, 0)).collect::<HashMap<_, _>>(); n];

    for i in 0..s.len() {
        for c in &s[i] {
            *counts[i].entry(*c).or_insert(0) += 1;
        }
    }

    for c in a_z.chars() {
        let mut counter = 51;
        for map in &counts {
            counter = min(counter, *map.get(&c).unwrap());
        }
        for _ in 0..counter {
            print!("{}", c);
        }
    }
    println!("");
}

Measured memory_bytes: 2164
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;


int v[1010]={0};
int w[1010]={0};
int dp[1010][10010]={{0}};
int n,W;
int main(){
	cin>>n>>W;
	 for(int i =0;i <n;i++){
		cin>>v[i]>>w[i];
	}
	
	for(int i =0;i < n;i++){
		for(int j =0;j <=W;j++){
			if(j-w[i]>=0){
				dp[i+1][j]=max(dp[i][j], dp[i][j-w[i]]+v[i]);
			}else{
				dp[i+1][j]=dp[i][j];
			}

		}

	}

	cout <<dp[n][W]<<endl;
	return 0;
}

Measured memory_bytes: 5220
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    set<ll> s;
    ll n,k;
    cin>>n>>k;
    ll ans = n-k+1;
    ll m = 0;
    vector<ll> data(n);
    FOR(i,0,n) cin>>data[i];
    FOR(i,0,k){
        s.insert(data[i]);
        m = max(m,data[i]);
    }
    FOR(i,k,n){
        ll hd = i - k;
        ll hd_d = data[hd];
        ll tl = i;
        ll tl_d = data[tl];
        s.insert(tl_d);
        if(*s.begin() == hd_d && *s.rbegin() == tl_d) ans--;
        s.erase(hd_d);
    }
    vector<ll> c(n);
    ll res = -1;
    FOR(i,1,n){
        if(data[i]>data[i-1]) c[i] = c[i-1] + 1;
        if(c[i] == k - 1) res++;
    }
    res = max(res,(ll)0);
    cout<<ans-res<<endl;

}

Measured memory_bytes: 12800
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        long res = a[n-1];

        PriorityQueue<Interval> q = new PriorityQueue<>();
        q.offer(new Interval(a[n-2], a[n-1]));
        q.offer(new Interval(a[n-2], a[n-1]));
        for(int i = n-3; i>=0; i--) {
            Interval v = q.poll();
            res += v.min();
            q.offer(new Interval(v.a, a[i]));
            q.offer(new Interval(v.b, a[i]));
        }
        System.out.println(res);

    }

    static class Interval implements Comparable<Interval> {
        int a;
        int b;
        Interval(int a, int b) {
            this.a = a;
            this.b = b;
        }
        int min() {
            return Math.min(a, b);
        }
        @Override public int compareTo(Interval o) {
            return o.min() - min();
        }
    }




}

Measured memory_bytes: 63188
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;


int main()
{
	int count;

	cin >> count;

	int *s = new int[count];

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

	for (int k = 0; k < count; k++)
	{
		cout << (k ? " " : "") << s[k];
	}

	cout << endl;

	

	for (int i = 1; i < count; i++)
	{
		int v = s[i];
		int j = i - 1;
		while (j >= 0 && s[j] > v)
		{
			s[j + 1] = s[j];
			j--;
		}

		s[j + 1] = v;

		for (int k = 0; k < count; k++)
		{
			cout << (k ? " " : "") << s[k];
		}

		cout << endl;
	}
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
const int N=100;
const int M=1e6;
int b[N];
int a[N];
int main()
{
	int n;
	while (cin>>n)
	{
		memset(b,0,sizeof(b));
		for (int i=0;i<=n;i++)
			a[i]=M;
		for (int i=0;i<n-1;i++)
			cin>>b[i];
		for (int i=0;i<n-1;i++)
		{
			a[i]=min(b[i],a[i]);
			a[i+1]=min(b[i],a[i+1]);
		}
		long long sum=0;
		for(int i=0;i<n;i++)
			sum+=a[i];
		cout<<sum<<endl;
				
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b;
	char n;
	scanf("%d",&a);
	getchar();
	scanf("%c",&n);
	scanf("%d",&b);
	if(n=='+')
		printf("%d",a+b);
	else
		printf("%d",a-b);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    int n, m;
    cin >> n >> m;
    cout << (n-1)*(m-1) << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		int[] t = new int[n];
		for(int i=0; i<n; i++) {
			t[i] = sc.nextInt(); x[i] = sc.nextInt(); y[i] = sc.nextInt();
		}
		int nowx = 0; int nowy = 0; int nowt = 0;
		for(int i=0; i<n; i++) {
			int d = Math.abs(nowx-x[i])+Math.abs(nowy-y[i]);
			int dt = t[i]-nowt;
			if(d<=dt && (d-dt)%2==0) {
				nowx = x[i]; nowy = y[i]; nowt = t[i];
			} else {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
	
	static int binarySearch(int[] A, int x) {
		int l = 0;
		int r = A.length;
		while(l<r) {
			int mid = (l+r)/2;
			if(A[mid] == x) return mid;
			else if(x<A[mid]) r = mid;
			else l = mid+1;
		}
		return -1;
	}
	
	static long upper_bound(int[] A, int b) {
		// bよりおおきい値がはじめて出てくるindexを返す
		return lower_bound(A, b+1);
	}

	static long lower_bound(int[] A, int b) {
		// b以上の値がはじめて出てくるindexを返す
		int lb=0;
		int ub=A.length;
		while(ub>lb) {
			int mid = (lb+ub)/2;
			if(A[mid]>=b) ub = mid;
			else lb = mid+1;
		}
		return lb;
	}
	
	// union find lib
	// usage:
	// 最初にinitを呼ぶ
	// root: 直接は呼ばないで
	// unite: まとめる
	// same: グループ判定
	static void init(int par[], int N) {
		for(int i=0; i<N; i++) {
			par[i] = i;
		}
	}
	
	static int root(int x, int [] par) {
		if(par[x] == x) {
			return x;
		} else {
			return (par[x] = root(par[x], par));
		}
	}
	
	static boolean same(int x, int y, int[] par) {
		return root(x, par) == root(y, par);
	}
	
	static void unite(int x, int y, int[] par) {
		x = root(x, par);
		y = root(y, par);
		if(x == y) return;
		par[x] = y;
	}
	
	// end union find lib
	
	// number lib
	
	static int max(int...ls) {
		int ans = Integer.MIN_VALUE;
		for(int i=0; i<ls.length; i++) {
			ans = Math.max(ans, ls[i]);
		}
		return ans;
	}
	
	static int min(int...ls) {
		int ans = Integer.MAX_VALUE;
		for(int i=0; i<ls.length; i++) {
			ans = Math.min(ans, ls[i]);
		}
		return ans;
	}
	
	static long lcm(long a, long b) {
		return a*(b/gcd(a, b));
	}
	
	static long gcd(long a, long b) {
		long ta = Math.max(a, b);
		long tb = Math.min(a, b);
		long tmp;
		while((tmp = ta%tb) != 0) {
			ta = tb;
			tb = tmp;
		}
		return tb;
	}
	
	static long modcomb(long n, long k, long mod) {
		if(k==1) {
			return n;
		}
		
		long ans = 1;
		for(long i=n; i>=n-k+1; i--) {
			ans = (ans * i)%mod;
		}
		for(long i=k; 0<i; i--) {
			ans = (ans * modpow(i, mod-2, mod)) % mod;
		}
		return ans;
	}
	
	static long modpow(long a, long b, long mod) {
		if(b==0) return 1;
		if(b%2==0) {
			long d = modpow(a, b/2, mod);
			return (d*d)%mod;
		} else {
			return (a*modpow(a, b-1, mod))%mod;
		}
	}
	
	static int disit(long a, long d) {
		int count = 0;
		while(a!=0) {
			a = a/d;
			count++;
		}
		return count;
	}
	
	// end number lib
}

Measured memory_bytes: 91680
#include <stdio.h>

int main(){
  int n, fd[6] = {}, i, j;
  double height;

  scanf("%d", &n);
  while(n--){
    scanf("%lf", &height);
    if(height >= 185.0) fd[5]++;
    else if(height >= 180.0) fd[4]++;
    else if(height >= 175.0) fd[3]++;
    else if(height >= 170.0) fd[2]++;
    else if(height >= 165.0) fd[1]++;
    else fd[0]++;
  }

  for(i = 0;i < 6;i++){
    printf("%d:", i + 1);
    for(j = 0;j < fd[i];j++)
      putchar('*');
    puts("");
  }
  return 0;
}

Measured memory_bytes: 648
r, c = map(int, input().split())

sr = []

for i in range(r):
  row = [i for i in map(int, input().split())]
  row.append(sum(row))
  print(' '.join(map(str, row)))
  sr = row if i == 0 else [sr[i] + row[i] for i in range(c + 1)]

print(' '.join(map(str, sr)))



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

int main()
{
    int n;
    cin >> n;
    while(n > 0)
    {
        if(n % 4 == 0 || n % 7 == 0) return cout << "Yes\n" ,0;
        else n -= 7;
    }
    cout << "No\n";
}

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

int main(){
  int A, B, K;
  cin >> A >> B >> K;
  
  for(int i=max(A,B); i>0; i--){
    if(A%i==0 && B%i==0){
      K--;
      if (K==0) cout << i << endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <typeinfo>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    ll s, w;

    cin >> s >> w;
    cout << (s > w ? "safe" : "unsafe") << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(){
  long int n,l[1000000],r[100000];
  long int i,ans=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%ld %ld",&l[i],&r[i]);
    ans=ans+r[i]+1-l[i];
  }
  printf("%ld\n",ans);
  return(0);
}
    


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int n ;
const int mxN=3002,M=1e9+7;

long long k,a[mxN+1];

//long long dp[mxN][mxN];
int main(){
	cin >> n  ;
    for(int i = 0 ; i< n  ; ++i){
        cin >> a[i];
    }

    vector< vector<long long> > dp(n,vector<long long>(n,0));
    
    for(int i = n-1 ; i>=0 ; --i){
        for(int j=i; j<=n-1 ; j++){
            if(i==j)
            dp[i][j] = a[i];
            else
            dp[i][j] = max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
        }
    }

    cout << dp[0][n-1];
}

Measured memory_bytes: 73716
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9+7
#main code here!
    h,w,k=MI()
    cake=[SI() for i in range(h)]
    last=[-1 for i in range(w)]
    for i in range(w):
        for j in range(h):
            if cake[j][i]=="#":
                last[i]=j
    lis=[[0]*w  for i in range(h)]
    ans=0
    for i in range(w):  
        if last[i]==-1:
            continue
        if last[i]!=-1:
            ans+=1
        for j in range(h):
            lis[j][i]=ans
            if cake[j][i]=="#":
                if last[i]!=j:
                    ans+=1
    #print(lis)
    pos=[]
    for i in range(w):
        if last[i]!=-1:
            pos.append(i)
    pos.append(w)
    for i in range(w):
        if last[i]==-1:
            u=pos[bisect_left(pos,i)]
            #print(u)
            if u!=w:
                for j in range(h):
                    lis[j][i]=lis[j][u]
            else:
                for j in range(h):
                    lis[j][i]=lis[j][pos[-2]]

            
        
    
    for i in range(h):
        print(*lis[i])
    #print(lis)

            
            
            

    
        
        
        
        
    
        
                    
            
        



        
        
        
        
        
    
if __name__=="__main__":
    main()



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

int main(void)
{
	int N, i, j, sum = 0;
	int *n;
	scanf("%d", &N);;
	n = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++)
		scanf("%d", &n[i]);
	for(i = 0; i < N-1; i++)
		for(j = i+1; j < N; j++)
			sum += n[i] * n[j];
	printf("%d\n", sum);
	return 0;
}

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

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

  string T,P;
  cin >> T;
  cin >> P;
  for(int it=0;it<T.length();it++) {
    int s = T.find(P,it);
    if(s != string::npos) {
      cout << s << "\n";
      it = s;
    }
    else {
      return 0;
    }
  }
}

Measured memory_bytes: 1196
(function Main(){
    var input = require("fs").readFileSync("/dev/stdin", "utf8");
    var v = input.split(" ");
    var a = parseInt(v[0], 10);
    var b = parseInt(v[1], 10);
    var c = parseInt(v[2], 10);
    
    if(a < b && b < c) console.log("Yes");
    else console.log("No");
})();


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e15;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(),a.end()
bool debug = 0;
const int MAXN = 1e5 + 100;
const int LOG = 20;
const int mod = 1e9 + 7;
const int MX = 1e6 + 100;
typedef long long li;
const li MOD = 1000000000949747713ll;


ll dp[MAXN];
void solve() {
    int n;
    cin>> n;
    int W;
    cin >> W;
    for(int i=1;i<=n;++i){
        int w,v;
        cin >> w >> v;
        for(int j = W;j>=1;--j){
            if(j - w>=0){
                dp[j] = max(dp[j], dp[j-w] + v);
            }
        }
    }
    cout << dp[W]<<"\n";
}

signed main() {
#ifdef zxc
    debug = 1;
    freopen("../input.txt", "r", stdin);
#else

#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(20);

    int t = 1;

    while (t--)
        solve();
    dout <<endl<< (1.0 * clock() / CLOCKS_PER_SEC) << endl;
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        int[] tastes = new int[N];
        int min = Integer.MAX_VALUE;
        int index = 0;
        for (int i = 0; i < N; i++) {
            int taste = L+i;
            tastes[i] = taste;
            int moo = Math.abs(taste);
            if (moo < min) {
                min = moo;
                index = i;
            }
        }
        System.out.println(Arrays.stream(tastes).sum()-tastes[index]);
    }
}

Measured memory_bytes: 36000
#include <bits/stdc++.h>
#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 namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{

  int a,b,c,d,e,f,g,h;
  cin >> a >> b >> c >> d;
  e = c - (d - b);
  f = d + c - a;
  g = e - (f - d);
  h = f + e - c;
  cout << e << " " << f << " " << g << " " << h << endl;
  return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>

int tate,yoko;
int i,s,t;
int n;
int x,y;
int total,ans;

int hoge[256][256];
int hoge2[256];
main(){
	scanf("%d%d",&tate,&yoko);
	for(i=0; i<tate; i++){
		for(s=0;s<yoko; s++){
			scanf("%d",&x);
			hoge[i][s]=x;
		}
	}
	
	for(t=0;t<yoko;t++){
		scanf("%d",&y);
		hoge2[t]=y;
	}	
		
		
	
	for(i=0; i<tate; i++){
		for(s=0;s<yoko;s++){
			
			total+=hoge[i][s]*hoge2[s];
			if(s==yoko-1){
				printf("%d\n",total);
				total=0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 704
#include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define all(c) (c).begin(), (c).end()

using namespace std;
template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }

int main() {
	bool keys[(int)'z'+1];
	rep(i,(int)'z'+1) {
		keys[i] = false;
	}
	keys['y']=true; keys['u']=true; keys['i']=true;
	keys['o']=true; keys['p']=true;
	keys['h']=true; keys['j']=true;
	keys['k']=true; keys['l']=true;
	keys['n']=true; keys['m']=true;

	string a_str;
	bool is_right_back;
	bool is_right;
	bool is_first;
	int cnt;
	while(cin >> a_str) {
		is_first = true;
		cnt = 0;
		if (a_str[0] == '#') { break; }
		rep(i,a_str.size()) {
			if (!is_first) {
				is_right = keys[(int)a_str[i]];
				if (is_right != is_right_back) {
					cnt++;
				}
			}
			is_right_back = keys[(int)a_str[i]];
			is_first = false;
		}
		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#define rep(i, n) for (int i = 0; i <= (n); i++)
using namespace std;

int main() {

    int n, y; cin >> n >> y;

    rep(i, n) {
        rep(j, n - i) {
            int k = n - i - j;
            int sum = i * 10000 + j * 5000 + 1000 * k;
            if (sum == y) {
                cout << i << " " << j << " " << k << endl;    
                return 0;
            }
        }
    }cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
int n;
std::vector<int> prime;
bool isprime(int n){
    if(n == 1) return false;
    if(n == 2) return true;
    if(n % 2 == 0) return false;
    for(int i = 3; i*i <=n; i+=2){
        if(n % i == 0) return false;
    }
    return true;
}
int main(){
    std::cin >> n;
    std::vector<int> prime;
    for(int i = 2; i*i <= n; i++){
        if(isprime(i)) prime.push_back(i);
    }
    std::vector<int> ans;
    int t = n;
    while(n != 1){
        if(isprime(n)){
            ans.push_back(n);
            break;
        }
        else{
            for(int i: prime){
                if(n % i == 0) {
                    ans.push_back(i);
                    n /= i;
                    break;
                }
            }
        }
    }
    printf("%d:", t);
    for(int i: ans) printf(" %d", i);
    printf("\n");
}


Measured memory_bytes: 3280
#include <iostream>
using namespace std;
int main () {
	int a, b;
	cin >> a >> b;
		if (a <= 9 & 1 <= a & b <= 9 & 1 <= b) {
			cout << a * b;
		}
		else {
			cout << -1;
		}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
    ll n,x;
    cin>>n>>x;
    V<ll> a(n),b(n,inf);
    for(int i=0;i<n;i++)cin>>a[i];
    ll ans=inf;
    for(ll i=0;i<n;i++){
        ll sum=0,c=i*x;
        for(int j=0;j<n;j++){
            chmin(b[j],a[(j-i+n)%n]);
            sum+=b[j];
        }
        chmin(ans,sum+c);
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3696
using System;
using System.Linq;
class P
{
    static void Main()
    {
        var i = Console.ReadLine();
        var j = new int[] { int.Parse(i[0].ToString()), int.Parse(i[1].ToString()), int.Parse(i[2].ToString()), int.Parse(i[3].ToString()) };
        var k = j.Sum();
        if (k == 7) Console.WriteLine($"{j[0]}+{j[1]}+{j[2]}+{j[3]}=7");
        else if (k - 2 * j[3] == 7) Console.WriteLine($"{j[0]}+{j[1]}+{j[2]}-{j[3]}=7");
        else if (k - 2 * j[2] == 7) Console.WriteLine($"{j[0]}+{j[1]}-{j[2]}+{j[3]}=7");
        else if (k - 2 * (j[2] + j[3]) == 7) Console.WriteLine($"{j[0]}+{j[1]}-{j[2]}-{j[3]}=7");
        else if (k - 2 * j[1] == 7) Console.WriteLine($"{j[0]}-{j[1]}+{j[2]}+{j[3]}=7");
        else if (k - 2 * (j[1] + j[3]) == 7) Console.WriteLine($"{j[0]}-{j[1]}+{j[2]}-{j[3]}=7");
        else if (k - 2 * (j[1] + j[2]) == 7) Console.WriteLine($"{j[0]}-{j[1]}-{j[2]}+{j[3]}=7");
        else if (k - 2 * (j[1] + j[2] + j[3]) == 7) Console.WriteLine($"{j[0]}-{j[1]}-{j[2]}-{j[3]}=7");
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define for(i,a,b) for(int i=a; i<b; i++)
#define d = 1000000007
int main(){
    int K, A, B;
    cin >> K;
    cin >> A >> B;
    if((A+K-1)/K <= B/K)
        cout << "OK";
    else
        cout << "NG";
    return 0;
}

Measured memory_bytes: 3592
a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i

if a >= b && c >= d
  puts b + d
elsif a <= b && c >= d
  puts a + d
elsif a >= b && c <= d
  puts b + c
elsif a <= b && c <= d
  puts a + c
end


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int n, x;
    cin >> n >> x;
    vector<int> m(n);
    rep(i, n) cin >> m[i];
    rep(i, n) x -= m[i];
    int ans = n;
    sort(All(m));
    while (x >= m.front())
    {
        x -= m.front();
        ans++;
    }
    c(ans);
    return 0;
}

Measured memory_bytes: 256
/*#### bits/stdc++.h */
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<string>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<deque>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
/*####*/
char s[111111];
int main(){
	scanf("%s",s);
	int st = 0, en = strlen(s)-1, res = 0;
	while(st < en){
		if(s[st] == s[en]){
			st ++;
			en --;
		}else
		if(s[st] == 'x'){
			st ++;
			res ++;
		}else
		if(s[en] == 'x'){
			en --;
			res ++;
		}else{
			puts("-1");
			return 0;
		}
	}
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 384