akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func newInt() int {
  sc.Scan()
  i, _ := strconv.Atoi(sc.Text())
  return i
}

func main() {
  k := newInt()
  
  s := 7 % k
  for i := 1; i <= k; i++ {
    if s == 0 {
      fmt.Println(i)
      return
    }
    s = (s * 10 + 7) % k
  }
  fmt.Println(-1)
}

Measured memory_bytes: 1776
ans' [] _ _ = "YES"

ans' (i:is) (a:as) (b:bs)
  | (i>a) && (a>b) = if   ans' is (i:a:as) (b:bs) == "YES"
                     then "YES"
                     else ans' is (a:as) (i:b:bs)
  | (a>i) && (i>b) =      ans' is (a:as) (i:b:bs)
  | (a>b) && (b>i) = "NO"
  | otherwise      =      ans' (i:is) (b:bs) (a:as)
  
ans i = ans' i [0] [-1]

main = do
  n <- getLine
  c <- getContents
  let n' = read n :: Int
      i = map (map read) $ map words $ take n' $ lines c :: [[Int]]
      o = map ans i
  mapM_ putStrLn o
  

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

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


ll n,k;
vll G[100005];
ll dist[100005];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>k;
  rep(i,n-1){
    ll a,b; cin>>a>>b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  queue<pll> q;
  q.emplace(0,0);
  vb visited(n);
  dist[0]=k;
  
  while(!q.empty()){
    auto p=q.front(); q.pop();
    ll v=p.first, c=p.second;
    visited[v]=true;
    ll color;
    if(c==0) color=k;
    else if(c==1) color=k-1;
    else color=k-1;
    for(auto nv: G[v]){
      if(visited[nv]) continue;
      dist[nv]=--color;
      // cout<<nv<<" "<<dist[nv]<<endl;
      q.emplace(nv,c+1);
    }
  }
  
  ll ans=1;
  rep(i,n){
    // cout<<dist[i]<<endl;
    ans*=dist[i];
    ans%=MOD;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 8948
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
 ll n,m,i,ans,c,x,y;
 cin>>n;
 ll k=n%1000;
 if(!k)cout<<0;
 else cout<<1000-k;
}


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

using namespace std;
#define int long long
int MOD = 1000000007;

signed main(){
    string O,E;
    cin >> O >> E;
    
    int o=0,e=0;
    for(int i=0;i<O.length()+E.length();i++){
        if(i%2==0){
            cout << O[o];
            o++;
        }else{
            cout << E[e];
            e++;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;

#define REPP(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)
#define PER(i,a) for(int i = (a) - 1; i >= 0; --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair

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

int main() {
  int n;
  scanf("%d", &n);
  vector<ll> v(n);
  for (ll& x : v) {
    scanf("%lld", &x);
    if (x == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll res = 1;
  for (ll& x : v) {
    if (x < 2e18 / res) res *= x;
    else {
      res = -1;
      break;
    }
  }
  if (res > (long long) 1e18) res = -1;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4032
#include <iostream>
#include <math.h>
int main()
{
    int a ;
    float keta,count ;
    long long ans = 1 ;
    std::cin >> a ;
    long long A[a] ;
    keta = 0 ;
    for (int i = 0 ; i < a ; i++)
    {
        std::cin >> A[i] ;
        count = log10(A[i]) ;
        keta = keta + count ;
        if (A[i] == 0)
        {
            ans = 0 ;
            break ;
        }
    }
  
    for (int i = 0 ; i < a ; i++)
    {
        if (ans == 0) break ;
        if (keta > 18)
        {
          std::cout << -1 << std::endl;
          break ;
        }
          
        ans = ans * A[i] ;
        if(ans > 1000000000000000000)
        {
          std::cout << -1 << std::endl;
          break ;
        }

    }
  if (ans <= 1000000000000000000 && keta <= 18 && ans >= 0)
  std::cout << ans << std::endl;
}

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const int N = 200010;
int n, a[N];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  
  int j = 0, sm = 0, x = 0;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    sm += a[i];
    while ((x ^ a[i]) != sm) {
      x ^= a[j];
      sm -= a[j];
      j++;
    }
    x ^= a[i];
    ans += (i - j + 1);
  }
  printf("%lld\n", ans);
}



Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n, m;
    cin >> n >> m;
    vector< pair<ll, ll> > V(n, make_pair(0,0));
    REP(i, n) cin >> V[i].first >> V[i].second;
    sort(ALL(V));
    // REP(i,n) cout <<i << " "<< V[i].first << " " << V[i].second << endl;
    ll ans=0;
    REP(i,n){
        // cout << i << "にいて，もう " << m << "個かいたい．お金はまだ"<<ans << endl;
        if(m >= V[i].second ) {
            ans += V[i].first * V[i].second;
            m -= V[i].second;
        }
        else {
            ans+= V[i].first * m;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#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()

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

    // start
    int n, k;
    cin >> n >> k;
    cout << (n % k == 0 ? "0" : "1") << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

using namespace std;
using ll = long long;

bool isUnique(map<int, int> &a)
{
	for (auto m : a) {
		if (m.second == 2)
			return false;
	}

	return true;
}

int main()
{
	int s;
	cin >> s;
	map<int, int> a;
	int ans = 1;
	a[s] = 1;
	while (isUnique(a)) {
		int tmp;
		if (s % 2 == 0)
			tmp = s / 2;
		else
			tmp = s * 3 + 1;
		a[tmp] += 1;
		ans++;
		s = tmp;
	}

	cout << ans << endl;
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author __shangu__
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CSwitches solver = new CSwitches();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSwitches {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt(), sta[] = new int[m], cur[] = new int[m];
            ArrayList<Integer> sw[] = new ArrayList[m];
            for (int i = 0; i < m; ++i) sw[i] = new ArrayList<>();

            for (int i = 0; i < m; ++i) {
                int k = in.nextInt();
                for (int j = 0; j < k; ++j) sw[i].add(in.nextInt() - 1);
            }

            for (int i = 0; i < m; ++i) sta[i] = in.nextInt();

            int ans = 0;
            for (int k = 0; k < 1 << n; ++k) {
                for (int i = 0; i < m; ++i) {
                    int on = 0;
                    for (Integer pos : sw[i]) {
                        if ((k >> pos & 1) == 1) ++on;
                    }
                    cur[i] = on % 2;
                }
                boolean ok = true;
                for (int i = 0; i < m && ok; ++i) {
                    if (sta[i] != cur[i]) ok = false;
                }
                if (ok) ++ans;
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



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

int main(void){
  int N;
  cin >> N;
  vector<long long> primes;
  vector<long long> ans;
  primes.reserve(100000);
  ans.reserve(N);
  primes.push_back(2);
  for(long long n = 3; n <= 55555 * 5; n++){
    int i;
    for(i = 0; i < primes.size(); i++){
      if(n % primes[i] == 0) break;
    }
    if(i >= primes.size()){
      primes.push_back(n);
      if(n % 5 == 1){
        ans.push_back(n);
        if(ans.size() >= N) break;
      }
    }
  }
  
  for(long long l : ans) cout << l << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
SWITCH = M.times.map { gets.split.map(&:to_i) }
P = gets.split.map(&:to_i)

def all_on?(rump)
  i = -1

  SWITCH.all? do |_, *s|
    cnt = 0

    s.each do |idx|
      cnt += 1 if rump[idx - 1]
    end

    i += 1
    cnt % 2 == P[i]
  end
end

ans = 0

[false, true].repeated_permutation(N).each do |list|
  ans += 1 if all_on?(list)
end

puts ans


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

def rootT(x):
  if T[x][0] == -1:
    return x, 0
  else:
    k, d = rootT(T[x][0])
    T[x][1] += d
    T[x][0] = k
    return k, T[x][1]

T = [[-1, 0] for _ in range(N + 1)]

Ans = "Yes"
for L, R, D in LRD:
  l, ld = rootT(L)
  r, rd = rootT(R)
  if l == r:
    if ld + D != rd:
      Ans = "No"
      break
  else:
    x = D + ld - rd
    if x < 0:
      x *= -1
      l, r = (r, l)
    T[r] = [l, x]

print(Ans)


Measured memory_bytes: 63068
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
	Scanner s = new Scanner(System.in);
	
	int a[] = new int[10];
	int top = 0;
	int second =0;
	int thard = 0;
	
	//???????????????
	for(int i = 0;i < 10;i++){
		a[i] = s.nextInt();
		if(i > 0){
			if(top <= a[i]){
				thard  = second;
				second = top;//?????????
				top = a[i];
			}else if(second <= a[i] && top >= a[i]){
				thard  = second;
				second = a[i];
			}else if(thard <= a[i] && second >= a[i]){
				thard = a[i];
			}
		}else{
			top = a[i];
		}
	}
	System.out.println(top);
	System.out.println(second);
	System.out.println(thard);
  }
}

Measured memory_bytes: 26044
/*
 * test.cpp
 *
 *
 *      Author: Fireworks
 */

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<cmath>
#include<bitset>
#include<set>
#include<iomanip>
#include<fstream>
#include<bitset>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<list>
#include<sstream>

using namespace std;

typedef pair<int,int> ii;
typedef pair<int,long long> il;
typedef pair<long long,long long> ll;
typedef pair<ll,int> lli;
typedef pair<long long,int> li;
typedef pair<double,double> dd;
typedef pair<ii,int> iii;
typedef pair<double,int> di;
typedef pair<ii,ii> iiii;
long long mod = 1000000007LL;
long long base = 37;
long long large = 1000000000000000000LL;


int up;
long long uv;
vector<long long> sum;
int sz;

void update(int o,int l,int r){
	if(l==r){
		sum[o]+=uv;
	}else{
		int m = (l+r)/2;
		if(up<=m) update(o*2,l,m);
		if(up>m) update(o*2+1,m+1,r);
		sum[o]=sum[o*2]+sum[o*2+1];
	}
}

int ql,qr;
long long re;
void query(int o,int l,int r){
	if(ql<=l&&qr>=r){
		re+=sum[o];
	}else{
		int m = (l+r)/2;
		if(ql<=m) query(o*2,l,m);
		if(qr>m) query(o*2+1,m+1,r);
	}
}
int main(){

	int n;
	cin>>n;
	vector<long long> s(n,0);
	long long k;
	cin>>k;
	for(int i=0;i<n;i++){
		cin>>s[i];
		if(i) s[i]+=s[i-1];
	}
	vector<long long> p(n,0);
	for(int i=0;i<n;i++){
		p[i]=1LL*(i+1)*k-s[i];
	}
	map<long long,int> comp;

	vector<long long> a=p;
	sort(a.begin(),a.end());
	a.erase(unique(a.begin(),a.end()),a.end());
	for(int i=0;i<(int)a.size();i++) comp[a[i]]=i;
	sz = (int)a.size();
	sum.assign(4*sz+10,0LL);
	long long ans = 0LL;
	for(int i=0;i<n;i++){
		qr=sz-1;
		ql=comp[p[i]];
		re=0LL;
		query(1,0,sz-1);
		ans+=re;
		uv=1LL;
		up=comp[p[i]];
		update(1,0,sz-1);
	}
	for(int i=0;i<n;i++) if(s[i]>=1LL*(i+1)*k) ans++;


	cout<<ans<<endl;



	/*int totalcase;
	int testcase=0;
	cin>>totalcase;
	ofstream out;
	out.open("result.txt");

	while(totalcase--){
		testcase++;
		out<<"Case #"<<testcase<<": ";
		cout<<testcase<<": "<<endl;

		//GOGOGO


		//END
	}
	out.close();*/

	return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll X; cin >> X;
	ll balance = 100LL;
	int year = 0;
	while (balance < X) {
		balance = floor(1.01*balance);
		year++;
	}
	cout << year << "\n";
	return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    int N; cin >> N;
    if(N) {AA(0);}
    else AA(1);
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define sf1(n) scanf("%d",&n)
#define sf2(n,q) scanf("%d %d",&n,&q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar,false) memset(ar,false,sizeof(ar))
#define mpr make_pair
#define endl "\n"
#define mod 1000000007
#define inf 9000000000000000000LL
#define M 200005

using namespace std;

int ar[300005];
int dp[300005];

int tree[300005 * 4];
void init(int node, int b, int e)
{
    if (b == e) {
        tree[node] = 0;
        return;
    }
    int Left = node * 2;
    int Right = node * 2 + 1;
    int mid = (b + e) / 2;
    init(Left, b, mid);
    init(Right, mid + 1, e);
    tree[node] = max(tree[Left],tree[Right]);
}
int query(int node, int b, int e, int i, int j)
{
    if (i > e || j < b)
        return 0;
    if (b >= i && e <= j)
        return tree[node];
    int Left = node * 2;
    int Right = node * 2 + 1;
    int mid = (b + e) / 2;
    int p1 = query(Left, b, mid, i, j);
    int p2 = query(Right, mid + 1, e, i, j);
    return max(p1,p2);
}
void update(int node, int b, int e, int i, int newvalue)
{
    if (i > e || i < b)
        return;
    if (b >= i && e <= i) {
        tree[node] = newvalue;
        return;
    }
    int Left = node * 2;
    int Right = node * 2 + 1;
    int mid = (b + e) / 2;
    update(Left, b, mid, i, newvalue);
    update(Right, mid + 1, e, i, newvalue);
    tree[node] = max(tree[Left],tree[Right]);
}
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,k;
    cin >> n >> k;

    for(int i=0;i<n;i++)
    {
        cin >> ar[i];
    }
    init(1,1,300001);

    int ans = 0;
    for(int i=0;i<n;i++)
    {
        int l = ar[i]-k;
        int r = ar[i]+k;
        l = max(l,0);
        r = min(r,300000);


        dp[ar[i]] = 1+query(1,1,300001,l+1,r+1);

        ans = max(ans,dp[ar[i]]);
        update(1,1,300001,ar[i]+1,dp[ar[i]]);
    }
    cout <<ans << endl;
    return 0;

}


Measured memory_bytes: 10060
#include <stdio.h>

int main(void)
{
	double x, max, min;
	
	scanf("%lf", &x);
	max = min = x;
	while (scanf("%lf", &x) != EOF) {
		if (x > max) {
			max = x;
		}
		if (x < min) {
			min = x;
		}
	}
	printf("%.1f\n", max - min);
	return (0);
}

Measured memory_bytes: 652
h,w,n = gets.split.map(&:to_i)
lis = []
for i in 0...h do
  s = gets.chomp.chars
  lis.push(s)
end
ans = 0
for i in 0...2**h do
  for j in 0...2**w do
    cnt = 0
    for k in 0...h do
      for l in 0...w do
        if (i&(2**k)==2**k) && (j&(2**l)==2**l) && (lis[k][l]=='#')then
          cnt +=1
        end
      end
    end
    if cnt==n then
      ans += 1
    end
  end
end
puts ans

Measured memory_bytes: 14300
/*input
10 1000000000000000000
0 0 1 1 0 0 0 1 1 0
0 0 0 0 0 1 1 1 0 0
0 1 0 0 0 1 0 1 0 1
1 1 1 0 1 1 0 1 1 0
0 1 1 1 0 1 0 1 1 1
0 0 0 1 0 0 1 0 1 0
0 0 0 1 1 0 0 1 0 1
1 0 0 0 1 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
1 0 1 1 1 0 1 1 1 0

3 3
0 1 0
1 0 1
0 0 0

4 2
0 1 0 0
0 0 1 1
0 0 0 1
1 0 0 0
*/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long int ll;

const ll inf = 1e9;
const int mod=1000000007;

ll n;
ll K;

vector<vector<ll>>adj;
vector<vector<ll>>answer;
vector<vector<ll>>identity;

vector<vector<ll>>mulmat(vector<vector<ll>>a, vector<vector<ll>>b){
    vector<vector<ll>>ret;
    ret.resize(n, vector<ll>(n, 0));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            for(int k = 0; k < n; ++k){
                ret[i][j] = (ret[i][j] + (a[i][k] * b[k][j]) % mod) % mod;
            }
        }
    }
    return ret;
}

// int pow(int a, int p){
//     if(p == 0)return 1;
//     int half = pow(a, p/2);
//     if(p % 2 == 0)
//         return half*half;
//     else return a*half*half;
// }

vector<vector<ll>> MatPow(vector<vector<ll>>mat, ll k){
    if(k == 0){
        return identity;
    }
    vector<vector<ll>>half = MatPow(mat, k / 2);    
    if(k % 2 == 0)
        return mulmat(half, half);
    else
        return mulmat(mat, mulmat(half, half));
}

int main(){
    #if ONLINE_JUDGE
        ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    #endif

    cin >> n >> K;        

    adj.resize(n, vector<ll>(n, 0));

    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            cin >> adj[i][j];
        }
    }

    identity.resize(n, vector<ll>(n, 0));

    for(int i = 0; i < n; ++i)
        identity[i][i] = 1;

    vector<vector<ll>>v = MatPow(adj, K);

    ll ans = 0;

    for(int i = 0; i < n; ++i){
    	for(int j = 0; j < n; ++j){
            ans = (ans + v[i][j]) % mod;
    	}
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1664
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
n = int(input())
s = input()
cnt = 0
ans = 0
for i in s:
    if i == "I":
        cnt += 1
    else:
        cnt -= 1
    ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 5180
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

int n, k, f[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> k;
    int cnt = 0;
    ll res = 0;
    FOR(b,k+1,n) {
        int g = n / b;
        int h = n % b;
        if (h >= k) f[h]++;
        cnt++;
        res += (ll) g * cnt;
    }
    FORE(i,n,0) f[i] += f[i+1];
    FOR(r,max(1,k),n-1) res += f[r];

    cout << res;
    return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 1
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	char x,y;
	cin>>x>>y;

	if(x<y)cout<<"<"<<endl;
	else if(x>y)cout<<">"<<endl;
	else cout<<"="<<endl;

	return 0;
}

Measured memory_bytes: 256
N,A,B,C=map(int,input().split())
l=[int(input()) for i in range(N)]
INF=10**9

def dfs(cur,a,b,c):
    if cur == N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF
    ret0=dfs(cur+1,a,b,c)
    ret1=dfs(cur+1,a+l[cur],b,c)+10
    ret2=dfs(cur+1,a,b+l[cur],c)+10
    ret3=dfs(cur+1,a,b,c+l[cur])+10
    return min(ret0,ret1,ret2,ret3)

print(dfs(0,0,0,0))

Measured memory_bytes: 3064
using System;

namespace ABC046B_PaintingBallswithAtCoDeer
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');

            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);


            double result = k * Math.Pow(k - 1, n - 1);

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef long double ld;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
const int MOD=1e9+7;
const int N=1e5+5;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a)  (a).begin(),(a).end()

int n,tw;
int w[105];
int v[105];
int dpp[105][N];
int dp(int idx,int wt)
{
    if(wt>tw)
        return -1e15;
    if(idx==n+1)
        return 0;
    int &ans=dpp[idx][wt];
    if(ans!=-1)
        return ans;
    ans=max(dp(idx+1,wt),v[idx]+dp(idx+1,wt+w[idx]));
    return ans;
}


int32_t main()
{
    IOS;
    memset(dpp,-1,sizeof(dpp));
    cin>>n>>tw;
    for(int i=1;i<=n;i++)
        cin>>w[i]>>v[i];
    int ans=dp(1,0);
    cout<<ans<<endl;


}


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

int a,b,c;

int main(){
	cin>>a>>b>>c;
	if((a!=b)&&(a!=c)){
		cout<<a<<endl;
	}else if((b!=a)&&(b!=c)){
		cout<<b<<endl;
	}else{
		cout<<c<<endl;
	}
}

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

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

    int c500 = x / 500;
    int r500 = x % 500;
    int c5 = r500 / 5;

    cout << c500 * 1000 + c5 * 5 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,i,s=0;
	cin>>n;
	int v[n];
	for(i=0;i<n;i++){
		cin>>v[i];
	}
	int c[n];
	for(i=0;i<n;i++){
		cin>>c[i];	
	}
	for(i=0;i<n;i++){
		if(v[i]>c[i]){
			s=s+v[i]-c[i];
		}
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 504
from collections import deque
N,M=map(int,input().split())
tree=[[] for _ in range(N)]
paths=[]
cnt=0
for i in range(M):
    a,b=map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
    paths.append([a-1,b-1])
#print(tree)
for i in range(M):
    stop=paths[i]
    seen=[0]*N
    d=deque()
    d.append(0)
    while len(d)>0:
        v=d.popleft()
        seen[v]=1
        for j in tree[v]:
            if not(((v==stop[0])and(j==stop[1]))or((v==stop[1])and(j==stop[0])))and(seen[j]==0):
                d.append(j)
        #print(i,d,seen,stop)
        #input()
    if sum(seen)!=N:
        cnt=cnt+1
print(cnt)

Measured memory_bytes: 40432
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

enum { A, B, NA };
int f(string s){
    if(s.size() < 6) return NA;
    if(s.substr(0,2)==">'"){
        size_t i=2;
        while(i<s.size() && s[i]=='=') i++;
        if(i==2 || i==s.size() || s[i]!='#') return NA;
        size_t j=i+1;
        while(j<s.size() && s[j]=='=') j++;
        if(i-2 != j-i-1 || j==s.size() || s[j]!='~') return NA;
        return (j+1==s.size() && s[j]=='~') ? A : NA;
    } else if(s.substr(0,2)==">^"){
        size_t i=2;
        while(i<s.size() && s[i]=="Q="[i&1]) i++;
        if((i&1)==1 || i==2 || i==s.size() || s[i]!='~') return NA;
        return (i+2==s.size() && s.substr(i)=="~~") ? B : NA;
    } else {
        return NA;
    }
}

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        char res[3][3] = {"A","B","NA"};
        puts(res[f(s)]);
    }
}

Measured memory_bytes: 1204
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

#define INF LLONG_MAX / 5
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define enld endl

signed main() {
	int N, M;
	cin >> N >> M;
	vector<int>A(M);
	rep(i, M) {
		cin >> A[i];
	}
	set<int>S;
	rep(i, M) {
		S.insert(A[i]);
	}
	vector<int>dp(N+1);
	rep(i, N+1) {
		if (i == 0) {
			dp[i] = 1;
		}
		else if (i == 1) {
			if (S.count(i)) {
				dp[i] = 0;
			}
			else {
				dp[i] = 1;
			}
		}
		else {
			if (S.count(i)) {
				dp[i] = 0;
			}
			else {
				dp[i] = dp[i - 2] + dp[i - 1];
			}
		}
		dp[i] = dp[i] % 1000000007;
	}
	cout << dp[N] << endl;
}

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

template <long long mod, long long primitive_root>
struct NTT {
private:
    static long long mod_pow(long long n, long long p) {
        long long ret = 1;
        while (p > 0) {
            if (p & 1) ret = ret * n % mod;
            n = n * n % mod;
            p >>= 1;
        }
        return ret;
    }

    static pair<long long, long long> extgcd(long long a, long long b) {
        long long s = a, sx = 1, sy = 0, t = b, tx = 0, ty = 1;
        while (t) {
            long long q = s / t;
            s -= t * q;
            swap(s, t);
            sx -= tx * q;
            swap(sx, tx);
            sy -= ty * q;
            swap(sy, ty);
        }
        return {sx, sy};
    }

    static long long mod_inv(long long a) {
        long long inv = extgcd(a, mod).first;
        return (inv % mod + mod) % mod;
    }

    static void untt(vector<long long>& a) {
        int n = a.size();
        for (int m = n; m > 1; m >>= 1) {
            long long omega = mod_pow(primitive_root, (mod - 1) / m);
            for (int s = 0; s < n / m; s++) {
                long long w = 1;
                for (int i = 0; i < m / 2; i++) {
                    long long l = a[s * m + i];
                    long long r = a[s * m + i + m / 2];
                    a[s * m + i] = (l + r) % mod;
                    a[s * m + i + m / 2] = (l - r + mod) * w % mod;
                    w = w * omega % mod;
                }
            }
        }
    }

    static void iuntt(vector<long long>& a) {
        int n = a.size();
        for (int m = 2; m <= n; m <<= 1) {
            long long omega = mod_inv(mod_pow(primitive_root, (mod - 1) / m));
            for (int s = 0; s < n / m; s++) {
                long long w = 1;
                for (int i = 0; i < m / 2; i++) {
                    long long l = a[s * m + i];
                    long long r = a[s * m + i + m / 2] * w % mod;
                    a[s * m + i] = (l + r) % mod;
                    a[s * m + i + m / 2] = (l - r + mod) % mod;
                    w = w * omega % mod;
                }
            }
        }
    }


public:
    static vector<long long> convolution(const vector<long long>& a, const vector<long long>& b) {
        int size = a.size() + b.size() - 1;
        int n = 1;
        while (n < size) n <<= 1;
        vector<long long> na = a, nb = b;
        na.resize(n);
        nb.resize(n);
        untt(na);
        untt(nb);
        for (int i = 0; i < n; i++) na[i] = na[i] * nb[i] % mod;
        iuntt(na);
        na.resize(size);
        long long n_inv = mod_inv(n);
        for (int i = 0; i < size; i++) na[i] = na[i] * n_inv % mod;
        return na;
    }
};

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

    int N, M;
    cin >> N >> M;
    vector<ll> a(N), b(M);
    for (int i = 0; i < N; i++) cin >> a[i];
    for (int i = 0; i < M; i++) cin >> b[i];
    vector<ll> c = NTT<998244353, 3>::convolution(a, b);
    for (int i = 0; i < N + M - 1; i++) cout << c[i] << (i < N + M - 2 ? " " : "\n");
}

Measured memory_bytes: 31948
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

A = list(map(int, input().split()))

neg_cnt = 0
minimum = 10**10
for num in A:
    minimum = min(minimum, abs(num))
    if num < 0:
        neg_cnt += 1
        
ans = 0
for num in A:
    if num < 0:
        ans += -num
    else:
        ans += num 

if neg_cnt % 2 == 0:
    print(ans)               
else:
    print(ans - minimum * 2)

Measured memory_bytes: 64752
#include<iostream>
#include<algorithm>
typedef long long lint;
using namespace std;

int main()
{
	int N;
	int s[110]={};
	int sum=0;
	
	cin >> N;
	for(int i=0;i<N;i++)
	{
		cin >> s[i];
		sum+=s[i];
	}
	
	sort(s,s+N);
	if(sum%10==0)
	{
		for(int i=0;i<N;i++)
		{
			if(s[i]%10!=0)
			{
				sum-=s[i];
				break;
			}
		}
	}
	if(sum%10==0)cout << 0;
	else cout << sum;
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

#define N 200001

int parent[N];
int visited[N];
int num[N];
vector<vector<int>> edge(N, vector<int>(0));
vector<vector<int>> dame(N, vector<int>(0));
int findroot(int a){
  if (parent[a] == a)
    return a;

  int newparent = findroot(parent[a]);
  parent[a] = newparent;
  return newparent;
}

void dfs(int cur){
  if (visited[cur])
    return;

  visited[cur] = 1;
  for (int i = 0; i < edge[cur].size(); i++){
    int u = findroot(cur);
    int v = findroot(edge[cur][i]);
    if (u != v){
      parent[v] = u;
      num[u] = num[u] + num[v];
    }
    dfs(edge[cur][i]);
  }
}

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


  if (p != 2 && p != 5){
    vector<ll> dp(n + 1, 0);
    vector<ll> num(p + 1, 0);
    ll ten = 1;

    num[0]++;

    for (ll i = 1; i <= n; i++){
      dp[i] = ((ten * (s[n - i] - '0') + dp[i-1])) % p;
      ten = (ten * 10) % p;
      num[dp[i]]++;
    }

    ll res = 0;
    for (ll i = 0; i < p; i++){
      res += num[i] * (num[i] - 1)/2;
    }

    cout << res << endl;
  }
  else if (p == 2){
    ll res = 0;

    for (int i = 0; i < n; i++){
      if ((s[n - i - 1] - '0') % 2 == 0){
        res += n - i;
      }
    }
    cout << res << endl;
  }
  else {
    ll res = 0;

    for (int i = 0; i < n; i++){
      if ((s[n - i - 1] - '0') % 5 == 0){
        res += n - i;
      }
    }
    cout << res << endl;
  }


  return 0;
}


Measured memory_bytes: 11524
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vint num(n,1);
    vint red(n,0);
    red[0]=1;
    REP(i,m){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        if(red[x]==1){
            if(num[x]==1){
                red[x]=0;
                red[y]=1;
            }else{
                red[y]=1;
            }
        }
        num[x]--;
        num[y]++;
    }
    int ans=0;
    REP(i,n){
        ans+=red[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

        long l = sc.nextInt();
        long r = sc.nextInt();

//        int min =0;

//        if ((l<2019)&&(r<2019)){
//            min = Math.min(min)
//            System.out.println(l*(l+1)%2019);
//        }else if ((l<2019)&&(2019<=r)){
//            System.out.println(0);
//        }else if(l==2019){
//            System.out.println(0);
//        }else if ((2019<l)&&(r<=2019*2-1)){
//            System.out.println(l*(l+1)%2019);
//        }else if ((2019<l)&&(2019*2<=r)){
//            System.out.println(0);
//        }
         long min= l*(l+1)%2019;


        if ((l%2019==0) || (r%2019==0)){
            System.out.println(0);
        }else if ((l/2019)!=(r/2019)){
            System.out.println(0);
        }else if ((l/2019)==(r/2019)) {
            for (long i = l; i < r; i++) {
                for (long j = i + 1; j < r + 1; j++) {
                    min = Math.min(min, i * j % 2019);
                }
            }
            System.out.println(min);

        }
    }
}


Measured memory_bytes: 23508
#include "bits/stdc++.h"
#include <chrono>
#include <random>
#include <cstdio>
#define ll long long int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define pll pair<ll, ll>
#define pint pair<int, int>
#define S second
#define F first
#define all(c) (c).begin(),(c).end()
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500001;
// vector<pair<ll, ll> > adj[N];
// bool vis[N];
ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } 
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
#define pi 3.14159265358979323846264338
using namespace std; 
ll max(ll a, ll b){ if(a>b)return a;return b;}
ll min(ll a, ll b){ if(a < b) return a;return b;}
ll inf = 100000000000000000;
// vector<pair<int, char> > adj[N];


void solve()
{ 
    
    int n;
    cin>>n;

    int a = 0, b = 0, c = 0, d = 0;
    rep(i, n)
    {
        string s;
        cin>>s;

        if(s == "AC") a++;
        else if(s == "WA") b++;
        else if(s == "TLE") c++;
        else if(s == "RE") d++;

    }

    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;
}

int main()
{
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)
    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

#define F first    
#define S second
#define mp make_pair
#define pii pair<int,int>         
// mikty prikoldar
#define ll long long  
#define pb push_back
#define sz(a) (int)(a.size())
#define Accepted 0
#define endl '\n'
//everything goes according to the plan
#define y1 		 NOT
#define left   NEEDED
#define right  THINGS  
//countdown BEGAN. 10 , 9 , 8 ...
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 9223372036854775807;
const int Sz = 1110111;
// ai dyn dyn dyn dirindai ai dyn dyn dirindai
using namespace std;
// skr skr skr v chernih naikah
inline void Read_rap () {	// smoke weed everyday
  ios_base :: sync_with_stdio(0);
	cin.tie(0);      
}         
int n;

int a[Sz];

bool possible () {
  map <int, int> cnt;
  for (int i = 1;i <= n;i ++)	cnt[a[i]] ++;
	int d = cnt.rbegin() -> F; 
	int mid = d / 2 + d % 2;   
	                                
	for (int i = d;i >= mid+1;i --)
		if (cnt[i] < 2) {
			return 0;
		}	
	
	if (d & 1) {
		return (cnt[mid] == 2);
	}
	return (cnt[mid] == 1);
}	
	 
int main() 
{
	Read_rap ();
	cin >> n;
	for (int i = 1;i <= n;i ++)		cin >> a[i];
	
	cout << (possible () ? "Possible" : "Impossible");


	return Accepted;
}	









// Coded by Z...

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    int n;
	while(cin >> n && n)
	{
		int res = 0;
		rep(i, n / 4)
		{
			int p;
			cin >> p;
			res += p;
		}
		
		cout << res << endl;
	}
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i] = Integer.parseInt(br.readLine());
        }

        System.out.println(maxDif(arr));
    }
    private static int maxDif(int[] arr){
        int min = arr[0],
            maxDif = arr[1] - min;
            if(min > arr[1])min = arr[1];

        for(int i=2; i<arr.length; i++){
            if(arr[i] - min > maxDif) maxDif = arr[i] - min;
            else if(arr[i] < min)min = arr[i];
        }
        return maxDif;
      }
}

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

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

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<ll> b;
    for(int i = 0; i < n; i += 2) {
        b.push_back(a[i]);
    }
    reverse(b.begin(), b.end());
    for(int i = 1; i < n; i += 2) {
        b.push_back(a[i]);
    }
    if(n % 2 == 0) reverse(b.begin(), b.end());
    for(int i = 0; i < n; i++) {
        if(i != n - 1) cout << b[i] << ' ';
        else cout << b[n - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 6864
n,m = map(int, input().split())
x = sorted(list(map(int, input().split())))
l = [0] * (m-1)
if n >= m:
  print(0)
  exit()
else:
  for i in range(m-1):
    l[i] = x[i+1] - x[i]
  print(sum(sorted(l)[:m-n]))

Measured memory_bytes: 13968
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c,d;
long long ans;
int main()
{
    
    cin>>n;
    b=n%10;
    c=n/100;
    if(b==c)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int X, t;
    cin >> X >> t;
    cout << max(X - t, 0) << endl;
}


Measured memory_bytes: 256
# input
N, T = map(int, input().split())
rhr = []
r_append = rhr.append
for i in range(1, N + 1):
    c, t = map(int, input().split())
    r_append(
        {
            "index": i,
            "cost": c,
            "time": t
        }
    )

target_routes = [
    r
    for r in rhr
    if r["time"] <= T
]

if not target_routes:
    print("TLE")
else:
    target_routes.sort(key=lambda x: x["cost"])
    print(target_routes[0]["cost"])

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
 
int main(void){
  int s;
  int a=0;
  int b=0;
  int c=0;
  int d=0;
  scanf("%d",&s);
  for (; ; ){
    if(s<1000){
      break;
    }
    a++;
    s = s-1000;
  }
  for (; ; ){
    if(s<100){
      break;
    }
    b++;
    s = s-100;
  }
  for (; ; ){
    if(s<10){
      break;
    }
    c++;
    s = s-10;
  }
  d = s;
  if(a==b||b==c||c==d){
  printf("Bad");
  }else{
  printf("Good");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top;
int S[1000];
int jou(int);
void push(int x){
  top++;
  S[top]=x;
  //printf("%d ",S[top]);
}

int pop(){
  top--;
  return  S[top+1];
}
int jou(n){
  int i,jou=1;
  for(i=0;i<n;i++){
    jou=jou*10;
  }
  return jou;
}


int main(){
  char s[100];
  int a=0,b;
  int top=0;
  int i;
  int j;
  int cnt=0;
  int n;
  int p,q;
  while((scanf("%s",s))!=EOF){
    if(s[0]=='+'){
      p=pop();
      q=pop();
      push(p+q);
    }
    else if(s[0]=='-'){
      p=pop();
      q=pop();
      push(q-p);
    }
    else if(s[0]=='*'){
      p=pop();
      q=pop();
      push(p*q);
    }
    else{
      if(s[1]<='9'&&s[1]>='0'){
	for(i=1;s[i]!='\0';i++){
	  if(s[i]<='9'&&s[i]>='0'){
	    cnt++;
	  }
	  else break;
	}
	n=cnt+1;
	for(j=0;j<n;j++){
	  b=jou(cnt);
	  a=a+(s[j]-48)*b;
	  cnt--;
	}
	push(a);
	cnt=0;a=0;b=0;
      }
      else{	  
	push(atoi(s));
      }
    }
    a=0;
  }
  printf("%d\n",pop());
  return 0;
}
      
      



Measured memory_bytes: 2108