akhauriyash/Code-Regression huggingface dataset:
// ConsoleApplication1.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//


#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
#include<queue>
typedef long long  i64;
using namespace std;
int n;
int m;
int a[2000];
int b[2000];
i64 c[2000];
struct Edge {
	int src, dst;
	i64 cost;
public:
	Edge(int src, int dst, i64 cost) {
		this->src = src;
		this->dst = dst;
		this->cost = cost;
	}
};
struct State {
	int cur;
	i64 cost;
public:State(int cur, i64 cost) {
	this->cur = cur;
	this->cost = cost;
}
};
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		scanf("%d%d%lld", a + i, b + i, c + i);
		--a[i];
		--b[i];
		c[i] *= -1;
	}
	vector<vector<Edge>> g;
	vector<vector<int>> rev;
	g.resize(n);
	rev.resize(n);
	for (int i = 0; i < m; ++i) {
		Edge e = { a[i],b[i],c[i] };
		g[a[i]].push_back(Edge(a[i], b[i], c[i]));
		rev[b[i]].push_back(a[i]);
	}

	i64 d[1000];
	for (int i = 0; i < n; ++i) {
		d[i] = 1LL << 60;
	}

	d[0] = 0;
	vector<queue<State>> pend;
	pend.resize(n + 2);
	pend[0].push(State(0, 0));
	for (int i = 0; i < n; ++i) {
		while (pend[i].size() > 0) {
			//while (!pend[i].empty()) {
			State s = pend[i].front();
			pend[i].pop();
			if (d[s.cur] < s.cost)
				continue;
			for (Edge e : g[s.cur]) {
				if (d[e.dst] > d[s.cur] + e.cost) {
					d[e.dst] = d[s.cur] + e.cost;
					State ns = { e.dst, d[e.dst] };
					pend[i + 1].push(ns);
				}
			}
		}
	}
	bool reach[1000];
	queue<int> q;
	q.push(n - 1);
	reach[n - 1] = true;
	while (q.size() > 0) {
		int v = q.front();
		q.pop();
		for (int dst : rev[v]) {
			if (!reach[dst]) {
				reach[dst] = true;
				q.push(dst);
			}
		}
	}
	bool f = false;
	while (pend[n].size() > 0) {
		State s = pend[n].front();
		pend[n].pop();
		f |= reach[s.cur];
	}
	if (!f) {
		printf("%lld\n", -d[n - 1]);
	}
	else {
		printf("inf\n");
	}


	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define  pb push_back
#define  xx first
#define  yy second
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;
int h,n;
int dp[1001];
int v[4000],cost[4000];
int ans = 1e-9;
/*
int go(int i,int sum){

        if(dp[i][sum]!=-1) return dp[i][sum];

       dp[i][sum] =min(val[i]+go(i+1,W-a[i]),go(i+1,W));
       return dp[i][sum];
}
*/
void go(int i,int x, int y ){

     ans = max(ans,x-y);
    if(i>n){
      return ;
    }
    go(i+1,v[i]+x,cost[i]+y);
    go(i+1,x,y);
    return;
}
 int main()
{
   // fast;

    int n;
    cin >> n;
    int a[n+10];
    for(int i = 1; i<=n; i++) cin >> a[i];
     int gc1[n+10];
     int gc2[n+10];
     gc1[0] = 0;
     gc1[n+1] = 0;
     gc2[0] = 0;
     gc2[n+1] = 0;
     int mx = 0;
     for(int i = 1; i<=n; i++){
        gc1[i] = __gcd(gc1[i-1],a[i]);
     }

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

     for(int i  = 1; i<=n; i++){
      //  cout<<gc[i-1] << " " << i << " " << gc[i+1] << endl;
        mx = max(mx,__gcd(gc1[i-1],gc2[i+1]));
     }

     cout << mx << '\n';

   return 0;
}


Measured memory_bytes: 1408
//package Qc
import java.util.*
import java.math.*
import java.lang.Math.*

private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = {readLine()!!.toInt()}
private val readLong: ()->Long = {readLine()!!.toLong()}
private val readIntArray: ()->IntArray = {readLine()!!.split(' ').map{it.toInt()}.toIntArray()}
private val readLongArray: ()->LongArray = {readLine()!!.split(' ').map{it.toLong()}.toLongArray()}
private val errPrintln: (String)->Unit = {msg -> System.err.println(msg)}
private val MOD = 1e9.toLong()+7
private val INF = Int.MAX_VALUE/2
private val LINF = Long.MAX_VALUE/2


fun solveC(A: IntArray): String {
    val N = A.size
    var res = ""
    for (p in 0 until (1 shl N)) {
        if ((p shr (N-1)) and 1 == 1) continue

        var ptn = p
        var sum = A[0]
        for (i in 1 until N) {
            if (ptn and 0b01 == 0) {
                sum += A[i]
            } else {
                sum -= A[i]
            }
            ptn = ptn shr 1
        }
        if (sum == 7) {
            ptn = p
            res = "${A[0]}"
            for (i in 1 until N) {
                if (ptn and 0b01 == 0) {
                    res += "+${A[i]}"
                } else {
                    res += "-${A[i]}"
                }
                ptn = ptn shr 1
            }
            res += "=7"
            break
        }
    }

    return res
}


fun main(args: Array<String>) {
    val S = readString()
    val A = S.toCharArray().map { it-'0' }.toIntArray()

    val ans = solveC(A)

    println(ans)
}


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

using namespace std;
long long count(long long arr[], long long l[], long long r[], int s1, int s2){
  int i=0;
  int j=0;
  long long cnt = 0;
  while (i < s1 || j < s2){
    if (i == s1){
      arr[i+j] = r[j];
      j++;
    }else if (j == s2){
      
      arr[i+j] = l[i];
      i++;
    }else if (l[i] <= r[j]){
      arr[i+j] = l[i];
      i++;
     
    }else{
      arr[i+j] = r[j];
      j++;
      cnt += s1-i;
    }
  }
  return cnt;
}
long long counter(long long arr[], int sz){
  
  if (sz == 1){
    return 0;
  }
  int thiss = sz/2+1;
  long long l[thiss];
  long long r[thiss];
  int s1 = 0;
  int s2 = 0;
  for (int i=0; i<sz/2; i++){
    l[i] = arr[i];
    
    s1++;
  }
  for (int i=sz/2; i<sz; i++){
    r[s2] = arr[i];
    
    s2++;
  }
  return counter(l, s1)+counter(r, s2)+count(arr, l, r, s1, s2);
}

int main()
{
    long long n, k;
    cin >> n >> k;
    long long thiss[n];
    int toadd = 0;
    for (int i=0; i<n; i++){
      int num;
      cin >> num;
      thiss[i] = num-k;
    }
    //cout << thiss[0] << " ";
    if (thiss[0] >= 0){
      toadd++;
    }
    for (int i=1; i<n; i++){
      thiss[i] = thiss[i-1]+thiss[i];
      if (thiss[i] >= 0){
        toadd++;
      }
      //cout << thiss[i] << " ";
    }
    //cout << endl;
  
    // see how many intervals have less than k, or see how many i's have a j greater than i that's over the place at i and how many i's are negative
    
    cout << n*(n+1)/2-counter(thiss, n)+toadd-n << endl;
    //cout << counter(another, 3) << endl;
    
    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

int main(){
	int N, A, B;
	scanf("%d %d %d", &N, &A, &B);
	int ans = 0;
	for(int i = 1; i <= N; i++){
		int temp = i;
		int total = 0;
		
		while(temp > 0){
			total += temp % 10;
			temp /= 10;
		}
		if(total >= A && total <= B){
			ans += i;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1736
#include<iostream>
using namespace std;
int main()
{
	int n,k,i,a=1;
	cin>>n>>k;
	for(i=1;i<=n;i++)
	{
		if(a<=k)a+=a;
		else a+=k;
	}
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
if s[0] == 'A' and s[2:-1].count('C') == 1:
    i = s.index('C') # Cの0オリジンで探してその場所を代入
    #print(i)
    ss = s[1:i] + s[i+1:] #全体の2文字目（1オリジン）からi番目までと、iのあとの末尾までの文字判定
    if ss.islower():
        print("AC")
    else:
        print("WA")
else:
    print("WA")

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

int main()
{
    int n;
    std::unordered_map<int,int> um;
    std::cin>>n;
    for(int i=0;i<n;i++){
        int tmp;
        std::cin>>tmp;
        um[tmp]++;
    }
    int ans = 0;
    for(auto i : um){
        if(i.second&1)ans++;
    }
    std::cout<<ans<<std::endl;

}

Measured memory_bytes: 4388
L,R = map(int, input().split())


diff = R - L
ans = 2019
if diff >= 2019:
    print(0)
else:
    for i in range(diff+1):
        for j in range(i+1,diff+1):
            l = (L+i)
            r = (L+j)
            ans = min(ans,(l*r)%2019)
    print(ans)

Measured memory_bytes: 41068
using System;
class Program
{
  static void Main(string[] args)
  {
    int n = int.Parse(Console.ReadLine());
    string[] input = Console.ReadLine().Split(' ');
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = int.Parse(input[i]);
    }
    
	int sum = 0;
    for (int i = 1; i < n-1; i++) {
      int [] three = new int[] { array[i-1], array[i], array[i+1] };
      Array.Sort(three);
      if (three[1] == array[i]) { sum++; }
    }
    Console.WriteLine(sum);
  }
}

Measured memory_bytes: 13140
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp2
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] Vs = Read(Console.ReadLine());

            Array.Sort(Vs);

            double ans = Vs[0]/(Math.Pow(2,N-1));

            for (int i = 1; i < Vs.Length; i++)
            {
                ans += (double)Vs[i] / (Math.Pow(2,N-i));
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        private static int[] Read(string input)
        {
            string[] aaa = input.Split(' ');
            int num = aaa.Length;
            int[] ints = new int[num];
            for (int i = 0; i < num; i++)
            {
                ints[i] = int.Parse(aaa[i]);
            }
            
            return ints;
        }
    }
}


Measured memory_bytes: 11220
#include<stdio.h>

void swap(int, int);
int gcdh(int, int);

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

  swap(a, b);

  //in here, why is not changeing place a and b ? 

  printf("%d\n", gcdh(a, b));
  
  return 0;
}

void swap(int x, int y){
  int t;
  if(x < y){
    t=x;
    x=y;
    y=t;
  }

}

int gcdh(int m, int n){
  int t;
  while(n>0){
    t = m % n;
    if(t==0) break;
    m = n;
    n = t;
  }
  return n;
}

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

#define fi first
#define se second

const int N = 200200;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int m;
int a[N];
int f[N];
long long t[4 * N];
long long lz[4 * N];
vector < int > b[N], e[N];

void push(int x)
{
        if(lz[x]){
                t[x * 2] += lz[x];
                lz[x * 2] += lz[x];
                t[x * 2 + 1] += lz[x];
                lz[x * 2 + 1] += lz[x];
                lz[x] = 0;
        }
}

void upd(int x, int l, int r, int tl, int tr, long long y)
{
        if(tl > tr){
                return;
        }
        if(l == tl && r == tr){
                t[x] += y;
                lz[x] += y;
                return;
        }
        push(x);
        int m = (l + r) / 2;
        upd(x * 2, l, m, tl, min(m, tr), y);
        upd(x * 2 + 1, m + 1, r, max(m + 1, tl), tr, y);
        t[x] = max(t[x * 2], t[x * 2 + 1]);
}

long long get(int x, int l, int r, int tl, int tr)
{
        if(tl > tr){
                return -1e18;
        }
        if(l == tl && r == tr){
                return t[x];
        }
        push(x);
        int m = (l + r) / 2;
        return max(get(x * 2, l, m, tl, min(m, tr)), get(x * 2 + 1, m + 1, r, max(m + 1, tl), tr));
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n >> m;
        for(int i = 1; i <= m; i++){
                int l, r;
                cin >> l >> r >> a[i];
                f[i] = l;
                b[l].push_back(i);
                e[r].push_back(i);
        }
        long long d = 0, best = 0;
        for(int i = 1; i <= n; i++){
                upd(1, 0, n, i - 1, i - 1, d);
                for(int x: b[i]){
                        upd(1, 0, n, 0, i - 1, a[x]);
                }
                d = get(1, 0, n, 0, i - 1);
                for(int x: e[i]){
                        upd(1, 0, n, 0, f[x] - 1, - a[x]);
                }
                best = max(best, d);
        }
        cout << best << "\n";
}



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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMinimum(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMaximum(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */


long long facctorialMethod(long long k) {
    ll sum = 1;
    for (ll i = 1; i <= k; ++i) {
        sum = (sum * i) % (1000000007);
        //sum = sum % (1000000007);
    }
    return sum;
}

int N;
vector<int> a(100010);
vector<int> c(100010, 0);
int ccc = 0;

int cal(int n) {
    int nn = n - 1;
    int t = a[nn];
    c[nn]++;
    ccc += 1;
    if (t == 2) {
        return 1;
    } else if (c[nn] > 1) {
        return 2;
    } else {
        return cal(t);
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    int ans = -1;
    int aa = cal(1);
//    cout << aa << endl;
    if (aa == 1) {
        ans = ccc;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int64_t N, M;
    cin >> N >> M;
    int64_t x = M * 1900 + (N - M) * 100;
    int64_t y = pow(2, M);
    int64_t z = x * y;
    cout << z << endl;
}

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

int main() {
	long n;
	cin >> n;
	string s;
	vector<string> vec;
	for (long i = 0; i < n; i++) {
		cin >> s;
		vec.push_back(s);
	}
	std::sort(vec.begin(), vec.end());
	vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
	cout << vec.size() << endl;
	return 0;
}

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

bool linear_search(int A[], int n, int m) {
    int i = 0;
    A[n] = m;
    while(A[i] != m) {
        i++;
    }
    return i != n;
}

int main() {
    int n;
    cin >> n;
    int S[n];
    for (int i = 0; i < n; ++i) {
        cin >> S[i];
    }
    int q;
    int count = 0;
    cin >> q;
    int t;
    for (int j = 0; j < q; ++j) {
        cin >> t;
//        for (int i = 0; i < n; ++i) {
//           if(S[i] == t) {
//               count++;
//           }
//        }
        if(linear_search(S, n, t)){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3108
A, B, K = map(int, input().split())
for i in range(K):
	if i % 2 == 0:
		# takahashi
		if A % 2 == 1:
			A -= 1
		A, B = A // 2, B + A // 2
	else:
		# aoki
		if B % 2 == 1:
			B -= 1
		A, B = A + B // 2, B // 2
print(A, B)


Measured memory_bytes: 2940
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());
    long digit = whatDigit(n);
    long answer = 0;
    if(n<10) Console.WriteLine(n);
    else
    {
      answer += 9*(digit-1);
      long memo = 10;
      for(long i = 0; i < digit-2; i++)
      {
        memo *= 10;
      }
      answer += n / memo - 1;
      if(n % 10 == 9) answer++;
      Console.WriteLine(answer);
    }
	}
  
  static long whatDigit (long n)//nは何桁か
  {
    for(long i = 1; i < 20; i++)
    {
      n /= 10;
      if(n == 0)
      {
        return i;
        break;
      }
    }
    return 0;
  }
}

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


int main(int argc, const char * argv[]) {
    
    int h,w;
    string s[51];
    int result[51][51];
    
    for(int i=0;i<51;i++){
        for(int j=0;j<51;j++){
            result[i][j]=0;
        }
    }
    
    cin >> h >> w;
    
    for(int i=0;i<h;i++){
        cin >> s[i];
    }
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            
            if(s[i][j]=='#'){
                continue;
            }
            
            if(i!=0){
                if(j!=0){
                    if(s[i-1][j-1]=='#'){
                        result[i][j]++;
                    }
                }
                
                if(s[i-1][j]=='#'){
                    result[i][j]++;
                }
                
                if(j-1!=w){
                    if(s[i-1][j+1]=='#'){
                        result[i][j]++;
                    }
                }
                
            }
            
            
            if(j!=0){
                if(s[i][j-1]=='#'){
                    result[i][j]++;
                }
            }
            if(j-1!=w){
                if(s[i][j+1]=='#'){
                    result[i][j]++;
                }
            }
            
            
            if(i-1!=h){
                if(j!=0){
                    if(s[i+1][j-1]=='#'){
                        result[i][j]++;
                    }
                }
                
                if(s[i+1][j]=='#'){
                    result[i][j]++;
                }
                
                if(j-1!=w){
                    if(s[i+1][j+1]=='#'){
                        result[i][j]++;
                    }
                }
            }
            
        }
        
    }
    
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
        
            if(s[i][j]=='#'){
                cout << '#';
            }
            else{
                cout << result[i][j];
            }
            
        }
        cout << endl;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-9;
const double PI = acos(-1);
const int MOD = 998244353;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 500005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
int arr[MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#else
#endif
    scanf("%d", &n);
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        sum += i;
    }
    printf("%lld", sum);
    return 0;
}

Measured memory_bytes: 3820
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

const int mod = 1e9 + 7;

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

  vector<int> pow10(7 + 1);
  pow10[0] = 1;
  for (int i = 1; i < (int)pow10.size(); ++i)
    pow10[i] = 10LL * pow10[i - 1] % mod;

  vector<int> f((int)1e7);
  f[0] = 0;
  for (int d = 1; d <= 7; ++d) {
    for (int i = pow10[d - 1]; i < pow10[d]; ++i)
      f[i] = d;
  }

  int result = 0;

  int current_sum = 1;
  int r = 1;
  for (int l = 1; l < (int)1e7; ++l) {
    while (current_sum < sum) {
      ++r;
      if (r < (int)1e7) current_sum += f[r];
      else current_sum += 8;
    }
    if (current_sum == sum) {

      ++result;
      if (result >= mod) result -= mod;
    }
    assert(l <= r);
    current_sum -= f[l];
  }

  int pow10fl = 1e8;
  int pow10fl1 = 1e7;

  for (int fl = 8; fl <= sum; ++fl) {
    if (sum % fl == 0) {
      int many = sum / fl;
      result += pow10fl - pow10fl1 - many + 1;
      result %= mod;
      if (result < 0) result += mod;
    }

    int min_b = sum % fl;
    if (min_b == 0) min_b = fl;
    if ((sum - min_b) / fl - min_b >= 1) {
      int max_k = (sum - 1 - (lint)min_b * (fl + 1)) / ((lint)fl * (fl + 1));
      result += max_k + 1;
      if (result >= mod) result -= mod;
    }

    pow10fl = 10LL * pow10fl % mod;
    pow10fl1 = 10LL * pow10fl1 % mod;
  }
  printf("%d\n", result);
  return 0;
}


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

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String[] line;
      MyList list = new MyList();

      for(int i=0; i<n; i++) {
        line = br.readLine().split(" ");
        switch( line[0] ) {
          case "insert" :
            list.insertFirst( Integer.parseInt(line[1]) );
            break;
          case "delete" :
            list.delete( Integer.parseInt(line[1]) );
            break;
          case "deleteFirst" :
            list.deleteFirst();
            break;
          case "deleteLast" :
            list.deleteLast();
            break;
          default :
            System.out.println("n:" + i + " is failed.");
        }
      }

      System.out.println ( list.getAllElements() );
    }
  }
}

class Node {
  Node next,prev;
  int key;

  public Node(int key) {
    this.key = key;
  }
}

class MyList {
  Node nil;
  Node current;
  int size;

  public MyList() {
    nil = new Node(0);
    nil.next = nil.prev = nil;
    size = 0;
  }

  public StringBuilder getAllElements() {
    StringBuilder buf = new StringBuilder(size*2);

    if(size > 0){
      current = nil.next;
      for(int i=0; i<size; i++){
        buf.append(current.key).append(" ");
        current = current.next;
      }
    }
    buf.setLength(buf.length()-1);

    return buf;
  }
  public void insertFirst(int x) {
    if(size == 0) {
      current = new Node(x);
      nil.next = current;
      nil.prev = current;
      current.prev = nil;
      current.next = nil;
      size++;
    }
    else {
      Node add = new Node(x);
      
      current.prev.next = add;
      add.prev = current.prev;

      add.next = current;
      current.prev = add;

      current = add;
      size++;
    }
  }
  public void deleteFirst() {
    current = nil.next;

    nil.next = current.next;
    current.next.prev = current.prev;

    current = current.next;
    size--;
  }
  public void deleteLast() {
    current = nil.prev;

    nil.prev = current.prev;
    current.prev.next = current.next;

    current = nil.next;
    size--;
  }
  public void delete(int x) {
    Node target = findFirst(x);

    if(target == nil) current = current.next;
    else if( target == nil.prev ) deleteLast();
    else {
      current.prev.next = target.next;
      current.next.prev = target.prev;
      current = nil.next;
      size--;
    }
  }
  private Node findFirst(int x) {
    while(current != nil) {
      if(current.key == x) break;
      current = current.next;
    }

    return current;
  }
}


Measured memory_bytes: 190300
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define zahyoutype double
int r;
typedef struct Point{zahyoutype x,y;}P;
typedef struct line{P p1,p2;}L;
P zero={0,0};

zahyoutype innerproduct(P p,P q,P o){return (p.x-o.x)*(q.x-o.x)+(p.y-o.y)*(q.y-o.y);}
zahyoutype crossproduct(P p,P q,P o){return (p.x-o.x)*(q.y-o.y)-(p.y-o.y)*(q.x-o.x);}
double crossangle(P p,P q,P o){return atan2(crossproduct(p,q,o),innerproduct(p,q,o));}

double seglen(L s){return hypot(s.p2.x-s.p1.x,s.p2.y-s.p1.y);}
double distPP(P p,P q){return hypot(p.x-q.x,p.y-q.y);}
double distPL(P p,L s){return fabs(crossproduct(p,s.p2,s.p1)/seglen(s));}
double distPS(P p,L s){
	zahyoutype c =innerproduct(   p,s.p2,s.p1);
	zahyoutype ss=innerproduct(s.p2,s.p2,s.p1);
	if(c<=0)return distPP(p,s.p1);
	if(c<=ss)return distPL(p,s);
	return distPP(p,s.p2);
}
P crosspoint(L s,L t){
	zahyoutype x=1;if(x/2==0){puts("type error");exit(0);}
	double deno=(s.p1.x-s.p2.x)*(t.p1.y-t.p2.y)-(t.p1.x-t.p2.x)*(s.p1.y-s.p2.y);
	zahyoutype xnume=  s.p1.x*t.p1.x*(s.p2.y-t.p2.y)-s.p1.x*t.p2.x*(s.p2.y-t.p1.y)-s.p2.x*t.p1.x*(s.p1.y-t.p2.y)+s.p2.x*t.p2.x*(s.p1.y-t.p1.y);
	zahyoutype ynume=-(s.p1.y*t.p1.y*(s.p2.x-t.p2.x)-s.p1.y*t.p2.y*(s.p2.x-t.p1.x)-s.p2.y*t.p1.y*(s.p1.x-t.p2.x)+s.p2.y*t.p2.y*(s.p1.x-t.p1.x));
	P p={xnume/deno,ynume/deno};
	return p;
}

P cross(L s,int r){
	//segment sとx^2+y^2=r^2の交点のうち、s.p1に近い方を求める
	//s.p1が円の外、s.p2が円の中
	P p={0,0};
	P q={s.p2.y-s.p1.y,-(s.p2.x-s.p1.x)};
	L t={p,q};
	P c=crosspoint(s,t);
	double d=distPP(c,p);
	double coe=sqrt(r*r-d*d)/seglen(s);
	P ans={c.x-coe*(s.p2.x-s.p1.x),c.y-coe*(s.p2.y-s.p1.y)};
	return ans;
}

void readpoint(P*p){zahyoutype x=1;scanf(x/2?"%lf%lf":"%ld%ld",&p->x,&p->y);}

double f(P p,P q){
	int coe=1;
	if(crossproduct(p,q,zero)<0){
		P t=p;p=q;q=t;
		coe=-1;
	}	
	double ans;
	if(distPP(p,zero)<r){
		if(distPP(q,zero)<r)ans=crossproduct(p,q,zero)/2;//中中
		else{//中外
			L s={q,p};
			P m=cross(s,r);
			double theta=crossangle(m,q,zero);
			ans=crossproduct(p,m,zero)/2+r*r*theta/2;
		}
	}else{
		L s={p,q};
		if(distPP(q,zero)<r){//外中
			P m=cross(s,r);
			double theta=crossangle(p,m,zero);
			ans=crossproduct(m,q,zero)/2+r*r*theta/2;
		}else{//外外
			if(distPS(zero,s)<r){//交わる
				L s1={p,q};
				P m1=cross(s1,r);
				L s2={q,p};
				P m2=cross(s2,r);
				double theta1=crossangle(p ,m1,zero);
				double theta2=crossangle(m2,q ,zero);
				ans=r*r*theta1/2+crossproduct(m1,m2,zero)/2+r*r*theta2/2;
			}else{
				double theta=crossangle(p,q,zero);
				ans=r*r*theta/2;
			}
		}
	}
	return ans*coe;
}

P a[110];
int main(){
	int n;
	scanf("%d%d",&n,&r);
	for(int i=0;i<n;i++)readpoint(a+i);
	double ans=0;
	for(int i=0;i<n;i++)ans+=f(a[i],a[(i+1)%n]);
	printf("%.9f\n",ans);
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        string s, t;
        in >> s;
        t = s;
        reverse(t.begin(), t.end());
        out << (s == t ? "Yes" : "No") << endl;
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	char s[100];
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	int flag = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'Y') {
			flag = 1;
		}
	}
	if (flag == 0) {
		cout << "Three" << endl;
	}
	else {
		cout << "Four" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
struct edge
{
	int to,cap,cost,rev;
};
int nn=5100;
vector<edge>G[5105];
int dist[5105];
int prevv[5105],preve[5105];

void add_edge(int from,int to,int cap,int cost)
{
	G[from].pb((edge){to,cap,cost,G[to].size()});
	G[to].pb((edge){from,0,-cost,G[from].size()-1});
}
int ans = INF;
int mincost_maxflow(int s,int t,int f)
{
	int res=0;
	while(f>0)
	{
		//??????n???????????????????????°?????????????????°??§???????????¨?????°?????????????????°??§?????????!!!!!!
		fill(dist,dist+nn,INF);
		dist[s]=0;
		bool upd=true;
		while(upd)
		{
			upd=false;
			for(int v=0;v<nn;v++)
			{
				if(dist[v]==INF) continue;
				for(int i=0;i<G[v].size();i++)
				{
					edge &e = G[v][i];
					if(e.cap>0 && dist[e.to]>dist[v]+e.cost)
					{
						dist[e.to]=dist[v]+e.cost;
						prevv[e.to]=v;
						preve[e.to]=i;
						upd=true;
					}
				}
			}
		}
		if(dist[t]==INF) return res;
		int d=f;
		for(int v=t;v!=s;v=prevv[v])
		{
			d = min(d,G[prevv[v]][preve[v]].cap);
		}
		f-=d;
		res+=d*dist[t];
		ans = min(ans,res);
		for(int v=t;v!=s;v=prevv[v])
		{
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}
int n,a[1005],b[1005];
vector<int>val;
int main(){
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i] >> b[i];
		val.pb(a[i]); val.pb(b[i]);
	}
	SORT(val); ERASE(val);
	for(int i=1;i<=n;i++){
		add_edge(0,i,1,0);
		int A = POSL(val,a[i]),B = POSL(val,b[i]);
		add_edge(i,1200+A,1,-b[i]);
		add_edge(i,1200+B,1,-a[i]);
	}
	for(int i=0;i<val.size();i++){
		add_edge(i+1200,3500,1,0);
	}
	mincost_maxflow(0,3500,n);
	cout << -ans << endl;
}

Measured memory_bytes: 3540
mod=1000000007
n=int(input())
a=input()
b=input()
#1 22
#1
d=[1]
for i in range(1,n):
    if a[i-1]==a[i]:
        d[-1]+=1
    else:
        d.append(1)
ans=[3,6][d[0]-1]
for i in range(1,len(d)):
    if d[i-1]==d[i]==1:
        t=2
    elif d[i-1]==d[i]==2:
        t=3
    elif d[i-1]==2 and d[i]==1:
        t=1
    else:
        t=2
    ans=(ans*t)%mod
print(ans)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

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

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

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

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



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

ll solve(ll h, ll w)
{
    if (h==1||w==1)
    {
        return 1;
    }
    ll ans=0, a=0, b=0;
    if (w%2!=0)
    {
        a=w/2+1;
    }
    else
    {
        a=w/2;
    }
    b=w/2;
    if (h%2==0)
    {
        ans=(h/2)*(a+b);
    }
    else
    {
        ans=((h/2+1)*a)+((h/2)*b);
    }
    return ans;

}
int main()
{
    start();
    ll h, w;
    cin>>h>>w;
    cout<<solve(h, w);
    return 0;
}

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

//const int maxn=1e5+5;
char s[105];
int main()
{
    scanf("%s",s+1);
    int n=strlen(s+1);
    for(int i=1;i<=n;i++)
    {//L, U, or D
        if(((i&1)&&(s[i]=='R'||s[i]=='U'||s[i]=='D'))||((i%2==0)&&(s[i]=='L'||s[i]=='U'||s[i]=='D')))
            continue;
        else
        {
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}


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

ll cnt;
int l;
int a[1000000];
int n;
vector<int> G;

void insertionsort(int a[],int n,int g){
  for(int i=g;i<n;i++){
    int v=a[i];
    int j=i-g;
    while(j>=0 && a[j]>v){
      a[j+g]=a[j];
      j-=g;
      cnt++;
    }
    a[j+g]=v;
  }
}

void shellsort(int a[],int n){
  for(int h=1;;){
    if(h>n) break;
    G.push_back(h);
    h=3*h+1;
  }
  for(int i=G.size()-1;i>=0;i--){
    insertionsort(a,n,G[i]);
  }
}

int main() {
  cin>>n;
  for(int i=0;i<n;i++) scanf("%d",&a[i]);
  cnt=0;
  shellsort(a,n);
  cout<<G.size()<<endl;
  for(int i=G.size()-1;i>=0;i--){
    printf("%d",G[i]);
    if(i)printf(" ");
  }
  printf("\n");
  printf("%d\n",cnt);
  for(int i=0;i<n;i++) printf("%d\n",a[i]);
  return 0;
}



Measured memory_bytes: 7180
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <unordered_set>
#include <unordered_map>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
#define debug( fmt, ... ) \
        fprintf( stderr, \
                  fmt "\n", \
                  ##__VA_ARGS__ \
        )

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1 << 30;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int MOD = 1000000007;
// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

struct prepare {
	prepare() {
	    cout.setf(ios::fixed, ios::floatfield);
	    cout.precision(8);
	    ios_base::sync_with_stdio(false);
	}
} _prepare;

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

    char st = S[0];
    int c = 0;
    REP(i, 1, S.size()) {
        if(st != S[i]) {
            c++;
            st = S[i];
        }
    }

    cout << c << endl;
	
	
    return 0;
}


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

using ll = long long;

void max_self(ll& a, ll b) {
    a = max(a, b);
}


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

    int base = 1;
    while(base <= n) {
        base *= 2;
    }
    // base is the smallest power of 2 that is not smaller than n
    vector<ll> tree(2 * base);

    vector<int> h(n), a(n);
    for(int i = 0; i < n; ++i) {
        scanf("%d", &h[i]);
    }
    for(int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    vector<ll> dp(n + 1);
    // dp[i] - the max total beauty so far if the last taken flower has height i
    for(int flower = 0; flower < n; ++flower) {

        // max dp[i] for i in [0, h[flower]-1]
        int x = h[flower] + base;
        ll best = 0;
        while(x > 1) {
            if(x % 2 == 1) {
                max_self(best, tree[x-1]);
            }
            x /= 2;
        }
        dp[h[flower]] = best + a[flower];

        for(int i = base + h[flower]; i >= 1; i /= 2) {
            max_self(tree[i], dp[h[flower]]);
        }

        //~ for(int i = 0; i < h[flower]; ++i) {
            //~ max_self(dp[h[flower]], dp[i] + a[flower]);
        //~ }
    }
    ll answer = 0;
    for(int i = 0; i <= n; ++i) {
        max_self(answer, dp[i]);
    }
    printf("%lld\n", answer);
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  cout << x2 + y1 - y2 << " " << y2 - (x1 - x2) << " ";
  cout << x1 + y1 - y2 << " " << y1 - (x1 - x2) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    vector<int> cs(9);
    for (int i = 0; i < 9; i++) {
        cin >> cs[i];
    }

    for (int b1 = 0; b1 <= 100; b1++) {
        for (int b2 = 0; b2 <= 100; b2++) {
            for (int b3 = 0; b3 <= 100; b3++) {
                vector<int> bs = {b1, b2, b3};
                vector<set<int>> cand_as(3);
                // set<int> cand_a1, cand_a2, cand_a3;
                for (int i = 0; i < 9; i++) {
                    cand_as[i % 3].insert(cs[i] - bs[i / 3]);
                }

                bool ok = true;
                for (auto as : cand_as) {
                    if ((int) as.size() != 1 || *as.begin() < 0 || *as.begin() > 100) {
                        ok = false;
                    }
                }
                if (ok) {
                    // printf("a1: %d, a2: %d, a3: %d, b1: %d, b2: %d, b3: %d\n",
                    //         *cand_as[0].begin(), *cand_as[1].begin(), *cand_as[2].begin(),
                    //         b1, b2, b3);
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3604
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N,0);
	
	for(int i=0;i<N;++i){
		cin >> A[i];
		B[ A[i] ]++;
	}
	sort(A.begin(), A.end() );
	int MIN = A[0];
	int MAX = A[N-1];
	int MIN_count = B[MIN];
	int MAX_count = B[MAX];
	for(int i=MIN+1;i<=MAX;++i){
		if( B[i] < 2 ){
			cout << "Impossible" << endl;
			return;
		}
	}
	
	if( MIN == 1 ){
		if( MIN_count == 1 ){
			if( MAX == 2 && MAX_count == N-1 ){
				cout << "Possible" << endl;
			}else{
				cout << "Impossible" << endl;
			}
			return;
		}
		if( MIN_count == 2 ){
			if( MAX == 1 && N==2 ){
				cout << "Possible" << endl;return;
			}else{
				cout << "Impossible" << endl;return;
			}
			return;
		}
		cout << "Impossible" << endl;
		return;
	}else{
		if( MIN_count > 2 ){
			cout << "Impossible" << endl;
			return;
		}
		if( MIN_count == 1 ){
			if( MAX != MIN*2 ){
				cout << "Impossible" << endl;
				return;
			}
		}else{
			if( MAX != MIN*2-1 ){
				cout << "Impossible" << endl;
				return;
			}
		}
	}
	cout << "Possible" << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main() {
    int N =0;
    int i,j;
    int sorted=0;
    int data[110];
    int temp;

    scanf("%d",&N);

    for(i = 0; i < N; i++){
        scanf("%d",&data[i]);
    }
    while(sorted < N-1) {

        for(i = 0;i < N-1; ++i){
            printf("%d ",data[i]);
        }
        printf("%d",data[N-1]);

        for (i = 0; i < sorted+1; ++i) {
            if (data[sorted + 1] < data[i]) {
                temp = data[sorted + 1];
                for (j = sorted; j >= i ; --j) {
                    data[j + 1] = data[j];
                }
                data[i] = temp;
                break;
            }
        }


        putchar('\n');
        sorted++;
    }

    for(i = 0;i < N-1; ++i){
        printf("%d ",data[i]);
    }
    printf("%d\n",data[N-1]);


    return 0;
}


Measured memory_bytes: 2124
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
  int N, tmp, sum;
  cin >> N;
  
  vector<int> A(N), C(N-1);
  
  sum = 0;
  for(int i=0; i<N; i++) {
    cin >> A[i];
  }
  for(int i=0; i<N; i++) {
    cin >> tmp;
    sum += tmp;
  }
  for(int i=0; i<N-1; i++) {
      cin >> C[i];
  }

  for(int i=0; i<N-1; i++) {
    if(A[i+1]-A[i] == 1){
      sum += C[A[i]-1];
    }
  }
  
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
//ミョ(-ω- ?)
int main() {
    int n,p;
    cin >> n >> p;
    cout << fixed << setprecision(0);
    vector<bool> a(n);
    bool b = 0;
    rep(i,n){
        int in;cin >> in;
        if(in%2)b = true;
    }
    if(!b){
        if(p)cout << 0 << endl;
        else cout << pow(2,n) << endl;
    }else cout << pow(2,n-1) << endl;
    return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val H, W = ni()
    val g = nm_c(H, W)

    val dp = Array.ofDim[Long](H, W)
    dp(0)(0) = 1
    REP(H) { i =>
      REP(W){ j =>
        if (g(i)(j) == '.') {
          if (i > 0) dp(i)(j) += dp(i - 1)(j)
          if (j > 0) dp(i)(j) += dp(i)(j - 1)
          dp(i)(j) %= MOD
        }
      }
    }

    out.println(dp(H-1)(W-1))
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }


  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

Measured memory_bytes: 41828
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    val heights = listOfInt()

    if (n == 1) {
        println("Yes")
        return
    }

    var lastH = heights[n-1]
    for (i in n-2 downTo 0) {
        if (lastH < heights[i]) {
            if (lastH < heights[i] - 1) {
                println("No")
                return
            }
            lastH = heights[i] - 1
        } else {
            lastH = heights[i]
        }
    }

    println("Yes")
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 56176
#include<stdio.h>
#include<math.h>
int main(void)
{
  int n,i;
  while(1)
  {
    double m,In=0,alp;
    int sum=0;
    scanf("%d",&n);

    if(n==0) break;

    int s[n];
    for(i=0;i<n;i++)
    {
      scanf("%d",&s[i]);
      sum+=s[i];
    }
    m=(double)sum/n;
    //printf("%f\n",m);
    for(i=0;i<n;i++)
    {
      In+=pow(s[i]-m,2);
    }
    alp=sqrt(In/n);
    printf("%f\n",alp);
  }
  return 0;
}



Measured memory_bytes: 2096