akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli bit_count(lli x) {
  lli y=0;
  for (; x>0; x>>=1) if (x&1) y++;
  return y;
}

lli n;
lli f[101];
lli p[101][11];
int main() {
  cin >> n;
  for (lli j=0; j<n; ++j) {
    f[j] = 0;
    for (lli i=9; i>=0; --i) {
      lli x; cin >> x;
      f[j] |= (x<<i);
    }
  }
  for (lli j=0; j<n; ++j)
    for (lli i=0; i<=10; ++i)
      cin >> p[j][i];
  lli ans = -1e9;
  for (lli b=1; b<(1<<10); ++b) {
    lli y = 0;
    for (lli j=0; j<n; ++j) {
      lli a = f[j] & b;
      lli c = bit_count(a);
      y += p[j][c];
    }
    ans = max(ans, y);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n, m; read(n), read(m);
  if (n > 9 || m > 9) return puts("-1"), 0;
  printf("%d\n", n * m);

  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;

int main(){

    long long n, k; cin >> n >> k;
    if(n > k) return !printf("0\n");

    long long ans = 1;
    for(long long i = 0; i < n; i++){
        ans *= (k - i);
        ans %= MOD;
    }

    return !printf("%d\n", ans);
}


Measured memory_bytes: 3180
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
#define MOD (1e9+7)
#define INF (1e9)
#define LLINF (4e18)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
void input() {}
template<typename... R> void input(int& f, R&... r) { scanf("%d", &f); input(r...); }
template<typename... R> void input(double& f, R&... r) { scanf("%lf", &f); input(r...); }
template<typename... R> void input(ll& f, R&... r) { scanf("%lld", &f); input(r...); }
template<typename... R> void input(char& f, R&... r) { scanf("%c", &f); input(r...); }
template<typename... R> void input(string& f, R&... r) { cin >> f; input(r...); }
template<typename T, typename... R> void input(vector<T>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion

//gcd
template<typename T>
T gcd(T a, T b) {
    return b ? gcd(b, a%b) : a;
}

int main() {
    ll A, B, C, D; input(A, B, C, D);
    ll cntAC, cntAD, cntBC, cntBD, cntACD,cntBCD;
    cntAC = (A-1) / C;
    cntAD = (A-1) / D;
    cntBC = B / C;
    cntBD = B / D;
    cntACD = (A-1) / (C * D / gcd(C,D));
    cntBCD = B / (C * D / gcd(C, D));
    cout << (B - A + 1) - ((cntBC-cntAC) + (cntBD - cntAD) - (cntBCD - cntACD)) << endl;
    getchar(); getchar();
}

Measured memory_bytes: 256
n,m=map(int,input().split())
par=[-1]*(n+m)

def find(x):
  if par[x]<0:
    return x
  else:
    par[x]=find(par[x])
    return par[x]

def unite(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return False
  else:
    if par[x]>par[y]:
      x,y=y,x
    par[x]+=par[y]
    par[y]=x
    return True

def same(x,y):
  return find(x)==find(y)

def size(x):
  return -par[find(x)]

for i in range(n):
  KL=[int(i) for i in input().split()]
  for j in range(1,len(KL)):
    unite(i,n+KL[j]-1)
chk=True
for i in range(1,n):
  if not same(0,i):
    chk=False
print("YES" if chk==True else "NO")

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 4e4+5;
int add(ll a, ll b) {return (a + b + mod) % mod;}
int mul(ll a, ll b) {return (a * b) % mod;}
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n], b[m], suma = 0, sumb = 0;
    for (int i = 0; i < n; i++)
        cin >> a[i], suma = add(suma, a[i]);
    for (int i = 0; i < m; i++)
        cin >> b[i], sumb = add(sumb, b[i]);
    int x = 0, y = 0;
    for (int i = 0; i < n; i++)
    {
        suma = add(suma, -a[i]);
        x = add(x, suma);
        x = add(x, -mul(a[i], n - i - 1));
    }
    for (int i = 0; i < m; i++)
    {
        sumb = add(sumb, -b[i]);
        y = add(y, sumb);
        y = add(y, -mul(b[i], m - i - 1));
    }
    cout << mul(x, y);
    return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
def check_word(word):
    return word[:int(len(word)/2)] == word[int(len(word)/2):len(word)]

a = input()
count = 0
for i in range(1, len(a)):
    b = a[:-i]
    if check_word(b):
        count = len(b)
        break
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N; cin >> N;
	vector<int> cnt(4);
	for (int i = 0; i < N; i++) {
		string s; cin >> s;
		if (s == "AC") cnt[0]++;
		if (s == "WA") cnt[1]++;
		if (s == "TLE") cnt[2]++;
		if (s == "RE") cnt[3]++;
	}
	cout << "AC x " << cnt[0] << endl;
	cout << "WA x " << cnt[1] << endl;
	cout << "TLE x " << cnt[2] << endl;
	cout << "RE x " << cnt[3] << endl;
	
}


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

int main() {
  long X;
  cin >> X;
  long Y;
  Y=X%11;
  int a;
  if(Y==0)a=0;
  else if(Y<7)a=1;
  else a=2;
  cout << X/11*2+a;
}

Measured memory_bytes: 256
w1 = input()
w2 = input()

s1 = list(w1)
s2 = list(w2)
s1.sort()
s2.sort()

c1 = 0
t1 = ""
a1 = []
for i1 in range(len(s1)):
    if s1[i1] != t1:
        a1.append(c1)
        t1 = s1[i1]
        c1 = 1
        if i1 == len(s1) - 1:
            a1.append(c1)
    else:
        c1 += 1
        if i1 == len(s1) - 1:
            a1.append(c1)

c1 = 0
t1 = ""
a2 = []
for i2 in range(len(s2)):
    if s2[i2] != t1:
        a2.append(c1)
        t1 = s2[i2]
        c1 = 1
        if i2 == len(s2) - 1:
            a2.append(c1)
    else:
        c1 += 1
        if i2 == len(s2) - 1:
            a2.append(c1)

a1.sort()
a2.sort()

if a1 == a2:
    print("Yes")
else:
    print("No")

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

int main() {
  int A, B;

  cin >> A >> B;

  if (A >= 13) {
    cout << B << endl;
  } else if (A >= 6 && A <= 12) {
    cout << B / 2 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()

int subsum(int l, int r, vi& s) {
  if (l > 0)
    return s[r] - s[l - 1];
  else
    return s[r];
}

int subxor(int l, int r, vi& x) {
  if (l > 0)
    return x[r] ^ x[l - 1];
  else
    return x[r];
}

int main() {
  //
  int n;
  cin >> n;
  vi s(n), x(n);
  int sum = 0;
  int xr = 0;
  rep(i, n) {
    int a;
    cin >> a;
    sum += a;
    s[i] = sum;
    xr = xr ^ a;
    x[i] = xr;
  }
  int l = 0, r = 0;
  int cursum = s[0];
  int curxr = x[0];
  ll ans = 0;
  while (l < n) {
    while (r < n - 1 && subsum(l, r + 1, s) == subxor(l, r + 1, x)) {
      r++;
    }
    ans += r - l + 1;
    l++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1920
import java.util.Scanner;
public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	int A=sc.nextInt();
	int B=sc.nextInt();

	if(A<10&&B<10) {
		System.out.println(A*B);
	}else {
		System.out.println(-1);
	}
}
}

Measured memory_bytes: 23124
#define NDEBUG 1

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cassert>
#include <string>
#include <stack>
#include <queue>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

typedef long long ll;

int h,w,n;

int erase(vector<string> & g){
    bool rem[30][30];
    rep(i,h)rep(j,w) rem[i][j] = g[i][j] != '.';
    rep(i,h)rep(j,w){
        int ni = i;
        while(ni < h && g[i][j] == g[ni][j]) ni++;
        if(ni-i >= n) loop(ii,i,ni) rem[ii][j] = false;
        int nj = j;
        while(nj < w && g[i][j] == g[i][nj]) nj++;
        if(nj-j >= n) loop(jj,j,nj) rem[i][jj] = false;
    }

    int res = 0;
    rep(i,h)rep(j,w){
        if(!rem[i][j] && g[i][j]!='.'){
            g[i][j] = '.';
            res++;
        }
    }
    return res;
}

void fall(vector<string> & g){
    // vector<stack<char>> pillar;
    rep(j,w){
        int top = h-1;
        for(int i=h-1;i>=0;i--){
            if(g[i][j] != '.'){
                g[top--][j] = g[i][j];
            }
        }
        while(top >= 0) g[top--][j] = '.';
    }
}

bool solve(vector<string> const & g){
    int rem = 0;
    rep(i,h)rep(j,w) if(g[i][j] != '.') rem++;
    rep(i,h)rep(j,w-1){
        int rrem = rem;
        auto ng = g;
        swap(ng[i][j],ng[i][j+1]);
        fall(ng);
        while(1){
            int e = erase(ng);
            if(e) fall(ng), rrem -= e;
            else break;
        }
        if(rrem == 0) return true;
    }
    return false;
}

int main(){
    while(cin >> h >> w >> n){
        vector<string> g(h);
        rep(i,h) cin >> g[i];
        puts(solve(g) ? "YES" : "NO");
    }
}

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

typedef long long ll;

int main () {
	int N, M;
	cin >> N >> M;
	for (int i=0; i<M; i++) {
		int tmp;
		cin >> tmp;
		N -= tmp;
	}
	if (N>=0)
		cout << N << endl;
	else
		cout << -1 << endl;
	return 0;
}

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en 


constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

void Main(){
    int N;
    cin >> N;
    vector<double> x(N);
    vector<double> y(N);
    REP(i, N){ cin >> x[i]; cin >> y[i]; }
    vector<int> v(N);
    REP(i, N) v[i] = i;
    double su = 0;
    int c = 0;
    do {
        c++;
        REP(i, N - 1)
        {
            double dx = x[v[i + 1]] - x[v[i]];
            double dy = y[v[i + 1]] - y[v[i]];
            su += sqrt(dx * dx + dy * dy);
        }
    } while (next_permutation(ALL(v)));
    cout << su / c << endl;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3780
X, Y = map(int, input().split())

if (Y%2 == 1):
  print("No")
elif (Y > (X*4)):
  print("No")
else:
  yes = False
  for i in range(0,X+1):
    fNum = i
    tNum = X-i
    if ((fNum*4)+(tNum*2)==Y):
      print("Yes")
      yes = True
  if not (yes):
    print("No")
      
  

Measured memory_bytes: 9184
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
int main()
{
  double a,b,h,m;cin >> a >>b >> h >> m;
  double PI = 4*atan(1);
  double theta = m/60.*2.*PI - (h/12.+m/60./12.)*2*PI;
  theta = min(theta, 2*PI - theta);
  double res = sqrt(a*a + b*b - 2*a*b*cos(theta));
  printf("%.10f\n", res);
  return 0;
}


Measured memory_bytes: 4288
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
const ll MOD=1e9+7;
using namespace std;

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

  if(a%2==0){
    num = b-a+1;
    if(num%2==0){
      if(num%4==0){
        cout << 0 << endl;
      }else{
        cout << 1 << endl;
      }
    }else{
      if((num-1)%4==0){
        cout << (0^b) << endl;
      }else{
        cout << (1^b) << endl;
      }
    }
  }else{
    num = b-a-1;
    if(num%2==0){
      if(num%4==0){
        cout << (0^a^b) << endl;
      }else{
        cout << (1^a^b) << endl;
      }
    }else{
      if((num-1)%4==0){
        cout << (0^a^(b-1)^b) << endl;
      }else{
        cout << (1^a^(b-1)^b) << endl;
      }
    }
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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





ll POW(ll n, ll m, ll p){
    ll res = 1, x = n;
    for(ll i = m; i > 0; i >>= 1){
        if(i & 1){
            res *= x;
            res %= p;
        }
        x *= x;
        x %= p;
    }
    return res;
}

ll Fermat(ll a, ll x, ll p){
    return POW(a, p - 1 - x, p);
}


const ll table_size = 200005;
ll fact[table_size], finv[table_size], inv[table_size];

void make_table(ll mod) {
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < table_size; i++){
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

ll nCr(ll n, ll r, ll mod){
    if(n < r) return 0;
    return fact[n] * (finv[r] * finv[n - r] % mod) % mod;
}

int main() {
    ll b, w;
    cin >> b >> w;
    
    make_table(MOD);
    
    vector<ll> p(b + w), q(b + w);
    for(ll i = 1; i < b + w; i++){
        p[i] = (p[i - 1] + ((nCr(i - 1, b - 1, MOD) * Fermat(2, i, MOD)) % MOD)) % MOD;
        q[i] = (q[i - 1] + ((nCr(i - 1, w - 1, MOD) * Fermat(2, i, MOD)) % MOD)) % MOD;
    }
    
    for(ll i = 0; i < b + w; i++){
        cout << (((1 - p[i] + q[i] + MOD) % MOD) * Fermat(2, 1, MOD)) % MOD << endl;
    }
}

Measured memory_bytes: 9984
#include <cstdio>
#include <algorithm>
#include <vector>

const int MN = 100005;

int N;
std::vector<int> G[MN];
int dep[MN], faz[MN], o[MN], cnt[MN], tp;

void DFS(int u, int fz) {
	dep[u] = dep[faz[u] = fz] + 1;
	for (auto v : G[u]) if (v != fz) DFS(v, u);
}

int main() {
	scanf("%d", &N);
	for (int i = 1, x, y; i < N; ++i)
		scanf("%d%d", &x, &y),
		G[x].push_back(y),
		G[y].push_back(x);
	DFS(1, 0);
	int u = 0, v = 0;
	for (int i = 1; i <= N; ++i) if (dep[u] < dep[i]) u = i;
	DFS(u, 0);
	for (int i = 1; i <= N; ++i) if (dep[v] < dep[i]) v = i;
	for (int x = v; x != u; x = faz[x]) o[x] = ++tp;
	o[u] = ++tp;
	for (int i = 1; i <= N; ++i) if (!o[i]) {
		if (G[i].size() == 1) ++cnt[o[G[i][0]]];
		else return puts("-1"), 0;
	}
	int rev = 0;
	for (int i = 1, j = tp; i < j; ++i, --j)
		if (cnt[i] != cnt[j]) { rev = cnt[i] > cnt[j]; break; }
	if (rev) std::reverse(cnt + 1, cnt + tp + 1);
	int now = 1;
	for (int i = 1; i <= tp; ++i) {
		for (int j = 1; j <= cnt[i]; ++j) printf("%d ", now + j);
		printf("%d ", now), now += cnt[i] + 1;
	}
	return 0;
}

Measured memory_bytes: 12160
S=input()
#YY :[00,99]
#MM :[01,12]
head = S[0:2]
tail = S[2:4]
head_mm = head >= "01" and head <= "12"
tail_mm = tail >= "01" and tail <= "12"
if(head_mm and tail_mm):
    ret = "AMBIGUOUS"
elif(head_mm):
    ret = "MMYY"
elif(tail_mm):
    ret = "YYMM"
else:
    ret = "NA"
print(ret)



Measured memory_bytes: 3060
a,b,c=map(int, input().split())
if a>b:
 i=a
 a = b
 b = i
if b>c:
 i=b
 b=c
 c=i
if a>b:
 i=a
 a=b
 b=i

str="{d} {e} {f}"
print(str.format(d=a, e=b, f=c))

Measured memory_bytes: 7672
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a1;
        int num = 0;

        String s = sc.nextLine();
        a1 = s.length();

        for(int i =0; i < a1/2; i++){
            if(s.charAt(i) != s.charAt(a1-i-1)){
                num++;
            }
        }
        System.out.println(num);

            // write your code here
    }

}


Measured memory_bytes: 22996
#include <iostream>
 
int main(int argc, char *argv[])
{
  char c[5];
  std::cin >> c;
  if((c[0] == c[1] && c[2] == c[3] && c[0] != c[2]) ||
     (c[0] == c[2] && c[1] == c[3] && c[0] != c[1]) ||
     (c[0] == c[3] && c[1] == c[2] && c[0] != c[1]))
  {
    std::cout << "Yes" << std::endl;
  }
  else
  {
    std::cout << "No" << std::endl;
  }
}

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

int main()
{
    long long X, K, D;
    cin >> X >> K >> D;
    long long z = abs(X) / D;
    if(z >= K) {
        cout << abs(X) - (K*D) << endl;
    } else {
        K -= z;

        // cout << K << endl;
        // cout << abs(X) - (z*D) << endl;
        if((K%2) == 0) {
            cout << abs(X) - (z*D) << endl;
        } else {
            cout << D - (abs(X) - (z*D)) << endl;
        }

        /*
        if((D%2) == 0) {
            cout << abs(X) - (z*K) << endl;
        } else {
            cout << K - (abs(X) - (z*K)) << endl;
        }
        */
    }
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;


int main(int argc, char **argv) {
    string s;
    cin >> s;

    i64 ans{0},rem{0};

    for (int i=0;i<s.size();++i) {
        if (s[i]=='R') ++rem;
        else rem=0;
        ans = max(ans,rem);
    }

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

Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 1e8;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<int, int> P;

P operator -(P p, P q){
  return P(p.first - q.first, p.second - q.second);
}

inline int distP(P p, P q){
  return abs(p.first - q.first) + abs(p.second - q.second);
}

inline int inner(P p, P q){
  return p.first * q.first + p.second * q.second;
}
inline int cross(P p, P q){
  return p.first * q.second - p.second * q.first;
}

inline bool ok(P p, P q){
  //assert(p.first == 0 || p.second == 0);
  //assert(q.first == 0 || q.second == 0);
  return (inner(p, q) > 0 && cross(p, q) == 0) || (inner(p, q) == 0 && cross(p, q) > 0);
}

int main(){
  assert(P(3, 1) - P(2, 10) == P(1, -9));
  assert(!ok(P(2, 0), P(0, -2)));
  assert(!ok(P(2, 0), P(-2, 0)));
  assert(ok(P(2, 0), P(2, 0)));
  assert(ok(P(2, 0), P(0, 2)));
  int M, N;
  while(cin>>M>>N && M){
    map<string, int> id_inter;
    vector<P> inter_p(M);
    REP(i, M){
      string inter; int x, y;
      cin>>inter>>x>>y;
      int t = i;
      //int t = id_inter.size();
      id_inter[inter] = t;
      inter_p[t] = P(x, y);
    }
    vector<int> connect[1000];
    REP(i, N){
      string inter1, inter2;
      cin>>inter1>>inter2;
      int id1 = id_inter[inter1];
      int id2 = id_inter[inter2];
      connect[id1].push_back(id2);
      connect[id2].push_back(id1);
    }
    string src, dst; cin>>src>>dst;
    int from = id_inter[src];
    int to = id_inter[dst];
    P dist[1000][1000];
    REP(i, M)REP(j, M) dist[i][j] = P(-1, -1);
    queue<P> que;
    FORIT(it, connect[from]){
      que.push(P(from, *it));
      dist[from][*it] = P(distP(inter_p[from], inter_p[*it]), 2);
    }
    P ans = P(INF, INF);
    while(!que.empty()){
      P p = que.front(); que.pop();
      P state = dist[p.first][p.second];
      if(p.second == to){
        ans = min(ans, state);
      }
      FORIT(it, connect[p.second]){
        P p1 = inter_p[p.second] - inter_p[p.first];
        P p2 = inter_p[*it] - inter_p[p.second];
        if(ok(p1, p2)){
          P next = P(state.first + distP(P(0, 0), p2), state.second + 1);
          if(dist[p.second][*it] != P(-1, -1) && dist[p.second][*it] <= next){
            continue;
          }
          dist[p.second][*it] = next;
          que.push(P(p.second, *it));
        }
      }
    }
    if(ans != P(INF, INF)) cout<<ans.second<<endl;
    else cout<<"impossible"<<endl;
    assert(id_inter.size() == M);
  }
  return 0;
}

Measured memory_bytes: 9260
#include <stdio.h>
#define REP(i, n) for(i = 0; i < n; i++)
#define N 100
#define NOTVISITED   0
#define NOWSEARCHING 1
#define VISITED      2

int n, M[N][N];
int state[N], d[N], f[N], time;

void dfs(int v) {
    int i;
    d[v] = time;
    time += 1;
    state[v] = NOWSEARCHING;
    REP(i, n) {
        if(M[v][i] == 1 && state[i] == NOTVISITED) {
            dfs(i);
        }
    }
    state[v] = VISITED;
    f[v] = time;
    time += 1;
}


int main(void) {
    int u, k, v;
    int i, j;

    scanf("%d", &n);
    REP(i, n) REP(j, n) M[i][j] = 0;
    REP(i, n) state[i] = NOTVISITED;

    REP(i, n) {
        scanf("%d %d", &u, &k);
        REP(j, k) {
            scanf("%d", &v);
            M[u - 1][v - 1] = 1;
        }
    }

    time = 1;
    REP(v, n) {
        if(state[v] == NOTVISITED) {
            dfs(v);
        }
    }

    REP(i, n) printf("%d %d %d\n", i + 1, d[i], f[i]);

    return 0;
}

Measured memory_bytes: 636
# 根付き木の表現
class Node:
    def __init__(self):
        self.parent_id = -1
        self.depth = 0
        self.children = []

global nodes

V = int(input())

# 空のノードで初期化
nodes = []
for _ in range(V):
    node = Node()
    nodes.append(node)

# 親子関係を入力
for _ in range(V):
    table = list(map(int, input().split()))
    node_id = table[0]

    num = table[1]
    for i in range(num):
        child_id = table[2+i]
        nodes[node_id].children.append(child_id)
        nodes[child_id].parent_id = node_id

# 根を探して深さを計算
def calc_depth(node_id, arg_depth):
    nodes[node_id].depth = arg_depth
    for child in nodes[node_id].children:
        calc_depth(child, arg_depth+1)

for i in range(V):
    if nodes[i].parent_id == -1:
        calc_depth(i, 0)
        break

# 解答
for i in range(V):
    print("node %d: parent = %d, depth = %d, "%(i,nodes[i].parent_id,nodes[i].depth),end = "")
    if nodes[i].parent_id == -1:
        print("root,",end = "")
    else:
        if len(nodes[i].children) == 0:
            print("leaf,",end = "")
        else: #節
            print("internal node,",end = "")

    print(" [",end = "")
    print(', '.join(map(str,nodes[i].children)),end = "")
    print("]")



Measured memory_bytes: 40704
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
//#include <numeric> //iota
//#include <sstream>
#include <cstring>
//#include <tuple>
//#include <random>
//#include <string>
//#include <unordered_set>
//#include <bitset>
//#include <unordered_map>
//#include <stack>
#include <cmath>
//#include <deque>
#include <queue>
//#include <list>
#include <array>
using namespace std;
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define vec vector
#define pb push_back
#define pp pop_back
#define fi first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define se second
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i) 
#define inc_rep(i,a,n,inc) for (int i = a; i < n; i += inc) 
#define couts(x) cout << x << "\n" 
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long, long long>  PLII;
template<typename T>
void print(vector<T>& v) {rep(i, 0, (int)v.size()) cout << v[i] << " ";cout << endl;}
int nxt() {int x;cin >> x;return x;}
ll nxtl() {ll x;cin >> x;return x;}
string nxts() {string x;cin >> x;return x;}
double nxtd() {double x; cin >> x; return x;}

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll power_mod(ll a, ll b, ll mo) {
	ll ans = 1;
	while (b) {
		if(b & 1) {
			ans = (ans % mo * a % mo) % mo;
		}
		a = (a % mo * a % mo) % mo;
		b /= 2;
	}
	return ans;
}
int main() {
	IOS;
	int n;
	cin >> n;
	vector<ll> v(n);
	for (auto &x : v) {
		cin >> x;
	}
	ll const mod = 1e9 + 7; 
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		sum += v[i];
	}
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		ll z = (sum - v[i])  % mod * v[i] % mod;
		ans = (ans + z) % mod;
	}
	cout << (ans * power_mod(2, mod- 2, mod)) % mod ;
}















	



Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n,k;
  cin>>n>>k;
  ll a[n];
  rep(i,0,n){
    cin>>a[i];
  }
  sort(a,a+n);
  ll ans=1e9;
  rep(i,0,n-k+1){
    ans=min(a[k-1+i]-a[i],ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int x[110];
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=b;i++) scanf("%d",&x[i]);
	
	int max = a, min = a;
	for(int i=a;i<=101;i++)
	{
		for(int j=1;j<=b;j++) if(i==x[j]) goto u;
		max = i;
		break;
		u:;
	}
	
	for(int i=a;i>=0;i--)
	{
		for(int j=1;j<=b;j++) if(i==x[j]) goto v;
		min = i;
		break;
		v:;
	}
	
	if(a-min<=max-a) printf("%d",min);
	else printf("%d",max);
}

Measured memory_bytes: 1728
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        
        List<Integer> m  = new ArrayList<>();
        List<Integer> f  = new ArrayList<>();
        List<Integer> r  = new ArrayList<>();
        
        int count = 0;
        
        while(true){
            m.add(sc.nextInt());
            f.add(sc.nextInt());
            r.add(sc.nextInt());
            
            if(m.get(count) == -1 && f.get(count) == -1 && r.get(count) == -1) break;
            
            count++;
        }      
        
        for(int i=0; i<m.size()-1; i++){
            if(m.get(i) == -1  || f.get(i) == -1){
                System.out.println("F");
            }else if(m.get(i) + f.get(i) >= 80){
                System.out.println("A");
            }else if(m.get(i) + f.get(i) >= 65 ){
                System.out.println("B");
            }else if(m.get(i) + f.get(i) >= 50 ){
                System.out.println("C");
            }else if(r.get(i) >= 50){
                System.out.println("C");
            }else if(m.get(i) + f.get(i) >= 30 ){
                System.out.println("D");
            }else{
                System.out.println("F");
            }
            
        }
    }
}





Measured memory_bytes: 26192
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const long int size=2*100000;
int main(){
  long N,A[size],b,result=0;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>A[i];
    A[i]-=(i+1);
  }

  sort(A,A+N);

  b=A[N/2];

  for(int i=0;i<N;i++) result+=abs(A[i]-b);
 
  cout<<result<<endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();

    while (true) {
      c -= b;
      if (c <= 0) {
        System.out.println("Yes");
        break;
      }
      a -= d;
      if (a <= 0) {
        System.out.println("No");
        break;
      }
    }

  }

}


Measured memory_bytes: 35804
if __name__ == "__main__":
    K, N = map(int, input().split())
    A = list(map(int, input().split()))

    A.sort()

    # print(A)

    min_d = 1000000
    for i in range(1, N):
        d = K - (A[i] - A[i-1])
        min_d = min(min_d, d)

    d = A[N-1] - A[0]
    min_d = min(min_d, d)

    print(min_d)


Measured memory_bytes: 26444
a = input()
b = input()
k = []
l = []
np=0
nq=0
for i in range(0,len(a)):
    if a[i] not in k:
        k.append(a[i])
        np+=1
    if b[i] not in l:
        l.append(b[i])
        nq+=1
    if i != 0:
        if not (k.index(a[i])==l.index(b[i]) and ((a[i-1]==a[i] and b[i-1] == b[i]) or ( a[i-1] != a[i] and b[i-1]!= b[i]))):
            np*=0
if np == nq:
    print("Yes")
else:
    print("No")

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

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

    // n要素の整数の配列a
    vector<int> a(n);
    for(int i = 0 ; i < n ; i++){
        cin >> a[i];
    }

    // aは全て正の整数なので、求めたい値は(aの最大値 - aの最小値)
    // maxi:最大値, mini:最小値 を入れる変数
    // それぞれ十分 小さい/大きい 値を最初に入れておく
    int maxi = 0, mini = 2000000000;
    for(int i = 0 ; i < n ; i++){
        // max(a, b)はaとbのうち大きいもの
        // maxiと比較することで、より大きい値を見つけた時にのみ書き換えることができる
        maxi = max(maxi, a[i]);
        
        // min(a, b)はaとbのうち小さいもの
        // miniと比較することで、より小さい値を見つけた時にのみ書き換えることができる
        mini = min(mini, a[i]);
    }

    cout << maxi - mini << endl;

    return 0;
}

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

std::string str;

int main()
{
	std::cin >> str;
	std::cin >> str;
	if(str[0]<='z' && str[0]>='a')
		str[0]+='A'-'a';
	std::cout << 'A' << str[0] << 'C' << '\n';
}

Measured memory_bytes: 384
import fileinput

dict = {}
for i in range(ord("a"), ord("z") + 1):
	dict[chr(i)] = 0

for line in fileinput.input():
	for char in list(line):
		c = char.lower()
		if c in dict:
			dict[c] += 1

# ?????????????????¨?????????.
for i in range(ord("a"), ord("z") + 1):
	print(chr(i), ":", dict[chr(i)])

Measured memory_bytes: 7500
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

void lun(int depth, int t_depth, int64_t num, int t_order, vector<int64_t>& lun_list)
{
    if (t_order == lun_list.size())
    {
        return;
    }
    if (depth == t_depth)
    {
        lun_list.push_back(num);
    }
    else
    {
        const int dig = num % 10;
        const int l = depth == 0 ? 1 : max(0, dig - 1);
        const int r = depth == 0 ? 9 : min(9, dig + 1);
        for (int i = l; i <= r; i++)
        {
            lun(depth + 1, t_depth, num * 10 + i, t_order, lun_list);

            if (t_order == lun_list.size())
            {
                return;
            }
        }
    }
}

int main()
{
    int k;
    cin >> k;
    for (int d = 1;; d++)
    {
        vector<int64_t> lun_list;

        lun(0, d, 0, k, lun_list);
        if (k == lun_list.size())
        {
            cout << lun_list.back() << endl;
            break;
        }
        else
        {
            k -= lun_list.size();
        }
    }
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
unsigned f(unsigned long k){
    if(k == 1)
        return 1;
    return (k*f(k-1))%(1000000000+7);
}
int main(){
    long n,m;
    cin>>n>>m;
    if(abs(n-m)>1){
        cout<<"0";
        return 0;
    }
    int t = max(n,m);
    long nn = n+m - (t-1)*2;
    long nc = f(n),mc;
    if(n== m)
        mc = nc;
    else
        mc = f(m);
    cout<<(((mc*nc)%(1000000000+7))*nn)%(1000000000+7);
}

Measured memory_bytes: 1792
using System;
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var L = new int[n];
        var R = new int[n];
        L[0] = a[0];
        R[n - 1] = a[n - 1];
        for (int i = 1; i < n; i++)
        {
            L[i] = GCD(L[i - 1], a[i]);
        }
        for (int i = n - 2; i >= 0; i--)
        {
            R[i] = GCD(R[i + 1], a[i]);
        }
        int ans = Math.Max(L[n - 2], R[1]);
        for (int i = 1; i < n - 1; i++)
        {
            int temp = GCD(L[i - 1], R[i + 1]);
            if (ans < temp) ans = temp;
        }
        Console.WriteLine(ans);
    }
    public static int GCD(int a, int b)
    {
        if (a > b) return GCD(b, a);
        while (a != 0)
        {
            var temp = b % a;
            b = a;
            a = temp;
        }
        return b;
    }
}

Measured memory_bytes: 23772
#include <bits/stdc++.h>
using namespace std;
#define rep(shoki,i,n) for(int i= shoki; i<n; i++)
#define _GLIBCXX_DEBUG

int main(){
    int n,a; cin>>n>>a;
    if((n%500)>a) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
//#define inf 2000000000
#define inf 8000000000000000000
#define pi 3.14159265358979323846264338328
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a)
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;

inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=200005;
//i_am_noob
int n,a[maxn],b[maxn],cnt[maxn]={0},x,Pow2[maxn],ans=0;
string str;
vector<int> vec;

bool comp(){
    rep(n){
        if(a[i]>b[i]) return false;
        if(a[i]<b[i]) return true;
    }
    return false;
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> str;
    rep(n) a[i]=str[i]-'0';
    Pow2[0]=1;
    rep2(i,1,maxn) Pow2[i]=Pow2[i-1]*2%MOD;
    rep2(i,1,2*n+1) if(2*n%i==0&&n%i) vec.pb(i);
    rep(sz(vec)){
        x=vec[i]/2;
        rep1(j,n){
            if(j<x) b[j]=a[j];
            else b[j]=1-b[j-x];
        }
        rep1(j,x) cnt[i]=add(cnt[i],a[j]*Pow2[x-1-j]);
        if(!comp()) cnt[i]=add(cnt[i],1);
        rep1(j,i) if(vec[i]%vec[j]==0) cnt[i]=sub(cnt[i],cnt[j]);
        //print2(vec[i],cnt[i]);
    }
    rep(sz(vec)) ans=add(ans,cnt[i]*vec[i]%MOD);
    print1(ans);
    return 0;
}


Measured memory_bytes: 8464
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    map<ll, ll> m;

    ll ans = 0;
    REP(i, N) {
        ans += m[A[i] - i];

        m[-A[i] - i]++;
    }

    cout <<  ans << endl;
}


Measured memory_bytes: 27384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#define PB push_back
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
vector<string> s;
string S,ans,cur;
int n,m;

void sol(string &s) {
	vector<int> p1,p2;
	string t="";
	for(int i=0;i<s.length();++i)
		if(s[i]=='a') p1.PB(i);
		else p2.PB(i);
	if(s[0]=='a') {
		int last=-1;
		for(int i=0;i<p1.size();++i)
			if(p1[i]>last) last=p2[i],t+="ab";
	}
	else {
		for(int i=0;i<p1.size();++i) {
			string p="";
			int x=i,y=i;
			while(1)
				if(x<p1.size()&&(y==p2.size()||p1[x]<p2[y]))
					p+='a',x++;
				else if(y<p2.size())
					p+='b',y++;
				else break;
			if(p>t) t=p;
		}
	}
	s=t;
}


int main() {
	rd(n);
	cin>>S;
	int cnt=0;	
	for(int i=0;i<n*2;++i) {
		if(S[i]=='a') cnt++;
		else cnt--;
		cur+=S[i];
		if(cnt==0) {
			s.PB(cur);
			cur="";
		}
	}
	for(int i=0;i<s.size();++i) sol(s[i]);
	ans=s.back();
	for(int i=(int)s.size()-2;i>=0;--i) {
		int flg=1;
		for(int j=0;j<min(s[i].length(),ans.length());++j)
			if(s[i][j]!=ans[j]) {
				if(s[i][j]<ans[j]) flg=0;
				break;
			}
		if(flg) ans=s[i]+ans;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define PR pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;
#define int ll

// Programming contest

const int MAX=1e5+10;

signed main(){
  int N,R,L;
  cin>>N>>R>>L;
  
  set<PR> teams;
  int score[MAX];
  int tele[MAX];
  for(int i=0; i<N; i++){
    teams.insert(mk(0,i+1));
    score[i+1]=0;
    tele[i+1]=0;
  }
  
  int now_time=0;
  for(int i=0; i<R; i++){
    int team,time,s;
    cin>>team>>time>>s;
    PR M=*(teams.begin());
    tele[M.second]+=time-now_time;
    teams.erase(mk(-score[team],team));
    teams.insert(mk(-score[team]-s,team));
    score[team]+=s;
    now_time=time;
  }
  PR M=*(teams.begin());
  tele[M.second]+=L-now_time;

  PR ans=mk(0,0);
  for(int i=1; i<=N; i++){
    if(ans.first<tele[i]){
      ans.second=i;
      ans.first=tele[i];
    }
  }
  cout<<ans.second<<en
}



Measured memory_bytes: 10880
#include <stdio.h>
#include <cmath>
using namespace std;
int main(){
  int i, n;
  while (scanf("%d", &n)) {
    int sum=0, arr[n];
    double avg, s1=0.0, s2;
    if (n==0) break;
    for (i=0; i<n; i++) {
      scanf("%d", &arr[i]);
      sum+=arr[i];
    }
    avg=(double)(sum)/n;
    for (i=0; i<n; i++) {
      s1+=(arr[i]-avg)*(arr[i]-avg);
    }
    s2=s1/n;
    printf("%lf\n", sqrt(s2));
  }
}


Measured memory_bytes: 2724
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

struct score
{
    int num;
    string city;
    int score;
};

int main(void)
{
    int N, tmpScore;
    string tmpStr;
    cin >> N;
    vector<struct score> SP(N);
    for (int count = 0; count < N; count++)
    {
        cin >> SP.at(count).city >> SP.at(count).score;
        SP.at(count).num = count + 1;
    }
    sort(SP.begin(), SP.end(), [](struct score &a, struct score &b)
    {
        if (a.city == b.city)
        {
            return a.score > b.score;
        }
        else
        {
            return a.city < b.city;
        }
    });
    for (struct score x : SP)
    {
        cout << x.num << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,M,X;
ll C[13];
ll A[13][13];
int main(){
    cin>>N>>M>>X;
    for(ll i=0;i<N;i++){
        cin>>C[i];
        for(ll j=0;j<M;j++){
            cin>>A[i][j];
        }
    }
    ll ans=INF;
    for(ll state=0;state<(1<<N);state++){
        ll cnt[13]={};
        ll money=0;
        for(ll i=0;i<N;i++){
            if((1<<i)&state){
                money+=C[i];
                for(ll j=0;j<M;j++){
                    cnt[j]+=A[i][j];
                }
            }
        }
        bool f=true;
        for(ll i=0;i<M;i++){
            if(cnt[i]<X)f=false;
        }
        if(f)ans=min(ans,money);
    }
    cout<<((ans==INF)?(-1):ans)<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    
    map<ll, ll> M;
    ll sum = 0;
    rep(i, N) {
        sum += A[i];
        M[sum]++;
    }
    ll ans = 0;
    for(auto a: M) {
        if(a.first == 0) {
            ans += a.second * (a.second + 1) / 2;
        }
        else ans += a.second * (a.second - 1) / 2;
    }
    output(ans);
    
    
    
    return 0;
}


Measured memory_bytes: 14336
import sys
A,B = map(int,input().split())

if A < 0 or B < 0 or A > 100 or B > 100:
    sys.exit()

if A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0:
    print("Possible")
else:
    print("Impossible")

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

int main(){
	int n,k;
	cin >> n >> k;
	int a[n];
	REP(i,n) cin >> a[i];
	int num[MAX] = {};
	REP(i,n) num[a[i]]++;
	int type = 0;
	for(int i = 1; i < MAX; i++){
		if(num[i] > 0) type++;
	}
	sort(num, num + MAX);
	int ans = 0, cnt = 0;
	for(int i = 1; i < MAX; i++){
		if(num[i] > 0){
			cnt++;
			if(cnt > type - k) break;
			ans += num[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#define ll long long

using namespace std;

int main(){
    int N;
    cin >> N;
    if(N==1){
        cout << "Hello World" << endl;
    }
    else{
        int A,B;
        cin >> A >> B;
        cout << A+B << 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;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    string n;
    cin>>n;
    int sz=n.size();
    int dp[sz+1][2];
    dp[0][0]=0;
    dp[0][1]=1;
    rep(i,sz){
        int d=n[i]-'0';
        dp[i+1][0]=min(dp[i][0]+d,dp[i][1]+10-d);
        dp[i+1][1]=min(dp[i][0]+d+1,dp[i][1]+9-d);
    }
    cout<<dp[sz][0]<<endl;
}


Measured memory_bytes: 9220