akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int parent(int);
int left(int);
int right(int);


int main(){
  int n,i,a[100001];

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }

  for(i=1;i<=n;i++){
    printf("node %d: ",i);
    printf("key = %d, ",a[i]);
    if(parent(i))printf("parent key = %d, ",a[parent(i)]);
    if(left(i)<=n)printf("left key = %d, ",a[left(i)]);
    if(right(i)<=n)printf("right key = %d, ",a[right(i)]);
    printf("\n");
  }

  return 0;
}


int parent(int x){
  return x/2;
}


int left(int x){
  return x*2;
}

int right(int x){
  return x*2+1;
}

  



Measured memory_bytes: 2704
#include<cstdio>
int main(){
	char A,B;
	scanf("%c %c",&A,&B);
	if(A == 'H' && B == 'H') printf("H\n");
	if(A == 'H' && B == 'D') printf("D\n");
	if(A == 'D' && B == 'H') printf("D\n");
	if(A == 'D' && B == 'D') printf("H\n");
	return 0;
}

Measured memory_bytes: 128
n, k, q = map(int, input().split())
a_list = [k] * n
for _ in range(q):
    a = int(input())
    a -= 1
    a_list[a] += 1
for i, aa in enumerate(a_list):
    if aa - q > 0:
        print("Yes")
    else:
        print("No")

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


     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define sz size()
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

     
const ll MOD = 1e9 + 7;
const ll ZER = 0;

vector<int> d(10, 0);
bool func(ll n){
    while(n){
        int now = n % 10;
        if(d[now])return false;
        n /= 10;
    }
    return true;
}

int main(){
    ll n, k;
  	cin >> n >> k;
    bool f = false;
    
    rep(i, k){
        int a;
        cin >> a;
        d[a] = 1;
    }
    ll res = n;
    while(1){
        if(func(res)){
            cout << res << endl;
            return 0;
        }
        res++;
    }
}





Measured memory_bytes: 3572
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

//想定解答との絶対誤差または相対誤差が 10−6以下の場合+1以上だしておく。適当に15とかでもおｋ．
//cout << fixed << setprecision(15);

class Radix {
private:
  const char* s;
  int a[128];
public:
  Radix(const char* s = "0123456789ABCDEF") : s(s) {
    int i;
    for(i = 0; s[i]; ++i)
      a[(int)s[i]] = i;
  }
  std::string to(long long p, int q) {
    int i;
    if(!p)
      return "0";
    char t[64] = { };
    for(i = 62; p; --i) {
      t[i] = s[p % q];
      p /= q;
    }
    return std::string(t + i + 1);
  }
  std::string to(const std::string& t, int p, int q) {
    return to(to(t, p), q);
  }
  long long to(const std::string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for(i = 1; i < (int)t.length(); ++i)
      sm = sm * p + a[(int)t[i]];
    return sm;
  }
};

int main() {
    //string N;
    ll N;
    int k;
    cin >> N >> k;
    //vector<vector<int>> data(3, vector<int>(4));
    //初期値0
    //vector<int> data(i, 0);
    Radix r;
    string res = r.to(N, k);
    cout << res.length() << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  long long all = 0;
  for(int i = 0;i < s.size();i++){
    all += (s[i] - '0');
  }
  if(all % 9 == 0)cout <<"Yes" << endl;
  else cout << "No" << endl;

}

Measured memory_bytes: 3748
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N;
	int[] T;
	boolean[][][] dp;

	public void solve() {
		N = nextInt();
		T = new int[N];
		int sum = 0;
		for(int i = 0;i < N;i++){
			T[i] = nextInt();
			sum += T[i];
		}

		dp = new boolean[N + 1][850 + 1][850 + 1];
		dp[0][0][0] = true;

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

			for(int j = 0;j < 850 + 1;j++){

				for(int k = 0;k < 850 + 1;k++){

					if(!dp[i][j][k])continue;

					if(j + T[i] < 850)dp[i + 1][j + T[i]][k] = true;

					if(k + T[i] < 850)dp[i + 1][j][k + T[i]] = true;

					dp[i + 1][j][k] = true;

				}

			}

		}

		int ans = Integer.MAX_VALUE;

		for(int i = 0;i < 850 + 1;i++){
			for(int j = 0;j < 850 + 1;j++){
				if(dp[N][i][j]){
					ans = Math.min(ans, Math.max(sum - i - j,Math.max(i, j)));
				}

			}
		}

		out.println(ans);
	}
	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

Measured memory_bytes: 89296
#include <stdio.h>
#include <math.h>

int main(){

    int n;

    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x=i;
        if(x%3==0){
            printf(" %d",i);
            continue;
        }
        while(1 <= x){
            if(x % 10 == 3){
                printf(" %d",i);
                break;
            }
            x /= 10;
        }
    }

    printf("\n");
    return 0;
}



Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define MAX_N 100000

int dp[MAX_N];

signed main(){
	int n,k;
	cin >> n >> k;
	int  h[n];
	REP(i,n){
		cin >> h[i];
	}
	REP(i,n){
		dp[i] = INF;
	}
	dp[0] = 0;
	for(int i = 1; i < n; i++){
		for(int j = 1; j <= k; j++){
			if(i - j < 0){
				continue;
			}
			dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}

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

int main()
{
  int r, g, b;

  cin >> r >> g >> b;

  if ((r * 100 + g * 10 + b) % 4) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int[] h = new int[n + 1];
		for (int i = 1; i < n + 1; i++)
			h[i] = sc.nextInt();

		int c = 0;
		int max = 0;

		for (int i = 1; i < n; i++) {
			if (h[i] >= h[i + 1]) {
				c++;
				if (max < c)
					max = c;
			} else
				c = 0;

		}

		System.out.println(max);

	}

	static class FastScanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private static boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

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

}

Measured memory_bytes: 24148
#include <iostream>
#include <vector>
#include <functional>
#include <unordered_map>
#include <algorithm>
#include <utility>

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

  std::vector<long> a(s.size() + 1, 0);
  for (long i = 0; i < (long)a.size(); ++i) {
    // 両隣より小さい
    if ((i == 0 || s[i - 1] == '>') && (i == (long)a.size() - 1 || s[i] == '<')) {
      for (long j = i - 1; j >= 0 && s[j] == '>'; --j) {
        long v = a[j + 1] + 1;
        if (a[j] < v) a[j] = v;
      }
      for (long j = i + 1; j < (long)a.size() && s[j - 1] == '<'; ++j) {
        long v = a[j - 1] + 1;
        if (a[j] < v) a[j] = v;
      }
    }
  }

  long sum = 0;
  std::for_each(a.begin(), a.end(), [&](auto &x) {sum += x;});
  std::cout << sum << std::endl;

  return 0;
}

Measured memory_bytes: 4740
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
template<class Abel> struct UnionFind {
    vector<ll> par;
    vector<ll> rank;
    vector<Abel> diff_weight;

    UnionFind(ll n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(ll n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (ll i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    ll root(ll x) {
        if (par[x] == x) {
            return x;
        }
        else {
            ll r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(ll x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    bool merge(ll x, ll y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(ll x, ll y) {
        return weight(y) - weight(x);
    }
};
int main(){
  ll n,m;cin>>n>>m;
  UnionFind<ll>uf(n);
  rep(i,m){
    ll l,r,d;cin>>l>>r>>d;
    l--;r--;
    if(uf.issame(l,r)){
      ll diff=uf.diff(l,r);
      if(diff!=d){
        cout<<"No"<<endl;
        return 0;
      }
    }
    else uf.merge(l,r,d);
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 2688
# cardGame.py
num = int(input())
result = {'taro':0, 'hanako':0}
for i in range(num):
    cards = input().split()
    taro = cards[0]
    hanako = cards[1]
    sorted_cards = sorted(cards)
    if taro == hanako:
        result['taro'] += 1
        result['hanako'] += 1
    elif cards == sorted_cards:
        result['hanako'] += 3
    else :
        result['taro'] += 3
print(result['taro'], result['hanako'])


Measured memory_bytes: 5604
#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(void){

	int N;
	ll Y;
	cin >> N >> Y;

	rep(x, N+1){
		rep(y, N-x+1){
			int z=N-x-y;
			if((10000*x + 5000*y + 1000*z) == Y){
				cout << x << " " << y << " " << z << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1 -1" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
class Graph{
private:
  int node;
  int edge_num;
  vector<vector<int>> edge;  
  vector<int> f;
  vector<int> d;
  int time;
public:
  //***************Constractor****************************
  Graph(int n,vector<int> a,vector<int> b){
    node = n;
    edge_num = a.size();
    time = 1;
    edge.resize(node);
    f.resize(node,0);
    d.resize(node);    
    rep(i,edge_num){
      edge[a[i]].push_back(b[i]);
    }
  }

  //***********************************************
  
  void simple_dfs(int v){
    f[v] = time++;
    for(auto w:edge[v]){
      if(f[w]>0) continue;
      simple_dfs(w);
    }
    d[v] = time++;
  }

  void run_dfs(int s){//check each node can reach goal
    rep(i,node){
      if(f[i]<=0) simple_dfs(i);
    }
  }

  void show(){
    rep(i,node){
      cout << i+1 << " " << f[i] << " " << d[i] << "\n";
    }
  }
};


int main()
{
  int n;
  cin >> n;
  vector<int> a,b;
  rep(i,n){
    int aa;cin >> aa;aa--;
    int m;cin >> m;
    rep(i,m){
      int bb;cin >> bb;bb--;
      a.push_back(aa);
      b.push_back(bb);      
    }
  }

  Graph gp(n,a,b);
  gp.run_dfs(0);
  gp.show();
  
  return 0;
}



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

int main(void){
  int N;
  cin >> N;
  vector<int> W(N);
  for (int i = 0; i < N; i++) cin >> W[i];

  vector<int> sum(N);
  for (int i = 0; i < N; i++){
    if (i == 0) sum[i] = W[i];
    sum[i] = sum[i - 1] + W[i];
  }

  int diff_min = sum[N-1];
  for (int i = 1; i < N; i++){
    int S1 = sum[i];
    int S2 = sum[N - 1] - sum[i];
    diff_min = min(diff_min, abs(S1 - S2));
  }
  cout << diff_min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200000 + 10;
struct point{
    ll x,y;
    point(){}
    point(ll x,ll y):x(x),y(y){}
    point operator - (point p){
        return point(x-p.x,y-p.y);
    }
};
ll det(point a,point b){
    return a.x * b.y - a.y * b.x;
}
ll a[N],b[N],c[N];
point var[N];
int main(){
    int n; scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%lld",&a[i]);
    for(int i=0;i<n;i++) scanf("%lld",&b[i]);
    int pos = 0;
    for(int i=0;i<n;i++){
        if(a[i]>a[pos]) pos = i;
    }
    rotate(a,a+pos,a+n);
    rotate(b,b+pos,b+n);
    c[0] = c[1] = 1;
    for(int i=1;i<n;i++) c[i+1] = 2*c[i]+2*b[i]-c[i-1];
    vector<point> v; int r = 0;
    for(int i=0;i<=n;i++){
        point p(i,a[i%n]-c[i]);
        while(r>=2&&det(v[r-1]-v[r-2],p-v[r-1])>=0) v.pop_back(), r--;
        v.push_back(p), r++;
    }
    ll ans = 0;
    for(int i=1;i<(int)v.size();i++){
        ans += (v[i-1].y+v[i].y)*(v[i].x-v[i-1].x+1);
        ans -= 2*v[i].y;
    }
    for(int i=0;i<n;i++) ans += 2*c[i];
    printf("%.12f\n",0.5*ans/n);
}


Measured memory_bytes: 12096
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main(){
    int n,h,w,c=0;
    cin>>n>>h>>w;
    for (int i=1; i<=n; i++) {
        int a,b;
        cin>>a>>b;
        if (a>=h && b>=w) c++;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
def make_divisors(m,n):
    divisors = []
    ans = 0
    for i in range(1, int(n**0.5)+1):
        if n % i == 0 and m <= n//i and ans < i:
            ans = i
            if i != n//i and m <= i and ans < n//i:
                ans = n//i
    print(ans)

n,m = map(int, input().split())
make_divisors(n,m)


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

int main() {
    int a, b;
    cin >> a >> b;
    if (a == 1) {
        a = 14;
    }
    if (b == 1) {
        b = 14;
    }

    if (a > b) {
        cout << "Alice" << endl;
    }
    else if (a < b) {
        cout << "Bob" << endl;
    }
    else {
        cout << "Draw" << endl;
    }

}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x)end()
#define sz(x) (int)(x).size
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int h,w,mat[105][105];
void out() {
    rep(i,0,h) {
        rep(j,0,w) {
            printf((j == w - 1) ? "%d\n" : "%d ",mat[i][j]);
        }
	}
}


int main ()
{
	int n;
	scanf("%d%d%d",&h,&w,&n);
	int a[10005];
	rep(i,0,n) scanf("%d",&a[i]);
	int cnt = 0,c[10005];
    rep(i,0,n) {
        rep(j,0,a[i]) {
            c[cnt++] = i + 1;
        }
    }
	n = h * w;

	memset(mat,0,sizeof(mat));
	cnt = 0;
	int i = 0,j = -1;
	while (cnt < n) {
        while (j + 1 < w && mat[i][j + 1] == 0 && cnt < n) { mat[i][++j] = c[cnt++];}
        while (i + 1 < h && mat[i + 1][j] == 0 && cnt < n) { mat[++i][j] = c[cnt++];}
        while (j - 1 > -1 && mat[i][j - 1] == 0 && cnt < n) { mat[i][--j] = c[cnt++];}
        while (i - 1 > -1 && mat[i - 1][j] == 0 && cnt < n) { mat[--i][j] = c[cnt++];}
	}
	rep(i,0,h) {
        rep(j,0,w) {
            printf((j == w - 1) ? "%d\n" : "%d ",mat[i][j]);
        }
	}

    return 0;
}


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

int main()
{
	int n, m;
	int msquare=1;
	int result;
	cin >> n >> m;

	for(int i =0;i<m;i++)
	{
		msquare = msquare*2;
	}
	//cout << msquare;

	result = ((n - m) * 100 + (m * 1900)) * msquare;

	cout << result;

	return 0;
	

}	


Measured memory_bytes: 256
S=input()
T=input()
SL=list(S)
N=len(S)
M=len(T)

if len(S)<len(T):
    print("UNRESTORABLE")
    
else:
    for i in range(N-M+1):
        cond=True
        temp=S[N-M-i:N-i]
        for s in range(M):
            if temp[s]!="?" and temp[s]!=T[s]:
                cond=False
        if cond:
            SL[N-M-i:N-i]=list(T)
            break
    if not cond:
        print("UNRESTORABLE")
    else:
        for j in range(N):
            if SL[j]=="?":
                SL[j]="a"
    
        for a in SL:
            print(a,end="")

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

int main() {
	int n ;
	scanf("%d",&n);
	int arr[n];
	long long prod = 1;
	for(int i = 0 ; i < n ; ++i){
		scanf("%d",&arr[i]);
	}
	long long sum = 0;
	for(int i = 0 ; i < n ; ++i){
		for(int j = i+1 ; j < n ; ++j) sum += (arr[i] * arr[j]);
	}
	printf("%lld",sum);
	return 0;
}

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

int main()
{
	int n, a,b;
	cin >> n >> a >> b;
	vector<int> p(n);
	for (int i = 0; i < n; i++)
	{
		cin >> p.at(i);
	}
	sort(p.begin(), p.end());
	vector<int> dame(n);
	
	int ans = 0;
	for (int i = 0; i< n; i++)
	{
		for (int j = i+1; j < n; j++)
		{
			for (int k = j+1; k < n; k++)
			{
				if (dame.at(i)==1||dame.at(j)==1||dame.at(k)==1)
				{
					continue;
				}
					
				if (p.at(i)<=a&&p.at(j)>=a+1&&p.at(j)<=b&&p.at(k)>=b+1)
				{
					dame.at(i) = 1;
					dame.at(j) = 1;
					dame.at(k) = 1;
					ans++;

				}
			}
		}
	}
	cout << ans << endl;

	


}

Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int A[100010];

signed main() {
    int N; cin >> N;
    rep(i,0,N) {
        cin >> A[i];
    }

    int cur = 1, ans = 0;
    rep(i,0,N) {
        int div = (A[i] - 1) / cur;
        if(div) A[i] = 1;
        ans += div;
        if(cur == A[i]) cur++;
        // printf("debug: %lldth: cur = %lld\n", i+1, cur);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mod 998244353
#define MAX 500005
using namespace std;
//char nc()
//{
//	static char buf[100000],*p1=buf,*p2=buf;
//	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
char nc(){return getchar();}
int read()
{
	int x=0,y=1;
	char c=nc();
	while(!isdigit(c))
	{
		if(c=='-')y=-1;
		c=nc();
	}
	while(isdigit(c))
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=nc();
	}
	return x*y;
}
int n,k;
long long fac[MAX],inv[MAX],facinv[MAX];
void pre()
{
	fac[0]=fac[1]=1;inv[1]=1;facinv[0]=facinv[1]=1;
	for(int i=2;i<=k;i++)
		fac[i]=fac[i-1]*i%mod,
		inv[i]=inv[mod%i]*(mod-mod/i)%mod,
		facinv[i]=facinv[i-1]*inv[i]%mod;
}
long long mo(long long x)
{
	return x<mod?x:x-mod;
}
long long C(int down,int up)
{
	if(up<0||down<up) return 0;
	return fac[down]*facinv[down-up]%mod*facinv[up]%mod;
}
long long calc(int r,int b)
{
	int l=r-n+1;
	return mo(C(r+b,r)-C(r+b,r+l)+mod);
}
int main()
{
	n=read();k=read();
	pre();
	long long ANS=0;
	for(int i=0;i<=k;i++)
	{
		int j=k-i;
		if(i<n||i<j) continue;
		if(i==j) ANS=mo(ANS+calc(i,j-1));
		else ANS=mo(ANS+calc(i,j)); 
	}
	printf("%lld",ANS);
	return 0;
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

typedef pair<int, int> P;

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

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

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

signed main(){
    int N;
    while( cin >> N, N ){
        vector<P> xy( N );
        xy[0].first = xy[0].second = 0;

        int r, l, u, d;
        r = l = u = d = 0;
        REP( i, N - 1 ){
            int p, c; cin >> p >> c;

            xy[i + 1].first = xy[p].first + dx[c];
            xy[i + 1].second = xy[p].second + dy[c];

            chmax( r, xy[i + 1].first );
            chmin( l, xy[i + 1].first );
            chmax( u, xy[i + 1].second );
            chmin( d, xy[i + 1].second );
        }
        cout << r - l + 1 << " " << u - d + 1 << endl;
    }
}



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

int main()
{
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for(int& i : a)
  {
    scanf("%d", &i);
  }
  long long dp[n][n];
  for(int i = n - 1; i >= 0; i--)
  {
    for(int j = i; j < n; j++)
    {
      if(i == j)
        dp[i][j] = a[i];
      else
        dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]);  
    
    }
  } 
  printf("%lld", dp[0][n - 1]);
  return 0;
}


Measured memory_bytes: 46464
from collections import deque

n, q = map(int, input().split())
queue = deque()
for _ in range(n):
    n, t = input().split()
    queue.append([n, int(t)])
time = 0
finish = []
while len(queue) > 0:
    l = queue.popleft()
    cost = min(q, l[1])
    l[1] -= cost
    time += cost
    if l[1] == 0:
        finish.append((l[0], time))
    else:
        queue.append(l)
for f in finish:
    print(*f)



Measured memory_bytes: 14836
#include<stdio.h>
int main(){
long long x,k,d;
  scanf("%lld%lld%lld",&x,&k,&d);
  if(x<0)x*=-1;
  if(k>x/d){		//最適解に一度でもたどり着ける時
    if((k-x/d)%2==0)	
      printf("%lld",x%d);
      else
        printf("%lld",d-x%d);
  }
  else {
    printf("%lld",x-d*k);
  }
  return 0;
}

Measured memory_bytes: 1720
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 2020;
int a[N] , x , n , Min[N];


int main(){
    cin >> n >> x;
    rep(i,0,n) cin >> a[i] , Min[i] = a[i];
    ll ans = 1ll << 62;
    rep(i,0,n){
        ll sum = 1ll * x * i;
        rep(j,0,n) sum += Min[j];
        ans = min(ans , sum);
        rep(j,0,n) Min[j] = min(Min[j] , a[(j-i-1+n)%n]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int N;
int A[2 * 100000];
 
long long diff(long long b) {
    long long d = 0;
    for (int i = 0; i < N; i++) {
        d += abs(A[i] - b);
    }
    return d;
}
 
int main() {
    long long b = 0;
    long long suma = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        A[i] -= i + 1;
    }
    sort(A, A+N);
    cout << diff(A[N/2]) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include<math.h>
#include<cmath>

using namespace std;

int main()
{
    long long a,b,k,result;
    cin>>a>>b;
    long long temp = b - a;
    long long res = temp/2;

    result = b - res;


    if(abs(b-result) == abs(a - result)){
        cout<<result<<endl;
    }


    else
        cout<<"IMPOSSIBLE"<<endl;
}


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

int main() {
  int h, w;
  std::cin >> h >> w;
  std::vector<std::vector<int>> c(h, std::vector<int>(w));
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (auto &i : a) {
    std::cin >> i;
  }

  int i = 0, j = 0;

  for (int k = 0; k < n; k++) {
    auto l = a[k];
    while (l != 0) {
      if (j == w) {
        i++;
        j = 0;
      }
      c[i][j] = k + 1;
      l--;
      j++;
    }
  }

  for (int i = 0; i < h; i++) {
    if (i % 2 == 1) {
      std::reverse(c[i].begin(), c[i].end());
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      std::cout << c[i][j];
      if (j != w - 1) {
        std::cout << " ";
      }
    }
    std::cout << std::endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

bool isPalindrome(int x){
  string s = to_string(x);
  int n=s.length();
  bool ret=true;
  repeat(i,(n+1)/2){
    ret &= s[i]==s[n-1-i];
  }
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A,B,C;cin>>A>>B>>C;
  int K;cin>>K;
  cout << A+B+C+(max({A,B,C})<<K)-max({A,B,C})<<endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
    "fmt"
)

func main() {
  var a, b int
  fmt.Scan(&a, &b)

  if a < b {
    fmt.Println("a < b")
  }
  if a > b {
    fmt.Println("a > b")
  }
  if a == b {
    fmt.Println("a == b")
  }
}


Measured memory_bytes: 1124
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
    int a,b;
    cin >> a >> b;
    if(a<=b) cout << a << endl;
    else cout << a-1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,x,cnt=1,d=0;
  cin >> n >> x;
  int l[n];
  for(int i=0;i<n;i++){
    cin >> l[i];
    d=d+l[i];
    if(d<=x) cnt++;
  }
  cout << cnt << endl;
}


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

typedef long long LL;
typedef unsigned long long ULL;

#define debug printf("fuck %d\n", __LINE__);

inline LL read() {
	LL res = 0, bo = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') bo = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		res = (res << 1) + (res << 3) + ch - '0';
		ch = getchar();
	}
	return bo * res;
}

template <typename T>
void read(T &x) {
	x = read();
}

template <typename T, typename... Argv>
void read(T &a, Argv &... argv) {
	read(a);
	read(argv...);
}

const int N = 5005;
LL s[N], p[N], f[N];
int n, A, B;

int main() {
	memset(f, 0x3f, sizeof(f));
	read(n, A, B); f[0] = 0;
	for (int i = 1, x; i <= n; ++ i) {
		read(x);
		for (int j = 0; j <= n; ++ j) 
			if (j) p[j] = std::min(p[j - 1], f[j]);
			else p[j] = f[j];
		for (int j = 0; j <= x; ++ j) f[j] += A;
		for (int j = x + 1; j <= n; ++ j) f[j] += B;
		f[x] = std::min(f[x], p[x]);
	}
	LL ans = f[n + 1];
	for (int i = 0; i <= n; ++ i) ans = std::min(ans, f[i]);
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3

import itertools

degit = list(map(int, input().split()))

flag = 0
for i, j, k in itertools.permutations(degit, 3):
    if i == j:
        if j != k:
            flag = 1
    else:
        if j == k:
            flag = 1
    # print(i, j, flag)


print("Yes" if flag == 1 else "No")


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

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<int> a(n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);

	int min{1 << 30};
	for (int i = -100; i <= 100; i++)
	{
		int cost{};
		for (int j = 0; j < n; j++)
			cost += (a[j] - i) * (a[j] - i);

		min = std::min(cost, min);
	}
	printf("%d\n", min);

	return 0;
}

Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

double dp[301][301][301];
int n, a, b, c, d;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    double x[n];
    for (int i=0; i<n; i++) {
        cin >> x[i];
        if (x[i] == 0) a++;
        if (x[i] == 1) b++;
        if (x[i] == 2) c++;
        if (x[i] == 3) d++;
    }
    dp[n][0][0] = 0;
    for (int i=1; i<=n-a; i++) {
        dp[n-i][i][0] = dp[n-i+1][i-1][0] + 1.0 * n/i;
        for (int j=1; j<=i && j<=c+d; j++) {
            if (i == j) dp[n-i][0][j] = dp[n-i][1][j-1] + 1.0 * n/i;
            else dp[n-i][i-j][j] = 1.0*(i-j)/i * dp[n-i+1][i-j-1][j] + 1.0*j/i * dp[n-i][i-j+1][j-1] + 1.0* n/i;
            for (int k=1; k<=j && k<=d; k++) {
                if (j == k) dp[n-i][i-j][0] = 1.0 * (i-j)/i * dp[n-i+1][i-j-1][0] + 1.0*j/i * dp[n-i][i-j][1] + 1.0*n/i;
                else dp[n-i][i-j][j-k] = 1.0* (i-j)/i * dp[n-i+1][i-j-1][j-k] + 1.0 * (j-k)/i * dp[n-i][i-j+1][j-k-1] + 1.0*k/i * dp[n-i][i-j][j-k+1] + 1.0*n/i;
            }
        }
    }
    cout << fixed << setprecision(11) << dp[a][b][c] << endl;
}

Measured memory_bytes: 213248
N, K = map(int, input().split())
M = list(map(int, input().split()))
SM = sorted(M, reverse=True)

# 必殺技で倒す数
SkillKill = len(SM[:K])

remain = N - SkillKill
if remain > 0:
  print(sum(SM[K:]))
else:
  print(0)


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

int main(){
  int N;
  cin >> N;
  if(N<=9) cout << N << endl;
  else if(N<=99) cout << 9 << endl;
  else if(N<=999) cout << 9 + (N-99) << endl;
  else if(N<=9999) cout << 909 << endl;
  else if(N<=99999) cout << 909 + (N-9999) << endl;
  else cout << 90909 << endl;
  return 0;
}


Measured memory_bytes: 256
N=int(input())
P=0
for i in range(N):
  P+=(i+2)*(i+1)//2
u,v=0,0
for i in range(N-1):
  u,v=map(int,input().split())
  if u>v:
    u,v=v,u
  P-=u*(N-v+1)
print(P)

Measured memory_bytes: 68952
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
import std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	int n = read.to!int;
	int[] as;
	foreach(i; 0 .. n) as ~= read.to!int;
	
	bool[int] aset;
	foreach(a; as) aset[a] = 1;
	
	if(aset.keys.length > 2){
		debug writeln("A");
		writeln("No");
		return;
		}
	
	if(aset.keys.length == 2){
		int m;
		if(aset.keys[0] + 1 == aset.keys[1]) m = aset.keys[0];
		else if(aset.keys[1] + 1 == aset.keys[0]) m = aset.keys[1];
		else{
			debug writeln("B");
			writeln("No");
			return;
			}
		
		int k = 0;
		foreach(a; as) if(a == m) k += 1;
		
		if(m < k){
			debug writeln("C-1");
			writeln("No");
			return;
			}
		
		if(k + (n - k) / 2 < m + 1){
			debug writeln("C-2");
			writeln("No");
			return;
			}
		
		debug writeln("D");
		writeln("Yes");
		return;
		
		}
	
	else{
		int m = aset.keys[0];
		if(m == n - 1){
			debug writeln("E");
			writeln("Yes");
			return;
			}
		if(n >= m * 2){
			debug writeln("F");
			writeln("Yes");
			return;
			}
		
		debug writeln("G");
		writeln("No");
		return;
		}
	
	}



/*

差は最大で1である。
（たとえば9と10しか存在しないなど）

9と言うのは他の誰ともちがうぼうしをかぶっている人
10と言うのは他の誰かと同じぼうしをかぶっている人

9と言った人の人数+(10と言った人の人数 / 2)に注目。
それが10以上ならOK。

差が0つまり全員同じ数を言った場合は2つのパターンがある。
全員他の人と違う帽子をかぶっているパターン。
これは人数-1を言っているならOK。
全員誰かと同じ帽子をかぶっているパターン。
これは人数がその言った数の2倍以上ならOK。



*/

Measured memory_bytes: 8636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
#include<bitset>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
typedef long long ll;
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T&a , T b){ if(a<b){ a=b; return true; } else{ return false; } }
template<class T> inline bool chmin(T&a , T b){ if(a>b){ a=b; return true; } else{ return false; } } 

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;


int main(){
    int n;
    cin >> n;
    vector<int> d(3);
    rep(i,3) cin >> d[i];
    vector<P> q;
    rep(i,n){
        string s;
        cin >> s;
        int a,b;
        if(s=="AB") a=0, b=1;
        if(s=="AC") a=0, b=2;
        if(s=="BC") a=1, b=2;
        q.emplace_back(a,b);
    }
    string ans;
    auto add = [&](int a, int b){
        d[a]++;
        d[b]--;
        ans += 'A'+a;
    };
    q.emplace_back(0,1);
    rep(i,n){
        int a = q[i].first;
        int b = q[i].second;
        if(!d[a] && !d[b]){
            cout << "No" << endl;
            return 0;
        }
        if(!d[a]){
            add(a,b);
        }else if(!d[b]){
            add(b,a);
        }else{
            int na = q[i+1].first;
            int nb = q[i+1].second;
            if(a==na || a==nb){
                add(a,b);
            }else{
                add(b,a);
            }
        }
    }
    cout << "Yes" << endl;
    rep(i,n){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5380
#include <cstdio>
#include <stdlib.h>
#include <ctype.h>
#include <cstring>
#include <math.h>


int main(){
    int N;
    int M;
    int S;
    int A;
    int B[2000001];
    scanf("%d",&N);

    for(int i = 1; i <= N; ++i){
        B[i] = 0;
    }


    for(int i = 0; i < N-1; ++i){
        scanf("%d",&A);
        B[A] +=1;
    }

    for(int i = 1; i <= N; ++i){
        printf("%d\n", B[i]);
    }
    return 0;
}


Measured memory_bytes: 2472
N, M, X = map(int, input().split())
CA = []
for i in range(N):
  karilist = list(map(int, input().split()))
  CA.append(karilist)
ans = 0
for i in range(M):
  rikai = 0
  for j in range(N):
    rikai += CA[j][i+1]
  if rikai < X:
    ans = -1
    break

if ans == 0:
  ans = N*(10**5)
  for j in range(2**N):
    dame = 0
    rikaiM = [0 for i in range(M)]
    cost = 0
    for k in range(N):
      if (j >> k) & 1 == 1:
        cost += CA[k][0]
        for h in range(M):
          rikaiM[h] += CA[k][h+1]
    # 理解度計算終了
    for h in rikaiM:
      if h < X:
        dame = 1
        break
    if dame == 0:
      ans = min(ans, cost)
print(ans)

Measured memory_bytes: 9240
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename T>
class flow_graph {
  public:
  static constexpr T eps = (T) 1e-9;
 
  struct edge {
    int from;
    int to;
    T c;
    T f;
  };
 
  vector< vector<int> > g;
  vector<edge> edges;
  vector<int> ptr;
  vector<int> d;
  vector<int> q;
  int n;
  int st, fin;
  T flow;
   
  flow_graph(int n, int st, int fin) : n(n), st(st), fin(fin) {
    assert(0 <= st && st < n && 0 <= fin && fin < n && st != fin);
    g.resize(n);
    ptr.resize(n);
    d.resize(n);
    q.resize(n);
    flow = 0;
  }
 
  void clear_flow() {
    for (const edge &e : edges) {
      e.f = 0;
    }
    flow = 0;
  }
   
  void add(int from, int to, T forward_cap, T backward_cap) {
    assert(0 <= from && from < n && 0 <= to && to < n);
    g[from].push_back(edges.size());
    edges.push_back({from, to, forward_cap, 0});
    g[to].push_back(edges.size());
    edges.push_back({to, from, backward_cap, 0});
  }
 
  bool expath() {
    fill(d.begin(), d.end(), -1);
    q[0] = fin;
    d[fin] = 0;
    int beg = 0, end = 1;
    while (beg < end) {
      int i = q[beg++];
      for (int id : g[i]) {
        const edge &e = edges[id];
        const edge &back = edges[id ^ 1];
        if (back.c - back.f > eps && d[e.to] == -1) {
          d[e.to] = d[i] + 1;
          if (e.to == st) {
            return true;
          }
          q[end++] = e.to;
        }
      }
    }
    return false;
  }
   
  T dfs(int v, T w) {
    if (v == fin) {
      return w;
    }
    int &j = ptr[v];
    while (j >= 0) {
      int id = g[v][j];
      const edge &e = edges[id];
      if (e.c - e.f > eps && d[e.to] == d[v] - 1) {
        T t = dfs(e.to, min(e.c - e.f, w));
        if (t > eps) {
          edges[id].f += t;
          edges[id ^ 1].f -= t;
          return t;
        }
      }
      j--;
    }
    return 0;
  }
 
  T max_flow() {
    while (expath()) {
      for (int i = 0; i < n; i++) {
        ptr[i] = (int) g[i].size() - 1;
      }
      T big_add = 0;
      while (true) {
        T add = dfs(st, numeric_limits<T>::max());
        if (add <= eps) {
          break;
        }
        big_add += add;
      }
      if (big_add <= eps) {
        break;
      }
      flow += big_add;
    }
    return flow;
  }
 
  vector<bool> min_cut() {
    max_flow();
    vector<bool> ret(n);
    for (int i = 0; i < n; i++) {
      ret[i] = (d[i] != -1);
    }
    return ret;
  }
};

int main() {
  int h, w;
  cin >> h >> w;
  flow_graph<int> flow(h + w + 2, h + w, h + w + 1);
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      if (s[j] == 'S') {
        flow.add(h + w, i, 1e9, 0);
        flow.add(h + w, h + j, 1e9, 0);
      }
      else if (s[j] == 'T') {
        flow.add(i, h + w + 1, 1e9, 0);
        flow.add(h + j, h + w + 1, 1e9, 0);
      }
      else if (s[j] == 'o') {
        flow.add(i, h + j, 1, 0);
        flow.add(h + j, i, 1, 0);
      }
    }
  }
  int res = flow.max_flow();
  if (res >= 1e9) res = -1;
  cout << res << '\n';
}

Measured memory_bytes: 1456
def solve(n):
    ans = 0
    for i in range(1, n+1):
        if (i % 3 == 0 and i % 5 == 0) or (i % 3 == 0) or (i % 5 == 0):
            continue
        else:
            ans += i
    print(ans)

if __name__ == "__main__":
    n = int(input())
    solve(n)

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

int main(){
    string S;
    cin >> S;
    int N = S.size();
    string BW, WB;
    for(int i = 0; i < N; i++)
    {
        char c = (i % 2) ? '0' : '1';
        char d = ((i+1)%2) ? '0' : '1';
        BW.push_back(c);
        WB.push_back(d);
    }
    int costBW = 0, costWB = 0;
    for(int i = 0; i < N; i++)
    {
        if(S[i] != BW[i]) costBW++;
        if(S[i] != WB[i]) costWB++;
    }
    cout << min(costBW, costWB) << "\n";
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define rank AAAAAA
#define MAX 114514
using namespace std;
int par[MAX];
int rank[MAX];
  
void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    rank[i]=0;
  }
}
int find(int x){
  if(par[x]==x)return x;
  else return par[x]=find(par[x]);
}
void unit(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  
  if(rank[x]<rank[y]){
    par[x]=y;
  }
  else{
    par[y]=x;
    if(rank[x]==rank[y])rank[x]++;
  }
}
  
unordered_map<int,int> mm;
  
int main(){
  int n,m,k,a,b,c;
  cin>>n>>m>>k;
  init(n+1);
  for(int i=1;i<=k;i++){
    cin>>c>>a>>b;
    if(c==1){
      int p1=find(a),p2=find(b);
      if(mm[p1]&&mm[p2]&&mm[p2]!=mm[p1]){
        cout<<i<<endl;
        break;
      }
      unit(a,b);
      if(mm[p1])mm[p2]=mm[p1];
      if(mm[p2])mm[p1]=mm[p2];
    }
    else{
      int p=find(a);
      if(mm[p]&&mm[p]!=b){
    cout<<i<<endl;
    break;
      }
      mm[p]=b;
    }
    if(i==k)cout<<0<<endl;
  }
}

Measured memory_bytes: 7664
using System;
 
namespace _171_c
{
    internal class Dalmatians
    {
        private static void Main(string[] args)
        {
            var input = Console.ReadLine();
            if (input == null) return;
            var number = long.Parse(input);
 
            const int numOfAlphabet = 26;
            var result = GetName(number, numOfAlphabet);
            Console.WriteLine(result);
        }
 
        private static string GetName(long number, int numOfAlphabet)
        {
            var quotient = number / numOfAlphabet;
            var remainder = number % numOfAlphabet;
 
            // ちょうど割り切れた場合
            if (remainder == 0)
            {
                quotient -= 1;
                remainder = numOfAlphabet;
            }
 
            // 文字コードと数値の差分
            const int ascDiff = 96;
 
            if (quotient == 0)
            {
                return Convert.ToChar(remainder + ascDiff).ToString();
            }
            return GetName(quotient, numOfAlphabet) + Convert.ToChar(remainder + ascDiff);
        }
    }
}

Measured memory_bytes: 27584
#include <stdio.h>

int main() {
  long int a, b, c, k, ans;
  
  scanf("%ld %ld %ld %ld", &a, &b, &c, &k);
  ans = 0;
  
  while (k > 0 && a > 0) {
    ans += 1;
    k -= 1;
    a -= 1;
  }
  
  if (k > 0 && b > 0) {
    k -= b;
  }
  
  while (k > 0 && c > 0) {
    ans -= 1;
    k -= 1;
    c -= 1;
  }
    
  printf("%ld", ans);
  return (0);
}

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

int main(void){
   int S,h,m,s;
   cin >> S;
   h=S/3600;
   m=(S-h*3600)/60;
   s=S-h*3600-m*60;
   
   cout << h;
   cout << ":";
   cout << m;
   cout << ":";
   cout << s;
   cout << endl;
}


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

int main() {
	string s, ans;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'B') {
			if (!ans.empty()) ans.pop_back();
		} else {
			ans += s[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;
vector<int> Zalgo(const string &S) {
    int N = (int)S.size();
    vector<int> res(N);
    res[0] = N;
    int i = 1, j = 0;
    while (i < N) {
        while (i+j < N && S[j] == S[i+j]) ++j;
        res[i] = j;
        if (j == 0) {++i; continue;}
        int k = 1;
        while (i+k < N && k+res[k] < j) res[i+k] = res[k], ++k;
        i += k, j -= k;
    }
    return res;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int n ;
  cin >> n;
  string s;
  cin >> s;
  
  int ans = 0;
  for(int i=0;i<n;i++){
    string t = s.substr(i);
    auto vec = Zalgo(t);
    
    for(int j=0;j<t.size();j++){
      int l = min(vec[j],j);
      chmax(ans,l);
    }
  }
  cout << ans << endl;
                         
  return 0;
}

Measured memory_bytes: 3688
import java.util.Scanner;
import java.util.Stack;

public class Main {
	public static void main(String[] args){
		String str;
		int num1, num2, result = 0;
		Scanner in = new Scanner(System.in);
		Stack<Integer> poland = new Stack<Integer>();

		while(in.hasNext()){
			str = in.next();

			if(str.equals("+") || str.equals("-") || str.equals("*")){
				num1 = poland.pop();
				num2 = poland.pop();
				if(str.equals("+")) result = num2 + num1;
				else if(str.equals("-")) result = num2 - num1;
				else if(str.equals("*")) result = num2 * num1;
				poland.push(result);
			}
			else{
				poland.push(Integer.parseInt(str));
			}
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 26224
n = gets.to_s.to_i
abs = Array.new(n){ gets.to_s.split.map{|e| e.to_i } }
a, b = abs.transpose

a.sort!
b.sort!

ans = 0
if n.odd?
  ans = b[n/2] - a[n/2] + 1
  ans = 0 if ans < 0
else
  ans = ( Rational( b[n/2] +  b[n/2-1], 2) - Rational( a[n/2] + a[n/2-1], 2) ) * 2 + 1
  ans = ans.to_i
  ans = 0 if ans < 0
end

puts ans

Measured memory_bytes: 33112