akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll inf = LONG_LONG_MAX / 2 - 1;
    const ll d[4][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    queue<pair<ll, ll>> q;
    q.push(make_pair(0, 0));
    vector<vector<ll>> dist(h, vector<ll>(w, inf));
    dist[0][0] = 0;
    vector<vector<bool>> seen(h, vector<bool>(w, false));
    seen[0][0] = true;
    while(!q.empty()) {
        pair<ll, ll> p = q.front(); q.pop();
        ll x = p.first, y = p.second;
        rep(i, 4) {
            ll nx = x + d[i][0];
            ll ny = y + d[i][1];
            if ((nx < 0) || (nx >= w) || (ny < 0) || (ny >= h)) continue;
            if (s[ny][nx] == '#') continue;
            if (seen[ny][nx]) continue;
            dist[ny][nx] = dist[y][x] + 1;
            seen[ny][nx] = true;
            q.push(make_pair(nx, ny));
        }
    }
    if (dist[h - 1][w - 1] == inf) {
        cout << -1 << endl;
        return 0;
    }
    ll cnt = 0;
    rep(i, h) {
        rep(j, w) {
            if (s[i][j] == '#') cnt++;
        }
    }
    cout << (h * w - cnt - dist[h - 1][w - 1] - 1) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    Long A = sc.nextLong();
    Double B = sc.nextDouble();
    BigDecimal ad = new BigDecimal(String.valueOf(A));
    BigDecimal bd = new BigDecimal(String.valueOf(B));
    BigDecimal bd3 = bd.setScale(2, RoundingMode.DOWN);
    BigDecimal bd4 = ad.multiply(bd3);
    System.out.println(bd4.setScale(0, RoundingMode.DOWN));

  }

  
}

Measured memory_bytes: 37780
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
typedef long long ll;
int main() {
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n);
    ll sum = 0;
    for(ll i=0;i<n;i++){
        cin >> a[i];
        sum += a[i];
    }
    sort(a.begin(),a.end(),greater<int>());
    for(ll i=0;i<m;i++){
        if((4*m*a[i]) < sum){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  int N;
  cin >> N;
  vector<int> vec(10000010,0);
  rep(i,10000000)
  {
    vec[N] ++;
    if(vec[N]==2)
    {
      cout << i + 1 << endl;
      return 0;
    }
    if(N%2==0)
    {
      N /= 2;
    }
    else
    {
      N *= 3;
      N += 1;
    }
  }
  return 0;
}


Measured memory_bytes: 42328
import sys

A,B,K = [int(s) for s in input().split()]

cnt = 0

N = min(A,B) 

for i in range(N,0,-1):
  if A % i == 0 and B % i == 0:
    cnt += 1
  if cnt == K:
    print(i)
    sys.exit()

Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = 0

for i in range(N):
    if A[i] != 0:  # 担当の街
        if B[i] > A[i]:  # 担当の街を全滅させられる
            B[i] -= A[i]
            count += A[i]
        else:  # 担当の街で精一杯
            count += B[i]
            continue
    if A[i+1] < B[i]:  # 隣の街を全滅させられる
        count += A[i+1]
        A[i+1] = 0
    else:  # 隣の街を全滅させられない
        A[i+1] -= B[i]
        count += B[i]

print(count)


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

using namespace std;

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

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

int main() {
    int A, B;
    while (cin >> A >> B, A && B) {
        int C = B - A;
        int div[] = {1000, 500, 100};
        vector<int> ans;
        rep(i, 3) {
            ans.push_back(C / div[i]);
            C %= div[i];
        }
        reverse(all(ans));
        rep(i, 3) cout << ans[i] << (i == 2 ? '\n' : ' ');
    }

    return 0;
}

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

#define Max(a,b) max({a,b})
#define Min(a,b) min({a,b})
#define rep(i,m,n) for(int (i)=(m);(i)<(int)(n);(i)++)
#define len(n) n.size()
#define print(n) cout << (n) << endl;


// s.substr(i,n)

typedef long long ll;

using namespace std;

//char a = 65;
long long int inf = 1000000007;
int n,m,a,b,c,d,cou,co,p;
long long int lla,llb,llc;
double k;
const ll LINF = 1e18;
char num = 65;
string s,t;
int lis[20];
/*
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}
*/

int main(){
    
    cin >> a >> b;
    if(a == 2 || b == 2) print("No")
    else print("Yes")
    
    return 0;
}

Measured memory_bytes: 256
from collections import*
A=deque(list(input()))
B=deque(list(input()))
C=deque(list(input()))
now=A[0];A.popleft()
while True:  
  if now=="a":
    if len(A)==0:
      print("A")
      break
    now=A[0];A.popleft()    
  elif now=="b":
    if len(B)==0:
      print("B")
      break
    now=B[0];B.popleft()
  elif now=="c":
    if len(C)==0:
      print("C")
      break
    now=C[0];C.popleft()
  else:
    pass
  #print(A,B,C)

    





Measured memory_bytes: 3316
fun main(arr:Array<String>) {
    val (a,b) = readLine()!!.split(" ").map { it.toInt() }
    val postalCode = readLine()!!.split("-")
    if(postalCode.size != 2) {
        println("No")
        return
    }
    if(!postalCode.all { it.all { it in '0'..'9' } }) {
        println("No")
        return
    }
    if(postalCode[0].length != a || postalCode[1].length != b) {
        println("No")
        return
    }
    println("Yes")
}

Measured memory_bytes: 38004
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[2];
    rep(i,2){
        cin >> A[i];
    }
    cout << A[0]-A[1]+1 << endl;
}

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

using namespace std;

int n;
int t[202];
int v[202];
const double INF = 10000000.0;

int main() {
  cin >> n;

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

  vector<double> dp(101,-INF);
  dp[0] = 0.0;

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < t[i]; j++) {
      vector<double> nextdp(101,-INF);
      for(double k = 0; k <= v[i]; k++) {
	nextdp[k] = max(nextdp[k],dp[k] + k);
	if(k < v[i]) {
	  nextdp[k] = max(nextdp[k],dp[k] + k + 0.25);
	  nextdp[k+1] = max(nextdp[k+1],dp[k] + k + 0.5);
	}
	if(k > 0)
	  nextdp[k-1] = max(nextdp[k-1],dp[k] + k - 0.5);
      }
      dp.swap(nextdp);
    }
  }

  cout << fixed << dp[0] << endl;
}


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

const int mod = 1e9 + 7;

typedef pair<int, int> pii;

int n, K;

int pr(int a, int z) {
	int s = 1;
	while (z > 0) {
		if (z % 2 == 1) s = 1ll * s * a % mod;
		a = 1ll * a * a % mod;
		z /= 2;
	}
	return s;
}

map<int, int> sum;
pii li[200];
int len;

#define fi first
#define se second

int main() {
	//freopen("64D.in", "r", stdin);
	scanf("%d%d", &n, &K);
	int _n = n;
	for (int i = 2; i * i <= _n; ++i) if (_n % i == 0) {
		int c = 0;
		while (_n % i == 0) _n /= i, ++c;
		li[++len] = pii(i, c);
	}

	if (_n != 1) li[++len] = pii(_n, 1);

	for (int d = 1; d * d <= n; ++d) {
		if (n % d == 0) {
			sum[d] = d;
			sum[n / d] = n / d;
		}
	}



	for (int i = 1; i <= len; ++i) {
		for (auto it = sum.begin(); it != sum.end(); ++it) if (it->fi % li[i].fi == 0 && sum.find(it->fi / li[i].fi) != sum.end()) {
			sum[it->fi / li[i].fi] -= sum[it->fi];
		}
	}


	int ans = 0;

	for (pii p : sum) {
		ans = (ans + 1ll * pr(K, (n / p.fi % 2 == 1) ? (p.fi + 1) / 2 : p.fi) * p.se % mod + mod) % mod;
	}

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


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#include <cctype>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}


int main() {
	int i, j, k;
	int N, M, K;

	string S;


	cin >> i >> j;
	cout << i * j;

}


Measured memory_bytes: 3624
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int H, W, K;
	cin >> H >> W >> K;
	vector<string>c(H);
	rep(i, H)cin >> c[i];
	int ans = 0;
	int cnt = 0;
	for (int i = 0; i < (1ll << H); i++) {
		for (int j = 0; j < (1ll << W); j++) {
			vector<string>cpy(H);
			cpy = c;
			for (int k = 0; k < H; k++) {
				if ((i >> k) & 1) {
					for (int l = 0; l < W; l++)cpy[k][l] = 'R';
				}
			}

			for (int k = 0; k < W; k++) {
				if ((j >> k) & 1) {
					for (int l = 0; l < H; l++)cpy[l][k] = 'R';
				}
			}

			int res = 0;
			for (int x = 0; x < H; x++) {
				for (int y = 0; y < W; y++) {
					if (cpy[x][y] == '#')res++;
				}
			}
			if (res == K)ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define ll long long 
ll ans[3][121340],visited[3][121340];
ll mini(ll a,ll b,ll c)
{
	ll z=a;
	z=min(z,b);
	z=min(z,c);
	return z;
}

int main()
{
	ll n=1,a=0,b,c,i;
    string ans,ans2;
    cin>>ans;
    cin>>ans2;
    for(i=0;i<ans.size();i++)
    {
        if(ans[i]!=ans2[i])
        a++;
    }
    cout<<a<<endl;
}

Measured memory_bytes: 3912
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
#include <set> 
using namespace std;
typedef long long ll;
const int N = 1000010;
int n, a[N], w[N], fa[N];
struct data
{
	ll w; int s, x;
	bool operator <(const data &p) const
	{
		if (w * p.s != p.w * s)return w * p.s<p.w*s;
		return x < p.x;
	}
} p[N];
set<data>Q;
int cnt = 0, b[N];
inline int find(int x) { return b[x] == x ? x : b[x] = find(b[x]); }
inline void _read(int &x)
{
	x = 0;
	char t = getchar();
	while (!isdigit(t)) t = getchar();
	while (isdigit(t))
	{
		x = x * 10 + t - '0';
		t = getchar();
	}
}
int main()
{
	_read(n);
	for (int i = 2; i <= n; i++)
		_read(fa[i]);
	for (int i = 1; i <= n; i++) _read(w[i]);
	for (int i = 1; i <= n; i++)
	{
		p[i] = (data) { w[i], 1, i };
		Q.insert(p[i]); b[i] = i;
	}
	cnt = n;
	ll ans = 0;
	data t;
	while (!Q.empty())
	{
		t = *Q.begin(); Q.erase(t);
		int y = find(fa[t.x]);
		if (!y)continue;
		ans += (t.s - t.w)*p[y].w;
		Q.erase(p[y]);
		data e = t;
		e.w += p[y].w; e.s += p[y].s; e.x = ++cnt;
		b[cnt] = cnt; b[y] = cnt; b[find(t.x)] = cnt;
		fa[cnt] = fa[y]; fa[t.x] = cnt;
		p[cnt] = e;
		Q.insert(e);
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 28672
n,x=map(int,raw_input().split(" "))
a=map(int,raw_input().split(" "))
t=[i for i in a]
s=10**15
for m in range(n):
    t=[min(t[j],a[(j-m)%n]) for j in range(n)]
    s=min(x*m+sum(t),s)
print s

Measured memory_bytes: 2816
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int n,m;
    while(scanf("%d%d",&n,&m)==2)
    {
        int a[1010];
        if(n==0&&m==0){
            break;
        }
        else{
            for(int i=0;i<n;i++){
                scanf("%d",&a[i]);
            }
            int max = 0;
            for(int i=0;i<n-1;i++){
                for(int j=i+1;j<n;j++){
                    if(a[i]+a[j]>max && a[i]+a[j]<=m){
                        max = a[i] + a[j];
                    }
                }
            }
            if(max==0){
                printf("NONE\n");
            }
            else{
                printf("%d\n",max);
            }
        }
    }
    return 0;
}



Measured memory_bytes: 2064
#include <bits/stdc++.h>
#define pb push_back
#define ld long double
#define ll long long
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ld,ld>
#define f first
#define s second
#define sz(x) (int)x.size()

using namespace std;

const ll N = 2e5 + 10;
const ll big = 1e18;
const ll block = 100;
const ll mod = 1e6;

ll n;
ll c;

ll h[N];
ll dp[N];

vector<pill> convex;

ld cross(pill a,pill b){
    return (b.s - a.s + 0.0) / (a.f - b.f + 0.0);
}

void add(ld k,ld b){
    while(sz(convex) > 1){
	    ll szs = sz(convex);
        if(cross({k,b} , convex[szs - 2]) > cross(convex[szs - 1] , convex[szs - 2]) )
            break;
        convex.pop_back();
    }
    convex.pb({k, b});
}

int main() {
    speed;
    cin >> n >> c;
    for(int i = 0 ; i < n ; i++)
        cin >> h[i];
    for(int i = 0 ; i < n ; i++){
        if(i){
            ll l = 0, r = sz(convex) - 2;
            while(l <= r){
                ll m = (l + r) / 2;
                ld y = cross(convex[m] , convex[m + 1]);
                if(y > h[i] + 0.0)
                    r = m - 1;
                else
                    l = m + 1;
            }
            dp[i] = convex[l].f * h[i] + convex[l].s + h[i] * h[i] + c;
        }
        add(-2 * h[i], dp[i] + h[i] * h[i]);
    }
    cout << dp[n - 1] << '\n';
}

/*
    Code written by
    Codeforces : I_Love_Trott
    mail : dzhon.snoudin@mail.ru
*/

Measured memory_bytes: 13548
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        String s = next();

        String before = "";
        boolean flag = false;
        for(String value : s.split("")){
            if(before.equals(value)){
                flag = true;
                break;
            }
            before = value;
        }

        println(flag ? "Bad" : "Good");
    }

    static class Point {
        int x;
        int y;
        Point(int x, int y){
            this.x = x;
            this.y = y;
        }
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int N, M;
    scan(N, M);
    vector<string> a(N), b(M);
    scan(a);
    scan(b);

    rep(y, N) {
        rep(x, N) {
            bool f = true;
            rep(yy, M) {
                rep(xx, M) {
                    if (y + yy >= N || x + xx >= N) {
                        f = false;
                        break;
                    }
                    if (a[y + yy][x + xx] != b[yy][xx]) {
                        f = false;
                        break;
                    }
                }
            }
            if (f) {
                print("Yes");
                return 0;
            }
        }
    }
    print("No");

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

using ll = long long;
using namespace std;

#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define LFOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define FORR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LFORR(i,a,b) for(ll i = (int)(a); i >= (ll)(b); i--)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define LREP(i,n) LFOR(i,0,(ll)(n)-1)
#define REPR(i,n) FORR(i,(int)(n)-1,0)
#define LREPR(i,n) LFORR(i,(ll)(n)-1,0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;





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

  int a,p;
  cin >> a >> p;
  cout << (int)((a*3+p)/2) << endl;

}


Measured memory_bytes: 256
n = gets.to_i
arr = gets.chomp.split(" ").map(&:to_i)

flag = true
i = 0
sort_num = 0
while flag do
  flag = false
  ((i+1)..(n-1)).reverse_each do |j|
    if arr[j] < arr[j-1]
      org_arr_j = arr[j]
      arr[j] = arr[j-1]
      arr[j-1] = org_arr_j
      sort_num += 1
      flag = true
    end
  end
  i += 1
end

puts arr.join(' ')
puts sort_num


Measured memory_bytes: 6908
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};

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

  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  rep(i,h) cin >> grid[i];
  int cnt = 0;
  rep(i,h) rep(j,w) if(grid[i][j] == '.') cnt++;

  queue<pair<int, int>> que;
  vector<vector<int>> dist(h, vector<int> (w, -1));
  dist[0][0] = 0;
  que.push({0, 0});

  while(!que.empty()) {
    int vh = que.front().fi;
    int vw = que.front().se;
    que.pop();

    rep(dir, 4) {
      int nvh = vh + dy[dir];
      int nvw = vw + dx[dir];

      if(nvh < 0) continue;
      if(nvw < 0) continue;
      if(nvh >= h) continue;
      if(nvw >= w) continue;
      if(dist[nvh][nvw] != -1) continue;
      if(grid[nvh][nvw] == '#') continue;

      dist[nvh][nvw] = dist[vh][vw]+1;
      que.push({nvh, nvw});
    }
  }
  cout << (dist[h-1][w-1] == -1 ? -1 : cnt - dist[h-1][w-1] - 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int LeapYear (int x);
int main()
{
    int a,b;
    std::cin >> a >> b;
    while (true) {
        int n = 0;
        if (a == 0 && b == 0) {
            break;
        } else {
            for (int i = a; i <= b; i++) {
                if (LeapYear (i) == 1) {
                    std::cout << i << std::endl;
                    n++;
            }				
        }
            if (n == 0) {
                std::cout << "NA" << std::endl;
            }
            std::cin >> a >> b;
            if (b != 0) {
                std::cout << std::endl;
            }
        }
    }
    return 0;
}

int LeapYear (int x)
{
    if (x % 400 == 0) {
    return 1;
    } else if (x % 100 == 0) {
    return 0;
    } else if (x % 4 == 0) {
    return 1;
    }else {
    return 0;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i, n) cin >> x.at(i);
  vector<int> d(n-1);
  rep(i, n-1) d.at(i) = x.at(i+1) - x.at(i);
  if(n == 2){
    cout << x.front() << endl;
    return 0;
  }
  int ds = d.size();
  vector<mint> c(n-1);
  vector<mint> cd(n-2);
  mint now = 1;
  mint pn = 1;
  rep(i, ds-1){
    now *= (i+2);
    if(i != ds-2) pn *= (i+3);
  }
  c.front() = now;
  cd.front() = pn;
  rep(i, cd.size()-1){
    cd.at(i+1) = cd.at(i)*(i+2)/(i+3);
  }
  rep(i, cd.size()){
    c.at(i+1) = c.at(i) + cd.at(i);
  }
  mint ans = 0;
  rep(i, d.size()){
    ans += c.at(i) * d.at(i);
  }
  cout << ans.x << endl;
  // vector<int> index;
  // rep(i, n-1) index.push_back(i);
  // vector<int> fout(n-1, 0);
  // do{
  //   vector<int> out(n-1, 0);
  //   rep(i, n-1){
  //     for(int j = i; j < n-1 && index.at(j) <= index.at(i); j++){
  //       out.at(j)++;
  //     }
  //   }
  //   rep(i, n-1){
  //     cerr << out.at(i) << " ";
  //     fout.at(i) += out.at(i);
  //   }
  //   cerr << endl;
  // }while(next_permutation(ALL(index)));
  // cerr << endl << endl;
  // rep(i, n-1) cerr << fout.at(i) << " ";
  // cerr << endl;
  // rep(i, n-2) fout.at(i) = fout.at(i+1) - fout.at(i);
  // rep(i, n-2) cerr << fout.at(i) << " ";
  // cerr << endl;

  return 0;
}

Measured memory_bytes: 5560
#include<bits/stdc++.h>
#define maxn 105
#define ll long long
#define inf 100000000000000000LL
using namespace std;
int n,s,t,pos[maxn],dd[maxn],d[maxn],cnt;
ll res;
struct data
{
        int u,v;
        ll f,c;
};
vector<int > g[maxn];
vector<data >edge;
void add_edge(int u,int v,ll c)
{
        g[u].push_back(edge.size());
        edge.push_back({u,v,0,c});
        g[v].push_back(edge.size());
        edge.push_back({v,u,0,0});
}
bool bfs()
{
        dd[s]=++cnt;
        queue<int > q;
        q.push(s);
        while(!q.empty())
        {
                int u=q.front();
                q.pop();
                pos[u]=0;
                for (int i=0;i<g[u].size();++i)
                {
                        int id=g[u][i];
                        int v=edge[id].v;
                        if (dd[v]==cnt||edge[id].f==edge[id].c) continue;
                        dd[v]=cnt;
                        d[v]=d[u]+1;
                        q.push(v);
                }
        }
        return dd[t]==cnt;
}
ll dfs(int u,ll low)
{
        if (u==t||low==0) return low;
        for (;pos[u]<g[u].size();++pos[u])
        {
                int id=g[u][pos[u]];
                int v=edge[id].v;
                if (d[v]!=d[u]+1||edge[id].f==edge[id].c) continue;
                ll x=dfs(v,min(low,edge[id].c-edge[id].f));
                if (x!=0)
                {
                        edge[id].f+=x;
                        edge[id^1].f-=x;
                        return x;
                }
        }
        return 0;
}
int main()
{
        //freopen("E_MUL.inp","r",stdin);
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cin>>n;
        s=n+1,t=n+2;
        for (int i=1;i<=n;++i)
        {
                int x;
                cin>>x;
                if (x<0) add_edge(s,i,-x);
                else
                {add_edge(i,t,x);
                res+=x;
                }
        }
        for (int i=1;i<=n;++i)
        {
                for (int j=2;j*i<=n;++j)
                        add_edge(i,i*j,inf);
        }
        while(bfs())
        {
              while(ll x=dfs(s,1e9))
              {
                      res-=x;
              }
        }
        cout<<res;
        return 0;
}


Measured memory_bytes: 256
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


a, b, x = read_ints()

S = x/a

import numpy as np
if S < a*b / 2:
    # 水が三角形になる
    print(np.arctan((b*b)/(2*S))*180/np.pi)
else:
    # 水が△と平行四辺形になる
    print(np.arctan(2*(a*b-S)/(a*a)) * 180/np.pi)


Measured memory_bytes: 12452
//https://atcoder.jp/contests/abc174/tasks/abc174_b
#include <stdio.h>
#include <math.h>

int main() {
    
    float a[200000];
    float b[200000];
    int n= 0;
    int D= 0;
    int j= 0;
    
    printf("\n");
    scanf("%d", &n);
    scanf("%d", &D);
    
    for(int i=0; i<n; i++){
        printf("\n");
        scanf("%f", &a[i]);
        scanf("%f", &b[i]);
        
        if(sqrt(pow(a[i], 2) + pow(b[i], 2))<D||sqrt(pow(a[i], 2) + pow(b[i], 2))==D)
                  j++;
    }
    printf("%d", j);
    
    return 0;
}


Measured memory_bytes: 3800
# 写経しましたが、何もわかっていません。

def floor_sum(n, m, a, b):
    "Return sum( floor( (A * i + B) / M ) for i in range(N) )"
    ret = 0
    while True:
        if a >= m:
            ret += ((n - 1) * n) // 2 * (a // m)
            a %= m
        if b >= m:
            ret += n * (b // m)
            b %= m
        y_max = (a * n + b) // m
        if y_max == 0:
            return ret
        x_max = y_max * m - b
        ret += (n - (x_max + a - 1) // a) * y_max
        n, m, a, b = y_max, a, m, -x_max % a

def main():
    import sys
    input = sys.stdin.buffer.readline

    ans = []
    T = int(input())
    for _ in range(T):
        N, M, A, B = map(int, input().split())
        ans.append(floor_sum(N, M, A, B))

    print('\n'.join(map(str, ans)))


if __name__ == "__main__":
    main()

Measured memory_bytes: 79544
# -*- coding: utf-8 -*-
# input
a, b = map(int, input().split())
# calc
if b == 1:
    print(0)
elif b-a <= 0:
    print(1)
else:
    if (b-a) % (a-1) == 0:
        print(int(((b-a)//(a-1))+1))
    else:
        print(int(((b-a)//(a-1))+2))


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		while(true){
			String[] arr = reader.readLine().split(" ", 0);
			int[] arr_int = new int[2];
			for (int i =0; i< 2; i++){
				arr_int[i] = Integer.parseInt(arr[i]);
			}
			if (arr_int[0] == arr_int[1] && arr_int[0] == 0){
				
				break;
			}
			change(arr_int);
			builder.append(arr_int[0]).append(" ").append(arr_int[1]).append("\n");
		}
		System.out.print(builder);

	}
	
	public static void change(int[] array){
		if (array[0] > array[1]){
			int tmp = array[0];
			array[0] = array[1];
			array[1] = tmp;
		}
	}

}

Measured memory_bytes: 26308
n = int(input())
say = {}
for i in range(n):
    a = int(input())
    xy = []
    for j in range(a):
        xy.append(list(map(int,input().split())))
    say[i] = xy
ans = 0
for i in range(2 ** n):
    c = [0 for i in range(n)]
    p = 0
    for j in range(n):
        # 順に右にシフトさせ最下位bitのチェックを行う
        if ((i >> j) & 1):
            # フラグが立っていた時の処理
            c[j] = 1
    #print(c)
    for j in range(n):
        # 順に右にシフトさせ最下位bitのチェックを行う
        if ((i >> j) & 1):
            # フラグが立っていた時の処理
            if c[j] == -1 or c[j] == 1:
                c[j] = 1
            else:
                p = 1
                #print(j,1)
                break
            for k in say[j]:
                if c[k[0]-1] == -1:
                    c[k[0]-1] = k[1]
                elif c[k[0]-1] != k[1]:
                    p = 1
                    #print(j)
                    break
        #print(c,i)
        if p == 1:
            break
    if p == 0 and ans < c.count(1):
        ans = c.count(1)
print(ans)
        

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
char a[55][55],b[55][55];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<m;j++){
			cin>>b[i][j];
		}
	}
	bool ans=false;
	for(int i=0;i<=n-m;i++){
		for(int j=0;j<=n-m;j++){
			bool ok=true;
			for(int f=0;f<m;f++){
				for(int g=0;g<m;g++){
					if(a[f+i][g+j]!=b[f][g])ok=false;
				}
			}
			if(ok){
				ans=true;
				break;
			}
		}
	}
	cout<<(ans?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();
        sc.nextLine();

        if (A >= K) {
            System.out.println(K);
            System.exit(0);
        } else {
            K -= A;
        }

        if (B >= K) {
            System.out.println(A);
        } else {
            K -= B;
            System.out.println(A-K);
        }

    }
}

Measured memory_bytes: 35896
#include<iostream>
#define MAX_V 100000
#define MAX_E 500000
#define INF 1e9
using namespace std;
struct edge {
	int from, to, cost;
};
edge es[MAX_E];
int d[MAX_V];
int V;
int E;

bool find_negative_loop(int s) {
	d[s] = 0;
	int count = 0;
	while (true) {
		bool update = false;
		count++;
		for (int i = 0; i < E; i++) {
			if (d[es[i].from] != INF && d[es[i].to] > d[es[i].from] + es[i].cost) {
				if (count == V) {
					return true;
				}
				d[es[i].to] = d[es[i].from] + es[i].cost;
				update = true;
		   }
		}
		if (update == false) {
			return false;
		}
	}
}


int main() {
	int r;
	cin >> V >> E >> r;
	for (int i = 0; i < MAX_V; i++) {
		d[i] = INF;
	}
	for (int i = 0; i < E; i++) {
		cin >> es[i].from >> es[i].to >> es[i].cost;
	}
	if (find_negative_loop(r)) {
		cout << "NEGATIVE CYCLE" << endl;
	}
	else {
		for (int i = 0; i < V; i++) {
			if (d[i] == INF) {
				cout << "INF" << endl;
			}
			else {
				cout << d[i] << endl;
			}
		}
	}
	return 0;
}

















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

ll gcd(ll x, ll y) {
    if(y == 0)
        return x;
    else
        return gcd(y,x%y);
}

void print_vec(vector<ll> vec) {
  cout << "{ ";
  for (int i = 0; i < vec.size(); i++) {
    cout << vec.at(i) << " ";
  }
  cout << "}" << endl;
}

void solve() {
    ll N; cin >> N;

    //print_vec(x);
    
    ll g = 0;
    for(int i = 0; i < N; i++) {
        ll a; cin >> a;
        g = gcd(g,a);
    }

    cout << g << endl;
}

int main() {
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, K; cin >> N >> K;
    vector<int> X(N);
    REP(i, 0, N) cin >> X[i];

    int ans = 1 << 30;
    REP(i, 0, N - K + 1) {
        if (X[i] > 0) {
            ans = min(ans, X[i + K - 1]);
        } else {
            if (X[i + K - 1] > 0) {
                if (abs(X[i]) > abs(X[i + K - 1])) {
                    ans = min(ans, abs(X[i]) + 2 * abs(X[i + K - 1]));
                } else {
                    ans = min(ans, 2 * abs(X[i]) + abs(X[i + K - 1]));
                }
            } else {
                ans = min(ans, abs(X[i]));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
x1, y1, x2, y2 = gets.chomp!.split.map(&:to_i)

# (x1,y1) = (0,0), (x2,y2) = (x2 - x1reverse, y2 - y1reverse)

x2tmp = x2 - x1
y2tmp = y2 - y1

# 90度回転で (x4,y4) を指す場所を決めた

x4tmp = -1*y2tmp
y4tmp = x2tmp

# (x2,y2) = (0,0) まで動かして今度は、 (x3,y3) を代入しつつ、 (x4,y4) を決める
# その分移動させる

x3tmp = x4tmp
y3tmp = y4tmp
x4tmp -= x2tmp
y4tmp -= y2tmp

# もとに戻す

x3 = x3tmp + x2
y3 = y3tmp + y2
x4 = x4tmp + x2
y4 = y4tmp + y2

puts "#{x3} #{y3} #{x4} #{y4}"

Measured memory_bytes: 3836
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <limits.h>
#include <float.h>
#include <math.h>

typedef struct maxspace_t {
    int spaces;
    int h_or_w;
    int num;
} maxspace;

int qsort_maxspace_spaces_rev(const void *a, const void *b)
{
    return (*(maxspace *)b).spaces - (*(maxspace *)a).spaces;
}

#define POS(x,y) ((y) * 2000 + (x))
#define MAX(a,b) ((a>b)?(a):(b))

int solve(int h, int w, char s[2000][2001])
{
    int *x_spaces = malloc(sizeof(int) * 2000 * 2000);
    int *y_spaces = malloc(sizeof(int) * 2000 * 2000);

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            x_spaces[POS(x, y)] = INT_MIN;
            y_spaces[POS(x, y)] = INT_MIN;
        }
    }

    for (int y = 0; y < h; y++) {
        int x_start = 0;
        for (int x = 0; x <= w; x++) {
            if (s[y][x] == '.') {continue;}

            const int count = x - x_start;
            for(int i = x_start; i < x; i++) {
                x_spaces[POS(i, y)] = count;
            }
            x_start = x + 1;
        }
    }

    for (int x = 0; x < w; x++) {
        int y_start = 0;
        for (int y = 0; y <= h; y++) {
            if (s[y][x] == '.') {continue;}

            const int count = y - y_start;
            for (int i = y_start; i < y; i++) {
                y_spaces[POS(x, i)] = count;
            }
            y_start = y + 1;
        }
    }

    int max = 0;
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int spaces = x_spaces[POS(x, y)] + y_spaces[POS(x, y)] - 1;
            //printf("%5d ", (spaces > 0)?(spaces):(0));
            max = MAX(max, spaces);
        }
        //printf("\n");
    }

    return max;
}

int main(int argc, char *argv[])
{
    int h, w;
    char s[2000][2001];
    int i;
    int ans;

    scanf("%d %d", &h, &w);
    for (i = 0; i < h; i++) {
        scanf("%s", s[i]);
    }

    ans = solve(h, w, s);

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 35328
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

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

    REP(i, 0, S.size()) {
        // cout << i << " : " << K << endl;
        if (S[i] == 'a') continue;

        if ('a' + 26 - S[i] <= K) {
            K -= ('a' + 26 - S[i]);
            S[i] = 'a';
        }
    }

    if (K > 0) {
        S[S.size() - 1] = (S[S.size() - 1] - 'a' + K) % 26 + 'a';
    }

    cout << S << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
 
int main()
{
  double x1,y1,x2,y2,distance;
  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
  distance=sqrt( pow(x2-x1,2) + pow(y2-y1,2) );
  printf("%lf\n",distance);
 
  return 0;
}

Measured memory_bytes: 652
n = gets.to_i
ans = Array.new(4,0)
n.times do
  a = gets.chomp
  case a
  when "AC"
    ans[0] += 1
  when "WA"
    ans[1] += 1
  when "TLE"
    ans[2] += 1
  when "RE"
    ans[3] += 1
  end
end
puts "AC x #{ans[0]}"
puts "WA x #{ans[1]}"
puts "TLE x #{ans[2]}"
puts "RE x #{ans[3]}"

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main()
{
    ll n, k;
    cin >> n >> k;
    ll r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;

    ll ans = 0;
    char prev;
    for (int i = 0; i < k; i++) {
        for (int j = i; j < t.size(); j += k) {
            bool win = false;
            if (t[j] == 'r') if (j == i || prev != 'p') { ans += p; prev = 'p'; win = true; }
            if (t[j] == 's') if (j == i || prev != 'r') { ans += r; prev = 'r'; win = true; }
            if (t[j] == 'p') if (j == i || prev != 's') { ans += s; prev = 's'; win = true; }
            if (!win) prev = 'N';
        }
    }
    cout << ans << endl;
    return 0;
}


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

struct union_find {
    int n;
    vector<int> pars;

    union_find(int n): pars(n) {
        for (int i = 0; i < n; i++) {
            pars[i] = i;
        }
    }

    int get_root(int i) {
        if (pars[i] == i) {
            return i;
        } else {
            pars[i] = get_root(pars[i]);
            return pars[i];
        }
    }
    bool is_same(int i, int j) {
        return get_root(i) == get_root(j);
    }
    void unite(int i, int j) {
        if (is_same(i, j) == false) {
            pars[get_root(j)] = get_root(i);
        }
    }
};

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

    int n, m;
    cin >> n >> m;
    union_find uf(n);
    for (int i = 0; i < m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        uf.unite(x, y);
    }

    set<int> num;
    for (int i = 0; i < n; i++) {
        num.insert(uf.get_root(i));
    }

    cout << num.size() << endl;
    return 0;
}

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

int main() {
    int x;
    cin >> x;
    if (x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> cnt(n, 0);
    rep(i, k){
        int d;
        cin >> d;
        rep(j, d){
            int a;
            cin >> a;
            cnt[a-1]++;
        }
    }
    int ans = 0;
    rep(i, n)ans += (cnt[i]==0);
    cout << ans << endl;
}


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

using namespace std;

long long mod = 1e9 + 7;

int main() {

    cin.tie(0); ios_base::sync_with_stdio(0); //Don't ever delete this line

    int n;

    cin >> n;

    vector <int> v(n);

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

        cin >> v[i];

    }

    sort(v.begin(),v.end());

    if(n%2==0){

        bool notzero=true;

        for(int i=1;i<=n/2;i++){

            if(v[2*(i-1)]!=(2*(i-1)+1)||v[2*(i-1)+1]!=(2*(i-1)+1)){

                notzero=false;

            }

        }

        if(notzero==false){cout<<0<<"\n";}

        else{

            long long ans = 1;

            for (int i = 0; i < n/2; i++) {

                    ans = (ans * 2) % mod;

                }

            cout << ans << "\n";

        }

    }

    else{

        bool notzero=true;

        if(v[0]!=0)notzero=false;

        for(int i=1;i<=n/2;i++){

            if(v[2*(i)]!=(2*i)||v[2*(i)-1]!=(2*i)){

                notzero=false;

            }

        }

        if(notzero==false){cout<<0<<"\n";}

        else{

            long long ans = 1;

            for (int i = 0; i < n/2; i++) {

                    ans = (ans * 2) % mod;

                }

            cout << ans << "\n";

        }

    }

	return 0;

}

Measured memory_bytes: 3712
N = gets.to_i

h = [0] * 100
ans = 0
(1..N).each{|i|
  r = i % 10 
  next if r == 0
  l = i / 10 ** Math.log10(i).floor
  h[l * 10 + r] += 1
  ans += h[r * 10 + l] * 2
  ans -= 1 if r == l
}
p ans

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

int main() {
    int N;
    std::cin >> N;
    int h[N],dp[N];
    for(int i = 0; i < N; i++) {
        std::cin >> h[i];
    }
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < N; i++) {
        dp[i] = std::min( dp[i-2] + abs(h[i]-h[i-2]) , dp[i-1] + abs(h[i]-h[i-1]) );
    }
    std::cout << dp[N-1] << std::endl;
}

Measured memory_bytes: 1024
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    size_t A, B, T;

    scanf("%zu %zu %zu", &A, &B, &T);

    printf("%zu\n", T/A*B);

    return 0;
}


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

int gcd(int a, int b) {

    if(a % b == 0) return b;

    return gcd(b, a%b);
}

int main()
{
    int k;
    cin >> k;
    int tmp,tmp2;
    int ans = 0;

    rep(i,k) {
        rep(j,k) {

            tmp = gcd(i+1,j+1);

            rep(l,k) {
                tmp2 = gcd(tmp, l+1);
                ans += tmp2;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3648