akhauriyash/Code-Regression huggingface dataset:
//         Jai Saraswati Maa       Om Namah Shivaay        Jai Bhawani
// You have to work hard and keep coding till you get correct output never quit! :-)
// May the force be with you
// Ganpatai Bappa Morya! Mangal Murti Morya!
#include<bits/stdc++.h>
#define sc(x) scanf("%d",&x);
#define scc(x,y) scanf(" %d %d",&x,&y);
#define sccc(x,y,z) scanf("%d %d %d",&x,&y,&z);
#define sl(x) scanf("%lld",&x);
#define sll(x,y) scanf("%lld %lld",&x,&y);
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z);
#define pf(x) printf("%d",x);
#define pfn(x) printf("%d\n",x);
#define pl(x) printf("%lld",x);
#define pln(x) printf("%lld\n",x);
#define st(s) scanf("%s",s);
using namespace std;
/*struct Node{
      int data;
      Node* next;
};*/
 // Node* head;
/*void Insert(int data,int n)
{
    Node* temp1 = (Node*)(malloc(sizeof(Node*)));
    temp1->data = data;
    temp1->next = NULL;
    if(n==1){
        temp1->next = head;
        head = temp1;
        return;
    }
    Node* temp2 = head;
    for(int i=0;i<n-2;i++)
    {
       temp2 = temp2->next;
    }
    temp1->next = temp2->next;
    temp2->next = temp1;
}
void Print()
{
    Node* temp = head;
    printf("The List is : ");
    while(temp!=NULL)
    {
        printf("%d ",temp->data);
        temp = temp->next;
    }
   printf("\n");
}
void Delete(int n)
{
    Node* temp1 = head;
    if(n==1)
    {
        head = temp1->next;
        free(temp1);
    }
       for(int i=0;i<n-2;i++)
           temp1 = temp1->next;
      Node* temp2 = temp1->next;
      temp1->next = temp2->next;
      free(temp2);
}*/
int main()
{
   /* head = NULL;
    printf("How many Numbers?\n");
    int n,i,x,j;
    sc(n)
     for(i=0;i<n;i++)
     {
         printf("Enter the number and its position to be inserted\n");
         scc(x,j)
         Insert(x,j);
         Print();
     }
     printf("Which position is to be deleted\n");
     sc(x)
     Delete(x);
     Print();*/
     int x,a,b;
     sccc(x,a,b)
     x=x-a;
     printf("%d",x%b);
 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 a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		System.out.println(Math.min(a , b) + Math.min(c, d));
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define PI  3.14159265358979323846
#define M 1000000007
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll res=fast(n/2,a,m)%m;
        if(n%2==0)
            return (((res%m)*(res%m))%m);
        else
            return (((((res%m)*a)%m)*res)%m);
    }
}
ll lcm(ll x,ll y)
{
    ll P=x*y;
    P/=gcd(x,y);
    return P;
}
int main()
{
   char p;
   cin>>p;
   p++;
   cout<<p;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
  char A[4];
  char B;
  int i;
  B=0;
  
  for(i=0;i<4;i++){
   cin >> A[i];
  }
  for(i=0;i<3;i++){
   if(A[i]==A[i+1])
     B=1;
  }
  if(B==1)
    cout<<"Bad";
  if(B==0)
    cout<<"Good";
}


Measured memory_bytes: 256
'use strict';

const input = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");
const count = parseInt(input[0]);
const inputList = input[1].split(" ");

const process = (input, count) => {
    for (let i=0; i<count; i++) {
        input[i] = parseInt(input[i]) - (i + 1);
    }
    input.sort((a,b) => a-b);
    const median = parseInt(input[Math.floor(count/2)]);

    return input.reduce((acc, curr) => acc + Math.abs(curr - median), 0);
}

console.log(process(inputList,  count));

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

int main(){
  char s[1000];
 
  scanf("%s",s);
   int n;
  n=strlen(s);
  int count=0;
  for(int i=0;i<n/2;i++){
    if(s[i]!=s[n-1-i]) count++;
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[105],b[105];
int main(){
    int n,k,num=0;
    cin>>n>>k;
    string s;
    cin>>s;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]=='R'&&s[i+1]=='R') num++;
    }
    for(int i=s.length()-1;i>=1;i--){
        if(s[i]=='L'&&s[i-1]=='L') num++;
    }
    cout<<min(n-1,num+k*2)<<endl;
}

Measured memory_bytes: 512
N = int(input())
s = ''

if N != 0:
    while N != 0:
        if N % 2 == 1:
            s += '1'
            N = (N - 1) / (-2) 
        else:
            s += '0'
            N = N / ( -2 )
else :
    s = '0'
print(s[::-1])

Measured memory_bytes: 38768
import java.util.Scanner;
public class Main{
	int x;
	
	public void solve(){
		Scanner sc = new Scanner(System.in);
		x=sc.nextInt();
		System.out.println(x*x*x);
	}
		
	public static void main(String[] args){
		Main obj = new Main();
		obj.solve();
	}
}	

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	string s;
	cin >> s;
	int n=s.length();
	bool bl=(s[0]==s[n-1]);

	if((n%2)^bl) cout << "First" << endl;
	else cout << "Second" << endl;
	return 0;
}

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

int main() {
    int n, q, c;
    int a[100010] = {0};
    ll k;
    cin >> n >> k >> q;
    for (int i = 0; i < q; i++) {
        cin >> c;
        a[c-1]++;
    }
    for (int j=0; j<n;j++) {
        if (k-(q-a[j])>0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>



int main()
{
	int N;
	scanf("%d", &N);
	double x;
	int a = N / 2 + 1;
	x = (double)a / N;
	if (N % 2 == 0) {
		double y = 0.5;
		printf("%f", y);
	}
	else printf("%f", x);
}






Measured memory_bytes: 128
#include <iostream>
 using namespace std;
 long long N, A[87], CurrentMoney = 1000;
 int main() {
 cin >> N;
 for (int i = 1; i <= N; i++) cin >> A[i];
 for (int i = 1; i <= N - 1; i++) {
 long long Stocks = 0;
 if (A[i] < A[i + 1]) Stocks = CurrentMoney / A[i];
 CurrentMoney += (A[i + 1] - A[i]) * Stocks;
 }
 cout << CurrentMoney << endl;
 }


Measured memory_bytes: 3532
import java.util.Scanner;

public class Main {
	public static void PrintChess(int H,int W){
		for(int i=1;i<H+1;i++){
			PrintLine(i, W);
		}
	}
	//一行出力メソッド
	public static void PrintLine(int lineCounter,int W){
		//引数はラインカウンタと高さ
		if(lineCounter%2==0){
			for(int i=1;i<W+1;i++){
				if(i%2==0){
					System.out.print("#");
				}else{
					System.out.print(".");
				}
			}
		}else{
			for(int i=1;i<W+1;i++){
				if(i%2==0){
					System.out.print(".");
				}else{
					System.out.print("#");
				}
			}
			
		}
		System.out.println("");
	}

	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int H;
		int W;
		//最初の値を格納
		H=scanner.nextInt();
		W=scanner.nextInt();
		while(H!=0&&W!=0){
			PrintChess(H, W);
			
			System.out.println("");
			H=scanner.nextInt();
			W=scanner.nextInt();
		}
		scanner.close();
		//System.out.println("exit");
	}

}

Measured memory_bytes: 25728
#include <iostream>

using namespace std;

typedef long long ll;

int main () {
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;

  if (a > b) {
    a = -a;
    b = -b;
  }

  a += t * v;
  b += t * w;

  if (a >= b) {
    cout << "YES" << '\n';
  } else {
    cout << "NO" << '\n';
  }
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        char c = s.next().charAt(0);
        System.out.println((char)(c+1));
    }
}



class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25432
def dfs(seq):
    # 返り値は、すべての数列の得点の最大値 ans です。
    ans = 0
    if len(seq) == n:
        # 数列が完成したので、得点を計算します
        score_ret = 0
        for a, b, c, d in req:
            if seq[b-1] - seq[a-1] == c:
                score_ret += d
        return score_ret  # この数列の得点を返します
    else:
        # まだ数列が完成していません
        for i in range(seq[-1], m + 1):
            seq_next = seq + (i,)  # 長さ1のタプル(i,)を連結します
            score = dfs(seq_next)  # seq_nextから派生するすベての数列の中での、得点の最大値が返ってきます
            ans = max(ans, score)  # 最大の得点を更新します

    # すべてが終わったので、得点の最大値を返します
    return ans


n, m, q = list(map(int, input().split()))
# reqは[[a1,b1,c1,d1],[a2,b2,c2,d2]……]が入ったリストのリストです
req = [list(map(int, input().split())) for _ in range(q)]

# 最終的に答えが返ってくるようにします。処理はすべてdfsメソッドでやってもらいます。
# リストだとどこかで間違えて値を書き換えそうで怖いので、タプルにしておきます
# 1番目が1の場合以外は考えなくていいので、(1,)だけやります
ans = 0
score = dfs((1,))
ans = max(ans, score)
print(ans)


Measured memory_bytes: 9120
/*
*	User: Isanchez_Aguilar
*	Problem: AtCoder ABC134B - Golden Apple
*/
#include <bits/stdc++.h>

using namespace std;
using Long = long long;

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

	int n;
	cin >> n;

	vector< vector<int> > activities(n, vector<int>(3));

	for (int i = 0; i < n; ++i)
		cin >> activities[i][0] >> activities[i][1] >> activities[i][2];

	int dp[n][3];

	for (int i = 0; i < 3; ++i)
		dp[0][i] = activities[0][i];

	for (int day = 1; day < n; ++day)
	{
		for (int i = 0; i < 3; ++i)
			dp[day][i] = INT_MIN;

		dp[day][0] = max(dp[day - 1][1], dp[day - 1][2]) + activities[day][0];
		dp[day][1] = max(dp[day - 1][0], dp[day - 1][2]) + activities[day][1];
		dp[day][2] = max(dp[day - 1][0], dp[day - 1][1]) + activities[day][2];

	}	


	cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});

	return 0;
}

Measured memory_bytes: 6912
#include "bits/stdc++.h"
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 imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=2e3+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }

   void solve() {
	      int n,a,b,nax=0,sm=0;
	      cin>>n>>a>>b;
	      nax=a+b;
	  
	      int yo=0;
	      if(nax>0) 
	        yo=n/nax;
	      sm=yo*a;
	      
	      if(nax>0) {
			    int nv=n%nax;
			    if(nv>=a) sm+=a;
			    else sm+=nv;
			  }
	      cout<<sm<<endl;
	   
	   }

    
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	solve();


return 0;	   
}


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

using namespace std;

int main(void){
  int n,ans=0,index=1;
  vector<int> masu(101);
  cin >> n;
  for(int i=0;i < n;i++){
    cin >> masu.at(i);
  }
  
  for(int i=0;i < n;i++){
    if(index % 2 != 0 && masu.at(index-1) % 2 != 0) ans++;
    index++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int a[3];
int main() {
  for (int i = 0; i < 3; ++i) cin >> a[i];
  sort(a, a+3);
  if (a[2] == a[0] + a[1]) puts("Yes");
  else puts("No");
}
							 






Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int r = sc.nextInt();
    int D = sc.nextInt();
    int x = sc.nextInt();
    
    for(int i=0; i<10; i++){
      x = r*x - D;
      System.out.println(x);
    }
  }
}


Measured memory_bytes: 21844
/*================================================================
*   Copyright (C) 2019 Sangfor Ltd. All rights reserved.
*
*   创 建 者： badcw
*   创建日期： 2019/12/22
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 1e5+50;
const int mod = 1e9+7;
ll qp(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template <class T>
inline bool scan(T& ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return 0; // EOF
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

//template <class T>
//inline void out(T x) {
//    if (x > 9) out(x / 10);
//    putchar(x % 10 + '0');
//}

int n;
vector<int> edge[maxn];
int x, y;
int dep[maxn], fa[maxn][30];

void dfs(int u, int pre) {
    dep[u] = dep[pre] + 1, fa[u][0] = pre;
    for(int i = 1; (1 << i) <= n; i ++)
        fa[u][i] = fa[fa[u][i - 1]][i - 1];
    for(auto v : edge[u]) if(v != pre) dfs(v, u);
}

int LCA(int u, int v) {
    if(dep[u] < dep[v]) swap(u, v);
    int d = dep[u] - dep[v];
    for(int i = 0; (1 << i) <= d; i ++)
        if((1 << i) & d) u = fa[u][i];
    if(u == v) return u;
    for(int i = 20; i >= 0; i --)
        if(fa[u][i] != fa[v][i])
            u = fa[u][i], v = fa[v][i];
    return fa[u][0];
}

int dist(int u, int v) {
    return dep[u] + dep[v] - 2 * dep[LCA(u, v)];
}

int main(int argc, char* argv[]) {
    scanf("%d%d%d", &n, &x, &y);
    for (int i = 1; i < n; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    dfs(1, 0);
    int res = 0;
    for (int i = 1; i <= n; ++i) {
        int tmp1 = dist(x, i);
        int tmp2 = dist(y, i);
        if (tmp1 < tmp2) res = max(res, tmp2 - 1);
    }
    printf("%d\n", res);
    return 0;
}


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

int main(){
  vector<int> l(11); int v1, v2; char c;

  while(cin>>l[1]>>c>>l[2]>>c>>l[3]>>c>>l[4]>>c>>l[5]>>c>>l[6]>>c>>l[7]>>c>>l[8]>>c>>l[9]>>c>>l[10]>>c>>v1>>c>>v2){
    vector<int> sum(11, 0);
    for(int i=1; i<=10; i++) sum[i] = sum[i-1] + l[i];

    for(int i=1; i<=10; i++){
      if(sum[i-1] * (v1+v2) < v1 * sum[10] && sum[i] * (v1+v2) >= v1 * sum[10]){
        cout << i << endl;
      }
    }
  }
}
  
  


Measured memory_bytes: 3092
#include<stdio.h>

int main(){
	
	//準備・入力部分
	int n,m,c,a[100][100]={},b[100]={},h,i;
	scanf("%d %d",&n,&m);
	
	for(h=0;h<n;h++){
		for(i=0;i<m;i++){
			scanf("%d",&a[h][i]);
		}
	}
	for(h=0;h<m;h++)scanf("%d",&b[h]);
	
	//計算・出力部分
	for(h=0;h<n;h++){
		c=0;
		for(i=0;i<m;i++){
			c+=a[h][i]*b[i];
		}
		printf("%d\n",c);
	}
	
	return 0;
}



Measured memory_bytes: 2108
import math

N, K = list(map(int, input().split(" ")))

prob = 0
for i in range(N):
  if i + 1 < K:
    n = math.ceil(math.log(K / (i + 1), 2))
    prob += 1 / (N * (2 ** n))
  else:
    prob += (N - K + 1) / N
    break

print(prob)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int c[3][3], d[3][3];
int main(){
  for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) cin >> c[i][j];
  for(int i = 0; i <= 100; i++)
    for(int j = 0; j <= 100; j++)
      for(int k = 0; k <= 100; k++){
      	for(int l = 0; l < 3; l++) for(int m = 0; m < 3; m++) d[l][m] = c[l][m];
        for(int m = 0; m < 3; m++) d[0][m] -= i;
        for(int m = 0; m < 3; m++) d[1][m] -= j;
        for(int m = 0; m < 3; m++) d[2][m] -= k;
		bool good = true;
        for(int m = 0; m < 3; m++) good &= d[0][m] == d[1][m] && d[1][m] == d[2][m];
        if(good){
          cout << "Yes" << endl;
          return 0;
        }
      }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iomanip>
#include<queue>
#include<cmath>
#include<stack>
#include <map>
#define ll long long int
#define skip cin>>ws;
#define vll vector<ll> 
#define vb vector<bool>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define vs vector<string>
#define vvpll vector<vector<pair<ll, ll>>>
#define pb push_back
#define pob pop_back()
#define MOD (ll)(1e9 + 7)
#define test ll t; cin>>t; while(t--)

using namespace std;

void enter(vll &ar)
{
    ll n = ar.size();

    for(ll i=0;i<n;i++)
    {
        cin>>ar[i];
    }
}

void show(vll &a)
{
    ll n = a.size();

    for(ll i=0;i<n;i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void SieveOfErat1sthenes(int n, vll &pri) 
{ 
    vb prime(n+1, true); 
   
    for (int p=2; p*p<=n; p++) 
    { 
        
        if (prime[p] == true) 
        { 
            pri.pb(p);
            
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll mo(ll a)
{
    return a%MOD;
}

bool compare(pll a, pll b)
{
    return a.first>b.first;
}

vvll done(3000, vll(3000, 0)), dp(3000, vll(3000, 0)); 
vll a;

ll func(ll i, ll j)
{
    if(i>j) return 0;

    if(done[i][j]) return dp[i][j];

    done[i][j] = 1;
    dp[i][j] = max(a[i] + min(func(i+2, j), func(i+1, j-1)), a[j] + min(func(i+1, j-1), func(i, j-2)));
    return dp[i][j];
}

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

    ll n;
    cin>>n;

    a.resize(n);
    enter(a);

    ll sum = 0;
    for(ll ele: a) sum += ele;

    ll ans = func(0, n-1);

    cout<<ans-(sum-ans)<<"\n";

    return 0;
}


Measured memory_bytes: 144664
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		pr.println(Math.min(a, b) + Math.min(c, d));
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 22996
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String nl = System.getProperty("line.separator");
		StringBuilder p = new StringBuilder(1000);
		StringBuilder d = new StringBuilder(".");
		StringBuilder s = new StringBuilder("#");
		StringBuilder k = new StringBuilder(50);
		Scanner r = new Scanner(System.in);
		int h, w, i, ww;
		String t, u;
		for (i = 0; i < 4; ++i) {
			d.append(d);
			s.append(s);
		}
		ww = d.length();
		while ((h = r.nextInt()) + (w = r.nextInt()) > 0) {
			while (w > ww) {
				d.append(d);
				s.append(s);
				ww += ww;
			}
			p.append(u = s.substring(0,w));
			p.append(nl);
			k.setLength(0);
			k.append('#');
			k.append(d.substring(2, w));
			k.append('#');
			k.append(nl);
			for (i = h - 2; i > 0; --i) {
				p.append(k);
			}
			p.append(u);
			p.append(nl);
			p.append(nl);
		}
		System.out.print(p);
	}
}

Measured memory_bytes: 18372
import sys
sys.setrecursionlimit(180000)

def dfs(i,j):
    for m in move:
        ni = i + m[0]
        nj = j + m[1]
        if ni < 0 or ni >= H or nj < 0 or nj >= W:
            continue
        if ch[ni][nj]:
            continue
        if X[i][j] == X[ni][nj]:
            continue
            
        ch[ni][nj] = 1
        K[(ni+nj)%2] += 1
        dfs(ni, nj)
        
H, W = map(int, input().split())
X = [[[0, 1][a=="#"] for a in input()] for i in range(H)]
ch = [[0] * W for _ in range(H)]
    
move = [[0,1], [0,-1], [1,0], [-1,0]]

K = [0, 0]
ans = 0
for i in range(H):
    for j in range(W):
        if ch[i][j] > 0:
            continue
        ch[i][j] = 1
        K = [0, 0]
        K[(i+j)%2] = 1
        dfs(i, j)
        ans += K[0] * K[1]
        
print(ans)



Measured memory_bytes: 170224
import sys
N = int(input())
 
if N == 3:
    print('2 5 63')
    sys.exit()
if N == 4:
    print('2 5 20 63')
    sys.exit()
 
if N == 5:
    print('2 3 6 4 9')
    sys.exit()
 
 
S = '2 3 6 4 9'
 
N -= 5
 
print(S, end='')
 
if N == 1:
    print(' 12')
    sys.exit()
 
for i in range(5001):
    
    Tmp1 = 6 * i + 8
    Tmp2 = 6 * i + 10
    if Tmp2 > 30000:
        break
    
    print(' %d %d' %(Tmp1, Tmp2) , end='')
    N -= 2
    if N == 0:
        print()
        sys.exit()
    elif N == 1:
        print(' 12')
        sys.exit()
        
for i in range(5001):
    
    Tmp1 = 12 * i + 15
    Tmp2 = 12 * i + 21
    if Tmp2 > 30000:
        break
    
    print(' %d %d' %(Tmp1, Tmp2), end='')
    N -= 2
    if N == 0:
        print()
        sys.exit()
    elif N == 1:
        print(' 12')
        sys.exit()   
 
for i in range(N):
    
    Tmp1 = 6 * (i + 2)
    if Tmp1 > 30000:
        break
    
    print(' %d' %(Tmp1) , end='')
 
 
print()
 

Measured memory_bytes: 3436
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
#define REP(i,st,ed) for(int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(int i=st,i##end=ed;i>=i##end;--i)
const char str[]="GBYR";
const int maxn=505;
int n,m,d;
char ans[maxn][maxn];
int main(){
	scanf("%d%d%d",&n,&m,&d);
	REP(i,1,n)
		REP(j,1,m)
			ans[i][j]=str[((((i+j)/d)&1)<<1)|(((i-j+m)/d)&1)];
	REP(i,1,n)
		puts(ans[i]+1);
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  string s,tmp;
  bool can=true;
  cin >> s;
  reverse(s.begin(),s.end());
  int n=s.size();
  for(int i=0;i<n;){
    tmp=s.substr(i,5);
    if(tmp=="maerd"||tmp=="esare"){
      i+=5;
      continue;
    }
    tmp=s.substr(i,6);
    if(tmp=="resare"){
      i+=6;
      continue;
    }
    tmp=s.substr(i,7);
    if(tmp=="remaerd"){
      i+=7;
      continue;
    }
    can=false;
    break;
  }
  if(can)cout <<"YES\n";
  else cout <<"NO\n";

}


Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); int m = sc.nextInt();
		int x = sc.nextInt(); int y = sc.nextInt();
		int i,k,xmax = -100,ymin = 100,flg = 1; 
		int[] arX = new int[n]; int[] arY = new int[m];
		for(i = 0;i < n;i ++) {
			arX[i] = sc.nextInt();
			if(i == 0) {
				xmax = arX[i];
			}else {
				if(xmax < arX[i]) xmax = arX[i];
			}
		}
		for(i = 0;i < m;i++) {
			arY[i] = sc.nextInt();
			if(i == 0) {
				ymin = arY[i];
			}else {
				if(ymin > arY[i]) ymin = arY[i];
			}
		}
		int d = ymin - xmax;
		for(i = 0;i < d;i ++) {
			if((x < xmax+(i+1)) && ((xmax+(i+1)) <= y)) flg = 0;
		}
		if(ymin <= xmax || flg == 1) System.out.println("War");
		else {
			for(i = 0;i < n;i ++) {
				for(k = 0;k < m;k ++) {
					if(arX[i] > arY[k]) flg = 1; 
				}
				if(flg == 1) {System.out.println("War"); return;}
			}
			System.out.println("No War");
		}
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pll;
typedef pair<int, int> pii;
#define ff first
#define ss second
#define mod 1000000007

vector<lli> dp,h;

lli func(lli in){
    if(in==h.size()-1 ) return 0;
    if(in>=h.size()) return 0;
    if(dp[in]!=-1) return dp[in];

    lli a,b;
    a=abs(h[in+1]-h[in]) + func(in+1);
    if(in+2<h.size()) a=min(a, abs(h[in+2]-h[in]) + func(in+2));

    return dp[in]=a;
}

int main(){
    lli n;
    cin>>n;
    lli i,j,l;
    dp.resize(n);
    for(i=0;i<n;i++){
        cin>>j;
        h.push_back(j);
        dp[i]=-1;
    }
    lli ans=func(0);
    cout<<ans<<endl;
    return 0;
}


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

int main() {
	int N;
	string W[100];
	bool check = true;
	cin >> N >> W[0];
	for (int i = 1; i < N; i++) {
		cin >> W[i];
		if (W[i - 1][W[i - 1].size() - 1] != W[i][0]) check = false;
		for (int j = 0; j < i; j++) {
			if (W[i] == W[j]) check = false;
		}
	}
	if (check) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
n, x = gets.chomp.split.map(&:to_i)
y = gets.chomp.split.map(&:to_i)
d = (y[0] - x).abs
1.step(n - 1) do |i|
  break if d == 1
  d = d.gcd((y[i] - x).abs)
end
puts d

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

#define ll long long

ll n, k, r, s, p;
string t;
// 出した手にに対応した得点を返す
int score(char hand) {
    if(hand == 'r') return p;
    if(hand == 's') return r;
    return s;
}
int main() {
  cin >> n >> k >> r >> s >> p >> t;
  ll result = 0;
  vector<bool> memo(n);
  for(int i = 0; i < n; i++) {
      if(i < k || t[i] != t[i - k] || memo[i - k]) {
          result += score(t[i]);
      } else {
          // 手が出せなかったことをメモしておく
          memo[i] = true;
      }
  }
  cout << fixed << result;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    long long N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    
    long long MinTime = min({A, B, C, D, E});
    long long ans = (N + MinTime - 1) / MinTime + 4;
    
    cout << ans << endl;
    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int a,b;
		Scanner scan = new Scanner(System.in);
		a=scan.nextInt();
		b=scan.nextInt();
		System.out.println(a/b+" "+a%b+" "+String.format("%.5f", (double)a/b));
	}
}


Measured memory_bytes: 26468
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int x, y, a, b, c; ulint s = 0;
  cin >> x >> y >> a >> b >> c;
  priority_queue<int> t, u, v;
  rep(i, a){
    int d;
    cin >> d;
    t.push(d);
  }
  rep(i, b){
    int d;
    cin >> d;
    u.push(d);
  }
  rep(i, c){
    int d;
    cin >> d;
    v.push(d);
  }
  rep(i, x){
    v.push(t.top());
    t.pop();
  }
  rep(j, y){
    v.push(u.top());
    u.pop();
  }
  rep(i, x+y){
    s += v.top();
    v.pop();
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3188
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <utility>
#include <set>
#include <map>
using namespace std;

int n,m,r=0;
string st;
map<string,int> mp;

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin>>st;
        mp[st]+=1;
    }
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        cin>>st;
        mp[st]-=1;
    }
    for(auto itr=mp.begin();itr!=mp.end();++itr){
        r=max(r,itr->second);
    }
    printf("%d\n",r);
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    println(problem071b(s))
}

fun problem071b(s: String): String {
    val alphabets = arrayOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z")
    val set = mutableSetOf<String>()
    for (c in s) {
        set.add(c.toString())
    }
    for (i in alphabets.indices) {
        if (!set.contains(alphabets[i])) {
            return alphabets[i]
        }
    }
    return "None"
}

Measured memory_bytes: 39264
#include<iostream>

using namespace std;
int main()
{
	int N,i,j,x[30],y[30],max=-1,tmp;
	string S;
	cin >> N >> S;

	for(i=1; i<N; i++){
		tmp = 0;
		for(j=0; j<26; j++){
			x[j] = 0;
			y[j] = 0;
		}
		for(j=0; j<i; j++){
			x[S[j] - 'a']++;
		}
		for(j=i; j<N; j++){
			y[S[j] - 'a']++;
		}
		for(j=0; j<26; j++){
			if(x[j] > 0 && y[j] > 0)
				tmp++;
		}
		if(max < tmp)
			max = tmp;
	}
	cout << max << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1};
const vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0};
const vi d4y = {0, 1, 0, -1};

//----------------ここからだよ-------------------

int main(){
    int K,X; cin>>K>>X;
    cout<<(500*K>=X ?  "Yes" : "No")<<endl;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))

a=[]
b={}
ans=0

for i in range(n):
    a.append(i+l[i])
    b[i-l[i]] = b.get(i-l[i],0) + 1

for av in a:
    ans = ans + b.get(av,0)

print(ans)

Measured memory_bytes: 46412
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;
int main(void)

{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int right = 0, res = 0;
    set<char> st;
    int len = s.length();
    st.insert('A'), st.insert('C'), st.insert('G'), st.insert('T');
    rep(left, 0, len)
    {
        while (right < len && st.find(s[right]) != st.end())
            right++;
        res = max(res, right - left);
        if (left == right)
            right++;
    }
    cout << res << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
#define PRYES(x) PR((x) ? "Yes" : "No")
const long long INF = numeric_limits<long long>::max();
// SourceTest用出力マクロ
#ifdef SOURCE_TEST
#define SPR(x) PR(x)
#define SPS(x) PS(x)
#else
#define SPR(x) \
    {}
#define SPS(x) \
    {}
#endif
int main() {
    ll N;
    cin >> N;
    bool isOk = false;
    while (N > 0) {
        isOk |= (N % 10) == 7;
        N /= 10;
    }
    PR(isOk ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2);
        if(y%2==0)
         return (p*p)%hell;
        else
        return (x*((p*p)%hell))%hell;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
   ll n,k,x=0;
   cin>>n>>k;
   ll a[n];
   for(int i=0;i<n;i++)
   cin>>a[i];
   sort(a,a+n);
   for(int i=0;i<k;i++)
   x=x+a[i];
   cout<<x;}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n) {
        vector<vector<int>> v(n, vector<int>(n));
        for (int i = 0; i < n; ++i) {
            string s;
            cin >> s;
            for (int j = 0; j < n; ++j) {
                v[i][j] = (s[j] == '.' ? min(i+1, j+1) : 0);
                if(!v[i][j]) continue;
                if(i) v[i][j] = min(v[i][j], v[i-1][j]+1);
                if(j) v[i][j] = min(v[i][j], v[i][j-1]+1);
                if(i && j) v[i][j] = min(v[i][j], v[i-1][j-1]+1);
            }
        }
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                ans = max(ans, v[i][j]);
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 6700
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();
    LL n;
    cin >> n;
    LL ans = 1;
    for(LL i=1; i*i<=n; i++){
        if(n%i == 0) ans = i;
    }
    LL x = ans-1, y= (n/ans)-1;
    cout << x+y << endl;
}

Measured memory_bytes: 384
n = int(input())
j = {"AC": 0,"WA": 1,"TLE": 2, "RE": 3}
c = [0,0,0,0]
for i in range(n):
    c[j[input()]] += 1
print("AC x "+ str(c[0]))
print("WA x "+ str(c[1]))
print("TLE x "+ str(c[2]))
print("RE x "+ str(c[3]))

Measured memory_bytes: 9184
import java.util.Scanner;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a[] = new int[n];
		int sum=0;
		int min=-1;
		for(int i=0; i<n; i++) {
			a[i]=sc.nextInt();
			if(a[i]%10 != 0) {
				if(min == -1 || a[i]<min) {
					min=a[i];
				}
			}
			sum += a[i];
		}
		if(sum%10 == 0) {
			if(min == -1) {
				sum=0;
			} else {
				sum -= min;
			}
		}
		System.out.println(sum);
		sc.close();
	}
}




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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
int H, W;
bool isin(const PII& p){
  return 0 <= p.FF && p.FF < W && 0 <= p.SS && p.SS < H;
}
bool isin(int x, int y){
  return isin(MP(x,y));
}

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

  cin >> H >> W;
  VVI xs(H, VI(W));
  REP(y,H) REP(x,W) cin >> xs[y][x];

  vector<PII> out;
  REP(y,H) REP(x,W){
	bool ok = true;
	REP(d,4){
	  int tx = x + dx[d];
	  int ty = y + dy[d];
	  if(isin(tx,ty) && xs[y][x] > xs[ty][tx])
		ok = false;
	}
	if(ok) out.EB(x,y);
  }

  VVI st(H, VI(W));
  for(auto&& s: out){
	vector<vector<bool>> vis(H, vector<bool>(W));
	queue<PII> q;
	q.push(s);
	vis[s.SS][s.FF] = true;
	while(!q.empty()){
	  PII p = q.front();
	  q.pop();
	  REP(d,4){
		PII np(p.FF+dx[d], p.SS+dy[d]);
		if(isin(np) && !vis[np.SS][np.FF] && st[np.SS][np.FF] < 2 && xs[np.SS][np.FF] > xs[p.SS][p.FF]){
		  q.push(np);
		  st[np.SS][np.FF]++;
		  vis[np.SS][np.FF] = true;
		}
	  }
	}
  }

  int ans = 0;
  REP(y,H) REP(x,W)
	if(st[y][x] >= 2){
	  ++ans;
	}
  cout << ans << endl;

  return 0;
}

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

int table[6][7] = {
  {-1, 2, 6, 3, 4, 1, 5},
  {-1, 4, 2, 1, 6, 5, 3},
  {-1, 3, 2, 6, 1, 5, 4},
  {-1, 5, 1, 3, 4, 6, 2},
  {-1, 1, 3, 5, 2, 4, 6},
  {-1, 1, 4, 2, 5, 3, 6},
};

vector<int> rotate(const vector<int>& dice, int op) {
  vector<int> next(7);
  for (int i = 1; i <= 6; ++i)
    next[i] = dice[table[op][i]];
  return next;
}

int main() {
  int n;
  while (cin >> n, n) {
    vector<int> dice{-1, 1, 2, 3, 4, 5, 6};
    int ans = 1;
    for (int i = 0; i < n; ++i) {
      string operation; cin >> operation;
      if (operation == "North")
        dice = rotate(dice, 0);
      else if (operation == "East")
        dice = rotate(dice, 1);
      else if (operation == "West")
        dice = rotate(dice, 2);
      else if (operation == "South")
        dice = rotate(dice, 3);
      else if (operation == "Right")
        dice = rotate(dice, 4);
      else if (operation == "Left")
        dice = rotate(dice, 5);
      else
        assert(false);
      ans += dice[1];
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1216
#include <iostream>
using namespace std;
typedef long long ll;
ll n,s=0,g,m;
int main(void){
    cin>>n;
    g=n+1;
    while(g-s>1){
        m=(g+s)/2;
        //cout<<s<<" "<<g<<endl;
        if(m*(m+1)/2>=n)g=m;
        else s=m;
    }
    //cout<<g<<endl;
    s=g*(g+1)/2-n;
    for(int i=1;i<=g;i++){
        if(i==s)continue;
        cout<<i<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int N;
const int maxn = 101;
int num[2][maxn];
int sumMax = -1;
int main(){
    int tempSum=0;
    cin>>N;
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<N;j++)
        {
            cin>>num[i][j];
        }
    }

    for(int y=0;y<N;y++)
    {
        for(int a=0;a<=y;a++)
        {
            tempSum+=num[0][a];
        }
        for(int b=y;b<N;b++)
        {
            tempSum+=num[1][b];
        }
        sumMax = max(sumMax,tempSum);
        tempSum = 0;
    }
    cout<<sumMax<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
static const LL INF = 1LL<<61LL;
static const int MAX_N = 10000;
typedef pair<int,int> PII;

int par[MAX_N];
int rank[MAX_N];
int n,q;
int com,x,y;

class UF{
    public:
        void init(int n){
            rep(i,n){
                par[i]=i;
                rank[i]=0;
            }
        }

        int find(int x){
            if(par[x]==x)return x;
            return par[x]=find(par[x]);
        }

        void unite(int x,int y){
            x=find(x);
            y=find(y);
            if(x==y)return;
            if(rank[x]<rank[y])par[x]=y;
            else {
                par[y]=x;
                if(rank[x]==rank[y])rank[x]++;
            }
        }

        bool same(int x,int y){
            return find(x)==find(y);
        }
};
int main(){
    UF uf;
    cin>>n>>q;
    uf.init(n);
    rep(i,q){
        cin>>com>>x>>y;
        if(com==0)uf.unite(x,y);
        else cout<<uf.same(x,y)<<endl;
    }
    return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define FASTIO() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N = 200005, M = 1000000007, BIG = 0x3f3f3f3f;

int n, k;
int a[N];

bool Read() {
  cin >> k;
  if (cin.eof())
    return 0;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  return 1;
}

void Process() {
  int os = a[0];
  for (int i = 0; i < n; i++)
    a[i] -= os;
  int mx = k - a[n - 1];
  for (int i = 1; i < n; i++)
    mx = max(mx, a[i] - a[i - 1]);
  cout << k - mx << "\n";
}

int main() {
  FASTIO();

  while (Read())
    Process();

  return 0;
}

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

int main() {
  
  string s;
  cin >> s;
  
  if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }
  
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,k,i,j,box,sum,p[1001];
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(p[i]>p[j]){
				box=p[i];
				p[i]=p[j];
				p[j]=box;
			}
		}
	}
	sum=0;
	for(i=0;i<k;i++){
		sum=sum+p[i];
	}
printf("%d\n",sum);
return 0;
}
		

Measured memory_bytes: 1728
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#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() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<VL> VVL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

int main(){
    ll x,y,n,m,h,k,w,max=-10000000,min=2020202021,ans=0,sum=0;
    string s,t;
    cin >> n;
    VI a(n);
    rep(i,n){
        cin >> a[i];
	}
    rep(i,n){
        if(i+1==a[i]){
            if(i+2==a[i+1]){
                ans++;
                i+=1;
            }
            else{
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  ll h,w;
  while(cin>>h>>w){
    if(h==0&&w==0)break;

    rep(i,0,h){
      rep(j,0,w){
        if(i==0||i==h-1||j==0||j==w-1)cout<<'#';
        else cout<<'.';
      }
      cout<<endl;
    }
    cout<<endl;
  }


  return 0;
}



Measured memory_bytes: 3076