akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			long[] a = cin.ArrayLong(n);
			long sum = a.Sum();
			int index = 0;
			long half = sum / 2;
			long tempSum = 0;
			for (int i = 0; i < n; i++) {
				tempSum += a[i];
				if (tempSum >= half) {
					index = i;
					break;
				}
			}

			long ans = long.MaxValue;
			{
				long sum1 = 0;
				for (int i = 0; i <= index - 1; i++) {
					sum1 += a[i];
				}

				long sum2 = 0;
				for (int i = index; i < n; i++) {
					sum2 += a[i];
				}

				long temp = Math.Abs(sum1 - sum2);
				ans = Math.Min(temp, ans);
			}

			{
				long sum1 = 0;
				for (int i = 0; i <= index; i++) {
					sum1 += a[i];
				}

				long sum2 = 0;
				for (int i = index + 1; i < n; i++) {
					sum2 += a[i];
				}

				long temp = Math.Abs(sum1 - sum2);
				ans = Math.Min(temp, ans);
			}


			Console.WriteLine(ans);
		}
	}


	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 35584
#include <stdio.h>

int main(void){

	int num,a,b,sum;
    char buf[128];
    fgets(buf, 128, stdin);
    sscanf(buf, "%d %d", &a,&b);

	int flag = 0;
	sum = a + b;

	if(a % 3 == 0 || b % 3 == 0 || sum % 3 == 0 ){flag = 1;}

	if(flag == 0){printf("Impossible");}
	else if(flag == 1){printf("Possible");}

	return 0;

}


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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {

    int h, w;
    cin >> h >> w;

    vector<string> grid(h);
    fo(i, h) cin >> grid[i];

    set<int> row, col;
    fo(i, h) {
        int cont = 0;
        fo(j, w) {
            if ( grid[i][j] == '.' ) cont++;
        }
        if ( cont == w ) row.insert(i);
    }

    fo(j, w) {
        int cont = 0;
        fo(i, h) {
            if ( grid[i][j] == '.' ) cont++;
        }
        if ( cont == h ) col.insert(j);
    }

    fo(i, h) {
        if ( row.find(i) != row.end() ) continue;
        fo(j, w) {
            if ( col.find(j) != col.end() ) continue;
            cout << grid[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
/******************************************
* NICK : nikhilsinghh59 *
******************************************/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"

#define PB push_back
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
const int M = 1e9+7;
int main()
{   
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    ll n;
    cin >> n;
    
    if(n==2) {
        cout << 1;
        return 0;
        //continue;
    }

    // k = (n-1)/m

   // int m=1;

    ll ans=1;

    for(ll i=2 ; i<=sqrt(n-1) ; i++) {
        if((n-1)%i==0) {
            ans++;
            if((n-1)/i != i) ans++;
        }
    }

    for(int i=2 ; i<=sqrt(n) ; i++) {
        if(n%i==0) {
            ll k = n;
            while(k%i==0) {
                k/=i;
            }
            if(k%i == 1) {
                ans++;
            }

            if(n/i != i) {
                k = n;
                while(k%(n/i) == 0) {
                    k/=(n/i);
                }
                if(k%(n/i) == 1) {
                    ans++;
                }
            }
        }
    }

    cout << ans+1;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		StringBuilder sb = new StringBuilder(sc.next()).reverse();
		int count = 0;
		for (int i = 0; i < sb.length(); i++) {
		    char c = sb.charAt(i);
		    if (c == ')') {
		        count++;
		    } else if (c == '(') {
		        if (count > 0) {
		            count--;
		        }
		    }
		}
		for (int i = 0; i < count; i++) {
		    sb.append("(");
		}
		sb.reverse();
		count = 0;
		for (int i = 0; i < sb.length(); i++) {
		    char c = sb.charAt(i);
		    if (c == '(') {
		        count++;
		    } else if (c == ')') {
		        count--;
		    }
		}
		for (int i = 0; i < count; i++) {
		    sb.append(")");
		}
	    System.out.println(sb);
   }
}




Measured memory_bytes: 23764
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-11

#define INF 1e16

const int MaxSize = 100 + 10;
int N, W;
int size[4];
LL vs[4][MaxSize];
LL ans = 0;
LL w1 = -1;

void calc(int si, LL rW, LL pV) {

	if (si < 3)
		calc(si + 1, rW, pV); //no s

	LP(i, 0, size[si])
	{
		LL curW = (w1 + si) * (i + 1);

		if (curW > rW)
			continue;

		LL curV = vs[si][i] + pV;

		//cout << si << " " << rW << " " << pV << " " << curV << endl;
		ans = min(ans, curV);

		if (si < 3)
			calc(si + 1, rW - curW, curV);
	}
}

int main() {

	ios_base::sync_with_stdio(false);
	//freopen("/Users/george/A_1.in", "r", stdin);

	cin >> N >> W;

	LL w, v;

	LP(i, 0, N)
	{
		cin >> w >> v;

		if (w1 < 0)
			w1 = w;

		int si = w - w1;

		//cout <<"PRE-SORT!" << endl;
		vs[si][size[si]] = -v;
		size[si]++;
	}

	LP(si, 0, 4)
	{
		//cout << "SORT!" << endl;

		sort(vs[si], vs[si] + size[si]);

		LP(i, 1, size[si])
			vs[si][i] += vs[si][i - 1];

		/*
		 LP(i, 0, size[si])
		 cout << vs[si][i] << " ";
		 cout << endl;
		 */

	}

	calc(0, W, 0);

	cout << -ans;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>

using namespace std;

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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        v[i] -= x;
        v[i] = abs(v[i]);
    }
    for (int i = 1; i < n; i++) {
        v[i] = gcd(v[i], v[i - 1]);
    }
    cout << v[n - 1] << endl;
}


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

int main(){
	int N, K;
	cin >> N >> K;
	int D[K];
	for(int i = 0; i < K; i++){
		cin >> D[i];
	}
	while(true){
		bool ok = true;
		for(int i = 0; i < to_string(N).size(); i++){
			for(int j = 0; j < K; j++){
				if(to_string(N)[i] - '0' == D[j]){
					ok = false;
					break;
				}
			}
			if(!ok){
				break;
			}
		}
		if(ok){
			cout << N << endl;
			return 0;
		}else{
			N++;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    string in; cin >> in;
    string res = "Good";
    rep(i, 3){
        if(in[i] == in[i+1]) res = "Bad";
    }
    cout << res << endl;

    return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll k, n;
    cin >> k >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; }
    ll longest = (k + a[0]) - a[n - 1];
    repd(i, 1, n) { longest = max(longest, abs(a[i] - a[i - 1])); }

    cout << k - longest << endl;
    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define print(x) cerr <<"\033[1;33m" << x << "\033[0m" << '\n'
#define int long long
#define LL __int128_t
const int xx = 2e5;
const int MOD = 1e9 + 7;
const int inf = 1e12;

bool cmp(const pair<int,int>&a , const pair<int,int>&b){
  return a.second < b.second;
}
signed main(){
  ios::sync_with_stdio(false);cin.tie(0);

  int n;
  cin >> n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  map<int,int>cnt;
  for(int i=0;i<n;i++){
    cnt[a[i]]++;
  }
  vector<pair<int,int>>vp;
  for(auto i : cnt){
    vp.emplace_back(i.first , i.second);
  }
  sort(vp.rbegin() , vp.rend() , cmp);
  dg1(vp);

  int x = 0 , y = 0;
  int ind = min(1ll , (int)vp.size() - 1ll);
  x = vp[0].first;
  y = vp[ind].first;

  if(x == y){
    if( x == 1){
      y = 2;
    }
    else y = x - 1;
  }
  dg2(x , y);

  int ans1 = 0 , ans2 = 0;

  for(int i=0;i<n;i+=2){
    if(a[i] != x){
      ans1++;
    }
    if(a[i] != y) ans2++;
  }

  for(int i=1;i<n;i+=2){
    if(a[i] != y) ans1++;
    if(a[i] != x) ans2++;
  }

  cout << min(ans1 , ans2) << '\n';

}

Measured memory_bytes: 9464
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG

 // 深さ優先探索
vector<bool> seen;
int dfs(const Graph &G, ll v) {
    seen[v] = true; // v を訪問済にする
    int score = 0; 

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー

        // 負荷さ優先探索中の処理



        dfs(G, next_v); // 再帰的に探索, 毎回mat渡してええの？
    }
    return score;
} 

/*
//桁数の計算
ll keta(ll num){
  ll ans= 0 ;
  ll rem;

  for (ll i = 4; i >= 0 ; i--){
    rem = pow(10,i);
    ans += (num / rem); 
    num = num % rem;
  }
  return ans;
}
*/


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

  bitset<1000000000> keep;

     for (ll i = 0; i < N; i++){
      ll tmp;
      cin >> tmp;
      keep.flip(tmp - 1); //ビット反転
    } 

    ll ans = keep.count();

    cout << ans <<endl; 

    return 0;
}

Measured memory_bytes: 122368
import numpy as np
input_line = map(int,raw_input().split(" "))
H = input_line[0]
W = input_line[1]
C = np.array([])
for h in range(H):
	tmp = list(raw_input())
	C = np.append(C,np.array(tmp))
	C = np.append(C,np.array(tmp))
	

C = C.reshape(2*H,W)
txt = ""
for c in C:
	for cc in c:
		txt += cc
	print txt
	txt = ""


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


int main()
{
	int a[100010] = {0};
	int N,num;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >>num ;
		 a[num]++;
	}

	int ans = 0;
	for (int i = 1; i < 100010; i++) {
		ans = max(ans, a[i-1]+a[i]+a[i+1]);
	}

	cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
int n,k;
  cin>>n>>k;
  if(n%k==0){
    cout<<0<<endl;
  }else{
    cout<<1<<endl;
  }


  return 0;
}

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

int main() {
    int N;
    std::string S;
    std::cin >> N >> S;

    for (size_t i = 0; i < S.size(); ++i) {
        if (S[i] + N <= 'Z') {
            std::printf("%c", (S[i] + N));
        } else {
            std::printf("%c", (S[i] + N - 'Z' + 'A' - 1));
        }
    }

    std::cout << std::endl;

    return 0;
}


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

int main(){
    int x, y, tmp;

    while (1) {
        cin >> x >> y;
        if ( x == 0 && y == 0) break;
        else if (x < y) cout << x << " " << y << endl;
        else {
            tmp = y;
            y = x, x = tmp;
            cout << x << " " << y << endl;
        }
    }   
}


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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back
#define fi first
#define se second
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
#define INF (ll)1e18
#define ll long long
#define P pair<ll, ll>
#define vll vector<ll>
#define vvll vector<vll>

ll n, m, st;
vector<vector<P> > g;

void solve1(void) {
    vll dist(n, INF);
    priority_queue<P, vector<P>, greater<P> > q;
    q.push(P(0, st)); 
    dist[st] = 0; // "見た"
    while (q.size()) { 
        // q = {(d, v)} : 頂点vに距離dで到達できる（dは最適とは限らない）
        // dist[v] : 今までに見た中で、vに到達するための最短距離
        //
        // vの初出がここに来た時点で、dist[v]が最適であることは保証されている！
        // あとは、d = dist[v]のものだけ遷移すれば良い
        P st = q.top(); q.pop();
        ll d = st.fi, v = st.se;
        if (d > dist[v]) continue; // 同じvに異なる距離dで到達可能だが、最適なものだけを見ればよい
        rep(i, g[v].size()) {
            P edge = g[v][i];
            ll u = edge.fi, cost = edge.se;
            if (dist[v] + cost >= dist[u]) continue;
            dist[u] = dist[v] + cost; // "見た"
            q.push(P(dist[v] + cost, u));
        }
    }
    rep(i, n) {
        if (dist[i] == INF) 
            cout << "INF" << endl;
        else
            cout << dist[i] << endl;
    }
}

void solve2(void) {
    vll dist(n, INF); 
    priority_queue<P, vector<P>, greater<P> > q;
    q.push(P(0, st));  
    while (q.size()) { 
        // q = {(d, v)}: vにdで到達できる（dは最適とは限らない）
        // dist[v]: 今までに"見た"中で、vに到達するための最短距離
        P st = q.top(); q.pop();
        ll d = st.fi, v = st.se;
        if (d >= dist[v]) continue; 
        chmin(dist[v], d); // "見た"
        rep(i, g[v].size()) {
            P edge = g[v][i];
            ll u = edge.fi, cost = edge.se;
            q.push(P(dist[v] + cost, u));
        }
    }
    rep(i, n) {
        if (dist[i] == INF) 
            cout << "INF" << endl;
        else
            cout << dist[i] << endl;
    }
}
int main(void) {
    cin >> n >> m >> st;
    g.resize(n);
    rep(i, m) {
        ll u, v, d; cin >> u >> v >> d;
        g[u].pb(P(v, d));
    }
//    solve1();
    solve2();

    return 0;
}



Measured memory_bytes: 21556
import java.util.*

/**
 * @author karayuu
 */

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val train_standard = scanner.nextInt()
    val train_endless = scanner.nextInt()

    val bus_standard = scanner.nextInt()
    val bus_endless = scanner.nextInt()

    var sum = 0

    fun returnSmallOne(first: Int, second: Int): Int {
        return if (first < second) {
            first
        } else {
            second
        }
    }

    sum += returnSmallOne(train_standard, train_endless)
    sum += returnSmallOne(bus_standard, bus_endless)

    println(sum)
}

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

#define lint long long

int main() {
    lint s;
    cin >> s;
    
    set<lint> list;
    lint t = s;
    int cnt = 2;
    list.insert(s);
    while(true){
        if(t % 2 == 0){
            t = t / 2;
        } else {
            t = 3 * t + 1;
        }
        
        if(list.find(t) != list.end()){
            cout << cnt << endl;
            return 0;
        } else {
            list.insert(t);
            cnt++;
        }
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int N = Integer.parseInt(br.readLine());
        List<Integer> list = Arrays.stream(br.readLine().split(" "))
            .map(Integer::parseInt)
            .sorted(Comparator.reverseOrder())
            .collect(Collectors.toList());
            
        int longest = 0;
        int others = 0;
        for (int i = 0; i < N; i++) {
            if (i == 0) {
                longest = list.get(i);
            } else {
                others += list.get(i);
            }
        }
        out.println(longest >= others ? "No" : "Yes");
        out.close();
    }
}


Measured memory_bytes: 26836
#include<iostream>
using namespace std;
int main(void) {
	int x, y;
	while (cin >> x>>y && (x !=0 || y != 0)) {
		if (x > y) {
			cout << y << " " << x << endl;
		}
		else {
			cout << x << " " << y << endl;
		}
	}
}


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

int main(){
    long a, b;

    // int d;
    // int r;
    // // float f;
    // double f;

    cin >> a >> b;

    // cout << a << endl;
    // cout << b << endl;

    // double L = 1.5;
    // double R = 1.8;

    // int val1 = L + R;
    // int val2 = (int)L + (int)R;

    // cout << val1 << endl;
    // cout << val2 << endl;

    int d = a / b;
    int r = a % b;
    double f = ((double)a) / ((double)b);

    // float fa = (float)a;
    // float fb = (float)b;

    // double da = (double)a;
    // double db = (double)b;

    printf("%d %d %f \n", d, r, f);

    // cout << endl;
    // cout << fa << endl;
    // cout << fb << endl;

    // printf("%f \n", fa);
    // printf("%f \n", fb);

    // printf("%f \n", da);
    // printf("%f \n", db);
    // printf("%f \n", da / db);

    return 0;
}


Measured memory_bytes: 3208
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MAX_N = 4020;
const int INF = 1145141919;

struct BIT{
    // [1, n]
    vector<int>bit;
    int N;
    void init(int n){
        N = n;
        bit.resize(n, 0);
    }
    BIT(int n=0){
        init(n);
    }
    int sum(int i){
        int s = 0;
        while(i>0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    void add(int i, int x){
        if(i==0)return;
        while(i <= N){
            bit[i] += x;
            i += i & -i;
        }
    }
};

int dp[MAX_N][MAX_N];

int main(){
    
    rep(i,MAX_N)rep(j,MAX_N)dp[i][j] = INF;
    dp[0][0]=0;

    int N;
    cin >> N;
    BIT bit(2*N+10);

    vector<int>bpos(N+2, 0), wpos(N+2, 0);
    for(int i = 1; i <= 2*N; i++){
        char c;
        int a;
        cin >> c >> a;
        if(c=='B')bpos[a] = i;
        else wpos[a] = i;
        bit.add(i, 1);
    }

    for(int b=0; b<=N; b++){
        BIT tmpBit = bit;
        for(int w=0; w<=N; w++){
            chmin(dp[b+1][w], dp[b][w] + tmpBit.sum(bpos[b+1]-1));
            chmin(dp[b][w+1], dp[b][w] + tmpBit.sum(wpos[w+1]-1));
            tmpBit.add(wpos[w+1], -1);
        }
        bit.add(bpos[b+1], -1);
    }

    cout << dp[N][N] << endl;

    return 0;
}

Measured memory_bytes: 63360
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>

namespace IO {
    template <typename _T>
    inline bool read (_T& x) {
        x = 0;
        _T y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return false;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        x *= y;
        return true;
    }

    template <typename _T>
    inline _T input () {
        _T x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        x *= y;
        return x;
    }
};
using namespace IO;

#define reg register
#define MAX_N 200007
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define lep(i, l, r) for(int i = l; i < r; ++i)
#define irep(i, r, l) for(int i = r; i >= l; --i)
#define ilep(i, r, l) for(int i = r; i > l; --i)
typedef long long ll;

int N, K, bg;
char s[MAX_N];
int q[MAX_N];

inline void print () {
    rep (i, 1, N) {
        putchar(q[bg] + 'A');
        (bg += 1) %= N;
    } puts("");
}

int main () {
#ifdef LOCAL
    FIN("in");
#endif
    read(N), read(K);
    scanf("%s", s);
    bg = 0;
    lep (i, 0, N) q[i] = s[i] - 'A';
    int now = 0;
    int M = std::min(K, 2 * N);
    rep (i, 1, M) {
        if (now == q[bg]) {
            q[bg] = now ^ 1;
        } else {
            q[bg] = now ^ 1;
            (bg += 1) >= N ? bg = 0 : 0;
            now ^= 1;
        }
    }
    rep (i, 1, N) q[bg] ^= now, (bg += 1) %= N;
    if (K <= 2 * N) print();
    else {
        if (q[(bg + 1) % N] == 1) {
            if (K - 2 * N & 1) q[bg] ^= 1;
        }
        print();
    }
    return 0;
}



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

#define f(i,a,b) for (int i = a; i < b; i++)
#define pb push_back

int main() {
	string s; cin >> s;
  	int n = s.length();
  	long long ans = 0;
  	vector<int> pos;
  	f(i,0,n) if (s[i] == 'B') pos.pb(i);
  	f(i,0,pos.size()) ans += n-pos.size()+i-pos[i];
  	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 1532
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  string A, B, C; cin >> A >> B >> C;
  string result = "NO";
  if(A[A.length()-1]==B[0]&&B[B.length()-1]==C[0]) result = "YES";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
  io := IO{bufio.NewReaderSize(os.Stdin,100),bufio.NewWriterSize(os.Stdout,100)}
  n,m := io.NextInts()
  g := make([][]int,n)
  r := make([][]int,n)
  for i:=0;i<m;i++ {
    s,t := io.NextInts()
    g[s-1] = append(g[s-1],t-1)
    r[t-1] = append(r[t-1],s-1)
  }
  en := make([]float64,n)
  pn := make([]float64,n)
  pn[n-1] = 1
  for v:=n-2;v>=0;v-- {
    deg := 1/float64(len(g[v]))
    for _,u := range g[v] {
      en[v] += en[u]
      pn[v] += pn[u]
    }
    en[v] = en[v]*deg+1
    pn[v] *= deg
  }
  e1 := make([]float64,n)
  p1 := make([]float64,n)
  p1[0] = 1
  for v:=1;v<n;v++ {
    for _,u := range r[v] {
      deg := 1/float64(len(g[u]))
      e1[v] += (e1[u]+1)*deg
      p1[v] += p1[u]*deg
    }
  }
  ans := en[0]
  for v:=0;v<n-1;v++ {
    if len(g[v]) == 1 { continue }
    deg := len(g[v])
    now := en[0]
    for _,u := range g[v] {
      now += (e1[v]*pn[u]+p1[v]*en[u]+p1[v]*pn[u])/(float64(deg)*float64(deg-1))
    }
    for _,u := range g[v] {
      tmp := (e1[v]*pn[u]+p1[v]*en[u]+p1[v]*pn[u])/float64(deg-1)
      if ans > now-tmp { ans = now-tmp }
    }
  }
  fmt.Printf("%.12f",ans)
}

type IO struct {
  reader *bufio.Reader
  writer *bufio.Writer
}
func(io *IO) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := io.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(io *IO) Println(a ...interface{}) (int,error) {
  return fmt.Fprintln(io.writer,a...)
}
func(io *IO) Flush() error {
  return io.writer.Flush()
}
func(io *IO) NextInts() (int,int) {
  s := strings.Fields(io.NextLine())
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  return x,y
}

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

map<string,int> cache;

string int2string(int n) {
  return to_string(n).c_str();
}

int main() {
  //input
  int N;
  string S;
  cin >> N;
  cin >> S;
  //calc
  int answer = 0;
  
  string numbers = "0123456789";
  string n1, n2;
  int pos1, pos2;
  string s2;
  string rest;
  string head;
  int pos;
  string entry;
  
  rep(i,100) {    
    n1 = int2string(i / 10);
    pos1 = S.find_first_of(n1.at(0));
    if ( pos1 == string::npos ) {
      continue;
    }
    n2 = int2string(i % 10);
    s2 = S.substr(pos1+1);
    pos2 = s2.find_first_of(n2.at(0));
    if ( pos2 == string::npos ) {
      continue;
    }
    head = n1 + n2;
//    cout << head << endl;
    string rest = s2.substr(pos2+1);
    if ( rest.size() > 0 ) {
      rep(j,10) {
        pos = rest.find_first_of(numbers.at(j));
        if ( pos == string::npos ) {
          continue;
        }
        entry = head + numbers.at(j);
        if ( cache.count(entry) ) {
          continue;
        }
        cache[entry] = 1;
        answer++;
      }
    }
  }
  //output
  cout << answer << endl;
}

Measured memory_bytes: 512
from itertools import groupby

N=int(input())
H=list(map(int,input().split()))
New=[]
_max=0
for _ in range(N-1):
    if H[_]>=H[_+1]:
        New.append(1)
    else:
        New.append(0)
for k,h in groupby(New):
    _sum=sum(list(h))
    if k==1 and _sum>_max:
        _max=_sum
print(_max)


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

using namespace std;

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

	string n;
	int sum = 0;

	cin >> n;

	for(int i=0;i<n.length();i++)
	{
		sum += (n[i]-'0');
	}

	if(sum%9==0)
	{
		cout << "Yes" << '\n';
	}
	else
	{
		cout << "No" << '\n';
	}

	return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = (int)1e9 + 7;
int INF = (int)2e18;


signed main() {
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++) cin >> p[i];
    int ans = 0;
    for (int i = 0; i < N - 2; i++) {
        vector<int> temp;
        for (int j = 0; j <= 2; j++) temp.push_back(p[i + j]);
        sort(temp.begin(), temp.end());
        if (p[i + 1] == temp[1]) ++ans;
    }
    cout << ans << endl;
}


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

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

        int n = Integer.parseInt(br.readLine());
        int t = 0;
        int h = 0;

        for(int i = 0; i < n; i++){
            String[] input = br.readLine().split(" ");
            if(input[0].compareTo(input[1]) < 0)        h += 3;
            else if(input[0].compareTo(input[1]) > 0)   t += 3;
            else {
                h++;
                t++;
            }
        }

        System.out.println(t + " " + h);
    }
}

Measured memory_bytes: 25536
from collections import Counter

n = int(input())

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

num = []

for i in range(n):
    num.append((i+1)-a[i])

ct = Counter(num)

ans = 0
for i in range(n):
    scan = (i+1) + a[i]
    if(ct[scan] != 0):
        ans += ct[scan]

print(ans)

Measured memory_bytes: 42624
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> v(100005,vector<int>(3));
vector<vector<int>> dp(100005,vector<int>(4));
int solve(int i,int prev)
{
    if(i==n)
    return 0;
    if(dp[i][prev])
    return dp[i][prev];

    int ans = 0;
    for(int j=0;j<3;j++)
    {
        if(j!=prev)
        ans = max(ans,v[i][j]+solve(i+1,j));
    }
    return dp[i][prev] = ans;
}
int main() {
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        v[i][0]=a;
        v[i][1]=b;
        v[i][2]=c;
    }
    cout<<solve(0,3);
}


Measured memory_bytes: 21968
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}

int main(){
	ll n;
	cin>>n;
	vector<ll> a(n);
	vector<ll> b(n);
	
	rep(i,0,n) cin>>a[i];
	rep(i,0,n) cin>>b[i];
	ll idx = n-1;
	rep(i,0,n){
		
		
		if(a[i]==b[i]){
			if(a[i]==b[idx]) idx = n-1;
			swap(b[i],b[idx]);
			idx--;
			
		}

	}
	
	idx = 0;
	rep(i,0,n){
		
		
		if(a[i]==b[i]){
			if(a[i]==b[idx]) idx = 0;
			swap(b[i],b[idx]);
			idx++;
			
		}
	
	}
	
	
	ll f = 0;
	rep(i,0,n){
		if(a[i]==b[i]) f=1;
	}
	
	if(f) cout<<"No";
	else{
		cout<<"Yes"<<endl;
		rep(i,0,n) cout<<b[i]<<" ";
		
	}
	
	
}

Measured memory_bytes: 6416
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <set>
#include <vector>

using namespace std;

int H,W;

int check(string board[], int h, int w) {
    // 配列外参照ならなにもしない
    if (h < 0 || H-1 < h || w < 0 || W-1 < w) return 0;
    if(board[h][w] == '#') {
        return 1;
    } else {
        return 0;
    }
}

int main(){
    //scanf("%d", &N);
    cin >> H >> W;
    string board[H];
    for (int i = 0; i < H; i++){
        cin >> board[i];
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            // 調べるマスが # ならなにもしない
            if (board[i][j] == '#') continue;
            // それいがいなら 調べるマスの周りの # の数を数える
            int count = 0;
            count += check(board, i-1, j-1);
            count += check(board, i-1, j);
            count += check(board, i-1, j+1);
            count += check(board, i, j-1);
            count += check(board, i, j+1);
            count += check(board, i+1, j-1);
            count += check(board, i+1, j);
            count += check(board, i+1, j+1);
            board[i][j] = '0' + count;
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << board[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
a = input().strip()
b = input().strip()
c = input().strip()
kk = 2000
K = kk*2
na, nb, nc = len(a), len(b), len(c)
def ll(s, t):
    X = [0] * 100000
    ns, nt = len(s), len(t)
    for i in range(ns):
        for j in range(nt):
            if s[i] != t[j] and s[i] != "?" and t[j] != "?":
                X[i-j+2*K] = 1
    return X

ab = ll(a, b)
bc = ll(b, c)
ac = ll(a, c)
r = na+nb+nc
for i in range(-K, K+1):
    for j in range(-K, K+1):
        if (not ab[i+2*K]) and (not ac[j+2*K]) and (not bc[j-i+2*K]):
            st = min(i, j, 0)
            en = max(i+nb, j+nc, na)
            r = min(en-st, r)
print(r)


Measured memory_bytes: 54256
#include <stdio.h>
#define MAX 100

int main(){
  int n,i,j,u,k,v,Ad[MAX][MAX];
  
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++) Ad[i][j] = 0;
  }
  
  for(i = 0;i < n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0;j < k;j++){
      scanf("%d",&v);
      Ad[u][--v] = 1;
    }
  }

  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      if(j != 0) printf(" ");
      printf("%d",Ad[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool chmax(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF 1000000007 //4000000000000000037
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  string s;
  cin>>s;
  int ans=0;
  rep(i,3){
    ans+=s[i]=='1';
  }
  cout<< ans <<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

int main(void)
{
    char S[11];
    char T[11];
    char U[11];
    int A, B;
    int ret;

    scanf("%s %s", S, T);
    scanf("%d %d", &A, &B);
    scanf("%s", U);

    ret = strcmp(S, U);

    if (ret == 0) {
        A -= 1;
    } else {
        B -= 1;
    }

    printf("%d %d", A, B);

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int  pop();
void push(int);
int d[11],top,n,i;
int main(){
  while(scanf("%d",&n)!=EOF){
  
      if(n==0){
	pop();
        printf("%d\n",d[top+1]);
	}
      else{
        push(n);
      }
    
  }
  
  return 0;
}
void push(int x){
  top++;
  d[top]=x;
}
int pop(){
  top--;
  return d[top+1];
}

Measured memory_bytes: 1028
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=1e6+5;
const int mod=1e9+7;

int n,f[N],a[N];
signed main(){
    FastIO;
    cin>>n;
    rep(i,1,n){
        cin>>a[i];
        f[a[i]]++;
    }
    int ans=0;
    rep(i,1,n){
        bool ok=1;
        f[a[i]]--;
        rep(j,1,sqrt(a[i])) if(a[i]%j==0){
            if(f[j]>0 or f[a[i]/j]>0){
                ok=0;
                break;
            }
        }
        ans+=ok;
        f[a[i]]++;
    }
    cout<<ans;
    return 0;
}


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

using namespace std;

#define MAX_N 10
#define INF 1e9
typedef pair<int,int> pii;
typedef pair<string,int> psi;

struct Edge{
  int to,dist;
  Edge(int t,int d) : to(t),dist(d) {}
};

struct State{
  int cost,dist,v,S;
  State(int c,int d,int v,int S) 
    : cost(c),dist(d),v(v),S(S) {}
  bool operator < (const State &s)const{
    if(cost != s.cost){
      return cost > s.cost;
    }else{
      return dist > s.dist;
    }
  }
};

int V,E,K[MAX_N],q;
string shopping_list[15];
vector<psi> items[MAX_N];
vector<Edge> G[MAX_N+1];

void solve(){
  priority_queue<State> Q;
  Q.push(State(0,0,0,0));
  pii d[MAX_N+1][1<<15];
  for(int i = 0 ; i <= V ; i++){
    for(int j = 0 ; j < (1<<q) ; j++){
      d[i][j] = pii(INF,INF);
    }
  }
  d[0][0] = pii(0,0);
  
  while(!Q.empty()){
    State s = Q.top(); Q.pop();
    int v = s.v,S = s.S;
    if(d[v][S] < pii(s.cost,s.dist)) continue;
    if(v == 0 && S == (1<<q)-1){
      cout << s.cost << " " << s.dist << endl;
      return;
    }   
    for(int i = 0 ; i < (int)G[v].size() ; i++){
      Edge e = G[v][i];
      pii next = pii(d[v][S].first,d[v][S].second+e.dist);
      if(next < d[e.to][S]){
        d[e.to][S] = next;
        Q.push(State(d[e.to][S].first,d[e.to][S].second,e.to,S));
      }
      if(v == 0) continue;
      for(int j = 0 ; j < q ; j++){
        if((S >> j) & 1) continue;
        for(int k = 0 ; k < K[v-1] ; k++){
          if(shopping_list[j] == items[v-1][k].first){
            pii next = pii(s.cost + items[v-1][k].second,
                           s.dist + e.dist);
            int nS = S|(1<<j);
            if(next < d[e.to][nS]){
              d[e.to][nS] = next;
              Q.push(State(d[e.to][nS].first,d[e.to][nS].second,e.to,nS));
            }
            next.second -= e.dist;
            if(next < d[v][nS]){
              d[v][nS] = next;
              Q.push(State(d[v][nS].first,d[v][nS].second,v,nS));
            }
          }
        }
      }
    }
  }
  cout << "impossible" << endl;
}

int main(){
  while(cin >> V, V){
    string name;
    int value,a,b,d;
    for(int i = 0 ; i <= V ; i++){
      G[i].clear();
    }
    for(int i = 0 ; i < V ; i++){
      cin >> K[i];
      items[i].clear();
      for(int j = 0 ; j < K[i] ; j++){
        cin >> name >> value;
        items[i].push_back(psi(name,value));
      }
    }
    cin >> q;
    for(int i = 0 ; i < q ; i++){
      cin >> shopping_list[i];
    }
    cin >> E;
    for(int i = 0 ; i < E ; i++){
      cin >> a >> b >> d;
      G[a].push_back(Edge(b,d));
      G[b].push_back(Edge(a,d));
    }
    solve();
  }
  return 0;
}

Measured memory_bytes: 5988
n,k = gets.chomp.split(" ").map(&:to_i)

order = gets.chomp.split(" ").map(&:to_i)

pos = 0

for i in 0..order.length do
    if order[i] == 1 then
        pos = i
    end
end

k -= 1

down =  pos / k

up = ( n - pos - 1 )/ k 

tmp = (pos % k )+ (( n - pos - 1 ) % k )
tmp = tmp.to_f
tmp = (tmp / k ).ceil

total = down + up + tmp
puts "#{total}\n"

Measured memory_bytes: 8716
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    string S; cin >> S;
    vi A(N);
    F0R(i, N) {
        if (S[i] == 'R') {
            A[i] = 0;
        } else if (S[i] == 'G') {
            A[i] = 1;
        } else {
            A[i] = 2;
        }
    }
    int P[N+1][3];
    F0R(i, 3) P[0][i] = 0;
    F0R(i, N) {
        F0R(j, 3) {
            P[i+1][j] = P[i][j];
        }
        P[i+1][A[i]]++;
    }

    ll ans = 0;
    F0R(i, N) {
        FOR(j, i+2, N) {
            if (A[i] == A[j]) continue;
            int G = 0;
            if (A[i] == 0 || A[j] == 0) {
                G = 1;
                if (A[i] == 1 || A[j] == 1) {
                    G = 2;
                }
            }

            ans += P[j][G] - P[i+1][G];
            if (i % 2 == j % 2) {
                if (A[(i+j)/2] == G) {
                    ans--;
                }
            }
        }
    }
    cout << ans << nl;

	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



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

int main() {
    int n, v, j;
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++) {
        cin >> a[i];
        if (i==n-1) {
            cout << a[i] << endl;
        } else {
            cout << a[i] << " "; 
        }
    }
    for (int i=1; i<n; i++) {
        v = a[i];
        j = i-1;
        while (j>=0 && a[j]>v) {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        cout << a[0];
        for (int k=1; k<n; k++){
        cout << " " << a[k];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define str string
#define fori(i,N) for(long long i=1;i<=N;++i)
#define forj(j,m) for(long long j=1;j<=m;++j)
#define fork(k,n) for(long long k=1;k<=n;++k)
#define fors(i,ssz) for(long long i=0;i<s.size();++i)
#define Need_for_Speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    getline(cin,s);
    getline(cin,t);
    int m = s.length(),n = t.length() ;
    int dp[m+1][n+1],i,j;
    for(i=0;i<=m;i++) {
        for(j=0;j<=n;j++){
            if(i==0||j==0)
            dp[i][j]=0;
            else {
                if(s[i-1]==t[j-1])
                    dp[i][j] = dp[i-1][j-1]+1;
                else
                    dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    i=m;
    j=n;
    string st;
    while(i>0&&j>0){
            if(s[i-1]==t[j-1]){
                st=s[i-1]+st;
                i--;
                j--;
            }
            else if (dp[i-1][j] > dp[i][j-1]) 
                i--; 
            else
             j--; 
        }
        cout<<st;
}

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

int main(){
        long long sum;
        scanf("%lld", &sum);
        long long deposit = 100;
        int count = 0;
        while ((long long) deposit < sum){
				deposit += deposit/100;
				count ++;
			}
		printf("\n%d",count);
        return 0;
}


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

int main(){
	int N,V,P;
	long long M;
	cin >> N >> M >> V >> P;
	vector<long long> A(N);
	for(auto &i:A)cin >> i;
	
	sort(A.begin(),A.end(),greater<long long>());
	int ok=-1,ng=N;
	while(abs(ok-ng)>1){
		//printf("ok=%d,ng=%d\n",ok,ng);
		int mid=(ok+ng)/2;
		if(mid<P){
			ok=mid;
			continue;
		}
		if(A[mid]+M<A[P-1]){
			ng=mid;
			continue;
		}
		vector<long long> add(N,0);
		long long score=A[mid]+M;
		add[mid]=M;
		long long c=M*(V-1);
		for(int i=N-1;i>=0;i--){
			if(i==mid)continue;
			if(c<=0)break;
			if(A[i]<score){
				c-=min(score-A[i],M);
				add[i]=min(score-A[i],M);
			}
			else break;
		}
		for(int i=0;i<P;i++){
			if(c<=0)break;
			c-=M-add[i];
			add[i]=M;
		}
		
		if(A[P-1]+add[P-1]<=score)ok=mid;
		else ng=mid;
	}
	//printf("ok=%d,ng=%d\n",ok,ng);
	cout << ok+1 << endl;
	return 0;
}

Measured memory_bytes: 1792
using System;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string[] str = Console.ReadLine().Split(' ');
			double x1 = double.Parse(str[0]);
			double y1 = double.Parse(str[1]);
			double x2 = double.Parse(str[2]);
			double y2 = double.Parse(str[3]);
			Console.WriteLine(System.Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));

		}
	}
}

Measured memory_bytes: 9140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N; cin >> N;
  vector<int> A(N); rep(i,N) cin >> A[i];
  vector<int> mins(N+1, 1e9);
  rep(i,N){
    mins[i+1] = min(mins[i], A[i]);
  }
  //rep(i,N) cout << mins[i] << endl;
  int ans = 0;
  rep(i,N){
    if(A[i] < mins[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792