akhauriyash/Code-Regression huggingface dataset:
module ABC132

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public  :: task_A
  private :: judge_string

  ! constants for this <module>
  integer(INT32), parameter, private :: len_string = 4_INT32

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_A

    ! variables for this <subroutine>
    character(len=len_string, kind=1) :: given_string

    ! STEP.01
    ! read out the given string
    read(unit=INPUT_UNIT, fmt='(A)') given_string

    ! STEP.02
    ! output the answer of this task
    if ( judge_string(given_string) ) then
      write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'Yes'
    else
      write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'No'
    end if

    ! STEP.END
    return

  end subroutine task_A

  function judge_string (str) result(stat)

    ! arguments for this <function>
    character(len=len_string, kind=1) :: str

    ! return value of this <function>
    logical :: stat

    stat = .false.

    if (str(1:1) .eq. str(2:2) .and. str(3:3) .eq. str(4:4) .and. str(1:1) .ne. str(3:3) ) then
      stat = .true.
      return
    end if

    if (str(1:1) .eq. str(3:3) .and. str(2:2) .eq. str(4:4) .and. str(1:1) .ne. str(2:2) ) then
      stat = .true.
      return
    end if

    if (str(1:1) .eq. str(4:4) .and. str(2:2) .eq. str(3:3) .and. str(1:1) .ne. str(2:2) ) then
      stat = .true.
      return
    end if

    ! STEP.END
    return

  end function judge_string

end module ABC132


program main

  ! <module>s to import
  use, non_intrinsic :: ABC132

  ! require all variables to be explicitly declared
  implicit none

  call task_A

end program main

Measured memory_bytes: 768
def nibutanlt(n,list_a,start_index):
    if list_a[0] >= n:
        return(start_index - 1)
    elif list_a[-1] < n:
        return(len(list_a)+start_index - 1)
    temp = len(list_a)//2
    if list_a[temp] < n:
        return(nibutanlt(n,list_a[temp:],temp + start_index))
    else:
        return(nibutanlt(n,list_a[0:temp],start_index))


n,k = map(int,input().split())
h_list = list(map(int,input().split()))
ans = 0
h_list.sort()
ans = nibutanlt(k,h_list,0) + 1
print(n - ans)

Measured memory_bytes: 11916
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		Scanner scan = new Scanner(System.in);
		char[] str;
		char[] temp = new char[200];
		int m, len;
		int[] h = new int[200];
		
		while (true) {
			// 入力
			str = scan.next().toCharArray();
			len = str.length; if (len == 1 && str[0] == '-') break;
			m = scan.nextInt();
			for (int i = 0; i < m; i++) h[i] = scan.nextInt();

			
			// シャッフル
			for (int i = 0; i < m; i++) {
				for (int j = h[i], k = 0; j < len; j++, k++) temp[k] = str[j];
				for (int j = 0, k = len-h[i]; j < h[i]; j++, k++) temp[k] = str[j];
				for (int j = 0; j < len; j++) str[j] = temp[j];
			}
			
			// 出力
			for (int i = 0; i < len; i++) System.out.print(str[i]);
			System.out.println();
		}
	}
}



Measured memory_bytes: 26544
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
 
  cin >> n;
  
  if(n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9)
  	cout << "hon";
   else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8)
	cout << "pon";
   else
   cout << "bon";
 
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int a,b,x;
    cin >> a >> b >> x;
    if(a>x){
        cout << "NO" << endl;
    }else if(a+b >= x){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3628
/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define N 1000005
//Variables Start
ll inf=1e18,MOD= 998244353;
//Variables End

ll mul(ll a,ll b){return (a*b)%MOD;}
ll sub(ll a,ll b){return (a-b+MOD)%MOD;}

ll modexp(ll pow,ll num){
	ll ret=1;
	while(pow){
		if(pow&1) ret = mul(ret,num);
		num = mul(num,num);
		pow/=2;
	}
	return ret;
}
ll modinv(ll num){
	return modexp(MOD-2,num);
}

bool comp(pair<int,int> &a, pair<int,int> &b){
	if(a.S-a.F==b.S-b.F)return a.F < b.F;
	else return a.S+b.F > a.F+b.S;
}
void solve(){
	int n;cin>>n;
	vector<pair<int,int>> in;
	int last=0,cur=0;
	for(int i=0;i<n;i++){
		string s;cin>>s;
		stack<char> st;
		for(int j=0;j<s.length();j++){
			if(st.empty() || st.top()==')' || s[j]=='(') st.push(s[j]);
			else st.pop();
		}
		int a=0,b=0;
		while(!st.empty() && st.top()=='(')b++,st.pop();
		while(!st.empty() && st.top()==')')a++,st.pop();
		if(a!=0 && b!=0)
			in.pb({a,b});
		else last+=a,cur+=b;
	}
	
	sort(all(in),comp);
	for(int i=0;i<in.size();i++){
		if(in[i].F>cur){
			cout<<"No"<<endl;
			return;
		}
		cur = cur - in[i].F + in[i].S;
	}
	
	if(cur!=last)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	 
}
int main()
{
    ios
    int ti=1;
    //cin>>ti;
    for(int i=1;i<=ti;i++)
    {
		solve();        
    }
    return 0;
        
}


Measured memory_bytes: 5336
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
typedef vector<int> vi;
int main()
{
 int n;
 cin>>n;
int k;
vi v,a;
 for(int i=0;i<n;i++)
 {   cin>>k;
     v.pb(k);
     a.pb(k);
 }
 sort(v.begin(),v.end());
 int p=v[n-1],r=-2;
 if(v[n-2]!=v[n-1])
 {
     for(r=n-2;v[r]==v[r-1];r--);
     if(r<0)
        r=0;
 }
 for(int i=0;i<n;i++)
 {
     if(a[i]!=v[n-1])
        cout<<p<<"\n";
     else
     {
        if(r>=0)
        cout<<v[r]<<"\n";
        else
          cout<<p<<"\n";
     }
 }

 return 0;

}


Measured memory_bytes: 3436
import math
n,m = map(int, input().split())
if abs(n-m) > 1:
    ans = 0
else:
    if n == m:
        ans = 2*math.factorial(n) * math.factorial(m)
    else:
        ans = math.factorial(n) * math.factorial(m)
print(ans%(int(10**9 + 7)))


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

#define endl '\n'
#define ll long long
#define ull unsigned long long
#pragma GCC optimize("-O3")
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const int inf=0x3f3f3f3f;
const int MAXN=101010;
const ull mod=1e9+7;

int a[MAXN];

int main() {
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int ans=0;
    string a,b;
    cin>>a>>b;
    for(int i=0;i<3;i++) {
        if(a[i]==b[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#n = int(input())
x,y = map(int,input().split())
#a_L = list(map(int,input().split()))

for i in range(0,101):
    for j in range(0,101):
        if i*2 + j*4 == y:
            if i+j == x:
                print("Yes")
                exit()

print("No")

Measured memory_bytes: 9140
from operator import itemgetter
N = int(input())
S = []
for i in range(N):
  S.append(list(map(int,input().split())))

T = []
for i in range(N):
  T.append(list(map(int,input().split())))
S.sort(key=itemgetter(1), reverse=True)
S.sort(key=itemgetter(0))
T.sort(key=itemgetter(0))

cnt = 0
for i in range(len(T)):
  jmax = -1
  ymax = -1
  for j in range(len(S)):
    if S[j][0] < T[i][0]:
      if S[j][1] < T[i][1] and ymax < S[j][1]:
        ymax = S[j][1]
        jmax = j
    else:
      break
  if jmax >= 0:
    cnt += 1
    del S[jmax]

print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int ch[10000005][3],ed[10000005],cnt=1,ans[10000005];
bool rev[10000005];
char s[200005];
void pushr(int x){swap(ch[x][1],ch[x][2]);rev[x]^=1;}
void pushdown(int x)
{
    if(!rev[x])return;
    for(int i=0;i<=2;i++)if(ch[x][i])pushr(ch[x][i]);
    rev[x]=0;
}
void dfs(int x)
{
    pushdown(x);
    swap(ch[x][0],ch[x][2]),swap(ch[x][1],ch[x][2]);
    if(ch[x][0])dfs(ch[x][0]);
}
void get(int x,int now,int pw)
{
    pushdown(x);
    if(ed[x]!=0xffffffff)ans[ed[x]]=now;
    if(ch[x][0])get(ch[x][0],now,pw*3);
    if(ch[x][1])get(ch[x][1],now+pw,pw*3);
    if(ch[x][2])get(ch[x][2],now+2*pw,pw*3);
}
int main()
{
    int n,m=1;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)m*=3;
    memset(ed,0xff,sizeof(ed));
    for(int i=0;i<m;i++)
    {
        int now=1,tmp=i;
        for(int k=0;k<n;k++)
        {
            int t=tmp%3;
            tmp/=3;
            if(!ch[now][t])ch[now][t]=++cnt;
            now=ch[now][t];
        }
        ed[now]=i;
    }
    scanf("%s",s+1);
    int q=strlen(s+1);
    for(int i=1;i<=q;i++)
    {
        if(s[i]=='S')pushr(1);
        else dfs(1);
    }
    get(1,0,1);
    for(int i=0;i<m;i++)printf("%d ",ans[i]);
    return 0;
}

Measured memory_bytes: 55608
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
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;
}

/*

A=0 B=0
000
000
000

A=1 B=0 no
A=1 B=1
100
011
011

N=4 A=2 B=1
1100
0011
0011
0011

1 5 2 0
00111

*/

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    vector<string> v(H, string(W, '0'));
    rep(i, 0, B) rep(j, 0, A) { v[i][j] = '1'; }
    rep(i, B, H) rep(j, A, W) { v[i][j] = '1'; }
    rep(i, 0, H) cout << v[i] << endl;
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(j, m) for (int j = 0; j < (int)(m); j++)
#define rep2(i, l, n) for (int i = l; i < (int)(n); i++)


int main() {
    ll x,y,z;
    cin >> x >> y >> z;
    cout << (x - z)/(y + z) << endl;
}



Measured memory_bytes: 3540
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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; }

//dp[i][j][k] := 数字を先頭からi桁決めたときの、0以外の数字がちょうどk個出ている数字の個数（jは未満フラグ）
ll dp[101][2][4];

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

    string N;
    cin >> N;

    int K;
    cin >> K;

    dp[0][0][0] = 1;

    rep(i, N.size())
    {
        int d = N[i] - '0';

        reple(smaller, 0, 1)
        {
            reple(j, 0, K)
            {
                for (int x = 0; x <= (smaller ? 9 : d); x++)
                {
                    //0でない数字がK個以上出現した場合は数えない
                    if (j == K && x != 0) continue;
                    dp[i + 1][smaller || x < d][(x ? j + 1 : j)] += dp[i][smaller][j];
                }
            }
        }
    }

    cout << dp[N.size()][0][K] + dp[N.size()][1][K] << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int min = Integer.MAX_VALUE;
        int minIndex = 0;
        int max = Integer.MIN_VALUE;
        int maxIndex = 0;
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
            min = Math.min(min, a[i]);
            if (min == a[i]) {
                minIndex = i;
            }
            max = Math.max(max, a[i]);
            if (max == a[i]) {
                maxIndex = i;
            }
        }
        System.out.println(2 * n - 2);
        if (Math.abs(max) >= Math.abs(min) || min >= 0) {
            for (int i = 0; i < n; i++) {
                if (i != maxIndex) {
                    System.out.println((maxIndex + 1) + " " + (i + 1));
                }
            }
            for (int i = 0; i < n - 1; i++) {
                System.out.println((i + 1) + " " + (i + 2));
            }
        } else {
            for (int i = 0; i < n; i++) {
                if (i != minIndex) {
                    System.out.println((minIndex + 1) + " " + (i + 1));
                }
            }
            for (int i = 0; i < n - 1; i++) {
                System.out.println((n - i) + " " + (n - i - 1));
            }
        }
    }
}


Measured memory_bytes: 23124
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class B
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var G = new int[3][].Select(x => Scanner.ScanEnumerable<int>().ToArray()).ToArray();
            var N = Scanner.Scan<int>();
            var B = new bool[3][].Select(x => new bool[3]).ToArray();
            for (var k = 0; k < N; k++)
            {
                var b = Scanner.Scan<int>();
                for (var i = 0; i < 3; i++)
                {
                    for (var j = 0; j < 3; j++)
                    {
                        if (G[i][j] == b) B[i][j] = true;
                    }
                }
            }

            var answer = false;
            for (var i = 0; i < 3; i++)
            {
                if (B[i][0] && B[i][1] && B[i][2]) answer = true;
            }
            for (var i = 0; i < 3; i++)
            {
                if (B[0][i] && B[1][i] && B[2][i]) answer = true;
            }
            if (B[0][0] && B[1][1] && B[2][2]) answer = true;
            if (B[0][2] && B[1][1] && B[2][0]) answer = true;

            Console.WriteLine(answer ? "Yes" : "No");
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 28468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1e9;
const int MOD = 1e9 + 7;

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

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=1;i<=n;i++){
    scanf("%hd",&A[i]);
  }

  for(i=0;i<VMAX+1;i++){
    C[i]=0;
  }
  
  for(i=1;i<=n;i++)C[A[i]]++;


  //for(i=0;i<=n;i++)printf("%d\n",C[i]);
  j=A[1];
  for(i=1;i<=n;i++){
    if(A[i+1]>j)j=A[i+1];
  }
  // printf("%d\n",j);
  for(i=1;i<=j;i++)C[i]=C[i]+C[i-1];



  for(i=n;i>0;i--){
    B[C[A[i]]]=A[i];
    C[A[i]]--;
  }
  for(i=1;i<n;i++)printf("%d ",B[i]);
  printf("%d\n",B[n]);
  return 0;
}



Measured memory_bytes: 9548
#pragma GCC target("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>

#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<int>
#define int ll
using namespace std;
using ll  = long long;
using lld = long double;

const int oo = 0x3f3f3f3f;
const ll MOD = 998244353;
const int N = 2e5  + 10;
int lazy[N << 2];
int tree[N << 2];
int val[10][N];
int pw[N];

int n , q;
void push_down(int l, int r , int t){
    if(lazy[t] == 0)
        return;
    tree[t] = val[lazy[t]][r - l + 1];
    if(l != r){
        lazy[t << 1] = lazy[t];
        lazy[t << 1 | 1] = lazy[t];
    }
    lazy[t] = 0;
}

void build(int l , int r , int t){
    if(l == r){
        tree[t] = 1;
        return;
    }
    lazy[t] = 0;
    int mid = (l + r) >> 1;
    build(l , mid , t << 1);
    build(mid + 1 , r , t << 1 | 1);
    tree[t] = ((tree[t << 1] * pw[r - mid]) % MOD + tree[t << 1 | 1]) % MOD;
}

void upd(const int ql , const  int qr , const int val , int l = 0 , int r = n - 1 , int t = 1){
    push_down(l , r , t);
    if(l > qr || r < ql)
        return ;

    if(l >= ql && r <= qr){
        lazy[t] = val;
        push_down(l , r , t);
        return;
    }

    int mid = (l + r) >> 1;

    upd(ql , qr , val , l , mid , t << 1);
    upd(ql , qr , val , mid + 1 , r , t << 1 | 1);

    tree[t] = ((tree[t << 1] * pw[r - mid]) % MOD + tree[t << 1 | 1]) % MOD;
    return;
}

signed main(){

#ifndef ONLINE_JUDGE
//	freopen("in.txt" , "r" , stdin);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);

    cin >> n >> q;
    pw[0] = 1;

    for(int i = 1 ; i < N ; i++)
        pw[i] = (pw[i - 1] * 10) % MOD;

    build(0 , n - 1 , 1);

    for(int i = 1 ; i <= 9 ; i++){
        val[i][0] = 0;
        for(int j = 1 ; j < N ; j++)
            val[i][j] = (val[i][j - 1] * 10 + i) % MOD;
    }

    while(q--){
        int l , r , t;
        cin >> l >> r >> t;
        l-- , r--;
        upd(l , r , t);
        cout << tree[1] << '\n';
    }



    return 0;

}



Measured memory_bytes: 27512
#include <iostream>
#include <algorithm>
using namespace std;
int d,s=0,m = -1;  
char c[110];        
int main() {
    cin>>d>>c;
    for(int i = 0 ; i < d ; ++ i)
	{
        if(c[i] == 'I')       
        s ++;
        else s --;              
        m = max(m,s);       
    }
    if(m == -1) 
	m = 0;     
    cout<<m;         
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
s = 0
ol = 0
for i in a:
	s += abs(i-ol)
	ol = i
s += abs(ol)
a.insert(0,0)
a.append(0)
for i in range(1,n+1):
	if (a[i-1] < a[i] < a[i+1]) or (a[i-1] > a[i] > a[i+1]):
		print (s)
	else:
		print (s-min(abs(a[i-1]-a[i]),abs(a[i]-a[i+1]))*2)


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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    int A[N];
    REP(i, N) {
        cin >> A[i];
    }

    int fm = -1;
    int fmi = -1;
    int sm = -1;

    REP(i, N) {
        if(fm < A[i]) {
            fm = A[i];
            fmi = i;
        }
    }
    REP(i, N) {
        if(i == fmi)continue;
        if(sm < A[i]) {
            sm = A[i];
        }
    }
    REP(i, N) {
        if(i == fmi) {
            cout << sm << endl;
        }else{
            cout << fm << endl;
        }
    }
    return 0;
}



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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::set<P> s;

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

  int N;
  std::cin >> N;

  for(int i=1;i<=N;++i){
      int A;
      std::cin >> A;

      s.emplace(A, i);
  }

  for(int i=1;i<=N;++i){
      int id;
      std::tie(std::ignore, id) = *s.begin();

      std::cout << id << " \n"[i == N];

      s.erase(s.begin());
  }
}


Measured memory_bytes: 5504
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

string s;

int main(){
	cin>>s;
	int l=s.sz,a=0;
	rep(i,l/2)if(!(s[i]=='i'&&s[l-1-i]=='i'||s[i]=='w'&&s[l-1-i]=='w'||s[i]=='('&&s[l-1-i]==')'||s[i]==')'&&s[l-1-i]=='('))a++;
	if(l%2&&s[l/2]!='i'&&s[l/2]!='w')a++;
	cout<<a<<endl;
}

Measured memory_bytes: 0
n, m = gets.split.map(&:to_i)
mat = []
vec = []
n.times do
  mat << gets.split.map(&:to_i)
end
m.times do
  vec << gets.to_i
end
mat.each do | line |
  puts line.zip( vec ).map{ | i, j | i * j }.inject(:+)
end

Measured memory_bytes: 9016
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

struct edge {
    int from;
    int to;
    int cost;
};

int n;
vector<edge> graph[100010];
int indeg[100010];
int color[100010];

void rec(int from, int s, bool c) {
    color[s] = c;
    for (auto ch: graph[s]) {
        if (ch.to == from) continue;
        if (ch.cost % 2 == 0) {
            rec(s, ch.to, c);
        } else {
            rec(s, ch.to, !c);
        }
    }
}

int main() {
    memset(color, -1, sizeof(color));
    scanf("%d", &n);
    edge e;
    rep(i, n-1) {
        scanf("%d %d %d", &e.from, &e.to, &e.cost);
        e.from--; e.to--;
        graph[e.from].push_back(e);
        swap(e.to, e.from);
        graph[e.from].push_back(e);
    }
    rec(0, 0, true);
    rep(i, n)
        printf("%d\n", color[i]);
    return 0;
}


Measured memory_bytes: 9216
#include<iostream>
#include<map>
#include<utility>
#include<string>
#include<vector>
#include<cstdio>
using namespace std;

int main(){
    int n,k;cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++) cin>>h[i];
    sort(h.begin(),h.end());

    int hm=1000000000;
    for(int i=0;i<=n-k;i++){
        hm=min(hm,h[i+k-1]-h[i]);
    }

    cout<<hm<<endl;
}



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

using namespace std;

int X, Y, Z;
int V[4],EventInfo[51][2];
double DpMoney[4901][51];


void solve() {
	int currentNode, currentMoney;

	DpMoney[0][0] = 1.0;
	for (int i = 0; i < Y; ++i) {
		for (int j = 0; j < 4901; ++j) {
			if (DpMoney[j][i] == 0) {
				continue;
			}
			for (int k = 0; k < X; ++k) {	
				currentNode = min(Y, i + V[k]);
				currentMoney = j;
				switch (EventInfo[currentNode][0]) {
					case 1:currentNode = min(Y, currentNode + EventInfo[currentNode][1]); break;
					case 2:currentMoney += EventInfo[currentNode][1]; break;
					case 3:currentMoney = max(0, currentMoney - EventInfo[currentNode][1]); break;
					default:break;
				}
				DpMoney[currentMoney][currentNode] += DpMoney[j][i] / X;
			}
		}
	}

}

int main() {
	int n, e, a;
	double total;

	while (cin >> X >> Y >> Z, X) {
		for (int i = 0; i < X; ++i) {
			cin >> V[i];
		}
		memset(EventInfo, 0, sizeof(EventInfo));
		for (int i = 0; i < Z; ++i) {
			cin >> n >> e >> a;
			EventInfo[n][0] = e;
			EventInfo[n][1] = a;
		}
		memset(DpMoney, 0, sizeof(DpMoney));
		solve();
		total = 0;
		for (int i = 0; i < 4901; ++i) {
			total += i*DpMoney[i][Y];
		}
		cout << (int)total << endl;
	}

	return 0;
}



Measured memory_bytes: 4936
import collections

class common_function():
    """
        1. よく使いそうで予め用意してあるものをまとめた
        2. よく使いそうな関数群をまとめた
    """
    def nCk(self, n:int, k:int):
        """
            mod を使用しない combination nCk を求めるメソッド
            1回 の nCk を求めるのに O(k) かかる.
        """
        k = min(k, n-k)
        numer = 1
        for i in range(n, n-k, -1):
            numer *= i
        denom = 1
        for i in range(k, 1, -1):
            denom *= i
        return numer // denom

def main():
    common = common_function()
    N = int(input())
    A = list(map(int, input().split()))
    cum = [0]
    for a in A:
        tmp = cum[-1] + a
        cum.append(tmp)
    cumcount = list(collections.Counter(cum).items())
    cumcount.sort(key=lambda x: x[1], reverse=True)
    ans = 0
    for number, count in cumcount:
        if count <= 1:
            break
        ans += common.nCk(count, 2)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 52276
W,H,N=map(int,input().split())
canvas=[[0 for j in range(W)] for i in range(H)]
for n in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        for i in range(x):
            for j in range(H):
                canvas[j][i]=1
    if a==2:
        for i in range(x,W):
            for j in range(H):
                canvas[j][i]=1
    if a==3:
        for i in range(W):
            for j in range(y):
                canvas[j][i]=1
    if a==4:
        for i in range(W):
            for j in range(y,H):
                canvas[j][i]=1
                
count=0
for i in range(H):
    count+=canvas[i].count(0)
    
print(count)

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

int Dice[6];

void North() {
	int p = Dice[0];
	Dice[0] = Dice[1];
	Dice[1] = Dice[5];
	Dice[5] = Dice[4];
	Dice[4] = p;
}

void South() {
	int p = Dice[0];
	Dice[0] = Dice[4];
	Dice[4] = Dice[5];
	Dice[5] = Dice[1];
	Dice[1] = p;
}

void East() {
	int p = Dice[0];
	Dice[0] = Dice[3];
	Dice[3] = Dice[5];
	Dice[5] = Dice[2];
	Dice[2] = p;
}

void West() {
	int p = Dice[0];
	Dice[0] = Dice[2];
	Dice[2] = Dice[5];
	Dice[5] = Dice[3];
	Dice[3] = p;
}

void Left() {
	int p = Dice[1];
	Dice[1] = Dice[2];
	Dice[2] = Dice[4];
	Dice[4] = Dice[3];
	Dice[3] = p;
}

void Right() {
	int p = Dice[1];
	Dice[1] = Dice[3];
	Dice[3] = Dice[4];
	Dice[4] = Dice[2];
	Dice[2] = p;
}

int main() {
	for (int i = 0; i < 6; i++) {
		cin >> Dice[i];
	}
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int A, B;
		cin >> A >> B;
		if (A == Dice[1]) North();
		else if (A == Dice[2]) West();
		else if (A == Dice[3]) East();
		else if (A == Dice[4]) South();
		else if (A == Dice[5]) North(), North();
		for (int i = 0; i < 4; i++) {
			if (Dice[1] == B) break;
			Left();
		}
		cout << Dice[2] << endl;
	}
}


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

int main() {
  long long n,m,scc;
  cin >> n >> m;
  
  if(m>2*n){
    scc = n+(m-2*n)/4;
  }
  else{
    scc = m/2;
  }

  cout << scc << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 2000
#define mod 924844033
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int n,K,f[MN+5][MN+5][8],g[MN+5],p[MN+5],h[MN+5][MN+5],r[MN+5],inv[MN+5];
inline void R(int&x,int y){x+=y;x>=mod?x-=mod:0;}
inline int C(int n,int m){return 1LL*p[n]*inv[m]%mod*inv[n-m]%mod;}
inline void Calc(int x){for(int i=0;i<=x;++i) for(int j=0;j<4;++j) R(h[x][i],f[x][i][j]);}
inline void Update(int x)
{
    for(int i=n;~i;--i) if(g[i])
    {
        for(int j=1;i+j<=n&&j<=x;++j) R(g[i+j],1LL*g[i]*h[x][j]%mod);
        g[i]=1LL*g[i]*h[x][0]%mod;
    }
}
int main()
{
    n=read();K=read();p[0]=p[1]=inv[0]=inv[1]=f[0][0][3]=g[0]=1;
    for(int i=2;i<=n;++i) p[i]=1LL*p[i-1]*i%mod,inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
    for(int i=2;i<=n;++i) inv[i]=1LL*inv[i-1]*inv[i]%mod;
    for(int i=1;i<=n;++i)
        for(int j=0;j<i;++j)
            for(int k=0;k<8;++k) if(f[i-1][j][k])
            {
                int th=k>>1;
                R(f[i][j][th],f[i-1][j][k]);
                R(f[i][j+1][th|4],f[i-1][j][k]);
                if(~th&1) R(f[i][j+1][th|1],f[i-1][j][k]);
            }
    Calc(n/K);if(n%K) Calc(n/K+1);
    for(int i=1;i<=K;++i) Update(n/K+(n%K>=i));
    for(int j=n;~j;--j)
    {
        r[j]=1LL*p[n-j]*g[j]%mod;
        for(int k=j+1;k<=n;++k) r[j]=(r[j]-1LL*r[k]*C(k,j)%mod+mod)%mod;
    }
    printf("%d\n",r[0]);
    return 0;
}


Measured memory_bytes: 127232
#include<stdio.h>
int main(){
  int dice[6];
  int temp1,temp2;
  char move;
  char kg;
  scanf("%d %d %d %d %d %d",&dice[0],&dice[1],&dice[2],&dice[3],&dice[4],&dice[5]);
  scanf("%c",&kg);
  while(1){
    scanf("%c",&move);
    if(move == '\n')break;
    if(move == 'N'){
      temp1 = dice[0];
      dice[0] = dice[1];
      temp2 = dice[4];
      dice[4] = temp1;
      temp1 = dice[5];
      dice[5] = temp2;
      dice[1] = temp1;
    }
    if(move == 'S'){
      temp1 = dice[0];
      dice[0] = dice[4];
      temp2 = dice[1];
      dice[1] = temp1;
      temp1 = dice[5];
      dice[5] = temp2;
      dice[4] = temp1;
    }
    if(move == 'W'){
      temp1 = dice[0];
      dice[0] = dice[2];
      temp2 = dice[3];
      dice[3] = temp1;
      temp1 = dice[5];
      dice[5] = temp2;
      dice[2] = temp1;
    }
    if(move == 'E'){
      temp1 = dice[0];
      dice[0] = dice[3];
      temp2 = dice[2];
      dice[2] = temp1;
      temp1 = dice[5];
      dice[5] = temp2;
      dice[3] = temp1;
    }
  }
  printf("%d\n",dice[0]);
  return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
   int W,H;
   int w,h;
   cin >> W >> H;
   cin >> w >> h;


   cout << (W-w) * (H-h) << endl;






   return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d;
	
	scanf("%d %d %d",&a,&b,&c);

	if(b < a){
		d=a;
		a=b;
		b=d;
	}
	else{
	}
	if(c < b){
		d=c;
		c=b;
		b=d;
	}
	else{
	}
	if(b < a){
		d=a;
		a=b;
		b=d;
	}

	printf("%d %d %d\n",a,b,c);

	return 0;
}



Measured memory_bytes: 2140
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vl Prime(MAX_N, 1);  // Prime[i] : iが素数のとき1、iが素数でないとき0

void Eratosthenes(ll n) {  // n未満の素数を求める    
    Prime[0] = Prime[1] = 0;
    for(ll i = 2; i*i < n; i++) {
        if(Prime[i]) {
            for(ll j = 2; i*j < n; j++) {
                Prime[i*j] = 0;
            }
        }
    }
}

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

    Eratosthenes(MAX_N);

    ll cnt = 0;
    exrep(x, 11, MAX_N) {
        if(Prime[x] && x%5 == 1) {
            cout << x << " ";
            cnt++;
        }
        if(cnt == n) {
            re0;
        }
    }

    re0;
}

Measured memory_bytes: 1024
N, X = map(int, input().split())
L = list(map(int, input().split()))
L.insert(0,0)
for i in range(1, len(L)):
    L[i] = L[i] + L[i-1] 
count = 0
for l in L:
    if l > X:
        break
    else:
        count += 1
print(count)


    



Measured memory_bytes: 3060
fun main(args:Array<String>){
    val a=readLine()!!.split( " ")
    val b=readLine()!!.split( " ").map{it.toInt()}
    val c=readLine()!!
   if (a[0]==c){
        when {
            b[0]-1>=1 ->{ println("${b[0]-1} ${b[1]}")}
            b[0]-1==0 ->{ println("0 ${b[1]}")}
        }
    }else if (a[1]==c){
        when {
            b[1] - 1 >= 1 -> { println("${b[0]} ${b[1]-1}") }
            b[1] - 1 == 0 -> { println("0 ${b[0]}") }
        }
   }
}




Measured memory_bytes: 35956
<?php
    fscanf(STDIN, "%d %d %d", $a, $b, $c);
    $min_array = [$a, $b, $c];
    sort($min_array);
    echo $min_array[0] . " " .$min_array[1] .  " " .$min_array[2] . "\n";
?>


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

int main()
{
    int N;
    cin >> N;
    vector<double> x(N);
    vector<string> u(N);
    double sum = 0;
    for(int i = 0; i < N; i++)
    {
        cin >> x[i] >> u[i];
    }
    for(int i = 0; i < N; i++)
    {
        if(u[i] == "BTC")
        {
            x[i] *= 380000;
        }
        sum += x[i];
    }
    cout << sum;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    
    int N;
    cin >> N;
    vl L(N);
    in(N,L);
    
    
    
    int ans = 0;
    rep(i,N) reps(j,i,N) reps(k,j,N){
        vl aa;
        if(L[i] == L[j] || L[i] == L[k] || L[j] == L[k]) continue;
        aa.push_back(L[i]);
        aa.push_back(L[j]);
        aa.push_back(L[k]);
        sort(all(aa));
        if(aa[0]+aa[1] > aa[2]) ans++;
    }
    
    cout << ans << endl;
    
    
    

    return 0;
}


Measured memory_bytes: 3608
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int m, n;
	@SuppressWarnings("unchecked")
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			n = sc.nextInt();
			m = sc.nextInt();
			if( (n|m) == 0 ) break;
			LinkedList<Integer>[] cups = new LinkedList[3+2];
			cups[0] = new LinkedList<Integer>();
			cups[4] = new LinkedList<Integer>();
			cups[0].add(30);
			cups[4].add(30);
			
			for(int i=1;i<=3;i++) {
				cups[i] = new LinkedList<Integer>();
				cups[i].add(0);
				int k = sc.nextInt();
				for(int j=0;j<k;j++) cups[i].add(sc.nextInt());
			}
			if( cups[1].size() == n+1 || cups[3].size() == n+1 ) System.out.println(0);
			int c = cups[2].getLast();
			int left = cups[1].getLast();
			int right = cups[3].getLast();
			int cnt = 0;
			if( c > max(left, right) ) {
				LinkedList<Integer>[] tmp = new LinkedList[5];
				for(int i=0;i<5;i++) tmp[i] = new LinkedList<Integer>(cups[i]);
				tmp[1].add(tmp[2].removeLast());
				cnt = solve(tmp, c, 2, 1);
				cups[3].add(cups[2].removeLast());
				cnt = min(cnt, solve(cups, c, 2, 1));
			}
			else {
				cnt = solve(cups, -1, -1, 0);
			}
			if( cnt <= m ) System.out.println(cnt);
			else System.out.println(-1);
		}
	}
	
	int solve(LinkedList<Integer>[] cups, int pastp, int pasti, int cp) {
		int cnt;
		int p, i;
		
		for(cnt=cp;cnt<=m;cnt++) {
			i = 0;
			p = 20;
			if( cups[1].size() == n+1 || cups[3].size() == n+1 ) {
				break;
			}
			int from = 0;
			
			for(int j=1;j<=3;j++) {
				int left = cups[j-1].getLast();
				int right = cups[j+1].getLast();
				int c = cups[j].getLast();
//				debug(left, right, c);
				if( p < c || c == 0 || ( c == 1 && ( j == 1 || j == 3 ) ) ) continue;
				if( c != pastp && c > left ) {
					p = c;
					i = j-1;
					from = j;
				}
				else if( c != pastp && c > right ) {
					p = c;
					i = j+1;
					from = j;
				}
				else if( c == pastp && c > left && pasti != j-1 ) {
					p = c;
					i = j-1;
					from = j;
				}
				else if( c == pastp && c > right && pasti != j+1 ) {
					p = c;
					i = j+1;
					from = j;
				}
				else continue;
//				debug("    ", p, i, from);
//				debug("    ", pasti, from);
			}
			cups[i].addLast( cups[from].removeLast() );
			pastp = p;
			pasti = from;
//			for(LinkedList<Integer> a: cups) debug(a);
		}
		return cnt;
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll h,a; cin >> h >> a;
    cout << (h + a - 1) / a << endl;
}

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

signed main(){
  int n;
  cin>>n;
  long long A[100];
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  int cnt=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        if(A[i]==A[j]||A[j]==A[k]||A[i]==A[k])continue;
        if(A[i]+A[j]<=A[k]||A[i]+A[k]<=A[j]||A[j]+A[k]<=A[i])continue;
        //cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;
        cnt++;
      }
    }
  }
  cout<<cnt<<endl;
  return 0;
}




Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  if(n>=m) {
    cout << 0 << endl;
    return 0;
  }

  vector<int> p(m);
  rep(i,m){
    cin>>p[i];
  }

  sort(all(p));

  vector<int> q(m-1);
  rep(i,m-1){
    q[i]=p[i+1]-p[i];
  }

  sort(all(q));
  reverse(all(q));

  ll sum=0;
  rep(i,n-1){
    sum+=q[i];
  }

  cout << p[m-1]-p[0]-sum << endl;

}

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

typedef pair<int, int> C;

int m, g;
vector<C> cs;

int solve(int n, int index) {
    //cout << n << endl;
    if (n < 0) return 0;
    if (index == cs.size()) {
        if (n == 0) return 1;
        return 0;
    }
    int ans = 0;
    for (int i = 0; i <= cs[index].second; i++) {
        cs[index].second -= i;
        ans += solve(n - cs[index].first * i, index+1);
        cs[index].second += i;
    }
    return ans;
}

int main() {
    while (cin >> m, m) {
        cs.clear(); cs.resize(m);
        for (int i = 0; i < m; i++) cin >> cs[i].first >> cs[i].second;
        //for (int i = 0; i < m; i++) cout << cs[i].first << ' ' << cs[i].second << endl;
        cin >> g;
        for (int i = 0; i < g; i++) {
            int n; cin >> n;
            cout << solve(n, 0) << endl;
        }
        //cout << endl;
    }
    return 0;
}

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

using namespace std;

const int N = int(1e6);
int pref[N];
int suf[N];
int a[N];

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

	int n;

	cin >> n;

	for(int i = 1 ; i <= n ; i++){
		cin >> a[i];
	}

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

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

	int best = 0;

	for(int i = 1 ; i <= n ; i++){
		best = max(best, __gcd(pref[i - 1], suf[i + 1]));
	}

	cout << best << endl;

	return 0;
}


Measured memory_bytes: 8832
#include <iostream>
#include <vector>

using namespace std;

typedef pair<int, int> P;

struct edge{
    int to;
    int cost;
};

vector<edge> G[100000];
vector<int> center;
bool used[100000];
int sz[100000];
int N;

P p[100000];

void dfs(int v){
    used[v] = true;
    bool isCenter = true;
    sz[v] = 1;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i].to]){
            dfs(G[v][i].to);
            sz[v] += sz[G[v][i].to];
            if(sz[G[v][i].to] > (N+1)/2) isCenter = false;
        }
    }
    if(sz[v] < (N+1)/2) isCenter = false;
    if(isCenter) center.push_back(v);
}

int main(){
    cin >> N;
    for(int i = 0; i < N-1; i++){
        int A, B, C;
        cin >> A >> B >> C;
        A--;
        B--;
        G[A].push_back((edge){B, C});
        G[B].push_back((edge){A, C});
        p[i] = P(A, B);
    }
    dfs(0);
    
    long ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < G[i].size(); j++){
            if(sz[i] < sz[G[i][j].to]){
                ans += ((long)G[i][j].cost)*min(sz[i], N-sz[i])*2;
                //cout << i << ' ' << G[i][j].to << ' ' << min(sz[i]*2, N-sz[i]) << ' ' << sz[G[i][j].to] << endl;
            }
        }
    }
    //cout << ans << endl;
    if(center.size() == 1){
        int c = center[0];
        int min_cost = 1e+9;
        for(int i = 0; i < G[c].size(); i++){
            if(min_cost > G[c][i].cost){
                min_cost = G[c][i].cost;
            }
        }
        ans -= min_cost;
    }
    if(center.size() == 2){
        for(int i = 0; i < N; i++){
            for(int j = 0; j < G[i].size(); j++){
                if(i == center[0] && G[i][j].to == center[1]){
                    ans -= G[i][j].cost;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

    int aIdx=0,zIdx=0;
    rep(s,0,S.size()){
        if(S.at(s)=='A'){aIdx=s; break;}
    }
    _rep(s,S.size()-1,aIdx+1){
        if(S.at(s)=='Z'){zIdx=s; break;}
    }

    cout<<zIdx-aIdx+1<<endl;
}

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

int main(){
  string a, b;
  cin >> a >> b;
  a=a+b;
  int num = stoi(a);
  int flag=0;
  for(int i=0; i<=317; i++){
    if(num==i*i) flag++;
  }
  if(flag>0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256