akhauriyash/Code-Regression huggingface dataset:
S = input()
Q = int(input())

from collections import deque
q = deque(S)
rev = False
for _ in range(Q):
    qr = input()
    if qr == '1':
        rev = not rev
        continue
    _,f,c = qr.split()
    if (f=='2') ^ rev:
        q.append(c)
    else:
        q.appendleft(c)

if rev:
    print(''.join(reversed(list(q))))
else:
    print(''.join(q))

Measured memory_bytes: 10100
///supercalifragilisticexpialidocious.
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(sum) sum.begin(),sum.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , string> pis;
const int MAXN = 2e5 + 10;
int n , q;
string s;
pair<char , char> c[MAXN];
int f(int i)
{
    int ptr = i;
    for(int j = 0 ; j < q ; j ++)
        if(c[j].f == s[ptr])
            if(c[j].s == 'L')
                ptr --;
            else
                ptr ++;
    if(ptr < 0)
        return 0;
    if(ptr >= n)
        return 1;
    return 2;
}
int32_t main()
{
    cin >> n >> q >> s;
    for(int i = 0 ; i < q ; i ++)
        cin >> c[i].f >> c[i].s;
    int l = -1 , r = n + 1;
    while(r - l > 1)
    {
        int mid = (l + r) / 2;
        if(f(mid) == 1)
            r = mid;
        else
            l = mid;
    }
    int right = l;
    l = -1 , r = n + 1;
    while(r - l > 1)
    {
        int mid = (l + r) / 2;
        if(!f(mid))
            l = mid;
        else
            r = mid;
    }
    return cout << n - (n - 1 - right + 1) - (l + 1) + 1 << endl , 0;
}


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

const int M = 1e9+7;
int N, A, B, C, D;
void madd(int& a, int b) {
    a += b;
    if (a >= M) a -= M;
}
int mult(int a, int b) {
    return (1LL*a*b) % M;
}
int modexp(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b&1) res = mult(res,a);
        a = mult(a,a);
        b >>= 1;
    }
    return res;
}

int dp[1005][1005];
int ch[1005][1005];
int part[1005][1005];
int inv[1005];

int main() {
    scanf("%d %d %d %d %d",&N,&A,&B,&C,&D);
    for (int i = 1; i <= N; i++) {
        inv[i] = modexp(i,M-2);
    }
    for (int i = 0; i <= N; i++) {
        ch[i][0] = 1;
        for (int j = 1; j <= i; j++) {
            madd(ch[i][j],ch[i-1][j]);
            madd(ch[i][j],ch[i-1][j-1]);
        }
    }
    for (int j = 1; j <= N; j++) part[0][j] = 1;
    for (int n = 1; n <= N; n++) {
        for (int j = 1; j <= n; j++) {
            if (n % j == 0) {
                part[n][j] = mult(ch[n][j],part[n-j][j]);
                part[n][j] = mult(part[n][j],inv[n/j]);
            }
        }
    }
    for (int i = 0; i <= N+1; i++) dp[0][i] = 1;
    for (int i = B; i >= A; i--) {
        for (int n = 1; n <= N; n++) {
            dp[n][i] = dp[n][i+1];
            for (int j = C*i; n-j >= 0 && j <= D*i; j += i) {
                int ways = mult(ch[n][j],part[j][i]);
                madd(dp[n][i],mult(ways,dp[n-j][i+1]));
            }
        }
    }
    printf("%d\n",dp[N][A]);
}



Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	// your code goes here
	string s;
	cin>>s;
	ll q;
	cin>>q;
	deque<char> pr;
	for(ll i=0;i<s.size();i++)
	{
		pr.push_back(s[i]);
	}
	ll r=0;
	while(q--)
	{
		ll x;
		cin>>x;
		if(x==1)
		{
			r++;
		}
		else
		{
			ll y;
			char c;
			cin>>y>>c;
			y+=r;
			if(y%2==0)
			{
				pr.push_back(c);
			}
			else
			{
				pr.push_front(c);
			}
		}
	}
	if(r%2==0)
	{
		while(pr.size())
		{
			cout<<pr.front();
			pr.pop_front();
		}
	}
	else
	{
		while(pr.size())
		{
			cout<<pr.back();
			pr.pop_back();
		}
	}
	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	odd := 0
	for i := 0; i<n; i++ {
		fmt.Scan(&a[i])
		if a[i]%2 > 0 {
			odd++
		}
	}
	if odd%2 > 0 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

const int M = 10100;

ll a[M], b[M];
ll sa = 0, sb = 0;
ll n;

int main() {
#ifdef LOCAL
  assert(freopen("b.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sa += a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    sb += b[i];
  }

  if (sa > sb) {
    cout << "No\n";
    return 0;
  }

  ll t = sb - sa;
  ll x = 0;
  for (int i = 0; i < n; ++i) {
    ll y = max(a[i], b[i]);
    if (y % 2 != a[i] % 2)
      ++y;
    x += y - b[i];
  }

  if (x <= t) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}



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

int main() {
	long long n,m,k,ans,cur,res,i,j;
	vector<long long> a(9);
	for(i=0; i<9; i++){
		cin >> a[i];
	}
	cin >> n;
	long long b;
	for(j=0; j<n; j++){
		cin >> b;
		for(i=0; i<9; i++){
			if(a[i]==b){
				a[i]=0;
			}
		}
	}
	if(a[0]==0 && a[1]==0 && a[2]==0){
		cout << "Yes" << endl;
	}else if(a[3]==0 && a[4]==0 && a[5]==0){
		cout << "Yes" << endl;
	}else if(a[6]==0 && a[7]==0 && a[8]==0){
		cout << "Yes" << endl;
	}else if(a[0]==0 && a[3]==0 && a[6]==0){
		cout << "Yes" << endl;
	}else if(a[1]==0 && a[4]==0 && a[7]==0){
		cout << "Yes" << endl;
	}else if(a[2]==0 && a[5]==0 && a[8]==0){
		cout << "Yes" << endl;
	}else if(a[0]==0 && a[4]==0 && a[8]==0){
		cout << "Yes" << endl;
	}else if(a[2]==0 && a[4]==0 && a[6]==0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int n;
 
  cin >> n >> a;
  
  int b;
  
  b = n % 500;
  
  if (b <= a){
      cout << "Yes" << endl;
  }
  else {
      cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <numeric>

using namespace std;

vector<int> line_to_array(istream& is, const int cnt, const char sep);
vector<string> split(const string &str, const char sep);
string trim(const string& str, const char* trimCharacterList  = " \t\v\r\n");
bool chk_rcsv(int j, int k, char** t, bool** chk_t, string str, int pos);

int main(){
    //ifstream cin("inputAB55_2.txt");
    
    int N;
    long P = 1;
    
    string str;
    vector<string> words;
    
    getline(cin, str);
    trim(str);
    N = atoi(str.c_str());
 
    for (int i=1; i<=N; i++) {
        P *= i;
        P %= 1000000007;
    }
    cout << P << endl;
    
    return 0;
}

vector<int> line_to_array(istream& is, const int cnt, const char sep){
    vector<int> v;
    string str;
    getline(is, str);
    vector<string> words = split(str, sep);
    for (int i=0; i < cnt; i++) {
        v.push_back( atoi(words[i].c_str()) );
    }
    return v;
}

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

string trim(const string& str, const char* trimCharacterList)
{
    string result;
    string::size_type left = str.find_first_not_of(trimCharacterList);
    
    if (left != string::npos)
    {
        string::size_type right = str.find_last_not_of(trimCharacterList);
        result = str.substr(left, right - left + 1);
    }
    return result;
}


Measured memory_bytes: 256
N=int(input())

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

flag = False
is_pos = True

for i in range(1,N):
    if H[i-1]-H[i]==1:
        if flag:
            is_pos=False
            break
        flag = True
    elif H[i-1]-H[i]<=-1:
        flag = False
    elif H[i-1]-H[i]>=2:
        is_pos = False
        break

if is_pos:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 63856
n,ma,mb = map(int,input().split())

INF = 10**4
dp = [[[INF] * (n*10+1) for _ in range(n*10+1)] for _ in range(n+1)]
dp[0][0][0] = 0

for i in range(n):
    a,b,c = map(int,input().split())
    for ai in range(i*10+11):
        for bi in range(i*10+11):
            if ai>=a and bi>=b:
                tmp = dp[i][ai-a][bi-b] + c
            else:
                tmp = INF
            dp[i+1][ai][bi] = min(dp[i][ai][bi], tmp)

ans = min(dp[n][ma*i][mb*i] for i in range(1,n*10//max(ma,mb)+1) )
if ans == INF: ans = -1
    
print(ans)

Measured memory_bytes: 59376
#include <iostream>
#include <string>
using namespace std;
int main(){
    long long i,j,n,ta = 0,tac = 0;
    cin >> n;
    long long a[n+1],b[n];
    for(i=0;i<=n;i++){
        cin >> a[i];
        ta = ta + a[i];
    }
    for(i=0;i<n;i++){
        cin >> b[i];
    }
    for(i=0;i<n;i++){
        if(b[i]>=a[i]){
            b[i] = b[i]-a[i];
            a[i] = 0;
            if(b[i]>=a[i+1]){
                a[i+1] = 0;
            }
            else{
                a[i+1] = a[i+1]-b[i];
            }
        }
        else{
            a [i] = a[i]-b[i];
        }
    }
    for(i=0;i<=n;i++){
        tac = tac+a[i];
    }
    cout <<ta-tac;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;


int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int a,b,c;
    cin >> a >> b >> c;
    cout << c<<" " << a << " "<< b << endl;
}



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

int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    int count=0;
    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]){
            count++;
            a[i+1]=10001;
        }
    }
    cout << count << endl;
}

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


int main(){
  double D,T,s;
  
  cin >> D >> T >>s;
  
  if(D/s<=T)
    cout << "Yes"<< endl;
  else
    cout << "No"<< endl;

}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(0, c - (a-b)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD (int)1e9 + 7
#define atoi(x) ((x)-'0')
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

int a, b;

int main() {
	cin >> a >> b;
	cout << a * b;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
#define papapa ans.push_back(P(nowx,nowy));
//template
//main
signed main(){
  int k,x,y;cin>>k>>x>>y;
  if(k%2==0&&((x+y)&1)){cout<<-1<<endl;return 0;}
  if(abs(x)+abs(y)==k){cout<<1<<endl<<x<<" "<<y<<endl;return 0;}
  int X=abs(x),Y=abs(y);
  typedef pair<int,int> P;
  std::vector<P> ans;int cou;
  for(int j=k*2;;j+=k){
    if(X+Y>j)continue;
    if((j-(X+Y))%2==0){
      cou=(j-(X+Y))/2;
      break;
    }
  }
  //cout<<cou<<endl;
  int nowx=0,nowy=0;
  if(cou){
    while(cou+nowx-k>=0){
      nowx-=k;
      cou-=k;
      papapa;
    }
    if(nowx==0){
      if(X>Y){
        nowy-=cou;
        nowx+=k-cou;
      }
      else {
        nowx-=cou;
        nowy+=k-cou;
      }
    }
    else{
      nowy-=cou;
      nowx+=(k-cou);
    }
    papapa
  }
  while(nowx+k<=X){
    nowx+=k;
    papapa
  }
  while(nowy+k<=Y){
    nowy+=k;
    papapa
  }
  if(nowx!=X||nowy!=Y)ans.push_back(P(X,Y));
  cout<<ans.size()<<endl;
  for(auto p:ans){
    if(x<0)cout<<p.first*(-1);
    else cout<<p.first;
    cout<<" ";
    if(y<0)cout<<p.second*(-1);
    else cout<<p.second;
    cout<<endl;
  }
}


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

int main()
{
  vector<int> vec(3);
  cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
  
  sort(vec.begin(), vec.end());
  cout << (vec.at(2) * 10) + vec.at(1) + vec.at(0) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC149A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            string ans = str[1] + str[0];
            Console.WriteLine(ans);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
package main

import (
	"fmt"
)

func main() {

	var N int
	fmt.Scanf("%d", &N)

	A := make([]int, N)
	B := make([]int, N)
	C := make([]int, N-1)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &A[i])
	}
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &B[i])
	}
	for i := 0; i < N-1; i++ {
		fmt.Scanf("%d", &C[i])
	}
	var result int
	for i := 0; i < N; i++ {
		result += B[A[i]-1]
		if i < N-1 && A[i]+1 == A[i+1] {
			result += C[A[i]-1]
		}
	}

	fmt.Println(result)
}


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

int main() {
  int H, W; cin >> H >> W;
  vector<vector<char>> table(H+2, vector<char>(W+2,'.')); 
  for (int i=1; i<H+1; i++){
    for (int j=1; j<W+1; j++){
      cin >> table.at(i).at(j);
    }
  }

  for (int i=1; i<H+1; i++){
    for (int j=1; j<W+1; j++){
      if(table.at(i).at(j)=='#'){
        int counter = 0;
        if (table.at(i-1).at(j)=='#') counter++;         
        if (table.at(i+1).at(j)=='#') counter++;         
        if (table.at(i).at(j-1)=='#') counter++;         
        if (table.at(i).at(j+1)=='#') counter++;         
          
//        cout << counter;
        if (counter == 0){
//          cout << i << " " << j << endl; 
          cout << "No" << endl;
          return 0;
        }
      }
    }
//    cout << endl;
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3612
import sys

sys.setrecursionlimit(10 ** 5 + 100)

# sys.stdin = open('d1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


adj = []
p = []
state = []


def dfs(root, parent):
    state[root] = 1
    p[root] = parent
    for i in adj[root]:
        if i != parent:
            dfs(i, root)
    state[root] = 2


def get_size(root):
    res = 1
    for i in adj[root]:
        if i != p[root]:
            res += get_size(i)
    return res


def solve():
    global adj
    global p
    global state
    n = read_int()
    pairs = [read_int_list() for i in range(n - 1)]
    adj = [[] for i in range(n)]
    for x, y in pairs:
        x -= 1
        y -= 1
        adj[x].append(y)
        adj[y].append(x)
    state = [0] * n
    p = [-1] * n
    dfs(0, -1)

    j = n - 1
    q = []
    while j != 0:
        q.append(j)
        j = p[j]
    q.append(0)

    lq = len(q)
    half = lq // 2

    s = get_size(q[half - 1])
    if n - s > s:
        return 'Fennec'
    return 'Snuke'


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  map<int, int> mp;
  mp[0] = 1;
  int res = 0, cur = 0, b = 1;
  reverse(S.begin(), S.end());
  for (char s : S) {
    cur += (s - '0') * b;
    cur %= 2019;
    b *= 10;
    b %= 2019;
    res += mp[cur]++;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 3752
#include <iostream>
#include <algorithm>

using namespace std;

const int INF = 100000000;

int main(){
	int size;
	while(cin >> size,size!=0){
		//sizeに標準入力して、その値が0でない間ループ
		//while(cin >> size,size)と書く人のほうが多い(意味は同じ)。ソースを読むときの参考に
		//scanfを使う場合はcin >> size の部分をscanfで入力するようにすればよい。
		int maxv = -INF;
		int minv = INF;
		int sum = 0;
		for(int i=0;i<size;i++){
			int num;
			cin >> num;
			sum+=num;
			maxv = max(maxv,num);
			minv = min(minv,num);
		}
		int result = (sum-minv-maxv)/(size-2);
		cout << result << endl;
	}
}

Measured memory_bytes: 1160
<?php
  function dis($x,$y){
    $len = count($x);
    $total = 0;
    for($i=0; $i<$len; $i++){
      $sa = abs($x[$i]-$y[$i]);
      $total += $sa*$sa;
    }
    $total = sqrt($total);
    $total_int = (int)($total);
    return ($total == $total_int);
  }
  
  fscanf(STDIN,"%d %d",$n,$d);
  while($line= trim(fgets(STDIN)) ){
   $x[] = explode(" ",$line);
  }
  $count = 0;
  for($i=0; $i<$n; $i++){
    for($j=$i+1; $j<$n; $j++){
      if( dis($x[$i],$x[$j]) ){
        $count++;
      }
    }
  }

  echo $count."\n";

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

int main(){
    int n;
    int d, x;
    cin >> n >> d >> x;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    int choco_count = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= d; j+=a[i]){
            //cout << j <<" ";
            choco_count++;
        }
    }

    cout << choco_count + x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ll                  long long int
#define ull                 unsigned long long int
#define ld                  long double
#define fi                  first
#define se                  second
#define pb                  push_back
#define pbb                 pop_back
#define mp                  make_pair
#define popcount            __builtin_popcountll
#define pii     	        pair<int,int>
#define all(x)              x.begin(), x.end()
#define uniq(x)             x.erase(unique(x.begin(),x.end()),x.end())
#define mem(array, value)   memset(array, value, sizeof(array))
#define lcm(a,b)            (abs(a)/gcd(a,b))*abs(b)
#define random(a, b)        ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
#define PI      	        2*acos(0.0)
#define EPS     	        1e-8
#define line                cout << "\n==========\n"
#define fastRead 	        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define trace(...)          __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " , ";
    __f(comma + 1, args...);
}
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

//int dx[] = {1, -1, 0, 0},                  dy[] = {0, 0, 1, -1};                  // 4 Direction
//int dx[] = {1, -1, 0, 0, 1, 1, -1, -1},    dy[] = {0, 0, 1, -1, 1, -1, 1, -1};    // 8 Direction
//int dx[] = {1, -1, 1, -1, 2, 2, -2, -2},   dy[] = {2, 2, -2, -2, 1, -1, 1, -1};   // Knight Direction

inline ll gcd(ll a, ll b){
    a = abs(a);
    b = abs(b);
    while (b){
        a = a % b;
        swap (a, b);
    }
    return a;
}
inline ll power(ll a, ll p){
    ll res = 1, x = a;
    while (p){
        if (p & 1){
            res = (res * x);
        }
        x = (x * x);
        p >>= 1;
    }
    return res;
}
inline ll mulmod(ll a, ll p, ll m){
    ll res = 0, x = a%m;
    while (p){
        if (p & 1){
            res = (res + x) % m;
        }
        x = (x << 1) % m;
        p >>= 1;
    }
    return res;
}
inline ll bigmod(ll a, ll p, ll m){
    ll res = 1 % m, x = a % m;
    while (p){
        if (p & 1){
            res = (res * x) % m;
        }
        x = (x * x) % m;
        p >>= 1;
    }
    return res;
}

const int INF = 1e9+9;

int main ()
{
    #ifdef Lollipop
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);
    #endif
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int& x: a){
        cin >> x;
    }
    vector<int> dp(k+1);
    for (int stone = 0; stone <= k; stone++){
        for (int x: a){
            if (stone >= x && !dp[stone-x]){
                dp[stone] = true;
            }
        }
    }
    cout << (dp[k] ? "First\n" : "Second\n");
    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define		CH		ch=(getchar())

inline		int		IN(){
	int x=0,f=1;char ch;
	for (CH;ch>'9'||ch<'0';CH) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';CH) (x*=10)+=ch-'0';
	return x*f;
}

int i,j,k,l,n,m,t;
long long ans,P;
char s1[105],s2[105];

int main(){
	scanf("%d",&n);
	scanf("%s",&s1);
	scanf("%s",&s2);
	ans=3;
	P=(long long) 1000000007;
	if (s1[0]==s2[0]) t=1;
		else t=2;
	if (t==2) ans*=2;
	for (;t<n;){
		if (s1[t]==s1[t+1]){
			if (s1[t-1]==s2[t-1]){
				ans=(ans*2)%P;
				t+=2;
			}
			else{
				ans=(ans*3)%P;
				t+=2;
			}
		}
		else{
			if (s1[t-1]==s2[t-1]){
				t++;
				ans=(ans*2)%P;
			}
			else t++;
		}
	}
	printf("%lld",ans);
}


Measured memory_bytes: 128
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cctype>
#include <queue>
using namespace std;
int a[1001];
int main()
{
	int n, k, num = 0;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= k; i++)
	{
		num += a[i];
	}
	cout << num << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

using namespace std;

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

    string S;
    cin >> S;

    map<char, int> cnt; 
    const int mod = 1e9 + 7;

    for (char c : S) cnt[c] += 1; 

    long long ans = 1;

    for (auto p : cnt) {
        ans = ans * (p.second + 1) % mod;
    }
    
    cout << (ans + mod - 1) % mod << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int r, d, x;

    cin >> r >> d >> x;

    for (int i = 0; i < 10; i++)
    {
        cout << r * x - d << endl;
        x = r * x - d;
    }

    return 0;
}


Measured memory_bytes: 256
var s:String;i:Longint;a:array[97..122]of boolean;
begin
	readln(s);
	for i:=1 to length(s) do begin
		inc(a[ord(s[i])]);
	end;
	for i:=97 to 122 do begin
		if not a[i] then begin
			writeln(chr(i));
			exit;
		end;
	end;
	writeln('None');
end.


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int A,B,C,D;
	scanf("%d %d %d %d",&A,&B,&C,&D);

	while(true){

		C -= B;
		if(C <= 0){

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

		A -= D;
		if(A <= 0){

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

	return 0;
}


Measured memory_bytes: 3668
#include <stdio.h>

typedef struct {
    int ue, shita , migi, hidari, oku, temae;
    int men[7];
}Dice;

Dice initialization(Dice);
Dice North(Dice);
Dice East(Dice);
Dice South(Dice);
Dice West(Dice);
Dice TurnDice(Dice);
int CheckDice(Dice, Dice);

int flag = 0;

int main() {
    int i, check = 0;
    Dice d1, d2;

    for (i = 1; i <= 6; i++) {
        scanf("%d", &d1.men[i]);
    }
    for (i = 1; i <= 6; i++) {
        scanf("%d", &d2.men[i]);
    }

    d1 = initialization(d1);
    d2 = initialization(d2);

    flag = CheckDice(d1, d2);

    if (flag == 0) {
        d1 = North(d1);
        flag = CheckDice(d1, d2);
    }

    if (flag == 0) {
        d1 = initialization(d1);
        d1 = East(d1);
        flag = CheckDice(d1, d2);
    }

    if (flag == 0) {
        d1 = initialization(d1);
        d1 = South(d1);
        flag = CheckDice(d1, d2);
    }

    if (flag == 0) {
        d1 = initialization(d1);
        d1 = West(d1);
        flag = CheckDice(d1, d2);
    }

    if (flag == 0) {
        d1 = initialization(d1);
        d1 = North(d1);
        d1 = North(d1);
        flag = CheckDice(d1, d2);
    }

    if (flag == 1) {
        printf("Yes\n");
    }
    else printf("No\n");

    

    return 0;
}


Dice initialization(Dice d) {
    d.ue = 1;
    d.temae = 2;
    d.migi = 3;
    d.hidari = 4;
    d.oku = 5;
    d.shita = 6;

    return d;
}

Dice North(Dice d) {
    int temp;

    temp = d.ue;
    d.ue = d.temae;
    d.temae = d.shita;
    d.shita = d.oku;
    d.oku = temp;

    return d;
}

Dice East(Dice d) {
    int temp;

    temp = d.ue;
    d.ue = d.hidari;
    d.hidari = d.shita;
    d.shita = d.migi;
    d.migi = temp;

    return d;
}

Dice South(Dice d) {
    int temp;

    temp = d.ue;
    d.ue = d.oku;
    d.oku = d.shita;
    d.shita = d.temae;
    d.temae = temp;

    return d;
}

Dice West(Dice d) {
    int temp;

    temp = d.ue;
    d.ue = d.migi;
    d.migi = d.shita;
    d.shita = d.hidari;
    d.hidari = temp;

    return d;
}

Dice TurnDice(Dice d) {
    int temp;

    temp = d.temae;
    d.temae = d.migi;
    d.migi = d.oku;
    d.oku = d.hidari;
    d.hidari = temp;
    
    return d;
}

int CheckDice(Dice d1, Dice d2) {
    int i, count = 0;

    if (d1.men[d1.ue] != d2.men[d2.ue]\
     || d1.men[d1.shita] != d2.men[d2.shita]) return 0;

    while(1) {
        if (count == 4) {
            return 0;
        }

        if (d1.men[d1.temae] == d2.men[d2.temae]\
        && d1.men[d1.migi] == d2.men[d2.migi]\
        && d1.men[d1.oku] == d2.men[d2.oku]\
        && d1.men[d1.hidari] == d2.men[d2.hidari]) {
            return 1;
        }

        d1 = TurnDice(d1);

        count++;
    }
}



Measured memory_bytes: 2120
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll x = 0;
    ll ans = 0;
    REP(i,n){
        if(s[i]=='I'){
            x++;
        }else{
            x--;
        }
        ans = max(ans,x);
    }
    cout << ans << endl;

    return 0;
}

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

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

    int a[n], b[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }

    sort(a, a+n);

    for (int i = 0; i < n; i++) {
        if (b[i] != a[n-1]) {
            cout << a[n-1] << endl;
        } else {
            cout << a[n-2] << endl;
        }
    }
    
    return 0;
}

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

int main() {
  int a[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }
  int n;
  cin >> n;
  bool x[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      x[i][j] = false;
    }
  }
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (b == a[j][k]) x[j][k] = true;
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    if ((x[i][0] && x[i][1] && x[i][2])
        || (x[0][i] && x[1][i] && x[2][i])) {
      puts("Yes");
      return 0;
    }
  }
  if (x[0][0] && x[1][1] && x[2][2]) {
    puts("Yes");
    return 0;
  }
  if (x[0][2] && x[1][1] && x[2][0]) {
    puts("Yes");
    return 0;
  }
  puts("No");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <deque>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
    int n;
    deque<int> d;
    cin >> n;
    bool f= true;
    rep(i,n){
        int tmp;
        cin >> tmp;
        if (f) d.push_back(tmp);
        else d.push_front(tmp);
        f = !f;
    }
    if (f){
        for(auto w : d){
            cout << w << " ";
        }
    }
    else{
        vector<int> v(n);
        int id = 0;
        for (auto w :d){
            v[id] = w;
            id++;
        }
        reverse(v.begin(),v.end());
        rep(i,n){
            cout << v[i] << " ";
        }
        cout << endl;   
    }
    
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using  namespace std;
int main(){
	int i;
	string a="",b="";
	cin>>a;
	for(i=0;i<a.size();i++){
		if(a[i]=='1'){
			b+="9";
		}
		if(a[i]=='9'){
			b+="1";
		}
	}
	cout<<b;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int solve(int n){
    int M = 26;
    vector<int> deg(M);
    vector<set<int>> G(M);
    vector<string> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    for (int i = 0; i < n-1; ++i) {
        int cur = 0;
        while(s[i][cur] == s[i+1][cur] &&
              cur < min(s[i].size(), s[i+1].size())) cur++;
        if(cur == min(s[i].size(), s[i+1].size())){
            if(s[i].size() <= s[i+1].size()) continue;
            else return 0;
        }
        G[s[i][cur]-'a'].emplace(s[i+1][cur]-'a');
        if(G[s[i+1][cur]-'a'].count(s[i][cur]-'a')) return 0;
    }
    for (int i = 0; i < M; ++i) {
        for (auto &&j : G[i]) {
            deg[j]++;
        }
    }
    vector<int> visited(M);
    stack<int> Q;
    for (int i = 0; i < M; ++i) {
        if(!deg[i]) Q.emplace(i);
    }
    while(!Q.empty()){
        int i = Q.top(); Q.pop();
        visited[i] = 1;
        for (auto &&j : G[i]) {
            deg[j]--;
            if(!deg[j]){
                Q.emplace(j);
            }
        }
        G[i].clear();
    }
    for (int i = 0; i < M; ++i) {
        if(!visited[i]) return 0;
    }
    return 1;
}

int main() {
    int n;
    while(cin >> n, n){
        puts(solve(n) ? "yes" : "no");
    }

    return 0;
}


Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int N;
    cin >> N;
    vector<int> L(2 * N);
    for(int &l : L) cin >> l;
    sort(L.begin(), L.end());
    int ans = 0;
    for(int i = 0; i < N; i += 1) ans += L[2 * i];
    cout << ans;
    return 0; 
}

Measured memory_bytes: 256
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a,b = [0],[0]
for i in range(n):
  a.append(a[i]+A[i])
for i in range(m):
  b.append(b[i]+B[i])

ans,j = 0,m
for i in range(n+1):
  if a[i]>k:
    break
  while b[j]+a[i]>k:
    j -= 1
  ans = max(ans,i+j)

print(ans)

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



long long mod = 1000000007;

vector<int> adj[100005];
typedef pair<int,int> ii;
map<ii, int> edges;
int colour[100005];
bool vis[100005];
int maxCol = 0;
void dfs(int u, int pc){
	vis[u] = true;
	int col = 1;
	for(int v : adj[u]){
		if(vis[v]) continue;
		if(col == pc) col++;
		colour[edges[ii(u,v)]] = col;
		maxCol = max(maxCol, col);
		dfs(v,col);
		col++;
		
	}
}

int main(){
	//freopen("i.txt","r",stdin);
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	for(int i = 0;i < n-1;i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		edges[ii(a,b)] = i;
		edges[ii(b,a)] = i;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	dfs(0,-1);
	cout << maxCol << "\n";
	for(int i = 0;i < n-1;i++){
		cout << colour[i] << "\n";
	}
	
	
}


Measured memory_bytes: 19456
n, m = map(int, input().split())
graph = [[] for _ in range(n+1)]
indeg = [0] * (n+1)
outdeg = [0] * (n+1)
for _ in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    indeg[b] += 1
    outdeg[a] += 1

is_valid = [indeg[i] * outdeg[i] for i in range(n+1)]
u = n+10
ans = []
from collections import deque
for start in range(1, n+1):
    if not is_valid[start]:
        continue

    # print("start: ", start, "---------")
    q = deque([start])
    visited = [False] * (n+1)
    prev = [-1] * (n+1)
    visited[start] = True

    has_ans = False
    while q:
        now = q.popleft()
        # print("now", now)
        for node in graph[now]:
            if node == start:
                # print("roop")
                prev[node] = now
                has_ans = True
                break
            if visited[node] or not is_valid[node]:
                continue
            # print("  to: ", node)
            prev[node] = now
            visited[node] = True
            q.append(node)
        if has_ans:
            break

    if not has_ans:
        continue
    cnt = 0
    tmp = []
    now = start
    for _ in range(n):
        tmp.append(now)
        cnt += 1
        now = prev[now]
        if now == start or now == -1:
            break
    if cnt < u:
        u = cnt
        ans = tmp

if ans:
    print(u)
    for t in ans:
        print(t)
else:
    print(-1)

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

int main()
{
  int n,m;
  scanf("%d%d",&n,&m);
  static vector<int> e[100000];
  for(int i=0;i<m;i++){
    int a,b;
    scanf("%d%d",&a,&b);
    a--,b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  long long ans=0;
  static int B[100000]={0};
  long long X=0ll,Y=0ll,Z=0ll;
  for(int i=0;i<n;i++){
    if(B[i]!=0){
      continue;
    }
    if(e[i].size()==0){
      Z++;
      continue;
    }
    queue<int> Q;
    Q.push(i);
    B[i]=1;
    bool F=0;
    while(!Q.empty()){
      int j=Q.front();
      Q.pop();
      for(int x=0;x<e[j].size();x++){
	int k=e[j][x];
	if(B[k]==0){
	  B[k]=3-B[j];
	  Q.push(k);
	}
	else if(B[k]!=3-B[j]){
	  F=1;
	}
      }
    }
    if(F){
      X++;
    }
    else{
      Y++;
    }
  }
  //printf("%lld %lld %lld\n",X,Y,Z);
  printf("%lld\n",X*X+2ll*X*Y+2ll*Y*Y+Z*n+(n-Z)*Z);
  return 0;
}



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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll h,n,sum=0,a;
	cin>>h>>n;
	forn(i,n){
		cin>>a;
		sum+=a;
	}
	(h>sum)?cout<<"No\n":cout<<"Yes\n";
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""
 


Measured memory_bytes: 3580
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  int M;
  cin >> N >> M;
  vector<long long> A(M);
  long long sum = 0;
  for (int i = 0;i < M;++i){
    cin >> A[i];
    sum += A[i];
  }
  if(N - sum >= 0){
    cout << N - sum;
  }else{ 
    cout << "-1";
   }
}

Measured memory_bytes: 3700
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderPractice
{
    class Alphabet
    {
        static void Main(string[] args)
        {
            char a = char.Parse(Console.ReadLine());
            if (Char.IsUpper(a))
            {
                Console.WriteLine("A");
            }
            else
            {
                Console.WriteLine("a");
            }
        }
    }
}


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

int main(){
  int n;
  cin>>n;
  cout<<n*(n+1)/2<<endl;
}


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

int main() {
    long long N; cin >> N;
    long long K = 1;
    bool exist = false;
    for (K = 1; K <= N; ++K) {
        if (K * (K+1) / 2 == N) {
            exist = true;
            break;
        }
    }
        
    if (!exist) puts("No");
    else {
        puts("Yes");
        cout << K+1 << endl;
        vector<vector<long long> > res(K+1, vector<long long>());
        long long sum = 1;
        for (int k = K; k >= 1; --k) {
            for (int i = 0; i < k; ++i) {
                res[K-k].push_back(sum + i);
                res[K-k + i + 1].push_back(sum + i);
            }
            sum += k;
        }
            
        for (int i = 0; i < K+1; ++i) {
            cout << res[i].size();
            for (int j = 0; j < res[i].size(); ++j) cout << " " << res[i][j];
            cout << endl;
        }
    }
}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int r = 0;
int gcd(int a,int b) {
	if (b == 0)return a;
	else r++;
	return (gcd(b, a%b));
}
int main()
{
	string s,t,u;
	int a,b;
	cin>>s>>t>>a>>b>>u;
	s==u?a--:b--;
	cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int a, p;
    cin >> a >> p;
    int x = a*3;
    x += p;
    cout << x/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* liblary */

/* main */

signed main() {
    int X, A;
    cin >> X >> A;
    if (X < A)
        cout << 0 << endl;
    else
        cout << 10 << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	vector<int> A, B;
	map<int,int> mp;
	vector<pair<int,int>> con;
	cin>>N;
	
	A.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		mp[A[i]]++;
		if(mp[A[i]] == 2){
			mp[A[i]] = 0;
			B.push_back(A[i]);
		}
	}
	
	for(pair<int,int> p : mp){
		con.push_back(p);
	}
	sort(B.begin(), B.end(), greater<int>());
	
	if(B.size() <= 1)cout<<0<<endl;
	else cout<<B[0]*B[1]<<endl;
	
	return 0;
}

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


using namespace std;

int main (void)
{

  int N;
  cin >> N;

  int i, j;
  vector<int> light(N);
  int two_cnt;

  two_cnt = 0;
  for(i=0; i<N; i++)
  {
    cin >> light.at(i);
    if(light.at(i) == 2)
    {
      two_cnt++;
    }
  }
  if(two_cnt == 0)
  {
    cout << -1 << endl;
    return 0;
  }

  // int  count;
  int  next;
  int  tmp;
  // vector<int> trans(N);
  // bool dup;

  // count = 0;
  tmp = 1;
  for(i=1; i<N; i++)
  {

    // if(i == 0)
    // {
    //   next = light.at(0);
    // }
    // else
    // {
      next = light.at(tmp -1);
    // }
    //count += 1;

    if(next == 2)
    {
      cout << i << endl;
      break;
    }

    // 同じ要素の探索
    // ここ時間かかりすぎ？

    // for(j=0; j<count; j++)
    // {

    //   if(next == trans.at(j))
    //   {
    //     cout << -1 << endl;
    //     return 0;
    //   }

    // }
    // trans.at(i) = next;

    // dup = binary_search(trans.begin(), trans.end(), next);
    // if(dup == true)
    // {
    //   cout << -1 << endl;
    //   break;
    // }

    // trans.at(i) = next;
    // tmp         = trans.at(i);
    tmp = next;

    // sort(trans.begin(), trans.end());
    
  }

  if(i == N)
  {
    cout << -1 << endl;
  }

  return 0;

}



Measured memory_bytes: 640
#提出 #6036238 参考
def main():
    A, B, C, D, E, F = (int(i) for i in input().split())

    WF = F//100
    water = [False] * (WF + 1)
    water[0] = True
    #30
    for n in range(WF + 1):
        if water[n]:
            if n+A <= WF: water[n+A] = True
            if n+B <= WF: water[n+B] = True

    sugar = [False] * (F + 1)
    sugar[0] = True
    #3000
    for n in range(F + 1):
        if sugar[n]:
            if n+C <= F: sugar[n+C] = True
            if n+D <= F: sugar[n+D] = True

    water = set(100*x for x in range(1,1+WF) if water[x]) #0除算を避け、かつ水の量0はありえないのでrange(1,1+WF)
    sugar = set(x for x in range(1+F) if sugar[x]) #砂糖0gでも、濃度0%の砂糖水

    max_consist = -1
    ans = (0,0)
    #at most 30*3000 
    for w in water:
        for s in sugar:
            if s <= w//100 * E and w + s <= F: #sがwに溶け残らない、かつwとsがビーカーに入り切る
                cur_consist = (100*s)/(w+s)
                if max_consist < cur_consist:
                    max_consist = cur_consist
                    ans = (w + s,s)

    print(*ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<string>
#include<limits.h>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<set>
#include<vector>
#include<queue>
#include<set>
#include<stdlib.h>
#include<time.h>
using namespace std;
typedef long long ll;
#define inf	0x3f3f3f3f
typedef pair<int,int>	P;
struct City{
	int to;
	int len;
	int cost;
	City();
	City(int a,int b,int c):to(a),len(b),cost(c){}
};
vector<City> city[10010];
int cost[10010];
int dis[10010];
int n,m;
void init(){
	for(int i=1;i<=n;i++){
		city[i].clear();
	}
	memset(cost,inf,sizeof(cost));
	memset(dis,inf,sizeof(dis));
	dis[1]=0;
	cost[1]=0;
}
void dijkstra(){
	priority_queue<P,vector<P>,greater<P> > myQ;
	myQ.push(P(0,1));
	while(!myQ.empty()){
		P p=myQ.top();
		myQ.pop();
		if(p.first>dis[p.second]){
			continue;
		}
		for(int i=0;i<city[p.second].size();i++){
			City x=city[p.second][i];
			if(dis[x.to]>dis[p.second]+x.len){
				dis[x.to]=dis[p.second]+x.len;
				cost[x.to]=x.cost;
				myQ.push(P(dis[x.to],x.to));
			}else if(dis[x.to]==dis[p.second]+x.len){
				cost[x.to]=min(cost[x.to],x.cost);
			}
		}
	}
}
int solve(){
	dijkstra();
	int sum=0;
	for(int i=1;i<=n;i++){
		sum+=cost[i]; 
	}
	return sum;
}
int main() {
	while(scanf("%d%d",&n,&m)!=EOF){
		if(n==0&&m==0){
			break;
		}
		init();
		int u,v,d,c;
		while(m--){
			scanf("%d%d%d%d",&u,&v,&d,&c);
			city[u].push_back(City(v,d,c));
			city[v].push_back(City(u,d,c));
		}
		printf("%d\n",solve());
	}
	return 0;
}


Measured memory_bytes: 5176