akhauriyash/Code-Regression huggingface dataset:
/*************************************
 * @contest:      AtCoder ABC156.
 * @user_id:      63720.
 * @user_name:    Jomoo.
 * @time:         2020-02-22.
 * @language:     C++.
 * @upload_place: Luogu.
*************************************/ 

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

typedef signed char          int8;
typedef unsigned char       uint8;
typedef short                int16;
typedef unsigned short      uint16;
typedef int                  int32;
typedef unsigned            uint32;
typedef long long            int64;
typedef unsigned long long  uint64;

template <typename Int>
inline Int read()       
{
    Int flag = 1;
    char c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
    return init * flag;
}

template <typename Int>
inline Int read(char &c)       
{
    Int flag = 1;
    c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
    return init * flag;
}

template <typename Int>
inline void write(Int x)
{
    if (x < 0) putchar('-'), x = ~x + 1;
    if (x > 9) write(x / 10);
    putchar((x % 10) | 48);
}  

template <typename Int>
inline void write(Int x, char nextch)
{
    write(x);
    putchar(nextch);
}

#define P 1000000007

int n, a, b;

int64 fexp(int64 a, int np)
{
    int64 res = 1;
    while (np) {
        if (np & 1) res = res * a % P;
        a = a * a % P;
        np >>= 1;
    }
    return res;
}
#define inv(x) fexp(x, P - 2)
int64 fac(int n)
{
    register int64 res = 1;
    for (register int i = 2; i <= n; i++) res = res * i % P;
    return res;
}
int64 C(int n, int m)
{
    int64 res = 1;
    for (int i = m; i >= m - n + 1; i--) res = res * i % P;
    return res * inv(fac(n)) % P;
}

int main()
{
    n = read<int>();
    a = read<int>();
    b = read<int>();
    int64 ans = fexp(2, n) - 1;
    ans = (ans - C(a, n) + P) % P;
    ans = (ans - C(b, n) + P) % P;
    write(ans, 10);
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split(" ").map(&:to_i)
b = gets.split(" ").map(&:to_i)

max = 0

for i in 0..n-1 do
    asum = 0
    bsum = 0
    for j in 0..i do
        asum = asum + a[j]
    end
    for k in i..n-1 do
        bsum = bsum + b[k]
    end
    if max < asum + bsum
        max = asum + bsum
    end
end
 
puts max

Measured memory_bytes: 1788
string vowels = ['a', 'e', 'i', 'o', 'u'];
void main(){
	char c = _scan!char();
	if(vowels.find(c).empty)writeln("consonant");
	else writeln("vowel");
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W,C=0;
  cin >> H >> W;
  vector<vector<char>> MS(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> MS[i][j];
    }  
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(MS[i][j]=='.'){
        if(j-1>-1){
          if(MS[i][j-1]=='#') C++;
        }
        if(j-1>-1&&i+1<H){
          if(MS[i+1][j-1]=='#') C++;
        }
        if(j-1>-1&&i-1>-1){
          if(MS[i-1][j-1]=='#') C++;
        }
        if(j+1<W){
          if(MS[i][j+1]=='#') C++;
        }
        if(i+1<H){
          if(MS[i+1][j]=='#') C++;
        }
        if(i-1>-1){
          if(MS[i-1][j]=='#') C++;
        }
        if(i+1<H&&j+1<W){
          if(MS[i+1][j+1]=='#') C++;
        }
        if(i-1>-1&&j+1<W){
          if(MS[i-1][j+1]=='#') C++;
        }
        MS[i][j]='0'+C;
        C=0;
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(j==W-1)cout << MS[i][j] << endl;
      else cout << MS[i][j];
    }
  }
}

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

using namespace std;

const int N = 122; 
int dp[N][2][4];

void solve() {
    string s; cin >> s;
    int n = s.size();
    int K; cin >> K;
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        int x = s[i]-'0';
        for (int j:{0,1}) {
            for (int d = 0; d <= 9; d++) if(j || d<=x){
                for (int k: {0,1,2,3}) {
                    int nj = j || d<x;
                    int nk = k + (d>0);
                    if (nk <= 3) {
                        dp[i+1][nj][nk] += dp[i][j][k];
                    }
                }
            }
        }
    }
    int res = dp[n][0][K] + dp[n][1][K];
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 256
// In the name of Allah the Lord of the Worlds.

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

typedef long long ll;

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

    ll a ,b ;
    cin >> a >> b;
    ll cnt = 0 , tot = 1;
    while(tot<b){
        cnt++;
        tot--;
        tot+=a;

    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){

    int a,b,c,d;
    cin >> a >> b >>c >>d;

    int n[105] = {};

    n[a]++;
    n[b]--;

     n[c]++;
    n[d]--;

    int t = 0,ans= 0;
    rep(i,0,105){
	t += n[i];

	if(t >= 2)ans ++;
    }
    P(ans);
    
    
    return  0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define BITBOOL(x,a) (((x)>>(a))&1LL)
//0=r 1=s 2=p
int winhand(int h){
  return ( (2+h) % 3);
}
int main(){
  int n, k; vector<pair<int,int>> pt(3); string t;
  cin >> n >> k >> pt[0].first >> pt[1].first >> pt[2].first >> t;
  FOR(i,0,3) pt[i].second = i;
  //sort(pt.begin(),pt.end());
  //reverse(pt.begin(), pt.end());
  ll ans = 0;
  vector<int> myh(n,-1);
  FOR(i,0,n){
    int h_;
    if(t[i]=='r') h_ = 0;
    if(t[i]=='s') h_ = 1;
    if(t[i]=='p') h_ = 2;
    h_ = winhand(h_);
    myh[i] = h_;
  }
  FOR(i,0,n){
    int aa=-1,bb=-1,cc=-1;
    if(i-k>=0) aa = myh[i-k];
    if(i+k<n) bb = myh[i+k];
    if(aa==-1 || aa!=myh[i]) {ans += pt[myh[i]].first;continue;}
    FOR(j,0,3){
      if(j==myh[i]) {continue;}
      if(j==bb) continue;
      cc = j;
    }
    if(cc!=-1) myh[i]=cc;
  }
  cout << ans << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
using namespace std;
  
int T[100010];
int find(int m,int x){
    int r=0,l=m-1,ans=0;
    while(1){
        ans++;  
        if(r>=l)break;
        if(T[(r+l)/2]==x)return ans;
        if(T[(r+l)/2]>x)l=(r+l)/2-1;
        else if(T[(r+l)/2]<x)r=(r+l)/2+1;
if(r>l) break;
    }
    return ans;
}
int main(){
    int n,k,num,ans;
    while(1){
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>T[i];
        }
        cin>>k;
        ans=find(n,k);
        cout<<ans<<endl;
    }
    return 0;
}

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

int main()
{
    long long k,sum=0;
    cin>>k;
    for(int a=1;a<=k;a++)
    {
        for(int b=1;b<=k;b++)
        {
            for(int c=1;c<=k;c++)
            {
                sum+=__gcd(a,__gcd(b,c));
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 3636
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
 
//#define mp make_pair
#define bug(v)                    cerr<<#v<<" = "<<(v)<<endl;
#define ERASE(x)                  x.erase(unique(x.begin(),x.end()),x.end())
#define pb                        emplace_back
#define vii                       vector<int>
#define vll                       vector<ll>
#define vpll                      vector< pair <ll,ll> >
#define pll                       pair <ll,ll>
#define pii                       pair <int,int>
#define pq                        priority_queue< int >
#define khtm                      "\n"
#define F                         first
#define S                         second
#define fr(i,a,n)                 for(i=a;i<n;i++)
#define mem(arr,l)                memset(arr,l,sizeof arr)
#define ALL(x)                    x.begin(), x.end()
#define frr(i,a,n)                for(i=n-1;i>=a;i--)
#define fast                      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase                  ll T; cin>>T; while(T--)


const int MAX = 1e6 +2;
const ll inf =  1e18;
const int N = 1010;
//const ll mod = 998244353 ;
const ll mod=1e9+7;
inline ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;return a;}
inline ll mul(ll a,ll b){return ((a%mod)*1ll*b)%mod;}
inline ll power(ll a,ll b){ll rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}


/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 

ll i,j,k,l,m,r,n;
ll a[MAX],b[MAX];
bool vis[20*N];
int main()
{
 
  #ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//cout << setprecision(15) << fixed;
fast

cin >> n >> k;
  for(int i = 1; i <= n; i++)
    cin >> a[i];
  int take = min(k, 200000LL);
  k -= take;
  int cur = 1;
  while(take > 0)
  {
    cur = a[cur];
    take--;
  }
  if(k == 0)
  {
    cout << cur;
    return 0;
  }
  int len = 0;
  while(!vis[cur])
  {
    vis[cur] = 1;
    len++;
    cur = a[cur];
  }
  k %= len;
  while(k > 0)
  {
    cur = a[cur];
    k--;
  }
  cout << cur;


  #ifndef ONLINE_JUDGE
  cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
  #endif
 
  return 0;
 
}


Measured memory_bytes: 5400
n = [[0 for i in range(3)] for j in range(3)]

for i in range(3):
  x,y,z = input().split()
  n[i][0] = int(x)
  n[i][1] = int(y)
  n[i][2] = int(z)
  
a = [0,0,0]
b = [0,0,0]



isCmp = False

for j in range(100 +1):
  b[0] = j
  
  a[0] = n[0][0] -b[0]
  a[1] = n[1][0] -b[0]
  a[2] = n[2][0] -b[0]
  b[1] = n[0][1] -a[0]
  b[2] = n[0][2] -a[0]
  
  isCmp = True
  
  for l in range(3):
    for m in range(3):
      if n[l][m] != a[l] + b[m]:
        isCmp = False
        
    if isCmp == False:
      break
      
  if isCmp == True:
    print('Yes')
    isCmp = True
    break
    
if isCmp == False:
  print('No')

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  string s, t; std::cin >> s >> t;
  int slen = s.size(), tlen = t.size();
  vvi dp(slen+1, vi(tlen+1));
  rep(i, slen) rep(j, tlen) {
    if (s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
    chmax(dp[i+1][j+1], dp[i+1][j]);
    chmax(dp[i+1][j+1], dp[i][j+1]);
  }

  string ans;
  int i = slen, j = tlen;
  while (i != 0 && j != 0) {
    if (i > 0 && dp[i-1][j] == dp[i][j]) i--;
    else if (j > 0 && dp[i][j-1] == dp[i][j]) j--;
    else i--, j--, ans += s[i];
  }
  reverse(rng(ans));
  std::cout << ans << "\n";
}


Measured memory_bytes: 35584
//https://atcoder.jp/contests/dp/tasks/dp_n
//shauryakr
#include<bits/stdc++.h>
using namespace std;
long long int arr[405], n;
long long int sum[405];
long long int dp[405][405];
long long int solve(int i, int j)
{
    if(i == j)
    {
        return 0;
    }

    if(dp[i][j] != -1)
        return dp[i][j];

    long long int ans = 1000000000000000;
    long long int tmp = sum[j] - sum[i-1];
    for(int k = i; k<j; k++)
    {    
        ans = min(ans, solve(i, k) + solve(k+1, j) + tmp);
    }
    dp[i][j] = ans;
    return ans;
}

int main()
{
    cin >> n;
    for(int i=1; i<=n; i++)
    {
        cin >> arr[i];
        sum[i] = sum[i-1] + arr[i];
    }

    memset(dp, -1, sizeof dp);
    cout << solve(1, n) << endl;

    // for(int i=1; i<=n; i++)
    // {
    //     for(int j=1; j<=n; j++)
    //     {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    return 0;
}

Measured memory_bytes: 1536
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000
#define MOD 1000000007
typedef long long ll;
typedef pair<string,int> P;

vector<int> V[30];

int main(){
  bool flag=true;
  ll ans;
  int  now,next;
  string s,t;
  cin>>s>>t;

  for(int i=0;i<(int)s.size();i++){
    V[s[i]-'a'].push_back(i);
  }
  for(int i=0;i<=25;i++) V[i].push_back(110000);

  for(int i=0;i<(int)t.size();i++){
    int temp=t[i]-'a';
    if((int)V[t[i]-'a'].size()==1){
      flag=false; break;
    }
    
    if(i==0){
       now=V[temp][0]; ans=now+1;
    }else{
      next=*upper_bound(V[temp].begin(),V[temp].end(),now);
      if(next==INF){
        ans+=V[temp][0]+s.size()-now;
        now=V[temp][0];
      }else{
        ans+=next-now;
        now=next;
      }
      
    }
    //cout<<i<<" "<<now<<" "<<ans<<endl;
  }

  if(flag) cout<<ans<<endl;
  else cout<<-1<<endl;
}


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

int main(void) {
    string s;

    while (1) {
        bool flag = false;
        getline(cin, s);
        if (s == ".") break;

        stack<char> sc;
        char tmp;
        for (auto i : s) {
            switch (i) {
            case '(':
                sc.push('(');
                break;
            case '[':
                sc.push('[');
                break;
            case ')':
                if (sc.size() == 0) {
                    flag = true;
                    break;
                }

                tmp = sc.top();
                if (tmp == '(') {
                    sc.pop();
                } else {
                    flag = true;
                }
                break;
            case ']':
                if (sc.size() == 0) {
                    flag = true;
                    break;
                }

                tmp = sc.top();
                if (tmp == '[') {
                    sc.pop();
                } else {
                    flag = true;
                }
                break;
            }
            if (flag) break;
        }
        if (flag || sc.size() != 0) {
            cout << "no" << endl;
        } else {
            cout << "yes" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1180
N, X = map(int, input().split())
axis = list(map(int, input().split()))

ans = abs(axis[0] - X)

def gcd(n, m) :
    n, m = max(n, m), min(n, m)
    if m == 0 :
        return n
    return gcd(m, n % m)

for a in axis :
    ans = gcd(ans, abs(a - X))

print(ans)

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

const int N = 1e5 + 10;

int n;
int num[N];
int cf[N];

signed main ( void ) {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>num[i]; 
		cf[i]=num[i]-num[i-1];
	}
	int ans=-1,tmp=0;
	for(int i=1;i<=n;i++){ 
		if(cf[i]>0){
			ans=max(ans,tmp);
			tmp=0;
			continue;
		}
		tmp++;
	}
	ans=max(ans,tmp);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
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; }

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  vector<queue<char>> Q(3);
  for(auto &p : A) Q[0].push(p);
  for(auto &p : B) Q[1].push(p);
  for(auto &p : C) Q[2].push(p);
  int c = 0;
  while(1) {
    int n = Q[c].front() - 'a'; Q[c].pop();
    c = n;
    if(Q[c].empty()) break;
  }
  char ans = 'A' + c;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int d;

vector<int> c;
vector<vector<int>> s;
vector<int> t;

int last(int d, int i) {
  int j;

  for (j=d; j>=0; j--) {
    if (t[j] == i) return d-j;
  }
  return d+1;
}

int cdiff(int, int);

int main()
{
  int i, j;

  c.resize(26);
  cin >> d;
  for(i=0; i<26; i++) {
    cin >> c[i];
  }

  s.resize(d);
  for (i=0; i<d; i++) {
    s[i].resize(26);
    for (j=0; j<26; j++) {
      cin >> s[i][j];
    }
  }
  t.resize(d);

  for (i=0; i<d; i++) {
//    t[i] = i%26;
    t[i] = 0;
  }
  int conf = 0;

  for (i=0; i<d; i++) {
    conf += s[i][t[i]];
//printf("+ %d\n", s[i][t[i]]);
    for (j=0; j<26; j++) {
      int cm;
      cm = c[j] * last(i, j);
      conf -= cm;
//printf("- %d\n", cm);
    }
  }

//printf("conf = %d\n", conf);

  int maxconf;
  maxconf = conf;

//  for (int loop=0; loop<10; loop++) {

    for (i=0; i<d; i++) {
      int oc;
      int mc;
      oc = t[i];
      mc = oc;
//printf("t[%d] = %d conf = %d\n", i, oc, conf);
      for (j=(oc+1)%26; j!=oc; j=(j+1)%26) {
        conf += cdiff(i, j);
//printf("t[%d] = %d conf = %d\n", i, t[i], conf);
        if (conf > maxconf) {
          maxconf = conf;
          mc = j;
//printf("%d %d %d\n", i, j, conf);
        }
      }
      t[i] = mc;
      conf = maxconf;
    }
//printf("maxconf = %d\n", maxconf);
//  }

  for (i=0; i<d; i++) {
    printf("%d\n", t[i]+1);
  }
  return 0;
}
int cdiff(int xd, int xq) {
  int rdiff;
  int oq;
  int j;

  oq = t[xd];

  rdiff = s[xd][xq] - s[xd][oq];
//printf("s[%d][%d] = %d -> s[%d][%d] = %d\n", xd ,oq, s[xd][oq], xd, xq, s[xd][xq]);

  for (j=xd; j<d; j++) {
    if (j>xd && t[j]==oq) break;
    rdiff += c[oq] * last(j, oq);
//printf("c[%d] * last(%d, %d) = %d\n", oq, j, oq, c[oq] * last(j, oq));
  }
  for (j=xd; j<d; j++) {
    if (j>xd && t[j]==xq) break;
    rdiff += c[xq] * last(j, xq);
//printf("c[%d] * last(%d, %d) = %d\n", xq, j, xq, c[xq] * last(j, xq));
  }

  t[xd] = xq;
  for (j=xd; j<d; j++) {
    if (j>xd && t[j]==oq) break;
    rdiff -= c[oq] * last(j, oq);
//printf("c[%d] * last(%d, %d) = %d\n", oq, j, oq, c[oq] * last(j, oq));
  }
  for (j=xd; j<d; j++) {
    if (j>xd && t[j]==xq) break;
    rdiff -= c[xq] * last(j, xq);
//printf("c[%d] * last(%d, %d) = %d\n", xq, j, xq, c[xq] * last(j, xq));
  }
  return rdiff;
}


Measured memory_bytes: 3792
#include <iostream>
#include <string>
#include <vector>
#include <cmath>


using namespace std;
int main()
{
	int x;
	vector<int> prime;
	int n = 2;

	cin >> x;

	int max_prime = ceil(sqrt(x));
	//printf("%d\n", max_prime);
	//prime.push_back(2);
	while (n <= max_prime) {
		bool isPrime = true;
		for (int i = 0; i < prime.size(); i++) {
			if (n % prime[i] == 0) {
				isPrime = false;
				break;
			}
		}

		if (isPrime) {
			prime.push_back(n);
		}

		n++;
		//printf("%d\n", n);
	}

	/*
	for (int i = 0; i < prime.size(); i++) {
		printf("%d\n", prime[i]);
	}
	*/
	n = x;

	while (true) {
		bool isPrime = true;
		for (int i = 0; i < prime.size(); i++) {
			if (n % prime[i] == 0) {
				isPrime = false;
				break;
			}
		}

		if (isPrime) {
			break;
		}

		n++;
	}
	
	
	
	
	if (x > 2) {
		cout << n << endl;
	}
	else {
		cout << 2 << endl;
	}
	return 0;


}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc147/tasks/abc147_c

#include "algorithm"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  V<V<PL>> st(N, V<PL>(0));

  rep(i, N) {
    ll a;
    cin >> a;

    rep(j, a) {
      ll x, y;
      cin >> x >> y;
      x--;

      st[i].emplace_back(x, y);
    }
  }

  ll res = 0;

  rep(digit, 1 << N) {
    VL facts(N, -1);  // 0: 嘘, 1: 本当

    ll ok = true;

    rep(i, N) {
      auto fact = (digit >> i) & 1;
      if (!fact) {
        if (facts[i] == 1) {
          ok = false;
          break;
        }
        facts[i] = 0;
        continue;
      }
      if (facts[i] == 0) {
        ok = false;
        break;
      }
      facts[i] = 1;

      for (auto pa : st[i]) {
        if (facts[pa.fi] == -1) {
          facts[pa.fi] = pa.se;
        } else {
          if (facts[pa.fi] != pa.se) {
            ok = false;
            break;
          }
        }
      }

      if (!ok) break;
    }

    if (ok) {
      ll sums = 0;
      rep(i, N) if (facts[i]) sums++;
      chmax(res, sums);
    }
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int H, W;
	
	cin >> H >> W;

	char old[H+1][W+1];
	char new_[2*H+1][W+1];

	for (int i = 1; i <= H; i++)
	{
		for ( int j = 1; j <= W; j++)
		{
			cin >> old[i][j];
			int a = i * 2 - 1;
			int b = i * 2;
			new_[a][j] = old[i][j];
			new_[b][j] = old[i][j];
		}
	}

	for (int i = 1; i <= 2*H; i++)
	{
		for (int j = 1; j < W; j++)
		{
			cout << new_[i][j];
		}
		cout << new_[i][W] << endl;

	}
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#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;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

int main() {
  //
  ll n;
  cin >> n;
  string s;
  cin >> s;
  string add;
  int open = 0;
  rep(i, s.size()) {
    if (s[i] == '(') {
      open++;
    } else {
      if (open == 0) {
        add += "(";
      } else {
        open--;
      }
    }
  }
  while (open > 0) {
    s += ")";
    open--;
  }
  cout << add + s << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define N 1116
#define M 111116
#define inf 1111111116
#define next nxt
 
int n,k,a[M],b[M],f[M],next[M],p[N],now[N],d[N],h[N],cnt,ans;
vector<int> x;
queue<int> q;
 
void add(int x,int y){
	a[++k]=x;b[k]=y;f[k]=1;next[k]=p[x];p[x]=k;
	a[++k]=y;b[k]=x;f[k]=0;next[k]=p[y];p[y]=k;
}
 
bool travel(){
	memcpy(now,p,sizeof(p));
	fill(d+1,d+n+3,inf);d[n+1]=0;
	q.push(n+1);h[n+1]=1;
	while (!q.empty()){
		int x=q.front();q.pop();h[x]=0;
		for (int t=p[x];t;t=next[t])
			if (f[t]&&d[x]+1<d[b[t]]){
				d[b[t]]=d[x]+1;
				if (!h[b[t]]) q.push(b[t]),h[b[t]]=1;
			}
	}
	return d[n+2]<inf;
}
 
int dinic(int x,int lmt){
	if (x==n+2) return lmt;int cnt=0;
	for (int t=now[x];t;t=now[x]=next[t])
		if (f[t]&&d[x]<d[b[t]]){
			int tmp=dinic(b[t],min(f[t],lmt-cnt));
			f[t]-=tmp;f[t^1]+=tmp;cnt+=tmp;
			if (cnt==lmt) return lmt;
		}
	return cnt;
}
 
bool check(int x){
	if (x%2==0||x==1) return false;
	for (int i=2;i*i<=x;i++)
		if (x%i==0) return false;
	return true;
}
 
int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
 
int main(){
	n=read();k=1;x.push_back(0);
	for (int i=1;i<=n;i++){
		int t=read();
		if (x.back()==t) x.pop_back();
		else x.push_back(t);
		x.push_back(t+1);
	}
	n=x.size()-1;
	for (int i=1;i<=n;i++)
		if (x[i]&1) add(n+1,i),cnt++;
		else {
			for (int j=1;j<=n;j++)
				if (check(abs(x[i]-x[j]))) add(j,i);
			add(i,n+2);
		}
	while (travel()) ans+=dinic(n+1,inf);
	printf("%d\n",n-ans+(cnt-ans)%2);
	return 0;
}

Measured memory_bytes: 384
/**********************************************

1.
2.テァツつュテァツ板ーテゥツォツ佚ィツシツ?
3.sumita.takaki@gmail.com

last updated: 2013-07-10@19:37

 **********************************************/
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;


int main(void){

        while(1){
                
        int number = 0;
        int place_num = 0;
        int frag = 0;

        cin >> number >> place_num;
        if(number==0 && place_num == 0)break;
        int num = place_num;
        int vote[number][place_num];
        vector<int> total(num);
        vector<int> tmp_total(num);
        vector<int> pos(num);
        vector<int> order(num);


        for(int i=0; i<number; i++){
                
                for(int j=0; j<place_num; j++){
                        
                        cin >> vote[i][j];
                }
                
        }

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

                for(int j=0; j<number; j++){

                        tmp_total[i] = tmp_total[i] + vote[j][i]; 
                }
                total[i] = tmp_total[i];
        }

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


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

                for(int j=0; j < place_num; j++){
                        if(tmp_total[place_num - i-1] == total[j]){

                                for(int k=0; k<i; k++){
                                        if(order[k] == j+1){
                                                frag =1;
                                                break;                         
                                        }else{
                                                frag =0;
                                        }
                                }
                                if(frag==0){
                                        order[i] = j+1;
                                        break;
                                }else{
                                        frag=0;
                                }
                        }
                }
        }

                for(int i=0; i<place_num; i++){
                        if(i==place_num-1){
                                cout << order[i]<<endl;
                        }else{
                                cout << order[i]<<" ";       
                        
                        }
                }

        }

        return 0;

}

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

int main() {
	while(1){
		int n;
		cin >> n;
		if(n == 0)break;
		string card;
		cin >> card;
		
		int p[10] = {0}, f = 0, t = 0;
		int c = 0;
		while(c < 100){
			string s = card.substr(c, 1);
			if(s == "M")
				p[t]++;
			else if(s == "S"){
				f += p[t] + 1;
				p[t] = 0;
			}
			else if(s == "L"){
				p[t] += (f + 1);
				f = 0;
			}
			
			if(t == n - 1)
				t = 0;
			else
				t++;
			c++;
		}
		
		sort(p, p + n);
		for(int i = 0; i < n; i++)
			cout << p[i] << " ";
		cout << f << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
n = int(input())

a =[]
a_li = input().split()

memo = 0
for i in range(n):
    a.append(int(a_li[i]))

    if i%2 == 0:
        memo += int(a_li[i])
    else:
        memo -= int(a_li[i])

ans = [0 for i in range(n)]

ans[0] = int(memo/2)*2

for i in range(1,n):
    ans[i] = int((a[i-1] - ans[i-1]/2) * 2)

for i in range(n):
    print(ans[i], end ="")
    if i != n-1:
        print(" " , end ="")



Measured memory_bytes: 19384
// Decayed Bridges
// 所要時間 分
// 全然わからなかった
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

class UnionFind {
public:
    vector<ll> d;
    UnionFind(ll n) : d(n, -1) {}
    ll find(ll x){
        if(d[x] < 0){
            return x;
        }
        return d[x] = find(d[x]);
    }

    bool unite(ll x, ll y){
        ll a = find(x);
        ll b = find(y);
        if(a == b){
            return false;
        }
        else if(size(a) < size(b)){
            swap(a, b);
        }
        d[a] += d[b];
        d[b] = a;
        return true;
    }

    bool same(ll x, ll y){
        return find(x) == find(y);
    }

    ll size(ll x){
        return -d[find(x)];
    }
};

int main() {

    ll n, m;
    cin >> n >> m;
    vector<ll> a(m), b(m);
    rep(i, m){
        ll x, y;
        cin >> x >> y;
        a[i] = --x;
        b[i] = --y;
    }

    UnionFind uf(n);
    vector<ll> ans(m);
    ans[m-1] = n * (n-1) / 2;
    for(int i=m-2; i>=0; --i){
        if(uf.same(a[i+1], b[i+1])){
            ans[i] = ans[i+1];
        }
        else{
            ans[i] = ans[i+1] - uf.size(a[i+1]) * uf.size(b[i+1]);
            uf.unite(a[i+1], b[i+1]);
        }
    }

    rep(i, m){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,cnt;cin >> a;
    vector<int> n(a+1);
    for(int i=0;i<a;i++){
        cin >> n[i];
    }

    cnt = 1;
    b = n[0];

    for(int j=1;j<a;j++){
        if(n[j]>=b){
            cnt++;
            b = n[j];
        }else{
            continue;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
H,W = map(int,input().split())

MarkList = []
for M in range(H):
    MarkList.append(input().split())

for N in range(2*H):
    if N%2 == 0:
        print("{0}".format(MarkList[int(N/2)][0]))

    else:
        print("{0}".format(MarkList[int((N-1)/2)][0]))

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int main()
{
	// ??\?????¨?????°??£?¨?
	int n;

	// ??\???
	cin >> n;

	// 1??????n?????§?????????
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 == 0 || i % 10 == 3)
		{
			cout << " " << i;
		}
		else
		{
			int x = i;
			while (x)
			{
				x /= 10;
				if (x % 10 == 3)
				{
					cout << " " << i;
					break;
				}
			}
		}
	}

	cout << endl;
	return 0;
}

Measured memory_bytes: 1160
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = INTINF;
	int tmp;
	int n, k;
	cin >> n >> k;
	int x[n+1]={}, rw[n+1]={};
	REP1(i, n){
		cin>> x[i];
		rw[i]=rw[i-1]+x[i];
	}
	for(int i = k; i<=n; i++){
		if(x[i] >= 0 && x[i-k+1] >= 0){
			ans = min(ans, x[i]);
		}
		else if(x[i] < 0 && x[i-k+1] < 0){
			ans = min(ans, 0- x[i-k+1]);
		}
		else {
			ans = min(ans, min(x[i], -x[i-k+1]) + x[i] - x[i-k+1]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

constexpr int Nmax = 100'000;

bool isEnough(const int* const w, const int& n, const int& k, const int& p) {
    int j = 0;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (sum + w[i] > p) {
            j++;
            sum = 0;
        }
        if (j >= k) { return false; }
        sum += w[i];
    }
    return true;
}

int searchP(const int* const w, const int& n, const int& k) {
    int p = -1;

    int left = 0;
    for (int i = 0; i < n; i++) {
        if (w[i] > left) { left = w[i]; }
    }
    int right = left * static_cast<int>(ceil(static_cast<float>(n) / k));
    int center = (left + right) / 2;
    while (true) {
        if (isEnough(w, n, k, center)) {
            right = center - 1;
            p = center;
        } else {
            left = center + 1;
        }
        int next = (left + right) / 2;
        if (next == center or left > right) { break; }
        center = next;
    }
    return p;
}

int main() {
    ios::sync_with_stdio(false);

    int n, k;
    int w[Nmax];
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
    }

    cout << searchP(w, n, k) << endl;

    return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <cstring>

#define PENALTY_TIME 20

using namespace std;

typedef struct TeamResult {
  int teamNo;
  int solved;
  int totalTime;
  int *incorrect;
} TeamResult;

static void sort(TeamResult *teamResult, int numOfTeam);
static void PrintResult(TeamResult *teamResult, int numOfTeam);

int main(void)
{
  int M, T, P, R;
  while (cin >> M >> T >> P >> R) {
    if (T == 0) break;	// 入力の条件は 1<=T なので0で終了

    TeamResult teamResult[T];
    // TeamResultの初期化
    memset(teamResult, 0, sizeof(teamResult));
    for (int i = 0; i < T; i++) {
      teamResult[i].teamNo = i;
      teamResult[i].incorrect = new int[P];
      for (int j = 0; j < P; j++) {
	teamResult[i].incorrect[j] = 0;
      }
    }
    
    for (int i = 0; i < R; i++) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      if (p == 0) goto FINISH;

      t = t - 1;
      p = p - 1;
      if (j != 0) {
	teamResult[t].incorrect[p]++;
      } else {
	teamResult[t].totalTime += m + teamResult[t].incorrect[p] * PENALTY_TIME;
	teamResult[t].solved++;
      }
    }

    sort(teamResult, T);
    PrintResult(teamResult, T);

    for (int i = 0; i < T; i++) {
      delete [] teamResult[i].incorrect;
    }
  }
FINISH:
  return 0;
}

static void sort(TeamResult *teamResult, int numOfTeam)
{
  TeamResult tmp;

  for (int i = 0; i < numOfTeam; i++) {
    for (int j = i+1; j < numOfTeam; j++) {
      // 正当数で昇順にソート
      if (teamResult[i].solved > teamResult[j].solved) {
	tmp = teamResult[i];
	teamResult[i] = teamResult[j];
	teamResult[j] = tmp;
      } else if (teamResult[i].solved == teamResult[j].solved) {
	// 正当数が同じ場合、総所要時間で昇順にソート
	if (teamResult[i].totalTime < teamResult[j].totalTime) {
	  tmp = teamResult[i];
	  teamResult[i] = teamResult[j];
	  teamResult[j] = tmp;
	} else if (teamResult[i].totalTime == teamResult[j].totalTime) {
	  // 正当数および総所要時間がともに同じ場合、チーム番号で降順にソート
	  if (teamResult[i].teamNo > teamResult[j].teamNo) {
	    tmp = teamResult[i];
	    teamResult[i] = teamResult[j];
	    teamResult[j] = tmp;
	  }
	}
      }
    }
  }
}

static void PrintResult(TeamResult *teamResult, int numOfTeam)
{
  /*
  for (int i = 0; i < numOfTeam; i++) {
    cout << "Team:" << teamResult[i].teamNo + 1
	 << ", Solved:" << teamResult[i].solved
	 << ", Time:" << teamResult[i].totalTime << endl;
  }
  */
  for (int i = numOfTeam; i > 0; i--) {
    cout << teamResult[i - 1].teamNo + 1;
    if (i - 1 > 0 &&
	teamResult[i - 1].solved == teamResult[i - 2].solved &&
	teamResult[i - 1].totalTime == teamResult[i - 2].totalTime) {
      cout << "=";
    } else if (i - 1 > 0) {
      cout << ',';
    } else {
      cout << endl;
    }
  }
}

Measured memory_bytes: 1204
#include<iostream>
#include<vector>
#include<cstring>
#include<string>
#include<algorithm>
#include<list>

using namespace std;
typedef long long int lli;

int n,m,l,r;
list<int>dag[100000];
bool visited[100000];
int dp[100000];

void dfs(int i){
    if(visited[i]){
        return;
    }
    visited[i]=true;
    for(auto x:dag[i]){
        //cout<<x<<endl;
        dfs(x);
        dp[i]=max(dp[i],dp[x]+1);
    }
}

int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i+=1){
	    scanf("%d%d",&l,&r);
	    dag[l-1].push_back(r-1);
	}
	for(int i=0;i<n;i+=1){
	    dfs(i);
	    //cout<<dp[i]<<endl;
	}
	int maxx=0;
	for(int i=0;i<n;i+=1){
	    maxx=max(maxx,dp[i]);
	}
	printf("%d",maxx);
}


Measured memory_bytes: 7424
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
// value, number
typedef pair<ll,ll> P;
int main() {
		ll N,M,a,b;
		cin >> N >> M;
		vector<P> v(N);
		for (int i=0; i<N; i++) {
				cin >> a >> b;
				v.push_back(P(a,b));
		}
		sort(v.begin(), v.end());
		
		ll min=0;
		for (const P &p: v) {
				if (p.second < M) {
						M -= p.second;
						min += p.first * p.second;
				} else {
						min += p.first * M;
						break;
				}
		}
		cout << min << endl;
		return 0;
}


Measured memory_bytes: 4864
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int par[N];
ll ans;
multiset<ll>s[N];
set<pair<ll,int>>all;
set<pair<int,int>>sz;
int n , m ;

int get(int i){
if( par[i]==i )return par[i];
par[i]=get(par[i]);
return par[i];
}
bool same(int i,int j){ return get(i)==get(j); }
void join(int i,int j){
i=get(i);
j=get(j);
if( i == j )return;
if( s[i].size() < s[j].size() )swap(i,j);
    par[j]=par[i];
    for(auto x:s[j])s[i].insert(x);
    s[j].clear();
}

int main(){

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

for(int i=0;i<n;i++)par[i]=i;

for(int i=0;i<n;i++){
    ll x;
    scanf("%lld",&x);
    s[i].insert(x);
    all.insert( {x,i} );
}

while( m-- ){
    int u , v ;
    scanf("%d %d",&u,&v);

    u=get(u);
    all.erase( { *s[u].begin(),u } );

    v=get(v);
    all.erase( { *s[v].begin(),v } );

    join(u,v);

    u=get(u);
    all.insert({ *s[u].begin(),u } );
}

for(int i=0;i<n;i++)sz.insert( { s[get(i)].size(),get(i) } );

while( all.size()>1 ){

    int u = (--sz.end())->second;
            all.erase({*s[u].begin(),u});

    int v = all.begin()->second;
            all.erase(all.begin());
    v=get(v);

    ans+=*s[u].begin();
    sz.erase({s[u].size(),u});
    s[u].erase(s[u].begin());

    ans+=*s[v].begin();
    sz.erase({s[v].size(),v});
    s[v].erase(s[v].begin());

    join(u,v);
    u = get(u);

    if( s[u].size() )
    all.insert({*s[u].begin(),u}),sz.insert({s[u].size(),u});
}


for(int i=1;i<n;i++)
if( !same(0,i) ){
    printf("Impossible\n");
    return 0;
}

printf("%lld\n",ans);
return 0;
}


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

int n, m, q;
int ans;
vector<int> a, b, c, d;

void dfs(vector<int> A){
	if(A.size() == n+1){
    	int now = 0;
      	for(int i = 0; i < q; i++){
        	if(A.at(b.at(i)) - A.at(a.at(i)) == c.at(i)) now += d.at(i);
        }
      	ans = max(ans,now);
      	return;
    }
  	
  	A.push_back(A.back());
  	while(A.back() <= m){
    	dfs(A);
      	A.back()++;
    }
}

int main(){
	cin >> n >> m >> q;
  	a = b = c = d = vector<int>(q);
  	for(int i = 0; i < q; i++){
    	cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    }
  	
  	dfs(vector<int>(1,1));
  	
  	cout << ans << endl;
  	
} 

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define emp emplace
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN = 200100;
const ll INF = 1e9;
const ll MOD = 1e9+7;

ll N,Q,a,b,c,d,e,M;


int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>N>>M;
	if(N%2==1){
		for (int i=1;i<=M;++i){
			cout<<i<<' '<<N-i<<'\n';
		}
	}else{
		for(int i=1;i<=M;++i){
			if(i*4<=N)cout<<i<<' '<<N+1-i<<'\n';
			else cout<<i<<' '<<N-i<<'\n';
		}
	}
}

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

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

  unordered_map<string, int> mp;

  REP(i, n) {
    string s;
    cin >> s;

    sort(s.begin(), s.end());
    mp[s]++;
  }

  ll ans = 0;

  for(auto& p : mp) {
    int s = p.second;    
    ans += (ll)s*(s-1)/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10660
N, W = map(int, input().split())
weight = []
value = []
for _ in range(N):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)
value_sum = sum(value)
dp = []
for _ in range(N + 1):
    dp_val = [float('inf') for _ in range(value_sum + 1)]
    dp.append(dp_val)
dp[0][0] = 0

for idx in range(N):
    for v in range(value_sum + 1):
        if value[idx] <= v:
            dp[idx + 1][v] = min(dp[idx][v], dp[idx][v - value[idx]] + weight[idx])
        else:
            dp[idx + 1][v] = dp[idx][v]
ans = 0
# print(dp)
for i in range(value_sum + 1):
    if dp[-1][i] <= W:
        ans = i
print(ans)

Measured memory_bytes: 320624
OFFSETS = [(-1,-1), (-1,0), (-1,1),
           (0,-1), (0,1),
           (1,-1), (1,0), (1,1)]

H, W = map(int, input().split())

Ses = []
for _ in range(H):
    Ses.append(input())

replaced_Ses = []
for y in range(H):
    replaced_S = ""
    for x in range(W):
        if Ses[y][x] == "#":
            replaced_S += "#"
            continue

        count_bomb = 0
        for dx, dy in OFFSETS:
            now_x = x+dx
            now_y = y+dy
            if now_x < 0 or now_x >= W:
                continue
            if now_y < 0 or now_y >= H:
                continue
            if Ses[now_y][now_x] == "#":
                count_bomb += 1
        replaced_S += str(count_bomb)
    replaced_Ses.append(replaced_S)

for line in replaced_Ses:
    print(line)


Measured memory_bytes: 3064
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define v vector<ll>
#define mp make_pair
#define fir first
#define sec second
#define _fast_ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int main()
{
    _fast_
    ll t = 1;
  //  cin>>t;
    while(t--){
    ll n,x,y;
    cin>>n>>x>>y;
    ll arr[n];
    memset(arr,0,sizeof(arr));
    for(ll i = 1;i<=n;i++)
    {
        for(ll j = i+1;j<=n;j++)
        {
            ll dis1 = j-i;
            ll dis2 = INT_MAX;
            {
                dis2 = abs(j-y)+abs(x-i)+1;
            }
            arr[min(dis1,dis2)]++;
           
        }
    }
    rep(i,1,n)
    {
        cout<<arr[i]<<"\n";
    }
    }
    return 0;
}

Measured memory_bytes: 256