akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

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

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

int main(){
    ll n, m, ans;
    cin >> n >> m;
    if(m >= 2*n){
        ans = n + (m - 2*n)/4;
    }else{
        ans = m/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 1e15;
const double eps = 1e-6;
const ll MOD = 1000000007;

int cal(int base, int x) {
	if (base < x)
		return (x - base);
	int sa = abs(base - x);
	return (sa+1) / 2 + sa % 2;
}

int main() {
	ll N;
	cin >> N;
	bool ok = true;
	ll sum = 0;
	ll mini = INF;
	for (int i = 0;i < N;i++) {
		ll a, b;
		cin >> a >> b;
		if (a != b)
			ok = false;
		sum += b;
		if (b < a) {
			mini = min(mini, b);
		}
	}
	if (ok)
		cout << 0 << endl;
	else
		cout << sum - mini << endl;
	return 0;
}


Measured memory_bytes: 888
N, Q = map(int, input().split())
S = input()

ans = [0] * N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ans[i+1] += (ans[i] + 1)
    else:
        ans[i+1] = ans[i]

for _ in range(Q):
    l, r = map(int, input().split())
    print(ans[r-1] - ans[l-1])

Measured memory_bytes: 6132
#include <bits/stdc++.h>
using namespace std;
vector<vector<long>> tree(1e5+1);
void f(long k,vector<long>& d){
    queue<long> q;
    q.push(k);
    while(!q.empty()){
        long t=q.front(); q.pop();
        for(auto x:tree[t]){
            if(x!=k&&d[x]==0){
                d[x]=d[t]+1;
                q.push(x);
            }
        }
    }
}
int main(){
    long n; cin>>n;
    for(int i=0;i<n-1;i++){
        long a,b; cin>>a>>b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<long> df(n+1,0),ds(n+1,0);
    f(1,df);
    f(n,ds);
    long sum=0;
    for(int i=1;i<=n;i++)
        sum+=df[i]<=ds[i]?1:-1;
    if(sum>0)
        cout<<"Fennec";
    else
        cout<<"Snuke";
}

Measured memory_bytes: 8004
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

bool isPrime(ll n){
  if(n < 2) return false;
  if(n == 2) return true;
  if(n % 2 == 0) return false;
  for(ll i = 3; i * i <= n; i += 2){
    if(n % i == 0) return false;
  }
  return true;
}

void priFac(ll n, map<ll, ll> &mp){
  if(isPrime(n)){
    mp[n] = 1;
    return;
  }
  ll loop = n;
  if(n % 2 == 0){
    ll cnt = 0;
    while(n % 2 == 0){
      n /= 2;
      cnt++;
    }
    mp[2] += cnt;
  }
  for(ll i = 3; i * i <= loop; i += 2){
    ll cnt = 0;
    while(n % i == 0){
      n /= i;
      cnt++;
    }
    if(cnt != 0) mp[i] += cnt;
  }
  if(n != 1) mp[n] += 1;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N; cin >> N;
  map<ll, ll> pf;
  for(ll i = 1; i <= N; i++){
    priFac(i, pf);
  }
  // 75 = 3 * 5 * 5; {74}, {2, 24}, {4, 14}, {2, 4, 4}
  ll cnt74 = 0, cnt24 = 0, cnt14 = 0, cnt4 = 0, cnt2 = 0;
  for(auto i : pf){
    if(i.second >= 74) cnt74++;
    if(i.second >= 24) cnt24++;
    if(i.second >= 14) cnt14++;
    if(i.second >= 4) cnt4++;
    if(i.second >= 2) cnt2++;
  }
  ll ans = 0;
  ans += cnt74;
  if(cnt2 > 1) ans += (cnt2-1) * cnt24;
  if(cnt4 > 1) ans += (cnt4-1) * cnt14;
  if(cnt4 > 1 && cnt2 > 2) ans += (cnt2-2) * (cnt4 * (cnt4-1))/2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int n, ans = 0;
  cin >> n;
  string s;
  cin >> s;
  for(int i=0; i<n-2; i++){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
      ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
const int MAX=100000;
const int INF=123456789;
vector<pair<int,int> > G[MAX];
bool vis[MAX];
int d[MAX];
int maxv;

void bfs(int s){
  for(int i=0;i<n;i++) d[i]=INF;

  queue<int> q;
  q.push(s);
  d[s]=0;
  while(!q.empty()){
    int u=q.front();q.pop();
    for(int i=0;i<G[u].size();i++){
      int v=G[u][i].first;
      if(d[v]==INF){
        d[v]=d[u]+G[u][i].second;
        q.push(v);
      }
    }
  }
}

void solve(){
   bfs(0);
   maxv=0;
   int tgt=0;
   for(int i=0;i<n;i++){
     if(d[i]==INF) continue;
     if(maxv<d[i]){
       maxv=d[i];
       tgt=i;
     }
   }

   bfs(tgt);
   maxv=0;
   for(int i=0;i<n;i++){
     if(d[i]==INF) continue;
     maxv=max(maxv,d[i]);
   }
}

int main(){
  cin>>n;
  for(int i=0;i<n-1;i++){
    int s,t,w;
    cin>>s>>t>>w;
    G[s].push_back(make_pair(t,w));
    G[t].push_back(make_pair(s,w));
  }

  solve();

  cout<<maxv<<endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
ll r,D,X; cin >> r >> D >> X;
  vector<ll> W(10);
  W[0] = r * X - D;
  
  for(int i = 0; i < 9 ; i++){
  W[i+1] = r * W[i] - D;}
  
  for(int j = 0; j < 10 ; j++){
    cout << W[j] << endl;}
  
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n; cout<<(n-2)*180<<"\n";
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
wa=[]
sa=[]
for i in range(n):
    wa.append(i+a[i])
    sa.append(i-a[i])
d=defaultdict(int)
for i in wa:
    d[i]+=1
ans=0
for i in sa:
    ans+=d[i]
print(ans)

Measured memory_bytes: 141024
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
ll sieve[1000001]={0},i,j;
ll m=1e9+7;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p);
p=(p*p);
k>>=1;
}
return a;
}
using namespace std;
  ll countDivisors(ll n) 
{ 
    ll cnt = 0; 
    for (ll i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            if (n / i == i) 
                cnt++; 
  
            else 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 
void add_self(int &a ,int b)
{
	a+=b;
	if(a>=m)
	a-=m;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
ll cas=1;
 while(tc--)
 {
	ll n;
	cin>>n;
	vector<vector<ll>> can(n,vector<ll>(n));
	for(ll i=0;i<n;i++)
	for(ll j=0;j<n;j++)
	cin>>can[i][j];
	vector<ll> dp(1<<n);
	dp[0]=1;
	for(ll mask=0; mask <(1<<n) -1;mask++)
	{
		ll a=__builtin_popcount(mask);
		for(ll b=0;b<n;b++)
		if(can[a][b] && !(mask & (1<<b)))
		{
		ll m2=(mask ^ (1<<b));
		  dp[m2]+=dp[mask];
		  dp[m2]%=m;
	    }
	}
	cout<<dp[(1<<n) -1];
	cout<<"\n"; 
 } 
}
 


Measured memory_bytes: 16640
#include<stdio.h>

/* prototype declaration */
void simultaneousEq();

double a, b, c, d, e, f;
double x, y;

int main(int argc, const char *argv[])
{
	simultaneousEq();
	return 0;
}

void simultaneousEq()
{
	double det;
	while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f) != EOF){
		det = a*e-b*d;
		x = (c*e-b*f)/det;
		y = (a*f-c*d)/det;
		if(x == -0.000) x = 0.000;
		if(y == -0.000) y = 0.000;
		printf("%.3f %.3f\n",x, y);	
	}	
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	if((c+(b-1))/b<=(a+(d-1))/d) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

double bmi(double w,double h){
	return w/(h*h);
}

int main(){
	int no;
	double w,h;

	while(scanf("%d,%lf,%lf",&no,&w,&h) != EOF){
		if(bmi(w,h) >= 25.0){
			printf("%d\n",no);
		}
	}

	return 0;
}

Measured memory_bytes: 624
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;

int main()
{
    ll n, k;
    cin >> n >> k;
    ll a[200002];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
    }
    map<ll, vector<ll>> mp;
    ll s = 0;
    for(int i = 0; i < n; i++){
        s = (s + a[i]) % k;
        mp[s].push_back(i);
    }
    ll ans = 0;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        vector<ll> v = itr -> second;
        for(int i = 0; i < (ll)v.size(); i++){
            ans += lower_bound(v.begin(), v.end(), v[i] + k) - v.begin() - 1 - i;
        }
        if(itr -> first == 0) ans += lower_bound(v.begin(), v.end(), k - 1) - v.begin();
    }
    cout << ans << endl;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

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

    int N;
    while (cin >> N, N) {
        vector<vector<int>> t(N, vector<int>(N + 1));
        REP (i, N) REP (j, N + 1) cin >> t[i][j];
        const int INF = 1LL << 30;
        vector<int> dp(1LL << N, INF);
        dp[0] = 0;
        REP (bit, 1LL << N) if (dp[bit] != INF) {
            REP (i, N) if (!(bit >> i & 1)) {
                int sum = t[i][0];
                REP (j, N) if (bit >> j & 1) {
                    sum = min(sum, t[i][j + 1]);
                }
                dp[bit | (1LL << i)] = min(dp[bit | (1LL << i)], dp[bit] + sum);
            }
        }
        cout << dp[(1LL << N) - 1] << endl;
    }
}


Measured memory_bytes: 3684
import sys
from operator import itemgetter
sys.setrecursionlimit(10**6)
def MAP(): return [int(s) for s in input().split()]

if sys.platform =='darwin':
	sys.stdin=open('input.txt')
input = sys.stdin.readline

N, M = MAP()
W = [MAP() for _ in range(M)]
W.sort()

low = W[0][0]
high = W[0][1]
cnt = 1

for i in range(1,M):
	low = max(low, W[i][0])
	high = min(high, W[i][1])
	if low < high:
		continue
	else:
		cnt += 1
		low = W[i][0]
		high = W[i][1]

print(cnt)

Measured memory_bytes: 21708
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  // val a = new Array[Int](N)

  val M = in.next().toInt
  val K = in.next().toInt
  if (K == 0) {
    for (i <- 0 until 1 << M) {
      if (i == 0) {
        pw.print("0 0")
      }
      else
        pw.print(s" $i $i")
    }
    pw.println()
  }
  else if (M == 1 && K == 1){
    pw.println(-1)
  }
  else if (K < (1<<M)) {
    var hoge = List[Int]()
    for (i <- 0 until 1<<M if i != K)
      hoge = i :: hoge

    val ans = hoge ++ List(K) ++ hoge.reverse ++ List(K)
    pw.println(ans.mkString(" "))
  }
  else
    pw.println(-1)

  pw.flush()
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


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

int main(){
    int a;
    int b;
    cin >> a >> b;
    if(a < b){
        cout << "a < b" << endl;
    }
    if(a > b){
        cout << "a > b" << endl;
    }
    if(a == b){
        cout << "a == b" << endl;
    }
    return 0;
}



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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int x;
    cin >> x;

    if(x >= 400 && x < 600) cout << "8\n";
    else if(x >= 600 && x < 800) cout << "7\n";
    else if(x >= 800 && x < 1000) cout << "6\n";
    else if(x >= 1000 && x < 1200) cout << "5\n";
    else if(x >= 1200 && x < 1400) cout << "4\n";
    else if(x >= 1400 && x < 1600) cout << "3\n";
    else if(x >= 1600 && x < 1800) cout << "2\n";
    else cout << "1\n";
    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 3800
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e10;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 100;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vector<bool> ok(n);
    rep(i,k){
        ll d,a;
        cin >> d;
        rep(i,d){
            cin >> a;
            ok[a-1] = true;
        }
    }
    ll ans = 0;
    rep(i,n) if (!ok[i]) ans++;
    PRINT(ans);
}


Measured memory_bytes: 3584
function main(input) {
    const args = input.split('\n');
    const A = parseInt(args[0], 10),
          B = parseInt(args[1], 10),
          C = parseInt(args[2], 10),
          X = parseInt(args[3], 10);

    var count = 0;

    for (var a = 0; a <= A; ++a) { //与えられた枚数以下で総当たりして結果とXが一致した場合はカウントアップ
        for (var b = 0; b <= B; ++b) {
            for (var c = 0; c <= C; ++c) {
                var sum = (a * 500) + (b * 100) + (c * 50);
                if (sum === X) ++count;
            }
        }
    }
    console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
(setq *m* 10000000000)
 
(defun calc (l)
  (+ (abs (- (nth 1 l) (nth 0 l))) (abs (- (nth 2 l) (nth 1 l)))))
 
(defun perm (now next)
  (if (equal now nil)
    (when (< (calc next) *m*) (setq *m* (calc next)))
    (dotimes (i (length now))
        (perm (append (subseq now 0 i) (nthcdr (+ i 1) now)) (append next (list (nth i now))))
        )
    )
)
 
(perm (list (read) (read) (read)) '())
(format t "~a~%" *m*)

Measured memory_bytes: 13284
#include<stdio.h>

struct Card{
  char suit;
  char value;
};

void bubble(Card A[], int n){
  int i, j;
  Card t;
  for ( i = 1; i <= n; i++ ){
    for ( j = n; j >= i+1; j-- ){
      if ( A[j].value < A[j-1].value ){
	t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(Card A[], int n){
  int i, j, mini;
  Card t;
 for ( i = 1; i <= n; i++ ){
    mini = i;
    for ( j = i; j <= n; j++ ){
      if ( A[j].value < A[mini].value ) mini = j;
    }
    t = A[i]; A[i] = A[mini]; A[mini] = t;
  }
}

void print(Card A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i >1) printf(" ");
    printf("%c%c", A[i].suit, A[i].value);
  }
  printf("\n");
}

int isStable(Card C1[], Card C2[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( C1[i].suit != C2[i].suit ) return 0;
  }
  return 1;
}

int main(){
  Card C1[101], C2[101];
  int n, i;
  char ch;

  scanf("%d\n", &n);
  for ( i = 1; i <= n; i++ ){
    scanf("%c%c ", &C1[i].suit, &C1[i].value);
  }

  for ( i = 1; i <= n; i++ ) C2[i] = C1[i];

  bubble(C1, n);
  selection(C2, n);

  print(C1, n);
  printf("Stable\n");
  print(C2, n);
  if ( isStable(C1, C2, n) ){
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.IntSummaryStatistics;
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		int[] X = new int[N];
		for (int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
		}
		IntSummaryStatistics statistics = Arrays.stream(X).summaryStatistics();
		long ceil = (long) Math.ceil(statistics.getAverage());
		long floor = (long) Math.floor(statistics.getAverage());
		long ceilSum = 0;
		long floorSum = 0;
		for (int i = 0; i < N; i++) {
			long C = X[i] - ceil;
			ceilSum += C * C;
			long F = X[i] - floor;
			floorSum += F *F;
		}

		System.out.println(Math.min(ceilSum, floorSum));
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

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

using namespace std;
using ll = long long;

#define gc getchar
int getint() { unsigned int c; int x = 0; while (((c = gc()) - '0') >= 10) { if (c == '-') return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - '0'); } while (((c = gc()) - '0') < 10); return x; }
int getstr(char *s) { int c, n = 0; while ((c = gc()) <= ' ') { if (!~c) exit(0); } do { s[n++] = c; } while ((c = gc()) > ' ' ); s[n] = 0; return n; }
template<class T> inline bool chmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<class T> inline bool chmax(T &a, T b) { return a < b ? a = b, 1 : 0; }

int n;
int s_times[555];
int srts[555], intervals[555];

int main () {

    n = getint();
    for (auto i = 0; i < n - 1; ++i) {
        s_times[i] = getint();
        srts[i] = getint();
        intervals[i] = getint();
    }
    for (auto i = 0; i < n; ++i) {
        int now = 0;
        for (auto j = i; j < n - 1; ++j) {
            auto prep = srts[j];
            chmax(now, prep);
            auto m = intervals[j];
            auto nxt = (now - prep + m - 1) / m * m + prep;
            now = nxt + s_times[j];
        }
        cout << now << endl;
    }
    return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    K,N=MI()
    A=LI()
    S=sum(A)
    L=[]
    for i in range(N-1):
        temp=A[i+1]-A[i]
        L.append(temp)
        
    L.append(A[0]+K-A[-1])
    M=max(L)
    
    print(K-M)

main()


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

int main() {
  int N, D, X;
  cin >> N >> D >> X;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin >> A[i];

  int sum = 0;
  for (int i=0; i<N; i++) {
    int j = 0;
    while (j*A[i] + 1 <= D) {
      sum++;
      j++;
    }
  }

  cout << sum + X << endl;

  return 0;
}


Measured memory_bytes: 256
require 'prime'
primes = Prime.each(102000).to_a
loop do
    n, p = gets.split.map(&:to_i)
    break if n == -1 && p == -1
    pm = primes.select{|p| p > n}[0..p]
    p pm.product(pm).map{|a| a.sort}.uniq.map{|a,b| a + b}.sort[p - 1]
end

Measured memory_bytes: 9196
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

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

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

LL lcm(LL a,LL b){
	return a*b/gcd(a,b);
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	int x;
	cin>>x;
	if(x>=30)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

int main()
{
	int x;
	cin >> x;
	unsigned long long pentas[2001];
	int a = 0, b = 0;
	for (unsigned long long i = 0; i <= 2000; i++)
	{
		pentas[i] = i * i * i * i * i;
		for (unsigned long long j = 0; j <= i; j++)
		{
			if (pentas[i] - pentas[j] == x)
			{
				a = i; b = j;
				break;
			}
			if (pentas[i] + pentas[j] == x)
			{
				a = i; b = -j;
				break;
			}
		}
	}
	cout << a << " " << b << endl;
}

Measured memory_bytes: 3616
import itertools
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
l = [i+1 for i in range(n)]
r = list(itertools.permutations(l))
j = 0
flagp = True
flagq = True
while flagp:
  if r[j] == p:
    x = j+1
    flagp = False
  j += 1
j = 0
while flagq:
  if r[j] == q:
    y = j+1
    flagq = False
  j += 1
print(abs(y-x))

Measured memory_bytes: 44912
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int getKeta(int);
int get357(int, int);
char* toString(int);
bool hasAllNum(char*);
int comp(char* str1, char* str2);

char chr[] = {'3', '5', '7'};

/* ザ・メイン
 */
int main(){
	int input = 0;
	int output = 0;

	scanf("%d", &input);

	int keta = getKeta(input);
	char* str = toString(input);

	//////////////////////////////
	// 入力ケタと同じケタの357数
	//////////////////////////////
	int max = (int)pow(3.0f, keta);
	char* str357 = new char[keta + 1];
	str357[keta] = '\0';
	for (int i = 0; i < max; i++) {
		for (int j = keta - 1; j >= 0; j--) {
			str357[keta - j - 1] = chr[(i / (int)pow(3.0f, j)) % 3];
		}
		if (hasAllNum(str357) == true && comp(str, str357) >= 0) {
			output++;
		}
	}

	//////////////////////////////
	// 入力よりも小さいケタの357数
	//////////////////////////////
	for (int i = keta - 1; i > 0; i--) {
		output += get357(i, 3);
	}

	printf("%d", output);
	return 0;
}

/* 入力された数値のケタを取得する
 * 99→2、100→3、999→3、1000→4
 */
int getKeta(int input){
	int ret = 0;
	while (input > 0) {
		ret++;
		input /= 10;
	}
	return ret;
}

/* 入力されたケタ数の357数を取得する
 * 第二引数で最低限含まれるべき数字の種類を指定する
 * 3,3→6、4,3→36
 */
int get357(int keta, int saitei){
	if (keta < 1 || keta < saitei) return 0;
	if (saitei == 0) return (int)pow(3.0f, keta);
	if (keta == 1 && saitei == 1) return 1;
	int ret = 0;
	ret += get357(keta - 1, saitei - 1) * saitei;
	ret += get357(keta - 1, saitei) * (3 - saitei);
	return ret;
}

/* 入力された数値を文字列化する
 * 123→"123"
 */
char* toString(int input){
	int keta = getKeta(input);
	char* p = (char*)malloc(keta + 1);
	for (int i = keta - 1; i >= 0; i--) {
		p[i] = '0' + input % 10;
		input /= 10;
	}
	p[keta] = '\0';

	return p;
}

/* 3と5と7をすべて含むか調べる
 */
bool hasAllNum(char* str){
	int flag3 = false;
	int flag5 = false;
	int flag7 = false;

	int index = 0;
	while(str[index] != '\0') {
		if (str[index] == '3') flag3 = true;
		else if (str[index] == '5') flag5 = true;
		else flag7 = true;

		index++;
	}

	return flag3 & flag5 & flag7;
}

/* 文字列の辞書順を比べる
 */
int comp(char* str1, char* str2){
	while (*str1 != '\0' && *str2 != '\0'){
		if (*str1 - *str2 == 0) {
			str1++;
			str2++;
			continue;
		}
		return *str1 - *str2;
	}
	return 0;
}


Measured memory_bytes: 256
#include "cstdio"
#include "algorithm"
using namespace std;
long long dp[100010];
int main(){
    int n=0;
    for(int i=1;i<=3;i++){
        int a; scanf("%d",&a);
        n=n*10+a;
    }
    if(n%4) puts("NO");
    else puts("YES");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 2002;
const int mo = 1e9 + 7;

int n, m, s[maxn], t[maxn], sum[maxn];

void add(int &a, int b) {
	a = (a+b) % mo;
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}

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

	int ans = 1;
	for (int i = 0; i < n; ++i) {
		int curSum = 1;
		for (int j = 0; j < m; ++j) {
			if (s[i] == t[j]) {

				add(ans, curSum);

				int tmp = sum[j];
				add(sum[j], curSum);
				add(curSum, tmp);
			} else
				add(curSum, sum[j]);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Read, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::str::FromStr;

// candles.rs --- Candles
// author: Seong Yong-ju <sei40kr@gmail.com>

#[allow(unused_macros)]
macro_rules! get {
  ($t:ty) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      line.trim().parse::<$t>().unwrap()
    }
  };
  ($($t:ty),*) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      let mut iter = line.split_whitespace();
      (
        $(iter.next().unwrap().parse::<$t>().unwrap(),)*
      )
    }
  };
  ($t:ty; $n:expr) => {
    (0..$n).map(|_|
                get!($t)
    ).collect::<Vec<_>>()
  };
  ($($t:ty),*; $n:expr) => {
    (0..$n).map(|_|
                get!($($t),*)
    ).collect::<Vec<_>>()
  };
  ($t:ty ;;) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      line.split_whitespace()
        .map(|t| t.parse::<$t>().unwrap())
        .collect::<Vec<_>>()
    }
  };
  ($t:ty ;; $n:expr) => {
    (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
  };
}

#[allow(unused_macros)]
macro_rules! debug {
  ($($a:expr),*) => {
    println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
  }
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("Failed to parse token")
}

#[allow(dead_code)]
fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
    let out = stdout();
    let writer = BufWriter::new(out.lock());
    f(writer);
}

fn main() {
    let (n, mut k) = get!(i32, i32);
    let xs = (0..n).map(|_| read()).collect::<Vec<i32>>();

    let mut ans = <i32>::max_value();

    if xs.contains(&0) {
        k -= 1;
    }

    let (mut xs_pos, mut xs_neg): (Vec<i32>, Vec<i32>) =
        xs.into_iter().filter(|&x| x != 0).partition(|&x| 0 <= x);
    xs_pos.insert(0, 0);
    xs_neg.reverse();
    xs_neg.insert(0, 0);

    for k_pos in 0..min(xs_pos.len(), k as usize + 1) {
        let d_pos = xs_pos[k_pos];

        let k_neg = k as usize - k_pos;
        if xs_neg.len() <= k_neg {
            continue;
        }
        let d_neg = -xs_neg[k_neg];

        ans = min(min(d_pos * 2 + d_neg, d_neg * 2 + d_pos), ans);
    }

    with_bufwriter(|mut out| writeln!(out, "{}", ans).unwrap());
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <array>
#include <string>

class Dice{
    /* left-hand dice      right-hand dice
            +---+                +---+    
            | 1 |                | 1 |    
    +---+---+---+---+    +---+---+---+---+
    | 5 | 3 | 0 | 2 |    | 5 | 2 | 0 | 3 |
    +---+---+---+---+    +---+---+---+---+
            | 4 |                | 4 |    
            +---+                +---+    
    */
    public:
    std::array<int, 6> state;
    Dice(bool isRight=false):state(std::array<int, 6>{{1, 2, (!isRight)?3:4, (!isRight)?4:3, 5, 6}}){}
    Dice(const Dice& d):state(d.state){}
    Dice(std::array<int, 6> d, bool isRight=false):state(d){if(isRight){int tmp=state[2];state[2]=state[3];state[3]=tmp;}}
    void RollTo(int d){
        /*
            0
            |
        2 --#-- 1
            |
            3
        */
        std::array<int, 6> tmp(state);
        switch(d){
            case 0: state[0] = tmp[4]; state[1] = tmp[0]; state[4] = tmp[5]; state[5] = tmp[1]; break;
            case 1: state[0] = tmp[3]; state[2] = tmp[0]; state[3] = tmp[5]; state[5] = tmp[2]; break;
            case 2: state[0] = tmp[2]; state[2] = tmp[5]; state[3] = tmp[0]; state[5] = tmp[3]; break;
            case 3: state[0] = tmp[1]; state[1] = tmp[5]; state[4] = tmp[0]; state[5] = tmp[4]; break;
        }
    }
    void RollTo(char c){
        switch(c){
            case 'N': RollTo(0); break;
            case 'E': RollTo(1); break;
            case 'W': RollTo(2); break;
            case 'S': RollTo(3); break;
        }
    }
    void Rotate(int d){
        /* 90d degrees clockwise
         -> 0 ->
        ^   |   v
        2 --#-- 1
        ^   |   v
         <- 3 <-
        */
        d%=4;
        std::array<int, 6> tmp(state);
        switch(d){
            case 0: state[1] = tmp[1]; state[2] = tmp[2]; state[4] = tmp[4]; state[3] = tmp[3]; break;
            case 1: state[1] = tmp[3]; state[2] = tmp[1]; state[4] = tmp[2]; state[3] = tmp[4]; break;
            case 2: state[1] = tmp[4]; state[2] = tmp[3]; state[4] = tmp[1]; state[3] = tmp[2]; break;
            case 3: state[1] = tmp[2]; state[2] = tmp[4]; state[4] = tmp[3]; state[3] = tmp[1]; break;
        }
    }
    bool operator==(const Dice& r)const{
        Dice t(r);
        for(int i=0; i<6; ++i){
            if(i&1) t.RollTo('E');
            else    t.RollTo('N');
            for(int j=0; j<4; ++j){
                t.Rotate(1);
                if(state == t.state) return true;
            }
        }
        return false;
    }
};  

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

    std::array<int, 6> state1;
    for(auto& i : state1){
        std::cin >> i;
    }
    Dice d1(state1, true);
    std::array<int, 6> state2;
    for(auto& i : state2){
        std::cin >> i;
    }
    Dice d2(state2, true);
    std::cout << ((d1==d2)?"Yes":"No") << "\n";
    
    return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();


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

Measured memory_bytes: 256
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

int main()
{
    int N,D,X;
    cin >> N >> D >> X;
    int A[110];
    for(int i = 0; i < N; ++i) cin >> A[i];

    int cnt = 0;
    for(int i = 0; i < N; ++i){
        int j = 0;
        while(A[i] * j + 1 <= D){
            cnt++;
            j++;
        }
    }
    cnt += X;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;
 
int main() {
  ll N;
  cin >> N;
 
  ll sum = 0;
  for (ll i = 1; i <= N; i ++) {
    if (i % 3 == 0 || i % 5 == 0) {
      continue;
    }
    sum += i;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    int h, w;
    cin >> h >> w;
    vector<vector<bool>> edge(h, vector<bool>(w, false));
    rep(i, h){
        rep(j, w){
            char c;
            cin >> c;
            if(c == '#'){
                edge[i][j] = true;
            }
        }
    }

    vector<vector<int>> mark(h, vector<int>(w));
    vector<int> d = {1, 0, -1, 0};
    int color = 0;
    rep(i, h){
        rep(j, w){
            if(mark[i][j] != 0){
                continue;
            }
            stack<pair<P, int>> st;
            st.emplace(make_pair(i, j), ++color);

            while(not st.empty()){
                int x = st.top().first.first;
                int y = st.top().first.second;
                int c = st.top().second;
                st.pop();

                if(mark[x][y] != 0){
                    continue;
                }
                mark[x][y] = c;

                rep(k, 4){
                    int nx = x + d[k];
                    int ny = y + d[k^1];

                    if(nx < 0 || nx >= h || ny < 0 || ny >= w){
                        continue;
                    }
                    if(edge[x][y] == not edge[nx][ny]){
                        st.emplace(make_pair(nx, ny), -c);
                    }
                }
            }
        }
    }

    map<int, int> m;
    rep(i, h){
        rep(j, w){
            if(m.find(mark[i][j]) == m.end()){
                m[mark[i][j]] = 0;
            }
            m[mark[i][j]]++;
        }
    }

    int ans = 0;
    for(int i = 1; i <= color; i++){
        ans += m[i] * m[-i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 18816
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    ll X, K, D;
    in3(X, K, D);

    X = abs(X);

    ll L = X / D;
    if (L <= K)
    {
        X -= L * D;
        K -= L;

        if (K % 2 == 1)
        {
            X = abs(X - D);
        }
    }
    else
    {
        X -= K * D;
    }

    outl(X);
    return 0;
}

Measured memory_bytes: 3652
import numpy as np
from sys import stdin
N,K=[int(x) for x in stdin.readline().rstrip().split()]
data=[]
for i in range(N):
    data.append(int(input()))
data.sort()
data.reverse()
ans=float("inf")
for i in range(N-K+1):
    tmp=data[i]-data[i+K-1]
    if ans > tmp:
        ans=tmp
print(ans)

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

int main(int argc, char *argv[]){
    int k;
    string s;
    cin >> k >> s;
    int c=s.size();
    if(c<=k){
        cout << s << endl;
        return 0;
    }
    string ss;
    for(int i=0;i<k;i++) cout << s[i];
    cout << "..." << endl;
    return 0;
}

Measured memory_bytes: 3624
import std.container;
import std.range;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
import std.stdio;
import std.container;

void main() {
	long n, k;
	readf("%s %s\n", &n, &k);
	auto p = readln.chomp.split(' ').map!(s => s.to!long - 1).array;
	auto c = readln.chomp.split(' ').map!(to!long).array;

	long ans = long.min;
	auto s = new long[n];

	foreach (si;0..n) {
		auto x = si;
		long total;

		s.length = 0;
		for (;;) {
			x = p[x];
			s ~= c[x];
			total += c[x];
			if (x == si) {
				break;
			}
		}

		long now;
		foreach (long i, e;s) {
			now += e;
			if (i + 1 > k) {
				break;
			}
			if (total > 0) {
				long d = (k - (i + 1)) / s.length;
				ans = max(ans, now + total * d);
			} else {
				ans = max(ans, now);
			}
		}
	}

	writeln(ans);
}


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

int main(void)
{
	int n;
	int dp[31];
	int i, j;

	while (scanf("%d", &n), n){
		memset(dp, 0, sizeof(dp));
		dp[1] = 1;
		dp[2] = 2;
		dp[3] = 4;

		for (i = 4; i <= n; i++){
			for (j = 1; j <= 3; j++){
				dp[i] += dp[i - j];
			}
		}

		if (dp[n] % 3650 == 0){
			printf("%d\n", dp[n] / 3650);
		}
		else {
			printf("%d\n", (dp[n] / 3650) + 1);
		}
	}

	return (0);
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int h = sc.nextInt();
            int w = sc.nextInt();
            if(h == 0 && w == 0){
                break;
            }
            
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    if(i != 0 && i != h - 1 && j != 0 && j != w - 1){
                        System.out.print('.');
                    }else{
                        System.out.print('#');
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 35924
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<char,int>;


int main(){
   string s;
   cin >> s;
   deque<P> deq;

   const int len = s.size();
   bool all_x = true;
   rep(i, len){
       if(s[i] == 'x')continue;
       if(s[i] != 'x')all_x = false;
       deq.push_back(P(s[i], i));
   }

   if(all_x){
       cout << 0;
       return 0;
   }

   bool f = true;
   int l, r;
   while(!deq.empty()){
       if(deq.front().first != deq.back().first)f = false;
       l = deq.front().second;
       r = deq.back().second;

       deq.pop_front();
       if(deq.empty())break;
       deq.pop_back();
   }

   if(!f){
       cout << -1 << endl;
       return 0;
   }
   else {
       int res = 0;
       while(l >= 0 || r <= len - 1){
           if(l < 0 || r > len - 1){
               res++;
               l--;
               r++;
               continue;
           }
           
           if(s[l] == s[r]){
               l--;
               r++;
           }
           else if(s[l] != s[r] && s[l] == 'x'){
               res++;
               l--;
           }
           else if(s[l] != s[r] && s[r] == 'x'){
               res++;
               r++;
           }
       }
       cout << res << endl;
       return 0;
   }
}



Measured memory_bytes: 1088
#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
int h[2010],nex[4010],to[4010],dep[2010],fa[2010],fav[2010],M;
void add(int a,int b){
	M++;
	to[M]=b;
	nex[M]=h[a];
	h[a]=M;
}
void dfs(int x){
	dep[x]=dep[fa[x]]+1;
	for(int i=h[x];i;i=nex[i]){
		if(to[i]!=fa[x]){
			fa[to[i]]=x;
			dfs(to[i]);
		}
	}
}
void col(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	while(dep[x]>dep[y]){
		fav[x]++;
		x=fa[x];
	}
	while(x!=y){
		fav[x]++;
		fav[y]++;
		x=fa[x];
		y=fa[y];
	}
}
struct rt{
	int x,y;
	rt(int a=0,int b=0){x=a;y=b;}
};
bool operator==(rt a,rt b){return a.x==b.x&&a.y==b.y;}
int d[2010],n;
vector<rt>solve(vector<rt>v){
	if(v.size()==0)return v;
	int x,u,i;
	for(x=1;x<=n;x++){
		if(d[x]==1)break;
	}
	if(x>n)return v;
	for(i=h[x];i;i=nex[i]){
		if(d[to[i]]){
			u=to[i];
			break;
		}
	}
	d[x]--;
	d[u]--;
	vector<rt>lx,nv;
	vector<int>id;
	int pos[2010];
	memset(pos,-1,sizeof(pos));
	for(i=0;i<(int)v.size();i++){
		if(v[i].x==x||v[i].y==x){
			lx.push_back(v[i]);
			id.push_back(i);
		}else{
			nv.push_back(v[i]);
			pos[i]=nv.size()-1;
		}
	}
	if(lx.size()==0)return solve(v);
	for(i=0;i+1<(int)lx.size();i+=2){
		if(lx[i].y==x)swap(lx[i].x,lx[i].y);
		if(lx[i+1].y==x)swap(lx[i+1].x,lx[i+1].y);
		if(lx[i]==lx[i+1]){
			if(v[id[i]]==v[id[i+1]])swap(v[id[i]].x,v[id[i]].y);
			continue;
		}
		nv.push_back(rt(lx[i].y,lx[i+1].y));
		pos[id[i]]=pos[id[i+1]]=nv.size()-1;
	}
	if(lx.size()&1){
		if(lx[lx.size()-1].y==x)swap(lx[lx.size()-1].x,lx[lx.size()-1].y);
		if(lx[lx.size()-1].y!=u){
			nv.push_back(rt(u,lx[lx.size()-1].y));
			pos[id[lx.size()-1]]=nv.size()-1;
		}
	}
	nv=solve(nv);
	for(i=0;i<(int)v.size();i++){
		if(pos[i]!=-1&&!(v[i].x==nv[pos[i]].x||v[i].y==nv[pos[i]].y))swap(v[i].x,v[i].y);
	}
	return v;
}
vector<rt>v;
int main(){
	int m,i,x,y,ans;
	scanf("%d%d",&n,&m);
	for(i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
		d[x]++;
		d[y]++;
	}
	dfs(1);
	for(i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		v.push_back(rt(x,y));
		col(x,y);
	}
	v=solve(v);
	ans=0;
	for(i=2;i<=n;i++)ans+=min(2,fav[i]);
	printf("%d\n",ans);
	for(rt t:v)printf("%d %d\n",t.x,t.y);
}

Measured memory_bytes: 56064
var
i,j,c,d,e:longint;
s,s1,s2:string;
n,b:qword;
begin
readln(n);
for i:=trunc(sqrt(n)) downto 1 do
if n mod i=0 then begin b:=n div i;str(b,s);write(length(s));break;end;
writeln;
end.

Measured memory_bytes: 128