akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

struct edge{
   int from, to, cost;
};

int n, m, p;
vector<edge> es;
vector<edge> res;
int d[2510];
int c[2510];
int b[2510];

int calc(){
    rep(i, 0, n) d[i] = INF;
    d[0] = 0;
    rep(i, 0, n){
        bool update = false;
        rep(j, 0, m){
            edge e = es[j];
            if(e.from == e.to) continue;
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if(!update) break;
    }
    return d[n - 1];
}

void calc2(){
    rep(i, 0, n) c[i] = INF;
    c[n - 1] = 0;
    rep(i, 0, n){
        bool update = false;
        rep(j, 0, m){
            edge e = res[j];
            if(e.from == e.to) continue;
            if(c[e.from] != INF && c[e.to] > c[e.from] + e.cost){
                c[e.to] = c[e.from] + e.cost;
                update = true;
            }
        }
        if(!update) break;
    }
}

bool f(){
    memset(b, 0LL, sizeof(b));
    rep(i, 0, n){
        rep(j, 0, m){
            edge e = es[j];
            if(d[e.to] == INF || c[e.to] == INF) continue;
            if(b[e.from] != INF && b[e.to] > b[e.from] + e.cost){
                b[e.to] = b[e.from] + e.cost;
                if(i == n - 1){
                    return true;
                }
            }
        }
    }
    return false;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n >> m >> p;
    rep(i, 0, m){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        es.push_back({a, b, p - c});
        res.push_back({b, a, p - c});
    }
    int ans = -calc();
    calc2();
    if(f()){
        cout << -1 << endl;
        return 0;
    }
    cout << max(0LL, ans) << endl;
}

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

vector<int> u;
vector<int> v;
vector<int> w;

int main() {
    int L;
    cin >> L;
    int r = 1, r_count = 0, M = 0;;
    while (r * 2 <= L) {
        r *= 2;
        r_count++;
    }
    int N = r_count + 1, length = 1;
    for (int i = 1; i <= r_count; i++) {
        u.push_back(i);
        v.push_back(i + 1);
        w.push_back(0);
        u.push_back(i);
        v.push_back(i + 1);
        w.push_back(length);
        length *= 2;
    }
    length /= 2;
    for (int i = N - 1; i >= 1; i--) {
        if (L - length >= r) {
            u.push_back(i);
            v.push_back(N);
            w.push_back(L - length);
            L -= length;
        }
        length /= 2;
    }
    cout << N << " " << u.size() << endl;
    for (int i = 0; i < u.size(); i++) {
        cout << u[i] << " " << v[i] << " " << w[i] << endl;
    }
    return 0;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  int x[M];
  rep(i,M) cin >> x[i];
  sort(x,x+M);
  int d[M-1];
  rep(i,M-1) d[i]=x[i+1]-x[i];
  sort(d,d+(M-1));
  int ans=0;
  rep(i,M-N) ans+=d[i];
  cout << ans << endl;
  return 0;
}

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

int main() {
  int A;
  string S;
  cin>>A>>S;
  int ans = 0;
  for(int i=0;i<A;i++){
    if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C'){
      ans++;
    }
  }
  cout<<ans<<endl;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> P;

int h,w;
string table[21];
int dp[21][21];
int ans;

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

void puts_max(){
    REP(i,h+1){
        REP(j,w+1){
            dp[i][j]=INT_MAX;
        }
    }
}

void solve(int y,int x){
    ans++;
    dp[y][x]=0;
    REP(i,4){
        if(y+dy[i]>=0 && y+dy[i]<h && x+dx[i]>=0 && x+dx[i]<w){
            if(dp[y+dy[i]][x+dx[i]]!=0 && table[y+dy[i]][x+dx[i]]!='#'){
                solve(y+dy[i],x+dx[i]);
            }
        }
    }
}

int main(){
    P st;
    while(cin>>w>>h,w){
        ans=0;
        REP(i,h)cin >> table[i];

        //cout << 1 << endl;
        REP(i,h){
            REP(j,w){
                if(table[i][j]=='@'){
                    st.fr=i;
                    st.sc=j;
                }
            }
        }
        puts_max();
        solve(st.fr,st.sc);
        cout << ans << endl;
    }
}



Measured memory_bytes: 3216
#include <stdio.h>
using namespace std;

int binary_search(int *A, int &key, int &length){
	int left = 0;
	int right = length;
	int mid;

	while(left < right){
		mid = (left + right) / 2;
		
		if(A[mid] == key){
			return 1;
		}else if(key < A[mid]){
			right = mid;
		}else{
			left = mid + 1;	
		}
	}

	return 0;
}

int main(){
	int n, q, s, temp;
	scanf("%d", &n);

	int *S = new int[n];
	for(int i=0; i<n; ++i){
		scanf("%d", &S[i]);
	}

	scanf("%d", &q);
	int *T = new int[q];
	for(int i=0; i<q; ++i){
		scanf("%d", &T[i]);
	}

	int key;
	int count = 0;
	for(int i=0; i<q; ++i){
		key = T[i];
		count += binary_search(S, key, n);
	}

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

	return 0;
}


Measured memory_bytes: 3144
main :: IO ()
main = do
  [n, a, b] <- map read . words <$> getLine
  print $ solve n a b

solve :: Integer -> Integer -> Integer -> Integer
solve n a b
  | odd (b - a) = (min ((n - a) + (n - b) + 1) ((a - 1) + (b - 1) + 1)) `div` 2
  | otherwise = (b - a) `div` 2


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

int main()
{
  int n,m,a,b;
  cin>>n>>m;

  vector<int> r(50,0);
  for(int i=0;i<m;i++)
  {
    cin>>a>>b;
    r.at(a-1)++;
    r.at(b-1)++;
  }

  for(int i=0;i<n;i++)
  {
    cout<<r.at(i)<<endl;
  }
}

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

int main() {
  int a,b,d;
  while(cin >> a >> b >> d) {
    if(a==0 && b==0 && d==0) break;
    int Min=1000000000,Min2=1000000000;
    int x,y;
    for(int i=0; i<=50000; i++) {
      if((b*i+d)%a==0) {
	if(i+(b*i+d)/a<Min || i+(b*i+d)/a==Min && i*b+(b*i+d)/a*a<=Min2) {
	  x=(b*i+d)/a;
	  y=i;
	  Min=x+y;
	  Min2=x*a+y*b;
	}
      }
      if((a*i+d)%b==0) {
	if(i+(a*i+d)/b<Min || i+(a*i+d)/b==Min && i*a+(a*i+d)/b*b<=Min2) {
	  x=i;
	  y=(a*i+d)/b;
	  Min=x+y;
	  Min2=x*a+y*b;
	}
      }
      if(d-a*i>=0 && (d-a*i)%b==0) {
	if(i+(d-a*i)/b<Min || i+(d-a*i)/b==Min && i*a+(d-a*i)/b*b<=Min2) {
	  x=i;
	  y=(d-a*i)/b;
	  Min=x+y;
	  Min2=x*a+y*b;
	}
      }
    }
    cout << x << " " << y << endl;
  }
  return 0;
}


Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n % 2) return x * modpow(x * x % mod, n / 2) % mod;
	return  modpow(x * x % mod, n / 2) % mod;
}

int fact(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= (i + 1);
		ans %= mod;
	}
	return ans;
}

int comb(int n, int r) {
	if (n < r) swap(n, r);
	if (n - r < r) r = n - r;
	return fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) % mod;
}

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

template <typename T>
void greater_sort(vector<T>& vec) {
	sort(all(vec), greater<T>());
	return;
}

int n;
vector<P>o, e;
map<int, int>o2, e2;
signed main() {
	cin >> n;
	rep(i, n) {
		int v;
		cin >> v;
		if (i % 2 == 0) {
			e2[v]++;
		}
		else {
			o2[v]++;
		}
	}
	for (auto s : o2) o.emplace_back(P(s.second, s.first));
	for (auto s : e2) e.emplace_back(P(s.second, s.first));
	greater_sort(o); greater_sort(e);
	if (o[0].second != e[0].second) {
		cout << n - o[0].first - e[0].first << endl;
	}
	else if (o.size() == 1 && e.size() == 1) {
		cout << n / 2 << endl;
	}
	else {
		cout << min(n - o[0].first - e[1].first, n - o[1].first - e[0].first) << endl;
	}
}

Measured memory_bytes: 8824
module ArrayRefinement
  refine Array do
    # 配列に対する最小公倍数
    def lcm
      self.inject(:lcm)
    end

    # 配列に対する最大公約数
    def gcd
      self.inject(:gcd)
    end
  end
end
using ArrayRefinement

def main
  s_len, t_len = gets.split.map(&:to_i)

  s = gets.chomp
  t = gets.chomp

  # s_len と t_len の最小公倍数 ＝ よい文字列の最短の長さ
  ans_len = [s_len, t_len].lcm
  # puts ans_len

  # 文字列SとTで共通の文字が必要なposition
  # S文字列の場合: (s_step * 0), (s_step * 1), (s_step * 2), ...
  # T文字列の場合: (t_step * 01), (t_step * 1), (t_step * 2), ...
  s_step = ans_len / t_len
  t_step = ans_len / s_len
  # puts [s_step, t_step]

  i = 0
  while true do
    s_pos = s_step * i
    t_pos = t_step * i

    break if s_len <= s_pos

    if s[s_pos] != t[t_pos]
      puts '-1'
      return
    end

    i += 1
  end

  puts ans_len
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 2044
//Love and Freedom.
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define inf 20021225
#define ll long long
using namespace std;
int a[(1<<18)|1];
int mx[1<<18][2];
int ans[1<<18];
bool cmp(int x,int y){return a[x]<a[y];}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<(1<<n);i++)
	{
		scanf("%d",&a[i]);
		mx[i][0] = i;
		mx[i][1] = (1<<n);
	}
	for(int i=0;i<(1<<n);i++)
	{
		int tmp[4]={0};
		for(int j=0;j<n;j++)
			if((i>>j)&1)
			{
				int _i = i^(1<<j);
				tmp[0] = mx[i][0]; tmp[1] = mx[i][1];
				tmp[2] = mx[_i][0]; tmp[3] = mx[_i][1];
				sort(tmp,tmp+4,cmp);
				mx[i][0] = tmp[3]; mx[i][1] = tmp[2]==tmp[3]?tmp[1]:tmp[2];
				//printf("%d %d\n",mx[i][0],mx[i][1]);
			}
		ans[i] = a[mx[i][0]] + a[mx[i][1]];
	}
	for(int i=1;i<(1<<n);i++)	ans[i] = max(ans[i],ans[i-1]);
	for(int i=1;i<(1<<n);i++)	printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n,u,v;
    cin >>n >>u >>v;
    --u;
    --v;

    vector<vector<int>> G(n);
    rep(i,n-1){
        int a,b;
        cin >>a >>b;
        --a;
        --b;
        G[a].pb(b);
        G[b].pb(a);
    }

    auto BFS = [&](int s){
        vector<int> d(n,n);
        d[s] = 0;
        queue<int> que({s});
        while(!que.empty()){
            int x = que.front();
            que.pop();
            for(int e:G[x])if(d[e] > d[x]+1){
                d[e] = d[x]+1;
                que.push(e);
            }
        }
        return d;
    };

    vector<int> du = BFS(u), dv = BFS(v);

    int ans = 0;
    rep(i,n){
        if(du[i]<dv[i] && G[i].size()==1){
            int nx = G[i][0];
            ans = max(ans, dv[nx]);
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 6656
#include<stdio.h>
#include<ctype.h>

int main()
{
 char c;
 for(;;){
         scanf("%c",&c);
         if(c=='\n'){printf("\n");
                     break;
                     }
                     else if(islower(c)!=0)printf("%c",toupper(c));
                     else if(isupper(c)!=0)printf("%c",tolower(c));
                     else printf("%c",c);
                     
         }

return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



string s,t;
void solve(){
	cin >> s >> t;
	int cnt = 0;
	for(int i = 0; i < 3; i++){
		if(s[i] == t[i]) cnt++;
	}
	cout << cnt << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver2.2.7
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define COUNT(a,i) upper_bound(ALL(a),i)-lower_bound(ALL(a),i)
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){if(!a[lY].empty()){Vout(a[lY]);}else cout<<endl;}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(iY,0,a.size()){if(!a[iY].empty()){Verr(a[iY]);}else cerr<<'.'<<endl;}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,m,q,qw,er,ty;
  cin >> n >> m >> q;
  VVi ex(n,Vi(1,-INF));
  rep(i,0,m){
    cin >> qw >> er;
    qw--,er--;
    ex[qw].pb(er);
  }
  
  rep(i,0,n){
    ex[i].pb(INF);
  }
  
  rep(i,0,n){
    sort(ALL(ex[i]));
  }
  
  int ans;
  
  VVerr(ex);
  
  rep(i,0,q){
    ans = 0;
    cin >> qw >> er;
    qw--,er--;
    repeq(j,qw,er){
      ty = upper_bound(ALL(ex[j]),er)-ex[j].begin();
      ans += ty-1;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string disp(bool x){
    return x ? "Yes" : "No";
}

void judge(string x,int y,int z){
    if(x[y] == '1' and y<z-1) judge(x,y+1,z);
    else cout << x[y] << endl;
    
    return;
}

int main(){
    string s; cin >> s;
    int k; cin >> k;
    judge(s,0,k);
}
    
    






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, M, S = 0;
    cin >> N >> M;
    vector<int> A(N);
    for (int &a : A) {
        cin >> a;
        S += a;
    }
    sort(A.rbegin(), A.rend());
    int m = 0;
    while (A[m] * 4 * M >= S) m++;
    cout << (m >= M ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <set>
using namespace std;
#define MAX_N (100010)
int L[MAX_N];
int main()
{
    int n;
    int length = 0;
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) {
	int d;
	scanf("%d", &d);

	int *pos = lower_bound( L, L + length, d );

	if ( pos == L + length ) {
	    L[length] = d;
	    length++;
	}
	else {
	    *pos = d;
	}
    }
    
    printf("%d\n", length);

    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = (int) 1e5+99;
int n, m, h[N];
bool jesteMax[N];
vector<pair<int, int>> edges;
int main() {
    IOS; cin >> n >> m;
    for(int i=1; i<=n; ++i) {
        cin >> h[i];
    }
    for(int i=0; i<m; ++i) {
        int prvi, drugi;
        cin >> prvi >> drugi;
        edges.push_back({prvi, drugi});
        edges.push_back({drugi, prvi});

    }
    sort(edges.begin(), edges.end());
    int trenElem=0, trenVr=0;
    bool jeLi=true;
    for(int i=1; i<=n; ++i) {
        jesteMax[i]=true;
    }
    for(auto tren:edges) {
        if(tren.first!=trenElem) {
            jesteMax[trenElem]=jeLi;
            jeLi=true;
            trenElem=tren.first;
            trenVr=h[tren.first];
        }
        if(trenVr<=h[tren.second]) {
            jeLi=false;
        }
    }
    jesteMax[trenElem]=jeLi;
    int br=0;
    for(int i=1; i<=n; ++i) {
        if(jesteMax[i]) ++br;
    }
    cout << br;
    return 0;
}


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

typedef long long LL;
typedef double DB;

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1

const int MOD   = 1e9+7;
const int MAXN  = 1010;

int main()
{
#ifdef LOACL
    freopen("sample.in","r",stdin);
#endif
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    if(abs(n-m)>1)
        cout<<0<<endl;
    else if(n==m)
    {
        LL ans=1;  
        for(int i=2;i<=n;i++)
            ans=(ans*i)%MOD;
        ans=(ans*(2*ans)%MOD)%MOD;
        cout<<ans<<endl;
    }
    else 
    {
        int M=max(n,m);
        LL ans=1;
        for(int i=2;i<=M;i++)
            ans=(ans*i)%MOD;
        LL ans2=1;
        for(int i=2;i<=M-1;i++)
            ans2=(ans2*i)%MOD;
        ans=(ans*(ans2)%MOD)%MOD;
        cout<<ans<<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 loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define inf (1e9)
#define eps (1e-9)

template<class S, class T> inline
ostream& operator<<(ostream&os, pair<S,T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S,T,U> t) {
  return os << '('
    << get<0>(t) << ", "
    << get<1>(t) << ", "
    << get<2>(t) << ')';
}

template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
  if (v.size() == 0) { return os << "(empty)"; }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

//           ^   >  v   <
int dx[] = { -1, 0, 1,  0 };
int dy[] = {  0, 1, 0, -1 };

typedef vector<int> vi;
int memo[20];

bool fourcard(vi&xs) {
  rep (i, 20) memo[i] = 0;
  for (int x: xs) memo[x]++;
  bool res = false;
  rep (i, 20) if (memo[i] == 4) res = true;
  return res;
}

bool straight(vi&xs) {
  {
    bool res = true;
    rep (i, xs.size()) {
      if (xs[i] != xs[0] + i) res = false;
    }
    if (res) return true;
  }
  if (xs[0] == 1) {
    bool res = true;
    for (int i = 1; i < xs.size(); ++i) {
      if (xs[i] != 9 + i) res = false;
    }
    if (res) return true;
  }
  return false;
}

bool fullhouse(vi&xs) {
  if ( xs[0] == xs[1] and xs[2] == xs[3] and xs[3] == xs[4]) return true;
  if ( xs[0] == xs[1] and xs[1] == xs[2] and xs[3] == xs[4]) return true;
  return false;
}

bool three(vi&xs) {
  int n = 0;
  rep (i, xs.size()) {
    int m = 0;
    for (int j = i; j < xs.size(); ++j) {
      if (xs[i] == xs[j]) ++m;
      else break;
    }
    n = max(n, m);
  }
  return n >= 3;
}

bool two(vi&xs) {
  rep (i,20) memo[i] = 0;
  for (int x: xs) memo[x]++;

  int m = 0;
  rep (i,20) if (memo[i] == 2) ++m;
  return m == 2;
}

bool one(vi&xs) {
  rep (i,20) memo[i] = 0;
  for (int x: xs) memo[x]++;

  int m = 0;
  rep (i,20) if (memo[i] == 2) ++m;
  return m == 1;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  random_device dev;
  mt19937 rand(dev());

  int a,b,c,d,e;
  char comma;
  while (cin>>a>>comma>>b>>comma>>c>>comma>>d>>comma>>e) {
    vi xs = {a,b,c,d,e};
    sort(begin(xs), end(xs));
    if (fourcard(xs)) {
      cout << "four card" << endl;
    } else if (fullhouse(xs)) {
      cout << "full house" << endl;
    } else if (straight(xs)) {
      cout << "straight" << endl;
    } else if (three(xs)) {
      cout << "three card" << endl;
    } else if (two(xs)) {
      cout << "two pair" << endl;
    } else if (one(xs)) {
      cout << "one pair" << endl;
    } else {
      cout << "null" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1244
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  x <- unsafeTextToInt <$> T.getLine :: IO Int
  print $ 10 - x `div` 200

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 3740
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
)

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
		//
		if res[i] == 0 {
			return []int64{0}
		}
		//
	}
	return res
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()
	a := make([]int64, n)
	for i := range a {
		a[i] = scanInt64()
		if a[i] == 0 {
			fmt.Println(0)
			return
		}
	}

	ans := big.NewInt(1)
	for _, num := range a {
		ans = ans.Mul(big.NewInt(num), ans)
		if ans.Cmp(big.NewInt(1e18)) == 1 {
			fmt.Println(big.NewInt(-1))
			return
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 5924
N=int(input())
C=input()
from heapq import heappop,heappush
sr=[]
for i,c in enumerate(C):
    if c=='R':
        heappush(sr,-i)
r=C.count('R')
x=0
while sr and -sr[0]>=r:
    heappop(sr)
    x+=1
print(x)

Measured memory_bytes: 17268
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n;
	scanf("%d", &n);
	int c[505];
	int s[505];
	int f[505];
	int t[505];
	int i, j;
	for (i = 0; i < n-1; i++)
	{
		scanf("%d%d%d", c+i,s+i,f+i);
		t[i] = s[i];
	}
	for (i = 0; i < n-1; i++)
	{
		for (j = i; j < n-1; j++)
		{
			while (!(t[i] % f[j] == 0) || t[i] < s[j])
			{
				t[i]++;
			}
			t[i] += c[j];
		}
	}
	for (i = 0; i < n-1; i++)
		printf("%d\n", t[i]);
	printf("0\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
#define double long double
#define PI 3.141592653589793
typedef long long ll;
const int MOD = 1000000007;
const int INF = 11000000000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> divisor(int n){
  vector<int> ret;
  for(int i = 1;i*i <= n;i++){
    if(n%i == 0){
      ret.push_back(i);
      if(i*i != n)ret.push_back(n/i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}


signed main() {
  int n;int ans = 0;int p[20];cin>>n;rep(i,n)cin>>p[i];
  repd(i,1,n-1){
    if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1])){
      ans++;
    }
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, k, a, d;
  in2(n, k);
  vector<ll> c(n, 0);
  rep(i, k){
    in(d);
    rep(j, d){
      in(a);
      c[a - 1]++;
    }
  }
  a = 0;
  rep(i, n){
    if(c[i] == 0)
      a++;
  }
  out(a);
  memi;
}

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

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

  int x = a - c;
  int y = b - d;
  cout << c + y << " " << d - x << " " << a + y << " " << b - x << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)


int hor[9][2]={
{1,8},{0,2},{1,3},
{2,4},{3,5},{4,6},
{5,7},{6,8},{0,7}
};

int _pow10[10]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};

struct A{
	int cost;
	int emp;
	long long s;
	bool operator<(const A &a)const{
		return s<a.s;
	}
};

int main(){
	int ch,cv;
	while(cin>>ch>>cv,ch|cv){
		map<long long,int> mincost;
		map<long long,int>::iterator it;
		long long start=0,goal=0;
		int emp;
		rep(i,9){
			int a;
			cin>>a;
			start+=a*_pow10[i];
			if(a==0)emp=i;
		}
		rep(i,9){
			int a;
			cin>>a;
			goal+=a*_pow10[i];
		}
		A a;
		a.cost=0;
		a.emp=emp;
		a.s=start;
		queue<A> q;
		q.push(a);
		mincost[start]=0;
		int ans=1000000000;
		if(start==goal)ans=0;
		while(!q.empty()){
			a=q.front();q.pop();
			if(mincost[a.s]<a.cost || ans<=a.cost)continue;
			int e=a.emp;		
			rep(i,2){
				a.cost+=ch;
				a.emp=hor[e][i];
				int x=a.s/_pow10[hor[e][i]]%10;
				a.s+=x*_pow10[e]-x*_pow10[hor[e][i]];
				it=mincost.find(a.s);
				if(a.cost<ans && (it==mincost.end() || a.cost < it->second)){
					mincost[a.s] = a.cost;
					q.push(a);
					if(a.s==goal)ans=min(ans,a.cost);
				}
				a.cost-=ch;
				a.emp=e;
				a.s-=x*_pow10[e]-x*_pow10[hor[e][i]];
			}
			rep(i,2){
				int ver=(e+3+i*3)%9;
				a.cost+=cv;
				a.emp=ver;
				int x=a.s/_pow10[ver]%10;
				a.s+=x*_pow10[e]-x*_pow10[ver];
				it=mincost.find(a.s);
				if(a.cost<ans && (it==mincost.end() || a.cost < it->second)){
					mincost[a.s] = a.cost;
					q.push(a);
					if(a.s==goal)ans=min(ans,a.cost);
				}
				a.cost-=cv;
				a.emp=e;
				a.s-=x*_pow10[e]-x*_pow10[ver];
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 24496
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    string S, T; 
    cin >> S >> T; 
    int A[30] = {}, B[30] = {}; 
    int L = S.size(); 
    for (int i = 0; i < L; ++i){
        A[S.at(i) - 'a'] ++; 
    }
    for (int i = 0; i < L; ++i){
        B[T.at(i) - 'a'] ++; 
    }
    sort(A, A + 26);
    sort(B, B + 26); 
    string ans = "Yes"; 
    for (int i = 0; i < 26; ++i){
        if(A[i] != B[i]){
            ans = "No"; 
            break; 
        }
    }
    cout << ans << endl; 
    return 0;
}

Measured memory_bytes: 916
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define SIZE 2000

typedef pair<int, int> P;

vector<int> tree[SIZE];
int parents[SIZE][SIZE];
int id[SIZE][SIZE];
int ans;

void dfs( int v, int parent, int root )
{
    parents[root][v] = parent;

    for ( auto to : tree[v] )
    {
        if ( to == parent ) continue;
        dfs( to, v, root );
    }
}

void dfs2( int v, int parent, int b )
{
    if ( id[b][v] == v )
    {
        ans++;
        b = v;
    }

    for ( auto to : tree[v] )
    {
        if ( to == parent ) continue;
        dfs2( to, v, b );
    }
}

void add( int a, int b )
{
    if ( id[a][b] == b || id[b][a] == a ) return;

    if ( id[a][b] != -1 )
    {
        add( id[a][b], b );
        return;
    }

    if ( id[b][a] != -1 )
    {
        add( id[b][a], a );
        return;
    }

    id[a][b] = b, id[b][a] = a;

    vector<P> nxt;
    queue<int> que;

    que.push( b );
    while ( !que.empty() )
    {
        int v = que.front();
        que.pop();

        for ( auto to : tree[v] )
        {
            if ( to == parents[a][v] ) continue;

            if ( id[a][to] != -1 )
                nxt.push_back( P( to, b ) );
            else
            {
                id[a][to] = b;
                que.push( to );
            }
        }
    }

    que.push( a );
    while ( !que.empty() )
    {
        int v = que.front();
        que.pop();

        for ( auto to : tree[v] )
        {
            if ( to == parents[b][v] ) continue;

            if ( id[b][to] != -1 )
                nxt.push_back( P( to, a ) );
            else
            {
                id[b][to] = a;
                que.push( to );
            }
        }
    }

    for ( auto e : nxt ) add( e.first, e.second );
}

int main( int argc, char **argv )
{
    int N, M;
    cin >> N >> M;

    for ( int n = 0; n < N - 1; n++ )
    {
        int a, b;
        cin >> a >> b;

        tree[a - 1].push_back( b - 1 );
        tree[b - 1].push_back( a - 1 );
    }

    for ( int i = 0; i < N; i++ ) dfs( i, -1, i );

    memset( id, -1, sizeof( id ) );

    for ( int m = 0; m < M; m++ )
    {
        int c, d;
        cin >> c >> d;

        add( c - 1, d - 1 );
    }

    ans = 0;
    for ( int i = 0; i < N; i++ )
        for ( auto to : tree[i] ) dfs2( to, i, i );

    cout << ( ans >> 1 ) << endl;

    return 0;
}


Measured memory_bytes: 32128
#include<stdio.h>
int main(void){
	int h,w,i,j,k;
	
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0&&w==0){
			break;
		}
		for(i=0;i<w;i++){
			printf("#");
		}
		printf("\n");
		for(j=0;j<h-2;j++){
			printf("#");
			for(i=0;i<w-2;i++){
				printf(".");
			}
			printf("#\n");
		}
		for(i=0;i<w;i++){
			printf("#");
		}
		printf("\n\n");
		
	}
	return 0;
}

Measured memory_bytes: 1672
#include <bits/stdc++.h>
using namespace std;
#define int long long

bool used[101010];
priority_queue<int, vector<int>, greater<int>> dup;

signed main() {

  int N, K;
  cin >> N >> K;

  vector<pair<int, int>> sushi;
  for (int i = 0; i < N; ++i) {
    int t, d;
    cin >> t >> d;
    sushi.emplace_back(make_pair(d, t));
  }

  sort(sushi.rbegin(), sushi.rend());

  int var = K;
  long long delic = 0;
  for (int i = 0; i < K; ++i) {
    int d, t;
    tie(d, t) = sushi[i];
    if (used[t]) {
      dup.push(d);
      --var;
    }
    used[t] = true;
    delic += d;
  }

  long long res = delic + var * var;
  for (int i = K; i < N; ++i) {
    int d, t;
    tie(d, t) = sushi[i];
    if (used[t]) continue;
    var++;
    used[t] = true;
    if (dup.empty()) break; /* (-_-#) */
    delic -= dup.top(); dup.pop();
    delic += d;
    res = max(res, delic + var * var);
  }

  cout << res << endl;

}


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

using ll = long long;

int main() {
  int N;
  cin >> N;
  ll sum = 0LL;
  map<ll, ll> elements;
  for (int i = 0; i < N; i++) {
    ll A;
    cin >> A;
    sum += A;
    elements[A]++;
  }

  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    ll B, C;
    cin >> B >> C;

    ll replaceCount = elements[B];

    sum += (C-B)*replaceCount;    
    elements.erase(B);
    elements[C] += replaceCount;

    cout << sum << endl;
  }


  return 0;
}

Measured memory_bytes: 7548
#![allow(non_snake_case)]
fn main() {

    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n:usize = sc.read();
    let mut l:Vec<i32> = sc.vec(n);
    // let t:i32 = sc.read();
    let mut ans:i64 = 0;
    l.sort();
    // println!("{}", bisect_left(&l,t,n));
    // println!("{}", bisect_right(&l,t,n));
    for i in 0..(n-2) {
        for j in (i+1)..(n-1) {
            ans += bisect_right(&l, l[i] + l[j] - 1, n) as i64 -j as i64-1;
        }
    }
    println!("{}", ans);
    
}


// fn bisect_left(v: &[i32], t: i32, n: usize)->i32{
//     if v[0] > t{
//         return 0
//     }
//     let mut l:usize =0;
//     let mut r:usize =n;
//     let mut m;
//     while r-l >= 2{
//         m = (l+r)/2;
//         if v[m] >= t{
//             r = m;
//         }else{
//             l = m;
//         }
//     }
//     r as i32
// }

fn bisect_right(v: &[i32], t: i32, n: usize)->i32{
    if v[0] > t{
        return 0
    }
    let mut l:usize =0;
    let mut r:usize =n;
    let mut m;
    while r-l >= 2{
        m = (l+r)/2;
        if v[m] <= t{
            l = m;
        }else{
            r = m;
        }
    }
    r as i32
}


pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
        .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}



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

const long double eps = 1.0e-10;

long double mysqrt(long double x){

  long double a = sqrt(x); 
  do {
    a = (a + x/a) / 2.0L;
  } while (fabsl(x - a*a) > eps);
  
  return a;
}


int main(){
    long double a,b,c;
    string ans;

    cin>>a>>b>>c;

    long double sqsum = mysqrt(a)*mysqrt(b);

    if( (long double)(a+b) + 2*sqsum < c){
        ans = "Yes";
    }

    else ans = "No";

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max(a,b)-min(a,b))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)n,(int)n)
#define nHr(n,r) nCr((int)(n+r+1),(int)r)
#define sankaku(x) ((1+x)*x)/2
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1][11];

  scanf("%lld",&n);
  rep(i,n) scanf("%s",s[i]);
  rep(i,n) qsort(s[i],10,sizeof(char),upchar);
  qsort(s,n,sizeof(s[0]),upchar);
  
  ll count=1;
  rep(i,n-1){
    if(strcmp(s[i],s[i+1])==0){
      count++;
    }else{
      if(count >= 2) result += nCr(count,2);
      count=1;//count reset
    }
  }
  if(count >= 2) result += nCr(count,2);
  printf("%lld",result);
  return 0;
}



Measured memory_bytes: 2812
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
li = [[] for _ in range(K)]
for k in range(N):
  if T[k] == 'r':
    li[k%K].append([P, 'r'])
  elif T[k] == 's':
    li[k%K].append([R, 's'])
  else:
    li[k%K].append([S, 'p'])
ans = 0
for k in range(K):
  j = 0
  while j < len(li[k])-1:
    if li[k][j][1] == li[k][j+1][1]:
      count = 0
      while(li[k][j+count][1] == li[k][j+count+1][1]):
        count += 1
        if j + count > len(li[k])-2:
          break
      dp = [0, 0]
      for l in range(count+1):
        dp[l%2] += li[k][j+l][0]
        dp[l%2] = max(dp)
      ans += max(dp)
      j += count
    else:
      ans += li[k][j][0]
    j += 1
  if j == len(li[k]) - 1:
    ans += li[k][-1][0]
print(ans)


Measured memory_bytes: 26048
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

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

    s[k-1] = tolower(s[k-1]);

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

h,w = map(int,input().split())
g = []
for i in range(h):
    g.append(input())
c = [[0 for i in range(w)] for i in range(h)]
for i in range(h):
    for j in range(w):
        if g[i][j] == "#":
            if j < w - 1:
                c[i][j+1] += 1
            if j>0:
                c[i][j-1] += 1
            if i < h-1:
                c[i+1][j] += 1
            if i > 0:
                c[i-1][j] += 1
            if i>0 and j>0:
                c[i-1][j-1] += 1
            if i > 0 and j < w -1:
                c[i-1][j+1] += 1
            if i<h-1 and j>0:
                c[i+1][j-1] += 1
            if i < h-1 and j < w - 1:
                c[i+1][j+1] +=1
        if g[i][j] == ".":
            continue
for i in range(h):
    ans = ""
    for j in range(w):
        if g[i][j] == "#":
            ans += "#"
        else:
            ans += str(c[i][j])
    print(ans)

Measured memory_bytes: 3420
#include <algorithm>
#include <cstdio>

#define MOD 1000000007

using namespace std;

long long n, m;

long long itung(int a, int b) {
	if(a > b) {
		swap(a, b);
	}
	long long ret = 1;
	for(int i = 2; i <= a; i++) {
		ret *= i;
		ret = ret % MOD;
	}
	ret *= ret;
	ret = ret % MOD;
	for(int i = a + 1; i <= b; i++) {
		ret *= i;
		ret = ret % MOD;
	}
	return ret;
}

int main() {
	scanf("%d%d", &n, &m);
	if(abs(n-m) > 1) {
		printf("0\n");
		return 0;
	} else if(n == m) {
		printf("%lld\n", (2*itung(n, m)) % MOD);
	} else {
		printf("%lld\n", itung(n, m));
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b;
	cin>>a>>b;
	cout<<(abs(a+b)%2==0?to_string(abs(a+b)/2):"IMPOSSIBLE")<<endl;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a(n + 1);
  for (int i = 0; i < m; i++) {
    int t; cin >> t; a[t]++;
  }
  for (int i = 1; i <= n; i++) {
    a[i] += a[i - 1];
  }
  cout << min(a[x], a[n] - a[x]) << '\n';
}


Measured memory_bytes: 3660
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	char c;
	cin>>c;
	if(isupper(c))cout<<"A"<<endl;
	else cout<<"a"<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h> 
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
typedef long long ll;
using namespace std;
int main(){
  ll n,k=0;
  cin>>n;
  vector<string> a(n);
  rep(i,n){cin>>a[i];}
  rep(i,n){sort(all(a[i]));}
  map<string,ll> t;
  rep(i,n){
    if(t.count(a[i])){t[a[i]]++;}
    else t[a[i]]=1;}
  for(auto x:t){k+=(x.second)*(x.second-1)/2;}
  cout<<k<<endl;
}

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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;

const int mod = 998244353;
const ll inf = 3e18 + 5;

int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }  

const int n = 1e9;

int main(){
    string s;
    cin >> s;
    int sol1 = 0, sol2 = 0;
    for(int i = 0; i < s.size(); i++){
        if(i%2 == 0){
            if(s[i] == '0')
                sol1++;
            if(s[i] == '1')
                sol2++;
        }
        else{
            if(s[i] == '1')
                sol1++;
            if(s[i] == '0')
                sol2++;
        }
    }
    cout << min(sol1, sol2);
}

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  ld ans=0;

  int n,k;cin>>n>>k;
  ld tmp=0;
  vector<ld> P(n);
  for(int i=0;i<n;i++){
    cin>>P[i];
  }
  cout.precision(17);
  for(int i=0;i<n;i++){
    tmp += (P[i]+1)/2.0;
    if(i>=k){
      tmp -= (P[i-k]+1)/2.0;
    }
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3584
n = int(input())
a = list(map(str,input().split()))
odd = []
even = []

for i in range(0,n,2):
    odd.append(a[i])
for i in range(1,n,2):
    even.append(a[i])

if n%2 == 0:
    even.reverse()
    ans = even + odd
else:
    odd.reverse()
    ans = odd + even
print(" ".join(ans))


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

vector<int>rinsetu[100]{};
unordered_map<int, int>taiou;
int main() {
	int a;
	cin >> a;
	for (int b = 0; b < a; b++) {
		int c, d; scanf("%d%d", &c, &d);
		taiou[c] = b;
		for (int e = 0; e < d; e++) {
			int f; scanf("%d", &f);
			rinsetu[b].push_back(f);
		}
	}
	int b; cin >> b;
	for (int c = 0; c < b; c++) {
		int g, h, i; scanf("%d%d%d", &g, &h, &i);
		int e[100]{};
		memset(e, -1, sizeof(e));
		queue<int>Q;
		e[taiou[g]] = 1;
		Q.push(g);
		while (Q.size()) {
			int o = Q.front(); Q.pop();
			o = taiou[o];
			if (e[o] > i)break;
			for (int p : rinsetu[o]) {
				if (e[taiou[p]] == -1) {
				 e[taiou[p]] = e[o] + 1; Q.push(p);
				}
			}
		}
		if (e[taiou[h]] == -1||e[taiou[h]]>i)puts("NA");
		else cout << e[taiou[h]] << endl;
	}
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
struct node
{
    long long int a,b;
}arr[100010];
bool cmp(node aa,node bb)
{
    return aa.a<bb.a;
}
int main()
{
    long long int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i].a>>arr[i].b;
    }
    int i=0;
    long long int sum=0;
    sort(arr,arr+n,cmp);
    while(m>0)
    {
        if(arr[i].b>m)
        {
            sum+=arr[i].a*m;
            m=0;
        }
        else
        {
            sum+=arr[i].a*arr[i].b;
            m-=arr[i].b;
        }
        i++;
    }
    printf("%lld\n",sum);
}


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

int main() {
  int N, K, sum;
  cin >> N >> K;
  sum = 1;
  
  for (int i = 0; i < N; i++) {    

    if (sum * 2 > sum + K){
      sum += K;
  	}
  	else {
      sum *= 2;
  	}
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
while True:
	n = int(input())
	if n == 0: break
	s, vmin, vmax = 0, 1001, -1
	for i in range(n):
		a = int(input())
		vmin = min(vmin, a)
		vmax = max(vmax, a)
		s += a
	print((s-vmin-vmax)//(n-2))


Measured memory_bytes: 5596
#include <iostream>
#include <set>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 2e5+17;
int a[MAXN],ocr[MAXN];
int main(int argc ,char const *argv[])
{
	#ifdef noob
    freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
    #endif
    int n,k;
    cin>>n>>k;
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    	ocr[a[i]]++;
    }
    multiset<int > ms;
    for (int i = 0; i <= n; ++i)
    {
    	if(ocr[i])
    		ms.insert(ocr[i]);
    }
    int ans = 0;
    while(ms.size()>k)
    {
    	ans+=*ms.begin();
    	ms.erase(ms.begin());
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11136
#include<stdio.h>

int main()
{
	float n,m,d;

	scanf("%f %f %f", &n, &m, &d);

	float ans = 0;

	if (d == 0)
		ans = (m - 1) / n;
	else
		ans = 2 * (n - d) * (m - 1) / (n * n);

	printf("%f\n", ans);

	return 0;
}


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

int main() 
{
  double a,b,c,d;
  cin >> a >> b >> c;
  double s,l,h;
  double radianc = c*M_PI/180;
  s = a*b*sin(radianc)/2;
  printf("%lf\n",s);
  d = sqrt(a*a + b*b -2*a*b*cos(radianc));
  l = a + b + d;
  printf("%lf\n",l);
  h = 2*s/a;
  printf("%lf\n",h);
  return 0;
}


Measured memory_bytes: 3472