akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (true) {
            int n = scanner.nextInt(), x = scanner.nextInt();

            if (n == 0 && x == 0) break;

            int count = 0;
            for (int i = 1; i <= n; ++i) {
                for (int j = i + 1; j <= n; ++j) {
                    for (int k = j + 1; k <= n; ++k) {
                        if (i + j + k == x) count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
}


Measured memory_bytes: 26268
#include <stdio.h>

int main(void)
{
	int i, i2;
	
	for (i = 1; i < 10; i++){
		for (i2 = 1; i2 < 10; i2++){
			printf("%dx%d=%d\n", i, i2, i*i2);
		}
	}
	
	return (0);
}

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

int main() {
	int a,b,c,k,Max,sum;
	cin>>a>>b>>c>>k;
	Max=max(a,b);
	Max=max(Max,c);
	sum=Max;
	for(int i=0;i<k;i++) sum *=2;
	cout<<a+b+c-Max+sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
/*ll modexpo(ll a,ll b)
{
     ll ans=1LL;
     while(b>0)
     {
          if(b&1)ans=(ans*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return ans;
}
int find(int a){
     if(par[a]==a)return a;
     return par[a]=find(par[a]);
}
void unite(int a,int b){
     a=find(a),b=find(b);if(a==b)return ;
     parent[b]=a;
}*/
 
 
 
 
 
 
 







int main(){
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++)cin>>a[i];
    int pre[n+2]={0};
    for(int i=1;i<=min(41,k);i++){
         for(int j=1;j<=n;j++){
              int l=max(1,j-a[j]);
              int r=min(n,j+a[j]);
              pre[l]++;
              if(r+1<=n)pre[r+1]--;

         }
         for(int j=2;j<=n;j++)pre[j]+=pre[j-1];
         for(int j=1;j<=n;j++){a[j]=pre[j];pre[j]=0;}
    }
    for(int i=1;i<=n;i++)cout<<a[i]<<" ";
}

























Measured memory_bytes: 5168
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt(),k=in.nextInt();
			int a[]=new int[n];
			int pre=0;
			if((n|k)==0)
				return;
			for(int i=0;i<n;i++)
				a[i]=in.nextInt();
			for(int i=0;i<k;i++)
				pre+=a[i];
			int max=pre;
			
			for(int i=0;i<n-k;i++)
			{
				pre=pre-a[i]+a[k+i];
				max=Math.max(max, pre);
			}
			System.out.println(max);
		}
	}
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';        
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';
#define dln cerr << '\n';
#define dsp cerr << ' ';
#define pln cout << '\n';
#define psp cout << ' ';

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9 + 7;

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

int main(){
  fastio

  ll n, k;
  cin >> n >> k;
  ll cnt = 0;

  for(int i = 1; i <= n; i++){
    ll h;
    cin >> h;
    cnt += (h >= k);
  }

  cout << cnt << '\n';


  ktj();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int sz=55;
int n;
long long x;
long long l[sz];
long long v[sz];

long long solve(int level,long long pos){
    if(!pos) return !level;
    if(pos==l[level]-1) return v[level];
    long long mid=l[level]>>1;
    if(pos==mid) return v[level-1]+1;
    else if(pos<mid) return solve(level-1,pos-1);
    return 1+v[level-1]+solve(level-1,pos-mid-1);
}


int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    l[0]=1;
    v[0]=1;
    for(int i=1;i<=50;i++){
        l[i]=2*l[i-1]+3;
        v[i]=2*v[i-1]+1;
    }
    scanf("%d %lld",&n,&x);
    x--;
    printf("%lld",solve(n,x));
    return 0;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
        q: usize,
    }
    let mut s = 0;
    let mut z = vec![0; 100001];
    for x in a {
        z[x] += 1;
        s += x;
    }
    for _ in 0..q {
        input! {
            b: usize, c: usize,
        }
        s += c * z[b];
        s -= b * z[b];
        z[c] += z[b];
        z[b] = 0;
        println!("{}", s);
    }
}


Measured memory_bytes: 5288
#include<iostream>
#include<vector>
#include<set>
int main()
{
	std::vector<int>point(100);
	std::set<int>point_set;
	while (true)
	{
		int p, s;
		char comma;
		std::cin >> p >> comma >> s;
		point[p - 1] = s;
		point_set.insert(s);
		if (p == 0 && s == 0)
		{
			break;
		}
	}
	for (int q; std::cin >> q;)
	{
		std::cout << std::distance(point_set.find(point[q - 1]), point_set.end()) << std::endl;
	}
	return 0;
}


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

using namespace std;


int main(int argc, char *argv[])
{
    
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    
    string line;
    int n, h;
    
    while (getline(cin,line), line != "-") {
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> h;
            string next;
            next += line.substr(h) + line.substr(0,h);
            line = next;
        }
        cout << line << endl;
        cin.ignore(1024, '\n');
    }
    
    
    
    return 0;
}



Measured memory_bytes: 3220
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    int a_i[n];
    for(int i=0; i<n; i++) cin >> a_i[i];
    for(int i=n-1; i>=0; i--){
        cout << a_i[i];
        if(i != 0) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3092
fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()
    val p = sc.asSequence().take(n).map(String::toInt).toList()

    var sum = p.take(k).sum()
    var max = sum
    var idx = k - 1

    (k until n).forEach {
        sum += p[it]
        sum -= p[it - k]
        //println(sum)
        if (sum > max) {
            max = sum
            idx = it
        }
        //println(it)
    }

    print(((idx - k + 1)..idx).map { (p[it] + 1) / 2.0 }.sum())
}


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

int main(){
    string s;
    string t;
    int num = 0;
    cin >> s >> t;
    for(int i=0; i<3; i++){
        if(s[i]==t[i]){
            num++;
        }
    }
    cout << num << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<ull, ull> P; //ペア　タイプでふ
constexpr ll bigNum = 1000000007;

int main(void)
{
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    //ここから本体
    int a, b, c;
    cin >> a >> b >> c;
    int d;
    if (c - (a - b) > 0)
    {
        cout << c - (a - b);
    }
    else
    {
        cout << 0;
    }
}


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

int main(){
    int n;cin >> n;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++){
        cin >> a.at(i);
    }
    vector<bool> b(n+1,false);
    int ans=0;
    int i=1;
    while(1){
        ans++;
        b.at(i)=true;
        i = a.at(i);
        if(i==2){
            cout << ans << endl;
            return 0;
        }
        if(b.at(i)) break;
    }
    cout << -1 << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
selectionSort(int *A,int N){
	int i,j,tmp,count=0,minj;
	for(i=0;i<N;i++){
		minj=i;
		for(j=i;j<=N-1;j++){
			if(A[j]<A[minj]){
				minj=j;
			}
		}
		if(i!=minj){
			tmp=A[i];
			A[i]=A[minj];
			A[minj]=tmp;
			count++;
		}
	}
	return count;
}
int main(){
	int i,n,N[100],count;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&N[i]);
	}
	count=selectionSort(N,n);
	for(i=0;i<n-1;i++){
		printf("%d ",N[i]);
	}
	printf("%d\n",N[n-1]);
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 600
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  int n;
  cin>>n;
  int x=n%10;
  int y=n/100%10;
    int z=n/10%10;
  string ans="No";
  if(x==7||y==7||z==7){
    ans="Yes";
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

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

    string s;
    cin >> s;
    cout << (s[0] == s[1] && s[1] == s[2] ? "No" : "Yes");

    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    ll l, r;
    ll ans;
    vector<int> cnt_ac;
    cnt_ac.resize(n);
    for (int i = 0; i < n; i++) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            cnt_ac[i]++;
        }
    }
    vector<int> cnt;
    cnt.resize(n);
    cnt[0] = 0;
    for (int i = 1; i < n; i++) {
        cnt[i] = cnt_ac[i - 1];
        cnt[i] += cnt[i - 1];
    }
    for (int i = 0; i < q; i++) {
        cin >> l >> r;
        ans = 0;
        ans = cnt[r - 1] - cnt[l - 1];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1872
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main() {
	int H, W;
	int count;
	cin >> H >> W;
	vector<vector<int>> a(H, vector<int>(W));
	vector<vector<int>> ans(H*W, vector<int>(4));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> a[i][j];
		}
	}
	count = 0;
	int x, y;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (i == H - 1 && j == W - 1)break;
			if (i % 2 == 1)x = W - 1 - j;
			else x = j;
			y = i;
			if (a[y][x] % 2 == 0)continue;
			else if ((y % 2 == 0 && x == W - 1) || (y % 2 == 1 && x == 0)) {
				ans[count][0] = y + 1;
				ans[count][1] = x + 1;
				ans[count][2] = y + 2;
				ans[count][3] = x + 1;
				a[y][x]--;
				a[y + 1][x]++;
				count++;
			}
			else if (y % 2 == 0) {
				ans[count][0] = y + 1;
				ans[count][1] = x + 1;
				ans[count][2] = y + 1;
				ans[count][3] = x + 2;
				a[y][x]--;
				a[y][x + 1]++;
				count++;
			}
			else if (y % 2 == 1) {
				ans[count][0] = y + 1;
				ans[count][1] = x + 1;
				ans[count][2] = y + 1;
				ans[count][3] = x;
				a[y][x]--;
				a[y][x - 1]++;
				count++;
			}
		}
	}

	cout << count << endl;
	for (int i = 0; i < count; i++) {
		if (count > 0) cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " " << ans[i][3] << endl;
	}
	return 0;
}

Measured memory_bytes: 16768
while 1:
    try:
        a = list(map(int, input().split()))
        b=list(a)
        a.sort()
        while a[1]%a[0] != 0:
            a[1] %= a[0]
            a.sort()
        print(a[0], int(b[0]*b[1]/a[0]))
    except:
        break


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

int main(void)
{
	const long int MOD = 1E9+7;
	int n, m;
	scanf("%d%d",&n,&m);
	long long int X = 0, Y = 0, a;

	for (int i = 0; i < n; i++) {
		scanf("%lld",&a);
		X += a*(n-2*i-1);
		X %= MOD;
	}

	for (int i = 0; i < m; i++) {
		scanf("%lld",&a);
		Y += a*(m-2*i-1);
		Y %= MOD;
	}

	printf("%lld\n",(X*Y)%MOD);

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n, k, h[];
		n = sc.nextInt();
		k = sc.nextInt();
		h = new int[n];

		for (int i = 0; i < n; ++i)
			h[i] = sc.nextInt();
		sc.close();

		Arrays.sort(h);

		int min = h[n - 1]; 

		for(int i = 0; i < n - k + 1; ++i) {
			int tmp = h[n - i - 1] - h[n - i - k];
			min = Math.min(min,  tmp);
		}
		
		System.out.println(min);
	}

}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll a,b,c,d; cin >> a >> b >> c >> d;
  cout << max({a*c,a*d,b*c,b*d}) << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;

ll N;
ll a[100010];
int main(){
    cin>>N;
    ll ans=0;
    for(ll i=0;i<N;i++){
        cin>>a[i];
    }
    ll ans1=0;
    ll sum=0;
    for(ll i=0;i<N;i++){
        sum+=a[i];
        if(sum==0){
            ans1++;
            sum = (i%2==0? 1:-1);
        }
        else if(sum>0 != (i%2==0)){
            ans1+=abs(sum)+1;
            sum = (i%2==0? 1:-1);
        }
    }   
    ll ans2=0;
    sum=0;
    for(ll i=0;i<N;i++){
        sum+=a[i];
        if(sum==0){
            ans2++;
            sum = (i%2==1? 1:-1);
        }
        else if(sum>0 != (i%2==1)){
            ans2+=abs(sum)+1;
            sum = (i%2==1? 1:-1);
        }
    }
    cout<<min(ans1,ans2)<<endl;
    return 0;
}

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

vector<vector<char> > v;
void removeRow(int x)
{
    vector<vector<char> > ret;
    for(int i = 0; i < v.size(); i++)
    {
        if(i == x)
            continue;
        ret.push_back(vector<char>());
        for(int j = 0; j < v[i].size(); j++)
        {
            ret[ret.size() - 1].push_back(v[i][j]);
        }
    }
    v = ret;
}

void removeCol(int x)
{
    vector<vector<char> > ret;
    for(int i = 0; i < v.size(); i++)
    {
        ret.push_back(vector<char>());
        for(int j = 0; j < v[i].size(); j++)
        {
            if(j == x)
                continue;
            ret[ret.size() - 1].push_back(v[i][j]);
        }
    }
    v = ret;
}

bool isRowWhite(int x)
{
    for(int i = 0; i < v[x].size(); i++)
        if(v[x][i] != '.')
        return 0;
    return 1;
}

bool isColWhite(int x)
{
    for(int i = 0; i < v.size(); i++)
        if(v[i][x] != '.')
            return 0;
    return 1;
}

int w, h;

void disp()
{
    cout << "---------------------";
    for(int i = 0; i < v.size(); i++)
        {
            for(int j = 0; j < v[i].size(); j++)
            {
                cout << v[i][j];
            }
            cout << endl;
        }
    cout << "---------------------";
}

int main()
{
    while(cin >> h >> w)
    {
        v.clear();
        v.resize(h);
        for(int i = 0; i < h; i++)
        {
            v[i].resize(w);
            for(int j= 0; j < w; j++)
                cin >> v[i][j];
        }

        for(int i = 0; i < v.size(); i++)
        {
            if(isRowWhite(i))
            {
                removeRow(i);
                i--;
                //cout << "Row " <<i <<endl;
                //disp();
            }

        }

        for(int i = 0; i < v[0].size(); i++)
        {
            if(isColWhite(i))
            {
                removeCol(i);
                i--;
                //cout << "Col " <<i <<endl;
                //disp();
            }
        }

        for(int i = 0; i < v.size(); i++)
        {
            for(int j = 0; j < v[i].size(); j++)
            {
                cout << v[i][j];
            }
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
import java.*;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str1 = sc.next();
		if(str1.equals("MON") ) {
			System.out.println(6);
		}else if(str1.equals("TUE")) {
			System.out.println(5);
		}else if(str1.equals("WED")) {
			System.out.println(4);
		}else if(str1.equals("THU")) {
			System.out.println(3);
		}else if(str1.equals("FRI")) {
			System.out.println(2);
		}else if(str1.equals("SAT")) {
			System.out.println(1);
		}else if(str1.equals("SUN")){
			System.out.println(7);
		}
	}
}


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

int h,w;
int maps[100][100];
int color;
int gy,gx,sy,sx;
int dy[]={-1,0,1,0};
int dx[]={0,-1,0,1};
int muki[2][2]={
  {2,4},
  {4,2}
};
    
  

bool dfs(int y,int x);

int main(){
  int n;
  int c,d,y,x;
  while(cin >> w >> h,w | h){
    memset(maps,-1,sizeof(maps));
    cin >> sx >> sy >> gx >> gy;
    sx--;sy--;gx--;gy--;
    cin >> n;
    for(int i = 0; i < n; ++i){
      cin >> c >> d >> x >> y;
      y--;x--;
      for(int j = 0; j < muki[d][0]; j++){
	for(int k = 0;k < muki[d][1]; k++){
	  maps[y + j][x + k] = c;
	}
      }
    }
    for(int i=0;i<h;i++){
      for(int j = 0; j< w ; j++){
	if(i==sy && j == sx)color = maps[sy][sx];
      }
    }
    /*
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	printf("%3d",maps[i][j]);
      }
      cout<<endl;
    }*/

    if(dfs(sy,sx))cout << "OK" << endl;
    else cout << "NG" << endl;
    
    /*
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	printf("%3d",maps[i][j]);
      }
      cout<<endl;
      }*/

  }
}
 
bool dfs(int y,int x){
  maps[y][x] = -1;
  if(gy==y && gx==x){
    return true;
  }
  bool b = false;
  for(int i=0;i<4;i++){
    int vy=y+dy[i];
    int vx=x+dx[i];
    if(vy >= 0 && vy < h && vx >= 0 && vx < w && maps[vy][vx] != -1 && maps[vy][vx] == color){
      b = b | dfs(vy,vx);
    }
  }
  return b;
}
  

Measured memory_bytes: 1204
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func main() {
	solve(NewScanner())
}

func contains(s []int, e int) (bool, int) {
	for i, v := range s {
		if e == v {
			return true, i
		}
	}
	return false, 0
}

func solve(s *Scanner) {
	wtr := bufio.NewWriter(os.Stdout)
	cardRows := 3
	A1 := s.nextIntSlice(cardRows)
	A2 := s.nextIntSlice(cardRows)
	A3 := s.nextIntSlice(cardRows)
	N := s.nextInt()
	bs := s.nextIntSlice(N)

	A1hits := make(map[int]bool)
	A2hits := make(map[int]bool)
	A3hits := make(map[int]bool)

	for i := 0; i < N; i++ {
		contain, j := contains(A1, bs[i])
		if contain {
			A1hits[j] = true
		}
		contain, k := contains(A2, bs[i])
		if contain {
			A2hits[k] = true
		}
		contain, l := contains(A3, bs[i])
		if contain {
			A3hits[l] = true
		}
	}

	if A1hits[0] && A1hits[1] && A1hits[2] {
		fmt.Fprintln(wtr, "Yes")
		wtr.Flush()
		return
	}
	if A2hits[0] && A2hits[1] && A2hits[2] {
		fmt.Fprintln(wtr, "Yes")
		wtr.Flush()
		return
	}
	if A3hits[0] && A3hits[1] && A3hits[2] {
		fmt.Fprintln(wtr, "Yes")
		wtr.Flush()
		return
	}
	if A1hits[0] && A2hits[0] && A3hits[0] {
		fmt.Fprintln(wtr, "Yes")
		wtr.Flush()
		return
	}
	if A1hits[1] && A2hits[1] && A3hits[1] {
		fmt.Fprintln(wtr, "Yes")
		wtr.Flush()
		return
	}
	if A1hits[2] && A2hits[2] && A3hits[2] {
		fmt.Fprintln(wtr, "Yes")
		wtr.Flush()
		return
	}
	if A1hits[0] && A2hits[1] && A3hits[2] {
		fmt.Fprintln(wtr, "Yes")
		wtr.Flush()
		return
	}
	if A1hits[2] && A2hits[1] && A3hits[0] {
		fmt.Fprintln(wtr, "Yes")
		wtr.Flush()
		return
	}

	fmt.Fprintln(wtr, "No")
	wtr.Flush()
}


Measured memory_bytes: 640
# Here your code !
until (n = gets.to_i) == 0 do

    dic = Array.new
    
    for i in 0...n do
        dic[i] = gets.split(" ").map(&:to_s)
    end
    
    m = gets.to_i
    
    for j in 0...m do
        printed = false
        str = gets.to_s.strip
        
        for i in 0...n do
            if dic[i][0] == str then
                printf("#{dic[i][1]}")
                printed = true
            end
        end
        if !printed then
            printf("#{str}")
        end
    end
    printf("\n")
end

Measured memory_bytes: 8704
import math
import collections
import itertools
import heapq

def main():
    N = int(input())
    A = list(map(int, input().split()))

    prod = 1
    for a in A:
        prod *= a
    prod_div_a = [0] * N
    for i in range(N):
        prod_div_a[i] = prod // A[i]
    res = prod / sum(prod_div_a)
    print(res)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 65432
#include <iostream>

using namespace std;

float FindGradient(float a1, float b1, float a2, float b2)
{
    return (b2 - b1)/(a2 - a1);
}

int main()
{
    int T;
    string Result[100];
    cin >> T;

    for(int a = 0; a < T; a++)
    {
        float x1,x2,x3,x4,y1,y2,y3,y4;
        float M1,M2;

        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        M1 = FindGradient(x1,y1,x2,y2);
        M2 = FindGradient(x3,y3,x4,y4);

        if(M1 == M2)
        {
            Result[a] = "YES";
        }
        else
        {
            Result[a] = "NO";
        }
    }

    for(int b = 0; b < T; b++)
    {
        cout << Result[b] << endl;
    }
}

Measured memory_bytes: 3220
#include <iostream>
#include <deque>
using namespace std;
 
int main(int argc, char** argv) {
    deque<int> deq;
    int n;
    while(cin >> n) {
        if(n == 0) {
            cout << deq.back() << endl;
            deq.pop_back();
        }else {
            deq.push_back(n);
        }
    }
    return 0;
}


Measured memory_bytes: 3056
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
vector<string>split(string s, char c = ' ') {
	vector<string>vec;
	string h = "";
	for (int i = 0; i < s.size();) {
		int j = i;
		while (j < s.size() && s[j] != ' ') {
			h += s[j++];
		}
		if (h.size() > 0) vec.push_back(h);
h = "";
i = j + 1;
	}
	return vec;
}
template<typename T>
void print_vec(vector<T>a) {
	for (int i = 0; i < a.size(); i++) {
		cout << (i == 0 ? "" : " ") << a[i];
	}
	cout << endl;
}
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
int a[200000];
signed main() {
	char s;
	cin >> s;
	if (s == 'A') cout << "T\n";
	if (s == 'C') cout << "G\n";
	if (s == 'G') cout << "C\n";
	if (s == 'T') cout << "A\n";
}

Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	char c;
	cin >> c;
	cout << (c < 'a' ? 'A' : 'a') << endl;
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

// HL 分解
// 頂点 v を根とする部分木: [ in[v], out[v] )
// 頂点 v から見た heavy edge chain の頭: head[v]
struct HLD {
    vector< vector<int> > G;
    vector<int> sub, par, depth, in, out, rev, head;
    
    void dfs_sub(int cur) {
        for(auto& to : G[cur]) {
            if(par[cur] == to) continue;
            par[to] = cur;
            depth[to] = depth[cur] + 1;
            dfs_sub(to);
            sub[cur] += sub[to];
            if(sub[to] > sub[ G[cur][0] ]) swap(to, G[cur][0]);
        }
    }
    void dfs_hld(int cur, int& ptr) {
        in[cur] = ptr; rev[ptr++] = cur;
        for(auto to : G[cur]) {
            if(par[cur] == to) continue;
            head[to] = (to == G[cur][0] ? head[cur] : to);
            dfs_hld(to, ptr);
        }
        out[cur] = ptr;
    }

    HLD(int N) : G(N), sub(N, 1), par(N, -1), depth(N),
                 in(N), out(N), rev(N), head(N) {}
    void add_edge(int u, int v) {
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    void build(int root=0) {
        int ptr = 0; dfs_sub(root); dfs_hld(root, ptr);
    }
    int lca(int u, int v) {
        while(1) {
            if(in[u] > in[v]) swap(u, v);
            if(head[u] == head[v]) return u;
            v = par[head[v]];
        }
    }
    int distance(int u, int v) {
        return depth[u] + depth[v] - 2 * depth[lca(u, v)];
    }
};


void GRL_5_C() {
    int N; cin >> N;
    HLD hl(N);
    for(int i=0; i<N; i++) {
        int c; cin >> c;
        for(int j=0; j<c; j++) {
            int u = i, v; cin >> v;
            hl.add_edge(u, v);
        }
    }
    hl.build();

    int Q; cin >> Q;
    for(int i=0; i<Q; i++) {
        int u, v; cin >> u >> v;
        cout << hl.lca(u, v) << endl;
    }
}

int main() {
    GRL_5_C(); // LCA
}



Measured memory_bytes: 15372
H,W=map(int,input().split())
board=[list(input()) for i in range(H)]
print()

for i in range(H):
	emp=1
	for j in range(W):
		if(board[i][j]=='#'):
			emp=0
	if(emp==1):
		for j in range(W):
			board[i][j]='0'

for i in range(W):
	emp=1
	for j in range(H):
		if(board[j][i]=='#'):
			emp=0
	if(emp==1):
		for j in range(H):
			board[j][i]='0'
			
for i in range(H):
	out=""
	for j in range(W):
		out+=board[i][j] if board[i][j]!='0' else ""
	if out!="":
		print(out)

Measured memory_bytes: 3188
let n:Int = Int(readLine()!)!
let l:[Int] = readLine()!.split(separator:" ").map{Int($0)!}
var count:Int = 0
if n < 3 {}
else {
  for i in 0..<n-2 { for j in i+1..<n-1 { for k in j+1..<n {
    let a = l[i], b = l[j], c = l[k]
    if a+b<=c || b+c<=a || c+a<=b || a==b || b==c || c==a {}
    else {count+=1}
  }}}
}
print(count)

Measured memory_bytes: 8268
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x;
    cin>>x;
    if(x>=400 && x<=599){
        cout<<"8";
    }
    else if(x>=600 && x<=799){
        cout<<"7";
    }
    else if(x>=800 && x<=999){
        cout<<"6";
    }
    else if(x>=1000 && x<=1199){
        cout<<"5";
    }
    else if(x>=1200 && x<=1399){
        cout<<"4";
    }
    else if(x>=1400 && x<=1599){
        cout<<"3";
    }
    else if(x>=1600 && x<=1799){
        cout<<"2";
    }
    else if(x>=1800 && x<=1999){
        cout<<"1";
    }
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    string s; cin >> s;
    int n = SZ(s);
    for (int i = 0; i < n; i++) {
        if (i & 1) {
            if (s[i] == 'R') {
                cout << "No\n";
                exit(0);
            }
        } else {
            if (s[i] == 'L') {
                cout << "No\n";
                exit(0);
            }
        }
    }
    cout << "Yes\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   

int32_t main() 
{
    fastio
    int h, w, k;
    cin>>h>>w>>k;
    vector<vi> arr(h, vi(w));
    for(int i = 0; i<h; ++i)  {
        string s;
        cin>>s;
        for(int j = 0; j<w; ++j) {
            arr[i][j] = s[j];
        }
    }

    ll ans = 0;
    for(int i = 0; i<(1<<h); ++i) {
        for(int j = 0; j<(1<<w); ++j) {
            vector<vi> arr2(arr);
            int cnt = 0;
            int temp = i;
            while(cnt<h) {
                if(temp&1) {
                    for(int pl = 0; pl<w; ++pl) {
                        arr2[cnt][pl] = 'R'; 
                    }
                }
                temp>>=1;
                cnt++;
            }

            cnt = 0;
            temp = j;
            while(cnt<w) {
                if(temp&1) {
                    for(int pl = 0; pl<h; ++pl) {
                        arr2[pl][cnt] = 'R'; 
                    }
                }
                temp>>=1;
                cnt++;
            }

            int c = 0;
            for(int pl1 = 0; pl1<h; pl1++) {
                for(int pl2 = 0; pl2<w; pl2++) {
                    if(arr2[pl1][pl2]=='#') {
                        c++;
                    }
                }
            }
            
            if(c==k) {
                ans++;
            }
        }
    }
    cout<<ans<<endl;
} 

Measured memory_bytes: 3644
#include<cstdio>
#include<algorithm>
#define N_ 101000
using namespace std;
long long D[N_];
int a, b, n, W;
int main() {
	int i, j;
	scanf("%d%d", &n,&W);
	for (i = 1; i <= n; i++) {
		scanf("%d%d", &a, &b);
		for (j = W - a; j >= 0; j--) {
			D[j + a] = max(D[j + a], D[j] + b);
		}
	}
	long long r = 0;
	for (i = 0; i <= W; i++)r = max(r, D[i]);
	printf("%lld\n", r);
}

Measured memory_bytes: 896
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair

/*int P[10010];
void init(int n){//Union-find
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？
//セグメント木？？
*/

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
/*ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination//ただしfは用意してね
*/

//cerrはコメントアウトしなくても通る

int main(){
    int n;
    cin >> n;
    int b[n-1];
    rep(i,n-1){
        cin >> b[i];
    }
    int a[n];
    rep(i,n){
        a[i]=INF;
    }
    a[0]=b[0];
    rep(i,n-2){
        if(b[i+1]>b[i]){
            a[i+1]=b[i];
        }else{
            a[i+1]=b[i+1];
        }
    }
    a[n-1]=b[n-2];
    ll ans=0;
    rep(i,n){
        ans+=a[i];
        cerr<<a[i]<<" ";
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int n, res = 0, tempres;
  cin >> n;
  for(int i = 1; i < sqrt(n); i++) {
    tempres = 0;
    int j = i;
    while(i*j < n) {
      tempres++;
      j++;
    }
    res += tempres*2 - 1;
  }
  cout << res << endl;
}

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

//#pragma gcc optimize("O3,unroll-loop")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
//#define int long long
#define double long double
#define PI 3.14159265358979

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

    int a, b, h, m;
    cin >> a >> b >> h >> m;

    double da = h * 30 + (double)m / 60 * 30, db = (double)m / 60 * 360;
    cout << fixed << setprecision(16) << sqrt(a * a + b * b - 2 * a * b * cos(min(360 - abs(da - db), abs(da - db)) / 180 * PI)) << '\n';

    return 0;
}

//      *   *  *****  *   *  *   *
//     *   *  *      **  *  *   *
//    *****  *****  * * *  *   *
//   *   *      *  *  **  *   *
//  *   *  *****  *   *   ***

//      ***** ***** *   * *     ***** *   * ***** *****
//        *  *   * *   * *       *   **  *   *   *   *
//       *  *   * ***** *       *   * * *   *   *****
//   *  *  *   *   *   *       *   *  **   *   *
//  ****  *****   *   ***** ***** *   *   *   *


Measured memory_bytes: 4164
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    for(size_t i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    int ans = 0;
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    
    for(size_t i = 0; i < k; i++)
    {
        ans += v[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def solve(a, b, c, d):
    return max([a * c, a * d, b * c, b * d])


def main():
    a, b, c, d = map(int, input().split())
    res = solve(a, b, c, d)
    print(res)


def test():
    assert solve(1, 2, 1, 1) == 2
    assert solve(3, 5, -4, -2) == -6
    assert solve(-1000000000, 0, -1000000000, 0) == 1000000000000000000


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 9188
let () = Scanf.scanf "%d" @@ fun n ->
  let ws = Array.init n @@ fun _ -> Scanf.scanf " %d" Fun.id in
  let acc = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    acc.(i + 1) <- acc.(i) + ws.(i)
  done;
  Printf.printf "%d\n" @@
  Array.fold_left min max_int @@
  Array.init n @@ fun i -> abs (acc.(n) - 2 * acc.(i))

Measured memory_bytes: 3864
#include<iostream>
#include<math.h>
using namespace std;
int main(){
	int x,res=0;
	cin>>x;
	for(int i=1;i<=x;i++){
		res+=i;
		if(res>=x){
			cout<<i;
			return 0;
		}
	}
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int Balls[10];
 
bool fork(int balls[], int i, int b, int c) {
  if (i == 10) return true;
  if (b > balls[i] && c > balls[i]) return false;
  if (b < balls[i]) fork(balls, i + 1, balls[i], c);
  if (c < balls[i]) fork(balls, i + 1, b, balls[i]);
}
 
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> Balls[j];
    }
    if(fork(Balls, 0, 0, 0)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 2996
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

enum OP{
  integer=0,
  add=1,
  sub=2,
  mul=3
};

const char *op2str = " +-*";

struct node{
  int op;
  int val;
  node *l;
  node *r;
  node(int v) : val(v), op(integer) {}
  node(int o, node *lt, node *rt) : op(o), l(lt), r(rt) {}
  int value(){
    if(op == integer) return val;
    int a = l->value();
    int b = r->value();
    if(op == add) return a+b;
    if(op == sub) return a-b;
    if(op == mul) return a*b;
  }
  void print(){
    if(op == integer){
      printf("%d",val);
      return;
    }
    printf("(");
    l->print();
    printf(" %c ",op2str[op]);
    r->print();
    printf(")");
  }
};

bool search(node *nd[], int n){
  if(n == 1){
    int val = nd[0]->value();
    //printf("%d : ",val); nd[0]->print(); puts("");
    if(val == 10){
      nd[0]->print();
      puts("");
      return true;
    }else{
      return false;
    }
  }else{
    int p[n];
    REP(i,n) p[i] = 0;
    p[n-1] = p[n-2] = 1;
    do{
      node *nd2[n-1];
      node *chs[2];
      int cnt1 = 0, cnt2 = 0;
      REP(i,n){
	if(p[i] == 0){
	  nd2[cnt1++] = nd[i];
	}else{
	  chs[cnt2++] = nd[i];
	}
      }
      REP(i,3){
	{
	  node nw(i+1,chs[0],chs[1]);
	  nd2[cnt1] = &nw;
	  if(search(nd2, n-1)) return true;
	}
	if(i == 1){
	  node nw(i+1,chs[1],chs[0]);
	  nd2[cnt1] = &nw;
	  if(search(nd2, n-1)) return true;
	}
      }
    }while(next_permutation(p, p+n));
  }
  return false;
}

int main(){
  int a,b,c,d;
  while(scanf("%d%d%d%d",&a,&b,&c,&d),a+b+c+d){
    node nd[4] = {node(a), node(b), node(c), node(d)};
    node *t[4] = {&nd[0], &nd[1], &nd[2], &nd[3]};
    if(!search(t,4)) puts("0");
  }
  return 0;
}

Measured memory_bytes: 0
/** author: __nishad__ **/

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


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a) for(int i=0; i<a;i++)
#define loop2(i,a,b) for(int i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    ll n;
    cin>>n;

    vector<string> str;
    vector<string>::iterator it;
    string s;

    while(n--){
        cin>>s;
        it = find(all(str), s);
        if(it == str.end()){
            str.pb(s);
        }
    }
    if(str.size() == 3)
        cout<<"Three";
    else
        cout<<"Four";

}




Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, c, x int
	fmt.Scan(&a, &b, &c, &x)
	cnt := 0
	for i := 0; i <= a; i++ {
		for j := 0; j <= b; j++ {
			if y := x - 500*i - 100*j; y >= 0 && y/50 <= c {
				cnt++
			}
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
#include <stdio.h>
int main (void) {
    int temp[5],card[14],i,one,two,three,four;
    while (scanf("%d,%d,%d,%d,%d\n",&temp[0],&temp[1],&temp[2],&temp[3],&temp[4])!=EOF) {
        one=0;
        two=0;
        three=0;
        four=0;
        for(i=1;i<=13;i++) card[i]=0;
        for (i=0; i<5; i++) {
            card[temp[i]]++;
            if (card[temp[i]]==1) one++;
            if (card[temp[i]]==2) {
                one--;
                two++;
            }
            if (card[temp[i]]==3) {
                two--;
                three++;
            }
            if (card[temp[i]]==4) {
                three--;
                four++;
            }
        }
        if (four==1) {
            printf("four card\n");
        } else if (three==1&&two==1) {
            printf("full house\n");
        } else if (one==5) {
            for (i=1;i<=10;i++) {
                if (i<=9&&card[i]==1&&card[i+1]==1&&card[i+2]==1&&card[i+3]==1&&card[i+4]==1) {
                    printf("straight\n");
                    break;
                } else if (i==10&&card[i]==1&&card[i+1]==1&&card[i+2]==1&&card[i+3]==1&&card[1]==1) {
                    printf("straight\n");
                    break;
                } else if (i==10) {
                    printf("null\n");
                    break;
                }
            }
        } else if (three==1) {
            printf("three card\n");
        } else if (two==2) {
            printf("two pair\n");
        } else if (two==1) {
            printf("one pair\n");
        } else {
            printf("null\n");
        }
    }
    return 0;
}

Measured memory_bytes: 584
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int size = 1e6 ;


int main() {
    /*#ifndef ONLINE_JUDGE 
   freopen("input.txt","r",stdin) ;
   freopen("output.txt","w",stdout) ;
   #endif */
   int N , M ;
   cin >> N >> M ;
   vector<int>a(M+1,0) ;
   for(int i = 0 ; i < N ; i++ )
   {
     int c , x ;
     cin >> c ;
     for(int j = 0 ; j < c ; j++)
     {
         cin >> x ;
         a[x]++;
     }
   }
   int ans = 0 ;
   for(int i =1 ; i <= M ; i++ ) 
   {
     if(a[i] == N) ans++;
   }
   cout<<ans<<endl;
   return 0 ;
}


Measured memory_bytes: 256
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    if N%2 == 0:
        print(N//2 - 1)
    else:
        print(N//2)


if __name__ == '__main__':
    main()

Measured memory_bytes: 66156
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;

int main()
{
	char buf[101];
	int n = 0;
	while (scanf("%s\n", buf) != EOF)
	{
		bool f = true;
		for (int i = 0; i < strlen(buf)/2; ++i)
		{
			if (buf[i] != buf[strlen(buf)-1-i])
			{
				f = false;
				break;
			}
		}
		if (f)
			++n;
	}
	printf("%d\n", n);
	
	return 0;
}

Measured memory_bytes: 0