akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
  int i,j,n,a;
  string str,ans;
  cin >> n;
  for(i=0;i<n;i++){  
    cin >> str;
    ans = "NA";

    if(str[0] == '>'){
      if(str[1] == '\''){
	a = 2;
	int c=0,c2=0;
	if(str[a] == '='){
	  while(str[a] == '='){
	    a++;
	    c++;
	  }
	  if(str[a] == '#'){
	    a++;
	    if(str[a] == '='){
	      while(str[a] == '='){
		c2++;
		a++;
	      }
	      if(str[a] == '~' && a + 1 == str.size() && c == c2) ans = "A";
	    }
	  }
	}
      }
      else if(str[1] == '^'){
	a = 2;
	if(str[a] == 'Q' && str[a+1] == '='){
	  while(str[a] == 'Q' && str[a+1] == '=') a += 2;
	  if(str[a] == '~' && str[a+1] == '~' && a + 2 == str.size()) ans = "B";
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/09/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  string s; cin>>s;
  int cnt=0;
  char p=' ';
  vector<pair<bool, ll>> rl;
  for (auto c:s) {
    if (c==p) {
      cnt++;
    } else {
      rl.emplace_back(p=='<', cnt);
      cnt=1;
    }
    p=c;
  }
  rl.emplace_back(p=='<', cnt);

  ll ans = 0;
  for (int i = 1; i < rl.size(); i++) {
    ll num = rl[i].second;
    if (rl[i].first and i < rl.size()-1 and rl[i+1].second > num) {
      --num;
    } else if (!rl[i].first and rl[i-1].second >= num) {
      --num;
    }
    ans += num*(num+1)/2;
  }
  cout << ans << endl;

  return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll A,B;
ll i,j,ans;
int main(){
    scanf("%lld%lld", &A, &B);
    if((A+B)%2){
        printf("IMPOSSIBLE");
    }else{
        printf("%lld", (A + B) / 2);
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int N,X;
  cin>>N>>X;
  vector<int> A(N);
  rep(i,N) cin>>A[i];
  ll ans=0,sum=0;
  int f=1;
  rep(i,N){
    sum+=A[i];
    if(sum>X){
      cout<<i+1<<endl;
      f=0;
      break;
    }
  }
  if(f) cout<<N+1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int x, a; cin >> x >> a;
    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
}

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

typedef long long ll;
typedef pair<int,int> P;
#define INF (int)(1e9)
#define EPS (1e-7)
#define MOD ((ll)1e9+7)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i = 1;i <= (int)(n); i++)
#define FOR(i,k,n) for(int i = (k); i < (int)(n); i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define pb push_back
#define vec vector<int>


/*--------------------------------------------*/
/*ll factorial(ll);
void list_Prime(ll);
ll divisor(ll);
ll lcm(ll, ll);//AとBの最小公倍数
ll gcd(ll,ll);

int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
*/
/*--------------------------------------------*/
/*--------------------------------------------*/
/*
ll factorial(ll n){
    if(n==1)return 1;
    return n*factorial(n-1);
}
ll lcm(ll A, ll B) {//最小公倍数
    ll a = A;
    ll b = B;
    if (a == 0 || b == 0) { return 0; }
    if (a < 0) { a = -a; }
    if (b < 0) { b = -b; }
    while (b > 0) {
        ll c = a % b;
        a = b;
        b = c;
    }
    return A/a*B;
}

ll gcd(ll a,ll b){
    while (b != 0) {
        int t = b;
        b = a % b;
        a = t;
    }
    return a;
}


void list_Prime(ll n){//n以下の素数を全て見つける
    ll Limit=(int)sqrt((double)n);
    for(ll i=2;i<=n;i++)prime[i]=1;//最初はみんな素数かも
    //素数の整数倍を消していく(ルートnまで)
    for(ll i=2;i<=Limit;i++){
        if(prime[i]){
            for(ll j=2*i;j<=n;j++){
                if(j%i==0){
                    prime[j]=0;                
                }
            }
        }
    }
}

ll divisor(ll n){
    for(ll i=2;i<=n;i++){
        ll d=1;
        ll tmp=i;
        while(tmp>0){
            d++;
            while(tmp%d==0){
                prime[i]++;
                tmp/=i;
            }
        }
    }
    ll sum=1;
    for(ll i=2;;i<=n;i++){
        sum*=(prime[i]+1)/MOD;
    }    
    cout<<"sum="<<sum<<endl;

    return sum%MOD;
}
*/
/*--------------------------------------------*/

int main(){
    string ps,t;cin>>ps>>t;
    int n=(int)ps.size();
    int num=INF;
    int flag;
    int perfect;
    //cout<<n-(int)t.size()+1<<endl;
    rep(i,n-(int)t.size()+1){
        flag=1;perfect=1;
        rep(j,t.size()){
            if(t[j]==ps[i+j] || ps[i+j]=='?'){
                if(ps[i+j]=='?'){perfect=0;}
                continue;
            }
            else {flag=0;perfect=0;
                  //break;
                 }
        }
        //printf("perfect=%d\n",perfect);
        if(perfect==1){num=i;
                       //printf("num=%d\n",num);
                       break;}//perfectならそこで確定
        if(flag==1){num=i;
                    //printf("num=%d\n",num);
                   }//もっとも良い(後ろの)numを見つける
    }
    //printf("finalnum=%d\n",num);
    if(num==INF)cout<<"UNRESTORABLE"<<endl;
    else{
        for(int i=0;i<n;){
            //printf("i=%d\n",i);
            if(i==num){cout<<t;i+=(int)t.size();}
            else{
                if(ps[i]=='?'){cout<<'a'
                    //<<endl;
                    ;i++;}
                else{cout<<ps[i]
                     //<<endl;
                     ;i++;}
            }
        }cout<<endl;
    }
    
}



Measured memory_bytes: 256
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
                         **/
#include<bits/stdc++.h>
using namespace std;
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz size
#define rep(i,n) for(int i=(0);i<(n);i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 1e5+1;
const int mod = 1000000009;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 10000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if(!e)return 1;
    if(e&1) return qpow(b,e-1)*b;
    int pwur=qpow(b,e>>1);
    return pwur*pwur;
}

/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n,m;
    cin>>n;
    vector<string>s(n);
    map<string,int>mp;
    rep(i,n){cin>>s[i];mp[s[i]]++;}
    cin>>m;
    vector<string>t(m);
    rep(i,m){cin>>t[i];mp[t[i]]--;}
    int ans=0;
    for(auto it:mp)ans=max(ans,it.s);
    cout<<ans<<enl;
    return 0;
}


Measured memory_bytes: 3668
/*
    Mbak Rose Dong
*/
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
long long int arr[100100], dp[100100];
int n;
long long int dfs(int now)
{
    if(now == 0)
        return 1;
    if(arr[now] == 0)
        return 0;
    if(dp[now] != -1)
        return dp[now];
    long long int sum = 0;
    if(now >= 1)
    {
        sum += dfs(now-1) % mod;
    }
    if(now >= 2)
    {
        sum += dfs(now-2) % mod;
    }
    return dp[now] = sum % mod;
}
int main()
{
	int i,j,k,x,y,ans,m,curr;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)
    {
        arr[i] = 1;
    }
    for(i=1;i<=m;i++)
    {
        scanf("%d",&curr);
        arr[curr] = 0;
    }
    if(n == 1)
    {
        cout << "1" << endl;
        return 0;
    }
    memset(dp, -1, sizeof(dp));
    dp[0] = 1;
    long long int rose;
    rose = dfs(n);
    cout << rose << endl;
    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    vector<int> pqr(3);
    for(int i = 0; i < 3; i++) cin >> pqr[i];

    sort(pqr.begin(), pqr.end());

    cout << pqr[0] + pqr[1] << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int>d(N);
  for(int i=0;i<N;i++) {
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  int count=1;
  for(int i=0;i<N-1;i++) {
    if(d.at(i) != d.at(i+1)) {
      count++;
    }
  }
  cout << count <<endl;
}


Measured memory_bytes: 256
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [[0] * 3 for i in range(3)]
for i in range(n):
  num = int(input())
  for i in range(3):
    for j in range(3):
      if num == a[i][j]:
        b[i][j] = 1
for i in range(3):
  if b[i][0] == b[i][1] == b[i][2] == 1:
    print("Yes")
    exit()
  if b[0][i] == b[1][i] == b[2][i] == 1:
    print("Yes")
    exit()
if b[0][0] == b[1][1] == b[2][2] == 1:
  print("Yes")
  exit()
if b[0][2] == b[1][1] == b[2][0] == 1:
  print("Yes")
  exit()
print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>

int main() {
  int H, W, K;
  std::cin >> H >> W >> K;
  int x1, y1, x2, y2;
  std::cin >> x1 >> y1 >> x2 >> y2;
  std::vector<std::string> pond(H + 2, std::string(W + 2, '@'));
  for (int i = 1; i <= H; ++i) {
    std::string row;
    std::cin >> row;
    pond[i] = "@" + row + "@";
  }
  constexpr int kInfinity = std::numeric_limits<int>::max();
  std::vector<std::vector<int>> distances(H + 2, std::vector<int>(W + 2, kInfinity));
  std::queue<std::tuple<int, int>> queue;
  distances[x1][y1] = 0;
  queue.emplace(x1, y1);
  std::vector<std::tuple<int, int>> directions = {
    {1, 0}, {-1, 0}, {0, 1}, {0, -1},
  };
  while (!queue.empty()) {
    const auto [x, y] = queue.front();
    queue.pop();
    for (const auto [dx, dy] : directions) {
      for (int d = 1; d <= K; ++d) {
        const int tx = x + d * dx;
        const int ty = y + d * dy;
        if (pond[tx][ty] == '@' || distances[tx][ty] <= distances[x][y]) break;
        if (distances[tx][ty] == kInfinity) queue.emplace(tx, ty);
        distances[tx][ty] = distances[x][y] + 1;
      }
    }
  }
  if (distances[x2][y2] == kInfinity) {
    std::cout << -1 << std::endl;
  } else {
    std::cout << distances[x2][y2] << std::endl;
  }
  return 0;
}


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

int main() {
	int R;
  	cin >> R;
  
  	if(R < 1200) {
    	cout << "ABC" << endl;
    }else if(R >= 1200 && R < 2800) {
    	cout << "ARC" << endl;
    }else {
    	cout << "AGC" << endl;
    }
}

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

int n,m;
vector<string> a;
vector<string> b;

bool check(int h, int w){
  for(int i=0;i<m;i++){
    if(b[i]==a[h].substr(w,m)) h++;
    else return false;
  }
  return true;
}

int main(){
  cin>>n>>m;
  a.resize(n);
  b.resize(m);
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<m;i++) cin>>b[i];

  bool flag=false;
  for(int i=0;i<n;i++){
    if(n-i<m){
      cout<<"No"<<endl;
      return 0;
    }
    for(int j=0;(j+m-1)<n;j++){
      if(b[0]==a[i].substr(j,m)) flag=check(i,j);
      if(flag){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;  
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int64_t gcd(int64_t a, int64_t b) {return b?gcd(b, a%b):a;}
int64_t lcm(int64_t a, int64_t b) {return a/gcd(a,b)*b;}
int64_t extgcd(int64_t a, int64_t b, int64_t &x, int64_t &y) { // ax+by=gcd(a, b)の解を与える
    int64_t d = a;
    if(b) {
        d = extgcd(b, a%b, y, x);
        y -= (a/b)*x;
    } else {
        x = 1; y = 0;
    }
    return d;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;

    int mm = gcd(n, m);
    rep(i, mm) {
        if(s[n/mm*i] != t[m/mm*i]) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << lcm((ll)n, m) << endl;
}

Measured memory_bytes: 3800
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [int(input()) for _ in range(m)]

for i in range(n):
    ans = 0
    for j in range(m):
        ans += a[i][j] *b[j]
    print(ans)


Measured memory_bytes: 6012
#include "bits/stdc++.h"
using namespace std;
const int N = 2e5 + 5;
int n , m;
int ton[N];
int fo1[N];
int a , b;
int main(){
	scanf("%d %d" , &n , &m);
	for(int i = 1 ; i <= m ; ++i){
		scanf("%d %d" , &a , &b);
		if(a == 1){
			fo1[b] = 1;
		}
		if(b == n){
			ton[a] = 1;
		}
	}
	for(int i = 2 ; i < n ; ++i){
		if(fo1[i] && ton[i]){
			printf("POSSIBLE\n");
			return 0;
		}
	}
	printf("IMPOSSIBLE\n");
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  double p=0;
  
  for (int i=1; i<=N; i++) {
    double q=1.00/N;
    int point=i;
    
    while (point<K) {
      q=q/2;
      point=point*2;
    }
    p=p+q;
  }
  
  
  cout << fixed << setprecision(10);
  cout << p << endl;
}

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

int dfs(int n, int cnt) {
    if (n == 0) return 1;
    if (cnt == 4) return 0;

    int ret = 0;
    for (int i = 0; i < 10; i++) {
        ret += dfs(n-i, cnt+1);
    }

    return ret;
}

int main(void) {
    int n;
    while (cin >> n) {
        int ret = dfs(n, 0);
        cout << ret << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>                                                 
#include<string.h>                                                
                                                                  
int main(void){                                                   
   char S[100];                                                   
   scanf("%s",S);                                                 
                                                                  
   int len = strlen(S);                                           
   for(int i = 0; i < len; i++){                                  
      printf("x");                                                
   }                                                              
   return 0;                                                      
}

Measured memory_bytes: 1624
// https://atcoder.jp/contests/practice2/tasks/practice2_g
// 理解していない

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

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

    scc_graph g(n);
    for (int i = 0; i < m; ++i)
    {
        int u, v;
        cin >> u >> v;
        g.add_edge(u, v);
    }

    auto scc = g.scc();

    cout << scc.size() << endl;
    for (auto v : scc)
    {
        cout << v.size();
        for (int x : v)
        {
            cout << " " << x;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 40104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[][] graph = new int[n][n];
      String[] vInfo;
      int degree;

      for(int i=0,v=0; i<n; i++) {
        vInfo = br.readLine().split(" ");
        degree = Integer.parseInt(vInfo[1]);
        for(int j=0,k=2; j<degree; j++) {
          v = Integer.parseInt(vInfo[k++]);
          graph[i][v-1] = 1;
        }
      }

      StringBuilder buf = new StringBuilder(n*n*2);
      for (int[] vertex : graph) {
        for (int v : vertex) {
          buf.append(v).append(" ");
        }
        buf.setLength(buf.length()-1);
        buf.append("\n");
      }

      System.out.print(buf);
    }
    catch (IOException e) {
      System.out.println("IOException!");
    }
  }
}


Measured memory_bytes: 25016
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int N; cin >> N;
    cout << 180 * (N - 2) << endl;

    
    return 0;
}


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

int partition(pair<char, int> A[],  int p, int r);
void swap(pair<char, int> *a, pair<char, int> *b);
void quicksort(pair<char, int> A[], int p, int r);

void merge(pair<char, int> A[], int left, int mid, int right);
void mergeSort(pair<char, int> A[], int left, int right);


#define M 100100

int n;

int main(){
    cin >> n;
    pair<char, int> A[M], B[M];
    char c;
    int num;
    for(int i = 0; i < n; i++){
        cin >> c >> num;
        A[i] = make_pair(c,num);
        B[i] = A[i];
    }

    quicksort(A, 0,n-1);
    mergeSort(B,0,n);

    bool stable = true;
    for(int i = 0; i < n; i++){
        if(A[i].first != B[i].first){
            stable = false; break;
        }
    }

    if(stable) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
    

    for(int i = 0; i < n; i++){
        cout << A[i].first << " " << A[i].second << endl;
    }
    
}

int partition(pair<char, int> A[],  int p, int r){
    pair<char, int> x = A[r];
    int i = p-1,j;
    for(j = p; j < r; j++){
        if(A[j].second <= x.second){
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i+1;
}

void swap(pair<char, int> *a, pair<char, int> *b){
    pair<char, int> w = *a;
    *a = *b; *b = w;
}

void quicksort(pair<char, int> A[], int p, int r){
    if(p < r){
        int q = partition(A, p,r);
        quicksort(A, p,q-1); quicksort(A, q+1,r);
    }
}

void merge(pair<char, int> A[], int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;

    pair<char, int> L[n1+10], R[n2+10];

    // 右側と左側に分割
    for(int i = 0; i < n1; i++){
        L[i] = A[left+i];
    }
    for(int i = 0; i < n2; i++){
        R[i] = A[mid+i];
    }
    L[n1].second = INT_MAX; R[n2].second = INT_MAX;

    // 右側と左側の小さい方を取ってきて並べ替え
    int i = 0, j = 0;
    for(int k = left; k < right; k++){
        if(L[i].second <= R[j].second){
            A[k] = L[i];
            i++;
        }else{
            A[k] = R[j];
            j++;
        }
    }
}


void mergeSort(pair<char, int> A[], int left, int right){
    if(left+1 < right){
        int mid = (left + right) /2;
        // 左側整頓
        mergeSort(A, left, mid);
        // 右側整頓
        mergeSort(A,mid, right);
        // まとめる
        merge(A,left, mid, right);
    }
}


Measured memory_bytes: 5416
#include <iostream>

using namespace std;

int main()
{
 	int N, T;

	cin >> N >> T;

	int costMin = 1001;
	int timeMin;

	int c, t;

	for (int i = 0; i < N; ++i)
	{
		cin >> c >> t;

		if (c < costMin)
		{
			if (t <= T)
			{
				costMin = c;
				timeMin = t;
			}
		}
	}

	if (timeMin <= T)
	{
		cout << costMin << endl;
	}
	else
	{
		cout << "TLE" << endl;
	}

  return 0;
}

Measured memory_bytes: 256
using System;


public class A{
	
	public static void Main(){
	
		string[] args = Console.ReadLine().Split(' ');
		long n = Int64.Parse(args[0]);
		long k = Int64.Parse(args[1]);
		Console.WriteLine( n % k == 0 ? 0 : 1 );
		
	}
	
}

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

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN3(n,a,b);
  Vi TIME(n);
  VIN(TIME)
  SORT(TIME);
  int limit = TIME[0] + b;
  int psg = 0;
  REP(i,n){
    if(TIME[i] <= limit){
      if(psg == a /*満員*/){
        z++;
        psg = 1;
        limit = TIME[i] + b;
      } else {
        //乗り込む
        psg++;
      }
    } else {
      //バスを発車させる
      z++;
      limit = TIME[i] + b;
      psg = 1;
    }
  }
  z++;
  OUT(z);
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define Graph vector<vector<int>>;
#define iterG(next_v, G, v) for(auto next_v : G[v]
int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    if (c * 2 <= a and c * 2 <= b)
    {
        cout << c * 2 * max(x, y) << endl;
    }
    else if (c * 2 <= a)
    {
        // aを買うよりabを買ったほうが有利
        cout << c * 2 * x + b * max(y - x, 0) << endl;
    }
    else if (c * 2 <= b)
    {
        // bを買うよりabを買ったほうが有利
        cout << c * 2 * y + a * max(x - y, 0) << endl;
    }
    else if (c * 2 <= a + b)
    {
        cout << c * 2 * min(x, y) + a * (x - min(x, y)) + b * (y - min(x, y)) << endl;
    }
    else
    {
        cout << a * x + b * y << endl;
    }
}

Measured memory_bytes: 3596
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>  // https://boostjp.github.io/tips/math.html
#include <boost/dynamic_bitset.hpp>  // https://boostjp.github.io/tips/dynamic_bitset.html

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    std::map<int64_t, int64_t> M;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        M[t]++;
    }

    std::vector<int64_t> E;
    for (auto& m: M) {
        auto count = m.second / 2;
        for (int64_t i = 0; i < count; ++i) {
            E.push_back(m.first);
        }
    }

    std::sort(std::begin(E), std::end(E),
              [](const auto& a, const auto& b) {
                  return a > b;
              });

    int64_t ans = 0;
    if (E.size() >= 2) {
        ans = E[0] * E[1];
    }
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 6528
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NAB = Sarray();
            var N = NAB[0];
            var A = NAB[1];
            var B = NAB[2];
            var ans = 0L;
            for (var i = 1L; i <= N; ++i)
            {
                var ketaWa = 0L;
                var s = i;
                while (s != 0)
                {
                    ketaWa += s % 10;
                    s /= 10;
                }

                if (A <= ketaWa && ketaWa <= B)
                    ans += i;
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
from collections import defaultdict


def inpl():
    return list(map(int, input().split()))


N, K = inpl()
aa = inpl()

s = 1

route = [s]
ed = set([s])

for i in range(1, K + 1):
    s = aa[s - 1]
    if s in ed:
        Li = route.index(s)
        Ri = len(route)
        idx = Li + (K - Li) % (Ri - Li)
        print(route[idx])
        break
    else:
        route.append(s)
        ed.add(s)
        continue
else:
    print(s)


Measured memory_bytes: 33908
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		HashSet<Long> set = new HashSet<>();
		boolean zero = true;
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextLong();
			zero &= a[i] == 0;
			set.add(a[i]);
		}
		if (zero) {// 00000000...
			System.out.println("Yes");
			return;
		}
		if (set.size() == 2 && n % 3 == 0) {
			long[] v = new long[2];
			int[] cnt = new int[2];
			int p = 0;
			for (long val : set) {
				v[p] = val;
				++p;
			}
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < v.length; ++j) {
					if (v[j] == a[i])
						++cnt[j];
				}
			}
			if (cnt[0] == cnt[1] * 2) {
				if (v[1] == 0) {
					System.out.println("Yes");
					return;
				}
			} else if (cnt[1] == cnt[0] * 2) {
				if (v[0] == 0) {
					System.out.println("Yes");
					return;
				}
			}
			System.out.println("No");
			return;

		} else if (set.size() != 3 || n % 3 != 0) {
			System.out.println("No");
			return;
		} else {
			long[] v = new long[3];
			int[] cnt = new int[3];
			int p = 0;
			for (long val : set) {
				v[p] = val;
				++p;
			}
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < v.length; ++j) {
					if (v[j] == a[i])
						++cnt[j];
				}
			}
			if ((v[0] ^ v[1] ^ v[2]) != 0) {
				System.out.println("No");
				return;
			}
			if (cnt[0] != cnt[1] || cnt[1] != cnt[2] || cnt[2] != cnt[0]) {
				System.out.println("No");
				return;
			}
			System.out.println("Yes");
		}
	}

	static int gcd(int a, int b) {
		if (a > b)
			return gcd(b, a);
		if (a == 0)
			return b;
		return gcd(a, b % a);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


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


int main()
{
	string s, t;
	cin >> s >> t;
	string f = "Yes";
	int size = s.size();

	vector<char> a(size);
	vector<char> b(size);
	vector<int> c(size);

	for (int i = 0; i < size; i++) {
		a[i] = s[i];
		b[i] = t[i];
		c[i] = 0;
	}
	for (int i = 0; i < size; i++) {
		if (c[i] == 1)continue;
		char p, q;
		p = a[i];
		q = b[i];
		for (int j = 0; j < size; j++) {
			//if (c[j] == 1)continue;
			if (a[j] == p) {
				a[j] = q;
				c[j] = 1;
			}
			else if (a[j] == q) {
				a[j] = p;
				
			}
		}
		c[i] = 1;
	}
	
	for (int i = 0; i < s.size(); i++) {
		if (a[i] != b[i])f = "No";
		
	}
	cout << f << endl;
	return 0;

}

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

int main() {
  int N;
  cin >> N;
  int x = 0;

  for (int i = 0; i < 8; i++){
    int a, b;
    b = 1;
    for(int j = 0; j < i; j++){
      b *= 10;
    }
    a = (N/b)%10;
    x += a;
  }
  
  if ( N%x != 0){
    cout << "No" << endl;
  }
  
  else{
    cout << "Yes" << endl;
  
  }
  
}
      
    

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 262144
#define REP(i,n) for(long long i = 0;i < n;++i)
long long costings[20000];
vector<int> vertexs[20000];
long long dp1[5101][5101];
long long dp2[5101][5101];
long long vertexes[5101];
long long tmp[5101*2][2];
long long dfs(long long now, long long back) {
	vertexes[now] = 1;
	for (int i = 0; i < vertexs[now].size(); ++i) {
		if (vertexs[now][i] != back) {
			dfs(vertexs[now][i], now);
			vertexes[now] += vertexes[vertexs[now][i]];
		}
	}
	REP(i, vertexes[now] + 2) {
		tmp[i][0] = LONG_INF;
		tmp[i][1] = LONG_INF;
	}
	tmp[0][0] = costings[now];
	if (costings[now] > 0) tmp[0][1] = costings[now];

	long long now_tea = 0;
	REP(i, vertexs[now].size()) {
		if (vertexs[now][i] != back) {
			int visiting = vertexs[now][i];
			for (int j = now_tea; j >= 0; --j) {
				long long geko_a = tmp[j][0];
				long long geko_b = tmp[j][1];
				tmp[j][0] = LONG_INF;
				tmp[j][1] = LONG_INF;
				for (int k = 0; k <= vertexes[visiting]; ++k) {
					tmp[j + k][0] = min(tmp[j + k][0], geko_a + dp1[visiting][k]);
					if (dp1[visiting][k] < 0 || dp2[visiting][k] < LONG_INF / 2) tmp[j + k + 1][0] = min(tmp[j + k + 1][0], geko_a);
					if (costings[now] > 0) {
						tmp[j + k][1] = min(tmp[j + k][1], geko_b + dp2[visiting][k]);
						if (dp1[visiting][k] < 0 || dp2[visiting][k] < LONG_INF / 2) tmp[j + k + 1][1] = min(tmp[j + k + 1][1], geko_b);
					}
				}
			}
			now_tea += vertexes[visiting];
		}
	}
	for (int j = 0; j <= vertexes[now]; ++j) {
		dp1[now][j] = tmp[j][0];
		dp2[now][j] = tmp[j][1];
	}
	return 0;
}
int main() {
#define int long long
	int n;
	cin >> n;
	REP(i, 5001) {
		REP(q, 5001) {
			dp1[i][q] = LONG_INF;
			dp2[i][q] = LONG_INF;
		}
	}
	REP(i, n) {
		cin >> costings[i];
	}
	REP(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		vertexs[a].push_back(b);
		vertexs[b].push_back(a);
	}
	dfs(0, -1);
	REP(i, n + 1) {
		if (dp1[0][i] < 0 || dp2[0][i] < LONG_INF / 2) {
			cout << i << endl;
			return 0;
		}
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 402688
import bisect

# LIS
N = int(input())
L = list(map(int, input().split()))
L.sort()

# shorter first
# c > b >a
count = 0
for i in range(0, N-2):
  for j in range(i+1, N-1):
    index = bisect.bisect_left(L, L[i]+L[j])
    count += max(0, index-(j+1))
print(count)

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


def main():
    N = int(input())
    a = list(map(int, input().strip().split()))
    ans = [0] * N

    for i, a_r in enumerate(a[::-1]):
        j = N - i - 1
        count = 0
        now = j+1
        while now <= N:
            count += ans[now-1]
            now += j+1

        if a_r == 0:
            if count % 2 == 1:
                ans[j] = 1
        else:
            if count % 2 == 0:
                ans[j] = 1

    output = ""
    count = 0
    for i, b in enumerate(ans):
        if b == 1:
            output += str(i+1) + " "
            count += 1
    print(count)
    if count != 0:
        print(output[:-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 10036
until(n,m=gets.split.map(&:to_i)).all?(&:zero?)do
r,p,a=[],[],[]
n.times{r.unshift(gets.gsub("?",".").split)}
m.times{p<<gets.split}
p.each{|p|r.each{|r|if/#{r[1]}/=~p[0]&&p[1]=~/#{r[2]}/
a<<p*" "if/p/=~r[0]
break
end}}
puts a.size,a
end

Measured memory_bytes: 9404
#include <stdio.h>

int main(void){
   int isu_len,hito,inter;
   scanf("%d%d%d",&isu_len,&hito,&inter);

   hito = hito+inter; isu_len = isu_len - inter;

   printf("%d\n",isu_len/hito);
   return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

int main(){
	
	long long int N;
	long long int tmp;
	vector<long long int> a;

	scanf("%lld", &N);
	for(int i=0; i<5; i++){
		scanf("%lld\n", &tmp);
		a.push_back((N+(tmp-1)) / tmp);
	}

	printf("%lld\n", *max_element(a.begin(), a.end()) + 4LL);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <functional>
#define MOD 1000000007

int i,j,k;

struct edge {
    int to;
    int cost;
};

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

bool compare_by_b(pair<int,pair<string,int>> a, pair<int,pair<string,int>> b) {
    if(a.second.first != b.second.first){
        return a.second.first < b.second.first;
    }else{
    return a.second.second > b.second.second;
    }
}

int main(void) {
    int x,a;
    cin >> x >> a;
    cout << ((x>=a)?10:0) << endl;
    return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#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 <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    vector<int> x(4), y(4);
    for(int i=0; i<2; i++) cin >> x[i] >> y[i];

    int dx = x[1] - x[0], dy = y[1] - y[0];
    x[2] = x[1] - dy, y[2] = y[1] + dx;
    x[3] = x[2] - dx, y[3] = y[2] - dy;
    printf("%d %d %d %d\n", x[2], y[2], x[3], y[3]);
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
 
 
struct Edge{
    bool operator<(const struct Edge &arg) const{
        if(s != arg.s){
            return s < arg.s;
        }else{
            return t < arg.t;
        }
    }
    int s,t;
};
 
struct Info{
    Info(int arg_to,int arg_edge_id){
        to = arg_to;
        edge_id = arg_edge_id;
    }
    int to,edge_id;
};
 
int V,E,number;
int order[100000],lowlink[100000];
bool visited[100000];
Edge edge[100000];
vector<Info> G[100000];
 
void recursive(int node_id){
 
    order[node_id] = number++;
    lowlink[node_id] = order[node_id];
 
    int next_node;
 
    for(int i = 0; i < G[node_id].size(); i++){
 
        next_node = G[node_id][i].to;
 
        if(order[next_node] == -1){
 
            visited[G[node_id][i].edge_id] = true;
            recursive(next_node);
            lowlink[node_id] = min(lowlink[node_id],lowlink[next_node]);
 
        }else if(visited[G[node_id][i].edge_id] == false){
 
            lowlink[node_id] = min(lowlink[node_id],order[next_node]);
        }
    }
}
 
int main(){
 
    scanf("%d %d",&V,&E);
 
    for(int i = 0; i < E; i++){
        scanf("%d %d",&edge[i].s,&edge[i].t);
	edge[i].s--;
	edge[i].t--;
        if(edge[i].s > edge[i].t){
            swap(edge[i].s,edge[i].t);
        }
        G[edge[i].s].push_back(Info(edge[i].t,i));
        G[edge[i].t].push_back(Info(edge[i].s,i));
    }
 
    sort(edge,edge+E);
 
    number = 0;
 
    for(int i = 0; i < V; i++){
        order[i] = -1;
        lowlink[i] = -1;
    }
 
    for(int i = 0; i < E; i++){
        visited[i] = false;
    }
 
    recursive(0);
 
    int from,to;
    int sum = 0;
    for(int i = 0; i < E; i++){
 
        from = edge[i].s;
        to = edge[i].t;
 
        if(order[edge[i].s] > order[edge[i].t]){
            swap(from,to);
        }
 
        if(order[from] < lowlink[to]){
	  sum++;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 2560
x=list(input())
a=x[0]
b=x[1]
c=x[2]
d=x[3]
if a==b and a!=c:
  if c==d:
    print("Yes")
  else:
    print("No")
elif a==c and a!=b:
  if b==d:
    print("Yes")
  else:
    print("No")
elif a==d and a!=b:
  if b==c:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long  a, b, x;
	scanf("%lld %lld %lld", &a, &b, &x);
	if(a == 0) printf("%lld\n", b / x + 1);
	else printf("%lld\n", b / x - (a - 1) / x);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#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()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};



typedef struct _state{
  int from,vis;
  double cost;
  _state(double ic,int ifr,int iv):cost(ic),from(ifr),vis(iv){
  };
  bool operator<(const _state&r)const{
    return cost>r.cost;
  };
}state;

vector<PI> V[30];


main(){
  int n,m,p,a,b;
  while(cin>>n>>m>>p>>a>>b,n){
    --a,--b;
    int ti[n];
    rep(i,n)cin>>ti[i];

    rep(i,m)V[i].clear();

    rep(i,p){
      int x,y,z;
      cin>>x>>y>>z;
      --x,--y;
      V[x].pb(mp(y,z));
      V[y].pb(mp(x,z));
    }

    priority_queue<state> Q;
    Q.push(state(0,a,0));

    bool cost[1<<n][m];
    memset(cost,0,sizeof(cost));
    double ans=-1;

    while(!Q.empty()){
      int from=Q.top().from,cti=Q.top().vis;
      double ccost=Q.top().cost;
      Q.pop();
      if(cost[cti][from])continue;
      cost[cti][from]=true;
      if(from==b){
        ans=ccost;
        break;
      }

      rep(i,n){
        if(cti>>i&1)continue;
        rep(j,V[from].size()){
          int to=V[from][j].first;
          int cc=V[from][j].second;
          if(cost[cti|1<<i][to])continue;
          double ncost=ccost+1.0*cc/ti[i];
          Q.push(state(ncost,to,cti|1<<i));
        }
      }
    }
    if(ans<0)cout<<"Impossible"<<endl;
    else cout<<ans<<endl;
  }
}

Measured memory_bytes: 7784
void main()
{
    string s = rdStr;

    long len = s.length;
    long[][] dp = new long[][](len+1, 4);
    dp[0][0] = 1;
    foreach (i, x; s)
    {
        long c = (x == '?' ? 3 : 1);
        foreach (j; 0 .. 4)
        {
            dp[i+1][j] = (dp[i+1][j] + c * dp[i][j]) % mod;
            if (j == 3) continue;
            if (x == '?' || j == x - 'A')
            {
                dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % mod;
            }
        }
    }

    dp[len][3].writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 11928
n=int(input())
s=input()
cnt=1
if n==1:
    print(cnt)
else:
    for i in range(n):
        if i==0: memo=s[i]
        else:
            if memo==s[i]:
                continue
            else:
                cnt+=1
                memo=s[i]
    
    print(cnt)

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 110;
int n, a[N];

int main() {
	
	cin >> n;
	int num = log(n) / log(2);
	cout << pow(2, num) << endl;
	return 0;
} 

Measured memory_bytes: 3384
MOD = 10 ** 9 + 7

n,k = map(int,input().split())
a = list(map(int,input().split()))

incount = 0
for i in range(n-1):
    for j in range(i+1,n):
        if a[i] > a[j]:
            incount += 1

#print(incount)

out = 0

for p in range(n):
    for q in range(n):
        if a[p] < a[q]:
            out += 1

#print(out)

outcount = out * (k * (k-1)) //2

print((incount * k + outcount) % MOD)


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

int main()
{
    int n, k; cin>>n>>k;
    int r, s, p; cin>>r>>s>>p;
    string t; cin>>t;

    long res=0;
    for(int i=0; i<k; ++i) {
        string a;
        int c=0;
        for(int j=i; j<n; j+=k) {
            a+=t[j];
            ++c;
        }
        vector<vector<long>> dp(c+1, vector<long>(3));
        for(int j=0; j<c; ++j) {
            dp[j+1][0]=max(dp[j][1], dp[j][2])+(a[j]=='r')*p;
            dp[j+1][1]=max(dp[j][2], dp[j][0])+(a[j]=='s')*r;
            dp[j+1][2]=max(dp[j][0], dp[j][1])+(a[j]=='p')*s;
        }
        res+=max({dp[c][0], dp[c][1], dp[c][2]});
    }
    cout<<res<<endl;
}


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

int main()
{
	int n;
	cin>>n;
	int i;
	int a[n],dp[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	dp[0]=0;dp[1]=abs(a[1]-a[0]);
	for(i=2;i<n;i++)
	{
		dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
	}
	cout<<dp[n-1];
}


Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

typedef string::const_iterator state;
class parse_error {};

void cmpinc(state &it, char expected) {
	if (*it == expected) {
		it++;
	}
	else {
		cerr << "Expected '" << expected << "',";
		cerr << "got '" << *it << "'";

		cout << endl;
		throw parse_error();
	}
}

/*

EBNF

CAT = "" | "m"+CAT+"e"+CAT+"w";

*/

bool cat(state &it) {
	bool ret = true;
	switch (*it) {
	case 'm':
		it++;//m
		ret &= cat(it);
		if (*it != 'e') {
			ret = false;
			break;
		}
		it++;//e
		ret &= cat(it);
		if (*it != 'w') {
			ret = false;
			break;
		}
		it++;//w
		break;
	default:
		break;
	}
	return ret;
}

int main() {
	string s; getline(cin, s);
	s += "$";
	state it = s.begin();
	bool b = cat(it);
	if (it - s.begin() != s.size() - 1)b = false;
	cout << (b ? "Cat" : "Rabbit") << endl;
	return 0;
}

Measured memory_bytes: 1180
import math

A, B, H, M = map(int, input().split())

C = math.radians(abs(30*H+0.5*M-6*M)) #長針と短針間のなす角度[radian]

distance = float(math.sqrt(math.pow(A,2)+math.pow(B,2)-2*A*B*math.cos(C)))

print(distance)

Measured memory_bytes: 9440