akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,W,w[222],sum[222];
ll dp[10010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N>>W;
	rep(i,N)cin>>w[i];
	sort(w,w+N);
	//while(N && w[N-1]>W)N--;
	sum[0]=0;
	rep(i,N)sum[i+1]=sum[i]+w[i];
	if(W>=sum[N]){
		cout<<1<<endl;
		return 0;
	}
	ll ans=0;
	dp[0]=1;
	for(int i=N-1;i>=0;i--){
		for(int j=W;j>=0;j--){
			if(sum[i]+j<=W && sum[i]+j>W-w[i])ans+=dp[j];
			if(j>=w[i])dp[j]=(dp[j]+dp[j-w[i]])%MOD;
		}
	}
	cout<<ans%MOD<<endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <string>
#include <locale>
#include <stack>
#include <map>
#include <queue>
using namespace std;

struct prosece {
	string name;
	int		time;
};

int main(void)
{
	deque<prosece> task;
	vector<prosece> endlist;

	int n, sycl;
	cin >> n>> sycl;
	for (size_t i = 0; i < n; i++)
	{
		prosece dis;

		cin >> dis.name >> dis.time;
		task.push_back(dis);

	}
	int ctime = 0;
	while (task.size()>0)
	{
		prosece dis = task.front();
		task.pop_front();
		ctime += sycl;
		dis.time -= sycl;
		if (dis.time > 0) {
			task.push_back(dis);
		}
		else {
			ctime += dis.time;
			dis.time = ctime;
			endlist.push_back(dis);
		}


	}
	for (auto a : endlist)
		cout << a.name << " " << a.time << endl;


	return 0;
}

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

int main()
{
    rep(i, 5)
    {
        int x;
        cin >> x;
        if (x == 0)
        {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int cnt = 0;
        int ans = 0;
        for (int i = Math.min(a, b); i >= 0; i--) {
            if (a % i == 0 && b % i == 0) {
                cnt++;
                if (cnt == k) {
                    ans = i;
                    break;
                }
            }
        }
        System.out.println(ans);
    }
}

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

#include <stdio.h>

#include <math.h>
/********
*	?¨??????????????±???????????????°??????
*********/	
/*********??¢?????´?????????
*	(1)??°????????\???
*	(2)?¨???????????????????
*********/

int main(void)
{
	double n ;	//??????????????°
	double a, m ;	//a?????£???m?????????
	double sum, aaa;
	double seito_tensu[1000]={0}; //????¨?????????°
	
	
	while(1){
    
		cin >> n ;
		if(n == 0 ){
			break;
		} else {
			sum = 0;
			aaa = 0;
			m=0;
			
			for (int i =0; i<n ; i++){
			    cin >> seito_tensu[i] ;
			}
			
			for(int i = 0 ; i<n ;i++){
				sum += seito_tensu[i];
			}
			m =sum/n ;		//???????????????????¨????
			
			for(int i = 0; i< n ; i++){
				aaa += (seito_tensu[i]-m)*(seito_tensu[i]-m);
			}
			a = sqrt((aaa)/n);
			
			
			printf("%f\n", a);
		}
	}
	return 0;
}

Measured memory_bytes: 1236
while True:
    n = int(input())
    if n == 0:
        break
    s = list(map(int,input().split()))
    m = sum(s) / len(s)
    
    sum_dev = 0
    for i in range(len(s)):
        sum_dev = sum_dev + (s[i] - m) ** 2
    a = (sum_dev / n) **0.5
    print("{:.8f}".format(a))


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, rating;
    cin >> n >> rating;
    if (n >= 10) {
        cout << rating << endl;
    } else {
        cout << rating + 100 * (10 - n) << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
const int mm=1e9;
int mp[100010],n;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin>>s;
	int len=s.size(),res=0;
	memset(mp,0,sizeof mp);
	for(int i=0;i<len;i++)
	{
		if(s[i]=='R')
			res++;
		else if(s[i-1]!='L')
		{
			if(res&1)
			{
				mp[i]+=(res+1)/2;
				mp[i-1]+=(res+1)/2; 
			}
			else
			{
				mp[i]+=(res/2+1);
				mp[i-1]+=(res/2);
			}
			res=0;
		}
	}
	for(int i=len-1;i>=0;i--)
	{
		if(s[i]=='L')
			res++;
		else 
		{
			if(res&1)
			{
				mp[i]+=res/2;
				mp[i+1]+=res/2; 
			}
			else
			{
				mp[i]+=res/2;
				mp[i+1]+=(res-1)/2;
			}
			res=0;
		}
	}
	for(int i=0;i<len;i++)
		printf("%d ",mp[i]);
	return 0;
}

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

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

    vector<int> H(N);
    for (int i = 0; i < N; i++)
    {
        cin >> H.at(i);
    }
    sort(H.begin(), H.end(), greater<int>());

    int64_t res = 0;
    for (int i = 0; i < N; i++)
    {
        if (K > 0)
            K--;
        else
            res += H.at(i);
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
/*
    author: masab hasnain
*/

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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> in(n + 5, 0);
    for(int i = 1; i < n; i++){
        int k;
        cin >> k;
        in[k]++;
    }
    for (int i = 1; i <= n; i++){
        cout << in[i] << endl;
    }
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int N, M;
	cin >> N >> M;
	ll lca;
	cin >> lca;
	ll cnt = __gcd(lca, INF);
	rep( i, 1, N ){
		ll input;
		cin >> input;
		ll gc = __gcd( lca, input );
		lca *= input;
		lca /= gc;
		if (lca > M * 2 || __gcd(input, INF) != cnt){
			cout << 0 << endl;
			return 0;
		}
	}
	M-=lca/2;
	cout << M / lca + 1 << '\n';
}


int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int h, w;
    for(;;) {
        scanf("%d %d", &h, &w);
        if(h==0) break;
        for(int i=0;i<h;i++) {
            for(int j=0;j<w;j++) {
                if(i==0 || i==h-1 || j==0 || j==w-1) printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2576
def main():
    N = int(input())
    cnt = 0
    for i in range(1, N+1, 2):
        cnt_tmp = 0
        for j in range(1, N+1):
            if i % j == 0:
                cnt_tmp += 1
        if cnt_tmp == 8:
            cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()


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

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    ll n; cin >> n;
    cout << (n * (n - 1)) / 2 << '\n';

    return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX 10010

using namespace std;

int r[MAX],c[MAX];

int main(){
  int n;
  while(cin >> n,n){
    rep(i,n)cin >> r[i]; 
    rep(i,n)cin >> c[i];
    sort(r,r+n,greater<int>());
    sort(c,c+n,greater<int>());
    bool judge = true;
    if(r[0] > n || c[0] > n)judge = false;
    rep(i,n){
      if(!judge)break;
      rep(j,c[i])r[j]--;
    }
    rep(i,n)if(r[i] != 0)judge = false;
    cout << (judge?"Yes":"No") << endl;
  }
  return 0;
}

Measured memory_bytes: 1248
# -*- coding: utf-8 -*-
# input
n, y = map(int, input().split())

for i in range(0, n + 1):
    for j in range(0, n + 1 - i):
        if y == 10000 * i + 5000 * j + 1000 * (n - i - j):
            print(i, j, n - i - j)
            exit()
        elif y < 10000 * i + 5000 * j + 1000 * (n - i - j):
            break

print('-1', '-1', '-1')


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    vector<lint> a(3*n);
    REP(i, 3*n) { cin >> a[i]; }

    sort(a.begin(), a.end());
    lint ans = 0;
    REP(i,n){
        ans += a[3 * n - 2 - (2 * i)];
    }

    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
using ll=long long;
int main()
{
    int a,b;
    string str;
        cin>>a;
        cin>>str;
        cin>>b;
    if(str[0] == '+')
    {
        cout<<a+b<<endl;
    }
     if(str[0] == '-')
    {
        cout<<a-b<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
//Catchharsh
    #include<bits/stdc++.h>
    #define ll long long int 
    #define ld long double
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define F first
    #define S second
    #define pb push_back
    #define endl '\n'
    const ll MOD = 1e9+7;
    const ll INF = 1011111111;
    const ll LLINF = 1000111000111000111LL;
    const ld EPS = 1e-10;
    const ld PI = 3.14159265358979323;
    using namespace std;
    ll power (int x,int n)
    {
        if(n==0)
        return 1;
        else if(n%2==0)
        return power((x*x),n/2);
        else
        return x*power((x*x),(n-1)/2); 
    }
    vector<ll> seve;
    void  seveprime()
    {
      int prime[1000000]={0};
      for(int i=2;i*i<1000000;i++)
       {
        if(prime[i]==0)
         {
      	  for(int j=i*2;j<=1000000;j+=i)
           prime[j]=1;
         }
       }
       for(int i=2;i<=1000000;i++)
       {
       	if(prime[i]==0)
       		seve.pb(i);
       }
    }
          int dp[1000+1][1000+1];
    int main()
    {   
         IOS;
         int n,m,i,j,k;
         cin>>n>>m;  
         char ch[n+1][m+1];
         for(i=1;i<=n;i++)
         	for(j=1;j<=m;j++)
         		cin>>ch[i][j];
         	dp[1][1]=0;
         	for(i=1;i<=m;i++)
         	{
         		if(ch[1][i]=='#')
         			break;
         		else
         			dp[1][i]=1;
         	}
         	for(i=1;i<=n;i++)
         	{
         		if(ch[i][1]=='#')
         			break;
         		else
         			dp[i][1]=1;
         	}
         for(i=1;i<=n;i++)
         {
          for(j=1;j<=m;j++)
          {
          	  if(ch[i][j]=='#')
          	  	 dp[i][j]=0;
          	 else if(i==1||j==1)
          	  {continue;}
          	  else
          	  {
          	  	  if(ch[i][j-1]!='#')
          	  	  	dp[i][j]+=dp[i][j-1];
          	  	  if(ch[i-1][j]!='#')
          	  	  	dp[i][j]+=dp[i-1][j];
          	  }
          	  dp[i][j]%=MOD;
          }
         }
         // for(i=1;i<=n;i++)
         // {
         // 	for(j=1;j<=m;j++)
         // 		cout<<dp[i][j]<<" ";
         // 	cout<<endl;
         // }
         cout<<dp[n][m];
    }

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

int n;

long long euclid(long long a, long long b)
{
	int temp;

	if (a < b) {
		temp = a; a = b; b = temp;
	}

	if (a % b == 0) return b;
	return euclid(b, a % b);
}


int main()
{
	std::cin >> n;
	long long ans;
	for (int i = 0; i < n; ++i) {
		long long a;
		std::cin >> a;
		if (i == 0)
			ans = a;
		else
			ans = euclid(ans, a);
	}

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


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

int main(){
    ll n, c, k; cin >> n >> c >> k;
    vector<ll> t(n);
    for(int i=0; i<n; i++)  cin >> t.at(i);
    sort(t.begin(), t.end());
    ll timer = t.at(0)+k, bus=1, cnt=1;
    for(int i=1; i<n; i++){
        if(t.at(i)<=timer && cnt+1<=c) {
            cnt += 1;   continue;
        }
        timer = t.at(i)+k;
        bus += 1;
        cnt = 1;
    }
    cout << bus << endl;

}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,v) VL v(n);rep(i,n)cin>>v[i]
#define int long long
#define itn int
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define ENDL cout<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define LINE puts("------------------")
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
typedef struct{ll to;ll cost;} Graphs;
typedef V<V<Graphs>> AdjList;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}

template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<class T>T center(T a,T b,T c){
  if( (a<=b&&b<=c)||(a>=b&&b>=c) )return b;
  if( (b>=a&&a>=c)||(b<=a&&a<=c) )return a;
  return c;
}
void print(){}
template<class Head,class... Tail>
void print(Head&& head, Tail&&... tail){
  cout<<head<<endl;
  print(forward<Tail>(tail)...);
}
void input(){}
template<class Head,class... Tail>
void input(Head&& head, Tail&&... tail){
  cin>>head;
  input(forward<Tail>(tail)...);
}
template<typename T>
ostream &operator<<(ostream&out,const vector<T>&v){
  if(!v.empty()){
    copy(v.begin(),v.end(),ostream_iterator<T>(out,", "));
    out<<"\b\b";
  }
  return out;
}
template<typename T1, typename T2>
ostream &operator<<(ostream&out,const pair<T1,T2>&p){
  out<<p.first<<", "<<p.second;
  return out;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  ll L,R;
  cin>>L>>R;
  if(R-L>1000)cout<<0;
  else{
    ll ans=LMAX;
    for(int i=L;i<=R;++i){
      for(int j=i+1;j<=R;++j){
        chmin(ans,i*j%2019);
      }
    }
    out(ans);
  }



  return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
typedef long long int ll;
typedef long double ld;
const ll INF = 1LL << 60;
const int inf = (1 << 30);
const int MOD = 1000000007;
int n, k, ans = 0, h, w, sum = 0;
int main() {
	cin >> n >> k;
	if (n <= k) cout << "unsafe" << endl;
	else cout << "safe" << endl;
}

Measured memory_bytes: 3636
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use proconio::input;
use proconio::marker::Usize1;
use std::collections::*;
use std::cmp::*;
use std::f64::consts::*;

const MOD: u64 = 1000000007;
const INF: usize = std::usize::MAX / 4;

fn main() {
    input! {
        A: usize,
        S: String,
    };

    let B: usize = S.replace(".", "").parse().unwrap();

    println!("{}", A * B / 100);
}


Measured memory_bytes: 2192
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a, b, c, d;
    
    scanf("%d %d", &a, &b);
    c = a * b;
    d = a * 2 + b * 2;
    printf("%d %d\n", c, d);
    
    return 0;
}


Measured memory_bytes: 2104
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
cnt = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        bi = bisect.bisect_left(l, l[i]+l[j])
        cnt += bi-j-1
print(cnt)

Measured memory_bytes: 3188
T=int(input())
ABCD=[list(map(int,input().split())) for i in range(T)]
from fractions import gcd
def f(a):
    print(['No','Yes'][a])
for a,b,c,d in ABCD:
    if a<b:f(0)
    elif d<b:f(0)
    elif b<=c:f(1)
    else:
        g=gcd(b,d)
        h=a%b
        f(max(((b-h)//g*g+h)%b,b-g)<=c)

Measured memory_bytes: 5352
#include <bits/stdc++.h>
using namespace std;
int ans;
void check(int n)
{
	int p;	
	while (n>0)
	{
	p=n%10;
	n/=10;
	if (p==2) ans++;	
	}
}
int main()
{
	int n;
	cin >>n;
	check (n);
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

type runeSort struct {
	s []rune
}

func (r runeSort)Len() int { return len(r.s) }
func (r runeSort)Less(i, j int) bool { return r.s[i] < r.s[j] }
func (r runeSort)Swap(i, j int) { r.s[i], r.s[j] = r.s[j], r.s[i] }

func main() {
	var N int
	fmt.Scanf("%d", &N)
	var str string

	m := make(map[string]int)

	for i := 0; i < N; i++ {
		fmt.Scanf("%s", &str)

		runes := []rune(str)
		sort.Sort(runeSort{runes})
		m[string(runes)]++
	}

	var ans int64
	for _, v := range m {
		ans += pairCount(int64(v))
	}
	fmt.Println(ans)
}


func pairCount(n int64) int64 {
	if n == 1 {
		return 0
	} else {
		return (n-1) + pairCount(n-1)
	}
}

Measured memory_bytes: 12672
# coding: utf-8
line = gets
line.chomp!
/(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ =~ line
x = $1.to_i
y = $2.to_i
z = $3.to_i
k = $4.to_i

line = gets
line.chomp!
arrayX = line.split(" ").map(&:to_i)
arrayX.sort!.reverse!

line = gets
line.chomp!
arrayY = line.split(" ").map(&:to_i)
arrayY.sort!.reverse!

line = gets
line.chomp!
arrayZ = line.split(" ").map(&:to_i)
arrayZ.sort!.reverse!

diffX=[]
for i in 0..x-2 do
  diffX.push(arrayX[i] - arrayX[i+1])
end

diffY=[]
for i in 0..y-2 do
  diffY.push(arrayY[i] - arrayY[i+1])
end

diffZ=[]
for i in 0..z-2 do
  diffZ.push(arrayZ[i] - arrayZ[i+1])
end

max=arrayX[0]+arrayY[0]+arrayZ[0]

stack=[]
stack.push([0,0,0,0])

def insertStack(st, array)
  for i in 0..st.size-1 do
    if (st[i][0] < array[0]) then
      next
    elsif (st[i][0] == array[0]) then
      j = 0
      while (st[i+j][0] == array[0]) do
        if (st[i+j][1] == array[1] and st[i+j][2] == array[2] and st[i+j][3] == array[3]) then
          return st
        end
        j += 1
        if (i+j >= st.size) then
          break
        end
      end
      return st.insert(i+j, array)
    else
      return st.insert(i, array)
    end
  end
  return st.insert(st.size, array)
end

for cnt in 1..k do
  target=stack.shift
  sum=target[0]
  iX=target[1]
  iY=target[2]
  iZ=target[3]

  puts(max-sum)
  
  if (iX +1 < x) then
    stack = insertStack(stack, [sum+diffX[iX], iX+1, iY, iZ])
  end

  if (iY +1 < y) then
    stack = insertStack(stack, [sum+diffY[iY], iX, iY+1, iZ])
  end

  if (iZ +1 < z) then
    stack = insertStack(stack, [sum+diffZ[iZ], iX, iY, iZ+1])
  end
  # print(cnt,", ",stack,"\n")
end


Measured memory_bytes: 2424
//is there any case of -1 or any special corner cases ?
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 
const int maxx  = 2*1e6 , limit = 9*1e18 , MOD=1e9+7;
string binary(int n){bitset<60>b(n) ;string p =b.to_string();return p;}
int decimal(string n) { int dec_value = 0;  int base = 1;  for (int i = n.size() - 1; i >= 0; i--) { if (n[i] == '1') 
dec_value += base; base = base * 2; } return dec_value; } 
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; }
int pow (int x, int n,int mod) {if (n == 0) return 1; int res = pow (x, n / 2,mod);res = (res * res) % mod;if (n % 2) res = (res * x ) % mod;return res;}

#define boost  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n';

int32_t main(){
    
    int n;
    
    cin>>n;
    
    map<int,int>cn;
    // int cn[maxx];
    // memset(cn,0,sizeof(cn));
    // int a[n+1];
    int su = 0;
    for(int i = 0 ;i  <n ; i ++ ){
        int x;
        cin>>x;
        cn[x]++;
        // cin>>a[i];
        su+=x;
    }
    int t;cin>>t;
    for(int i =0 ; i < t ; i ++ ){
        int x,y;
        cin>>x>>y;
        su-=x*cn[x];
        su+=y*cn[x];
        cn[y] += cn[x];
        cn[x]=0;
        cout<<su<<endl;
    }
}


Measured memory_bytes: 9444
n,k = map(int,input().split())

freq = {}
a = [int(i) for i in input().split()]

for i in a:
    if i not in freq:
        freq[i] = 1
    else:
        freq[i] += 1
        
l = sorted(freq.values())
total = 0
index = 0

while len(l) - index > k:
    total += l[index]
    index += 1
print(total)


Measured memory_bytes: 97616
#include<bits/stdc++.h>//万能文件头 

using namespace std;
int a[10][10],k;
int main()
{
    cin>>a[1][1]>>a[1][2]>>a[2][2];//输入3个数，我们用二维数组输入输出，更方便
    k=a[2][2]*3;//我们能发现，中间的数乘3就等于每行中的整数和、每一列中的整数和与每个对角线中的整数和 
	a[1][3]=k-a[1][1]-a[1][2];//右上角 
	a[3][3]=k-a[1][1]-a[2][2];//右下角
	//还需求a[2][1],a[2][3],a[3][1],a[3][2]
	a[2][3]=k-a[1][3]-a[3][3];//第二行第三个
	a[2][1]=k-a[2][2]-a[2][3];//第二行第一个
	a[3][1]=k-a[1][1]-a[2][1];//左下角 
	a[3][2]=k-a[1][2]-a[2][2];//第三行第二个
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		cout<<a[i][j]<<" ";
		cout<<"\n";//记得换行 
	}
    
    return 0;//结束 
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

MY_INF = 10 ** 8
ans = MY_INF
for dst in range(min(a), max(a) + 1):
    ans_tmp = 0
    for i, ai in enumerate(a):
        ans_tmp += abs(dst - ai) ** 2
    #
    ans = min(ans, ans_tmp)

print(ans)

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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX

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

/*
class Node {
public:
  int num;
  int index;
  bool operator<(const Node& b) const {
    if(num < b.num) return (num < b.num);
    else return index > b.index;
  }

  Node(){
    num=0; index=0;
  }
  Node(int n, int i) : num(n), index(i){
  }
};
*/

int main(){

  int h, w;
  cin >>h>>w;
  string s;
  rep(j, h){
    rep(i, w){cin >> s;
    if(s == "snuke") cout << char('A' + i) << j + 1<<endl;
  }
  }

  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << (x) << std::endl
using ll = long long;
template <typename T>
constexpr T INF = std::numeric_limits<T>::max() / 10;
template <typename T>
std::vector<T> slideMaximum(const std::vector<T>& a, const int k)  // 連続するk個の要素の最小値
{
    const int n = a.size();
    assert(n >= k);
    std::deque<T> deq;
    std::vector<T> b(n);
    for (int i = 0; i < n + k - 1; i++) {
        if (i < n) {
            while (not deq.empty() and a[deq.back()] < a[i]) { deq.pop_back(); }
            deq.push_back(i);
        }
        if (i >= k - 1) {
            b[i - k + 1] = a[deq.front()];
            if (deq.front() == i - k + 1) { deq.pop_front(); }
        }
    }
    return b;
}
int main()
{
    int N, M, K;
    std::cin >> N >> M >> K;
    std::vector<ll> A(N);
    for (int i = 0; i < N; i++) { std::cin >> A[i]; }
    std::vector<ll> sl(N + M, 0);
    for (ll i = K; i >= 1; i--) {
        std::vector<ll> tmp(N + M, -INF<ll>);
        for (int j = 0; j < N + i - K; j++) { tmp[j] = sl[j + 1] + A[j] * i; }
        sl = slideMaximum(tmp, M);
    }
    std::cout << slideMaximum(sl, sl.size())[0] << std::endl;
    return 0;
}


Measured memory_bytes: 6544
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 200007;
const int K = 5000;
int dp[N], x[N], f[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt", "r", stdin);
    int n, e, t;
    cin >> n >> e >> t;
    for (int i = 1; i <= n; i++){
        cin >> x[i];
    }
    dp[n] = e - x[n] + t;
    x[n + 1] = e;
    f[n] = x[n + 1] + 2 * x[n] + dp[n + 1];
    int z = 1e15;
    int p = n;
    for (int i = n - 1; i >= 1; i--){
        while((x[p] - x[i]) * 2 >= t){
            z = min(z, f[p]);
            p--;
        }
        dp[i] = x[p + 1] + 2 * x[p] + dp[p + 1] + max(t - 2 * x[p] + 2 * x[i], 0LL);
        dp[i] = min(dp[i], z);
        dp[i] = dp[i] - 3 * x[i];
        f[i] = x[i + 1] + 2 * x[i] + dp[i + 1];
    }
    cout << x[1] + dp[1];
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;

	bool f = true;
	for (int i = 1; i < s.length(); i++) {
		if (s[i] != '9') {
			f = false;
		}
	}
	if (f) {
		cout << (long long)9 * (s.length() - 1) + s[0] - '0' << endl;
	}
	else {
		cout << (long long)9 * (s.length() - 1) + s[0] - '1' << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int dig(int n, int a) {return n/(int)pow(10,a)%10;}
int digl(long n, int a) {return n/(long)pow(10,a)%10;}
int digsum(int n) {int r=0;REP(i,10){r+=dig(n,i);}return r;}
int digsuml(long n) {int r=0;REP(i,19){r+=digl(n,i);}return r;}
int dignum(int n) {return n?to_string(n).length():0;}
int dignuml(long n) {return n?to_string(n).length():0;}

int main(){
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  if (n<=k) {
    cout << x*n;
  } else {
    cout << x*k + (n-k)*y;
  } 
  return 0;
}

Measured memory_bytes: 256
/*input

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 
#define INF 0x3f3f3f3f


int32_t main(){
    IOS;
    int a , b;
    cin >> a >> b;
    if(a * b % 2 == 1) cout << "Yes" << endl;
    else cout << "No" << endl;     
    return 0;
}


Measured memory_bytes: 892
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b;
    
    scanf("%d%d",&a,&b);
    if(a>=13){
        printf("%d",b);
    }else if(a<=5){
        printf("0");
    }else{
        printf("%d",b/2);
    }
}


Measured memory_bytes: 128
n, m = map(int, input().split())
num = ['x'] * n
flag = 0

if n == 1:
    if m == 0:
        print(0)
    else:
        for i in range(m):
            s, c = map(int, input().split())
            if num[s-1] == 'x':
                num[s-1] = c
            else:
                if num[s-1] != c:
                    print(-1)
                    flag = 1
                    break
        if flag == 0:
            print(num[s-1])

else:
    for i in range(m):
        s, c = map(int, input().split())
        if num[s-1] == 'x':
            num[s-1] = c
            if s == 1 and c == 0:
                print(-1)
                flag = 1
                break
                
        else:
            if num[s-1] != c:
                print(-1)
                flag = 1
                break
    if flag == 0:
        if num[0] == 'x':
            num[0] = 1
        for j in range(1, n):
            if num[j] == 'x':
                num[j] = 0 
        str_num = map(str, num)
        print(''.join(str_num))

Measured memory_bytes: 3064
class Main
  def self.run
    rectangles = read_inputs
    puts rectangles.map(&:draw).join("\n")
    puts "\n"
  end

  private

  def self.read_inputs
    rectangles = []
    while true do
      h, w = gets.split(" ").map(&:to_i)
      case [h, w]
        when [0, 0] then break
        else rectangles << Rectangle.new(h, w)
      end
    end
    rectangles
  end
end

class Rectangle
  def initialize(height, width)
    @height, @width = height, width
  end

  def draw
    output = ""
    (1..@height).each {
      output << (1..@width).map{"#"}.join("") << "\n"
    }
    output
  end
end

Main.run

Measured memory_bytes: 8848
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int a, b, k;
    cin >> a >> b >> k;

    ll ans = 0, cnt = 0;
    vector<int> v;
    while(ans <= min(a, b)){
        ans++;
        if(a%ans == 0 && b%ans == 0){
            v.push_back(ans);
            cnt++;
        }
    }

    cout << v[cnt-k] << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt(); 
        
        Set<Integer> set = new HashSet<>();
        set.add(s);
        
        int ans = 1;
        int before = s;
        set.add(before);
        while(true){
            int x = f(before);
            ans++;
            before = x;
            if( set.contains(before) ){
                break;
            }
            set.add(before);
        }
        
        System.out.println(ans);
    }
    
    static int f(int n){
        if( n % 2 == 0 ) return n/2;
        return 3 * n + 1;
    }
}


Measured memory_bytes: 21844
// https://atcoder.jp/contests/dp/tasks/dp_c

#include "algorithm"
#include "iostream"
#include "set"
#include "vector"
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

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

  ll K = 3;

  V<V<ll>> as(N, V<ll>(K));
  rep(i, 0, N) rep(j, 0, K) cin >> as[i][j];

  V<V<ll>> dp(N + 1, V<ll>(K, 0));

  rep(i, 0, N) rep(lastK, 0, K) rep(nextK, 0, K) {
    if (lastK == nextK) continue;

    chmax(dp[i + 1][nextK], dp[i][lastK] + as[i][nextK]);
  }

  ll res = *max_element(dp[N].begin(), dp[N].end());
  cout << res << endl;
}

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

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

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

  return 0;
}
#endif

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

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

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

    cout << v[i];
  }

  cout << endl;
}

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


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

int ans[100010];
int main(){
     int n,q;
     cin >> n >> q;
     string s;
     cin >> s;
     vector<int> v(n);
     v[0]=0;
     for (int i=1;i < n;i++){
          if (s[i]=='C' && s[i-1]=='A') v[i]=v[i-1]+1;
          else v[i] = v[i-1];
     }
     int id=0;
     for (int j=0;j < q;j++){
          int l,r;
          cin >> l >> r;
          ans[id]=v[r-1]-v[l-1];
          id++;
     }
     //for (int h=0;h <= n;h++) cout << v[h];
     //cout << endl; 
     for (int i=0;i < q;i++){
          cout << ans[i] << endl;
     }
     return 0;
    
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>

int main(void){
	int n;
	scanf("%d",&n);
	long long int *a;
	long long int ans=1;
	a=(long long int *)malloc(n*sizeof(long long int));
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		if(a[i]==0){
			printf("0");
			return 0;
		}
	}
	for(int i=0;i<n;i++){
		if(ans!=0&&1000000000000000000/ans<a[i]){
			printf("-1");
			return 0;
		}else{
			ans*=a[i];
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 2512
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

void solve() {
	int n, x;
	while (cin >> n >> x, n) {
		int ans = 0;
		rep1(i, n) {
			Rep1(j, i + 1, n) {
				Rep1(k, j + 1, n) {
					if (i + j + k == x)ans++;
				}
			}
		}
		cout << ans << endl;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}



Measured memory_bytes: 3172
bi = 10

while True:

    H = int(input())
    if H == 0:
        break

    a = []

    for i in range(H):

        A = list(input().split())
        a.append(A)

    ans = 0
    rep = True
    while rep:

        b = [[False] * 5 for i in range(H)]
        
        rep = False

        for i in range(H):
            for j in range(5):

       

                if j - 2 >= 0 and a[i][j-2] == a[i][j-1] and a[i][j-1] == a[i][j]:
                    b[i][j] = True
                if j - 1 >= 0 and j + 1 < 5 and a[i][j-1] == a[i][j] and a[i][j+1] == a[i][j]:
                    b[i][j] = True
                if j + 2 < 5  and a[i][j+2] == a[i][j+1] and a[i][j+1] == a[i][j]:
                    b[i][j] = True

        for i in range(H):
            for j in range(5):
                if b[i][j]:
                    rep = True
                    #print (a[i][j])
                    ans += int(a[i][j])
                    a[i][j] = bi
                    bi += 0.1
        rep2 = True
        while rep2:
            rep2 = False
            
            for i in range(H-1):
                i = H-2-i
                for j in range(5):

                    if int(a[i][j]) <= 9 and int(a[i+1][j]) > 9:
                        a[i+1][j] = a[i][j]
                        a[i][j] = bi
                        bi += 0.1
                        rep2 = True
    #print (a)
    print (ans)              
                  




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

#define i64 long long int
#define ran 202202

int n;
i64 k;
int nxt[ran];
int step[ran];

int main() {
	scanf("%d%lld", &n, &k);
	for(int i=1;i<=n;i++) scanf("%d", &nxt[i]);
	
	memset(step, -1, sizeof step);
	int cur = 1;
	step[1] = 0;
	for(int i=1;i<=k;i++) {
		cur = nxt[cur];
		if(step[cur] >= 0) {
			int cycle = i - step[cur];
			i64 cnt = (k-i) / cycle;
			k-=cnt*cycle;
		}
		step[cur] = i;
	}
	printf("%d\n", cur);
	
	return 0;
}

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

using namespace std;

#define TC ll t; cin >> t; while(t--)
typedef long long ll;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    double l; cin >> l;
    l/=3.0; printf("%lf\n",l*l*l);
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define tag "spoj"
#define maxn 100007
#define maxc 0
#define maxlog 17
#define oo 1000000007
#define mid ((l+r)>>1)
#define meset(a,x) memset(a,x,sizeof(a))
#define loop(x) for(int LoOpEr=1;LoOpEr<=x;LoOpEr++)
///>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

#define MOD 1000000007LL

/// tổ hợp:
long long fct[maxn],inv[maxn],ivf[maxn];

void bornfact()
{
    fct[0] = ivf[0] = 1;
    fct[1] = ivf[1] = inv[1] = 1;
    for (int i=2;i<maxn; i++)
    {
        fct[i] = fct[i - 1] * i % MOD;
        inv[i] = MOD - MOD / i * inv[MOD % i] % MOD;
        ivf[i] = ivf[i - 1] * inv[i] % MOD;
    }
}

long long A(const int &n,const int &k)
{
    return (n<k)?0:fct[n] % MOD * ivf[n - k] % MOD;
}

long long C(const int &n,const int &k)
{
    return (n<k)?0:fct[n] % MOD * ivf[k] % MOD * ivf[n - k] % MOD;
}

long long P(const int &n)
{
    return fct[n];
}

///
int n,k;
long long ans=0;
vector<vector<int>> adj;
#define add_edge(u,v) adj[u].push_back(v),adj[v].push_back(u)

void dfs(const int& u,const int& parent)
{

    ans=ans*A(k-1-(u!=1),adj[u].size()-(u!=1))%MOD;

    for(const int& v: adj[u])
        if(parent!=v)
            dfs(v,u);
}
int main()
{
    #ifdef dmdd
    freopen(tag".inp","r",stdin); freopen(tag".out","w",stdout);
    #endif // dmdd
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    bornfact();

    cin>>n>>k;

    adj.resize(n+1);

    int x,y;
    loop(n-1) cin>>x>>y,add_edge(x,y);

    ans=k;

    dfs(1,0);

    cout<<ans;

    return 0;
}


Measured memory_bytes: 11648
n = input()
ryokan_height_list = list(map(int, input().split()))

c = 0
for i, target in enumerate(ryokan_height_list):
  impediments = [impediment for impediment in ryokan_height_list[:i] if impediment > target]
  if len(impediments) == 0:
     c += 1

print(c)

Measured memory_bytes: 2940
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int a, b; cin >> a >> b;
    if(a <= 0 && 0 <= b) {
        cout << "Zero" << endl;
        return;
    }
    if(a > 0) {
        cout << "Positive" << endl;
        return;
    }
    int cnt = min(0, b) - a + 1;
    if(cnt & 1) {
        cout << "Negative" << endl;
    } else {
        cout << "Positive" << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

int k,f,a;
int main(){
    cin>>k;
    f=k/100;
    a=k%100;
    if ((f>12&&a>12)||(f==0&&(a>12||a==0))||(a==0&&(f>12||f==0))) {
        cout<<"NA"<<endl;
    }else if ((a<=12&&f>12)||(f==0)){
        cout<<"YYMM"<<endl;
    }else if((f<=12&&a>12)||(a==0)){
        cout<<"MMYY"<<endl;
    }else if (f<=12&&a<=12){
        cout<<"AMBIGUOUS"<<endl;
    

    }
}

Measured memory_bytes: 256
import math
n = int(input())
csf = [list(map(int,input().split())) for i in range(n-1)]

for i in range(n-1): # i = 0,1,2,...,n-1
    c,s,f = csf[i]
    s += c
    #print("i=",i)
    for j in range(i+1,n-1): # j = i+1,i+2,...,n-1
        c1,s1,f1 = csf[j]
        s = ((math.ceil((s-s1)/f1))*f1 if s >= s1 else 0)+s1+c1
        #print("j=",j,"s=",s)
    print(s)
print(0)

Measured memory_bytes: 3188
import sys
input = sys.stdin.readline

X,N=(int(x) for x in input().rstrip('\n').split())
ps=[int(x) for x in input().rstrip('\n').split()]
if N==0:
  print(X)
else:
  for i in range(100):
    if X-i not in ps:
      print(X-i)
      break
    elif X+i not in ps:
      print(X+i)
      break

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

typedef vector<int> vi ;
typedef pair<int,int> ii ;
typedef pair<ii,int> ill;
typedef tuple<int,int,int> tt;
const int maxN = 50;
const int INF = 1e18;

vector<tt> Adj[maxN];
int d[55][5005];
int n, m, s;

void dijkstra ( int s)
{

    priority_queue<tt,vector<tt>,greater<tt> > pq;
    for(int i = 1; i< 51 ; i++)
        {
            fill(d[i] ,d[i] + 5005,INF);
        }
    pq.push({0,1,s});
    int u, cur, du;
    d[1][s] = 0 ;
    while ( !pq.empty() )
    {
        tt x = pq.top();
        pq.pop();

        tie(du, u, cur) = x;
        if ( du != d[u][cur] )
            continue;

        for( auto i : Adj[u])
        {
            int v, a, b, t;
            tie(v,a,b) = i ;

            t = cur - a ;
            if ( t < 0 ) continue;
            if ( t > 5000) continue;
            if ( du + b < d[v][t] )
            {
                d[v][t] = du + b;
                pq.push({d[v][t],v,t});
            }
        }
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> s;
    if ( s >= 5000) s= 5000;
    for(int i = 1; i<= m ; i++)
    {
        int u, v, a, b ;
        cin >> u >> v >>  a >> b;
        Adj[u].push_back({v,a,b});
        Adj[v].push_back({u,a,b});
    }

    for(int i = 1 ; i<= n; i++)
    {
        int c, d;
        cin >> c >> d;
        Adj[i].push_back({i,-c,d});
    }
    dijkstra( s );
    int ans = INF;
    for(int i= 2; i<= n; i++)
    {
        ans = INF;
        for(int j = 0 ; j<= 5000; j++)
            ans = min(ans,d[i][j]);
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 11356
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN=110000;
const int INF=0X3F3F3F3F;
int a[MAXN];
int main()
{
//	freopen("D.in", "r", stdin);
//	freopen("D.out", "w", stdout);
	int n, t;
	scanf("%d%d", &n, &t);
	for (int i=1; i<=n; i++) scanf("%d", &a[i]);
	int mx=0, ans=0;
	for (int i=1, mi=INF; i<=n; i++)
	{
		mi=min(mi, a[i]);
		if (a[i]-mi>mx) mx=a[i]-mi, ans=0;
		if (a[i]-mi==mx) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512