akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define kill _z_kill
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outv(x) cerr<<#x" = "<<x<<"  "
#define outtag(x) cerr<<"--------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
	For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
#define User_Time ((double)clock()/CLOCKS_PER_SEC)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned uint;
typedef long double LD;
typedef vector <int> vi;
typedef pair <int,int> pii;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
//const int mod=998244353;
//int Pow(int x,int y){
//	int ans=1;
//	for (;y;y>>=1,x=(LL)x*x%mod)
//		if (y&1)
//			ans=(LL)ans*x%mod;
//	return ans;
//}
//void Add(int &x,int y){
//	if ((x+=y)>=mod)
//		x-=mod;
//}
//void Del(int &x,int y){
//	if ((x-=y)<0)
//		x+=mod;
//}
//int Add(int x){
//	return x>=mod?x-mod:x;
//}
//int Del(int x){
//	return x<0?x+mod:x;
//}
unordered_map <LL,LL> dp;
LL n,A,B,C,D;
LL DP(LL n){
	if (n==0)
		return 0;
	if (n==1)
		return D;
	if (dp.count(n))
		return dp[n];
	LL res=(1e18/n)>=D?n*D:1e18;
	res=min(res,min(DP(n/2)+A+D*(n%2),
			n==2?(LL)1e18:(DP(n/2+1)+A+D*(2-n%2))));
	res=min(res,min(DP(n/3)+B+D*(n%3),DP(n/3+1)+B+D*(3-n%3)));
	res=min(res,min(DP(n/5)+C+D*(n%5),DP(n/5+1)+C+D*(5-n%5)));
	return dp[n]=res;
}
void Solve(){
	n=read(),A=read(),B=read(),C=read(),D=read();
	dp.clear();
	cout<<DP(n)<<endl;
}
int main(){
	int T=read();
	while (T--)
		Solve();
	return 0;
}

Measured memory_bytes: 4136
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
  int n,k;
  cin >> n >> k;
  int x[1000000];
  FOR(i,n){
    cin >> x[i];
  }
  int ans=1e9;
  FOR(i,n-k+1){
    chmin(ans,x[i+k-1]-x[i]+min(abs(x[i+k-1]-0),abs(x[i]-0)));
  }
  cout << ans << endl;
}


Measured memory_bytes: 2688
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>


using namespace std;
struct Node
{
  int key;
  Node *parent, *left, *right;
};

Node *root;

void insert(int k)
{
  Node *y = NULL;  //parent of the node to be inserted
  Node *x = root; //traverse the tree
  Node *z = new Node;
  z->key = k;
  z->left = NULL;
  z->right = NULL;

  //find the parent of z
  while (x != NULL)
  {
    y = x;
    if (z->key < x->key)
    {
      x = x->left;
    }
    else
    {
      x = x->right;
    }
  }

  z->parent = y;

  if (y == NULL)
  {
    root = z; //handle the case of z being the first inserted node
  }
  else
  {
    if (z->key < y->key)
    {
      y->left = z;
    }
    else
    {
      y->right = z;
    }
  }
}

void inorder(Node *u)
{
  if (u == NULL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u)
{
  if (u == NULL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main()
{
  int n, x;
  string com;
  scanf("%d", &n);

  while (n--)
  {
    cin >> com;
    if (com == "insert")
    {
      scanf("%d", &x);
      insert(x);
    }
    else if (com == "print")
    {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 26736
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sort stable_sort
#define all(x) (x).begin(),(x).end()
#define rep(i,x) for (int (i)=(1);(i)<=(x);(i)++)
#define rep2(i,x) for (int (i)=(x);(i)>=(1);(i)--)
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
using namespace std;
long long n,A,b,f[5005],pos[5005],ans,a[5005],c[5005];
int main(){
	ans=0x7f7f7f7f7f7f7f7fll;
	cin>>n>>A>>b;
	rep(i,n) f[i]=ans;
	rep(i,n){
		cin>>a[i];
		pos[a[i]]=i;
	}
	rep(i,n){
		c[i]=c[i-1]+(i<a[i]?A:b);
	}
	rep(i,n){
		long long s=0;
		for (int j=i-1;j>=0;j--){
			if (a[j]<a[i]){
				f[i]=min(f[i],f[j]+s);
				s+=b;
			} else {
				s+=A;
			}
		}
		ans=min(ans,f[i]+(n-i)*b);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	if (a == b && a != c || b == c && b != a || c == a && c != b) {
		cout << 2 << endl;
	}
	else if (a == b && b == c) {
		cout << 1 << endl;
	}
	else cout << 3 << endl;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		FastReader in = new FastReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		char[] c = in.next().toCharArray();
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < c.length - 2; i++) {
			int x = Integer.parseInt(c[i] + "" + c[i + 1] + "" + c[i + 2]);
			ans = Math.min(ans, Math.abs(x-753));
		}
		out.println(ans);

		out.flush();
		out.close();

	}

	static class FastReader {
		StringTokenizer st;
		BufferedReader br;

		public FastReader(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public FastReader(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}

}

Measured memory_bytes: 20948
from math import ceil
N = int(input())
S = input()
ans = [0]*1000
one = [0]*10
two = [0]*100

for s in S:
    s = int(s)
    for i in range(10):
        for j in range(10):
            if two[i*10+j]//1:
                ans[i*100+j*10+s] = 1 
            else:
                if one[i]//1 and two[i*10+s] == 0:
                    two[i*10+s] = 0.5
                elif one[s] == 0:
                    one[s] = 0.5        
    one = list(map(lambda x: ceil(x), one))
    two = list(map(lambda x: ceil(x), two))

print(sum(ans))

Measured memory_bytes: 9300
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <utility>

using namespace std;

using ll = long long;

bool comp(pair<string,int> a, pair<string,int> b) {
    return a.second < b.second;
}

int main(){

  int N;
  cin >> N;
  unordered_map<std::string, int> mp; 
  string str;
  for(int i = 0; i < N; ++i){
    cin >> str;
    auto itr = mp.find(str);
    if(itr != mp.end()) {
      ++mp[str];
    } else {
      mp[str] = 1;
    }
  }

  vector<pair<string, int>> elems(mp.begin(), mp.end());
  sort(elems.begin(), elems.end(), comp);

  int max = -1;
  for(auto itr = elems.begin(); itr != elems.end(); ++itr){
    if(max < (*itr).second){
      max = (*itr).second;
    }
  }

  vector<string> ans;

  for(auto itr = elems.begin(); itr != elems.end(); ++itr){
    if(max == (*itr).second){
      ans.push_back((*itr).first);
    }
  }

  sort(ans.begin(), ans.end());  
  
  for(auto s : ans){
    cout << s << endl;
  }


  return 0;
}


Measured memory_bytes: 31684
#include <stdio.h>

void Check(int *a,int *b){
	int check=0;
	if(*a>*b){
		check=*a;
		*a=*b;
		*b=check;
	}
}
	
int main(){
	int x,y,i;
	
	for(i=0;i<3000;i++){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0){
			return 0;
		}
		Check(&x,&y);
		printf("%d %d\n",x,y);
	}
	return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  cout << max(0, min(B, D) - max(A, C)) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

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

int main(){
    string a; cin >> a; queue<char> sa;
    rep(i, a.size()) sa.push(a[i]);
    string b; cin >> b; queue<char> sb; 
    rep(i, b.size()) sb.push(b[i]);
    string c; cin >> c; queue<char> sc;
    rep(i, c.size()) sc.push(c[i]);
    char turn='a';
    while(1){
        if(turn == 'a'){
            if(sa.empty()) break;
            turn = sa.front();
            sa.pop();
        }else if(turn == 'b'){
            if(sb.empty()) break;
            turn = sb.front();
            sb.pop();
        }else if(turn == 'c'){
            if(sc.empty()) break;
            turn = sc.front();
            sc.pop();
        }
    }
    cout << char(int(turn)-32) << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main() {
  int A, B, C;

  cin >> A >> B >> C;
  int sum = 0;
  for (int i = 0; i <= B; i++) {
    sum += A;
    int remainder = sum % B;

    if (remainder == C) {
      //cout << i << "," << sum << "," << remainder << "[got]" <<endl;
      cout << "YES" << endl;
      return 0;
    } else {
      //cout << i << "," << sum << "," << remainder << endl;
    }
  }
  cout << "NO" << endl;
}


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

int N, X;
int M[101];
int M_min = 1000; 

int main() {
    cin >> N >> X;
    for (int i = 0; i < N; ++i){
      cin >> M[i];
      X = X - M[i];
      if(M[i] <= M_min) M_min = M[i];
    }

    int count = N;
    count += X/M_min;  
  
    cout << count << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;
string a, b;
int main(){
	cin >> a >> b;
	if(a.length() > b.length())  cout << "GREATER" << endl;
	else if(a.length() < b.length())  cout << "LESS" << endl;
	else {
		if(a > b) cout << "GREATER" << endl;
		else if(a < b) cout << "LESS " << endl;
		else cout << "EQUAL" << endl;
	}
	return 0;
}

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

const long long INF = 1000000000000000;

int n, q, a, b, p, c, i;
long long tree[2][800005], ans[200005], add = 0, res = INF;

void build_tree(int l, int r, int ind)
{
    if (l == r)
    {
        tree[0][ind] = ans[l] - l;
        tree[1][ind] = ans[l] + l;
    }
    else
    {
        build_tree(l, (l + r) / 2, 2 * ind);
        build_tree((l + r) / 2 + 1, r, 2 * ind + 1);
        tree[0][ind] = min(tree[0][2 * ind], tree[0][2 * ind + 1]);
        tree[1][ind] = min(tree[1][2 * ind], tree[1][2 * ind + 1]);
    }
}

void update(int l, int r, int a, int ind)
{
    if (r < a || l > a)
        return;
    else if (l == a && r == a)
    {
        tree[0][ind] = ans[l] - l;
        tree[1][ind] = ans[l] + l;
    }
    else
    {
        update(l, (l + r) / 2, a, 2 * ind);
        update((l + r) / 2 + 1, r, a, 2 * ind + 1);
        tree[0][ind] = min(tree[0][2 * ind], tree[0][2 * ind + 1]);
        tree[1][ind] = min(tree[1][2 * ind], tree[1][2 * ind + 1]);
    }
}

long long abs(long long t)
{
    return (t < 0) ? -t : t;
}

long long query(int l, int r, int L, int R, int nom, int ind)
{
    if (r < L || l > R)
        return INF;
    else if (L <= l && r <= R)
        return tree[nom][ind];
    else return min(query(l, (l + r) / 2, L, R, nom, 2 * ind), query((l + r) / 2 + 1, r, L, R, nom, 2 * ind + 1));
}

int main()
{
    scanf("%d%d%d%d", &n, &q, &a, &b);
    fill(ans + 1, ans + n + 1, INF);
    scanf("%d", &p);
    ans[a] = abs(b - p);
    ans[b] = abs(a - p);
    q--;
    build_tree(1, n, 1);
    while (q--)
    {
        scanf("%d", &c);
        add += abs(c - p);
        ans[p] = min(ans[p], min(query(1, n, 1, c - 1, 0, 1) + c, query(1, n, c, n, 1, 1) - c) - abs(c - p));
        update(1, n, p, 1);
        p = c;
    }
    for (i = 1; i <= n; i++)
        res = min(res, ans[i]);
    printf("%lld", res + add);
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end(), greater<ll>());

    if (N % 2 == 0) {
        ll ans = 0;
        rep(i, N / 2 - 1) ans += A[i] * 2;
        ans += A[N / 2 - 1];
        ans -= A[N / 2];
        for (int i = N / 2 + 1; i < N; i++) ans -= A[i] * 2;
        cout << ans << endl;
    } else {
        ll ans1 = 0;
        rep(i, N / 2 - 1) ans1 += A[i] * 2;
        ans1 += A[N / 2 - 1] + A[N / 2];
        for (int i = N / 2 + 1; i < N; i++) ans1 -= A[i] * 2;

        ll ans2 = 0;
        rep(i, N / 2) ans2 += A[i] * 2;
        ans2 -= A[N / 2] + A[N / 2 + 1];
        for (int i = N / 2 + 2; i < N; i++) ans2 -= A[i] * 2;

        cout << max(ans1, ans2) << endl;
    }
}

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

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")   */


//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 2e6 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 2e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

int ost[N], sum[N];


signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, p;
    string s;
    cin >> n >> p >> s;
    int ans = 0;
    if (p == 2 || p == 5) {
        for (int i = n - 1; i >= 0; i--) {
            if ((s[i] - '0') % p == 0) ans += i + 1;
        }
    }
    else {
        ost[0] = 1;
        int tek = 1;
        for (int i = n - 1; i >= 0; i--) {
            sum[i] = (sum[i + 1] + ((s[i] - '0') * tek) % p) % p;
            tek = (tek * 10) % p;
            ans += ost[sum[i]]++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 4244
/**
 *    author:  tourist
 *    created: 24.01.2020 23:39:31       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  set<char> t;
  for (char c : s) {
    t.insert(c);
  }
  if ((t.find('N') != t.end()) != (t.find('S') != t.end())) {
    cout << "No" << '\n';
    return 0;
  }
  if ((t.find('W') != t.end()) != (t.find('E') != t.end())) {
    cout << "No" << '\n';
    return 0;
  }
  cout << "Yes" << '\n';
  return 0;
}


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

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  int num=0,sum=0;
  for (int i = 1; i <=n; i++)
  {
    /* code */
    int t=i;
    for (int j = 0; j <5; j++)
    {
      /* code */
      num+=t%10,t/=10;
    }
    
    if (num>=a&&num<=b)
    {
      /* code */
      sum+=i;
    }
    num=0;
    
  }
  cout<<sum<<endl;
  
  }

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

int main(int argc, char *argv[]){
    int n;
    cin >> n;
    int a[n];
    long long s=0;
    long long c=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        s+=a[i];
        s%=1000000007;
    }
    for(int i=0;i<n;i++){
        s-=a[i];
        if(s<0) s+=1000000007;
        c+=a[i]*s;
        c%=1000000007;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 4392
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string a, b, c; cin >> a >> b >> c;
	reverse(all(a));
	reverse(all(b));
	reverse(all(c));
	int turn = 0;
	while (1) {
		if (turn == 0) {
			if (a.empty())break;
			else {
				turn = a[a.size() - 1] - 'a';
				a.pop_back();
			}
		}
		else if (turn == 1) {
			if (b.empty())break;
			else {
				turn = b[b.size() - 1] - 'a';
				b.pop_back();
			}
		}
		else {
			if (c.empty())break;
			else {
				turn = c[c.size() - 1] - 'a';
				c.pop_back();
			}
		}
	}
	char ans = 'A' + turn;
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"
#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"

int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll min(ll a,ll b){return (a<b?a:b);}
ll max(ll a,ll b){return (a>b?a:b);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}

int main(){
  ll L,R; cin>>L>>R;
  ll r = 2019;
  if(R-L>=2019){
    r = 0;
  } else{
    bool fin = false;
    for(ll i=L;i<=R-1;i++){
      for(ll j=i+1;j<=R;j++){
        r = min((i*j)%2019,r);
        if(r==0){fin = true;break;}
      }
      if(fin) break;
    }
  }
  cout << r <<"\n";
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100

void Bubble(int N,int *A){

  int i;
  int cnt = 0;
  int temp;
  int flag;

  flag = 1;
  while(flag){
    flag = 0;
    for(i = N-1;i >=1;i--){
      if(A[i] < A[i-1]){
	temp = A[i];
	A[i] = A[i-1];
	A[i-1] = temp;
	cnt++;
	flag = 1;
      }
    } 
  }

  for(i = 0;i < N-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[N-1]);
  printf("%d\n",cnt);
}

int main(){

  int i;
  int num;
  int A[MAX];

  scanf("%d",&num);

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

  Bubble(num,A);

  return 0;
}

Measured memory_bytes: 600
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**5+1)
def dfs(p):
  for edge in g[p]:
    if x[edge[0]] is not None:
      if x[edge[0]]-x[p]!=edge[1]:
        print('No')
        exit()
    else:
      x[edge[0]]=x[p]+edge[1]
      dfs(edge[0])
n,m=map(int,input().split())
g=[[] for i in range(n)]
for i in range(m):
  u,v,c=map(int,input().split())
  g[u-1].append((v-1,c))
  g[v-1].append((u-1,-c))
x=[None]*n
for i in range(n):
  if x[i]==None:
    x[i]=0
    dfs(i)
print('Yes')

Measured memory_bytes: 128912
#include"bits/stdc++.h"
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vector<int> x;
	for(int i=0;i!=n;++i){
		int temp;
		cin>>temp;
		x.push_back(temp);
	}
	sort(x.rbegin(),x.rend());
	int ans=0;
	for(int i=0;i!=k;++i)
		ans+=x[i];
	cout<<ans;
}

Measured memory_bytes: 384
N = int(input())
S = list(input())
INF = int(1e6)

nE = S.count("E")
nW = N - nE

lnW = 0
ans = INF

for i in S:
    if i == "W":
        nW -= 1
        ans = min(ans, nE + lnW)
        lnW += 1
    else:
        nE -= 1
        ans = min(ans, nE + lnW)

print(ans)


Measured memory_bytes: 5920
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007
 
string s;

void one() {
	s += '1';
}
void zero() {
	s += '0';
}
void back() {
	if (s.length() > 0) {
		s.pop_back();
	}
}

int main() {
	string x;
	cin >> x;
	for (int i = 0; i < x.length(); i++) {
		if (x[i] == '1')one();
		else if (x[i] == '0')zero();
		else if (x[i] == 'B')back();
	}
	print(s);





	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b;
    cin >> a >> b;
    if ((a * b) % 2 == 0) cout << "Even" << endl;
    else cout << "Odd" << endl;
    return 0;
}


Measured memory_bytes: 256
def inpl(): return list(map(int, input().split()))
N, M = inpl()
if N > M:
    N, M = M, N

if N > 1:
    print((N-2)*(M-2))
elif M > 1:
    print(M-2)
else:
    assert N == M == 1
    print(1)

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

vector<int> x;

int main()
{
	int n, sum = 0, temp;
	cin >> n;
	for(int i = 1; i <= n; ++i)
	{
		cin >> temp;
		x.push_back(temp);
		sum += temp;
	}
	temp = ((double)sum / n + 0.5);
	int ans = 0;
	for(int i = 0; i < x.size(); ++i)
		ans += (x[i] - temp) * (x[i] - temp);
	cout << ans << endl;
}

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

int main(int argc, char *argv)
{
    int n, c;

    scanf("%d", &n);

    c = 0;
    while (n > 0) {
        if (n % 10 == 2) {c++;}
        n /= 10;
    }

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

    return 0;
}


Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	A, B, C, D := ReadInt(), ReadInt(), ReadInt(), ReadInt()
	fmt.Println(B - A + 1 - (g(A, B, C) + g(A, B, D) - g(A, B, LCM(C, D))))
}

func f(n, x int) int {
	return (n-1)/x + 1
}

func g(A, B, x int) int {
	return f(B+1, x) - f(A, x)
}

func LCM(a, b int) int {
	return a / GCD(a, b) * b
}
func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1844
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        List<Integer> l = new ArrayList<>();
        List<Integer> r = new ArrayList<>();
        for (int i = 0; i < q; i++) {
            l.add(sc.nextInt());
            r.add(sc.nextInt());
        }
        int[] sum = new int[n];
        sum[0] = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                sum[i] = sum[i - 1] + 1;
                continue;
            }
            sum[i] = sum[i - 1];
        }
        for (int i = 0; i < q; i++) {
            int left = l.get(i) - 1;
            int right = r.get(i) - 1;
            int ans = sum[right] - sum[left];
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 102124
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    a, b, h = ii(), ii(), ii()
    print(((a + b) * h) // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10108
w, h, n = map(int, input().split())
p = [tuple(map(int, input().split())) for _ in range(n)]

x1 = 0
y1 = 0
x2 = w
y2 = h

for x, y, a in p:
    if a == 1:
        if x > x1:
            x1 = x
    elif a == 2:
        if x < x2:
            x2 = x
    elif a == 3:
        if y > y1:
            y1 = y
    elif a == 4:
        if y < y2:
            y2 = y

if x2-x1 > 0 and y2-y1 > 0:
    print((x2-x1)*(y2-y1))
else:
    print(0)


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


int main()
{
   int n, k;
   string s="";
   cin>>n;
   cin>>s;
   cin>>k;

   char ch = s[k-1];
   for(int i=0;i<n;i++)
   {
     if(s[i]==ch)
     cout<<s[i];
     else if(s[i]!=ch)
     cout<<"*";

   }
   cout<<endl;
   return 0;
   
}


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

#define INIT_CAP 10
#define INF 1000000000

typedef struct {
	int to, w;
} Edge;

typedef struct {
	Edge *elem;
	int cap, size;
} VecEdge;

typedef struct {
	int num, d;
} PairNumDis;

VecEdge adj[10000];
PairNumDis heap[500000];
int hsize;
int d[10000];
// int prev[10000];

void init(int n) {
	while (n--)
		adj[n] = (VecEdge){malloc(sizeof(Edge) * INIT_CAP), INIT_CAP, 0};
}

void add(int from, int to, int w) {
	if (adj[from].size == adj[from].cap) {
		adj[from].cap <<= 1;
		adj[from].elem = realloc(adj[from].elem, sizeof(Edge) * adj[from].cap);
	}
	adj[from].elem[adj[from].size++] = (Edge){to, w};
}

void insert(int num, int d) {
	int i;
	for (i = hsize++; i > 0 && d < heap[i - 1 >> 1].d; i = i - 1 >> 1)
		heap[i] = heap[i - 1 >> 1];
	heap[i] = (PairNumDis){num, d};
}

int calcNextIdx(int i) {
	return i * 2 + 1 + (i * 2 + 2 < hsize && heap[i * 2 + 1].d > heap[i * 2 + 2].d);
}

PairNumDis delete(void) {
	int i;
	int nextIdx;
	const PairNumDis root = heap[0], last = heap[--hsize];

	for (i = 0; i * 2 + 1 < hsize && last.d > heap[nextIdx = calcNextIdx(i)].d; i = nextIdx)
		heap[i] = heap[nextIdx];
	heap[i] = last;

	return root;
}

void dijkstra(int n, int s) {
	int i;

	for (i = 0; i < n; i++)
		d[i] = INF;

	d[s] = 0;
	insert(s, 0);
	while (hsize > 0) {
		PairNumDis fromPair;

		fromPair = delete();
		if (fromPair.d > d[fromPair.num])
			continue;

		for (i = 0; i < adj[fromPair.num].size; i++) {
			Edge e = adj[fromPair.num].elem[i];
			if (fromPair.d + e.w < d[e.to]) {
				d[e.to] = fromPair.d + e.w;
				insert(e.to, d[e.to]);
			}
		}
	}
}

int main(void) {
	int i, j;
	int n;

	scanf("%d", &n);

	init(n);
	for (i = 0; i < n; i++) {
		int u, k;
		scanf("%d %d", &u, &k);
		while (k--) {
			int v, c;
			scanf("%d %d", &v, &c);
			add(u, v, c);
			// add(v, u, c);
		}
	}

	dijkstra(n, 0);

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

	return 0;
}

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

void ckmax (int64_t &x, int64_t a) {
	x = max(x, a);
}

struct edge {
	int u, v, w;
	
	edge (int a, int b, int c) {
		u = a, v = b, w = c;
	}
};

const int64_t inf = 1e18 + 13;

int n, m, p;
vector < edge > edges;
vector < vector < int > > gr, g;

vector < bool > bfs (int root) {
	vector < bool > used(n + 1, 0);
	queue < int > q;
	used[root] = 1;
	q.push(root);
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		for (int v: g[u]) {
			if (!used[v]) {
				used[v] = 1;
				q.push(v);
			}
		}
	}
	return used;
}

vector < bool > bfsr (int root) {
	vector < bool > used(n + 1, 0);
	queue < int > q;
	used[root] = 1;
	q.push(root);
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		for (int v: gr[u]) {
			if (!used[v]) {
				used[v] = 1;
				q.push(v);
			}
		}
	}
	return used;
}

void ford_iteration (vector < int64_t > &d) {
	for (edge e: edges) 
		ckmax(d[e.v], d[e.u] + e.w);
}

signed main () {
	cin >> n >> m >> p;
	edges.assign(m, edge(0, 0, 0));
	g.resize(n + 1);
	gr.resize(n + 1);
	for (int i = 0; i < m; ++i) {
		int u, v, w;
		cin >> u >> v >> w;
		edges[i] = edge(u, v, w - p);
		g[u].push_back(v);
		gr[v].push_back(u);
	}
	vector < int64_t > d(n + 1, -inf);
	d[1] = 0;
	for (int i = 0; i < n; ++i)
		ford_iteration(d);
	vector < bool > reachable = bfs(1);
	vector < bool > reachabler = bfsr(n);
	vector < int64_t > d_new = d;
	ford_iteration(d_new);
	bool fucked = 0;
	for (int i = 1; i <= n; ++i) 
		fucked |= ((d[i] != d_new[i] && reachabler[i] && reachable[i]));
	ckmax(d[n], 0);
	if (fucked)
		d[n] = -1;
	cout << d[n] << '\n';
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 





int main() {
  int ans = INF;
  int d, g;
  cin >> d >> g;
  vi p(d), c(d);
  rep(i,d) cin >> p[i] >> c[i];
  rep(i, 1<<d) {
    vector<bool> used(d, false);
    int score = 0;
    int num = 0;
    int maxUsable = -1;
    rep(j, d) {
      if ((1<<j) & i) {
        used[j] = true;
        score += p[j] * 100 * (j+1);
        score += c[j];
        num += p[j];
      } else {
        chmax(maxUsable, j);
      }
    }    
    if (score < g) {
      int want = g-score;
      int z = ceil(want/(double)((maxUsable+1)*100));
      if (z >= p[maxUsable]) {
        continue;
      } else {
        score += (maxUsable+1) * 100 * z;
      }
      num += z;
    }
    chmin(ans, num);
  }
  cout << ans << endl;  
  return 0;
}

Measured memory_bytes: 3600
#import sys
#input = sys.stdin.readline
def main():
    N, K = map( int ,input().split())
    A = list( map(int, input().split()))
    dp = [False]*(K+1)
    for i in range(A[0],K+1):
        for a in A:
            if a > i:
                break
            dp[i] |= not dp[i-a]
    if dp[K]:
        print("First")
    else:
        print("Second")
if __name__ == '__main__':
    main()


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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;
    vector<int> p(n + 1);
    for (int i = 1; i <= n; ++i) cin >> p[i];

    int cnt = 0;
    for (int i = 2; i <= n; ++i)
        if (p[i - 1] == i - 1 && p[i] == i) {
            ++cnt;
            swap(p[i - 1], p[i]);
        }

    for (int i = 2; i <= n; ++i)
        if (p[i - 1] == i - 1 || p[i] == i) {
            ++cnt;
            swap(p[i - 1], p[i]);
        }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 640
import java.util.*;
 
public class Main {
    
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        if(n>= 1 && n<=999){
            System.out.println("ABC");
        }
        else if(n>=1000 && n<=1998){
            System.out.println("ABD");
        }
 
    }
}

Measured memory_bytes: 23764
///not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair< int, pair<int, int> >
#define plpll pair< ll, pair<ll, ll> >

const int maxn = 1000* 100 + 5;
bool mrk[maxn];
int cn[maxn];

int32_t main(){
    int n, m;
    cin >>n >>m;
    for(int i = 0; i < n; i ++)
        cn[i] = 1;
    mrk[0] = true;
    for(int i = 0; i < m; i ++){
        int x, y;
        cin >>x >>y;
        x --;
        y --;
        if(cn[x] > 0){
            cn[y] ++;
            cn[x] --;
            if(mrk[x])
                mrk[y] = true;
            if(cn[x] == 0)
                mrk[x] = false;
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i ++){
        if(mrk[i])
            ans ++;
    }
    cout <<ans <<endl;
    return false;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e12;

template<typename T>
bool is_prime(T _Num){
    if(_Num < 2)return false;
    if(_Num % 2 == 0){
        if(_Num == 2)return true;
        else return false;
    }
    bool prime = true;
    for(int i = 3; i <= sqrt(_Num); i += 2){
        if(_Num % i == 0){
            prime = false;
            break;
        }
    }
    return prime;
}

int main(){
    long long cnt = 0;
    vector<long long> prime(1010000, 0);
    for(int i = 1; i < 1010000; i++){
        if(is_prime(i))cnt++;
        prime[i] = cnt;
    }
    
    while(true){
        int n = 0;
        cin >> n;
        if(n == 0)break;
        cout << prime[n] << endl;
    }
    return 0;
}


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

int
primep (
  int n
  )
{
  int i;

  for ( i = 2; i * i <= n; ++i )
  {
    if ( n % i == 0 )
      return ( 0 );
  }

  return ( 1 );
}

int
main (
  int   argc,
  char *argv[ ]
  )
{
  for ( ; ; )
  {
    int n;

    scanf ( "%d", &n );
    if ( n == 0 )
      break ;

    if ( n % 2 == 0 )
      --n;

    for ( ; ; )
    {
      if ( primep ( n ) && primep ( n - 2 ) )
        break ;

      n -= 2;
    }
    printf ( "%d %d\n", n - 2, n );
  }


  return ( EXIT_SUCCESS );
}

Measured memory_bytes: 596
n = int(input())
l = list(map(int,input().split()))
l.append(1000000000)
m = 'Yes'
for i in range(0,n-1):
  if l[n-i-1] <= l[n-i]:
    continue
  elif l[n-i-1] > l[n-i] + 1:
    m = 'No'
    break
  else:
    l[n-i-1] = l[n-i-1] - 1

print(m)


Measured memory_bytes: 14252
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define eps 0.00000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define f(n) for(int i=0;i<n;++i)
#define REP(i,n) for(long long i = 0;i < n;++i)
pair<long long,long long> seg[700000][2] = {};
const long long hogehoge = 262144;
pair<long long,long long> seg_find(long long left, long long right, long long w_l, long long w_r, long long now, long long a) {
	if (w_r <= left || right <= w_l) return make_pair(LONG_INF,0);
	if (w_l <= left&&right <= w_r) return seg[now][a];
	pair<long long, long long> ac = seg_find(left, (left + right) / 2, w_l, w_r, now * 2, a);
	pair<long long, long long> ad = seg_find((left + right) / 2, right, w_l, w_r, now * 2 + 1, a);
	if (ac.first > ad.first) {
		return ad;
	}
	else {
		return ac;
	}
}
long long seg_set(long long n,long long a) {
	seg[n][a] = min(seg[2*n][a],seg[2*n+1][a]);
	if (n != 1) seg_set(n / 2, a);
	return 0;
}
int main() {
#define int long long
	iostream::sync_with_stdio(false);
	int n;
	cin >> n;
	REP(i, n) {
		int a;
		cin >> a;
		seg[i + hogehoge][0] = make_pair(LONG_INF,i);
		seg[i + hogehoge][1] = make_pair(LONG_INF,i);
		seg[i + hogehoge][i % 2].first = a;
		seg_set((i + hogehoge) / 2, 0);
		seg_set((i + hogehoge) / 2, 1);
	}
	priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> nya;
	nya.push(make_tuple(0, 0, n));
	while (nya.empty() == false) {
		tuple<int, int, int> now = nya.top();nya.pop();
			pair<int, int> wow = seg_find(0, hogehoge, get<1>(now), get<2>(now), 1, get<1>(now) % 2);
			pair<int, int> hoge = seg_find(0, hogehoge, wow.second + 1, get<2>(now),1,(wow.second + 1) % 2);
			cout << wow.first << " ";
			cout << hoge.first << " ";
			if (get<1>(now) != wow.second) {
				nya.push(make_tuple(seg_find(0, hogehoge, get<1>(now), wow.second, 1, get<1>(now) % 2).first, get<1>(now), wow.second));
			}
			if (wow.second + 1 != hoge.second) {
				nya.push(make_tuple(seg_find(0, hogehoge, wow.second + 1, hoge.second, 1, (wow.second + 1) % 2).first, wow.second + 1, hoge.second));
			}
			if (hoge.second + 1 != get<2>(now)) {
				nya.push(make_tuple(seg_find(0, hogehoge, hoge.second + 1, get<2>(now), 1, (hoge.second + 1) % 2).first, hoge.second + 1, get<2>(now)));
			}
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 18548
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

struct edge{
	int to, cost;
	edge(int to_, int cost_){
		to = to_; cost = cost_;
	}
};
const int MAX_N = 101;
const int MAX_M = 1001;
const int INF = 1e+8;
vector<edge> G[MAX_N];
// memo[k][v] := テゥツ?づァツつケ v テ」ツ?セテ」ツ?ァテ」ツ?淌」ツ?ゥテ」ツつ甘ァツ敖?」ツ?湘」ツ?ョテ」ツ?ォ k テ・ツ崢榲」ツつィテ」ツδε」ツつクテ」ツ?ョテ」ツつウテ」ツつケテ」ツδ暗」ツつ?0 テ」ツ?ォテ」ツ?療」ツ?淌ァツ環カテヲツ?凝」ツつ津ヲツ篠「テァツエツ「テ」ツ?療」ツ?淌」ツ?凝」ツ?ゥテ」ツ??」ツ??
bool memo[MAX_M][MAX_N];
int n, m, c;

struct State{
	// cost := テ」ツつウテ」ツつケテ」ツδ? e := テ」ツつィテ」ツδε」ツつクテ」ツ?ョテ」ツつウテ」ツつケテ」ツδ暗」ツつ津・ツ、ツ嘉ヲツ崢エテ」ツ?療」ツ?淌・ツ崢榲ヲツ閉ー, v := テゥツ?づァツつケ
	int cost, e, v;  
	State(int cost_, int e_, int v_){
		cost = cost_; e = e_; v = v_;
	}
};
bool operator<(const State& a, const State& b){
	return a.cost > b.cost;
}

int solve(){
	for(int i=0 ; i < MAX_M ; i++ ) fill(memo[i], memo[i]+MAX_N, false);
	
	priority_queue<State> q;
	q.push( State(0, 0, 0) );
	int res = INF;
	while( !q.empty() ){
		int cost = q.top().cost, e = q.top().e, v = q.top().v; q.pop();
		
		if( memo[e][v] ) continue;
		memo[e][v] = true;
		
		if( v == n-1 ){ // テ」ツつエテ」ツδシテ」ツδォテ」ツ?ョテヲツ卍?
			res = min(res, e);
			continue;
		}
		
		for(int i=0 ; i < G[v].size() ; i++ ){
			int to = G[v][i].to;
			int next_cost = cost + G[v][i].cost;
			
			if( !memo[e][to] && next_cost <= c ){ // テ」ツつィテ」ツδε」ツつクテ」ツ?ョテ」ツつウテ」ツつケテ」ツδ暗」ツつ津・ツ、ツ嘉ヲツ崢エテ」ツ?療」ツ?ェテ」ツ??
				q.push( State(next_cost, e, to) );
			}
			next_cost -= G[v][i].cost;
			if( !memo[e+1][to] && e+1 <= n ){ // テ」ツつィテ」ツδε」ツつクテ」ツ?ョテ」ツつウテ」ツつケテ」ツδ暗」ツつ津・ツ、ツ嘉ヲツ崢エテ」ツ?凖」ツつ?
				q.push( State(next_cost, e+1, to) );
			}
		}
	}
	return res;
}

void add_edge(int u, int v, int cost){
	G[u].push_back( edge(v, cost) );
}

int main(){
	while( cin >> n >> m >> c , n || m || c ){
		for(int i=0 ; i < MAX_N ; i++ ) G[i].clear();
		
		for(int i=0 ; i < m ; i++ ){
			int u, v, cost;
			cin >> u >> v >> cost;
			u--; v--;
			add_edge(u, v, cost);
		}
		cout << solve() << endl;
	}
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
//#define ll __int128
//#define int ll
//#define int ll
//#define char ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef MAX_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1>
inline istream & operator >> (istream &in, pair<T0, T1> &a) {
    return in >> a.first >> a.second;
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void smain();



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

#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(4) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

void smain() {
    string s;
    cin >> s;
    map<char, int> cnt;
    for (auto c : s) {
        cnt[c]++;
    }
    ll ans = 1;
    for (auto item : cnt) {
        ans += (ll)item.second * (SZ(s) - item.second);
    }
    cout << (ans - 1) / 2 + 1;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int N;
int A[2000000];
int main(void){
	cin >> N;
	reps(i, pow(2, N), pow(2, N) * 2) cin >> A[i];
	int size = pow(2, N - 1);
	while(size >= 1){
		for (int i = size; i < size * 2; i++){
			if(A[i * 2] > A[i * 2 + 1]) A[i] = A[i * 2] - A[i * 2 + 1];
			else if(A[i * 2] == A[i * 2 + 1]) A[i] = A[i * 2];
			else A[i] = A[i * 2 + 1] - A[i * 2];
			// printf("%d %d %d\n", A[i], A[i * 2], A[i * 2 + 1]);
		}
		size >>= 1;
	}
	printf("%d\n", A[1]);
	return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e,f,wtr,sgr;
  cin >> a >> b >> c >> d >> e >> f;
  double cal=0.0;
  int ans_sgwtr=100*a;
  int ans_sgr=0;
  for(int A=0;A<31;++A){
    for(int B=0;B<31;++B){
      for(int C=0;C<101;++C){
        for(int D=0;D<101;++D){
        	wtr = 100*a*A+100*b*B;
        	sgr = C*c+D*d;
          if(wtr==0)break;
          if(wtr+sgr<=f && (wtr)/100*e>=sgr){
            double nongdu=(double)(100*(sgr))/(double)(wtr+sgr);
            if(cal<nongdu){
              ans_sgwtr = wtr+sgr;
              ans_sgr = sgr;
              cal = nongdu;
            }
          }
        }
      }
    }
  }
 
  cout << ans_sgwtr << " " << ans_sgr << endl;
  return 0;
 
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

using namespace std;
using ll = long long;

int main(){
    string s;
    cin>>s;
    bool ok=false;
    if(s[0] != s[1]) ok=true;
    else if(s[1] != s[2]) ok=true;

    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
program cookie
  implicit none
  integer(8) :: A, B, C, a1, b1, c1, count
  
  read(*,*) A, B, C
  if (A == B .and. B == C) then
     if (mod(A,2) == 0) then
        write(*,*) -1
     else
        write(*,*) 0
     end if
     stop
  end if
  a1 = A
  b1 = B
  c1 = C
  count = 0
  do while (.true.)
     if (mod(c1,2) == 1 .or. mod(a1,2) == 1 .or. mod(b1,2) == 1) then
        exit
     end if
     A = a1
     B = b1
     C = c1
     c1 = (A + B) / 2
     a1 = (B + C) / 2
     b1 = (C + A) / 2
     count = count + 1
  end do

  write(*,*) count
  
  stop
end program cookie

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;

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

vector<int> ans;
vector<int> col;



void changeCol(int p,int c){
    vector<int> toDOWN;
    vector<int> toUP;

    for (int i = 1; i <= p-1; i++)toDOWN.push_back(col[i]);
    for (int i = p; i <= p+c-1; i++)toUP.push_back(col[i]);

    for(int i=1;i<=c;i++)col[i]=toUP[i-1];
    for(int i=c+1,j=0;i<p+c;i++,j++)col[i]=toDOWN[j];
}


int main(){
int n,r;
int tmp1,tmp2;
    while(1){
        cin>>n>>r;
        if(n==0&&r==0)break;
        col.clear();
        for(int i=0;i<=n;i++)col.push_back(i);
        for (int j = 0; j < r; j++){
            cin>>tmp1>>tmp2;
            changeCol(tmp1,tmp2);
        }
        ans.push_back(n+1-col[1]);
    }
     for(int i=0;i<ans.size();i++){
        cout<<ans[i]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3052