akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 
int main(void) {
  int A, B, K;
  int i;
  
  scanf("%d %d %d", &A, &B, &K);
  if(B - A + 1 <= 2 * K) {
    for(i = A; i <= B; i++) printf("%d\n", i);
  } else {
    for(i = 0; i < K; i++) printf("%d\n", A + i);
  	for(i = K - 1; i >= 0; i--) printf("%d\n", B - i);
  }
  
  return 0;
}

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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var n = Console.ReadLine();
            var ans = "No";

            for(int i = 0; i < n.Length; i++)
            {
                if (n[i] == '7') ans = "Yes";
            }

            Console.WriteLine(ans);
                
                





        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }
    }
}


Measured memory_bytes: 25796
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using Graph = vector<vector<int>>;
using Wgraph = vector<vector<pair<int, long long int>>>;
constexpr long long int INF = 1001001001001001LL;
constexpr long long int MOD = 1000000007LL;
constexpr double PI = 3.1415926535897932;
constexpr long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = 1; i <= (n); i++)
#define DREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define SREP(i,s,t) for(int i = s; i < t; i++)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define PB push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
  
  lnt MAX_N = 1000003;
  vector<lnt> isPrime(MAX_N + 1, 1);
  // 0 := 素数じゃない
  // 1 := 素数
  isPrime[0] = 0;
  isPrime[1] = 0;

  for(lnt i = 1; i <= MAX_N; i++) {
    if(isPrime[i] == 0) continue;
    else {
      for(lnt j = 2; i * j <= MAX_N; j++) {
        isPrime[i * j] = 0;
      }
    }
  }
  
  while(1) {
    lnt a, d, n; cin >> a >> d >> n;
    if(a == 0 and d == 0 and n == 0) break;
    lnt cnt = 0;
    for(lnt i = 0;; i++) {
      lnt value = a + i * d;
      if(isPrime[value] == 1) cnt++;
      if(cnt == n) {
        cout << value << endl;
        break;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 10484
num = [input() for i in range(2)]
num_0 = int(num[0])
num_1 = list(map(int, num[1].split()))

num_min = num_1[0]
count = 0

for i in range(0,num_0):
  if(num_min >= num_1[i]):
    count = count+1
    num_min = num_1[i]
    
print(count)


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

const int MN = 100010;

int N;
int A[MN], B[MN];
vector<int> Va[MN], Vb[MN];

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N; i++) {
        scanf("%d %d", &A[i], &B[i]);

        Va[ A[i] ].push_back(i);
        Vb[ B[i] ].push_back(i);
    }

    if(A[0] || B[1]) {
        printf("-1");
        return 0;
    }
    if(Va[0].size() > 1 || Vb[0].size() > 1) {
        printf("-1");
        return 0;
    }

    multiset<int> pre;
    pre.insert(B[0]);

    for(int i = 1; i < N; i++) {
        multiset<int> cur;

        for(int j = 0; j < Va[i].size(); j++) {
            int x = Va[i][j];

            auto it = pre.lower_bound(B[x] - 1);
            if(it == pre.end() || B[x] + 1 < *it) {
                printf("-1");
                return 0;
            }

            cur.insert(B[x]);
        }
        pre = cur;
    }

    int ans = N - 1;

    pre.clear();
    pre.insert(A[1]);

    multiset<int> alive = pre;
    for(int i = 1; i < N; i++) {
        multiset<int> cur;
        multiset<int> tmp;

        for(int j = 0; j < Vb[i].size(); j++) {
            int x = Vb[i][j];

            auto it = pre.lower_bound(A[x] - 1);
            if(it == pre.end() || A[x] + 1 < *it) {
                printf("-1");
                return 0;
            }
            cur.insert(A[x]);
        }

        vector<int> chk(Vb[i].size(), 0);

        for(int j = 0; j < Vb[i].size(); j++) if(!chk[j]) {
            int x = Vb[i][j];

            if(alive.find(A[x] + 1) != alive.end()) {
                chk[j] = 1;
                alive.erase(alive.find(A[x] + 1));
                tmp.insert(A[x]);
            }
        }
        for(int j = 0; j < Vb[i].size(); j++) if(!chk[j]) {
            int x = Vb[i][j];

            if(pre.find(A[x] - 1) != pre.end()) {
                continue;
            }
            tmp.insert(A[x]);
            ans++;
        }

        pre = cur;
        alive = tmp;
    }

    printf("%d", ans);
}


Measured memory_bytes: 25588
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll res=0;
  map<char,ll> mp;
  string s;
  cin >> s;
  REP(i,s.size()){
    mp[s[i]]++;
  }
  for(char i='a';i<'z';i++){
    for(char j=i+1;j<='z';j++){
      res+=mp[i]*mp[j];
    }
  }
  res++;
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 6001001001001001001;
long double EPS = 1e-6;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

// MOD確認

int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> A(N);
    ll sum = 0;
    rep(i,N){
        cin >> A[i];
        sum += A[i];
    }
    ll cnt = 0;
    rep(i,N){
        if(A[i] * 4 * M >= sum) cnt++;
    }
    if(cnt >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<tuple<int, int, int>> V(M);
  for (int i = 0, p, y; cin >> p >> y; i++) V.at(i) = {y, p, i};
  sort(V.begin(), V.end());
  map<int, int> MA;
  for (auto &[y, p, i] : V) y = i, i = ++MA[p];
  sort(V.begin(), V.end());
  for (auto [i, p, y] : V) printf("%06d%06d\n", p, y);
}

Measured memory_bytes: 8956
#include<bits/stdc++.h>
using namespace std;
long long a[200010];
long long b[200010];
int main(){
    int c;
    cin>>c;
    long long s=0;
    for(int i=0;i<c;i++){
        cin>>a[i];
        if(i==0)
            b[i]=a[i];
        else
            b[i]=b[i-1]+a[i];//建数组b
        s=s+a[i];//求总
    }
    long long m;
    if(b[0]>s-b[0])
        m=b[0]+b[0]-s;
    else
        m=s-b[0]-b[0];//对m初始化
    for(int i=1;i<(c-1);i++){//每个人手里面必须有一张
        if(m>abs(s-b[i]-b[i]))
        m=abs(s-b[i]-b[i]);
    }
    cout<<m<<endl;
    return 0;
} 

Measured memory_bytes: 3328
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    Map<Character, Integer> map = new HashMap<>();
    for (char c : s.toCharArray()) {
    	if (map.containsKey(c)) {
        	map.put(c, map.get(c) + 1);
        } else {
          map.put(c, 1);
        }
    }
    
    for (char i : map.keySet()) {
    	if (map.get(i) != 2) {
        	System.out.println("No");
          	return;
        }
    }
    System.out.println("Yes");
  }
}

Measured memory_bytes: 35464
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
struct Combination {
  vector<vector<ll>> memo;
  Combination(int x) {
    memo.resize(x + 1);
    for (int i = 0; i <= x; i++) memo[i].resize(x + 1, 0);
  }
  ll RetCombination(int n, int r, int mod) {
    if (n < 0 || r < 0 || n < r) {
      return 0;
    }
    if (memo[n][r] != 0) return memo[n][r];
    if (r == 0 || n == r || n == 0) {
      return memo[n][r] = 1;
    }
    ll k = RetCombination(n - 1, r - 1, mod) % mod;
    ll l = RetCombination(n - 1, r, mod) % mod;
    memo[n - 1][r - 1] = k, memo[n - 1][r] = l;
    return memo[n][r] = (k + l) % mod;
  }
};
long long longpow(long long n, long long a, long long mod) {
  if (a == 0) return 1;
  if (a == 1) return n % mod;
  if (a % 2 == 1) return (n * longpow(n, a - 1, mod)) % mod;
  ll t = longpow(n, a / 2, mod) % mod;
  return (t * t) % mod;
}
int main() {
  int N, K;
  cin >> N >> K;
  Combination cm(2010);
  for (int i = 1; i <= K; ++i) {
    cout << (cm.RetCombination(K - 1, i - 1, MOD) *
                 cm.RetCombination(N - K + 1, i, MOD) +
             MOD) %
                MOD
         << endl;
  }
}

Measured memory_bytes: 35392
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

ll c[10][10];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    REP(i,10) REP(j,10) cin >> c[i][j];
    vector<vector<int>> A(H, vector<int>(W));
    REP(i,H) REP(j,W) cin >> A[i][j];

    REP(k,10) REP(i,10) REP(j,10){
        chmin(c[i][j], c[i][k] + c[k][j]);
    }
    ll ans = 0;
    REP(i,H) REP(j,W){
        if(A[i][j] == -1) continue;
        ans += c[A[i][j]][1];
    }
    cout << ans << endl;
}

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

int main(){
  int X,Y,Z,K;
  cin >> X >> Y >> Z >> K;
  vector<long> A(X),B(Y),C(Z),AB(X*Y),ABC(K*K);
  for(int i=0; i<X; i++){
    cin >> A.at(i);
  }
  for(int i=0; i<Y; i++){
    cin >> B.at(i);
  }
  for(int i=0; i<Z; i++){
    cin >> C.at(i);
  }
  for(int i=0; i<X; i++){
    for(int j=0; j<Y; j++){
      AB.at(Y*(i+1)-j-1)=A.at(i)+B.at(j);
    }
  }
  sort(C.begin(),C.end());
  sort(AB.begin(),AB.end());
  for(int i=0; i<X*Y&&i<K; i++){
    for(int j=0; j<Z&&j<K; j++){
      ABC.at(K*(i+1)-j-1)=AB.at(X*Y-1-i)+C.at(Z-1-j);
    }
  }
  sort(ABC.begin(),ABC.end());
  for(int i=0; i<K; i++){
    cout << ABC.at(K*K-1-i) << endl;
  }
}

Measured memory_bytes: 78464
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;
#define INF 100000

int main(){
    int a, b; cin >> a >> b;
    int n = a + b + 1;
    string s;
    cin >> s;
    bool exist = true;
    rep(i, n){
        if(i != a){
            if(s[i] == '-'){
                exist = false;
                break;
            }
        }else{
            if(s[i] != '-'){
                exist = false;
                break;
            }
        }
    }
    if(exist) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#include<map>
#include <limits>
# include <iomanip>
#include<queue>
#define INF 1000000009;
#define inl long long
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
int kaizyo(int a) {
	long long ans = 1;
	for (int i = a; i > 0; i--) {
		ans *= i;
		ans = ans % 1000000007;
		//cout << ans << endl;
	}
	ans = ans % 1000000007;
	return ans;
}
int main() {
	string manji;
	cin >> manji;
	int sco = 0;
	int gu = 0, pa = 0;
	if (manji[0] == 'p') {
		sco--;
	}
	gu++;
	for (int i = 1; i < manji.size(); i++) {
		if (manji[i] == 'g') {
			if (gu > pa) {
				sco++;
				pa++;
			}
			else {
				gu++;
			}
		}
		if (manji[i] == 'p') {
			if (gu > pa) {
				pa++;
			}
			else { gu++;
			sco--;
			}
		}
	}
	cout << sco << endl;
	return 0;
}






Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
long long h,w,memo[102][102];
string s[102];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
bool vis[102][102],yes;
long long dp (int x,int y)
{
    queue <pair<int,int> > q;
    q.push({0,0});
    memo[0][0]=1;
    while (!q.empty())
    {
        pair <int,int> p=q.front();
        q.pop();
        for (int i=0;i<4;i++)
        {
            int a=dx[i]+p.first;
            int b=dy[i]+p.second;
            if (a<0||b<0||a>=h||b>=w||s[a][b]=='#')
                continue;
            if (memo[a][b]==-1)
            {
                memo[a][b]=memo[p.first][p.second]+1;
                q.push({a,b});
            }
        }
    }
    return memo[h-1][w-1];
}
int main()
{
    cin >>h>>w;
    int cnt=0;
    for (int i=0;i<h;i++)
    {
        cin >>s[i];
        for (int j=0;j<w;j++)
            cnt+= (s[i][j]=='#');
    }
    memset(memo,-1,sizeof memo);
    if (s[0][0]=='#')
    {
        cout <<-1;
        return 0;
    }
    long long ans=dp(0,0);
    if (ans==-1)
    {
        cout <<-1;
        return 0;
    }
    cout << ((h*w)-cnt)-ans;
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
public  class Main
{
public static void main(String args[])
{
  Scanner sc=new Scanner(System.in);
  
  String h[]=sc.nextLine().split(" ");
 int n=Integer.parseInt(h[0]);
 int k=Integer.parseInt(h[1]);
 long ans=0;
 long sum=0;
 long sum1=0;
 long MOD=1000000007;
 for(int i=0;i<k;i++)
 {
 	sum+=i;
 	sum1+=(n-i);
 }
 int u=k;
 int uu=(n-k);
while(sum<=sum1)
{
	ans=ans+(sum1-sum)+1;
	sum+=u;
	sum1+=uu;
	u+=1;
	uu-=1;
}
System.out.println(ans%MOD);
 }
 
}



Measured memory_bytes: 35760
from collections import deque
[N,M] = list(map(int,input().split()))
AB = []
for i in range(M):
    AB.append(list(map(int,input().split())))

#そこから直で行けるところをまとめる
ikeru = [[] for i in range(N)]
for i in range(M):
    ikeru[AB[i][0]-1].append(AB[i][1]-1)
    ikeru[AB[i][1]-1].append(AB[i][0]-1)
# print('ikeru:',ikeru)



que = deque([])
que.append(0)
# print('que ini:',que)
out=[10**6]*N
out[0]=0

while que:
    p = que.popleft()
    # print('p,que:',p,que)

    for next in ikeru[p]:
        # print('next,out:',next,out)
        if out[next]==10**6:
            que.append(next)
            out[next]=p+1


# print(out)
print('Yes')
for i in range(1,N):
    print(out[i])



Measured memory_bytes: 129240
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> PL;

int n, A[100010];
int flip;
void SE(){
	puts("Second");
	exit(0);
}

void FI(){
	puts("First");
	exit(0);
}

void output(int o){
	o ^= flip;
	if(o == 0)FI();
	else SE();
}

int gc(int x, int y){
	return y == 0 ? x : gc(y, x%y);
}

void get(){
	ll sum = 0;
	for(int i=1;i<=n;i++)sum += A[i] - 1;
	if(sum & 1){
		output(0);
	}
	for(int i=1;i<=n;i++)if(A[i] == 1){
		output(1);
	}
	int cnt = 0, f = -1;
	for(int i=1;i<=n;i++)if(A[i] & 1)cnt++, f = i;
	if(cnt > 1){
		output(1);
	}
	A[f]--;
	int g = 0;
	for(int i=1;i<=n;i++)g = gc(g, A[i]);
	for(int i=1;i<=n;i++)A[i] /= g;
	flip ^= 1;
	get();
}

void solve(){
	scanf("%d", &n);
	for(int i=1;i<=n;i++)scanf("%d", A+i);
	if(n == 1){
		output(1);
	}
	get();
}

int main(){
	int Tc = 1; //scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
//#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
#define rep(i,a,n) for(Int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(Int (i)=(a); (i)<=(n); (i)++)
const int MAX_N = 1000000;
const Int MAX_N_Int = 1000000000000;

template <typename T>
void printV(const std::vector<T>& v, const char * const separator = " ")
{
    if(!v.empty())
    {
        std::copy(v.begin(),
                  --v.end(),
                  std::ostream_iterator<T>(std::cout, separator));
        std::cout << v.back() << "\n";
    }
}

int D;
string str,s,u;
vector<int>c(26);
vector<int>t(366);
vector<vector<int>> ss(366, vector<int>(26));
//vector<vector<int>> last(365, vector<int>(26));
vector<int> last(26);
int satisfaction=0;
int init_score;

int init(){
    vector<int>c_copy(26);
    c_copy=c;
    rsort(c_copy);
    for (int i = 0; i < D; ++i) {
        t[i]=1;
    }

    return 0;

}

int score(){
    for (int d = 0; d < D; ++d) {
        int i = t[d]-1;
        satisfaction+=ss[d][i];

        last[i]=d+1;
        for (int cc = 0; cc < 26; ++cc) {
            satisfaction-=c[cc]*((d+1)-last[cc]);
        }
        //cout<<satisfaction<<endl;
    }

    return satisfaction;
}

int loop(){
    int old_score=init_score;
    int new_score=0;
    for (int d = 0; d < D; ++d) {
        int now=t[d];
        t[d]++;
        new_score=score();
        if(new_score<=old_score){
            t[d]=now;
            continue;
        }else{
            old_score=new_score;
        }
        //cout<<d<<" "<<new_score<<endl;
    }


    return 0;
}

int main() {
    IOS;
    prec;

    cin>>D;
    rep(i,0,26)cin>>c[i];
    for (int y = 0; y < D; ++y) {
        for (int x = 0; x < 26; ++x) {
            cin>>ss[y][x];
        }
    }
    //rep(i,0,D)cin>>t[i];
    //cout<<score();
    init();
    init_score=score();
    loop();
    for (int j = 0; j < D; ++j) {
        cout<<t[j]+1<<endl;
    }
    //cout<<satisfaction;









    cout<<endl;
    return 0;
}


Measured memory_bytes: 3664
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        string word = rstr();
        int leng = word.Length;
        int count = 0;
        int ans = 0;
        for(int i=0;i<leng;i++){
            if(word[i] == 'A'||word[i] == 'T'||word[i] == 'C'||word[i] == 'G'){
                count++;
                ans = Max(ans,count);
            }else{
                count = 0;
            }
        }
        WriteLine(ans);
    }
    
    
    
    
    //各種読取
    static string rstr(){
        return ReadLine();
    }
    static int rint(){
        return int.Parse(ReadLine());
    }
    static string[] stra(){
        return ReadLine().Split(' ');
    }
    static int[] inta(){
        string[] read_str_array = ReadLine().Split(' ');
        int[] return_int_array = new int[read_str_array.Length];
        for(int countup_i=0;countup_i<read_str_array.Length;countup_i++){
            return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
        }
        return return_int_array;
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int main(){
	int t,d,l;
	while(cin >> t >> d >> l)
	{
		if(t==0) break;

		int ans = 0;
		int en = -1;
		for(int i=0;i<t;i++)
		{
			if(i<=en)
			{
				ans++;
			}
			int x;
			cin >> x;
			if(x >= l)
			{
				en = i + d;
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;
int main(void){
    ll x,y=100;
    cin>>x;
    for(ll i=1;i<=1000000;i++){
        y=y*1.01;
        if(y>=x){
            cout<<i<<endl;
            return 0;
        }
    }
}

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

#include <algorithm>

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;
const ll INFLL = 1000000000000000007LL;

void solve() {
  int N;
  cin >> N;
  vector<int> A(N, 0);
  map<int, int> cnt;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    cnt[A[i]]++;
  }
  map<int, ll> cmb;
  ll ans = 0;
  for (auto m : cnt) {
    ll tmp = cnt[m.first];
    ans += (tmp * (tmp - 1)) / 2;
  }
  for (int i = 0; i < N; i++) {
    ll tmp = cnt[A[i]];
    ll ans_i = ans - (tmp * (tmp - 1)) / 2;
    if (cnt[A[i]] > 2) ans_i += ((tmp - 1) * (tmp - 2)) / 2;
    cout << ans_i << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // cout << fixed << setprecision(12);

  solve();

  return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
void read(pp& x){ scanf("%d%d",&x.first, &x.second); }
void read(pll& x){ scanf("%lld%lld",&x.first, &x.second); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define sz(x) (int)(x).size()

int n;
ll W;
vector<ll> val[4];
ll base;

int main()
{
	read(n, W);
	rep(i, n){
		ll w, v;
		read(w, v);
		if(!i) base=w;
		val[w-base].eb(v);
	}
	rep(i, 4){
		auto& v=val[i];
		sort(all(v), greater<ll>());
		partial_sum(all(v), v.begin());
	}
	int s0=val[0].size();
	int s1=val[1].size();
	int s2=val[2].size();
	int s3=val[3].size();
	ll ans=0;
	rep(i0, s0+1)
	rep(i1, s1+1)
	rep(i2, s2+1)
	rep(i3, s3+1){
		if((i0+i1+i2+i3)*base+i1+i2*2+i3*3 <= W){
			ans=max(ans, (i0?val[0][i0-1]:0ll)+(i1?val[1][i1-1]:0ll)+(i2?val[2][i2-1]:0ll)+(i3?val[3][i3-1]:0ll));
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[]args){
	Scanner sc=new Scanner(System.in);
	int w=sc.nextInt();
	int n=sc.nextInt();
	int[] values =new int[w];

//Save memory
	for(int i=0;i<values.length;i++){
		values[i]=i+1;
	}
	for(int i=0;i<n;i++){
		String str=sc.next();
		String[] ab=str.split(",");
		int a=Integer.parseInt(ab[0])-1;
		int b=Integer.parseInt(ab[1])-1;
		int temp=values[a];
		values[a]=values[b];
		values[b]=temp;
	}
	for(int j=0;j<w;j++){
		System.out.println(values[j]);
	}
	}
}

Measured memory_bytes: 17200
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
#include <string.h>
using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)



int c[26];
signed main(){
	
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++)
		c[s[i] - 'a'] ++;

	for (int i = 0; i < 26; i++)
		if (c[i] % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 256
<?php  
$stdin1 = trim(fgets(STDIN));  
$array1 = explode(' ', $stdin1);
$numA = $array1[0];
$numB = $array1[1];
$lastNum = $numA;
$flgCount = 0;
$static = 1000;

while (true) {
  if ($numA % $numB === 0) {
    echo 0;
    break;
  }
  
  if ($numA > $numB * $static) {
    $numB = $numB * $static;
    $flgCount++;
  }
  
  if ($flgCount > 0 && $numA < $numB) {
    $numB = $numB / $static;
    $flgCount--;
  }

  $numA = abs($numA - $numB);
  
  if ($lastNum <= $numA) {
    echo $lastNum;
    break;
  }
  $lastNum = $numA;
}

Measured memory_bytes: 4604
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		long a = sc.nextLong();
		long b = sc.nextLong();
		long x = sc.nextLong();
      	long aa,bb;
      	
      	aa = a/x;
      	if(a%x == 0) aa--;
      	bb = b/x;     	

		System.out.println(bb-aa);
	}
}

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

const int pw10[10] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};

inline int lg(const int x) {return std::upper_bound(pw10, pw10 + 10, x) - pw10 - 1;}

int f[20][2][2];

int solve(int L, int D) {
	int i, hi, lo, hi_, lo_, cur;
	int lc, rc, ld, rd, lc_, rc_;
	memset(f, 0, sizeof f), f[0][0][0] = 1;
	for (i = 0; i < L / 2; ++i) {
		hi = D / pw10[std::min(L - i - 1, 9)] % 10, lo = D / pw10[i] % 10;
		for (lc = 0; lc < 2; ++lc)
			for (rc = 0; rc < 2; ++rc) if ((cur = f[i][lc][rc])) {
				hi_ = hi - (lc ? 10 : 0);
				lo_ = lo + rc;
				for (ld = 0; ld < 10; ++ld) {
					rd = (ld + lo_) % 10;
					if (!(i || rd)) continue;
					if (ld - rd == hi_) lc_ = 0;
					else if (ld - rd == hi_ + 1) lc_ = 1;
					else continue;
					rc_ = (rd - ld == lo_ ? 0 : 1);
					f[i + 1][lc_][rc_] += cur;
				}
			}
	}
	if (!(L & 1)) return f[L / 2][0][0] + f[L / 2][1][1];
	switch (D / pw10[L / 2] % 10) {
		case 0: return 10 * f[L / 2][0][0];
		case 9: return 10 * f[L / 2][1][1];
		default: return 0;
	}
}

int main() {
	int i, n, d, ans = 0;
	if (scanf("%d", &n), n % 9) return putchar(48), putchar(10), 0;
	assert(n), d = 1 + lg(n), assert(d <= 9);
	for (i = d; i <= 2 * d; ++i) ans += solve(i, n);
	return printf("%d\n", ans), 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <complex>
#include <queue>
#include <stack>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

int f(int n){
  if(n%2)return 3*n+1;
  return n/2;
}

void run(){
  int s;
  cin>>s;
  vi v(1000001);
  int a;
  REP(i,1,1000000){
    if(i==1)a=s;
    else a=f(a);
    if(!v[a])v[a]=i;
    else {
      cout<<i<<endl;
      break;
    }
  }
}


Measured memory_bytes: 8064
import java.util.*;


public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int M = scan.nextInt();
		int D = scan.nextInt();
		int count =0;
		int i =0,j=0;
		for ( i=1;i<M+1;i++) {
		for ( j=21;j<D+1;j++) {
			int d1= j/10, d2=j%10;
			if (d1 >=2 && d2 >=2 && d1*d2 == i) {
				count++;
				//System.out.println(i + " " + d1+""+ d2);
			}
		}
		}
		System.out.println(count);
	}
}
		
	

Measured memory_bytes: 21844
import sys
from itertools import permutations
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    P=tuple(map(int,input().split()))
    Q=tuple(map(int,input().split()))
    a=-1
    for i,x in enumerate(permutations(range(1,N+1))):
        if x==P or x==Q:
            if a==-1:
                a=i
            else:
                print(abs(i-a))
                exit()
    print(0)

if __name__ == '__main__':
    main()


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

using namespace std;

//#define FILE_IO

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    srand(time(0));

    int N, x;
    scanf("%d%d", &N, &x);

    if(x == 1 || x == 2 * N - 1)
    {
        printf("No\n");
        return 0;
    }

    if(N == 2)
    {
        printf("Yes\n");
        printf("1\n");
        printf("2\n");
        printf("3\n");
        return 0;
    }

    vector <int> v;
    for(int i = 2; i < 2 * N - 1; i++)
        if(i != x)
            v.push_back(i);

    random_shuffle(v.begin(), v.end());

    vector <int> ans;
    ans.resize(2 * N + 5);
    ans[N] = x;

    if(x == 2)
    {
        ans[N + 1] = 1;
        ans[N - 1] = 2 * N - 1;
        ans[N + 2] = 2 * N - 2;
        for(int i = 0; i < v.size(); i++)
            if(v[i] == 2 * N - 2)
            {
                v.erase(v.begin() + i);
                break;
            }
    }
    else
    {
        ans[N - 1] = 1;
        ans[N + 2] = 2;
        ans[N + 1] = 2 * N - 1;
        for(int i = 0; i < v.size(); i++)
            if(v[i] == 2)
            {
                v.erase(v.begin() + i);
                break;
            }
    }



    for(int i = 1; i <= 2 * N - 1; i++)
        if(!ans[i])
        {
            ans[i] = v.back();
            v.pop_back();
        }

    printf("Yes\n");
    for(int i = 1; i <= 2 * N - 1; i++)
        printf("%d\n", ans[i]);

    return 0;
}


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

int main()
{
    int i, n, m, a[10000], sum;
    sum = 0;
    cin >> n >> m;
    for (i = 0; i < m; i++)
    {
        cin >> a[i];
        sum = sum + a[i];
    }
    n = n - sum;
    if (n < 0)
    {
        cout << "-1" << endl;
    }
    else
    {
        cout << n << endl;
    }

    return 0;
}

Measured memory_bytes: 3656
/*
मनस्वी म्रियते कामं कार्पण्यं न तु गच्छति ।
अपि निर्वाणमायाति नानलो याति शीतताम् ॥
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
    ll n;
    cin>>n;

    vl v(n);

    ll sum = 0;

    map<ll,ll> m;

    forn(i,0,n)
    {
        cin>>v[i];
        sum += v[i];
        m[v[i]]++;
    }

    ll k;
    cin>>k;
        
    ll a,b;
    forn(i,0,k)
    {
        cin>>a>>b;
        if(m.find(a) != m.end())
        {
            sum += (b-a)*m[a];
            m[b] += m[a];
            m.erase(a);
        }
        cout<<sum<<endl;
    }    
        












    return 0;
}       

Measured memory_bytes: 7944
N,K=map(int,input().split())
l=[]
ans=10**9

for _ in range(N):
    l.append(int(input()))
    
l.sort()
temp=l[0:K]
ans=min(ans,temp[-1]-temp[0])

for i in range(N-K):
    temp.pop(0)
    temp.append(l[K+i])
    ans=min(ans,temp[-1]-temp[0])

print(ans)

Measured memory_bytes: 7832
#include<iostream>
#include<string>
#include<ctype.h>
 
std::string s;
std::string::iterator it;
 
int term();
int fact();
 
// ?¨????
int expr()
{
    int p = term();
     
    // + or -
    while( *it == '+' || *it == '-' ){
        if( *it == '+' ){
            it++;
            int q = term();
            p += q;
        }
        else{
            it++;
            int q = term();
            p -= q;
        }
    }
     
    return p;
}
 
// ???????¨????
int term()
{
    int p = fact();
     
    while( *it == '*' || *it == '/' ){
        if( *it == '*' ){
            it++;
            int q = fact();
            p *= q;
        }
        else{
            it++;
            int q = fact();
            p /= q;
        }
    }
     
    return p;
}
 
// ??¬??§??? or ??°???
int fact()
{
    if( *it == '(' ){
        it++;
        int p = expr();
        it++;
         
        return p;
    }
    else{
        int p = 0;
         
        while( isdigit( *it ) ){
            p *= 10;
            p += *it - '0';
            it++;
        }
         
        return p;
    }
}
 
int main()
{
    int n;
    std::cin >> n;
     
    while( n-- ){
        std::cin >> s;
        s[s.size()-1] = '\0';
        it = s.begin();
        std::cout << expr() << std::endl;
    }
 
    return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<cassert>
#include<sstream>
#include<complex>
#include<cstdio>
#include<climits>
#include<cstdlib>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<ctime>
#include<cctype>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS) 
#define all(n) (n).begin(),(n).end()
#define MOD (1000000007LL)

using namespace std;
typedef long long ll;
int N,W;

int main()
{

  cin >> N >> W;
  vector<int> w(N);
  rep(i,N)cin >> w[i];
  sort(all(w));
  
  int sum[N];
  rep(i,N)
    {
      if(i == 0)sum[i] = w[i];
      else      sum[i] = w[i] + sum[i-1];
    }

  ll dp[W+1];
  rep(i,W+1)dp[i] = 0;
  dp[0] = 1;
  ll ans = 0;

  for(int i=N-1;i>=0;i--)
    {
      if(w[i] > W)continue;

      int cost=(i-1<0?0:sum[i-1]);
      for(int j=max(0,W-(int)w[i]+1-cost);j<=W-cost;j++)
	{
	  ans = (ans+dp[j])%MOD;
	}

      for(int j=W;j>=0;j--)
	{
	  if(dp[j] == 0)continue;
	  if(j+w[i] > W)continue;
	  dp[j+w[i]] = (dp[j+w[i]]+dp[j]) % MOD;
	}
      /*
      if(i == 0)continue;
      int cost = (i-2<0?0:sum[i-2]);
      for(int j=max(0,W-(int)w[i-1]+1-cost);j<=W-cost;j++)
	{
	  ans = (ans+dp[j])%MOD;
	}
      */
    }

  //ans = (ans+dp[W])%MOD;

  if(ans == 0)ans = 1;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1280
#!/usr/bin/env python

s=input()
t=input()

if(len(s)>len(t)):
    min_len=len(t)
else:
    min_len=len(s)

ss=[]
for num in range(0, len(s)):
    ss.append(s[num])

tt=[]
for num in range(0, len(t)):
    tt.append(t[num])

ss.sort()
tt.sort()
tt.reverse()

if(ss>=tt):
    print("No")
else:
    print("Yes")

# print(ss)
# print(tt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
ll n;
long double mem[305][305][305];
long double search(ll a, ll b, ll c){
  if(mem[a][b][c]){
    return mem[a][b][c];
  }
  long double ans = 0;
  if(!a && !b && c==1) return n;
  if(a) ans += (long double)search(a-1, b+1, c) * a / (a+b+c);
  if(b) ans += (long double)search(a,b-1, c+1) * b / (a+b+c);
  if(c) ans += (long double)search(a,b,c-1) * c / (a+b+c);
  ans += (long double)n/(a+b+c);
  mem[a][b][c] = ans;
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  ll a= 0, b=0, c=0;
  REP(i,n){
      ll tmp ; cin >> tmp;
      if(tmp==3)a++;
      if(tmp==2)b++;
      if(tmp==1)c++;
  }
  long double ans = search(a,b,c);
  printf("%.12Lf\n",ans);


}

Measured memory_bytes: 436480
#![allow(non_snake_case)]
#![allow(unused_imports)]
use ascii::AsciiChar;
use ascii::AsciiStr;
use itertools::Itertools as _;
use permutohedron::LexicalPermutation as _;
use petgraph::algo::dijkstra;
use petgraph::algo::min_spanning_tree;
use petgraph::data::FromElements;
use petgraph::graph::NodeIndex;
use petgraph::graph::UnGraph;
use petgraph::unionfind::UnionFind;
use proconio::fastout;
use proconio::input;
use proconio::marker::Chars;
use proconio::marker::Usize1;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use superslice::Ext as _;

#[fastout]
fn main() {
    input! {
        N: usize,
        K: i64,
    }

    let mut ans: i64 = 1;

    for i in 0..N {
        if ans > K {
            ans += K
        } else {
            ans *= 2;
        }
    }

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


Measured memory_bytes: 2096
#include<iostream>
#include<cstdlib>
#include<stdio.h>
using namespace std;

int main()
{
 long long int a[25]={1};
 a[0]=0;
 a[1]=1;
 for (int i=2;i<25;i++)
 {
     a[i]=a[i-1]*i;
 }

 int n;

 while (cin >> n)
 {
 cout << a[n] << "\n";
 }

 return 0;
}

Measured memory_bytes: 1156
def unbounded_knapsack(items, target_value)
	table = [0]
	i = 0
	hash = {0 => 0}
	loop {
		i += 1
		table[i] = 0
		items.each{|c, v|
			next if c > i
			x = table[i-c] + v
			table[i] = x if x > table[i]
		}
		hash[table[i]] ||= i
		return hash.to_a if table[i] >= target_value
	}
end

loop {
	n = gets.to_i
	break if n == 0
	enemies = (1..n).map{gets.to_i}.sort
	m = gets.to_i
	single_spells = []
	all_spells = []
	zero = false
	(1..m).each{
		_, cost, type, damage = gets.chomp.split
		if cost == ?0
			if damage == ?0
				next
			else
				zero = true
			end
		end
		next if damage == ?0
		
		if type == 'Single'
			single_spells << [cost, damage].map(&:to_i)
		else
			all_spells << [cost, damage].map(&:to_i)
		end
	}

	if zero
		puts 0
		next
	end

	single_cost = (single_spells.empty? ? [] : unbounded_knapsack(single_spells, enemies.max))
	all_cost = (all_spells.empty? ? [] : unbounded_knapsack(all_spells, enemies.max))

	if all_cost.empty?
		cost = 0
		enemies.each{|hp|
			cost += single_cost.find{|v, c| v >= hp}[1]
		}
		puts cost
	elsif single_cost.empty?
		hp = enemies.max
		puts all_cost.find{|v, c| v >= hp}[1]
	else
		min = Float::INFINITY
		(0..enemies.max).each{|limit|
			all_cost.shift until all_cost[0][0] >= limit
			cost = all_cost[0][1]
			break if cost >= min
			
			l = 0
			enemies.each{|hp|
				if hp > limit
					l += 1 until single_cost[l][0] >= hp - limit
					cost += single_cost[l][1]
					break if cost >= min
				end
			}
			min = cost if cost < min
		}
		p min
	end
}

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

ll N, K, t, d, sum, ans;
vector<ll> F, S;
vector<pair<ll, ll>> v;
map<ll, ll> mp;

main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> t >> d;
        v.push_back(make_pair(t, d));
    }
    sort(v.rbegin(), v.rend());
    for (int i = 0; i < v.size(); i++) {
        pair<ll, ll> p = v[i];
        if (mp[p.first] == 0) F.push_back(p.second);
        else S.push_back(p.second);
        mp[p.first]++;
    }
    sort(F.rbegin(), F.rend());
    sort(S.rbegin(), S.rend());
    ll L = F.size(), M = S.size();
    for (int i = 0; i < min(K, L); i++) sum += F[i];
    if (K > L) {
        int check = 0;
        for (ll i = 0; i < K - L; i++) sum += S[i], check = i;
        check++, ans = sum + L * L;
        for (ll j = L - 1; j > 0 && check < M; check++, j--) {
            sum = sum - F[j] + S[check];
            ans = max(ans, sum + j * j);
        }
        cout << ans << endl;
    }
    else {
        ans = sum + K * K;
        for (ll i = 0; i < K - 1 && i < M; i++) {
            sum -= F[K - 1 - i];
            sum += S[i];
            ans = max(ans, sum + (K - i - 1) * (K - i - 1));
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 8816
import heapq
n,m = (int(i) for i in input().split())
ab = []
for i in range(n):
  tmp = [int(i) for i in input().split()]
  ab.append(tmp)
ab.sort()
heap = []
cur = 0
ans = 0

for i in range(1, m+1):
  while  (cur < n) and (ab[cur][0] <= i):
    heapq.heappush(heap, -ab[cur][1])
    cur += 1
  if heap:
    ans += -heapq.heappop(heap)
print(ans)

Measured memory_bytes: 25448
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;
int main() {
	int N, p[100000], ans;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &p[i]);
	}
	ans = 0;
	for (int i = 0; i < N; i++) {
		if (p[i] - 1 == i) {
			ans++; i++;
		}
	}

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

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    
    vec<int> p(N);
    rep(i, N) cin >> p[i];
    int ans = 0;
    bool b = false;
    rep(i,N){
        int t = i+1;
        if(p[i] == t && b) b=false;
        else if(p[i]==t && !b) {
            ++ans;
            b = true;
        } else if(p[i] != t && b){
            b = false;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3760
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n,m,c = map(int,input().split())
    base_data=[]
    source_codes=[]
    base_data=list(map(int,input().split()))
    source_codes=[list(map(int,input().split())) for _ in range(n)]
    ans=0
    cnt=0

    for i in range(n):
        for j in range(m):
            ans+=source_codes[i][j]*base_data[j]
        ans=ans+c
        if ans > 0:
            ans=0
            cnt+=1
        else:
            ans=0
            continue
    
    print(cnt)    
    
if __name__=="__main__":
    main()

Measured memory_bytes: 9252