akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int inf=1000001000;
ll INF=1e18;
ll mod=1000000007;
ll MOD=1000000007;

void Add(int &a, int b) {
  a += b;
  while (a >= MOD) a -= MOD;
  while (a < 0) a += MOD;
}
 
void Mul(int &a, int b) {
  a = 1LL * a * b % MOD;
}
 
int Pow(int b, int e) {
  if (e < 0) e += MOD - 1;
  int ret = 1;
  while (e) {
    if (e & 1) ret = 1LL * ret * b % MOD;
    b = 1LL * b * b % MOD;
    e >>= 1;
  }
  return ret;
}
 
namespace Math {
  const int NMAX = (int)1e7;
  int pow2[1 + NMAX];
  int fact[1 + NMAX], tcaf[1 + NMAX];
  void Precalc() {
    fact[0] = pow2[0] = 1;
    for (int i = 1; i <= NMAX; ++i) {
      pow2[i] = pow2[i - 1];
      Add(pow2[i], pow2[i]);
 
      fact[i] = fact[i - 1];
      Mul(fact[i], i);
    }
    tcaf[NMAX] = Pow(fact[NMAX], -1);
    for (int i = NMAX - 1; i >= 0; --i) {
      tcaf[i] = tcaf[i + 1];
      Mul(tcaf[i], i + 1);
      assert(1LL * fact[i] * tcaf[i] % MOD == 1);
    }
  }
  int Choose(int n, int k) {
    if (k > n || n < 0) return 0;
    return 1LL * fact[n] * tcaf[n - k] % MOD * tcaf[k] % MOD;
  }
};

int main() {
    Math::Precalc();
    ll s;
    cin >> s;
    ll ans=0,c=0;
    while(true){
        s-=3;
        if (s<0) break;
        ans+=Math::Choose(s+c,c);
        ans%=MOD;
        c++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 120828
l = input()
length = len(l)

idx = 0
ones = 0

prime = 1000000007

pattern = pow(3, length, prime)

for s in l:
    idx += 1
    if s == "1":
        ones += 1
    else:
        pattern -= (pow(2, ones + 1, prime) * pow(3, length - idx, prime)) % prime

print(pattern % prime)

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

int main() {
    int n, allzero = 1;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] != 0)
        {
            allzero = 0;
        }
    }
    
    if (allzero)
    {
        cout << "Yes" << endl;
        return 0;
    }
    
    if (n % 3 == 1)
    {
        cout << "No" << endl;
        return 0;
    }
    
    sort(a.begin(), a.end());

    for (int i = 0; i < 3; i++)
    {
        if (a[n / 3 * i] != a[n / 3 * (i + 1) - 1])
        {
            cout << "No" << endl; 
            return 0;
        }
        
    }
    if ((a[0] ^ a[n/3]) == a[n / 3 * 2])
    {
        cout << "Yes" << endl;
        return 0;
    }
    
    cout << "No" << endl;
}

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

#define printl(s) cout << s << endl;
#define print(s) cout << s << endl; return 0;
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n)+1; ++i)
using ll = long long;

const ll modseed = pow(10,9) + 7;

template <typename T>
vector<T> getValues(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

ll calculateDivNums(ll tg){
	ll ans = 0;
	for(ll a=1;a*a<=tg;a++){
      if(tg%a!=0){
        continue;
      }
      ans++;
      if(tg!=a*a){
        ans++;
      }
    }
  return ans;
 }   

string S;
int A,B,C,K,N, cnt;

int main(){
  cin >> A >> B >> K;
  stack<int> s;
  rep2(i,min(A,B)){
    if(A%i==0 && B%i==0){
      s.push(i);
    }
  }
  rep(i,K-1){
    s.pop();
  }
  printl(s.top());
}


Measured memory_bytes: 3600
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;


vector<pair<char, char>> bubbleSort(vector<pair<char, char>> data, int N){
    int count = 0;
    for(int j = 0; j < N - 1; j++){
        for(int i = N - 1; i > j; i--){
            if(data.at(i).second < data.at(i - 1).second){
                swap(data.at(i), data.at(i - 1));
                count++;
            }
        }
    }

    rep(i, N){
        cout << data.at(i).first << data.at(i).second;
        if(i < N - 1) cout << ' ';
    }

    cout << endl;
    cout << "Stable" << endl;
    return data;
}

vector<pair<char, char>> selectionSort(vector<pair<char, char>> data, int N){
    int count = 0;
    int min_i;

    for (int i = 0; i < N; i++)
    {
        int min = 101;
        for(int j = i; j < N; j++){
            if(data.at(j).second < min){
                min_i = j;
                min = data.at(j).second;
            }
        }
        if(i != min_i){
            swap(data.at(i), data.at(min_i));
            count++;
        }
    }

    rep(i, N){
        cout << data.at(i).first << data.at(i).second;
        if(i < N - 1) cout << ' ';
    }
    cout << endl;
    return data;
}

int main(){
    int N;
    cin >> N;
    
    string s;
    bool flag = true;
    vector<pair<char, char>> data(N);
    vector<pair<char, char>> b_data(N);
    vector<pair<char, char>> s_data(N);

    rep(i, N)
    {
        cin >> s;
        data.at(i).first = s[0];
        data.at(i).second = s[1];
    }

    b_data = bubbleSort(data, N);
    s_data = selectionSort(data, N);

    rep(i, N){
        if(b_data.at(i) != s_data.at(i)) flag = false;
    }
    if(flag) cout << "Stable" << endl;
    else cout << "Not stable" << endl;

    return 0;
}


Measured memory_bytes: 3176
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <set>

using namespace std;




int main(void) {
	int n, m, q;

	long long sum = 0;

	cin >> n >> m;

	cout << n * m << endl;

	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q,l,r,a[111111]={0};
  char s[111111];
  cin>>n>>q;
  cin>>s[1];
  for(int i=2;i<=n;i++){
    cin>>s[i];
    if(s[i-1]=='A'&&s[i]=='C') a[i]++;
    a[i]+=a[i-1];
  }
  for(int i=0;i<q;i++){
    cin>>l>>r;
    cout<<a[r]-a[l]<<endl;
  }
  return(0);
}


Measured memory_bytes: 1408
# from collections import namedtuple
# Node = namedtuple("Node", "in, out")
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N+M-1)]
ine = [[] * N for _ in range(N)]
oute = [[] * N for _ in range(N)]
for a, b in AB:
    ine[b-1].append(a-1)
    oute[a-1].append(b-1)
root = ine.index([])
v = [len(e) for e in ine]
#print(v)
ans = [0] * N
q = [(root, n) for n in oute[root]]
while q:
    nq = []
    for p, n in q:
        v[n] -= 1
        if v[n] == 0:
            ans[n] = p + 1
            nq += [(n, nn) for nn in oute[n]]
    q = nq

print("\n".join(map(str, ans)))




Measured memory_bytes: 64484
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;




signed main() {
    ll n;
    cin >> n;
    ll cnt = 0;
    vll l(n);
         
    rep(i, n) {
        cin >> l[i];
    }
    
    // 各 p の値に対して

    
    Sort(l);
    
    rep(i, (ll)l.size()-2) {
        for(ll j = i+1; j < l.size()-1; j++) {
            for(ll k = j+1; k < l.size(); k++) {
                if (l[i] == l[j] || l[j] == l[k]) continue;
                if (l[i] + l[j] > l[k]) cnt ++;
            }
            
        }
    }
    
    mes(cnt);
    
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
  }
  sort(vec.begin(),vec.end());
  
  
  double sum=vec[0];
  
  for(int i=1;i<N;i++){
    sum=(sum+vec[i])/2.0;
  }
  
  cout<<sum<<endl;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
int n,m,ans;
vector<int> edge[maxn];
int in_dgr[maxn],dp[maxn];
queue<int> q;
int main()
{
	cin>>n>>m;
	while(m--)
	{
		int u,v;
		cin>>u>>v;
		edge[u].push_back(v);
		in_dgr[v]++;
	}
	for(int i=1;i<=n;i++)
		if(!in_dgr[i])
			q.push(i);
	while(!q.empty())
	{
		int now=q.front();
		q.pop();
		for(int i=0;i<edge[now].size();i++)
		{
			int to=edge[now][i];
			dp[to]=max(dp[to],dp[now]+1);
			if(--in_dgr[to]==0)
				q.push(to);
			ans=dp[to];
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 6528
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let mut s = read::<String>().chars().collect::<VecDeque<_>>();
    let mut stored = vec![];
    while let Some(top) = s.pop_front() {
        if !stored.is_empty() && stored[stored.len() - 1] == 'S' && top == 'T' {
            stored.pop();
        } else {
            stored.push(top);
        }
    }
    println!("{}", stored.len());
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 6396
#include <stdio.h>

using namespace std;

void output(int H[3][10]){
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 10; j++){
			printf(" %d",H[i][j]);
		}
		printf("\n");
	}
}


int main(){
	int H1[3][10],H2[3][10],H3[3][10],H4[3][10],n,h_num,f_num,r_num,div_num;
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 10; j++){
			H1[i][j] = H2[i][j] = H3[i][j] = H4[i][j] = 0;
		}
	}
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d %d %d %d",&h_num,&f_num,&r_num,&div_num);
		switch(h_num){
		case 1:
			H1[f_num-1][r_num-1] += div_num;
			break;
		case 2:
			H2[f_num-1][r_num-1] += div_num;
			break;
		case 3:
			H3[f_num-1][r_num-1] += div_num;
			break;
		case 4:
			H4[f_num-1][r_num-1] += div_num;
			break;
		}
	}

	output(H1);
	printf("####################\n");
	output(H2);
	printf("####################\n");
	output(H3);
	printf("####################\n");
	output(H4);

}



Measured memory_bytes: 2732
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int days[][] = new int[N][7];
		char leader[] = new char[N]; 
		int result=0;
		int sub=10007;
		String st = sc.next();
		
		for(int i=0;i<N;i++){//責任者を配列に格納
		leader[i]=st.charAt(i);
		}
		
		//１日目
		if(leader[0]=='J'){//Jが責任者
			days[0][0]=1;
			days[0][3]=1;
			days[0][4]=1;
			days[0][6]=1;
		}
		else if(leader[0]=='O'){//Oが責任者
			days[0][3]=1;
			days[0][6]=1;
		}
		else{//(leader[0]=='I')　Iが責任者
			days[0][4]=1;
			days[0][6]=1;
		}
		//2日目以降
		for(int i=1;i<N;i++){
			if(leader[i]=='J'){
				days[i][0] = (days[i-1][0]+days[i-1][3]+days[i-1][4]+days[i-1][6])%sub;
			}
			if(leader[i]=='O'){
				days[i][1] = (days[i-1][1]+days[i-1][3]+days[i-1][5]+days[i-1][6])%sub;
			}
			if(leader[i]=='I'){
				days[i][2] = (days[i-1][2]+days[i-1][4]+days[i-1][5]+days[i-1][6])%sub;
			}
			if(leader[i]=='J'|| leader[i]=='O'){
				days[i][3] = (days[i-1][0]+days[i-1][1]+days[i-1][3]+days[i-1][4]+days[i-1][5]+days[i-1][6])%sub;
			}
			if(leader[i]=='J'|| leader[i]=='I'){
				days[i][4] = (days[i-1][0]+days[i-1][2]+days[i-1][3]+days[i-1][4]+days[i-1][5]+days[i-1][6])%sub;
			}
			if(leader[i]=='O'|| leader[i]=='I'){
				days[i][5] = (days[i-1][1]+days[i-1][2]+days[i-1][3]+days[i-1][4]+days[i-1][5]+days[i-1][6])%sub;
			}
			if(leader[i]=='J' || leader[i]=='O' || leader[i]=='I'){
				days[i][6]+=(days[i-1][0]+days[i-1][1]+days[i-1][2]+days[i-1][3]+days[i-1][4]+days[i-1][5]+days[i-1][6])%sub;
			}	
		}
		for(int i=0;i<7;i++){//全パターンを足す
			result += days[N-1][i];
		}
		System.out.println(result%sub);
		}
}

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

const int N = 2e5 + 10, mod = 1e9 + 7;

char s[N];

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1; 
    //scanf("%d", &tc);
    while(tc--) {
        scanf("%s", &s);
        int n = strlen(s);
        bool ok = 1;
        for(int i = 0; i < n / 2; i++) {
            ok &= (s[i] == s[n - i - 1]);
            if((n / 2) - i - 1 >= i) ok &= (s[i] == s[(n / 2) - i - 1]);
        }
        for(int i = (n / 2) + 1, j = 0; i < n; i++, j++) {
            if(n - j >= i) ok &= (s[i] == s[n - j - 1]);
        }
        if(ok) puts("Yes");
        else puts("No");
    }    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_lim=(n); i<i##_lim; ++i)
#define FOR(i, a, b) for (int i=(a), i##_lim=(b); i<i##_lim; ++i)
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    string S;
    cin >> S;
    string T;
    cin >> T;

    string noe = "UNRESTORABLE";
    string ret = "";
    REP(i, S.length()-T.length()+1)
    {
        bool ok = true;
        REP(j, T.length())
        {
            if (S[i+j] != '?' && S[i+j] != T[j]) { ok = false; break; }
        }
        if (!ok) continue;

        string tmp = "";
        REP(j, S.length())
        {
            tmp += i <= j && j < i+T.length() ? T[j-i] : S[j] == '?' ? 'a' : S[j];
        }
        if (ret == "" || tmp < ret) ret = tmp;
    }

    cout << (ret == "" ? noe : ret) << endl;
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    map<char, int> mp;
    for(int i=0; i<26; i++){
        mp['a'+i] = 0;
    }
    for(int i=0; i<s.length(); i++){
        mp[s.at(i)]++;
    }

    bool flg = true;
    int ids = 0;
    for(int i=0; i<26; i++){
        if(mp['a'+i] == 0){
            flg = false;
            ids = i;
            break;
        }
    }
    char res = 'a'+ids;
    if(flg)
        cout << "None" << endl;
    else
        cout << res << endl;

    return 0;
}

Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;


int main() { 
    int N; cin >> N;
    for (int i=1; i<10; i++) {
        if(N<=111*i) {
            print(i*111);
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 504
vacDuration, homeworkAmount = map(int, input().split())
daySpent = list(map(int, input().split()))
sum_daySpent = 0
for i in daySpent:
    sum_daySpent += i
if sum_daySpent > vacDuration:
    print('-1')
else:
    print(vacDuration - sum_daySpent)


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

#define int long long

vector<int> G[200000];
const int M = 100000;
vector<bool> used(200000, false);  
using P = pair<int, int>;
int A, B;

void dfs(int v) {
  if ( used[v] ) return;  
  used[v] = true;
  if ( v >= M ) B++;
  else A++;
  for ( int u : G[v] ) dfs(u);  
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;

  for ( int i = 0; i < N; i++ ) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    G[x].push_back(M+y);
    G[M+y].push_back(x);
  }

  int ans = -N;  
  for ( int i = 0; i < 200000; i++ ) {
    if ( used[i] ) continue;
    dfs(i);
    ans += A*B;
    A = B = 0;
  }

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


Measured memory_bytes: 10112
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

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

    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) {cin >> s[i];}

    map<string, int> num = {{"AC", 0}, {"WA", 0}, {"TLE", 0}, {"RE", 0}};
    rep(i, n) {
        num[s[i]]++;
    }
    
    cout << "AC x " << num["AC"] << endl;
    cout << "WA x " << num["WA"] << endl;
    cout << "TLE x " << num["TLE"] << endl;
    cout << "RE x " << num["RE"] << endl;
}

Measured memory_bytes: 6344
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	K := getStdinInt()
	S := getStdin()

	if len(S) <= K {
		fmt.Printf("%s\n", S)
		return
	}

	fmt.Printf("%s", S[:K])
	fmt.Printf("...\n")
}

func getStdin() string {
	sc.Scan()
	return sc.Text()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}


Measured memory_bytes: 1760
while 1:
    H, W = map(int, input().split())
    if H ==0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (j % 2 == 0 and i % 2 == 0)\
            or (j % 2 != 0 and i % 2 != 0): 
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()

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

vector<long> H,ans;

int main(void){
    long N;
    cin >> N;
    H = vector<long>(N);
    ans = vector<long>(N,0);
    for(long i=0;i<N;i++){
        cin >> H[i];
        if(i != 0){
            if(H[i-1] >= H[i]){
                ans[i] = ans[i-1] + 1;
            }
        }
    }
    sort(ans.begin(),ans.end());
    cout << ans.back() << endl;
    return 0;
}

Measured memory_bytes: 1792
N,K = map(int,input().split())
A = list(map(int,input().split()))

C = [0]*N
C[0] = 1
place = 1
i = 1
while True:
  place = A[place-1]
  if C[place-1] == 0:
    i += 1
    C[place-1] = i
  else:
    break
if K <= i-1:
  print(C.index(K+1) +1)
  exit()
K -= i-1
loop = i + 1 -C[place-1]
K %= loop
if K == 0:
  print(C.index(i) +1)
else:
  print(C.index(K-1 + C[place-1]) +1)

Measured memory_bytes: 100108
var a:array[0..100] of longint;
var them,n:longint;

procedure xuly(x:longint);
begin
   if (1<=x) and (x<=399) then inc(a[1])
      else if (x<=799) then inc(a[2])
         else if (x<=1199) then inc(a[3])
            else if (x<=1599) then inc(a[4])
               else if (x<=1999) then inc(a[5])
                  else if (x<=2399) then inc(a[6])
                     else if (x<=2799) then inc(a[7])
                        else if (x<=3199) then inc(a[8])
                           else inc(them);
end;

procedure nhap;
var i,the:Longint;
begin
   read(n);
   fillchar(a,sizeof(a),0);
   them:=0;
   for i:=1 to n do
      begin
      read(the);
      xuly(the);
      end;
end;

procedure xuat;
var i,tong:longint;
begin
   tong:=0;
      for i:=1 to 8 do
         if a[i]>0 then inc(tong);

   if tong=0 then write('1',' ') else
      write(tong,' ');
   write(tong+them);
end;

begin
   nhap;
   xuat;
end.

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
	char s[100010];
	while(scanf("%s",s)!=EOF)
	{
		int  i,flag=1;
		int len=strlen(s);
		for(i=0;i<len;i++)
		{
			if(s[i]==s[i+1])
			{
				flag=0;
				printf("%d %d\n",i+1,i+2);
				break;
			}
			else if(s[i]==s[i+2])
			{
				flag=0;
				printf("%d %d\n",i+1,i+3);
				break;
			}
		}
		if(flag)
			printf("-1 -1\n");
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,q,x,y,ans,xx;
vector <int> v[505];
int main(){
        scanf("%d%d%d",&n,&m,&q);
        for(int i=1;i<=m;i++){
                scanf("%d%d",&x,&y);
                v[y].push_back(x);
        }
        for(int i=1;i<=n;i++) sort(v[i].begin(),v[i].end());
        for(int i=1;i<=q;i++){
                scanf("%d%d",&x,&y);
                for(int i=x;i<=y;i++){
                        xx=lower_bound(v[i].begin(),v[i].end(),x)-v[i].begin();
                                ans+=v[i].size()-xx;
                    }
                printf("%d\n",ans);
                ans=0;
        }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <math.h>
#define ll long long
using namespace std;


const int MAX_CHAR = 26; 
const int MAX_FACT = 20; 
ll fact[MAX_FACT]; 
  
// utility for calculating factorials 
void precomputeFactorials() 
{ 
    fact[0] = 1; 
    for (ll i = 1; i < MAX_FACT; i++){
        fact[i] = fact[i - 1] * i;
        //cout << i << "||" << fact[i] << endl; 
    }
}

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(b, a%b);
}

vector <string> getWords(string s){
    string cur = "";
    vector <string> vec;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == ' '){
            vec.push_back(cur);
            cur = "";
        } else cur += s[i];
    }
    vec.push_back(cur);
    return vec;
}

map <int,string> mp;
const double pi = acos(-1.0);
int main(){
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    int minutes = 60*h+m;
    double theta1 = (((minutes)%360)*6.0);
    //cout << theta1 << " theta1" << endl;
    theta1 *= ((2.0*pi)/360.0);
    double theta2 = (minutes/2.0);
     //cout << theta2 << " theta2" << endl;
    theta2 *= ((2.0*pi)/360.0);
    double diff = abs(theta1-theta2);
    double ans = sqrt(a*a+b*b-2.0*a*b*cos(diff));
    printf("%0.12f", ans);
}
   

Measured memory_bytes: 4232
#include<iostream>
#include <string>
#include <unordered_set>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    string w;
    char prev;
    unordered_set<string> st;
    for (int i = 0; i < n; i++) {
        cin >> w;
        if (i) {
            if (w[0] != prev || st.find(w) != st.end()) {
                cout << "No" << endl;
                return 0;
            }
        }
        st.insert(w);
        prev = w[w.size() - 1];
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n,k;cin>>n>>k;){
		vvi bm(n);
		rep(i,k){
			int m; cin>>m;
			bm[i].resize(m);
			rep(j,m)
				cin>>bm[i][j];
		}
		int r; cin>>r;
		set<pii> rs;
		rep(i,r){
			int p,q; cin>>p>>q;
			rs.insert(mp(p,q));
		}
		
		vvi bad(n);
		rep(i,k){
			int m=bm[i].size();
			bad[i].resize(m);
			rep(j,m) rep(k,m)
				if(rs.count(mp(bm[i][j],bm[i][k]))){
					bad[i][j]=1;
					bad[i][k]=1;
				}
		}
		
		int res=0;
		rep(i,k) rep(j,bad[i].size())
			res+=bad[i][j];
		cout<<res<<endl;
	}
	
	return 0;
}

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

int main(void) {
	char s[52][52];
	int H, W, j, sum,flag;
	flag = 0;
	cin >> H >> W;
	int k,i;
	for (i = 1; i < H; i++) {
		for (k = 1; k < W; k++) {
			s[i][k]=' ';
		}
	}
	for (i = 1; i < H+1; i++) {
		for (k = 1; k < W+1; k++) {
			cin >> s[i][k];
		}
	}
	for (i = 1; i < H; i++) {
		for (k = 1; k < W; k++) {
			if (s[i][k] == '#'&&s[i + 1][k] != '#'&&s[i][k + 1] != '#'&&s[i - 1][k] != '#'&&s[i][k - 1] != '#') {
				flag = 1;
				break;
			}
			
		}
	}
	if (flag == 1) {
		cout << "No" << endl;
	}
	else
		cout << "Yes" << endl;
	
	return 0;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    bool flg = true;
    vector<int> vec(n);
    rep(i, n) cin >> vec.at(i);
    sort(vec.begin(), vec.end());
    rep(i, n-1){
        if(vec.at(i) == vec.at(i+1)) flg = false;
    }
    if(flg) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}



int main() {
	Int a, b; cin >> a >> b;

	if ((a + b) % 2 == 0) cout << (a + b) / 2;
	else cout << "IMPOSSIBLE";

	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

const int maxn = 300 + 10;
char tab[maxn][maxn];
char tab2[maxn][maxn];

int N;

bool check(int b) 
{
	for (int i = 0; i < N; i++) {
		for (int ind = 0; ind < N; ind++) {
			int j = (b + ind) % N;
			tab2[i][ind] = tab[i][j];
		}
	}

	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (tab2[i][j] != tab2[j][i])
				return false;
		}
	}
	return true;
}

int main()
{

	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	cin >> N;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> tab[i];
	}

	for (int i = 0; i < N; i++) {
		if (check(i))
			ans += N;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int main(){
    int n=0;
    while(1){
        char x[1000];
        scanf("%s",x);
        if(x[0] == '0') break;
        for(int i=0;i<strlen(x);i++){
            n += x[i] - '0';
        }
        printf("%d\n",n);
        n = 0;
    }
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,a[3000];
signed main()
{
	cin>>n;
	bool f=0;
	for(int i=1;i<=n;i++)cin>>a[i],f|=a[i]>0;
	if(!f)
	{
		int ans=-(1ll<<60),id=0;
		for(int i=1;i<=n;i++)ans=max(ans,a[i]),id=ans==a[i]?i:id;
		cout<<ans<<endl<<n-1<<endl;
		for(int i=1;i<n;i++)cout<<(i>=id?n-i+1:1)<<endl;
		return 0;
	}
	int odd=0,even=0;
	for(int i=1;i<=n;i++)(i&1?odd:even)+=max(0ll,a[i]);
	list<int> v,op;
	for(int i=1;i<=n;i++)v.emplace_back(a[i]>0&&(i&1)==(odd>even));
	while(v.size()>1)
	{
		while(!v.back())op.push_back(v.size()),v.pop_back();
		while(!v.front())op.push_back(1),v.pop_front();
		int pos=2;
		if(v.size()>2)for(auto i=++v.begin();i!=--v.end();i++,pos++)
		{
			auto k=i--,j=k++;
			if((*i&&*k)||(!*i&&!*j&&!*k))
			{
				op.push_back(pos);
				*j=*i||*k;
				v.erase(i);v.erase(k);
				break;
			}
			i++;
		}
	}
	cout<<max(odd,even)<<endl<<op.size()<<endl;
	for(int i:op)cout<<i<<endl;
	return 0;
}

Measured memory_bytes: 256
using namespace std; 
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define vect vector<ll>
#define maap map<ll,ll>  
#define MOD 1000000007
#define mit map::iterator
#define pii pair<ll,ll>
#define rep(i,a,b)	for(ll i=a;i< b;i++)
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
typedef  long long   int  ll;
//stringstream convert; 
  //  convert << number; 
  //  string s = convert.str();
 ll fact[500005],invfact[500005]; 
 ll power(ll x, ll y)
{
	ll z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = (z*x)%MOD;
		x = (x*x)%MOD;
		y /= 2;
	}
	return z;
}
 ll inv(ll x)
{
	return power(x,MOD-2);
}
ll divide(ll x, ll y)
{
	return (x*inv(y))%MOD;
}
ll C(ll n, ll k)
{
	if(k > n) return 0;
	return divide(fact[n], (fact[n - k]*fact[k])%MOD);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
bool isPrime(int n) {
 
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
} 
void init(){
	ll p=MOD;
	fact[0]=1;
	ll i;
	for(i=1;i<500005;i++){
		fact[i]=(i*fact[i-1])%p;
	}
	i--;
	invfact[i]=power(fact[i],p-2);
	for(i--;i>=0;i--){
		invfact[i]=(invfact[i+1]*(i+1))%p;
	}
}
ll s;
ll fun(ll a)
{
	if(a==0)
	return 0;
	return a+fun(a-1);
}
priority_queue < pair<ll,ll> , vector<pair<ll,ll> >,greater<pair<ll,ll> > > gq;

#define MAXN   10000001 
ll spf[MAXN]; 
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXN; i++) 
        spf[i] = i; 
    for (ll i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
    for (ll i=3; i*i<MAXN; i++) 
    {
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
set<ll> getFactorization(ll x) 
{ 
    set<ll> ret; 
    while (x != 1) 
    { 
        ret.insert(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}
ll sm(ll n)
{
	ll i;
	ll k=0;
	while(n>0)
	{
		k=k+n%10;
		n=n/10;
	}
	return k;
}
void ghost()
{   
  	ll i=0,j=0,k=0,l=0,n,r=0,q=0,t=0,y=100000000000,m,w;
    	cin>>n>>m;
       char a[n][m];
       for(i=0;i<n;i++)
       {
       	for(j=0;j<m;j++)
       	cin>>a[i][j];
	  }
	  ll dp[n+1][m+1];
	  for(i=0;i<=n;i++)
	  {
	  	for(j=0;j<=m;j++)
	  	dp[i][j]=0;
	  }
	  
	  for(i=1;i<=n;i++)
	  {
	  	for(j=1;j<=m;j++)
	  	{
	  		if(i==1&&j==1)
	  		dp[i][j]=1;
	  		else if(a[i-1][j-1]=='#')
	  		continue;
	  		else if(a[i-1][j-1]=='.')
	  		dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
		  }
	  }
	  cout<<dp[n][m];
	}
signed main()
{int test=1;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
fast
//cin>>test;
while(test--)
ghost();
return 0;
}

  


Measured memory_bytes: 12460
import sys
s = int(input())
a = [s]
for i in range(1, 1000001):
    if a[i-1] % 2 == 0:
        a.append(a[i-1]//2)
    else:
        a.append(3 * a[i-1] + 1)
for i in range(len(a)):
    if a[i] in a[0:i]:
        print(i+1)
        sys.exit()


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	string a, b; cin >> a >> b;
    if((a == "H" && b == "H") || (a == "D" && b == "D")) cout << "H" << endl;
    else cout << "D" << endl;
	return 0;
}

Measured memory_bytes: 3588
{-# LANGUAGE BangPatterns, OverloadedStrings #-}

import Control.Monad
import Data.Array.Unboxed
import Data.Bits
import Data.Bool
import Data.Char
import Data.Coerce
import Data.Function
import Data.Int 
import Data.IORef
import Data.List
import Data.Maybe
import qualified Data.Map.Strict as M
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  ns <- map (read . (:[])) <$> getLine
  if sum ns `mod` 9 == 0
    then putStrLn "Yes"
    else putStrLn "No"

-- Input

getInt :: IO Int
getInt = readLn
second :: (b -> c) -> (a, b) -> (a, c)
second f (a, b) = (a, f b)

readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = fmap (second BS.tail) . BS.readInt

getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n readInt <$> BS.getLine
 
getIntList :: IO [Int]
getIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

getIntegerList :: IO [Integer]
getIntegerList = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

getIntPair :: IO (Int, Int)
getIntPair = do
  v <- getIntVec 2
  return (v V.! 0, v V.! 1)

-- Search

bisearch :: (Int -> Bool) -> (Int, Int) -> (Int, Int)
bisearch check = bis
  where
    bis (l, r)
      | l + 1 == r = (l, r)
      | check mid  = bis (mid, r)
      | otherwise  = bis (l, mid)
      where
        mid = l + (r - l) `div` 2

-- Modular Arithmetic
--
 
modulo :: Int64
modulo = 10^9+7
addMod, subMod, mulMod :: Int64 -> Int64 -> Int64
addMod !x !y | x + y >= modulo = x + y - modulo
             | otherwise = x + y
subMod !x !y | x >= y = x - y
             | otherwise = x - y + modulo
mulMod !x !y = (x * y) `rem` modulo

newtype N = N { unwrapN :: Int64 } deriving (Eq)
instance Show N where
  show (N x) = show x
instance Num N where
  (+) = coerce addMod
  (-) = coerce subMod
  (*) = coerce mulMod
  fromInteger n = N (fromInteger (n `mod` fromIntegral modulo))
  abs = undefined; signum = undefined
---
 
exEuclid :: (Eq a, Integral a) => a -> a -> (a, a, a)
exEuclid !f !g = loop 1 0 0 1 f g
  where loop !u0 !u1 !v0 !v1 !f 0 = (f, u0, v0)
        loop !u0 !u1 !v0 !v1 !f g =
          case divMod f g of
            (q,r) -> loop u1 (u0 - q * u1) v1 (v0 - q * v1) g r
 
recipM :: Int64 -> Int64
recipM !x = case exEuclid x modulo of
             (1,a,_) -> a `mod` modulo
             (-1,a,_) -> (-a) `mod` modulo
divM :: Int64 -> Int64 -> Int64
divM !x !y = x `mulMod` recipM y
 
instance Fractional N where
  (/) = coerce divM
  recip = coerce recipM
  fromRational = undefined

-- 組み合わせ
powerset :: [a] -> [[a]]  
powerset xs = filterM (\x -> [True, False]) xs


Measured memory_bytes: 11928
//
//  main.cpp
//  A - September 9
//
//  Created by wenhan on 2017/9/9.
//  Copyright © 2017年 wenhan. All rights reserved.
//

#include <iostream>
using namespace std;
int main() {
    int n;
    cin>>n;
    if(n/10==9||n%10==9)
        printf("Yes\n");
    else
        printf("No\n");
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(System.Console.ReadLine());
            int count = 0;
            List<string> list = new List <string>{ "P", "W", "G", "Y" };
            string[] s = System.Console.ReadLine().Split(' ');
            for(int i = 0; i < n; i++)
            {
                if (list.IndexOf(s[i]) >= 0)
                {
                    count++;
                    list.Remove(s[i]);
                }
            }
            if(count==3)
                System.Console.WriteLine("Three");
            else
                System.Console.WriteLine("Four");
        }
    }
}

Measured memory_bytes: 11104
m = int(input())
s = ""
S = 0
C = 0

"""
各桁をa,bとすると
(1)a+b < 10 
(2)a+b >= 10
で場合分け
1234567890 -> 桁がn, 総和がs
(1)の操作 : n-1, s
(2)の操作 : n, s-9
POINT (1),(2) 両方の操作でも、9n+sの値が9ずつ減っていく
"""

for i in range(m):
    d,c = map(int, input().split())
    S += c*d # 総和
    C += c # 桁

n = S
while n >= 10:
    cnt = 0
    for s in str(n):
        cnt += int(s)
    n = cnt

begin = S + 9*C
end = n + 9
print((begin-end-1)//9 + 1)

Measured memory_bytes: 9212
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;



int main(){
  ll ii,jj,kk;
  int flg = 0;
  string s,t,a;
  cin >> s >> t;
  a = "";
  for(ii=s.size()-t.size();ii>=0;ii--){
    for(jj=0;jj<t.size();jj++){

      //cout << "ii:" << ii << "jj" << jj ;
      //cout << t[jj];

      if(s[ii+jj] == '?' ||
	 s[ii+jj] == t[jj]){
	
	if(jj==t.size()-1){
	  flg = 1;
	  goto label;
	}
      }
      else{
	break;
      }
    }
  }
 label:
  if(flg){
    //cout << "getkey";
    for(kk=0;kk<s.size();kk++){
      if(kk>=ii && kk<=ii+t.size()-1){
	a += t[kk-ii];
      }
      else{
	if(s[kk] == '?'){
	  a += 'a';
	}
	else{
	  a += s[kk];
	}
      }
    }
    cout << a << endl;
  }
  else{
    cout << "UNRESTORABLE" << endl;
  }

    
  return 0;
}


Measured memory_bytes: 256
# input
N = int(input())
A = [list(map(int, input().split())) for i in range(2)]

# check
element = set(A[0] + A[1])
if len(element) == 1:
    print(list(element)[0] * (N + 1))
else:
    res = 0
    for d in range(N):
        if d == 0:
            sum_num = A[0][0] + sum(A[1])
        elif d == N - 1:
            sum_num = sum(A[0]) + A[1][N - 1]
        else:
            sum_num = sum(A[0][:d + 1]) + sum(A[1][d:])
        if res < sum_num:
            res = sum_num
    print(res)

Measured memory_bytes: 9212
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <random>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <complex>
#include <functional>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> int(a);)
#define all(v) v.begin(),v.end()
#define trav(x, v) for(auto &x : v)
#define sz(v) int((v).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double ld;

void fail(){
	puts("Impossible");
	exit(0);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int h, w;
	cin >> h >> w;
	vector<string> ss(h);
	trav(s, ss) cin >> s;
	int cnt = 0;
	trav(s, ss) trav(c, s) cnt += c=='#';
	if(cnt != h+w-1) fail();
	vector<vector<int>> dp(h, vector<int>(w,-1));
	function<bool(int,int)> dfs = [&](int x, int y){
		if(x >= h || y >= w) return 0;
		if(dp[x][y] != -1) return dp[x][y];
		if(ss[x][y]=='.') return dp[x][y] = 0;
		if(x+1==h || y+1==w) return 1;
		return dp[x][y] = dfs(x+1,y)|dfs(x,y+1);
	};
	if(!dfs(0,0)) fail();
	puts("Possible");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N,K;
    cin>>N>>K;
    vi p(N);
    for(int i=0;i<N;i++){
        cin>>p[i];
    }
    sort(ALL(p));
    int ans=0;
    for(int i=0;i<K;i++){
        ans+=p[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define maxn 500050
using namespace std;
typedef long long LL;

int n,a[maxn];
char s[maxn];

int main()  {
    scanf("%s",s+1);
    n=strlen(s+1)+1;

    int mn=1<<30;
    for (int i=1,j=1;i<n;i=j)   {
        while (j<n&&s[i]==s[j]) ++j;
        if (s[i]=='<')  {
            for (int k=i;k<j;++k)
                a[k]=a[k-1]+1;
        } else  {
            a[i-1]=max(a[i-1],j-i);
            for (int k=j-2;k>=i;--k)
                a[k]=a[k+1]+1;
        }
    }
    // for (int i=0;i<n;++i)
    //     cout<<a[i]<<" ";
    // cout<<endl;

    LL sum=0;
    for (int i=0;i<n;++i)
        sum+=a[i];
    printf("%lld\n",sum);
    return 0;
}

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

using namespace std;

int N, T[100], M, P[100], X[100], sum;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
  }

  for (int i = 0; i < N; i++) {
    sum += T[i];
  }
  for (int i = 0; i < M; i++) {
    cout << sum - T[P[i] - 1] + X[i] << endl;
  }
  return 0;
}

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

int main(void) {
  int N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  long long bits = 0;
  for (int i = 0; i < N; i++) {
    bits ^= a[i];
  }
  for (int i = 0; i < N; i++) {
    cout << (a[i] ^ bits) << " \n"[i == N - 1];
  }
  return 0;
}

Measured memory_bytes: 4656
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

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

int ctoi(char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    return 0;
}

int main() {
    string S;
    cin >> S;
    // DEBUG(S);
    int first = ctoi(S[0]) * 10 + ctoi(S[1]);
    int second = ctoi(S[2]) * 10 + ctoi(S[3]);

    bool isMMYY = false;
    bool isYYMM = false;

    // DEBUG(first);
    // DEBUG(second);

    if (1 <= first && first <= 12) {
        isMMYY = true;
    }
    if (1 <= second && second <= 12 ) {
        isYYMM = true;
    }
    // DEBUG(isMMYY);
    // DEBUG(isYYMM);

    if (isMMYY && isYYMM) {
        cout << "AMBIGUOUS" << endl;
    } else if (isMMYY) {
        cout << "MMYY" << endl;
    } else if (isYYMM) {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define REP(i,m,n) for(int i=(m); i<(n); i++)
#define RREP(i,n,m) for(int i=(n);i>=(m); i--)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<int, int> mp;
    REP(i,1,n+1) mp[i] = 0;
    REP(i,0,n-1)
    {
      int tmp;
      cin >> tmp;
      mp[tmp]++;
    }
    REP(i,1,n+1)
    {
      cout << mp[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 13024
import operator
n=int(input())
rest=[]

for i in range(n):
    rest.append([s for s in input().split()])
    rest[i].append(i+1)
    rest[i][1]=int(rest[i][1])

rest.sort(key=operator.itemgetter(1),reverse=True)
rest.sort(key=operator.itemgetter(0))
for i in range(len(rest)):
    print(rest[i][2])


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


#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

int main() {

    int n;
    cin >> n;

    vector<int> nums(n);
    rep(i, n) {
        cin >> nums[i];
    }

    int ans = 0;
    bool active = false;
    for (int i = 0; i < n; i++) {
        if (nums[i] == (i + 1) && (!active)) {
            active = true;
            ans++;
        } else {
            active = false;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640