akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
vector<int> G[100005];
int V;

int color[100005];

bool dfs(int v, int c){
    color[v] = c;
    for(int i = 0; i < G[v].size(); i++){
        if(color[G[v][i]] == c){
            return false;
        }
        if(color[G[v][i]] == 0 && !dfs(G[v][i], -c)) return false;
    }
    return true;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    int a,b;
    rep(i,m){
        cin >> a >> b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    if(dfs(0,1)){
        ll hoge = 0;
        rep(i,n){
            if(color[i]==1)hoge++;
        }
        cout << hoge*(n-hoge) -m << endl;
    }else{
        cout << n*(n-1)/2-m << endl;
    }
    return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
#include<set>
#include<array>
using namespace std;

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



#define rep(p) for(int i=0;i<(p);i++)
typedef pair<int, int> pii;

typedef long long ll;
typedef pair<ll, ll>pll;
const int MOD = 1000000007;
const int INF = 1 << 29;




int main() {
	
	
	int n;

	cin >> n;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i*j == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		
		int res = 9999;
		for (int i=0;i<n;i++) {
			int ci = sc.nextInt();
			int ti = sc.nextInt();
			if (ti <= t && ci < res) {
				res = ci;
			}
		}
		if (res != 9999) {
			System.out.println(res);
		} else {
			System.out.println("TLE");
		}
	}
}

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

int main () {
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N), C(M), D(M);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i) >> B.at(i);
  }
  for (int i = 0; i < M; i++) {
    cin >> C.at(i) >> D.at(i);
  }
  for (int i = 0; i < N; i++) {
    int ans = 1;
    int man = fabs(A.at(i)-C.at(0)) + fabs(B.at(i)-D.at(0));
    for (int j = 0; j < M; j++) {
      if(man > fabs(A.at(i)-C.at(j)) + fabs(B.at(i)-D.at(j))) {
        ans = j + 1;
        man = fabs(A.at(i)-C.at(j)) + fabs(B.at(i)-D.at(j));
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  int n;cin>>n;
  vector<int> vec(n);
  for(auto &e: vec)cin>>e;
  if(n&1){
    for(int i=n-1;i>=0;i-=2){
      cout<<vec[i];
      if(n==1)cout<<endl;
      else cout<<" ";
    }
    for(int i=1;i<n-1;i+=2){
      cout<<vec[i];
      if(i!=n-2)cout<<" ";
      else cout<<endl;
    }
  }else{
    for(int i=n-1;i>=1;i-=2){
      cout<<vec[i]<<" ";
    }
    for(int i=0;i<n-1;i+=2){
      cout<<vec[i];
      if(i!=n-2)cout<<" ";
      else cout<<endl;
    }
  }
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1000000000;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
struct E {P pa;char cc;};

int main(){
    int h,w;cin >> h >> w;
    char c[401][401];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> c[i][j];
        }
    }
    bool s[h][w];
    memset(s,false,sizeof(s));
    queue<E> q;
    LL ans=0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if(s[i][j]) continue;
            LL a=0,b=0;
            q.push({{i,j},c[i][j]});
            s[i][j]=true;
            while(!q.empty()){
                E e=q.front();
                q.pop();
                if(e.cc=='#') a++;
                else b++;
                int y=e.pa.first;
                int x=e.pa.second;
                for (int k = 0; k < 4; k++) {
                    int nx=x+dx[k],ny=y+dy[k];
                    if(s[ny][nx]) continue;
                    if(0<=ny&&ny<h&&0<=nx&&nx<w&&c[ny][nx]!=e.cc){
                       q.push({{ny,nx},c[ny][nx]}); 
                       s[ny][nx]=true;
                    }
                }
            }
            ans+=a*b;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 512
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int M = sc.nextInt();
    	int[] road = new int[N+1];
    	for (int i = 0; i < M; i++) {
    		road[sc.nextInt()]++;
    		road[sc.nextInt()]++;
    	}
    	StringBuilder sb = new StringBuilder();
    	for (int i = 1; i < N+1; i++) {
    		sb.append(road[i] + "\n");
    	}
    	System.out.println(sb);
    }
}

Measured memory_bytes: 23124
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> H(n); rep(i,n) cin >> H[i];
    vector<vector<int>> G(n, vector<int>());
    rep(i, m){
        int a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int cnt = 0;
    rep(i, n){
        bool fg = true;
        rep(j, G[i].size()){
            int index = G[i][j];
            if(H[i] <= H[index]){
                fg = false;
                break;
            }
        }
        if(fg) cnt++;
    }
    cout << cnt << ln;
}



Measured memory_bytes: 8804
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {

  int N, X;
  cin >> N >> X;
  vector<int> vec(N);
  REP(i, N) cin >> vec[i];

  int count = 0;
  REP(i, N) {
    count += vec[i];
    if (count > X) {
      cout << (i + 1) << endl;
      return 0;
    }
  }
  cout << (N + 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 200005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));

using namespace std;
using P = pair<long long, long long>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];

int H, W;

long long dp[1005][1005];
long long a[1005][1005];

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

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;
	
	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination() {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= MAX; ++i) {
		fact[i] = fact[i-1] * i % MOD;
	}

	inv[MAX] = CalcPow(fact[MAX], MOD - 2);
	for (int i = MAX - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

int dfs(int y, int x) {
	if (dp[y][x] != -1)return dp[y][x];
	ll count = 1;
	for (int i = 0; i < 4;++i) {
		int ny = y + dy[i];
		int nx = x + dx[i];
		if (ny < 0 || H <= ny || nx < 0 || W <= nx)continue;
		if (a[y][x] < a[ny][nx]) {
			count = (count + dfs(ny, nx)) % MOD;
		}
	}
	dp[y][x] = count;
	return count;
}

int main() {
	int r;
	cin >> r;
	int ans = r * r;
	cout << ans << endl;
}

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


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(fopen(".inp", "r")) freopen(".inp", "r", stdin);
    int n; string s;
    cin >> n >> s;
    s = '%' + s;
    int r=0;
    for(int i=1 ; i<=n ; ++i) r += s[i] == 'R';
    int lim = r;
    for(int i=1 ; i<=n ; ++i) {
        if(i <= lim && s[i]=='R') --r;
    }
    cout << r;


    return 0;
}


Measured memory_bytes: 3864
import bisect
import math
N = int(input())
lst = list(map(int, input().split()))
lst.sort()
n = max(lst)
a = bisect.bisect_right(lst, n//2)
if abs(math.ceil(n/2)-lst[a]) >= abs(math.ceil(n/2)-lst[a-1]):
    print(n, lst[a-1])
else:
    print(n, lst[a])

Measured memory_bytes: 14180
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,i,a[2000];
    cin>>n>>k;
    for(i=0;i<n;i++)
        cin>>a[i];

     sort(a,a+n);
     int s=0;
     for(i=0;i<k;i++){
        s=s+a[i];
     }
     cout<<s<<endl;
     return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define For(i,x,y) for(int i=x;i<=y;i++)
#define Rep(i,x,y) for(int i=x;i>=y;i--)
#define Forn(i,x,y) for(int i=x;i<y;i++)
#define oo 1000000
#define zyy 1000000007
#define N 100005
using namespace std;
inline ll read(){ll x=0,f=0;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;return f?-x:x;}
inline void write(ll x){if(x<10) putchar(x+48);else write(x/10),putchar(x%10+48);}
inline void writeln(ll x){if(x<0) putchar('-'),x=-x;write(x);putchar('\n');}
int n,a[N],p[N];
int main(){
	n=read();For(i,1,n) a[i]=read();
	For(i,1,n) p[a[i]]++;
	if(p[0]==1&&n%2==0) return puts("0"),0;
	if(p[0]==0&&n%2==1) return puts("0"),0;
	int ans=1;
	if(n&1){
		for(int i=2;i<=n;i+=2) if(p[i]!=2) return puts("0"),0;
		for(int i=2;i<=n;i+=2) ans=ans*2%zyy;
	}else{
		for(int i=1;i<=n;i+=2) if(p[i]!=2) return puts("0"),0;
		for(int i=1;i<=n;i+=2) ans=ans*2%zyy;
	}
	writeln(ans);
	return 0;
}

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

int main() {
	int n,i;
	cin>>n;
	string s;
	cin>>s;
	int teast=0,twest=0;
	for(i=0;i<s.size();i++)
	{
	    if(s[i]=='E')
	    {
	        teast++;
	    }
	    else
	    twest++;
	}
	int teastleft=0,teastright=0,twestleft=0,twestright=0;
	if(n==1||n==2)
	{
	    cout<<0;return 0;
	}
	int ans=INT_MAX;
	for(i=0;i<n;i++)
	{
	    //cout<<i<<" "<<teastleft<<" "<<twestleft<<" "<<teastright<<" "<<twestright<<endl;
	    if(s[i]=='E')
	    {
	        
	        teastright=teast-1-teastleft;
	        twestright=twest-twestleft;
	    }
	    else
	    {
	        teastright=teast-teastleft;
	        twestright=twest-1-twestleft;
	    }
	    //cout<<i<<" "<<teastleft<<" "<<twestleft<<" "<<teastright<<" "<<twestright<<endl;
	    //cout<<i<<" "<<teastright<<" "<<twestright<<endl;
	    ans=min(ans,twestleft+teastright);
	    if(s[i]=='E')
	    {
	        teastleft+=1;
	    }
	    else
	    twestleft+=1;
	}
	cout<<ans;
	return 0;
}

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

#define mp make_pair
#define pb push_back
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repn(i, n) for(int i = 1; i < n; ++i)
#define repm(i, n, m)  for(int i = n; i < m; ++i)
#define Repm(i, n, m)  for(int i = n; i <= m; ++i)
#define mod 1000000000+7

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

    int ans = 0;
    Repm(i, 0, a){
        Repm(j, 0, b){
            Repm(k, 0, c){
                if((500*i + 100*j + 50*k) == x)   ans++;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<char>> C(H,vector<char>(W));
  vector<vector<char>> Cout(2*H,vector<char>(W));
  for(int y =0;y<H;y++){
    for(int x = 0;x<W;x++){
      cin >> C.at(y).at(x);
    }
  }
  
  for(int y = 0; y<(2*H);y++){
    for(int x = 0;x<W;x++){
      Cout.at(y).at(x) = C.at(int(y/2)).at(x);
      cout << Cout.at(y).at(x);
    }
    cout << endl;
  }

}


Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = list(map(int, readline().split()))

R = {}

for i ,a in enumerate(A):
    val = i + a
    if not val in R:
        R[val] = 1
    else:
        R[val] += 1
ans = 0

for j, a in enumerate(A):
    val = j - a
    if val in R:
        ans += R[val]

print(ans)

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/15  Problem: 073_abc_d / Link: https://abc073.contest.atcoder.jp/tasks/abc073_d?lang=en  ----- */
/* ------問題------

Atcoder国には N 個の町があり、M 本の双方向に移動可能な道で結ばれています。
また、 i 本目の道は町 Ai と町 Bi の間を距離 Ci で結んでいます。
joisinoお姉ちゃんは、この国の R 個の町 r1,r2..rR を訪れることとなりました。
最初に訪れる町までの移動と、最後に訪れる町からの移動は空路で行うが、それ以外は道を使わなければなりません。
町を訪れる順番を、道での移動距離が最小となるように決めた時の移動距離を答えてください。

-----問題ここまで----- */
/* -----解説等-----

巡回セールスマン的なbitDPをすればいいね

----解説ここまで---- */

LL N, M, R;

LL ans = 0LL;

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

	cin >> N >> M >> R;
	VI r(R);
	FOR(i, 0, R) {
		cin >> r[i];
		r[i]--;
	}

	VI a(M), c(M), b(M);
	VVL dist(N, VL(N, LINF));

	FOR(i, 0, M) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--, b[i]--;
		dist[a[i]][b[i]] = dist[b[i]][a[i]] = min((LL)c[i], dist[a[i]][b[i]]);
	}
	FOR(i, 0, N)dist[i][i] = 0;
	FOR(k, 0, N) {
		FOR(i, 0, N) {
			FOR(j, 0, N) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	VVL d(1 << R, VL(R, LINF));
	FOR(i, 0, R) {
		d[1 << i][i] = 0;
	}

	FOR(state, 0, 1 << R) {
		FOR(k, 0, R) {
			if(state&(1<<k))
			FOR(i, 0, R) {
				if (!(state&(1 << i)))
					d[state | 1 << i][i] = min(d[state | 1 << i][i], d[state][k] + dist[r[k]][r[i]]);
			}
		}
	}
	ans = LINF;
	FOR(i, 0, R) {
		ans = min(ans, d[(1 << R) - 1][i]);
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 896
// D - Wizard in Maze
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

// ダイクストラ　O(ElogV)
using PR = pair<int, int>;
#define INF 1'000'000'000
vector<vector<PR>> G; // [from]<to, cost> 隣接リスト
int V; // 頂点数(max:10^3*10^3=10^6)

vi dijkstra(int s){
	vi dist(V, INF);
	dist[s] = 0;
	priority_queue<PR, vector<PR>, greater<PR>> pq; // <dist, u>
	pq.push({0, s});
	while(pq.size()){
		int d, u; tie(d, u) = pq.top(); pq.pop();
		if(dist[u] < d) continue;
		for(auto e:G[u]){
			int v = e.first, next_d = e.second + dist[u];
			if(dist[v] <= next_d) continue;
			dist[v] = next_d;
			pq.push({dist[v], v});
		}
	}
	return dist;
}

int main(){
	int H, W, sh, sw, eh, ew; cin>>H>>W>>sh>>sw>>eh>>ew;
	string S[H]; rp(i, 0, H) cin>>S[i];

	V = H * W;
	G.resize(V); // 隣接リスト初期化
	rp(u, 0, V){
		int h = u / W, w = u % W;
		rp(i, -2, 3) rp(j, -2, 3){ //[i, j]: [-2,-2]~[2,2]
			int nx_h = h + i, nx_w = w + j;
			if(nx_h < 0 || H <= nx_h || nx_w < 0 || W <= nx_w || S[nx_h][nx_w] == '#') continue;
			if(i*i + j*j == 1) G[u].emplace_back(nx_h*W + nx_w, 0);
			else if(i*i + j*j > 1) G[u].emplace_back(nx_h*W + nx_w, 1);
		}
	}

	int ans = dijkstra((sh-1)*W + (sw-1))[(eh-1)*W + (ew-1)];
	cout<< (ans==INF? -1:ans) <<endl;
}


Measured memory_bytes: 172192
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);



signed main(){
  int n, a, b;cin >> n >> a >> b;
  cout << min(a*n, b) << endl;
  return 0;
}






Measured memory_bytes: 256
gene = STDIN.gets.chomp

while true 
  if gene == 'ABC' then 
    puts 'Yes'
    break
  end

  if gene.size <= 4 then
    puts 'No'
    break
  end

  if !gene.gsub!(/ABC/, 'X') then
    puts 'No'
    break
  end

  if !gene.include?('A') and gene.include?('B') and gene.include?('C') then
    gene.gsub!(/X/, 'A')
  elsif gene.include?('A') and !gene.include?('B') and gene.include?('C')  then
    gene.gsub!(/X/, 'B')
  elsif gene.include?('A') and gene.include?('B') and !gene.include?('C') then
    gene.gsub!(/X/, 'C')
  else
    puts 'No'
    break
  end
end

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

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int[] N = new int[3];
		for (int i = 0; i < N.length; i++) {
			N[i] = scanner.nextInt();
		}
		Arrays.sort(N);
		System.out.println(N[0]+N[1]);
		
		scanner.close();
	}

}

Measured memory_bytes: 23764
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef vector<string>vs;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<double>vd;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef vector<ll>vl;
#define rrep(i,x,n) for(int i=(x);i<(n);++i)
#define rep(i,x) rrep(i,0,(x))
#define fi first
#define se second
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define maxs(a,b) (a)=max(a,b)
#define mins(a,b) (a)=min(a,b)

struct UF{
    int N;
    vi par,sz;
    void init(int _N){
        N=_N;
        par=vi(N);
        sz=vi(N,1);
        rep(i,N)par[i]=i;
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        par[y]=x;
        sz[x]+=sz[y];
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
};

int main(){
    int N,Q;
    scanf("%d%d",&N,&Q);
    UF uf;
    uf.init(N);

    while(Q--){
        int type,x,y;
        scanf("%d%d%d",&type,&x,&y);
        if(type){
            printf("%d\n",(uf.same(x,y)?1:0));
        }
        else{
            uf.unite(x,y);
        }
    }

    return 0;
}

Measured memory_bytes: 1328
#include <stdio.h>
int main(void) {
	while(1){
		int t;
		scanf("%d",&t);
		if(t==0) break;
		int n;
		scanf("%d",&n);
		int i,s[n],f[n];
		for(i=0;i<n;i++){
			scanf("%d %d",&s[i],&f[i]);
		}
		int a[n],sum=0;
		for(i=0;i<n;i++){
			a[i]=f[i]-s[i];
		}
		for(i=0;i<n;i++){
			sum=sum+a[i];
		}
		if(sum>=t){
			printf("OK\n");
		}
		else{
			printf("%d\n",t-sum);
		}
	}
	return 0;
}


Measured memory_bytes: 2140
#include <iostream>

using namespace std;

int main() {
    int n, *a;
    cin >> n;
    a = new int[n];
    int i;
    for (i = 0; i < n; i++) {
        cin >> a[i];
    }
    int j;
    for (i = 0; i < n; i++) {
        for (j = n-1; j > i; j--) {
            if (a[j] < a[j-1]) {
                int tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
            }
        }
    }
    cout << a[n-1]-a[0];
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#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>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    ll t1, t2, a1, a2, b1, b2; cin>>t1>>t2>>a1>>a2>>b1>>b2;

    ll p = (a1 - b1) * t1, q = (a2 - b2) * t2;

    if(p > 0) p *= -1, q *= -1;

    if(p + q == 0){
        cout << "infinity" << endl;
    }
    else if(p + q < 0){
        cout << 0 << endl;
    }
    else{
        ll div = -p / (p + q), rem = -p % (p + q);
        if(rem == 0) cout << div * 2 << endl;
        else cout << div * 2 + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int S, h, m, s;
    scanf("%d", &S);
    h = S / 60 / 60;
    m = S / 60 - h * 60;
    s = S - m * 60 - h * 60 * 60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}


Measured memory_bytes: 2700
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static int A;
    static int B;
    static int C;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();

        System.out.println(solve());
    }

    static int solve() {
        int[] arr = new int[3];
        arr[0] = A;
        arr[1] = B;
        arr[2] = C;
        Arrays.sort(arr);
        return arr[2] * 10 + arr[1] + arr[0];
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

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

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

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 410;
int a[MAX_N];
ll dp[MAX_N][MAX_N];
ll acc[MAX_N];

ll ps(int a, int b) {
  return acc[b] - acc[a];
}

int main2() {

  int N = nextInt();
  REP(i, N) a[i] = nextInt();
  acc[0] = 0;
  REP(i, N) acc[i+1] = acc[i] + a[i];

  const ll INF = 1LL << 61;
  REP(i,MAX_N) REP(j, MAX_N) {
    if (j - i == 1) dp[i][j] = 0;
    else
      dp[i][j] = INF;
  }

  for (int len = 2; len <= N; len++) {
    for (int i = 0; i + len <= N; i++) {
      for (int k = 1; k < len; k++) {
        chmin(dp[i][i+len], dp[i][i+k] + dp[i+k][i+len] + ps(i, i+len));
      }
    }
  }
  ll ans = dp[0][N];
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 1536
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

n,k = map(int, input().split())
a = [int(i) for i in input().split()]
x=n
for i in range(n):
    if a[i] == 1:
        x=i
        break

y = n - x - 1

p = (x-1)//(k-1) + (y-1)//(k-1) + 2
if (n-1) % (k-1) == 0:
    q = (n-1)//(k-1)
else:
    q = (n-1)//(k-1)+1

print(min(p,q))


Measured memory_bytes: 25440
#include <iostream>
#include <numeric>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>
#include <iterator>
#include <iomanip>
#define rep(i,n) for(int i = 0; i < (n); i++) 
using namespace std;


int main() {
	int n,count = 0;
	double ans = 0.0, total = 0.0;
	cin >> n;
	vector<int> x(n), y(n), r(n);
	rep(i,n) cin >> x[i] >> y[i];

	iota(r.begin(), r.end(), 0);
	int i = 0;
	do{
		for(int j=1; j<n; j++) {
			double dx = x[r[0]] - x[r[j]];
 			double dy = y[r[0]] - y[r[j]];
			total += sqrt(dx*dx + dy*dy);
			

		}
		count += 1;
	} while (next_permutation(r.begin(), r.end()));
	
	cout << fixed << setprecision(15) <<total/count << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 99999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    llong n,sum=0;
    cin >> n;
    for(llong i=1;i<n;i++){
        sum += i;
    }
    cout << sum << endl;
}

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


int main() {
	int n,y;
  	cin>>n>>y;
  	
  bool ok=false;
  int a,b,c;
  	
  
  	for(int i=0;i<=n;i++){
    	for(int j=0;j<=n;j++){
        	int k=n-i-j;
          if(10000*i+5000*j+1000*k==y&&k>=0){
            a=i;
            b=j;
            c=k;
          	ok=true;
            break;
          }
          
        }
    }
  
  if(ok)cout<<a<<" "<<b<<" "<<c<<endl;
  else cout<<-1<<" "<<-1<<" "<<-1<<endl;
}


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


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


int main()
{
	int t;
	cin >>t;
	array<array<int,10>, 10> ba;
	rep(i,10) rep(j,10) cin >>ba[i][j];
	
	vector<vector<array<int, 2>>> mdl={
		{{0,0},{1,0}, {1,-1}, {1,1},{2,0}},
		{{0,0},{1,1},{0,1},{0,2},{1,0},{1,2},{2,0},{2,1},{2,2}},
		{{0,0},{2,0},{1,-1},{1,0},{1,1},{2,-2},{2,-1},{2,1},{2,2},
		 {3,-1},{3,0},{3,1},{4,0}}
	};
	
	int gk=0;
	rep(i,10) rep(j,10) gk+=ba[i][j];
	
	vector<int> cnd;
	rep(a,t+1) rep(b,t+1) rep(c,t+1){
		if(a+b+c==t && 5*a + 9*b + 13*c == gk){
		
			string s = string(a, '0') + string(b, '1') + string(c, '2');
			do {
				auto wa = ba;
				vector<int> ans;
				rep(i,t){
					int my,mx;
					rep(y,10) rep(x,10) if(wa[y][x]>0){my=y; mx=x; y=100; break;}
					ans.push_back(my*100+mx);
					bool ok=1; 
					int cr=s[i]-'0';
					
					for(auto r: mdl[cr]) if(ok){
						int ny=r[0]+my, nx=r[1]+mx;
						if(ny<0 || ny>=10 || nx<0 || nx>=10){ ok=0; break;}
						if(wa[ny][nx] >0 ) wa[ny][nx]--;
						else if(wa[ny][nx] <1 ){ ok=0; break;}
					}
				}
				bool ng=0;
				rep(y,10) rep(x,10) if(wa[y][x] !=0) ng=1;
				//rep(y,10) rep(x,10) printf("%d%s",wa[y][x],(x==9? "\n":" "));
				if(!ng){
					rep(i,t){
						printf("%d %d %d\n", 
							ans[i]%100 + mdl[s[i]-'0'][1][1],
							ans[i]/100 + mdl[s[i]-'0'][1][0],
							s[i]-'0'+1);
					}
					return 0;
				}
			} while ( next_permutation(s.begin(), s.end()) );
		}
	}
	return 0;
}

Measured memory_bytes: 3368
n = int(input())
a = (int(x) for x in input().split())

b = list(a)

cnt = 0

for i in range(len(b)) :
        for j in range(len(b)) :
                for k in range(len(b)):
                        c = [i,j,k]
                        if len(c) == len(set(c)) :
                                d = [b[i],b[j],b[k]]
                                m = max(d) 
                                if m < sum(d) - m and b[i] != b[j] and b[j] != b[k] and b[k] !=b[i]:
                                        cnt += 1
                                else :
                                        None
                        else :
                                None
                                
print(int(cnt/6))

Measured memory_bytes: 9160
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>

using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < n; i++)


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

    rep (i, 101) {
        if (a*i <= b) {
            x = i;
        }
    }
    cout << min(c, x) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int N,M;
    cin>>N>>M;
    vector<int> H(N);
    rep(i,N){
        cin>>H.at(i);
    }
    vector<int> A(M),B(M);
    rep(i,M){
        cin>>A.at(i)>>B.at(i);
    }
    vector<pair<int,bool>> p(N);
    rep(i,N){
        p.at(i).first=i;
        p.at(i).second=true;
    }
    //各展望台をtrueで初期化
    //各橋について、低い側のpairのbool値をfalseで更新
    //最後にtrueの数を数える
    rep(i,M){
        if(H.at(A.at(i)-1)>H.at(B.at(i)-1)){
            p.at(B.at(i)-1).second=false;
        }else if(H.at(A.at(i)-1)<H.at(B.at(i)-1)){
            p.at(A.at(i)-1).second=false;
        }else{
            //両方同じならどっちもfalse
            p.at(A.at(i)-1).second=false;
            p.at(B.at(i)-1).second=false;
        }
    }
    int ans=0;
    rep(i,N){
        if(p.at(i).second){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5316
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

ll gcd (ll p, ll q)
{
    if (q==0) {return p;}
    return gcd(q,p%q);
}

int main(){
    ll n,i,j,k,s=0,l; cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        { l=gcd(i,j);
            for(k=1;k<=n;k++)
            {
                s+=gcd(l,k);
            }
        }
    } cout<<s;
    return 0;
}


Measured memory_bytes: 3572
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    C = [list(map(int, readline().split())) for _ in range(3)]

    for i in range(3):
        if (
            not C[(i + 1) % 3][0] - C[i][0]
            == C[(i + 1) % 3][1] - C[i][1]
            == C[(i + 1) % 3][2] - C[i][2]
        ):
            print('No')
            return
        if (
            not C[0][(i + 1) % 3] - C[0][i]
            == C[1][(i + 1) % 3] - C[1][i]
            == C[2][(i + 1) % 3] - C[2][i]
        ):
            print('No')
            return

    print('Yes')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9248
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  char c;
  cin >> c;
  c++;
  cout << c ;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

int main(){
  int n;
  cin >> n;
  bool frag=false;
  if((n/100)==7){
    frag=true;
  }else if(((n/10)%10)==7){
    frag=true;
  }else if((n%10)==7){
    frag=true;
  }
  if(frag==true){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

using namespace std;

int main() {
	int N;

	cin >> N;

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

		A[i] -= i + 1;
	}

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

	long long ans = 0;

	if (N % 2 == 0) {
		for (int i = 0; i < N / 2; i++)
			ans += A[N - 1 - i] - A[i];
	}
	else {
		for (int i = 0; i < (N - 1) / 2; i++)
			ans += A[N - 1 - i] - A[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
// Problem : D - Alter Altar
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// It's something that is not good
// & i'm trying right just nothing
// dont't know what god is upto
// but i shall tryna make it come.
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define el "\n"

ll tests=1;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //cin>>tests;
    while(tests--){
        ll n; cin>>n; 
        string s; cin>>s;
        ll ans=INT_MAX;
        ll w=0,r=0;
        ll psum[n+1][2]; psum[0][0]=0; psum[0][1]=0;
        for(int i=0;i<n;i++){
        	psum[i+1][0]=psum[i][0]+1*(s[i]=='W');
        	psum[i+1][1]=psum[i][1]+1*(s[i]=='R');
        }
        //for(int i=0;i<=n;i++) cout<<"dbg "<<psum[i][0]<<" "<<psum[i][1]<<el;
        ans=min(n-psum[n][0],n-psum[n][1]);
        for(int i=1;i<=n-1;i++){
        	ll white=psum[i][0]-psum[0][0];
        	ll red=psum[n][1]-psum[i][1];
        	ll mini=min(white,red);
        	//if(s=="RR") cout<<white<<" "<<red<<el;
        	ans=min(ans,mini+white-mini+red-mini);
        }
        cout<<ans<<el;
    }
}

Measured memory_bytes: 6824
# Edit Distance
def ED():
    X = " " + input()
    Y = " " + input()
    ed = [[float("inf")]*(len(X)) for _ in range(len(Y))]
    
    for j in range(len(X)):
        ed[0][j] = j
    for i in range(len(Y)):
        ed[i][0] = i
        
    for j in range(1, len(X)):
        for i in range(1, len(Y)):
            if (X[j] == Y[i]):
                ed[i][j] = ed[i-1][j-1]
            else:
                ed[i][j] = min(ed[i-1][j-1], ed[i][j-1], ed[i-1][j]) + 1
            
    return ed[len(Y)-1][len(X)-1]

if __name__ == '__main__':
     print(ED())

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

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int N, L, sum = 0, mx = 0;
	
	cin >> N;
	while (N--)
	{
		cin >> L;
		sum += L;
		mx = max(mx, L);
	}//while
	
	if (sum - mx > mx) cout << "Yes\n";
	else cout << "No\n";
	
	return 0;
}//main


Measured memory_bytes: 256
use std::cmp;

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

fn main() {
    read_line();
    let ms: Vec<u64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let hs: Vec<u64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    
    let mut v = Vec::new();
    let mut ps = ms[0];
    for (w, h) in ms.windows(2).zip(hs) {
        let first = cmp::min(ps, h);
        let s = cmp::min(w[1], h - first);
        ps = w[1] - s;
        v.push(first + s);
    }
    println!("{}", v.into_iter().sum::<u64>());
}


Measured memory_bytes: 10676
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265358979
#define mod 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using Graphi = vector<vi>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
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; }
struct edge {
    int to; 
    int weight;
    edge(int t, int w) : to(t),weight(w) {}
};

int main(){

    string s,t; cin >> s >> t;
    int ss = s.size();
    int ts = t.size();
    vector<vi> dp(ss+1,vi(ts+1,0));
    s = ' ' + s;
    t = ' ' + t;
    for(int i = 1; i <= ss; i++){
        for(int j = 1; j <= ts; j++){
            if(s.at(i) == t.at(j)){
                dp.at(i).at(j) = dp.at(i-1).at(j-1)+1;
            }
            else{
                dp.at(i).at(j) = max(dp.at(i-1).at(j),dp.at(i).at(j-1));
            }
        }
    }
    int flag_s = ss;
    int flag_t = ts;
    string ans = "";
    while(flag_s >0 && flag_t >0){
        if(dp.at(flag_s-1).at(flag_t) == dp.at(flag_s).at(flag_t)){
            flag_s--;
        }
        else if(dp.at(flag_s).at(flag_t-1) == dp.at(flag_s).at(flag_t)){
            flag_t--;
        }
        else{
            ans = s.at(flag_s)+ans;
            flag_s--;
            flag_t--;
        }
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	vector<char>st;
	st.push_back('0');
	cin >>s;
	rep(i,s.size()){
		if(st.back()=='S' and s[i]=='T'){
			st.pop_back();
		}else{
			st.push_back(s[i]);
		}
	}
	
	cout<<st.size()-1<<endl;
}

Measured memory_bytes: 772
#include "bits/stdc++.h"
using namespace std;

int cnt(const vector<int> &A){
    int foo=A.size();
    vector<int> a=A;
    sort(a.begin(), a.end());
    long long presum=a[0]*1LL;
    for(size_t i=1; i<a.size(); i++){
        if(presum*2LL<a[i]*1LL){
            foo=a.size()-i;
        }
        presum+=a[i]*1LL;
    }
    return foo;
}

int main(){
    int n;
    while(scanf("%d", &n)!=EOF){
        vector<int> a(n, 0);
        for(int i=0; i<n; i++){
            scanf("%d", &a[i]);
        }
        printf("%d\n", cnt(a));
    }
    return 0;
}

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

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

    bool is_yes = false;
    if(c-a-b>=0){
      if(4*a*b<(c-a-b)*(c-a-b))is_yes = true;
    }
    cout << (is_yes ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int N, K;
    cin >> N >> K;

    vector<int> H(N);

    for(int i = 0; i < N; i++)
    {
        cin >> H.at(i);
    }

    sort(H.begin(), H.end(), greater<int>());

    long cnt = 0;

    for(int i = K; i < N; i++)
    {
        cnt += H.at(i);
    }

    cout << cnt;

    return 0;
}

Measured memory_bytes: 1024
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<climits>
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>

using namespace std;

void solve(){
  int n;
  cin >> n;
  int up = 0,down = 0;
  int prev;
  cin >> prev;
  for(int i = 0;i < n - 1;i++){
    int cur;
    cin >> cur;
    if(cur > prev){
      up = max(up,cur - prev);
    }else{
      down = max(down,prev - cur);
    }
    prev = cur;
  }
  cout << up << ' ' << down << endl;
}


int main(){
  int c;
  cin >> c;
  for(int i = 0;i < c;i++){
    solve();
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

const ll INF=1e9;

int main(){
  ll N,K,S;
  cin>>N>>K>>S;

  vector<ll> ans;
  for(int i=0;i<N;i++){
    if(i<K) ans.push_back(S);
    else{
      if(S==INF) ans.push_back(1);
      else ans.push_back(INF);
    }
  }

  rep(i,N) cout<<ans[i]<<" ";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 2292