akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 200100
int i,n,a[N],b[N];
int main(){
	scanf("%d",&n);
	for(i=1;i<n;++i){
		scanf("%d",&a[i]);
		b[a[i]]++;
	}
	for(i=1;i<=n;++i){
		printf("%d\n",b[i]);
	}
	return 0;
}

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

  int main(){
    int n,a,b;
    string s;
    cin >> n >> a >> b;
    int ans=0;
    for (int i=1;i <= n;i++){
      s=to_string(i);
      int sum=0;
      rep(i,s.size()){
         sum+=stoi(s.substr(i,1));
      }
      if (sum <= b && sum >= a) ans+=i;
    }
    cout << ans << endl;
     
      
    return 0;
  }
    
    

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

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

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> c(n, 0), a(m);
    for (auto &&i : a) scanf("%lld", &i);
    for (int i = 0; i < m-1; ++i) {
        c[min(a[i], a[i+1])-1]++;
        c[max(a[i], a[i+1])-1]--;
    }
    ll S = 0;
    for (int i = 0; i < n+1; ++i) {
        S += c[i];
        c[i] = S;
    }
    ll ans = 0;
    for (int i = 0; i < n-1; ++i) {
        int p, q, r;
        scanf("%d %d %d", &p, &q, &r);
        ans += min(p*c[i], q*c[i]+r);
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 4408
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,L,ans=1e9,num=0;
	scanf("%d%d",&n,&L);
	for(int i=1;i<=n;i++){
		num+=L+i-1;
		if(abs(L+i-1)<abs(ans))ans=L+i-1;
	}
	printf("%d",num-ans);
	return 0;
}

Measured memory_bytes: 256
### main

loop do
  plen = gets.to_i
  break if plen == 0

  cnum = gets.to_i
  wdth = gets.to_i
  cspc = gets.to_i

  lines = []

  loop do
    line = gets.strip
    break if line == '?'

    while line.length > wdth
      lines << line[0, wdth]
      line[0, wdth] = ''
    end

    lines << line + '.' * (wdth - line.length)
  end
  #p lines

  cplen = plen * cnum
  rlen = lines.length % cplen
  if rlen > 0
    lines += ['.' * wdth] * (cplen - rlen)
  end
  #p lines.length

  while ! lines.empty?
    plines = plen.times.map{''}

    for col in (0...cnum)
      for i in (0...plen)
        plines[i] += '.' * cspc if col > 0
        plines[i] += lines.shift
      end
    end

    plines.each{|pl| puts pl}
    puts '#'
  end

  puts '?'
end

Measured memory_bytes: 6132
import sys,collections;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n,x = Is()
lis = []
for _ in range(n):
    lis.append(I())
lis = sorted(lis)
c = 0
for e in lis:
    if x - e >= 0:
        x = x - e
        c += 1
    else:
        break
c += x//lis[0]
print(c)

Measured memory_bytes: 3564
<?php
$to_i = function($s){return (int)$s;};
list($a, $b, $c) = array_map($to_i, explode(" ", fgets(STDIN)));
$n = 0;
foreach(range($a, $b) as $i) {
    if($c%$i == 0) $n++;
}
echo("$n\n");


Measured memory_bytes: 10712
//package atcoder.beginner_179;

import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main (String[] args) throws Exception {

        String s = "5\n" +
                "1 2\n" +
                "6 6\n" +
                "4 4\n" +
                "3 3\n" +
                "3 2";

//        br = new BufferedReader(new StringReader(s));
        br = new BufferedReader(new InputStreamReader(System.in));
        bw = new BufferedWriter(new OutputStreamWriter(System.out));

        rl(); int n=nin();
        boolean res = false;
        int c=0;
        for (int i = 0; i<n; ++i) {
            rl();
            if (nin() == nin()) {
                ++c;
            } else {
                c=0;
            }
            if (c==3) res = true;
        }
        bw.write((res ? "Yes" : "No") + "\n");
        bw.flush();

    }

    static BufferedReader br;
    static BufferedWriter bw;
    static StringTokenizer st;
    static void rl() throws Exception{
        st = new StringTokenizer(br.readLine());
    }
    static long nlo(){
        return Long.parseLong(st.nextToken());
    }
    static int nin(){
        return Integer.parseInt(st.nextToken());
    }
    /*private static void te(){
      }*/
    static double ndo(){
        return Double.parseDouble(st.nextToken());
    }
    static char[] nca(){
        return st.nextToken().toCharArray();
    }
    static String nstr(){
        return st.nextToken();
    }
}

Measured memory_bytes: 36740
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int x, y;
	cin >> x >> y;

	for (int turu = 0; turu <= x; ++turu) {
		for (int kame = 0; kame <= (x - turu); ++kame) {
			if (y == turu * 2 + kame * 4 && turu + kame == x) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    int x = 1;

    if(D !=0) {
        for (int i = 0; i < D; ++i) {
            x *= 100;
        }
    }

    if (N == 100) {
        cout << 101 * x << endl;
        return 0;
    }
    cout << N * x << endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    while(sc.hasNextLine()){
		    int n = sc.nextInt();
		    int x = sc.nextInt();

		    if ( n == 0 && x == 0)
		    	break;

		    int sum = 0;

		    for (int i = 1; i <= n-2; i++){
		    	for (int j = i+1; j <= n-1; j++){
		    		for (int k = j+1; k <= n; k++){
				    	if (i + j + k == x){
				    		sum++;
				    	}
				    }
			    }
		    }
		    System.out.println(sum);
	    }
	}

}



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

        int main() {
          int N, M;
          cin>> N >> M; 
          int maxL=-1, minR = 10000000;
          int L, R; 
          for(int i=0; i<M; i++){
            cin>> L >> R; 
            maxL= max( maxL, L );
            minR= min( minR, R );
          } 
          if( minR >= maxL){
            cout << minR - maxL +1 << endl;
            //cout << R << L  << endl;
          }else{
            cout << 0 << endl;
          }   
      
        }

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

const int MAX_N = 110000;

int memo[MAX_N]; // memo[i] が i についての答え
int rec(int n) {
    if (n == 0) return 0; // 終端条件
    if (memo[n] != -1) return memo[n]; // すでに探索済みならリターン

    int res = n; // INF の気持ち

    // 1, 6, 6^2, ..., を試す (n を超えない範囲で)
    for (int pow6 = 1; pow6 <= n; pow6 *= 6) res = min(res, rec(n - pow6) + 1);

    // 1, 9, 9^2, ..., を試す (n を超えない範囲で)
    for (int pow9 = 9; pow9 <= n; pow9 *= 9) res = min(res, rec(n - pow9) + 1);

    // メモしながらリターン
    return memo[n] = res;
}

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

    // テーブルを -1 で初期化
    for (int i = 0; i < MAX_N; ++i) memo[i] = -1;
    cout << rec(N) << endl;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
    using namespace std;
     
    template <class T>
    inline bool chmax(T &a, T b)
    {
        if (a < b)
        {
            a = b;
            return true;
        }
        return false;
    }
    template <class T>
    inline bool chmin(T &a, T b)
    {
        if (a > b)
        {
            a = b;
            return true;
        }
        return false;
    }
     
    /* define const */
    const long long INF = (1LL << 60);
    /* end defineing */
     
    int main()
    {
        long long n;
        long long a[5];
        cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
     
        sort(a, a + 5);
     
       // cout << a[0] << a[1] << a[2] << a[3] << a[4] << endl;
     
        long long tmp;
        if (n % a[0] != 0)
            tmp = n / a[0] + 1;
        else
            tmp = n / a[0];
     
        tmp += 4;
     
        cout << tmp << endl;
    }

Measured memory_bytes: 256
from sys import stdin

i = stdin.readline().rstrip().split()
arr = [int(x) for x in stdin.readline().rstrip().split()]

count = 0
flg = True
while True:
    for h,num in enumerate(arr):
        if num%2!=0:
            flg = False
            break
        else:
            arr[h] = num/2
    if(flg):
        count += 1
    else:
        break


print(count)

# 解答例とほぼ同じ

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main(void)
{
    long long a[100001], n;
    a[1] = 1;
    for(int i=2; i<=100000; i++)
        a[i] = (a[i-1]%1000000007 * i%1000000007) % 1000000007;
    while(~scanf("%d", &n))
        printf("%d\n", a[n]);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  map<int, int> mp;
  REP(i,n-1){
    int a;
    cin >> a;
    mp[a]++;
  }
  FOR(i,1,n+1){
    cout << mp[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 13004
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	
	int N;
	int[] T;
	int M;
	int[] P;
	int[] X;
	int sum=0;
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		N=sc.nextInt();
		T=new int[N];
		for(int i=0;i<N;i++){
			T[i]=sc.nextInt();
			sum+=T[i];
		}
		M=sc.nextInt();
		P=new int[M];
		X=new int[M];
		for(int i=0;i<M;i++){
			P[i]=sc.nextInt();
			X[i]=sc.nextInt();
		}
		
		for(int i=0;i<M;i++){
			System.out.println(sum-T[P[i]-1]+X[i]);
		}
	}
}

Measured memory_bytes: 23892
#include <iostream>
#include <vector>


using namespace std;

int main()
{
	int n; cin >> n;
	vector<int> v(n+1);
	for(int i = 1; i <= n; ++i)
		cin >> v[i];

	int time = 0;
	int cur = 1;

	while(cur != 2)
	{
		int next = v[cur];
		if(next == -1)
		{
			time = -1;
			break;
		}
		v[cur] = -1;
		cur = next;
		++time;
	}

	cout << time;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int n;cin>>n;
    if(n<1000)cout<<"ABC"<<endl;
    else cout<<"ABD"<<endl;

    return 0;
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, b, e) for (i64 i = (b); i <= (e); ++i)
#define repr(i, b, e) for (i64 i = (b); i >= (e); --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// input
void input() {}
template <class Head, class... Tail>
void input(Head&& head, Tail&&... tail) {
  cin >> head;
  input(forward<Tail>(tail)...);
}

// outs
void outs() {}
template <class Head, class... Tail>
void outs(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  outs(forward<Tail>(tail)...);
}

template <class T>
void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void outs(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// outl
void outl() {}
template <class Head, class... Tail>
void outl(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  outl(forward<Tail>(tail)...);
}

template <class T>
void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// outn
void outn() {}
template <class Head, class... Tail>
void outn(Head&& head, Tail&&... tail) {
  cout << head;
  outn(forward<Tail>(tail)...);
}

template <class T>
void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

// dump
template <class T>
void dump_(const char *s, T&& x) {
  clog << '{';
  while(*s != '\0') clog << *(s++);
  clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void dump_(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  dump_(s, forward<Tail>(tail)...);
}
// }}} End

i64 updiv(i64 a, i64 b) { return (a + b - 1) / b; }

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

  var(i64, q, h, s, d, N);

  chmin(h, 2 * q);
  chmin(s, 2 * h);

  if (N == 1) outl(s);
  else if (N == 2) outl(d);

  else {
    i64 v1 = s * N;
    i64 v2 = d * (N / 2) + s * (N % 2);
    i64 v3 = s * (N - 2) + d;
    outl(min({v1, v2, v3}));
  }


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int a[5],cnt,i;
	for(i=0;i<3;i++) scanf("%d",&a[i]);
	cnt=0;
	while(1){
		if(a[0]==a[1]&&a[1]==a[2]) break;
		sort(a,a+3);
		if(a[2]==a[1]){
			a[0]+=2;
			cnt++;
		}
		else{
			a[1]++; a[0]++;
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

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

#define pb     push_back
#define mp     make_pair
#define all(v) v.begin() , v.end()
#define allr(v) v.rbegin(), v.rend()
const ll INF =  0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int MAX = 1e5+5;

int r, c;
char ch;
int cnt[30];

int main(int argc, char const *argv[])
{
  scanf("%d %d" , &r, &c);
  for(int i = 0 ; i < r ; i++){
  	for(int j = 0 ; j < c ; j++){
  		scanf(" %c" , &ch);
  		cnt[ch-'a']++;
  	}
  }

  int f, t, o;
  f = t = o = 0;

  for(int i = 0 ; i < 26 ; i++){
  	f += (cnt[i]/4);
  	cnt[i] = cnt[i]%4;
  	t += (cnt[i]/2);
  	cnt[i] = cnt[i]%2;
  	o += cnt[i];
  }

  if((r%2 == 0) && (c%2 == 0)){
  	if(4*f == r*c)
  		printf("Yes");
  	else
  		printf("No");
  }
  else if((r%2 == 0) && (c%2 == 1)){
  	if((o == 0) && (4*f >= r*c - r) && (4*f + 2*t == r*c))
  		printf("Yes");
  	else
  		printf("No");
  }
  else if((r%2 == 1) && (c%2 == 0)){
  	if((o == 0) && (4*f >= r*c - c) && (4*f + 2*t == r*c))
  		printf("Yes");
  	else
  		printf("No");
  }
  else{
  	if((4*f >= (r*c - r - c - 1)) && (o == 1) && (4*f + 2*t + o == r*c) )
  		printf("Yes");
  	else
  		printf("No");
  }

  return 0;
}  


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

#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()

using namespace std;
using ll = long long;
using P = pair<int, int>;

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; }

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

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

    bool ok = true;
    map<char, char> mp1, mp2;
    REP( i , s.size() ){
        if( !mp1[s[i]] ) mp1[s[i]] = t[i];
        if( !mp2[t[i]] ) mp2[t[i]] = s[i];

        if( mp1[s[i]] != t[i] || mp2[t[i]] != s[i] ) ok = false;
    }

    if( ok ) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 776
//
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define speed ios::sync_with_stdio(false)
using namespace std;

string gs(char x){
    string s(1,x);
    return s;
}

int main()
{
	speed;
	
	ll n,m,t;
	cin>>n>>m>>t;

	ll l,r;
	ll dp[n+2][n+1];
	ll arr[n+2][n+1];
	for(ll i=1;i<=(n+1);i++){
		for(ll j=0;j<=n;j++){
			arr[i][j]=0;
			dp[i][j]=0;
		}
	}
	for(ll i=0;i<m;i++)
	{
		cin>>l>>r;
		arr[l][r]++;
	}
	for(ll i=n;i>=1;i--)
	{
		for(ll j=1;j<=n;j++)
		{
			dp[i][j]=dp[i][j-1]+dp[i+1][j]-dp[i+1][j-1]+arr[i][j];
		}
	}
	for(ll i=0;i<t;i++)
	{
		cin>>l>>r;
		cout<<dp[l][r]<<endl;
	}


	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <functional>
using namespace std;

int main()
{
    int a,b,c;

    cin >> a >> b >> c;

    if((a<=c&&b>=c) || (a>=c&&b<=c))
        cout<<"Yes"<<endl;
    else
    {
        cout<<"No"<<endl;
    }
    

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

int main() {
    int h,w,m;
    cin >> h >> w >> m;
    set<pair<int,int>> st;//爆破対象を記録
    map<int,int> mph,mpw;
    int maxh = 0;
    int maxw = 0;
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        mph[a]++;//ある行の爆破物の個数をカウント
        mpw[b]++;//ある列の爆破物の個数をカウント
        //爆破物の個数が最大の行と列の個数を更新
        chmax(maxh,mph[a]);
        chmax(maxw,mpw[b]);
        st.insert({a,b});
    }
    //最大行と最大列の座標を記録
    vector<int>H,W;
    for(auto tmp : mph) {
        if(tmp.second==maxh) H.push_back(tmp.first);
    }
    for(auto tmp : mpw) {
        if(tmp.second == maxw) W.push_back(tmp.first);
    }
    int ans = maxh+maxw-1;
    for(auto i : H) {
        for(auto j: W) {
            //最大行と最大列の座標が見つからないとき
            //つまり爆破するマスに爆破物がない
            if(st.find({i,j})==st.end()) {
                ans++;
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
    

}

Measured memory_bytes: 49624
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+10;
int main()
{
	int n;
  int a[maxn][maxn]={};
bool vis[maxn]={};
int  now[maxn]={};
	scanf("%d",&n);
	for(int i=1;i<maxn;i++)now[i]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n-1;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	int day = 0;
    int round = 0;
    while(1)
    {   memset(vis,false,sizeof(vis));
        bool ok = false;
    	for(int j=1;j<=n;j++)
    	{
		int b = a[j][now[j]]; 
		if(now[j]>=n||vis[b]||vis[j])continue;
		if(a[b][now[b]]==j)
		{
		        ok = true;
    			now[j]++;
				now[b]++;
    			vis[j]=true;
    			vis[b]=true;
    			round++;
    			if(round==n*(n-1)/2)return 0*printf("%d\n",day+1);
    	}
		}
		if(!ok)return 0*printf("-1\n");
		day++;
	}
	return 0*printf("%d\n",day);
}

Measured memory_bytes: 4224
{-# LANGUAGE FlexibleContexts, OverloadedStrings #-}
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace
import Data.List (sort)

main = do
  xs <- sort <$> getInts
  print . sum $ take 2 xs

-- util
getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine


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

int main() {
  long long X;
  int Ansi, Ansj, A=0;
  cin >> X;
  for(int i=-200; i<=200; i++){
    for(int j=-200; j<=200; j++){
      if(pow(i,5)-pow(j,5)==X){
        Ansi=i;
        Ansj=j;
        A=1;
        break;
      }
    }
    if(A==1) break;
  }
   cout << Ansi << " " << Ansj << endl;
}


Measured memory_bytes: 4116
package main

import(
  "fmt"
)

func main() {
  var N, K int
  fmt.Scan(&N,&K)

  var min1, min2, min int

  min1 = N%K
  min2 = (min1-K) * -1
  if min1 <= min2 {
	min = min1
  }else {
	min = min2
  }
  fmt.Println(min)
}



Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;



int main(){
  string s, t, u;
  cin >> s >> t >> u;
  char x = s[0] - 32;
  char y = t[0] - 32;
  char z = u[0] - 32;
  cout << x << y << z << endl;
}

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

a_list = [ [ 0 for j in range(9) ] for i in range(9) ]
b_list = [ [ 0 for j in range(9) ] for i in range(9) ]
for i in range(1,n+1):
    a = i // ( 10 ** (len(str(i)) - 1 ) )
    b = i % 10

    if b != 0:
        if (a != b):
            a_list[a-1][b-1] += 1
        else:
            a_list[a-1][b-1] += 1

for i in range(9):
    for j in range(9):
        if i == j:
            b_list[i][j] = a_list[i][j]**2
        else:
            b_list[i][j] = (a_list[i][j] * a_list[j][i]) 
        
ans = 0

for i in b_list:
    ans += sum(i)
print(ans)

Measured memory_bytes: 40684
#include <iostream>

using namespace std;

int main (){
  long int n, m, ans;
  cin >> n >> m;
  if (n == 1 && m==1) ans=1;
  else if (n == 1) ans = m-2;
  else if (m == 1) ans = n-2;
  else ans = n * m - n * 2 - m * 2 +4;
  cout << ans << endl;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define repi(i,a,b) for(int i = (a); i<= (b); i++)
#define repA(i,n) for(int i=n; i>=0; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (int)(a.size())

typedef long long ll;
typedef long double ld;
const ll mod = (ll)(1e9+7);//998244353;
const int N = (int)(2e6+5);

void pre() {

}

void solve() {
  int n;  cin>>n;
  string s; cin>>s;
  int ans = 0;
  rep(i,n) {
    ans++;
    while(s[i+1] == s[i]) i++;
  }
  cout<<ans;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  #endif
  int t = 1;
  pre();
//  cin>>t;
  rep(i,t)  {
    //cout<<"\nCase #"<<(i+1)<<"\n";
    solve();
    cout<<'\n';
  }
  return 0;
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

//しっかり制約確認したか?
int main()
{
    int n; cin >> n;
    if(n >= 30){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;


    system("pause");
}


Measured memory_bytes: 3692
N,x=[int(i)for i in input().split()]
a=[int(i)for i in input().split()]

cnt=0
for i in range(N):
    if a[i]>x:
        cnt+=a[i]-x
        a[i]=x
for i in range(1,N):
    su = a[i-1]+a[i]
    if su>x:
        sub=su-x
        a[i]-=sub
        cnt+=sub
print(cnt)


Measured memory_bytes: 14540
from collections import deque

def run():
    n = int(input())
    dq = deque()
    for _ in range(n):
        order = input()
        if order[0] == 'i':
            dq.appendleft(order[7:])
        elif order[6] == ' ':
            key = order.split()[1]
            if not key in dq:
                continue
            for i in range(len(dq)):
                if dq[i] == key:
                    dq.remove(key)
                    break
        elif order[6] == 'F':
            dq.popleft()
        elif order[6] == 'L':
            dq.pop()

    print(' '.join(dq))

if __name__ == '__main__':
    run()




Measured memory_bytes: 69740
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
vector<vector<int> > g;
vector<int> c;
vector<int> res;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>> > pq;
int main(){
    int n;
    cin >> n;
    g.resize(n);
    c.resize(n);
    res.resize(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
        c[a]++;
        c[b]++;
    }
    rep(i,n){
        if(c[i]==1){
            pq.push(MP(1,i));
        }
    }
    while(!pq.empty()){
        auto x = pq.top();
        pq.pop();
        int id = x.second;
        vector<int> cnt(21);
        for(auto y:g[id]){
            res[id] |= res[y];
            rep(i,20){
                if((res[y]>>i)&1){
                    cnt[i]++;
                }
            }
        }
        if(res[id]==0){
            res[id] = 1;
        }else{
            int k = -1;
            for(int i=20;i>=0;i--){
                if(cnt[i]>=2){
                    k = i;
                    break;
                }
            }
            int bits = (1<<(k+1))-1;
            res[id] &= ~bits;
            res[id] += bits+1;
        }
        for(auto y:g[id]){
            c[y]--;
            if(c[y]==1){
                pq.push(MP(res[id],y));
            }
        }
    }
    int mx = 0;
    rep(i,n){
        chmax(mx,res[i]);
        // cerr << i+1 << " " << res[i] << endl;
    }
    cout << 31 - __builtin_clz(mx) << endl;
    return 0;
}

Measured memory_bytes: 11064
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define rep_r(i,s,n)for(ll i = n-1;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

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

	int cnt = 0;
	rep(i, 0, s.size() - 2) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 256
# C - Sum of gcd of Tuples (Easy)

import math

k = int(input())
s = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        gcdab = math.gcd(a,b)
        if  gcdab== 1:
            s += k
        else:
            for c in range(1,k+1):
                s += math.gcd(gcdab,c)

print(s)




Measured memory_bytes: 9004
def solve():
  N,M = map(int, input().split())
  An = []
  Bn = []
  [An.append(str(input())) for i in range(N)]
  [Bn.append(str(input())) for i in range(M)]

  for i in range(0,N-M+1):
    for j in range(0,N-M+1):
      ret = True
      for k in range(M):
        if An[i+k][j:M+j] != Bn[k]:
          ret = False
      if ret:
        return True
  return False

if __name__ == "__main__":
  if solve():
    print('Yes')
  else:
    print('No')    


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int mx = 3005;
int dp[mx][mx];
string st ="";
void build(string s,string p)
{
    int k = s.size();
    int l = p.size();
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=k;i++)
        for(int j=1;j<=l;j++)
    {
        if(s[i-1]==p[j-1])
        {
            dp[i][j]= dp[i-1][j-1]+1;
        }
        else
            dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
    }
    int i=k,j = l;
    while(i>0&&j>0)
    {
        if(s[i-1]==p[j-1])
        {
            st+=s[i-1];
            j--;
            i--;
        }

    else
        {
            if(dp[i-1][j]>=dp[i][j-1])
                i--;
            else
                j--;
        }

    }
    reverse(st.begin(),st.end());
}
int main()
{
    string s,p;
    cin>>s>>p;
    build(s,p);
   cout<<st<<endl;
    return 0;
}


Measured memory_bytes: 35584
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int n;
vector<long long> a;
vector<vector<int>> p;
vector<long long> q; // max, min
vector<bool> c;

long long dfs(int id, int from) {
  if (c[id])
    return q[id];
  c[id] = true;
  if (p[id].size() == 1) {
    return q[id] = a[id];
  }
  long long sum = 0;
  for (int i = 0; i < p[id].size(); i++)
    if (p[id][i] != from)
      sum += dfs(p[id][i], id);
  long long b = sum - a[id];
  long long c = a[id] - b;
  if (b < 0 || c < 0) {
    return q[id] = -1000000000000ll;
  }
  long long mm = 0;
  for (int i = 0; i < p[id].size(); i++)
    mm = max(mm, dfs(p[id][i], id));
  if (mm > sum / 2) {
    if (sum - mm < b)
      return q[id] = -1000000000000ll;
  } else {
    if (sum / 2 < b)
      return q[id] = -1000000000000ll;
  }
  return q[id] = c;
}

int main() {
  cin >> n;
  a.resize(n);
  p.resize(n);
  c.resize(n);
  q.resize(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    p[a].push_back(b);
    p[b].push_back(a);
  }
  if (n == 2) {
    if (a[0] == a[1])
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
    return 0;
  }

  for (int i = 0; i < n; i++) {
    if (p[i].size() == 1)
      continue;
    if (dfs(i, -1) == 0) {
      cout << "YES" << endl;
      return 0;
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 13952
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;

/// M A C R O Starts Here
#define pf printf
#define sf scanf
#define MAX 500000
#define MOD 100000007
#define INF INT_MAX
#define LINF LONG_LONG_MAX
#define pi acos(-1.0)
#define get_stl(s) getline(cin,s)
#define sif(a) scanf("%d",&a)
#define pif(a) printf("%d\n",a)
#define puf(a) printf("%llu\n",a)
#define pii pair<int, int>
#define p_b push_back
#define debug cout<<"Reached Here"<<endl;
#define pdd pair<double, double>
#define mem(name, value) memset(name, value, sizeof(name))
#define all(name) name.begin(),name.end()
#define pq_min priority_queue< int, vector<int>, greater<int> >
#define dbg(args...)    do { cerr << #args << ' ' ; print(args); } while(0); cerr << endl;

typedef long long ll;
typedef unsigned long long ull;

int dx[]= {0,0,1,-1,-1,1,-1,1};
int dy[]= {-1,1,0,0,1,1,-1,-1};
int dz[]= {0,0,1,-1,-1,1,-1,1};
int kx[]= {2,2,-2,-2,1,-1,1,-1};
int ky[]= {1,-1,1,-1,2,2,-2,-2};

/// Template Starts here

template <typename T>
void print(const T& x)
{
    cerr<<x<<' ';
}

template <typename T1, typename... T2>
void print(const T1& first, const T2&... rest)
{
    print(first);
    print(rest ...) ;
}
/// Template Ends here

/// Functions Starts here

bool isPal(string s)
{
    int half = s.size()/2;
    for(int i=0,j=s.size()-1;i<half;i++,j--)
        if(s[i]!=s[j])  return false;
    return true;
}

double _distance(double x1,double y1,double x2,double y2)
{
    double x1x2 = x1 - x2;
    double y1y2 = y1 - y2;
    return sqrt((x1x2*x1x2)+(y1y2*y1y2));
}

bool inBound(int x,int y,int r,int c)
{
    return (x>=0&&x<r&&y>=0&&y<c);
}

ll mulmod(ll a, ll b, ll c)
{
    ll x = 0, y = a % c;
    while (b > 0)
    {
        if (b&1) x = (x + y) % c;
        y = (y << 1) % c;
        b >>= 1;
    }
    return x % c;
}

/*
int lp[32001];
vector<int>prime;
void sieve(int limit = 32001)
{
    for(int i=2;i<limit;i++)
    {
        if(!lp[i])
        {
            lp[i] = i;
            prime.push_back(i);
        }
        for(int j=0;j<prime.size()&&prime[j]<=i&&i*prime[j]<limit;j++)
            lp[i*prime[j]]=i;
    }
}
*/

/// Functions Ends here

int main()
{
    /// Suck my dick! HACKER -_-
    //freopen("in.txt","r", stdin);
    //freopen("out.txt","w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);

    ll n;
    cin>>n;

    ll a[n+1],suff[n+2],pref[n+1];

    pref[0] = suff[n+1] = 0;

    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        pref[i] = __gcd(pref[i-1],a[i]);
    }

    for(int i = n;i>=1;i--)
        suff[i] = __gcd(suff[i+1],a[i]);

    ll ans = 0;

    for(int i=1;i<=n;i++)
        ans = max(ans,__gcd(pref[i-1],suff[i+1]));

    cout<<ans<<endl;

    return 0;
}


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

int main()
{
  int N ;
  cin>>N ;
  vector<int>A(N) ;
  for(int i=0;i<N;i++) cin>>A.at(i) ;
  
  sort(A.begin(),A.end()) ;
  for(int i=0;i<N-1;i++){
    if(A.at(i)==A.at(i+1)){
      cout<<"NO"<<endl ;
      return 0 ;
    }
  }
  cout<<"YES"<<endl ;
  
  return 0 ;
}


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

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

template<int mod> struct Combination {
    vector<ModInt<mod>> fact, ifact;
    Combination(int n) : fact(n+1), ifact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i);
        ifact[n] = fact[n].inverse();
        for (int i = n; i > 0; i--) ifact[i - 1] = ifact[i] * i;
    }
    ModInt<mod> operator() (int n, int r) {
        if (n < 0 or r < 0 or r > n) return 0;
        assert(n < fact.size() and r < fact.size());
        return fact[n] * ifact[n - r] * ifact[r];
    }
    const ModInt<mod> &operator[] (int i) const {
        return fact[i];
    }
};

constexpr int MOD = 998'244'353;
constexpr int MAX = 300'300;

int main() {
    Combination<MOD> comb(MAX);
    
    long long n, a, b, k;
    cin >> n >> a >> b >> k;
    
    ModInt<MOD> ans = 0;
    
    for (long long i = 0; i <= n; i++) {
        long long val = k - a * i;
        if (val % b != 0) continue;
        ans += (comb(n, i) * comb(n, val / b));
    }
    
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <complex.h>
#include <assert.h>
#include <errno.h>

#define loop(i,a,n) for (int i = a; i < n; ++i)
#define print(i) printf("%d\n",i)
#define input(a) scanf("%d",&a)
#define input2(a,b) scanf("%d %d",&a,&b)
#define input3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define inputv(a,n) loop(i,0,n) input(a[i])

int main(void)
{
  int k,a,b;
  input(k);
  input2(a,b);
  loop(i,a,b+1) 
    if (i % k == 0) {
      printf("OK");
      return 0;
  	}
  printf("NG");
  return 0;
}

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

/*int par[100000];

void init(int n){
    for(int i=0; i<n; i++) par[i] = i;
}

int find(int x){
    if(par[x] == x) return x;
    else{
        par[x] = find(par[x]);
        return par[x];
    }
}

int min(int a, int b){
    if(a > b) return b;
    else return a;
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    par[x] = y;
}*/
int dp[50001];

int main(){
	int n, m;
	cin >> n >> m;
	int c[20];
	for (int i = 0; i < m; i++) {
		cin >> c[i];
		dp[c[i]] = 1;
	}
	dp[0] = 0;
	for (int i = 1; i <= n; i++) {
		dp[i] = 99999;
		for (int j = 0; j < m; j++) {
			if (i >= c[j]) {
				dp[i] = min(dp[i], 1 + dp[i - c[j]]);
			}
		}
	}
	cout << dp[n] << endl;

/*int W;
cin>>W;
cout<<W*32<<endl;*/

    return 0;
}


Measured memory_bytes: 3312
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <cstdlib>
#include <unordered_map>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007 
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
using namespace std;
int main() {
	string s;
	cin >> s;
	map<char, int> ww;
	for (int i = 0; i < s.length(); ++i) {
		ww[s[i]] = 1;
	}
	for (char i = 'a'; i <= 'z'; ++i) {
		if (ww[i] == 0) {
			cout << s << i << endl;
			return 0;
		}
	}
	if (s == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
		return 0;
	}
	vector<char> hoge;
	for (int i = 0; i < s.length(); ++i) {
		hoge.push_back(s[i]);
	}
	string geko;
	next_permutation(hoge.begin(), hoge.end());
	for (int i = 0; i < hoge.size(); ++i) {
		geko.push_back(hoge[i]);
		if (s < geko)break;
	}
	cout <<geko <<  endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

const int mod = 1e9 + 7;

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

ll modpow(ll k, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * k % mod;
    k = k * k % mod;
    n /= 2;
  }
  return res;
}

struct Sieve {
  vector<int> p;
  Sieve(int n) : p(n) {
    for (int i = 2; i <= n; ++i) {
      p[1] = -1;
      if (p[i] == 0) {
        p[i] = i;
        for (int j = 2 * i; j <= n; j += i) {
          if (p[j]) continue;
          p[j] = i;
        }
      }
    }
  }

  map<int, int> factMap(int n) {
    map<int, int> mp;
    while (p[n] != -1) {
      ++mp[p[n]];
      n /= p[n];
    }
    return mp;
  }
};

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];

  Sieve s(1000005);

  map<int, int> mp;
  rep(i, n) {
    auto m = s.factMap(a[i]);
    for (auto p : m) {
      mp[p.first] = max(mp[p.first], p.second);
    }
  }

  ll lcd = 1;
  for (auto p : mp) {
    rep(i, p.second) { lcd = lcd * p.first % mod; }
  }

  int b[n];
  rep(i, n) { b[i] = lcd * modpow(a[i], mod - 2) % mod; }

  ll ans = 0;
  rep(i, n) { ans = (ans + b[i]) % mod; }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7572
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;

//int main(int argc, char *argv[]){
int main(){

	char str;
  	cin >> str;
  	int c = str;
  
  	if(c>=97 && c<=122) cout << "a" << endl;
  	if(c>=65 && c<=90)  cout << "A" << endl;

}

Measured memory_bytes: 3568
import sys
import numpy as np
input = sys.stdin.readline
H, W = [int(x) for x in input().strip().split()]
masu = np.zeros((H, W), dtype=int)
for h in range(H):
    masu[h] = [int(x) for x in input().strip().split()]

def nextp(p, H, W):
    if p[0] % 2 == 0 and p[1] == W-1:
        p[0] += 1
        return p[0] < H
    if p[0] % 2 == 1 and p[1] == 0:
        p[0] += 1
        return p[0] < H
    if p[0] % 2 == 0:
        p[1] += 1
        return True
    else:
        p[1] -= 1
        return True

ans = []
p = [0, 0]
not_end = True
while True:
    if masu[p[0], p[1]] % 2 == 1:
        masu[p[0], p[1]] -= 1
        p_ = p[:]
        not_end = nextp(p, H, W)
        if not not_end:
            masu[p_[0], p_[1]] += 1
            break
        ans.append([p_[0]+1, p_[1]+1, p[0]+1, p[1]+1])
        while True:
            if masu[p[0], p[1]] % 2 == 1:
                masu[p[0], p[1]] += 1
                not_end = nextp(p, H, W)
                break
            p_ = p[:]
            not_end = nextp(p, H, W)
            if not_end:
                ans.append([p_[0]+1, p_[1]+1, p[0]+1, p[1]+1])
                continue
            masu[p_[0], p[1]] += 1
            break
    else:
        not_end = nextp(p, H, W)
    if not_end:
        continue
    break

print(len(ans))
for a in ans:
    print(*a)

Measured memory_bytes: 39004
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>

typedef long long ll;

#define debug(x) cout << #x << "=" << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << " "
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>

using namespace std;

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

ll lcm(ll a,ll b){
    return a * b/ gcd(a,b);
}

int f(ll n){
    ll res = 0;

    while(n % 2 == 0){
        n /= 2;
        res ++;
    }

    return res;
}

int main(){
    ll n,m;
    cin >>n >>m;

    vector<ll> a(n);
    loop(i,n) cin >>a[i];

    loop(i,n) {
        if (a[i] % 2 != 0) {
            cout << 0 << endl;
            return 0;
        }
        a[i] /= 2;
    }

    int t = f(a[0]);
    loop(i,n){
        if(t != f(a[i])){
            cout << 0 << endl;
            return 0;
        }

        a[i] >>= t;
    }
    m >>= t;

    ll l = 1;
    loop(i,n){
        l = lcm(l,a[i]);
        if(l > m){
            cout << 0 << endl;
            return 0;
        }
    }
    m /= l;
    ll ans = (m+1)/2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define f   first
#define s   second
#define pb          push_back
#define mod         1000000007
#define hell        998244353
#define inf         1000000000000000000LL
using namespace std;
ll n,k,m,l;
//ll dp[15][1005];
void solve()
{   
  
string s;
cin>>k;
int ans=0;
for(int i=1;i<=k;i++)
{   int a=i;
    for(int j=1;j<=k;j++)
    {   int b=__gcd(a,j);
        for(int l=1;l<=k;l++)
            {  int c=__gcd(b,l);ans+=c;}
    }
}
cout<<ans;




}    
int main()
{  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //cout<<primes.size();
    ll t=1;
    //cin>>t;
    while(t--)
        solve();

}


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

typedef long long ll;

int main() {

  ll n;
  ll a[100];
  cin >> n;
  for(int i=0; i<n; ++i) cin >> a[i];

  ll money = 1000;   //所持金

  for(int i=0; i<n-1; ++i) {
    ll stock = 0;
    if(a[i]<a[i+1]) {
      stock = money/a[i];
      money += (a[i+1]-a[i])*stock;
    }
  }

  cout << money << endl;

  return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
void solveA()
{
  long long a,b,tem;
  cin>>a>>b;
  tem=(a+b);
  if(tem%2==0)
  {
    cout<<tem/2<<endl;
  }
  else
  {
    cout<<"IMPOSSIBLE"<<endl;
  }
}
void solveB()
{
  int n,i,j,count;
  cin>>n;
  int ar[n];
  for(i=0;i<n;i++)
  {
    cin>>ar[i];
  }
  j=1;
  count=0;
  for(i=0;i<n;i++)
  {
    if(ar[i]!=j)
    {
      count++;
    }
    if(count>2)
    {
      cout<<"NO"<<endl;
      return;
    }
    j++;
  }
  cout<<"YES"<<endl;
}
void solveC()
{
  int a,b,x,y;
  cin>>a>>b;
  x=max(a,b);
  y=min(a,b);
  if((x-y)>=2)
  {
    cout<<2*x-1<<endl;
  }
  else
  {
    cout<<x+y<<endl;
  }
}
void solveD()
{
  int n,i,j;
  cin>>n;
  int ar[n];
  for(i=0;i<n;i++)
  {
    cin>>ar[i];
  }
  int count=n;
  for(i=n-1;i>=0;i--)
  {
    for(j=i-1;j>=0;j--)
    {
      if(ar[i]<ar[j])
      {
        count--;
        break;
      }
    }
  }
  cout<<count<<endl;
}
void solveE()
{
  int h,w,x,y,H,W;
  cin>>H>>W;
  cin>>h>>w;
  x=h*W;
  y=(H-h)*w;
  cout<<(H*W)-(x+y)<<endl;
}
void solveF()
{
  int n,m,c,i,j;
  cin>>n>>m>>c;
  int b[m];
  int ar[n][m];
  for(i=0;i<m;i++)
  {
    cin>>b[i];
  }
  for(i=0;i<n;i++)
  {
    for(j=0;j<m;j++)
    {
      cin>>ar[i][j];
    }
  }
  int count=0;
  int sum;
  for(i=0;i<n;i++)
  {
    sum=0;
    for(j=0;j<m;j++)
    {
      sum=sum+ar[i][j]*b[j];
    }
    if((sum+c)>0)
    {
      count++;
    }
  }
  cout<<count<<endl;
}
void solveG()
{
  int a,b,c,tem;
  cin>>a>>b>>c;
  tem=b/a;
  if(tem>c)cout<<c<<endl;
  else cout<<tem<<endl;
}
void solveH()
{
  int a,b,c,tem,i;
  cin>>a>>b>>c;
  tem=min(a,b);
  vector<int>vec;
  for(i=1;i<=tem;i++)
  {
    if(a%i==0&&b%i==0)
    {
      vec.push_back(i);
    }
  }
  cout<<vec[vec.size()-c]<<endl;
}
void solveI()
{
  double t,x;
  cin>>t>>x;
  cout<<fixed<<setprecision(10)<<t/x<<endl;
}
void solveJ()
{
  int n,i;
  cin>>n;
  int ar[n];
  for(i=0;i<n;i++)
  {
    cin>>ar[i];
  }
  sort(ar,ar+n);
  int sum=0;
  for(i=0;i<n-1;i++)
  {
    sum=sum+ar[i];
  }
  if(ar[n-1]<sum)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
int main()
{
  // solveA();
  //solveB();
  // solveC();
  // solveD();
// solveE();
 //solveF();
// solveG();
//solveH();
//solveI();
solveJ();
  return 0;
}

Measured memory_bytes: 3616