akhauriyash/Code-Regression huggingface dataset:
from bisect import bisect_left as bl

N = int(input())
L = list(map(int,input().split()))
L = sorted(L)

p = L[-1]
q = bl(L,p/2)
if N == 2 :
    r = L[0]
else :
    if abs((p/2)-L[q]) < abs((p/2)-L[q-1]) :
        r = L[q]
    else :
        r = L[q-1]
print(p,r)

###計算時間考察
from math import factorial as f


Measured memory_bytes: 14428
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z;
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[1000010],cnt;
int main()
{
	long long n;
	scanf("%lld",&n);
	while(n){
		a[++cnt]=n%26;
        n/=26;
        if(!a[cnt])a[cnt]=26,n--;
	}
	for(int i=cnt;i>=1;i--)
	printf("%c",a[i]+'a'-1);
	return 0;
}

Measured memory_bytes: 3684
def m(L,R):
 T=[]
 for l in L[::-1]:
  while R and R[-1]>l:T+=[R.pop()]
  T+=[l]
 return R+T[::-1]
def d(A):
 l=len(A);global c;c+=l
 s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A
if'__main__'==__name__:
 c=-int(input())
 print(*d(list(map(int,input().split()))))
 print(c)


Measured memory_bytes: 63688
#include<stdio.h>

int main(){
  int N,SN=0;
  int i,work;
  scanf("%d", &N);
  work = N;
  for(i=0;work!=0;i++){
    SN +=work % 10;
    work = work /10;
  }
  if(N % SN == 0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll ans=0LL;
	cin >>n;
	V a(n);
	rep(i,n){
		cin>>a[i];
	}
	rep(i,n){
		while(a[i]%2==0){
			ans++;
			a[i]/=2;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


class Main{
	public static void main(String[] args) {
		FastReader f = new FastReader();
		int n = ii(f);
		int[][] arr = new int[n+1][3];
		for(int i=1; i<=n; i++){
			for(int j=0; j<3; j++)
				arr[i][j] = ii(f);
		}
		int[][] dp = new int[n+1][3];
		dp[1][0] = arr[1][0];
		dp[1][1] = arr[1][1];
		dp[1][2] = arr[1][2];
		for(int i=2; i<=n; i++){
			dp[i][0] = max(dp[i-1][1] + arr[i][0], dp[i-1][2] + arr[i][0]);
			dp[i][1] = max(dp[i-1][0] + arr[i][1], dp[i-1][2] + arr[i][1]);
			dp[i][2] = max(dp[i-1][0] + arr[i][2], dp[i-1][1] + arr[i][2]);
		}
		System.out.println(max(dp[n][0], dp[n][1], dp[n][2]));
	}


	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static int ii(FastReader fr){
		return fr.nextInt();
	}

	static long il(FastReader fr){
		return fr.nextLong();
	}

	static double id(FastReader fr){
		return fr.nextDouble();
	}

	static void printArray(Object[] arr) {
		for (Object x : arr)
			print(x, " ");
		printn("");
	}

	static void print(Object s, String sep) {
		System.out.print(s + sep);
	}

	static void printn(Object s) {
		System.out.println(s);
	}

	static long[] inputArrL(int n, FastReader fr) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++)
			arr[i] = fr.nextLong();
		return arr;
	}

	static int[] inputArr(int n, FastReader fr) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
			arr[i] = fr.nextInt();
		return arr;
	}

	static int max(int... args) {
		int max = Integer.MIN_VALUE;
		for (int x : args) {
			max = Math.max(x, max);
		}
		return max;
	}

	static int min(int... args) {
		int min = Integer.MAX_VALUE;
		for (int x : args) {
			min = Math.min(x, min);
		}
		return min;
	}

	static long max(long... args) {
		long max = Integer.MIN_VALUE;
		for (long x : args) {
			max = Math.max(x, max);
		}
		return max;
	}

	static long min(long... args) {
		long min = Integer.MAX_VALUE;
		for (long x : args) {
			min = Math.min(x, min);
		}
		return min;
	}

	static int lenDigit(int d) {
		if (d == 0)
			return 1;
		int l = 0;
		while (d != 0) {
			l++;
			d /= 10;
		}
		return l;
	}

}



Measured memory_bytes: 50032
using System;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int m = sc.NextInt();

        Console.WriteLine((n - 1) * (m - 1));
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

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

int main(void){
    string S;
    cin >> S;
    vector<char> Trans(S.size());
    if (S[0] == '0'){
        for(int i = 0;i < S.size(); i++){
            Trans[i] = i % 2 == 0 ? '0' : '1';
        }
    }else{
        for(int i = 0;i < S.size(); i++){
            Trans[i] = i % 2 == 0 ? '1' : '0';
        }
    }
    long long count = 0;
    for(int i = 0;i < S.size();i++){
        if(S[i] != Trans[i]){
            count++;
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>

#define M 1000033/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h(int key,int i){ return (h1(key) + i*h2(key))%M/* your task */; }
int h1(int key){ return key%M/* your task */; }
int h2(int key){ return 1+key%(M - 1)/* your task */; }

int find(char str[]){
  int i=0,k=getKey(str),m=h(k,i);

  while(H[m][0] != '\0'){
   
    if(strcmp(str, H[m])==0){
  
  return 1;
    }
    i++;
    m=h(k,i);
  }
 return 0;
                 /* your task */

}

int insert(char str[]){

  int i=0,k=getKey(str),m;
  while(1){
    m=h(k,i);
    if( H[m][0] == '\0'){
      strcpy(H[m],str);
      return 7;
    }
    i++;
  }

/* your task */
  
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
      scanf("%s %s", com, str);
      
	if ( com[0] == 'i' ){
	  insert(str);
	} else {
	  if (find(str)){
	    printf("yes\n");
	  } else {
	    printf("no\n");
	  }
	}
    }
    
    return 0;
}

Measured memory_bytes: 14280
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string.h>

using namespace std;

int main() {
    int n;
    cin>>n;
    int tmp;
    vector<int> a(n,0);
    for(int i=0;i<n;i++){
        cin>>tmp;
        if(tmp == i+1) a.at(i) = 1;
    }

    int cnt = 0;
    for(int i = 0;i<n-1;i++){
        if(a.at(i) == 1){
           cnt ++;
           a.at(i) = 0;
           a.at(i+1) = 0;
        }
    }

    if(a.at(n-1)==1) cnt++;
    cout<<cnt<<endl;

}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    ll a,b;
    cin >> a >> b;
    if((a+b)%2){
        cout << "IMPOSSIBLE";
    }else{
        cout << (a+b)/2;
    }
}

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

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            long ac  = 0;
            long wa  = 0;
            long tle = 0;
            long re = 0;
            for (int i = 0; i < n; i++)
            {
                // 文字列の入力
                string s = Console.ReadLine();
                if (s == "AC")
                {
                    ac++;
                }
                else if (s == "WA")
                {
                    wa++;
                }
                else if (s == "TLE")
                {
                    tle++;
                }
                else if (s == "RE")
                {
                    re++;
                }
            }

            Console.WriteLine("AC x " + ac.ToString());
            Console.WriteLine("WA x " + wa.ToString());
            Console.WriteLine("TLE x " + tle.ToString());
            Console.WriteLine("RE x " + re.ToString());

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 30688
n = int(input())
d = list(map(int,input().split()))
m = int(input())
t = list(map(int,input().split()))
d.sort()
t.sort()
j = 0
for i in range(n):
    if d[i] == t[j]:
        j += 1
    if j == m:
        break

if j == m:
    print('YES')
else:
    print('NO')

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

using namespace std;

int main(){
    int n;
    cin >>n;
    vector<int>a(n, 0);
    for(int i = 1;i < n;i++){
        int x;cin >> x;
        x--;
        a[x]++;
    }
    for(int i = 0;i < n;i++){
        cout<< a[i] << endl;
    }
}



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

int N;
string S;
typedef long long ll;
vector<vector<ll>> vec(2,vector<ll>(64,1));
int i=3, ans = 0, ref,K[4] = {0,16,32,48},L,rev;

ll modu(ll n){
  return n % 1000000007;
}

int main() {
  cin >> N;
  while(i < N) {
    for(int j = 0; j < 64;j++) {
      if(j == 6 || j == 9 || j == 33){
	    vec.at(i&1).at(j) = 0;
      }
	}
    i++;
	rev = (i&1)^1;
	
    for(int j = 0; j < 64;j++) {
      vec.at(i&1).at(j) = 0;
	  if(j == 6 || j == 9 || j == 33){
	    vec.at(i&1).at(j) = 0;
		continue;
	  }
	  ref = j / 4;
	  for(int k = 0;k < 4; k++) {
	    L = K[k] + ref;
		if(j == 41 && k == 0) continue;
		if(j == 45 && k == 0) continue;
		if(j == 57 && k == 0) continue;
        if(j == 25 && k == 0) continue;
		vec.at(i&1).at(j) += vec.at(rev).at(L);
	  }
	  vec.at(i&1).at(j) = modu(vec.at(i&1).at(j));
	}
  }
  
  for(int j = 0; j < 64;j++) {
	if(j == 6 || j == 9 || j == 33){
	  vec.at(i&1).at(j) = 0;
	}
	ans += vec.at(i&1).at(j);
	ans = modu(ans);
    //cout << vec.at(i&1).at(j) << ' ';
  }
  
  cout << ans << endl;
}

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

int main(){
  int X,A,B;
  cin>>X>>A>>B;
  if(A>=B)
    cout<<"delicious"<<endl;
  else if(A+X>=B)
    cout<<"safe"<<endl;
  else
    cout<<"dangerous"<<endl;
    
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<cmath>
#include<string>
#include<vector>
#include<cstring>
#define ll long long
#define pb push_back
// #define memset(a,n) memset(a,n,sizeof(a))
#define mp make_pair
using namespace std;
const int maxn = 2e5 + 100;

void FAST()
{
    ios::sync_with_stdio(0);cin.tie(0);
}



int main()
{
    FAST();
    int n;scanf("%d",&n);
    printf("%.6f\n",3.1415926 * 2 * n);
    // system("pause"); // 测试专用，提交勿忘注释掉
    return 0;
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
ll dp[101][100001];
int main(){
	int N,W;
	cin>>N>>W;
	rep(i,N+1) rep(j,W+1) dp[i][j] = -1;
	dp[0][0] = 0;

	rep(i,N){
		int w,v;
		cin>>w>>v;
		rep(j,W+1) if(dp[i][j] != -1){
			chmax(dp[i+1][j],dp[i][j]);
			if(j+w<=W) chmax(dp[i+1][j+w],dp[i][j]+v);
		}
	}
	ll ans = 0;
	rep(j,W+1) chmax(ans,dp[N][j]);
	cout<<ans<<endl;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

int main() { _
    int a, b, c, x;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;
    int count = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if ((500*i) + (100*j) + (50*k) == x) count ++;
            }
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#!usr/bim/python
#! -*- coding: utf-8 -*-

n = raw_input()
n = int(n)

s = []
for i in range(n):
    score = raw_input()
    score = int(score)
    s.append(score)

s = sorted(s)

score = 0
if sum(s) % 10 == 0:
    for i in range(n):
        if s[i] % 10 == 0:
            pass
        else:
            score = sum(s) - s[i]
            break
else:
    score = sum(s)

print score


Measured memory_bytes: 2568
#include <iostream>
#include <vector> 
#include <algorithm>

using namespace std;

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

  // **
  // It's easier to think about all 1000 combinations of the 3 digit passcode 
  int size = 0;
  for (int i = 0; i < 1000; i++) {
    int h = i / 100;
    int t = i / 10 - h * 10;
    int o = i - (i / 10 * 10);
    string::iterator curr = S.begin();
    while (curr != S.end()) {
      ++curr;
      if (*(curr-1) == h + '0') break;
    }
    while (curr != S.end()) {
      ++curr;
      if (*(curr-1) == t + '0') break;
    }
    while (curr != S.end()) {
      ++curr;
      if (*(curr-1) == o + '0') {
        size++;
        break;
      }
    }
  }

  cout << size << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

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

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n, n) {
        vector<P> anime(n);
        REP(i, 0, n) {
            string s;
            cin >> s;
            int w, d;
            cin >> w >> d;
            int t = w * 24 * 60 + d / 100 * 60 + d % 100;
            anime[i] = {t, s};
        }
        const int size = 24 * 60 * 7;

        int m;
        cin >> m;
        vector<int> used(size, 0);
        {
            REP(i, 0, m) {
                string s;
                cin >> s;
                for (auto it = anime.begin(); it != anime.end(); it++) {
                    if ((*it).second == s) {
                        REP(j, 0, 30) {
                            used[((*it).first + j) % size]++;
                        }
                        anime.erase(it);
                        break;
                    }
                }
            }
            bool check = true;
            REP(i, 0, size) {
                if (used[i] > 1) {
                    check = false;
                }
            }
            if (!check) {
                cout << -1 << endl;
                continue;
            }
        }
        sort(anime.begin(), anime.end());

        int ans = m;
        for (auto &A : anime) {
            bool check = true;
            REP(j, 0, 30) {
                if (used[(A.first + j) % size] != 0) {
                    check = false;
                }
            }
            if (check) {
                REP(j, 0, 30) {
                    used[(A.first + j) % size]++;
                }
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3184
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define mod  1000000007
#define ll long long
using namespace std;

int main()
{
	char a[60],b[60];
	int i,j;
	ll sum;
	int n;
	cin>>n;
	cin>>a;
	cin>>b;
	i=0;j=0;
	if(a[0]==b[0])
	{
		sum=3;
		i++;
		j++;
	}
	else
	{
		sum=6;
		i+=2;
		j+=2;
	}
//	cout<<i<<' '<<j<<' '<<sum<<endl;
	while(i<n&&j<n)
	{
		if(a[i]==b[j])
		{
			if(a[i-1]==b[j-1])
			{
				sum=(sum*2)%mod;
			}
			i++;
			j++;
		}
		else
		{
			if(a[i-1]==b[j-1])
			{
				sum=(sum*2)%mod;
			} 
			else
			{
				sum=(sum*3)%mod;
			}
			i+=2;
			j+=2;
		}
		
	}
	cout<<sum<<endl;
	return 0;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
int n,m;
vector<vector<int>> A_list;
void gen_A(int pos,vector<int> A){
    if(pos>m){
        return;
    }
    A.pb(pos);
    if(A.size()==n+1){
        A_list.pb(A);
        return;
    }
    rep(i,m-pos+1){
        gen_A(pos + i, A);
    }
    return;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int q;
cin>>n>>m>>q;
vector<int> A;
gen_A(1, A);

vector<int> a(q),b(q),c(q),d(q);
rep(i,q)cin>>a[i]>>b[i]>>c[i]>>d[i];
ll max_val=0;
for(auto _A:A_list){
    ll total=0;
    rep(i,q){
        if(_A[b[i]]-_A[a[i]]==c[i]){
            total+=d[i];
        }
    }
    chmax(max_val, total);
}
cout << max_val << endl;
return 0;
}

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

LL n,m;

char s[maxn],t[maxn];

void init()
{
	scanf("%lld%lld",&n,&m);
	scanf("%s%s",s,t);
}

LL gcd(LL a,LL b)
{
	return !b?a:gcd(b,a%b);
}

bool solve()
{
	for (LL i=0;i<n;++i)
	{
		if (i*m%n)	continue;
		if (s[i]!=t[i*m/n])	return 0;
	}
	printf("%lld\n",n*m/gcd(n,m));
	return 1;
}

int main()
{
//	freopen("c.in","r",stdin);
	init();
	if (!solve())
		puts("-1");
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void) {
 int x = 0, tmp = 0;
 int N;
 scanf("%d", &N);
 char S[N];
 scanf("%s", S);
 for(int i=0; i<N; i++) {
  if(S[i] == 'I') {
   x++;
   if(x>tmp) tmp = x;
  }
  else {
   x--;
   if(x>tmp) tmp = x;
  }
 }
 printf("%d\n", tmp);
 return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long xo(long long t){
    int s = t%4;
    if(s==0){
        return t;
    }else if(s==1){
        return 1;
    }else if(s==2){
        return t+1;
    }else{
        return 0;
    }
}
int main(){
    long long a,b;
    cin>>a>>b;
    if(a==b) {
        cout<<a;
        return 0;
    }
    if(a==0){
        cout<<xo(b)<<endl;
    }else{
        long long aa = xo(a-1);
        long long bb = xo(b);
        cout<<(bb^aa)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//		String W	 = in.readLine();
//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		String ans ="";

		for(int i = 0;i<N; i++) {
			ans += S.charAt(i);
			ans += T.charAt(i);
		}




		System.out.println(ans);

	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}



}


Measured memory_bytes: 39444
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: u128,
    }

    let mut ans = 0;

    for i in 1..=n {
        if !(i % 5 == 0 || i % 3 == 0) {
            ans += i;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2140
using System;

namespace AOJ {
    class ALDS1_1_A {
        static void InsertionSort(int[] A, int n) {
            for(int i=0; i<n; i++) {
                int v = A[i];
                int j = i - 1;
                while (j >= 0 && A[j] > v) {
                    A[j + 1] = A[j];
                    j--;
                }
                A[j + 1] = v;
                PrintLine(A, n);
            }
        }
        static void PrintLine(int[] A, int n) {
           for(int i = 0; i < n; i++) {
                Console.Write(A[i]);
                if (i != n - 1) Console.Write(" ");
           }
            Console.WriteLine();
        }
        static void Main(string[] args) {
            int n;
            n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split();
            int[] A = new int[n];
            for(int i=0; i<n; i++){
                A[i] = int.Parse(input[i]);
            }
            InsertionSort(A, n);
        }
    }
}



Measured memory_bytes: 17900
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = 0;
            while(true)
            {
                ans = 0;
                //??????????????????
                var read = Console.ReadLine();
                //var temp_string = read.Split(' ');

                if(read=="0")
                {
                    break;
                }

                //???????????£????????????char?????????????§£
                var read_arry = read.ToCharArray();


                //char?????????1?????????????????????
                foreach(char c in read_arry)
                {
                    ans += int.Parse(c.ToString());
                }

                //??¨???
                Console.WriteLine(ans);
            }
            
        }
    }
}

Measured memory_bytes: 9248
import           Control.Monad
import           Text.Printf

getLines :: Int -> IO [String]
getLines n = replicateM n getLine

getLinesInt :: Int -> IO [Int]
getLinesInt n = fmap read <$> getLines n

getInts :: IO [Int]
getInts = map (read :: String -> Int) . words <$> getLine

getDoubles :: IO [Double]
getDoubles = map (read :: String -> Double) . words <$> getLine

splitOn :: (Char -> Bool) -> String -> [String]
splitOn p s = case dropWhile p s of
    "" -> []
    s' -> w : splitOn p s'' where (w, s'') = break p s'

toInt :: [String] -> [Int]
toInt = map ((read :: String -> Int) . dropZero)

dropZero :: String -> String
dropZero s = if head s == '0' then drop 1 s else s

main :: IO ()
main = do
    [n, s] <- getLines 2
    putStrLn $ let r = foldl (\t c -> t + if c == 'R' then 1 else 0) 0 s in
        if r > (read :: String -> Int) n - r
            then "Yes"
            else "No"


Measured memory_bytes: 508
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main (){
    int n,k;
    cin >>n >> k;
    int x[n];
    int ans = 0;
    rep(i,n){
        cin >> x[i];
        ans += min(k-x[i],x[i]);
    }
    cout << ans *2 << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
arr = [i for i in input().split()]
c = [Counter([i for (a,i) in enumerate(arr) if a%2==j]) for j in range(2)]
if c[0].most_common()[0][0]!=c[1].most_common()[0][0] :
    print(n-c[0].most_common()[0][1]-c[1].most_common()[0][1])
else :
    if(len(c[0].most_common())==1):
        co0 = 0
    else:
        co0 = c[0].most_common()[1][1]
    if(len(c[0].most_common())==1):
        co1 = 0;
    else :
        co1 = c[1].most_common()[1][1]
    print(min(n-c[0].most_common()[0][1]-co1,n-co0-c[1].most_common()[0][1]))


Measured memory_bytes: 19896
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define MOD 10007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=10007;
const int INF=1e9;
int dp[1000][1<<3];
string JOI="JOI";
int main(){
      int n;
      string s;
      cin>>n;
      cin>>s;
      REP(i,n){
            int p;
            REP(j,3)if(s[i]==JOI[j])p=j;
            if(i==0){
                  REP(j,1<<3){
                        if(j&1&&j>>p&1)dp[0][j]=1;
                  }
            }else{
                  REP(j,1<<3){
                        if(j>>p&1){
                              REP(k,1<<3){
                                    bool f=false;
                                    REP(l,3){
                                          if(j>>l&1&&k>>l&1)f=true;
                                    }
                                    if(f)dp[i][j]=(dp[i][j]+dp[i-1][k])%MOD;
                              }
                        }
                  }
            }
      }
      int ans=0;
      REP(i,1<<3){
            ans+=dp[n-1][i];
      }
      cout<<ans%MOD<<endl;
}

Measured memory_bytes: 1248
n, k = map(int, input().split())
x = list(map(int, input().split()))
 
ans = []
 
for _ in range(n - k + 1):
    ans.append(abs(x[k + _ - 1]) + abs(x[k + _ - 1] - x[_]))
    ans.append(abs(x[_]) + abs(x[_] - x[k + _ - 1]))
    
 
print(min(ans))

Measured memory_bytes: 84636
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end() 
ll mod_pow(ll x,ll n,ll mod) {
ll res=1;
  while(n>0) {
     if(n&1) {
       res=res*x%mod;
     }
     x=x*x%mod;
     n>>=1;
   }
   return res;
}
int main() {
  ll mod=1000000007;
  ll n,a,b;
  cin>>n>>a>>b;
  ll A=1;
  ll B=1;
  for(ll i=0;i<a;i++) {
    A*=(n-i);
    A%=mod;
  }
  for(ll i=0;i<b;i++) {
    B*=(n-i);
    B%=mod;
  }
  for(ll i=2;i<=a;i++) {
    A*=mod_pow(i,mod-2,mod);
    A%=mod;
  }
  for(ll i=2;i<=b;i++) {
    B*=mod_pow(i,mod-2,mod);
    B%=mod;
  }
  ll ans=mod_pow(2,n,mod);
  ans--;
  ans-=(A+B);
  if(ans<0) {
    while(ans<0) {
      ans+=mod;
    }
  } 
  cout<<ans<<endl;
}

Measured memory_bytes: 3640
#include <stdio.h>
int main()
{
	int n,d;
	while(~scanf("%d %d",&n,&d))
	{
		if(n%(2*d+1)!=0)
		{
			printf("%d",n/(2*d+1) + 1);
		}
		else
		{
			printf("%d",n/(2*d+1));
		}
		printf("\n");
	}
}

Measured memory_bytes: 1728
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
A, B, C = ri_()
print('Yes' if C <= A + B else 'No')

Measured memory_bytes: 62956
<?php

$line = fgets(STDIN);
$tmp = explode(" ", $line);

$result = (int)$tmp[0] * (int)$tmp[1];


if ($result % 2 === 0) {
	echo "Even\n";
} elseif ($result % 2 === 1) {
	echo "Odd\n";
}

Measured memory_bytes: 4604
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>

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

int div(int x)
{
    int cnt = 0;
    while (1)
    {
        if (x % 2 == 1)
            return cnt;
        cnt++;
        x /= 2;
    }
}

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

    vi a(n);
    rep(i, 0, n) cin >> a[i];

    int ans = INF;
    rep(i, 0, n)
    {
        ans = min(ans, div(a[i]));
    }
    cout << ans << endl;
}


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

int main(){
	int a, b, c;
	while(cin >> a >> b >> c){
		bool f = false;
		if(a == b){
			if(a != c) 
				f = true;
		}
		else if(b == c){
			if(a != b) 
				f = true;			
		}

		else if(a == c) {
			if(a != b) 
				f = true;			
		}

		if(f) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long int a,b,c,k,a1,b1=0,c1=0,ans;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
     if(k==a)
     {
         ans=a;
         printf("%lld\n",ans);
     }


     else if(k<a)
     {
         ans=k;

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

     else if(k>a)
     {
         a1=a;
         if((k-a)>=b)
         {
             b1=b;
         }
         else
         {
             b1=k-a;
         }
         if((k-a-b)>=0)
         {
             c1=k-a-b;
         }

         ans=(a1+(b1*0)+(c1*-1));
         printf("%lld\n",ans);
     }
     return 0;

}


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

int n, m, l[10], r[10];
char s[10][10];

inline void end() {
	printf("Impossible\n");
	exit(0);
}

int main() {
	cin >> n >> m;
	r[0] = 1;
	for(int i = 1; i <= n; i++) {
		scanf("%s", s[i]+1);
		for(int j = 1; j <= m; j++) {
			if(s[i][j] == '#' && s[i][j-1] != '#') {
				if(l[i]) end();
				l[i] = j;
			}
			if(s[i][j] != '#' && s[i][j-1] == '#') {
				if(r[i]) end();
				r[i] = j-1;
			}
		}
		if(!r[i]) r[i] = m;
		//printf("%d %d\n", l[i], r[i]);
		if(l[i] != r[i-1]) end();
	}
	printf("Possible\n");
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, k, q int
	fmt.Scan(&n, &k, &q)

	pt := make([]int, n)
	for i := 0; i < q; i++ {
		var a int
		fmt.Scan(&a)
		pt[a-1] += 1
	}

	b := q - k
	for i := 0; i < n; i++ {
		if pt[i] > b {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


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

struct UnionFind{
    vector<int> r;
    UnionFind(int N){
        r = vector<int>(N, -1);
    }

    int root(int x){
        if(r[x] < 0){
            return x;
        }
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y){
        x = root(x);
        y = root(y);
        
        if(x == y){
            return false; 
        }

        if(r[x] > r[y]){
            swap(x, y);
        }

        r[x] += r[y];
        r[y] = x;

        return true;
    }
};

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

    vector<int> p(N);
    for(int i=0; i<N; i++){
        cin>>p[i];
        p[i]--;
    }

    UnionFind uni(N);
    for(int i=0; i<M; i++){
        int x, y;
        cin>> x >> y;
        x--; y --;
        uni.unite(x, y);
    }
 
    int ans = 0;

    for(int i=0; i<N; i++){
        if(uni.root(i) == uni.root(p[i])){
            ans++;
        }
    }

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

Measured memory_bytes: 4040
#include <bits/stdc++.h>
#define int long long
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
#define NIL -1
using ll = long long;
const ll MOD = 1000000007;
#define REP(i,n) for (ll i=0; i < (n); ++i)
#define FOR(i,a,b) for (ll i=(a); i < (b); ++i)
using namespace std;

int get_gcd(int a, int b){while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;

  unordered_map<string, bool> memo_is_ok;
  auto is_ok = [&](const string& str){
    const auto itr = memo_is_ok.find(str);
    if (itr != memo_is_ok.end()) return itr->se;

    REP(i,4) {
      string s = str;
      if (i > 0) swap(s[i],s[i-1]);
      REP(j,2) {
        if(s.substr(j,3) == "AGC") {
          memo_is_ok.insert(make_pair(str, false));
          return false;
        }
      }
    }

    memo_is_ok.insert(make_pair(str, true));
    return true;
  };



  // i文字で、最後の3文字がsであるの時の条件を満たす文字列数
  vector<unordered_map<string, int>> dp(n+1);
  const string nexts = "ACGT";
  dp[0]["TTT"] = 1;
  for(int i=0; i<n; i++){
    for (const auto& prev: dp[i]) {
      REP(j,4) {
        const string str = prev.fi + nexts[j];
        if (is_ok(str)) {
          const string substr = str.substr(1,3);
          const auto itr = dp[i+1].find(substr);
          if (itr != dp[i+1].end()) {
            itr->se += prev.se;
            itr->se %= MOD;
          }
          else {
            dp[i+1].insert(make_pair(substr, prev.se));
          }
        }
      }
    }
  }

  int ans = 0;
  for(const auto& x: dp[n]) {
    ans += x.se;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 896
N, M = map(int, input().split())
egdes = [list(map(int, input().split())) for _ in range(M)]

INF = 10 ** 13
dist = [INF] * (N + 1)
dist[1] = 0
for _ in range(N - 1):
    for a, b, c in egdes:
        dist[b] = min(dist[b], dist[a] - c)
ans = dist[N]
for a, b, c in egdes:
    dist[b] = min(dist[b], dist[a] - c)
print(-ans if ans == dist[N] else 'inf')


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



int main()
{
    ll a,b;
    while(cin>>a>>b)
    {
        ll t=a%b;
        if(b-t<t)
            cout<<b-t<<endl;
        else
            cout<<t<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int x[300005],y[300005],cx[300005],cy[300005];
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	FOR(i,1,k){
		cin>>x[i]>>y[i];
		cx[x[i]]++;
		cy[y[i]]++;
	}
	int mx=0,my=0;
	FOR(i,1,n){
		mx=max(mx,cx[i]);
	}
	FOR(i,1,m)my=max(my,cy[i]);
	int cnt=0;
	FOR(i,1,k){
		if(cx[x[i]]==mx&&cy[y[i]]==my){
			cnt++;
		}
	}
	int cxx=0,cyy=0;
	FOR(i,1,n)cxx+=cx[i]==mx;
	FOR(i,1,m)cyy+=cy[i]==my;
	if(cxx*cyy==cnt){
		cout<<mx+my-1;
	} else cout<<mx+my;
	RE 0;
}


Measured memory_bytes: 8316
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include<complex>

#define for0(i,n) for(ll i = 0;i < (n);i++)
#define for1(i,n) for(ll i = 1;i<=(n);i++)
#define for2(i,n) for(ll i = 2;i<=(n);i++)
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
#define rep(i,st,en,cnt) for(ll i = st;i <= en;i+=cnt)
#define PB push_back
#define MP make_pair
#define fastio cin.tie(NULL);cout.tie(NULL);ios::sync_with_stdio(false)
#define F first
#define S second
#define INF 0x3f3f3f3f
#define NEGINF 0xC0C0C0C0
#define EPS 1e-8
#define ALL(x) x.begin,x.end
#define SZ(vec)         int((vec).size())
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()
#define inp_arr(a,n) for0(i,n) {cin>>a[i];}
#define out_arr(a,n) for0(i,n) {cout<<a[i]<<" ";}

using namespace std;

typedef unsigned long long ul;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<pair<ll, ll> > vll;
typedef pair<ll,pll> tll;
typedef complex<double> point;

const ll mod = 998244353;

ll FACT[(int)2e5];

ll mexp(ll a,ll b) {
    ll ans = 1;
    while(b > 0) {
        if(b&1) {
            ans = (ans*a)%mod;
        }
        b >>= 1;
        a = (a*a)%mod;
    }
    return ans;
}

int main() {
    memset(FACT,0,sizeof(FACT));
    FACT[0] = FACT[1] = 1;
    for2(i,2e5-1) {
        FACT[i] = (FACT[i-1]*i)%mod;
    }
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans = 0;
    for0(i,k+1) {
        ll tmp = (m*mexp(m-1,n-i-1))%mod;
        tmp = (tmp*FACT[n-1])%mod;
        tmp = (tmp*mexp(FACT[i],mod-2))%mod;
        tmp = (tmp*mexp(FACT[n-i-1],mod-2))%mod;
        ans = (ans + tmp)%mod;
    }
    cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 5200
# -*- coding: utf-8 -*-
from bisect import bisect_right, bisect_left
N = int(input())
a_list = [int(input()) for _ in range(N)]

color_list = [1]
for a in a_list:
    a *= -1
    index = bisect_right(color_list, a)
    if index < len(color_list):
        color_list[index] = a
    else:
        color_list.append(a)
#     print(color_list, a)
print(len(color_list))

Measured memory_bytes: 11032
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int n,d[100000],i,x;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&d[i]);
	sort(d,d+n);
	x=d[n/2]-d[n/2-1];
	printf("%d\n",x);
	return 0;
}

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

//関数

//main関数
int main() {
    //入力
    long N;
    cin>>N;
    vector<long> A(N+2,0);
    for(int i=1;i<=N;i++){
        cin>>A.at(i);
    }
    //計算
    vector<long> R(N+2,0),L(N+2,0);
    for(int i=1;i<=N;i++){
        R.at(i)=__gcd(R.at(i-1),A.at(i));
        L.at(N+1-i)=__gcd(L.at(N+2-i),A.at(N+1-i));
    }
    long ans=0;
    for(int i=1;i<=N;i++){
        long pans=__gcd(L.at(i+1),R.at(i-1));
        ans=max(ans,pans);
        //cout<<pans<<endl;
    }
    
    
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;

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

	cout << (24-n) + 24 << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.Keyence
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            var aArray = ReadInts();
            var bArray = ReadInts();
            Array.Sort(aArray);
            Array.Reverse(aArray);
            Array.Sort(bArray);
            Array.Reverse(bArray);
            int i = 0;
            int j = 0;
            long max = nm[0] * nm[1];
            if (!(aArray[i] == bArray[j] && aArray[i] == max))
            {
                Console.WriteLine(0);
                return;
            }
            i++;
            j++;
            long res = 1;
            long mask = 1000000000 + 7;
            for (long val = max - 1; val >= 1; val--)
            {
                long space = 0;
                if (i < nm[0] && j < nm[1]
                    && val == aArray[i] && val == bArray[j])
                {
                    space = 1;
                    i++;
                    j++;
                }
                else if (i < nm[0] && val == aArray[i])
                {
                    space = j;
                    i++;
                }
                else if (j < nm[1] && val == bArray[j])
                {
                    space = i;
                    j++;
                }
                else
                {
                    space = i * j - (max - val);
                }
                if (space == 0)
                {
                    Console.WriteLine(0);
                    return;
                }
                res *= space;
                res %= mask;
            }
            Console.WriteLine(res);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13148