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

int main(){
	int A, B, C, N;
    cin >> A >> B;
     
     C=1;
     N=0;
   
     while(C<B){
      
      C = C+A-1;
      N ++;
     }
    cout << N <<endl;
   }


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int nmax = 200;
int rmax = 8;
int n,m,r;
vint to(rmax);
vvint d(nmax,vint(nmax,INF));
vint visited(rmax,0);
vint seq(rmax,0);
int solve(int id){
    int ret=0;
    if(id==r){
        REP(i,r-1){
            ret+=d[seq[i]][seq[i+1]];
        }
        return ret;
    }
    ret = INF;
    REP(i,r){
        if(visited[i]==0){
            seq[id]=to[i];
            visited[i]=1;
            ret = min(ret,solve(id+1));
            visited[i]=0;
        }
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> r;
    REP(i,r) {
        cin >> to[i];
        to[i]--;
    }
    REP(i,n)d[i][i]=0;
    REP(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b]=c;
        d[b][a]=c;
    }
    REP(k,n){
        REP(i,n){
            REP(j,n){
                d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }
    int ans = solve(0);
    cout << ans  << endl;
    return 0;
}

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

int main()
{
	int x, y;
	cin >> x >> y;

	if (x % y == 0) cout << -1 << endl;
	else{
		for (int i = 1; ; i++) {
			if (x * i % y != 0) {
				cout << x * i << endl;
				break;
			}
		}
	}
}

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

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

    int N;
    cin >> N;

    vector<vector<int>> adj_matrix;
    adj_matrix.resize(N + 1);
    for (int i = 0; i < adj_matrix.size(); i++)
    {
        adj_matrix[i].resize(N + 1);
    }

    int e_num = (N * N - N) / 2;
    if (N % 2 == 1)
    {
        for (int i = 1; i <= N / 2; i++)
        {
            adj_matrix[i][N - i] = 1;
            adj_matrix[i][i] = 1;
            e_num--;
        }
    }
    else
    {
        for (int i = 1; i <= N / 2; i++)
        {
            adj_matrix[i][N + 1 - i] = 1;
            adj_matrix[i][i] = 1;
            e_num--;
        }
    }

    cout << e_num << endl;
    for (int i = 1; i <= N - 1; i++)
    {
        for (int j = i + 1; j <= N; j++)
        {
            if (adj_matrix[i][j] == 0)
            {
                cout << i << " " << j << endl;
            }
        }
    }

    return 0;
}

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

void Main()
{
  ll n; cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll money = 1000;
  for (int i = 1; i < n; i++) {
    if (a[i-1] < a[i]) {
      money = (money/a[i-1]) * a[i] + money % a[i-1];
    }
  }
  cout << money << endl;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 3652
if __name__ == '__main__':
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = input()
    elec = []
    point = 0
    for i in range(k):
        if t[i] == "r":
            point += p
            elec.append("r")
        if t[i] == "s":
            point += r
            elec.append("s")
        if t[i] == "p":
            point += s
            elec.append("p")

    for i in range(k, n):
        if elec[i - k] == t[i]:
            if i < n - k:
                elec.append(" ")
        else:
            if t[i] == "r":
                point += p
                elec.append("r")
            if t[i] == "s":
                point += r
                elec.append("s")
            if t[i] == "p":
                point += s
                elec.append("p")
    print(point)


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

using namespace std;

const int MAX_V = 8;
vector<int> G[MAX_V + 1];
int ans = 0;
bool used[MAX_V + 1];

void dfs(int n, int no_used) {
    used[n] = true;

    if (no_used == 0) ans++;

    for (int i = 0; i < G[n].size(); i++) {
        if (!used[G[n][i]]) {
            dfs(G[n][i], no_used - 1);
        }
    }
    used[n] = false;
}

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

    for (int i = 0; i < M; i++) {
        int a, b;
        scanf("%d %d", &a, &b);

        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs(1, N - 1);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

int main()
{
	fastio;
	lli n,x,y,i;
	cin>>n;
	lli a[n],b[n];
	for(i=0;i<n;i++)
		cin>>x>>y , a[i]=x+y , b[i]=x-y ;
	sort(a,a+n);
	sort(b,b+n);
	cout<<max(a[n-1]-a[0],b[n-1]-b[0]);
	return 0;
}


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

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

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

const ll MAX = 100010;

int main(int argc, char **argv)
{
	ll n; cin >> n;
	ll h[MAX];
	ll dp[MAX];

	for (ll i = 0; i < n; ++i)
		cin >> h[i];

	for (ll i = 0; i < MAX; ++i) dp[i] = INF;

	dp[0] = 0;
	for (ll i = 1; i < n; ++i)
	{
		chmin(dp[i], abs(h[i]-h[i-1]) + dp[i-1]);
		if (i != 1) chmin(dp[i], abs(h[i]-h[i-2])+dp[i-2]);
	}

	std::cout << dp[n-1] << std::endl;
}


Measured memory_bytes: 1792
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m;
  cin >> n >> m;
  vll cnt(n, 1), flg(n, 0);
  flg[0] = 1;
  rep(i, m) {
    ll x, y;
    cin >> x >> y;
    x--, y--;
    cnt[x]--, cnt[y]++;
    if (flg[x]) flg[y] = 1;
    if (cnt[x] == 0) flg[x] = 0;
  }
  ll soooz = 0;
  rep(i, n) if (flg[i]) soooz++;
  
  cout << soooz << endl;

  return 0;
}


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


int main()
{
   int a,b,c,t;cin>>a>>b>>c;
   t=b;b=a;a=t;
   t=c;c=a;a=t;
   cout<<a<<" "<<b<<" "<<c;
}


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

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

int main()
{
    int N, W;
    scanf("%d%d", &N, &W);
    int wv[N][2];
    for (int i = 0; i < N; ++i) scanf("%d%d", &wv[i][0], &wv[i][1]);

    long int dp[N+1][W+1];
    for (int i = 0; i < N+1; ++i)
    {
        for (int j = 0; j < W+1; ++j)
        {
            dp[i][j] = 0;
        }
    }

    for (int i = 0; i < N; ++i)
    {
        int w = wv[i][0];
        int v = wv[i][1];
        for (int sum_weight = 0; sum_weight < W+1; ++sum_weight)
        {
            if (sum_weight-w >= 0)
            {
                dp[i+1][sum_weight] = max(dp[i+1][sum_weight], dp[i][sum_weight-w] + v);
        }
        dp[i+1][sum_weight] = max(dp[i+1][sum_weight], dp[i][sum_weight]);
        }
    }

    printf("%ld\n", dp[N][W]);

    return 0;
}

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

int main(){
    int h,w,ans=0;
    cin >> h >> w;
    int c[10][10];
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin >> c[i][j];
        } 
    }
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                c[i][j] = min(c[i][j],c[i][k]+c[k][j]);
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int a;
            cin >> a;
            if(a==-1) continue;
            if(a!=1) ans += c[a][1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import bisect

N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
n = min(N, K)
for A in range(n+1):
    for B in range(n-A+1):
        if not A and not B:
            continue
        if not A:
            AB = V[-B:]
        elif not B:
            AB = V[:A]
        else:
            AB = V[:A] + V[-B:]

        AB.sort()
        idx = bisect.bisect_left(AB, 0)
        k = K - (A + B)
        ans = max(ans, sum(AB[min(k, idx):]))

print(ans)

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

#define ll long long
#define ar array

int main() {
	int n;
	cin >>n;
	string a;
	cin >> a;
	if(a.size()>n) {
		for(int i=0;i<n;i++) {
			cout << a.at(i);
		}cout << "...";
	}else{
		cout << a;
	}
}



Measured memory_bytes: 3632
num = list(map(int,input().split()))
count5 = 0
count7 = 0
for i in num:
    if i == 5:
        count5 += 1
    elif i == 7:
        count7 += 1
    else:
        continue
if count5 == 2 and count7 == 1:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e5;
int main(){
  ll N; cin >> N;
 
  vector<vector<int>> to(N);
  
  vector<vector<int>> dist(N,vector<int>(N,inf));
  for(int i = 0; i < N; i++){ dist[i][i] = 0;}
  
  for(ll i = 0; i < N; i++){
    for(ll j = 0; j < N; j++){
      char c; cin >> c; 
      if( c == '1'){ to[i].push_back(j);
                     dist[i][j] = 1;
                   }
    }
  }
  
  vector<ll> visited(N,-1);
  
  queue<int> Q; Q.push(0);
  while(!Q.empty()){
    int p = Q.front(); Q.pop();
    
    for(auto u : to[p]){
      
      if( visited[u] != -1){ //-1は未到達
        if( visited[u] == visited[p]){ 
          cout << -1 << endl; return 0;} //この時、二部graph構成不可
        else{ continue;}
      }
      
      visited[u] = visited[p]+1;
      Q.push(u);
    }
  }
  
  //ここを通過すれば、二部グラフと言える
  //次に、最長の直径を求める
  
  // Warshall - Floyd
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
      }
    }
  }
  
  int res = 0;
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      res = max(res, dist[i][j]);
    }
  }
  
  cout << res+1 << endl; return 0;}
  
  
        
  

Measured memory_bytes: 640
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int bit = 0;
        for (int i=0; i<N; i++) {
            bit |= sc.nextInt();
        }
        System.out.println(Integer.numberOfTrailingZeros(bit));
    }
}

Measured memory_bytes: 21588
#include<iostream>
#include<vector>
#include<algorithm>

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

bool xdp[8001][20000];
bool ydp[8001][20000];
int os=10000;

int main(){

  string s;
  cin >> s;
  int x,y;
  cin >> x >> y;
  int n = s.length();
  int cur = 0;
  vector<int> f(n,0);
  rep(i,n){
    if (s[i] == 'T'){
      cur++;
    } else {
      f[cur]++;
    }
  }

  rep(i,n){
    for(int k=-8000;k<8001;k++){
      xdp[i][os+k]=false;
      ydp[i][os+k]=false;
    }
  }

  xdp[0][os+f[0]]=true;
  ydp[0][os]=true;

  rep(i,n-1){
    for(int k=-8000;k<8001;k++){
      if(i%2==0){
        xdp[i+1][os+k]=xdp[i][os+k];
        ydp[i+1][os+k]=ydp[i][os+k-f[i+1]] | ydp[i][os+k+f[i+1]];
      } else {
        xdp[i+1][os+k]=xdp[i][os+k-f[i+1]] | xdp[i][os+k+f[i+1]];
        ydp[i+1][os+k]=ydp[i][os+k];
      }
    }
  }
  if (xdp[n-1][os+x]&ydp[n-1][os+y]){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 312832
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll dp[1<<22],n,a[25][25];
ll count(ll mask){
    ll ret=0;
    while(mask){
        if(mask&1) ++ret;
        mask>>=1;
    }
    return ret;
}
ll foo(ll mask){
    ll person = count(mask)+1;
    // cout<<person<<"-"<<mask<<" ";
    if(person==n+1) return 1;
    ll a1;
    if(dp[mask]!=-1) return dp[mask];
    dp[mask]=0;
    for(a1=1;a1<=n;++a1){
        if(a[person][a1]){
            if(!(mask&1<<(a1-1))){
                dp[mask]=(dp[mask]+foo(mask|(1<<(a1-1))))%mod;
            }
        }
    }
    return dp[mask];
}
int main(){
    ll a1,a2;
    cin>>n;
    for(a1=1;a1<=n;++a1) for(a2=1;a2<=n;++a2) cin>>a[a1][a2];
    memset(dp,-1,sizeof(dp));
    cout<<foo(0);
    return 0;
}

Measured memory_bytes: 33024
#include <iostream>
#include <cstring>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
#define foR(i,x,y) for(register int i=(x); i>=(y); i--)
using namespace std;
const int maxn=4e3+10;
typedef long long ll;
char s[maxn];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    cin>>s+1;
    ll cnt1,cnt2,cnt3,ans=0;
    cnt1=cnt2=cnt3=0;
    For(i,1,n)
    {
        if(s[i]=='R')cnt1++;
        else if(s[i]=='G')cnt2++;
        else cnt3++;
    }
    ans=cnt1*cnt2*cnt3;
    For(i,1,n)
    {
        for(int j=1; i+j+j<=n; j++)
        {
            if((s[i]^s[i+j]^s[i+j*2])==('R'^'G'^'B'))ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD=998244353;

int dp[5000][5000];
int r,b;

signed main(){
  string s;cin>>s;
  int N=s.size();
  /*
  どんなのなら作れるかを考えるタイプ
  1個目は1人目が持っているやつ
  2個目は前2人が持っているやつ（ただし1個目で使われたやつは無理）
  dp[i]:現在赤のボールをi個使っている時の場合の数
  dp[i][j]:i個目のボールを配って赤いボールをj個消費した時の場合の数
  */
  dp[0][0]=1;
  for(int i=1;i<=2*N;i++){
    if(i<=N){
      if(s[i-1]=='0')r+=2;
      if(s[i-1]=='1')r+=1,b+=1;
      if(s[i-1]=='2')b+=2;
    }
    for(int j=0;j<4005;j++){
      if(i-j<=b)dp[i][j]+=dp[i-1][j];//青いボールを配る
      if(j+1<=r)dp[i][j+1]+=dp[i-1][j];//赤いボールを配る
      dp[i][j]%=MOD;dp[i][j+1]%=MOD;
    }
  }
  cout<<dp[2*N][r]<<endl;
}


Measured memory_bytes: 157696
import java.io.*;
import java.util.*;

public class Main{


	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner();
		PrintWriter out=new PrintWriter(System.out);
		int n=sc.nextInt();
		double ans=0;
		while(n-->0) {
			double x=sc.nextDouble();
			ans+=sc.next().equals("BTC")?x*380000.0:x;
			
		}
		out.println(ans);
		out.close();
	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		Scanner(String fileName) throws FileNotFoundException{
			br=new BufferedReader(new FileReader(fileName));
		}
		String next() throws IOException {
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		String nextLine() throws IOException {
			return br.readLine();
		}
		int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		long nextLong()  throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


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

template<typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n=0){
        initialize(n);
    }

    void initialize(int nin){
        n = nin;
        dat.assign(n, 0);
    }

    T sum(int i){
        T s = 0;
        while(i >= 0){
            s += dat[i];
            i = (i & (i+1)) - 1;
        }
        return s;
    }

    T sum_between(int i, int j){
        return sum(j) - sum(i-1);
    }

    void plus(int i, T x){
        while(i < n){
            dat[i] += x;
            i |= i+1;
        }
    }

    // a[0]+...+a[ret] >= x
    int lower_bound(T x){
        if(x < 0) return -1;
        int ret = -1;
        int k = 1;
        while(2*k <= n) k <<= 1;
        for( ;k>0; k>>=1){
            if(ret+k < n && dat[ret+k] < x){
                x -= dat[ret+k];
                ret += k;
            }
        }
        return ret + 1;
    }
};

int main(){
    int N, Q;
    cin >> N >> Q;
    BIT<int64_t> bit(N);
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        bit.plus(i, a);
    }
    while(Q--){
        int t, a, b;
        cin >> t >> a >> b;
        if(t == 0){
            bit.plus(a, b);
        }else{
            cout << bit.sum_between(a, b-1) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 8216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+7;
int a[N];
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int s,n;
	cin>>s>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	if(n==1||n==0){
		cout<<0<<endl;
		return 0;
	}
	int maxl = 0;
	for(int i=1;i<n;i++){
		maxl = max(maxl,a[i]-a[i-1]);
	}
	maxl = max(maxl,a[0]+s-a[n-1]);
	cout<<s - maxl<<endl;
}

Measured memory_bytes: 4392
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <cstdlib>
#include <map>

using namespace std;
#define ll long long

vector<int> par;
vector<int> rnk;
void init(int n) {
    par.clear();
    rnk.clear();
    for(int i = 0; i < n; i++) {
        par.push_back(i);
        rnk.push_back(0);
    }
}
int find(int x) {
    if(par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}
void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(rnk[x] < rnk[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if(rnk[x] == rnk[y]) rnk[x]++;
    }
}
bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> X, Y;
    map<pair<int, int>, int> m;
    int x, y;
    for(int i = 0; i < N; i++) {
        cin >> x >> y;
        X.push_back(make_pair(x, y));
        Y.push_back(make_pair(y, x));
        m[make_pair(x, y)] = i;
    }
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    vector<tuple<int, int, int>> tpl;
    int d;
    d = min(abs(X[1].first - X[0].first), abs(X[1].second - X[0].second));
    tpl.push_back(make_tuple(d, m[make_pair(X[1].first, X[1].second)], m[make_pair(X[0].first, X[0].second)]));
    d = min(abs(Y[1].first - Y[0].first), abs(Y[1].second - Y[0].second));
    tpl.push_back(make_tuple(d, m[make_pair(Y[1].second, Y[1].first)], m[make_pair(Y[0].second, Y[0].first)]));
    d = min(abs(X[N - 2].first - X[N - 1].first), abs(X[N - 2].second - X[N - 1].second));
    tpl.push_back(make_tuple(d, m[make_pair(X[N - 2].first, X[N - 2].second)], m[make_pair(X[N - 1].first, X[N - 1].second)]));
    d = min(abs(Y[N - 2].first - Y[N - 1].first), abs(Y[N - 2].second - Y[N - 1].second));
    tpl.push_back(make_tuple(d, m[make_pair(Y[N - 2].second, Y[N - 2].first)], m[make_pair(Y[N - 1].second, Y[N - 1].first)]));
    for(int i = 1; i < N - 1; i++) {
        d = min(abs(X[i + 1].first - X[i].first), abs(X[i + 1].second - X[i].second));
        tpl.push_back(make_tuple(d, m[make_pair(X[i].first, X[i].second)], m[make_pair(X[i + 1].first, X[i + 1].second)]));
        d = min(abs(X[i - 1].first - X[i].first), abs(X[i - 1].second - X[i].second));
        tpl.push_back(make_tuple(d, m[make_pair(X[i].first, X[i].second)], m[make_pair(X[i - 1].first, X[i - 1].second)]));
        d = min(abs(Y[i + 1].first - Y[i].first), abs(Y[i + 1].second - Y[i].second));
        tpl.push_back(make_tuple(d, m[make_pair(Y[i].second, Y[i].first)], m[make_pair(Y[i + 1].second, Y[i + 1].first)]));
        d = min(abs(Y[i - 1].first - Y[i].first), abs(Y[i - 1].second - Y[i].second));
        tpl.push_back(make_tuple(d, m[make_pair(Y[i].second, Y[i].first)], m[make_pair(Y[i - 1].second, Y[i - 1].first)]));
    }
    sort(tpl.begin(), tpl.end());
    init(N);
    ll ans = 0;
    for(int i = 0; i < tpl.size(); i++) {
        if(!same(get<1>(tpl[i]), get<2>(tpl[i]))) {
            unite(get<1>(tpl[i]), get<2>(tpl[i]));
            ans += get<0>(tpl[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18008
#include<iostream>
using namespace std;
int main(){
	int n,q;
	cin >> n >> q;
	string s;
	cin >> s;
	int sum[n];
	for(int i=0;i<n;i++){
		if(i==0) sum[i]=0;
		else if(s[i-1]=='A' && s[i]=='C') sum[i]=sum[i-1]+1;
		else sum[i]=sum[i-1];
	}

	for(int i=0;i<q;i++){
		int l,r;
		cin >> l >> r;
		l--,r--;
		cout << sum[r]-sum[l] << endl;
	}
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#ifdef TOPOLOGY
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
using namespace std;

int n, a;
map<int, int> cnt;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		cnt[a]++;
	}
	long long ans = 0;
	vector<int> two;
	for (auto &p : cnt) {
		if (p.second >= 2) {
			if (p.second >= 4) ans = max(ans, 1LL * p.first * p.first);
			two.push_back(p.first);
		}
	}
	sort(two.begin(), two.end(), greater<int>());
	if (two.size() > 1) {
		ans = max(ans, 1LL * two[0] * two[1]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll in(ll x)
{
    ll cnt=0;
    while(x)
    {
        x/=10;
        cnt++;
    }
    return cnt;
}
int main()
{
    ll n;
    scanf("%lld",&n);
    ll mid=sqrt(n),ans=1e9;
    for(int i=1;i<=mid;i++)
    {
        if(n%i==0)
        {
            ll cnt=max(in(i),in(n/i));
            ans=min(ans,cnt);
        }
    }
    printf("%lld\n",ans);
}


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

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << "\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

void solve(){
    int n;
    cin >> n;
    vi h(n);
    for(auto &it: h) cin >> it;

    vi dp(n, 1e9+5);
    dp[0] = 0;
    for(int i = 1; i < n; ++i){
        for(int j = max(i-2, 0); j < i; ++j){
            dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]));
        }
    }
    cout << dp[n-1] << "\n";
}

int main()
{
    Fast;
    //louisfghbvc{
        solve();
    //}
    return 0;
}


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

string s;
int st[20001];
int st_lmax[20001];
int st_rmax[20001];
int ed[20001];

int dy(char c) {
	if (c == '/') return 1;
	if (c == '_') return 0;
	return -1;
}

int main() {
	cin >> s;
	
	int i, n = s.length();
	
	st[0] = 0;
	for (i = 0; i < n; i++) {
		st[i + 1] = st[i] + dy(s[i]);
	}
	
	st_lmax[0] = st[0];
	for (i = 1; i < n + 1; i++) {
		st_lmax[i] = max(st_lmax[i - 1], st[i]);
	}
	
	st_rmax[n] = st[n];
	for (i = n - 1; i >= 0; i--) {
		st_rmax[i] = max(st_rmax[i + 1], st[i]);
	}
	
	for (i = 0; i < n + 1; i++) {
		ed[i] = min(st_lmax[i], st_rmax[i]);
	}
	
	//Answer
	vector<int> ans;
	int area = 0;
	for (i = 1; i < n + 1; i++) {
		area += ed[i - 1] - st[i - 1] + ed[i] - st[i];
		if (st[i - 1] != ed[i - 1] && st[i] == ed[i]) {
			ans.push_back(area / 2);
			area = 0;
		}
	}
	
	int ssum = 0;
	for (i = 0; i < ans.size(); i++) ssum += ans[i];
	
	cout << ssum << endl;
	cout << ans.size();
	for (i = 0; i < ans.size(); i++) {
		cout << " " << ans[i];
	}
	cout << endl;
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    string str = to_string(N);
    string res;

    if(str.find("7") != string::npos){
        res = "Yes";
    } else {
        res = "No";
    }

    cout << res << endl;

    return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m)==0)break;
			int[] a = new int[n];
			int s = 0;
			for(int i=0;i<n;i++){
				a[i] = sc.nextInt();
				s+=a[i];
			}
			Arrays.sort(a);
			int b = 0;
			for(int i=n-1;i>=0;i--){
				b++;
				if(b%m==0)s-=a[i];
			}
			System.out.println(s);
		}
	}
}

Measured memory_bytes: 52732
//written by libra9z
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cmath>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define repit(it,a) for (__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define RET(x) return writefln(x)*0
#define ITR(...) __VA_ARGS__::iterator
#define all(a) (a).begin(),(a).end()
#define reunique(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define sz(a) (int)a.size()
#define MP(...) make_pair(__VA_ARGS__)
#define X first
#define Y second
#define sqr(x) ((x)*(x))
#define fill_inf(a) memset(a,-19999873,sizeof(a))
#define fill_neginf(a) memset(a,-19999872,sizeof(a))
#define fill_0(a) memset(a,0,sizeof(a))
#define fill_neg1(a) memset(a,-1,sizeof(a))
#define pow_of_2(a) (1<<(a))
#define is_pow_of_2(a) (((a-1)&a)==0)
#define printtime cerr<<"\n\nTime elasped : "<<clock()*1.0/1000<<" seconds.\n\n"
const int inf=1e9;
const long long lnf=1e18;
const int mod=1e9+7;
const int Maxn=4005;
char c[Maxn][5];
int pos[2][Maxn];
int dp[Maxn][Maxn];
int cost[Maxn][Maxn][2];
int n,a[Maxn],tp[Maxn];
int small[Maxn][Maxn][2];
int biger[Maxn][Maxn][2];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie();cout.tie();
	cout<<setprecision(15);
	cin>>n;
	for (int i=1;i<=2*n;i++)
	{
		cin>>c[i]>>a[i];
		if (c[i][0]=='B') tp[i]=1;
		pos[tp[i]][a[i]]=i;
	}
	for (int i=1;i<=2*n;i++)
	{
		if (i) for (int j=0;j<=n;j++)
		{
			small[i][j][0]=small[i-1][j][0];
			small[i][j][1]=small[i-1][j][1];
			biger[i][j][0]=biger[i-1][j][0];
			biger[i][j][1]=biger[i-1][j][1];
		}
		for (int j=0;j<a[i];j++) small[i][j][tp[i]]++;
		for (int j=a[i];j<=n;j++) biger[i][j][tp[i]]++;
	}
	for (int i=0;i<=n;i++) for (int j=0;j<=n;j++)
	{
		if (i==n) continue;
		int nwpos=-1;
		if (pos[0][i+1]<=i+j) nwpos=i+j+small[pos[0][i+1]][i][0]+small[pos[0][i+1]][j][1];
		else nwpos=pos[0][i+1]+i-biger[pos[0][i+1]][i][0]+j-biger[pos[0][i+1]][j][1];
		cost[i][j][0]=nwpos-i-j-1;
	}
	for (int i=0;i<=n;i++) for (int j=0;j<=n;j++)
	{
		if (j==n) continue;
		int nwpos=-1;
		if (pos[1][j+1]<=i+j) nwpos=i+j+small[pos[1][j+1]][i][0]+small[pos[1][j+1]][j][1];
		else nwpos=pos[1][j+1]+i-biger[pos[1][j+1]][i][0]+j-biger[pos[1][j+1]][j][1];
		cost[i][j][1]=nwpos-i-j-1;
	}
	for (int i=0;i<=n;i++) for (int j=0;j<=n;j++)
	{
		if (!i && !j) continue;
		dp[i][j]=inf;
		if (i) dp[i][j]=min(dp[i][j],dp[i-1][j]+cost[i-1][j][0]);
		if (j) dp[i][j]=min(dp[i][j],dp[i][j-1]+cost[i][j-1][1]);
	}
	cout<<dp[n][n]<<endl;
	return 0;
}

Measured memory_bytes: 345600
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int N;
    string S;
    cin >> N >> S;
    // WWWWBBBB
    // ....####
    vector<int> left(N+2, 0);
    vector<int> right(N+2, 0);
    for(int i = 0; i < N; i++) {
        if (S[i] == '#')
            left[i+1] = left[i] + 1;
        else
            left[i+1] = left[i];
    }
    for(int i = N-1; i >= 0; i--) {
        if (S[i] == '.') {
            right[i+1] = right[i+2] + 1;
        } else
            right[i+1] = right[i+2];
    }
    /*
    for(int i = 0; i <= N+1; i++)
        cout << left[i] << " ";
    cout << endl;
    for(int i = 0;i <= N+1; i++)
        cout << right[i] << " ";
    cout << endl;*/
    int ans = INT_MAX;
    for(int i = 1; i <= N+1; i++) {
        ans = min(ans, left[i-1]+right[i]);
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 2704
//  aoj-VolumeICPCOOC2015-C  / 2015-11-29
#include<iostream>
#include<vector>
#include<cassert>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<tuple>
#include<array>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef ll int__;
#define rep(i,j) for(int__ i=0;i<(int__)(j);i++)
#define repeat(i,j,k) for(int__ i=(j);i<(int__)(k);i++)
#define all(v) v.begin(),v.end()

template<typename T>ostream& operator << (ostream &os , const vector<T> &v){
    rep(i,v.size()) os << v[i] << (i!=v.size()-1 ? " " : "\n"); return os;
}

template<typename T>ostream& operator << (ostream &os , const set<T> &v){
    os << "[";
    for(T i : v) os << i << " ";
    os << "]" << endl;
    return os;
}

template<typename T>istream& operator >> (istream &is , vector<T> &v){
    rep(i,v.size()) is >> v[i]; return is;
}

#ifdef DEBUG
void debug(){ cerr << endl; }
#endif
template<class F,class...R> void debug(const F &car,const R&... cdr){
#ifdef DEBUG
    cerr << car << " "; debug(cdr...);
#endif
}

typedef vector<vector<int>> Edgelist;

set<int> get_neighbors(const Edgelist &E,int s,int dist){
    set<int> state[2];
    state[0].insert(s);
    rep(i, dist){
        set<int> &pre = state[ i%2 ],
                 &now = state[ (i+1)%2 ];
        now.clear();
        for(int pv : pre){
            for(int nxt : E[pv]){
                now.insert(nxt);
            }
        }
        //debug("get",dist,i+1,now);
    }
    return state[dist%2];
}

set<int> get_intersection(int n,array<set<int>,3> &sets){
    vector<int> cnt(n,0);
    rep(i,3){
        for(int v : sets[i]){
            cnt[v]++;
        }
    }
    set<int> ret;
    rep(i,n)if(cnt[i]==3)ret.insert(i);
    return ret;
}

bool solve(){
    int n,m; cin >> n >> m;
    array<int,3> abc; rep(i,3) cin>>abc[i];
    Edgelist E(n);
    rep(i,m){
        int a,b; cin >> a >> b;
        --a;--b;
        E[b].push_back(a); // reversed edge
    }
    debug(E);
    
    set<int> goals;
    array<set<int>,3> neighbors;
    vector<bool> visited(n);
    vector<int> dist(n,-1);
    goals.insert(n-1);
    int pre_goals_size = 0;
    int turn = 1;
    while(pre_goals_size != (int)goals.size()){
        pre_goals_size = goals.size();
        set<int> goals_clone = goals;
        for(int v : goals_clone){
            if(visited[v])continue;
            visited[v] = true;
            rep(i,3){
                set<int> tmp = get_neighbors(E, v, abc[i]);
                neighbors[i].insert( all(tmp) );
                debug(i,neighbors[i]);
            }
        }

        set<int> intersection = get_intersection(n,neighbors);
        debug(intersection);
        for(int ng : intersection){
            if(not goals.count(ng)){
                dist[ng] = turn;
                goals.insert(ng);
            }
        }
        turn++;
    }

    if(dist[0] < 0) cout << "IMPOSSIBLE" <<endl;
    else cout << dist[0] << endl;
    
    return false;
}

int main()
{
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}

Measured memory_bytes: 3236
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> vi;
struct edge { int v; ll w; };

const int MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
ll INF = INT_MAX;

struct skew_heap {
	skew_heap *lch, *rch;
	int val;
	skew_heap(int _val) : lch(NULL), rch(NULL), val(_val) {}
};

skew_heap* meld(skew_heap* x, skew_heap* y) {
	if (!x) return y;
	if (!y) return x;
	if (x->val < y->val) swap(x, y);
	x->rch = meld(x->rch, y);
	swap(x->lch, x->rch);
	return x;
}

skew_heap* push(skew_heap* x, int val) {
	return meld(x, new skew_heap(val));
}

skew_heap* pop(skew_heap* x) {
	skew_heap* y = meld(x->lch, x->rch);
	delete x;
	return y;
}

int main() {
	skew_heap* pq = NULL;
	for (;;) {
		char s[10]; scanf("%s", s);
		if (s[2] == 's') {
			int x; scanf("%d", &x);
			pq = push(pq, x);
		}
		if (s[2] == 't') {
			printf("%d\n", pq->val);
			pq = pop(pq);
		}
		if (s[2] == 'd') break;
	}
}

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

using namespace std;

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

    if (s == "A") {
        cout << "T" << endl;
    }
    else if (s == "T") {
        cout << "A" << endl;
    }
    else if (s == "C") {
        cout << "G" << endl;
    }
    else {
        cout << "C" << endl;
    }
}

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

using namespace std;

int n, m, q;
vector <int> quad[55];
long long int ans = 0;

void solve(int i, vector <int> v)
{
    if (i == n)
    {
        long long int s = 0;

        for (int j = 0; j < q; j++)
        {
            int a = quad[j][0];
            int b = quad[j][1];
            int c = quad[j][2];
            int d = quad[j][3];

            if (v[b-1] - v[a-1] == c)
            {
                s += d;
            }
        }

        ans = max(ans, s);

        return;
    }

    for (int j = 1; j <= m; j++)
    {
        int last = -1;

        if (!v.empty())
            last = v[v.size()-1];

        if (j < last)
            continue;

        v.push_back(j);
        solve(i+1, v);
        v.pop_back();
    }
}

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

    for (int i = 0; i < q; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            int x;
            cin >> x;
            quad[i].push_back(x);
        }
    }

    solve(0, vector <int>());

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3636
from statistics import mean, median,variance,stdev
import sys
import math
import fractions

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())




#n = ip()                              #入力整数1つ
a,b= (int(i) for i in input().split())      #入力整数横2つ
#k,a,b = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
l = []
for x in range(10):
    for y in range(10):
        for z in range(10):
            l.append([str(z)])
            l.append([str(z),str(z)])
            l.append([str(y),str(z),str(y)])
            l.append([str(y),str(z),str(z),str(y)])
            l.append([str(x),str(y),str(z),str(y),str(x)])
clist = []

for i in range(len(l)):
    d  = l[i]
    e = ''.join(d)
    clist.append(e)
c = set(clist)
l = list(c)
s = 0
for i in range(len(l)):
    if a <= int(l[i]) and int(l[i]) <= b: s+=1
print(s)

Measured memory_bytes: 7192
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;	//参考書の数
    int M;	//学びたいアルゴリズムの数
    int X;	//目標理解度
    int[] C;	//参考書の値段
    int[][] A;	//参考書によって上がる理解度の値
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.N = sc.nextInt();
        this.M = sc.nextInt();
        this.X = sc.nextInt();
        C = new int[N];
        A = new int[N][M];
        for (int i=0; i<N; i++) {
        	C[i] = sc.nextInt();
        	for (int j=0; j<M; j++) {
        		A[i][j] = sc.nextInt();
        	}
        }
    }
    
    //解答処理
    private int solve() {   
        List<Integer> list = new ArrayList<>();
        int cost = -1;
        
        //bit全探索
        for (int i = 0; i < 1<<N; i++) {      	
        	int tmpC = 0;	//金額保持
        	int[] tmpA = new int[M];	//理解度保持
        	boolean judge = true;
        	for (int j = 0; j < N; j++) {
        		if ((1 & i >> j) == 1) { //購入
        			for (int k = 0; k < M; k++) {
        				tmpA[k] += A[j][k];
        			}
        			tmpC += C[j];	//金額の加算
        		}
        	}
        	for (int j = 0; j < M; j++) {
        		if (tmpA[j] < X) {	//理解度が目標に達していなければfalse
        			judge = false;
        			break;
        		}
        	}
        	if (judge) {	//目標に達していればリストに格納
        		list.add(tmpC);
        	}
        }
        
        if (!list.isEmpty()) {
        	Collections.sort(list);
        	cost = list.get(0);
        }
        return cost;
    }
    
    //出力
    public void show(int answer) {
        System.out.println(answer);
    }

}


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

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

  long long ans = 1;
  for (long long i = 1; i < N + 1; i++) {
    ans = ans * i % (long long)(pow(10, 9) + 7);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000000
#define VMAX 10000

int main(){
  unsigned short *A, *B;

  int C[VMAX+1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for ( i = 0; i <= VMAX; i++ ) C[i] = 0;

  for ( i = 0; i < n; i++ ){
    scanf("%hu", &A[i + 1]);
    C[A[i + 1]]++;
  }

  for ( i = 1; i <= VMAX; i++ ) C[i] = C[i] + C[i - 1];

  for ( j = 1; j <= n; j++ ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 8464
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String t = scanner.nextLine();

        if (s.length() + 1 == t.length() && t.substring(0, t.length() - 1).equals(s)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

using namespace std;

int c[3][3] , a1,a2 ,b1,b2 ;

int main()
{
    for (int i = 0 ; i < 3 ; ++ i)
        for (int j = 0 ; j < 3 ; ++ j){
            cin >> c[i][j] ;}
    a1 = c[0][0]-c[1][0];
    a2 = c[0][0]-c[2][0];
    b1 = c[0][0]-c[0][1];
    b2 = c[0][0]-c[0][2];
    for (int i = 0 ; i < 3 ; ++ i){
        if (c[0][i]-c[1][i]!=a1){
            cout << "No" ;
            return 0 ;
        }
    }
    for (int i = 0 ; i < 3 ; ++ i){
        if (c[0][i]-c[2][i]!=a2){
            cout << "No" ;
            return 0 ;
        }
    }
    for (int i = 0 ; i < 3 ; ++ i){
        if (c[i][0]-c[i][1]!=b1){
            cout << "No" ;
            return 0 ;
        }
    }
    for (int i = 0 ; i < 3 ; ++ i){
        if (c[i][0]-c[i][2]!=b2){
            cout << "No" ;
            return 0 ;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
use std::collections::HashSet;

fn read_line() -> String {
    use std::io;
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

fn main() {
    let mut s = HashSet::new();
    let n = read_line().trim_right().parse::<i32>().unwrap();
    for _ in 0..n {
        s.insert(read_line());
    }
    println!("{}", s.len());
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

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

	auto len = (int)L.length();
	auto mod = (unsigned long long)1e9 + 7;
	vector<unsigned long long> num;
	num.push_back(1);
	for (auto i = 0; i < len; ++i)
	{
		num.push_back(num[i] * 3 % mod);
	}

	auto result = 1ull;
	for (auto i = len - 1; i >= 0; --i)
	{
		if (L[i] != '1')
		{
			continue;
		}

		if (i == len - 1)
		{
			result = 3;
		}
		else
		{
			result = result * 2 % mod;
			result = (result + num[len - i - 1]) % mod;
		}
	}
	cout << result << endl;

	return 0;
}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 100005;

i64 n;

string s;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> s;

    i64 R = 0;
    char c = '!';


    for (i64 i = 0; i < n; i++) {
        if (c != s[i]) {
            c = s[i];
            R += 1;
        }
    }

    cout << R;
    return 0;
}

Measured memory_bytes: 512
# ABC143 D - Triangles
import bisect

def lower_bound(sorted_list, value):
    return bisect.bisect_left(sorted_list, value)


N = int(input())
L = list(map(int,input().split()))

L = sorted(L)

count = 0

for a in range(N):
    for b in range(a+1,N):
        count += lower_bound(L, L[a] + L[b]) - (b + 1)
            
print(count)


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

int main(){
    int N;  cin >> N;
    vector<vector<int>> c(10, vector<int>(10, 0));
    for(int i=1; i<=N; i++){
        string str = to_string(i);
        int top = str[0] - '0';
        int bottom = str[str.length() - 1] - '0';
        c[top][bottom]++;
    }

    ll ans = 0;
    for(int i=1; i<=9; i++) for(int j=1; j<=9; j++){
        ans += c[i][j] * c[j][i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Random;
import java.util.Scanner;

public class Main {
    static int d = 365;
    static int[] c = new int[26];
    static int[][] s = new int[d][26];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random random = new Random();
        sc.nextInt();
        for (int i=0;i<26;i++){
            c[i]=sc.nextInt();
        }
        for (int i=0;i<d;i++){
            for (int j=0;j<26;j++){
                s[i][j]=sc.nextInt();
            }
        }
        int[] contest = new int[d];
        int count = 75000;
        for (int i=0;i<d;i++)contest[i]=random.nextInt(26);
        for (int i=0;i<count;i++){
            int[] instance = contest.clone();
            int times = 1;
            int[] choose = new int[times];
            for (int j=0;j<times;j++)choose[j]=random.nextInt(d);
            for (int j=0;j<times;j++)instance[choose[j]]=random.nextInt(26);

            if (function(contest)<=function(instance)){
                contest=instance;
            }else {
                double r = random.nextDouble();
                double num = Math.pow(Math.E,-(function(instance)-function(contest))/r);
                if (r<=num)contest=instance;
            }
        }
        for (int i=0;i<d;i++)System.out.println(contest[i]+1);
    }
    static long function(int[] contest){
        long satisfaction = 0;
        int[] interval = new int[26];
        for (int i=0;i<d;i++){
            satisfaction+=s[i][contest[i]];
            for (int j=0;j<26;j++)interval[j]++;
            interval[contest[i]]=0;
            for (int j=0;j<26;j++)satisfaction-=c[j]*interval[j];
        }
        return  satisfaction;
    }
}


Measured memory_bytes: 60208
# -*- coding: utf-8 -*-
a = int(input())
from collections import defaultdict
d = defaultdict(int)

for _ in range(a):
    d[input()]+=1
d_max = max(d.values())
ret_d = [k for k,v in d.items() if v==d_max]
ret_d.sort()
for i in ret_d:
    print(i)

Measured memory_bytes: 32484
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
typedef long long ll;

int main() {
  int n,m ;
  cin >> n >> m;
  vector<bool> A(n+1,true);
  for(int i=0;i<m;i++){
    int b;
    cin >> b;
    A.at(b) = false;
  }
  vector<ll> B(n+1,1);
  for(int i=1;i<n+1;i++){
    if(i==1){
      if(A.at(i)){
        B.at(i) = B.at(i-1);
      }else{
        B.at(i) = 0;
      }
    }else{
      if(A.at(i)){
        B.at(i) = (B.at(i-1)%mod+B.at(i-2)%mod)%mod;
      }else{
        B.at(i) = 0;
      }
    }
  }
  cout << B.at(n) << endl;
}
      
    
   
    
  
             

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

using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> x;
  while (n>0) {
    x.push_back(n%10);
    n/=10;
  }
  if (x[0] == x[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

mindist = a[n - 1]

for j in range(n - 1):
    dist = int(abs(a[n - 1] / 2 - a[j]))
    if dist < mindist:
        aj = a[j]
        mindist = dist

print(a[n - 1], aj)

Measured memory_bytes: 14052