akhauriyash/Code-Regression huggingface dataset:
import scala.io.StdIn.{readInt, readLine}
case class Node[T](data: Option[T], var prev: Node[T], var next: Node[T])
case class DoublyLinkedList[T]() {
    val n = new Node[T](None, null, null)
    def isEmpty(): Boolean = if (n.prev == null && n.next == null) true else false
    def insert(e: T): Unit = {
        if (isEmpty) {
            val newNode = new Node(Option(e), n, n)
            n.next = newNode
            n.prev = newNode
        } else {
            val newNode = new Node(Option(e), n, n.next)
            n.next.prev = newNode
            n.next = newNode
        }
    }
    def find(e: T, node: Node[T]): Node[T] = node.next match {
        case a if a.data.isEmpty => null
        case a if a.data.get == e => a 
        case a => find(e, a)
    }
    def delete(e: T): Unit = {
        if (!isEmpty) {
            val target = find(e, n)
            if (target != null) {
                val targetNext = target.next
                val targetPrev = target.prev
                if (targetNext eq targetPrev) {
                    n.prev = null
                    n.next = null
                } else {
                    targetPrev.next = targetNext
                    targetNext.prev = targetPrev
                }
            }
        }
    }
    def deleteFirst(): Unit = {
        if (!isEmpty) {
            val targetNext = n.next.next
            if (n eq targetNext) {
                n.prev = null
                n.next = null
            } else {
                n.next = targetNext
                targetNext.prev = n
            }
        }
    }
    def deleteLast(): Unit = {
        if (!isEmpty) {
            val targetPrev = n.prev.prev
            if (n eq targetPrev) {
                n.prev = null
                n.next = null
            } else {
                n.prev = targetPrev
                targetPrev.next = n
            }
        }
    }
    def printList(): Unit = {
        if (isEmpty) {
            println()
        } else {
            def go(node: Node[T], list: List[T]): List[T] = node.prev match {
                case a if a.data.isEmpty => list
                case a => go(a, a.data.get :: list)
            }
            println(go(n, Nil).mkString(" "))
            
        }
    }
}
object Main {
    def main(args: Array[String]): Unit = {
        val list = DoublyLinkedList[String]()
        for (i <- (1 to readInt)) {
            val input = readLine.split(" ") 
            if (input(0) == "insert") list.insert(input(1))
            else if (input(0) == "delete") list.delete(input(1))
            else if (input(0) == "deleteFirst") list.deleteFirst()
            else if (input(0) == "deleteLast") list.deleteLast()
        }
        list.printList()
    }
}


Measured memory_bytes: 535860
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int checker(string s,int n)
{
    for (int i=1;i<n;++i)
    {
        if (s[i]!=s[0])
        {
            return 0;
        }
    }
    return 1;
}

ll curAns(string s,int n)
{
    ll ans=0;
    for (int i=0;i<n-1;++i)
    {
        if (s[i]==s[i+1])
        {
            s[i+1]='0';
            ++ans;
        }
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s,t;
    ll k,ans=0,n;
    cin>>s;
    cin>>k;
    n=s.size();
    if (n==1)
    {
        cout<<k/2;
        return 0;
    }
    if (n==2)
    {
        if (s[0]==s[1])
        {
            cout<<k;
        }
        else
        {
            cout<<0;
        }
        return 0;
    }
    if (checker(s,n))
    {
        cout<<(n*k)/2;
        return 0;
    }
    ll ans1,ans2,ans3;
    t=s;
    ans1=curAns(t,n);
    t+=s;
    ans2=curAns(t,2*n);
    t+=s;
    ans3=curAns(t,3*n);
    if (ans3-ans2==ans2-ans1)
    {
        cout<<ans1+((ans2-ans1)*(k-1));
        return 0;
    }
    //cout<<"not linear\n";
    for (int i=0;i<n-1;++i)
    {
        if (s[i]==s[i+1])
        {
            if (s[i]=='a'||s[(i+2)%n]=='a')
            {
                if (s[i]=='b'||s[(i+2)%n]=='b')
                {
                    s[i+1]='c';
                }
                else
                {
                    s[i+1]='b';
                }
            }
            else
            {
                s[i+1]='a';
            }
            ++ans;
        }
    }
    ans*=k;
    if (s[n-1]==s[0])
    {
        ans+=(k-1);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

double t[105][105];	// ツ行ツづ個値ツづ債前ツ嘉アツ与ツつヲツつスツ氾ャツ猟ソ,ツ療アツづ個値ツづ債債。ツ嘉アツ与ツつヲツつスツ氾ャツ猟ソ
double dp[105][105];

int main()
{
	int n, m;

	while (cin >> n >> m && n && m ){
		memset (t, 0.0, sizeof (t ) );
		memset (dp, 0.0, sizeof (dp ) );

		rep (i, n ){
			rep (j, n ){
				cin >> t[i][j];
			} // end rep
		} // end rep
		rep (j, n ){
			dp[1][j] = 1.0;
		} // end rep
		for (int i = 2; i <= m; i++ ){
			for (int j = 0; j < n; j++ ){
				for (int k = 0; k < n; k++ ){
					dp[i][j] = max (dp[i][j], dp[i-1][k]*t[k][j] );
				} // end for
			} // end for
		} // end for

		double res = 0.0;
		for (int i = 0; i < n; i++ ){
			res = max (res, dp[m][i] );
		} // end for

		printf ("%.02lf\n", res );
	} // end while

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, a,b; cin>>n>>a>>b;
	if(b-a>=n){cout<<"OK\n";}
	else{
		for(int i=a; i<=b; i++){
			if(i%n==0) {cout<<"OK\n"; return 0;}
		}
		cout<<"NG\n";
	}
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,x,y;
cin>>a>>b>>x>>y;
   
   while (a>=0 or x>=0){
        x-=b;
        if  (x<=0){
           cout << "Yes";
           break;
           }
        a-=y;
        if (a<=0){
            cout << "No";
            break;
        }
   }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    rep(1, i, 50001)
    {
        int n = i * 1.08;
        if (n == N)
        {
            cout << i << endl;
            break;
        }
        if (n > N)
        {
            cout << ":(" << endl;
            break;
        }
    }
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

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

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

int main() {

  string s;cin>>s;reverse(all(s));cout<<s<<'\n';

  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
double EPS=1e-10;
int INF=1e9;
int gcd(int a,int b){
      if(a<b)swap(a,b);
      if(b==0)return a;
      return gcd(b,a%b);
}
int main(){
      string s;
      while(cin>>s&&s!="#"){
            vector<int> dat;
            REP(i,s.size()){
                  if(s.substr(i,4)=="west"){
                        dat.PB(1);
                  }
                  if(s.substr(i,5)=="north"){
                        dat.PB(0);
                  }
            }
            reverse(ALL(dat));
            int a,b=1;
            if(dat[0])a=90;
            else a=0;
            for(int i=1;i<dat.size();i++){
                  a*=2;b*=2;
                  if(dat[i])a+=90;
                  else a-=90;
            }
            int c=gcd(a,b);
            b/=c;a/=c;
            if(b==1){
                  cout<<a<<endl;
            }else{
                  cout<<a<<'/'<<b<<endl;
            }
      }
}

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

int main()
{
	long long a, b, r, m;

	while (cin >> a >> b) {
		r = a % b;
		m = a * b;

		while (r > 0) {
			a = b;
			b = r;
			r = a % b;
		}

		cout << b << " " << m / b << endl;
	}

	return 0;
}


Measured memory_bytes: 3004
n, m = map(int, input().split())
L1 = [list(map(int, input().split())) for _ in range(n)]
L2 = [list(map(int, input().split())) for _ in range(m)]
for i in range(n):
    D = 10 ** 10
    ans = 0
    for j in range(m):
        d = abs(L1[i][0] - L2[j][0]) + abs(L1[i][1] - L2[j][1])
        if d < D:
            D = d
            ans = j + 1
    print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <set>
#include <string>
#include <sstream>
#include <vector>
using namespace std;

template<class T> inline string toString(T x) {
	ostringstream sout;
	sout << x;
	return sout.str();
}

vector<int> nums;
set<int> used;
set<string> results;

void permutations(const string& str, int k) {
	if (k == 0) {
		results.insert(str);
		return;
	}
	for (unsigned i = 0; i < nums.size(); i++) {
		if (used.find(i) != used.end()) continue;
		used.insert(i);
		permutations(str + toString(nums[i]), k - 1);
		used.erase(i);
	}
}

int main() {
	int n, k;
	while (cin >> n >> k, n || k) {
		nums.clear();
		used.clear();
		results.clear();
		for (int i = 0; i < n; i++) {
			int x;
			cin >> x;
			nums.push_back(x);
		}
		permutations("", k);
		cout << results.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1496
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
// scanf("%d %d %d %d",&w,&b,&d,&s); %lld
// printf("%d\n" ,points);
// const double PI=acos(-1);
int main(){
    int n,rta=0,aux;
    cin >> n;
    int L[n];
    for(int i=0;i<n;i++){
        cin >> L[i];
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                aux=max({L[i],L[j],L[k]});
                bool ok=L[i]!=L[j] && L[i]!=L[k] && L[j]!=L[k];
                if(ok && 1LL*L[i]+L[j]+L[k]-aux>aux) rta++;
            }
        }
    }
    cout << rta << endl;
    return 0;
}


Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#include <iostream>
#include <cmath>

#include <set>
#include <string>
#include <bits/stdc++.h>
#include <string>
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define MAX 100
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF INT_MAX
#define ll long long
#define vi vector<int>
#define all(a) a.begin(), a.end()
#define pb push_back
#define ull unsigned long long


using namespace  std;



const int N = 1e5 + 5;
void sol() {

    int n;
    cin >> n;
    string s;
    cin >> s;
    if(s.size() <=n) {
        cout << s;
    }
    else cout << s.substr(0,n) << "...";
}
int main() {
    fast;
    sol();




}




Measured memory_bytes: 3572
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
count=0
for i in range(N):
    A = list(map(int, input().split()))
    SUM=0
    for j in range(M):
        SUM += A[j]*B[j]
    if SUM+C > 0:count += 1
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<ll>>;
template<typename T=ll,typename U=ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;

ll misum =0;
ll func(ll i,const v<> &c){
    if(i>=c.size()||misum>=0)return 0;
    misum+=c[i];
    return func(i+1,c)+1;
}

int main(){
    
    ll n; cin  >>  n;
    auto a = v<>(n,0);
    auto b = v<>(n,0);
    auto c = v<>(n,0);
    
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) c[i] = a[i]-b[i];
    sort(c.begin(),c.end());
    
    ll ans =count_if(c.begin(),c.end(),[](ll i)mutable{
            if(i<0) {
                misum+=i;
                return true;
            }
            return false;
        });
    
    if(accumulate(c.begin(),c.end(),(ll)0)<0){
        cout << -1 << endl;
        return 0;
    }

    sort(c.begin(),c.end(),greater<ll>());
    cout << ans+func(0,c);
    
    return 0;
}

Measured memory_bytes: 2560
import sys
input=sys.stdin.readline
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
from math import gcd
n=N()
mod=10**9+7
az=0
bz=0
zz=0
l=LL(n)
ans=1
import collections
d=collections.defaultdict(int)
for a,b in l:
    if a==0 and b==0:
        zz+=1
    elif a==0:
        az+=1
    elif b==0:
        bz+=1
    elif a<0 and b<0:
        a=-a
        b=-b
        x=gcd(a,b)
        d[(a//x,b//x)]+=1
    elif a<0:
        a=-a
        x=gcd(a,b)
        d[(-a//x,b//x)]+=1
    elif b<0:
        b=-b
        x=gcd(a,b)
        d[(-a//x,b//x)]+=1
    else:
        x=gcd(a,b)
        d[(a//x,b//x)]+=1
pow2=[1]*(n+1)
t=1
for i in range(1,n+1):
    t*=2
    t%=mod
    pow2[i]=t
ans*=(1+(pow2[az]-1)+(pow2[bz]-1))
for a,b in list(d.keys()):
    if a>0 and b>0:
        x=d[(a,b)]
        y=d[(-b,a)]
        ans*=(1+(pow2[x]-1)+(pow2[y]-1))
        ans%=mod
    else:
        if not (b,-a) in d:
            ans*=pow2[d[(a,b)]]
            ans%=mod
print((ans+zz-1)%mod)

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

using namespace std;

int main(){
  int64_t n;
  cin >> n;
  int64_t div=1;
  int64_t ans=1;
  for(int64_t i=1;i<=1000000;i++){
    if(i*i<=n){
      ans=i;
    }
  }
  for(int64_t i=1;i<=ans;i++){
    if(n%i==0){
      div=i;
    }
  }
  cout << (int64_t)div+n/div-2 << endl;
}


Measured memory_bytes: 256
use std::collections::{HashMap, HashSet};
use std::error::Error;
use std::io;

pub fn main() {
    if let Err(_e) = run() {
        panic!("failed.");
    }
}

fn run() -> Result<(), Box<dyn Error>> {
    let mut input = String::new();
    io::stdin().read_line(&mut input)?;
    let first_line: Vec<i32> = input
        .trim()
        .split_whitespace()
        .map(|s| s.parse::<i32>().unwrap())
        .collect();
    let n = first_line[0];
    let m = first_line[1];
    input.clear();
    let mut all_edges = HashMap::new();
    for _ in 0..m {
        io::stdin().read_line(&mut input)?;
        let line: Vec<i32> = input
            .trim()
            .split_whitespace()
            .map(|s| s.parse::<i32>().unwrap())
            .collect();
        let from = line[0];
        let to = line[1];
        let edge_list = all_edges.entry(from).or_insert(vec![]);
        edge_list.push(to);
        // bi-directional
        let edge_list = all_edges.entry(to).or_insert(vec![]);
        edge_list.push(from);
        input.clear();
    }

    //BFS
    let mut visited = vec![-1; 1 + n as usize];
    visited[1] = 1;
    let mut queue = vec![];
    queue.push(1);

    while !queue.is_empty() {
        let current_node = queue.remove(0);
        let edges = all_edges.get(&current_node).unwrap();
        for &to in edges {
            if visited[to as usize] == -1 {
                queue.push(to);
                visited[to as usize] = current_node;
            }
        }
    }
    println!("Yes");
    for i in 2..=n as usize {
        println!("{}", visited[i]);
    }

    Ok(())
}


Measured memory_bytes: 10864
//include
//--------------------------------------------------
#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<ctime>

using namespace std;

//conversion
//--------------------------------------------------
inline int toInt(const string &s){
    int v;istringstream sin(s);sin>>v;
    return v;
}
template<class T> inline string toString(T x){
    ostringstream sout;sout<<x;
    return sout.str();
}

//math
//--------------------------------------------------
template<class T> inline T sqr(T x){return x*x;}

//typedef
//--------------------------------------------------
typedef vector<int>VI;
typedef vector<VI>VVI;
typedef vector<string>VS;
typedef pair<int,int>PII;
typedef long long LL;

//container util
//--------------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//--------------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

//constant
//--------------------------------------------------
const int INF=1e8;
const int dx[]={0,-1,0,1};
const int dy[]={-1,0,1,0};

//clear memory
#define CLR(a) memset((a),0,sizeof(a))

//debug
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<"(L"<<__LINE__<<")"<<endl

//---------------------------------------------------

int N,M,S,G1,G2;
int g[100][100];
int solve(){
    REP(k,N)REP(i,N)REP(j,N)
        g[i][j]=min(g[i][j],g[i][k]+g[k][j]);

    int mi=INF;
    REP(i,N)mi=min(mi,g[S][i]+g[i][G1]+g[i][G2]);

    return mi;

}


int main(){
    while(cin>>N>>M>>S>>G1>>G2,N||M||S||G1||G2){
        S--;G1--;G2--;
        fill_n(*g,10000,INF);
        REP(i,N)g[i][i]=0;
        REP(i,M){
            int a,b,c;
            cin>>a>>b>>c;
            g[--a][--b]=c;
        }
        cout<<solve()<<endl;
    }


    return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()0
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!
vector<int> primes;

void sieve(){
    primes.clear() ;   
}

bool isPrime(int n){
    if(n==2){return 1;}
    if(n%2==0){return 0;}
    if(n<2){return 0;}
    for(int i=3;i*i<=n;i+=2){
        if(n%i==0){
            return false;
        }
    }
    return 1;
}
void solve(){
    int n;
    cin>>n;
    while(1){
        if(isPrime(n)){
            cout<<n<<endl;
            return ;
        }
        n++;
    }
}

 
int main() {
    faster;
    int t=1;
    // cin>>t;
    
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
 
#define INF (1<<28)
#define DEKAI 1000000007
#define FDST int hogehoge;cin>>hogehoge;
 
 
int main(){
  string s;
  int p=0,ans=0;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='R') p++;
    if(s[i]=='L') p--;
    if(p==4){
      ans++;
      p=0;
    }
    if(p==-4) p=0;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3212
#include<stdio.h>

int main(void)

{

 int i,n;

 int number;

 long long int sum=0;

 int min=0;

 int max=0;

   scanf("%d",&n);

   for(i=0;i<n;i++)

 {

  scanf("%d",&number);

     if(i==0)

  {

   min = number;

   max = number;

  }   if(number<min)

min = number;

  if(number>max)

max = number;

     sum += number;

 }

   printf("%d %d %lld\n",min,max,sum);

   return 0;

  }

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

using namespace std;


int main() {
	string a, b,c;
	cin >> a >> b >> c;
	if (a.back() == b.front() && b.back() == c.front())
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	
}

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

using namespace std;

typedef long long int LL;
typedef int ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;

#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))

const ll M=2e5+5,LG=19,SM=2000+5,inf=1e9+1;
ll mod=1e9+7;

ll a[M];
ll n,l;
int main()
{
	ios::sync_with_stdio(0);
    cin >> n >> l;
    For(i,0,n) cin >> a[i];
    ll r=-1;
    For(i,1,n)
    {
        if (a[i]+a[i-1]>=l)
        {
            r=i;
            break;
        }
    }
    if (r==-1)
    {
        cout << "Impossible";
        return 0;
    }    
    cout << "Possible\n";
    For(i,1,r) cout << i << '\n';
    Ford(i,n-1,r) cout << i << '\n';
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
int t = 1;
int f(int x)
{
	for (int i = 1; i <= x; i++)
		t = t * 100;
	return t;
}
int main()
{
	int d, n;
	cin >> d >> n;
	if (n == 100)
	{
		if (d == 0)
		{
			cout << "101";
		}
		else
		{
			int temp = f(d);
			int ans = (n + 1)* temp;
			cout << ans;
		}
	}
	else
	{
		if (d == 0)
		{
			cout << n;
		}
		else
		{
			int temp = f(d);
			int ans = n * temp;
			cout << ans;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    vector<int> f(n), b(n);
    int left = -c - 1;
    int cnt = 0;
    rep(i, n)
    {
        if (s.at(i) == 'x')
        {
            // cs[i] = cnt;
            continue;
        }

        if (left + c < i)
        {
            cnt++;
            left = i;
            f[i] = cnt;
        }
    }
    reverse(s.begin(), s.end());
    int right = -c - 1;
    cnt = k + 1;
    rep(i, n)
    {
        if (s.at(i) == 'x')
        {
            // cs[i] = cnt;
            continue;
        }

        if (right + c < i)
        {
            cnt--;
            right = i;
            b[i] = cnt;
        }
    }
    reverse(b.begin(), b.end());

    rep(i, n)
    {
        if (f[i] == 0)
            continue;
        if (f[i] == b[i])
        {
            cout << i + 1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3332
numbers = {str(i) for i in range(10)}
N, K = map(int, input().split())
D = list(map(str, input().split()))
D = set(D)
available = numbers - D

for i in range(N, 100000):
  nums = set(str(i))
  if nums <= available:
    print(i)
    break

Measured memory_bytes: 3060
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

int st[30][100000];
ll dp[52][2510];
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int B[30];
int n;
int t[100010];
struct edge {
	int t;
	ll cost;
	edge(int _t,ll _cost) : t(_t)
							, cost(_cost){
	}
};
ll d[305];
int ct[505][505];
int p[22];
string ta[405];
bool table[405][405];
int tx[] = { 0,-1,0,1 };
int ty[] = { 1,0,-1,0 };
int h, w;
pair<ll,ll> rec(int x,int y) {

	pair<ll, ll> ret;
	if (ta[x][y] == '.') {
		ret.first++;
	}
	else ret.second++;
	for (size_t i = 0; i < 4; i++)
	{
		int nx = x + tx[i];
		int ny = y + ty[i];
		if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
		if (table[nx][ny]) continue;
		if (ta[x][y] == ta[nx][ny]) continue;
		table[nx][ny] = true;
		pair<ll, ll> p = rec(nx, ny);
		ret.first += p.first;
		ret.second += p.second;
	}
	return ret;
}
void Solve() {
	cin >> h >> w;
	for (size_t i = 0; i < h; i++)
	{
		cin >> ta[i];
	}

	ll res = 0;
	for (size_t i = 0; i < h; i++)
	{
		for (size_t j = 0; j < w; j++)
		{
			if (table[i][j])continue;
			if (ta[i][j] == '.')continue;
			table[i][j] = true;
			pair<ll, ll> p = rec(i, j);
			res += p.first * p.second;
		}
	}

	cout << res << endl;
}
int main() {
	Solve();
	return 0;
}



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

int main (){
	int N;cin >> N;
	vector<int> A(N);
	for(int i=0;i<N;++i){
		int a;
		cin >> a;
		A[i]=a;
	}
	sort(A.begin(),A.end());
	int count=0;
	int key;
	int ans=0;
	for(int i=0;i<N;++i){
		key=A[i];
		count++;
		i++;
		while(A[i]==key){
			count++;
			i++;
		}
		//cout <<key<<"の数は" <<count << endl;
	if(count!=key){
		if(key<count){
			ans+=count-key;
		}
		if(count<key){
			ans+=count;
		}
		
	}
	count=0;
	i--;
	}
	cout<<ans<<endl;
    return 0;
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 100010
#define inf 1e9

int main()
{

    ll n, k;
    cin >> n >> k;
    vector<ll > v;
    ll sum=0;
    for(ll i =0; i < n; i++)
    {

        ll x;
        cin >> x;
        v.pb(x);
    }
    if(k >= n)
    {

        cout << 0;
        return 0;
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for(ll i = k; i < v.size(); i++) sum+=v[i];
    cout << sum;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    string S; cin >> S;
    ll K; cin >> K;
    int ptr = 0;
    while(ptr < S.size() && S[ptr] == '1') ptr++;
    cout << (ptr < K ? S[ptr] : '1') << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def increment(i, j):
    if 0 <= i < h:
        if 0 <= j < w:
            c[i][j] += 1

h, w = [int(x) for x in input().split()]
c = [[0] * w for _ in range(h)]

for i in range(h):
    for j, m in enumerate(input()):
        if m == '#':
            for i2 in [i - 1, i, i + 1]:
                for j2 in [j - 1, j, j + 1]:
                    increment(i2, j2)
            c[i][j] = -100

for ci in c:
    for cj in ci:
        print('#' if cj < 0 else cj, end='')
    print()


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n;
    cin>>n;
    vector<string> s(n);
    rep(i,n) cin>>s[i];
    rep(i,n) sort(s[i].begin(),s[i].end());
    sort(s.begin(),s.end());
    ll ans=0,x=1;
    rep(i,n-1){
      if(s[i]==s[i+1]) x++;
      else ans+=x*(x-1)/2,x=1;
    }
    cout<<ans+x*(x-1)/2;
}

Measured memory_bytes: 7296
N, K=map(int, input().split())
sunuke=[list(map(str, input().split())) for _ in range(2*K)]
merge=[]
ans=0
for i in range(K):
  merge+=sunuke[2*i+1]
for j in range(1, N+1):
  if str(j) not in merge:
    ans+=1
print(ans)


Measured memory_bytes: 9356
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	String s;
	int[] dp;
	public boolean dfs(int n){

		if(n == s.length()){
			return true;
		}

		if(n > s.length()){
			return false;
		}

		if(dp[n] != -1){
			return dp[n] == 0 ? false : true;
		}

		boolean ret = false;

		if(n + 5 <= s.length()){
			String subStr = s.substring(n,n + 5);
			if(subStr.equals("dream") || subStr.equals("erase")){
				ret |= dfs(n + 5);
			}
		}

		if(n + 6 <= s.length()){
			String subStr = s.substring(n,n + 6);
			if(subStr.equals("eraser")){
				ret |= dfs(n + 6);
			}
		}

		if(n + 7 <= s.length()){
			String subStr = s.substring(n,n + 7);
			if(subStr.equals("dreamer")){
				ret |= dfs(n + 7);
			}
		}
		dp[n] = ret ? 1 : 0;
		return ret;
	}

	public void solve() {
		s = next();
		dp = new int[s.length() + 1];
		Arrays.fill(dp, -1);
		out.println(dfs(0) ? "YES" : "NO");

	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 18000
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int a[200000];
    int i,j,cnt[200000];
    cin>>n;
    if(n>=2&&n<=200000)
    {
        for(i=1;i<=n;i++)
            cnt[i]=0;
        for(i=2;i<=n;i++)
        {
            cin>>a[i];
            cnt[a[i]]++;
        }
        for(i=1;i<=n;i++)
            cout<<cnt[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 5200
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	LL X, K, D;
	cin >> X >> K >> D;
	X = abs(X);

	LL a = min(K - 1, X / D);
	X -= a * D;
	K -= a;

	LL ret = 1e18;
	if((K & 1) == 0) ret = abs(X);
	if(K & 1){
		ret = min(ret, abs(X - D));
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int main()
{
    lli n,k;
    cin>>n>>k;
    lli ani=0;
    for(lli i=0;i<n;i++){
    	lli x;
    	cin>>x;
    	if(x>=k)ani++;
    }
    cout<<ani;

 	return 0;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int N; cin >> N;
    int order[25], food[25], more[25];
    REP(i, N) cin >> order[i];
    REP(i, N) cin >> food[i];
    REP(i, N - 1) cin >> more[i];

    ll res = 0;
    REP(i, N){
        res += food[order[i] - 1];
        if(order[i] + 1 == order[i + 1]) res += more[order[i] - 1];
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    string s;cin>>s;
    ll n=SIZE(s)-2;
    while(n>=2){
        string l,r;
        REP(i,n/2){
            l+=s[i];
        }
        FOR(j, n/2, n){
            r+=s[j];
        }
        if(l==r){cout<<n<<endl;break;}
        n-=2;
    }
    return 0;
}


Measured memory_bytes: 3660
n,m = map(int, input().split())
stu = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(m)]

for x, y in stu:
    k = []
    for c, d in p:
        k.append(abs(x-c)+abs(y-d))
    print(k.index(min(k))+1)
        



Measured memory_bytes: 2940
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

all = []
for i,val in enumerate([p,q,r]):
    for j in val:
        all.append([j,i])

all.sort(reverse=True)

cnt = [0]*3
ans = 0
for tmp in all:
    i,j = tmp
    if(cnt[0]==x)&(j==0):
        continue
    if(cnt[1]==y)&(j==1):
        continue

    ans += i
    cnt[j] += 1

    if(sum(cnt) == x+y):
        break

print(ans)

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

int main(){
    string s;
    ll k;
    cin >> s >> k;
    if(s[0] == '1'&& k==1) cout << '1' << endl;
    else{
        bool ans=false;
        for(int i=0;i < k;i++){
            if(s[i]!= '1'){
                ans = true;
                cout << s[i] << endl;
                break;
            }
        }
        if(!ans) cout << '1' << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N;
  cin>>N;
  int ans=1;
  REP(i,1,N){
    ans*=i;
    ans%=MOD;
  }
  cout<<ans<<endl;
}


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

	#define E "\n"
	#define int long long 
	#define f(i,l,n) for(int i=l;i<n;i++)




	int solve()
	{
		int n,k;
		cin >> n >> k;

		vector<int> v(n+1);
		f(i,0,n)
		{
			int t;
			cin >> t;
			v[i+1]=t;
		}
		int loop;

		int visited[n+1]={0};
		int node=1,j=1,last=1;
		do{
			visited[node]=j++;
			last=node;
			node=v[node];
		}while(visited[node]==0);
		if(k<visited[node]-1)
		{
			f(i,1,n+1) if(visited[i]==k+1) return cout<<i,0;
		}
		k-=visited[node]-1;
		loop=visited[last]-visited[node]+1;
		k=k%loop;

		int cur=node;
		while(k)
		{
			node=v[node];
			k--;
		}
		cout<<node;


		return 0;
	}

		


		int32_t main()
		{
		 	int t=1;
		 	//cin >> t;
		 	while(t--)
		 	{
		 		solve();
		 		///cout<<(1<<1);
		 	}

		}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;


int main(){
    ll n;cin >>n;
    ll o;cin >>o;
    bool flg=true;
    if(o!=0){
        flg=false;
    }
    map<ll,ll>co;
    co[0]++;
    for (int i = 0; i < n - 1; ++i) {
        ll d;
        cin >> d;
        co[d]++;
    }
    ll ans=1;
    ll c=1;
    for(int i=1;;i++){
        if(co[i]==0)break;
        c+=co[i];
        for (int j = 0; j < co[i]; ++j) {
            ans*=co[i-1];
            ans%=998244353;
        }
       // cout <<ans <<endl;
    }
    if(c!=n)flg=false;
    if(co[0]>1)flg=false;
    if(flg){
        cout <<ans<<endl;
    }
    else {
        cout <<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 6528
#pypyは内包表記使わない, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    N = int(input())
    A = [0] + list(map(int, input().split())) + [0]
    diff = []
    for i in range(1, N+1):
        if A[i-1]<A[i] and A[i+1]<A[i]:
            diff.append((A[i]-max(A[i-1], A[i+1]))*2)
        elif A[i-1]>A[i] and A[i+1]>A[i]:
            diff.append((min(A[i-1], A[i+1])-A[i])*2)
        else:
            diff.append(0)
    res = 0
    for i in range(N+1):
        res += abs(A[i+1]-A[i])
    for i in diff:
        print(res-i)

if __name__ == '__main__':
    main()

Measured memory_bytes: 13788
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j), ED = (k); i <= ED; ++i)
#define Rep(i, j, k) for(R int i = (j), ED = (k); i >= ED; --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 300011;
const ll INF = 5e16;

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread (buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write (x); putchar (' '); }

	inline void wln ( ll x ) { write (x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn (x), wln (y); }

}

using IO::wln;
using IO::wlnn;
using IO::read;

namespace Cesare {
	
	ll n, m, cc = 0, Deg[N], W[N], V[N], fa[N];
	
	inline ll Find ( ll x ) {
		return x == fa[x]? x: fa[x] = Find(fa[x]); 
	}
	
	inline void Merge ( ll x, ll y ) {
		fa[Find(x)] = Find(y);
	}
	
	vector <ll> Ve[N], E[N];
	
	inline void Add ( ll u, ll v ) { Ve[u].push_back(v); }
	
	inline void dfs ( ll u, ll fa ) {
		For ( i, 1, Ve[u].size() ) if (Ve[u][i - 1] != fa) {
			ll v = Ve[u][i - 1]; dfs (v, u);
			if (Deg[v] & 1) E[v].push_back(u), ++Deg[v];
			else if (!(Deg[v] & 1)) E[u].push_back(v), ++Deg[u];
		}
	}
	
	int main() {
		n = read(), m = read();
		For ( i, 1, n ) fa[i] = i;
		if (m & 1) return puts ("-1"), 0;
		for (R int i = 1, u, v; i <= m; ++i) {
			u = read(), v = read();
			ll x = Find(u), y = Find(v);
			if (x == y) E[u].push_back(v), ++Deg[u];
			else Merge(u, v), Add(u, v), Add (v, u);
		}
		dfs (1, 0);
		For ( u, 1, n ) For ( i, 1, E[u].size() ) 
			wlnn (u, E[u][i - 1]);
		return 0;
	} 
}

int main()
{
	return Cesare::main();
}

/*

*/






Measured memory_bytes: 28288
// No sorceries shall prevail. //           
import java.util.*;
import java.io.*;
public class Main {
	
	static long gcd(long a, long b) { 
	      if (b == 0) 
	        return a; 
	      return gcd(b, a % b);  
	    }
	static int gcd(int a, int b) { 
	      if (b == 0) 
	        return a; 
	      return gcd(b, a % b);  
	    }
	
	static long mod = 1000000007;
	public static void main(String args[]) {
		Scanner inp=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		
		int x=inp.nextInt();
		int y=inp.nextInt();
		int a=inp.nextInt();
		int b=inp.nextInt();
		int c=inp.nextInt();
		long p[]=new long[a];
		long q[]=new long[b];
		long r[]=new long[c];
		long gg=0;
		for(int i=0;i<a;i++) {
			p[i]=inp.nextInt();
		}
		for(int i=0;i<b;i++) {
			q[i]=inp.nextInt();
		}
		for(int i=0;i<c;i++) {
			r[i]=inp.nextInt();
		}
		Arrays.sort(r);
		Arrays.sort(p);
		Arrays.sort(q);
		int mustEatX=Math.max(0, x-c);
		int mustEatY=Math.max(0, y-c);
		for(int i=0;i<mustEatX;i++) {
			gg+=p[a-1-i];
		}
		for(int i=0;i<mustEatY;i++) {
			gg+=q[b-1-i];
		}
		int xin=a-1-mustEatX;
		int yin=b-1-mustEatY;
		int cin=c-1;
		int aeaten=mustEatX,ceaten=0;
		int beaten=mustEatY;
		
		for(int i=mustEatX+mustEatY;i<x+y;i++) {
			if(aeaten<x && beaten<y && ceaten<c && p[a-1-aeaten]>=q[b-1-beaten] && p[a-1-aeaten]>=r[c-1-ceaten]) {
				gg+=p[a-1-aeaten];
				aeaten++;
			} 
			else if(aeaten<x && beaten<y && ceaten<c && p[a-1-aeaten]<=q[b-1-beaten] && q[b-1-beaten]>=r[c-1-ceaten]){
				gg+=q[b-1-beaten];
				beaten++;
			} 
			else if(aeaten<x && beaten<y && ceaten<c && p[a-1-aeaten]<=r[c-1-ceaten] && q[b-1-beaten]<=r[c-1-ceaten]){
				gg+=r[c-1-ceaten];
				ceaten++;
			}else if(aeaten<x && beaten<y && p[a-1-aeaten]>=q[b-1-beaten]) {
				gg+=p[a-1-aeaten];
				aeaten++;
			}else if(aeaten<x && beaten<y && p[a-1-aeaten]<=q[b-1-beaten]) {
				gg+=q[b-1-beaten];
				beaten++;
			}else if(aeaten<x && ceaten<c && p[a-1-aeaten]>=r[c-1-ceaten]) {
				gg+=p[a-1-aeaten];
				aeaten++;
			}else if(aeaten<x && ceaten<c && p[a-1-aeaten]<=r[c-1-ceaten]) {
				gg+=r[c-1-ceaten];
				ceaten++;
			}else if(ceaten<c && beaten<y && r[c-1-ceaten]>=q[b-1-beaten]) {
				gg+=r[c-1-ceaten];
				ceaten++;
			}else if(ceaten<c && beaten<y && r[c-1-ceaten]<=q[b-1-beaten]) {
				gg+=q[b-1-beaten];
				beaten++;
			}else if(aeaten<x) {
				gg+=p[a-1-aeaten];
				aeaten++;
			}else if(beaten<y) {
				gg+=q[b-1-beaten];
				beaten++;
			}else {
				gg+=r[c-1-ceaten];
				ceaten++;
			}
		}
		
		
		out.println(gg);
		out.close();
		inp.close();
	}
}

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

int main() {
  char b;
  cin >> b;
  if (b == 'A') b = 'T';
  else if (b == 'T') b = 'A';
  else if (b == 'C') b = 'G';
  else b = 'C';
  printf("%c\n", b);
};


Measured memory_bytes: 256