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

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

    vl s(n), t(m);
    rep(i, n) {
        cin >> s[i];
    }
    rep(i, m) {
        cin >> t[i];
    }

    vvl dp(n, vl(m));  // dp[i][j] : s[i]とt[j]をペアにするときs[i]までとt[j]までで整数列として等しい空でない部分列の組の個数
    vvl rui(n+1, vl(m+1));  // rui[i][j] : sum_{0 <= x < i, 0 <= y < j} dp[x][y]
    rep(i, n) {
        rep(j, m) {

            if(s[i] == t[j]) {
                dp[i][j] = rui[i][j] + 1;
            }

            rui[i+1][j+1] = rui[i+1][j] + rui[i][j+1] + mod - rui[i][j] + dp[i][j];
            
            dp[i][j] %= mod;
            rui[i+1][j+1] %= mod;
        }
    }

    out(rui[n][m] + 1);
    re0;
}

Measured memory_bytes: 62976
#include<bits/stdc++.h>
#define int long long
#define dd second
#define mp make_pair
#define pb push_back
#define ff first
#define pp pair<int,int>
using namespace std;

int n;

int tab[100005];

main()
{
    ios_base::sync_with_stdio(false); cin >> n;
    for(int i = 0; i < n; ++i) cin >>tab[i];
    int st = 0;
    int ans = 1e17;
    int res = 0;

    for(int i = 1; i < n; ++i) tab[i] += tab[i-1];

    for(int i = 0; i < n; ++i)
    {
        if(i & 1)
        {
            if(tab[i]+st <= 0)
            {
                res += 1-(tab[i]+st);
                st += 1-(tab[i]+st);
            }
        }
        else
        {
            if(tab[i]+st >= 0)
            {
                res += (tab[i]+st)+1;
                st -= (tab[i]+st)+1;
            }
        }
    }

    ans = min(ans, res);
    st = res = 0;


    for(int i = 0; i < n; ++i)
    {
        if(not (i & 1))
        {
            if(tab[i]+st <= 0)
            {
                res += 1-(tab[i]+st);
                st += 1-(tab[i]+st);
            }
        }
        else
        {
            if(tab[i]+st >= 0)
            {
                res += (tab[i]+st)+1;
                st -= (tab[i]+st)+1;
            }
        }
    }
    ans = min(ans,res);
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int mod = 1e9+7;
const long long INF = 1LL << 60;
typedef long long ll;

int weight[110], value[110]; 
int dp[110][10010];
int main(){
    int n, W;
    cin >> n >> W;
    rep(i,n) cin >> value[i] >> weight[i];
    //dp初期化
    for(int w = 0; w <= W; ++w)dp[0][w] = 0;
    //dpループ
    for(int i = 0; i < n; i++){
        for(int w = 0; w <= W; w++){
            if(w >= weight[i]){
                dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w]);
            }
            //選ばない場合
            else dp[i+1][w] = dp[i][w];
        }
    }
    cout << dp[n][W] << endl;
}


Measured memory_bytes: 7036
a['___'],c;
main(i,j)
{
  for(;++i<1e6;)for(j=i;a[j+=i]=j<1e6;);
  for(;scanf("%d",&j),i=j;c=!printf("%d\n",c))
    for(;++j<=i*2;)c+=!a[j];
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/

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

struct Z{
  ll y;
  ll x;
  ll depth;
};

ll H, W, K, y, x, depth, xs, ys, xg, yg;
vector<ll> y_vec = {1, 0, -1, 0};
vector<ll> x_vec = {0, 1, 0, -1};
vector<vector<ll>> A;
queue<Z> Q;

ll bfs(){
  ll ans = oo;
  while(!Q.empty()){
    Z now = Q.front(); Q.pop();
    y = now.y, x = now.x, depth = now.depth;
    if(y == yg && x == xg)
      return depth;
    for(ll i=0; i<4; i++){
      for(ll k=1; k<=K; k++){
        Z next={y + y_vec[i] * k, x + x_vec[i] * k, depth + 1};
        if(A[next.y][next.x] == -1) break;
        if(A[next.y][next.x] < next.depth) break;
        if(A[next.y][next.x] == next.depth) continue;
        A[next.y][next.x] = next.depth;
        Q.push(next);
      }
    }
  }
  return oo;
}

//A[y][x], A(x,y)として管理
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);  cin >> H >> W >> K;
  cin >> ys >> xs >> yg >> xg;
  A.assign(H+2, vector<ll>(W+2, -1));
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      char a; cin >> a;
      if (a == '@') continue;
      A[i][j] = oo;
    }
  }
  A[ys][xs] = 0;
  Z start = {ys, xs, 0};
  Q.emplace(start);
  ll ans = bfs();
  if(ans == oo) ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 34604
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <utility>

using namespace std;


char map[101][101];
pair<int,int> s;
int w,h;
int cnt;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
class Node{
public:
  int x,y;
  Node(int _x,int _y):x(_x),y(_y){

  }

};
int sx,sy;
void show(){
  for(int i=0;i<h;i++){
    cout<<map[i]<<endl;

  }
  cout<<endl;
}
void bfs(int x,int y,char c){
  //  cout<<x<<","<<y<<endl;
  queue<Node> q;
  q.push(Node(x,y));
  map[y][x]='.';
   while(!q.empty()){
    Node cur=q.front();q.pop();
    //    show();
     for(int i=0;i<4;i++){
      int nx=cur.x+dx[i];
      int ny=cur.y+dy[i];
      if(nx<0||nx>=w||ny<0||ny>=h||map[ny][nx]=='.'||map[ny][nx]!=c)continue;
      map[ny][nx]='.';
      q.push(Node(nx,ny));
    }
  }    
}
void solve(){
  cnt=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(map[i][j]!='.'){
	cnt++;
	bfs(j,i,map[i][j]);
      }
    }
  }
  cout<<cnt<<endl;
}
int main(){
  while(cin>>h>>w&&(w||h)){
    //    for(int i=0;i<h;i++)for(int j=0;j<w;j++)map[i][j]='.';
    for(int i=0;i<h;i++){
      cin>>map[i];
    }
    solve();
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main(){
  int S;
  cin >> S;
  //S -> h:m:s :貪欲法により実装
  const int H = 60 * 60;
  const int M = 60 ;
  int h = 0;
  int m = 0;

  while(S >= H){
      S -= H;
      h++;
      // cout<< "debug H S:" << S << endl;
  }
  while(S >= M){
    S -= M;
    m++;
    // cout<< "debug M S:" << S << endl;
  }

  cout << h << ':' << m << ':' << S<<endl;
  return 0;
}



Measured memory_bytes: 3096
#include <cstdio>
#include <algorithm>

int a[100001];

int main() {
  int r = 0;
  int i, n;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 0; i <= n; i++) r += abs(a[i] - a[i + 1]);
  for (i = 1; i <= n; i++) printf("%d\n", r - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]));
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000 + 7;
long long fac(long long n) {
    long long res = 1;
    for (long long i = 2; i <= n; i++) {
        res *= i;
        res %= mod;
    }
    return res;
}

long long binpow(long long k, long long n) {
    if(k == 0 || n == 1)
        return 1;
    if (k % 2) {
        return (n * binpow(k -1 , n)) % mod;
    } else {
        long long b = binpow(k / 2, n);
        return (b * b) % mod;
    }
}

void nextPermutation(vector<int>& a){ // n — длина перестановки
    int n = a.size();
    for (int i = n - 2; i >= 0; i--) {
        if (a[i] < a[i + 1]) {
            int mn = i + 1;
            for (int j = i + 1; j <= n - 1; j++)
                if (a[j] < a[mn] && a[j] > a[i])
                    mn = j;
            swap(a[i], a[mn]);
//            cout << i << " " << mn << endl;
            reverse(a.begin() + i + 1, a.end());
            return;
        }
    }
}

double sqr(double v) {
    return v * v;
}

int main() {
    int n, w;
    cin >> n >> w;
    w--;
    vector<int> a(n), b(n);
    int kk = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    int dp[n + 1][w + 1], dp1[n + 1][w + 1];
    for(int i = 0; i <= n; i++) {
        for (int j = 0; j <= w; j++) {
            dp1[i][j] = 0;
            dp[i][j] = 0;
        }
    }

    for (int k = 1; k <= n; k++) {
        for(int s = 1; s <= w; s++) {
            if(s >= a[k - 1]) {
                if (dp[k - 1][s] > dp[k - 1][s - a[k - 1]]+ b[k - 1]) {
                    dp1[k][s] = max(dp1[k - 1][s], b[k - 1]);
                } else if (dp[k - 1][s] == dp[k - 1][s - a[k - 1]]+ b[k - 1]) {
                    dp1[k][s] = max(dp1[k - 1][s], dp1[k - 1][s - a[k - 1]]);
                    dp1[k][s] = max(dp1[k][s], b[k - 1]);
                } else {
                    dp1[k][s] = max(dp1[k - 1][s], dp1[k - 1][s - a[k - 1]]);
                }
                dp[k][s] = max(dp[k - 1][s], dp[k - 1][s - a[k - 1]]+ b[k - 1]);
            } else {
                dp[k][s] = dp[k - 1][s];
                dp1[k][s] = max(b[k - 1], dp1[k - 1][s]);
            }
        }
    }
    int mx = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= w; j++) {
            mx = max(mx, dp[i][j] + dp1[i][j]);
        }
    }
    cout << mx;

    return 0;
}

Measured memory_bytes: 70656
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
                  log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


def inlist():
    return(list(map(int, input().split())))


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))


a, b = invr()
res = "No"
for i in range(a+1):

    if i*2 + (a-i)*4 == b:
        res = "Yes"
        break
print(res)


Measured memory_bytes: 10548
INF = 10 ** 10

s1,s2 = input(),input()
n,m = len(s1),len(s2)
dp = [[INF] * (m + 1) for i in range(n + 1)]
dp[0][0] = 0
for i in range(n + 1):
	for j in range(m + 1):
		if i >= 1:
			dp[i][j] = min(dp[i][j],dp[i - 1][j] + 1)
		if j >= 1:
			dp[i][j] = min(dp[i][j],dp[i][j - 1] + 1)
		if i >= 1 and j >= 1:
			dp[i][j] = min(dp[i][j],dp[i - 1][j - 1] + (s1[i - 1] != s2[j - 1]))
print(dp[n][m])


Measured memory_bytes: 43072
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		//n
		String[] temp = scanner.nextLine().split(" ");
		int n = Integer.parseInt(temp[0]);
		int m = Integer.parseInt(temp[1]);
		int x = Integer.parseInt(temp[2]);
		int y = Integer.parseInt(temp[3]);

		//list 差を求める
		String[] temp2 = scanner.nextLine().split(" ");
		String[] temp3 = scanner.nextLine().split(" ");
		int[] xlist = new int[n];
		int[] ylist = new int[m];

		xlist[n - 1] = Integer.parseInt(temp2[n - 1]);
		ylist[0] = Integer.parseInt(temp3[0]);

		for(int i = n - 1; i >= 0; i--) {
			xlist[n - 1] = Math.max(xlist[n - 1], Integer.parseInt(temp2[i]));

		}
		for(int i = 1; i < m; i++) {
			ylist[0] = Math.min(ylist[0], Integer.parseInt(temp3[i]));
		}

		if(x < ylist[0] && y > xlist[n - 1] && x <= y && xlist[n - 1] < ylist[0]) {
			System.out.println("No War");
		}else {
			System.out.println("War");
		}


	}
}


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

int main(){
    int N, Y;
    cin >> N >> Y;

    int res1 = -1, res2 = -1, res3 = -1;
    for (int a = 0; a <= N; a++){ // 10000 yen, 0 ~ N
        for (int b = 0; b + a <= N; b++){ // 5000 yen, 0 ~ N - a
            int c = N - a - b;
            int total = 10000 * a + 5000 * b + 1000 * c;
            if (total == Y){
                res1 = a;
                res2 = b;
                res3 = c;
            }
        }
    }

    cout << res1 << " " << res2 << " " << res3 << endl;
    return 0;
}

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

#define itn long long
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)(n);i>=0;--i)
#define debug(x) cout << #x << "=" << (x) << endl;
const ll MOD=1e9+7;

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end
int N;
vector<vector<int>> m;
vector<int> st;
void solve(){
  while(1){
    cin>>N;
    if(!N)return;
    st.assign(1<<N,1<<29);
    st[0]=0;
    m.assign(N,vector<int>(N+1));
    rep(i,N)
      rep(j,N+1)
        cin>>m[i][j];
    rep(i,1<<N){
      rep(j,N)
        if((1&i>>j)==0){
          int min=m[j][0];
          rep(k,N)
            if(1&(i>>k))
              chmin(min,m[j][k+1]);
          chmin(st[i|(1<<j)],st[i]+min);
        }
    }
    cout<<st[(1<<N)-1]<<endl;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  solve();
  return 0;
}


Measured memory_bytes: 3152
#include <stdio.h>

int main(){
  int data[100];
  int i,x,max=0;
  for (i=0;i<100;i++)
    data[i]=0;
  while (scanf("%d",&x)!=EOF){
    data[x-1]++;
  }
  for (i=0;i<100;i++){
    if (data[i]>max){
      max=data[i];
    }
  }
  for (i=0;i<100;i++){
    if (data[i]==max){
      printf("%d\n",i+1);
    }
  }

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int main()
{
    int x, y;
    cin >> x >> y;
    int leg = x * 2;
    for(int i = 0; i<=x;i++){
      if(leg + 2 * i == y) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  cout << "No" << endl;
}

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

vector<int> a(5);

int main(void){
	rep(i, 5) cin >> a[i];
	sort(a.begin(), a.end());
	int ans = INT_MAX;
	do{
		int t = 0;
		rep(i, 4) t+=((a[i]-1)/10+1)*10;
		ans = min(ans, t+a[4]);
	}while(next_permutation(a.begin(), a.end()));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3648
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    string s; cin>>s;
    int n = s.size();

    vector<int> l(n+1, 0);
    for(int i=0; i<n; i++){
        if(s[i] == '<') l[i+1] = l[i] + 1;
    }

    vector<int> r(n+1, 0);
    for(int i=n-1; i>=0; i--){
        if(s[i] == '>') r[i] = r[i+1] + 1;
    }

    vector<ll> ans(n+1);
    for(int i=0; i<=n; i++){
        ans[i] = max(l[i], r[i]);
    }

    cout << accumulate(ans.begin(), ans.end(), 0LL) << endl;

    return 0;
}

Measured memory_bytes: 8732
N=int(input())
a=list(map(int,input().split()))

def rewrite(n,l):
    cost=0
    for i in l:
        cost += (i-n)**2
    return cost

r1=rewrite(int(sum(a)/len(a)),a)
r2=rewrite(int(sum(a)/len(a))+1,a)

print(r1 if r1<r2 else r2)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
int main(void)
{
  char str[256];
  scanf("%s", str);
  if(strcmp(str,"Sunny")==0){printf("Cloudy");}
  if(strcmp(str,"Cloudy")==0){printf("Rainy");}
  if(strcmp(str,"Rainy")==0){printf("Sunny");}
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if((a==5 && b==5 && c==7) || (a==5 && b==7 && c==5) || (a==7 && b==5 && c==5)){
		printf("YES");
	}
	else {
		printf("NO");
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef long long ll;

using namespace std;

int main(int argc, const char * argv[]) {
  ll N;
  cin >> N;
  cout << N*(N-1)/2;
}


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

int arr[1000][3];
void solve(int n,int m){

	int ans=INT_MIN;
	for(int i=0;i<8;i++){
		bitset<3> bits(i);
		vector<int> temp;
		for(int j=0;j<n;j++){
			int val=0;
			for(int k=0;k<3;k++){
				if(bits[k]){
					val+=arr[j][k];
				}
				else
					val-=arr[j][k];
			}
			temp.push_back(val);
		}
		int res=0;
		sort(temp.begin(),temp.end());
		reverse(temp.begin(),temp.end());
		for(int k=0;k<m;k++){
			res+=(temp[k]);
		}
		// temp.clear();
		ans=max(ans,res);
	}

	cout<<ans<<endl;
}

int32_t main(){
	
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>arr[i][j];
		}
	}

	solve(n,m);
}




Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n, q;
  cin >> n;
  vector<ll> a;
  for(ll i = 0; i < n; i++){
    ll in;
    cin >> in;
    a.push_back(in);
  }
  cin >> q;
  ll ans = 0;
  for(ll i = 0; i < q; i++){
    ll in;
    cin >> in;
    ans += min(1l,upper_bound(a.begin(), a.end(), in) - lower_bound(a.begin(), a.end(), in));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vi a(m);
  int memo = -1;
  for (int i = 0; i < m; i++) {
    cin >> a.at(i);
    if (memo == -1 && a.at(i) >= x) memo = i;
  }
  if (a.at(memo) == x) {
    cout << min(m - memo - 1, memo) << endl;
  }
  else cout << min(m - memo, memo) << endl;
}

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

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String[] input = br.readLine().split(" ");
        int a = Integer.parseInt(input[0]);
        int b = Integer.parseInt(input[1]);
        int c = Integer.parseInt(input[2]);
        int d = Integer.parseInt(input[3]);
        
        int ans = Math.max(0, Math.min(b, d) - Math.max(a, c));
        
        out.println(ans);
        out.close();
        
    }
}

Measured memory_bytes: 32760
//Om Sree Sai Ram
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
vector<int> dp;



int main() 
{
  
 // cout<<" Hello world"<<endl;   
  int n,k;
  cin>>n>>k;
  int ar[n];
  for(int i=0;i<n;i++)
  {
    cin>>ar[i];
  }
  dp.assign(n,INT_MAX);
  dp[0] = 0;
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<=i+k;j++)
    {
      if(j<n)
      {
        dp[j] = min(dp[j],abs(ar[j]-ar[i])+dp[i]);
      }
    }
  }
  cout<<dp[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
def reconstruct(pre_list, in_list):
    if len(pre_list) <= 1:
        return pre_list
    now = pre_list[0]
    split_place = in_list.index(now)
    pre_left = pre_list[1:split_place + 1]
    in_left = in_list[0:split_place]
    pre_right = pre_list[split_place + 1:]
    in_right = in_list[split_place + 1:]
    return reconstruct(pre_left, in_left) + reconstruct(pre_right, in_right) + [now]

def print_list_split_whitespace(a):
    for x in a[:-1]:
        print(x, end=" ")
    print(a[-1])


n = int(input())
pre_list = [int(x) for x in input().split()]
in_list = [int(x) for x in input().split()]

post_list = reconstruct(pre_list, in_list)
print_list_split_whitespace(post_list)


Measured memory_bytes: 5604
#pragma GCC optimze("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
const ll inf=1e18;
inline ll mult(ll x,ll y){x%=hell;y%=hell;return (1LL*x*y)%hell;}
inline ll add(ll x,ll y){x+=y;return x%hell;}
inline ll powMod(ll base,ll expo){
	if(base==0)return 0;
	ll ans=1;
	while(expo){
		if(expo&1)ans=mult(ans,base);
		base=mult(base,base); 
		expo>>=1;
	}
	return ans;
}
vector<ll> pre,dp;
void rec(ll idx,vector<ll>& not_taken,ll mask,ll group_mask){
	if(idx==sz(not_taken)){
		dp[mask^group_mask]=max(dp[mask^group_mask],dp[mask]+pre[group_mask]);
		return;
	}
	rec(idx+1,not_taken,mask,group_mask);
	rec(idx+1,not_taken,mask,group_mask^(1LL<<not_taken[idx]));
}
void solve(){
	ll n;
	cin>>n;
	vector<vector<ll> > a(n,vector<ll>(n));
	rep(i,0,n)
		rep(j,0,n)
			cin>>a[i][j];
	pre.resize(1<<n);
	rep(mask,0,1LL<<n){
		rep(i,0,n){
			if((mask>>i)&1){
				rep(j,i+1,n){
					if((mask>>j)&1)pre[mask]+=a[i][j];
				}
			}
		}
	}
	dp.resize(1<<n,-inf);
	dp[0]=0;
	rep(mask,0,1LL<<n){
		vector<ll> not_taken;
		rep(i,0,n)
			if(!((mask>>i)&1))
				not_taken.pb(i);
        rec(0,not_taken,mask,0);
	}
	cout<<dp[(1<<n)-1];
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	//cin>>t;
   	tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> p(n);
  for(int i=0;i<n;i++)cin>>p[i];
  int ans=0;
  for(int i=1;i<n-1;i++){
    if((p[i - 1] < p[i]) && (p[i] < p[i + 1])) ans++;
	else if((p[i - 1] > p[i]) && (p[i] > p[i + 1])) ans++;
  }
  cout<<ans<<endl;
}


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

using namespace std;

int main(){
	int w, q, wall[100], id, cat;
	string op;
	cin >> w >> q;
	while (w){
		for (int i = 0; i < w; i++){
			wall[i] = -1;
		}
		for (int i = 0; i < q; i++){
			cin >> op >> id;
			if (op == "s"){
				cin >> cat;
				int possible = 0, idx;
				for (idx = 0; idx <= w - cat; idx++){
					if (wall[idx] == -1){
						possible = 1;
						for (int j = 0; j < cat; j++){
							if (wall[idx + j] != -1){
								possible = 0;
								break;
							}
						}
						if (possible){
							cout << idx << endl;
							for (int i = 0; i < cat; i++){
								wall[idx + i] = id;
							}
							break;
						}
					}
				}
				if (!possible){
					cout << "impossible" << endl;
				}
			}
			else if (op == "w"){
				for (int i = 0; i < w; i++){
					if (wall[i] == id){
						for (int j = i; wall[j] == id; j++){
							wall[j] = -1;
						}
						break;
					}
				}
			}
		}
		cout << "END" << endl;
		cin >> w >> q;
	}
	return 0;
}

Measured memory_bytes: 1208
h, w = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(10)]
a = [list(map(int, input().split())) for _ in range(h)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k]+c[k][j])

ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == -1:
            continue
        else:
            ans += c[a[i][j]][1]
print(ans)


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

int count(int n){
  return n==0?0:(n&1)+count(n>>1);
}

int main(){
  int N,M;
  cin >> N >> M;
  unsigned int f=0;
  unsigned int ans=pow(2,M)-1;
  int A;
  int K;
  for (int i=0;i<N;i++){
    cin >> K;
    f=0;
    for (int j=0;j<K;j++){
      cin >> A;
      f|=(1<<(A-1));
    }
    ans=ans&f;
  }
  cout << count(ans) <<endl; 
  return 0;
}


Measured memory_bytes: 256
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int n;
    cin >> n;
    vector<int> t(n+1),x(n+1),y(n+1);

    for (int i = 1; i < n+1; i++){
        cin >> t[i] >> x[i] >> y[i];
    }
    bool flag = true;
    for (int i = 1; i < n+1; i++){
        ll t_sub = t[i] - t[i-1];
        ll x_sub = abs(x[i] - x[i-1]);
        ll y_sub = abs(y[i] - y[i-1]);
        if (t_sub < x_sub + y_sub){
            flag = false;
            break;
        } else if (t_sub % 2 == 1){
            if ((x_sub + y_sub) % 2 == 0){
                flag = false;
                break;
            }
        } else if (t_sub % 2 == 0){
            if ((x_sub + y_sub) % 2 == 1){
                flag = false;
                break;
            }
        }
    }
    if (flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
struct edge { ll from,to, cost; };
edge G[2001];
int main() {
	int n, m;ll a, b, c;
	cin >> n >> m;
	int i,j;
	for (i = 0; i < m; i++) {
		cin >> a >> b >> c;
		a--; b--;
		G[i]={a,b,c };
	}
	ll d[1000];
	for (i = 0; i < 1000; i++) {
		d[i] = -INF;
	}
	d[0] = 0;
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			if (d[G[j].from] != -INF) {
				d[G[j].to] = max(d[G[j].to], d[G[j].from] + G[j].cost);
			}
		}
	}
	ll memo = d[n-1];
	for (i = 0; i < m; i++) {
		if (d[G[i].from] != -INF) {
			d[G[i].to] = max(d[G[i].to], d[G[i].from] + G[i].cost);
		}
	}
	if (memo != d[n - 1]) {
		cout << "inf" << endl;
	}
	else {
		cout << d[n - 1] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int a[4];
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    sort(a,a+4);
    if(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)cout << "YES";
    else cout << "NO";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) (a).begin(), (a).end()
#define pw(x) (1ll<<(x))
#define lb(x) ((x) & -(x))
#define endl "\n"
#define FI(x) freopen(#x".in","r",stdin)
#define FO(x) freopen(#x".out","w",stdout)
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
//typedef uniform_int_distribution<ll> RR;
const int P = 1e9 + 7;
//ll rnd(ll l, ll r) { mt19937 gen(rand()); RR dis(l, r); return dis(gen); }
int add(int a, int b) {if((a += b) >= P) a -= P; return a < 0 ? a + P : a;}
int mul(int a, int b) {return 1ll * a * b % P;}
int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----

const int N = 1e5 + 7;
int n, t, now, a[N];

int main() {
	//FI(a);
	ios::sync_with_stdio(0);
	cin.tie(0);
	//cout << setiosflags(ios::fixed);
	//cout << setprecision(2);
	cin >> n; 
	rep(i, 1, n+1) cin >> a[i];
	sort(a+1, a+n+1);
	per(i, 1, n+1) {
		if (a[i-1] <= now + 1) break;
		now++;
	}
	int ok2 = 0;
	per(i, 1, n - now + 1) if (a[i] <= now) break; else ok2 ^= 1;
	int ok1 = (a[n - now] - now) & 1;
	
	if (ok1 && ok2) cout << "Second";else cout << "First";	
	return 0;
}



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

using namespace std;

const int md = (int) 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, c;
  cin >> n >> c;
  vector<vector<int>> f(n + 1, vector<int>(c + 1));
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  f[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = a[i]; j <= b[i]; j++) {
      int p = 0;
      for (int k = 0; k <= c; k++) {
        p = (p * 1LL * j + f[i][k]) % md;
        f[i + 1][k] = (f[i + 1][k] + p) % md;
      }
    }
  }
  cout << f[n][c] << '\n';
  return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define HASH_SIZE 65536

struct list {
    int num;
    int cnt;
    struct list *next;
};

struct list *create_htable(void) {
    static struct list htable[HASH_SIZE];
    int i;
    for(i = 0; i < HASH_SIZE; i++) {
        htable[i].next = &htable[i];
    }
    return htable;
}

int get_key(int num) {
    return num & (HASH_SIZE-1);
}

struct list* find(struct list *htable, int num) {
    struct list *head = &htable[get_key(num)];
    struct list *elem;
    for(elem = head->next; elem != head; elem = elem->next) {
        if(elem->num == num) {
            return elem;
        }
    }
    return NULL;
}

int find_cnt(struct list *htable, int num) {
    struct list *elem = find(htable, num);
    if(!elem) return 0;
    return elem->cnt;
}

void add_elem(struct list *htable, int num) {
    struct list *elem = find(htable, num);
    if(elem) {
        elem->cnt++;
    } else {
        elem = malloc(sizeof(struct list));
        struct list *head = &htable[get_key(num)];
        elem->next = head->next;
        elem->num = num;
        elem->cnt = 1;
        head->next = elem;
    }
}

void put_elem(struct list *htable, int num) {
    struct list *elem = find(htable, num);
    if(elem) elem->cnt--;
}

#define NUM_MAX 100000

int main(void) {
    int num, multis;
    static int arr[NUM_MAX];
    get_int2(&num, &multis);
    fget_array(arr, num);
    int i;
    for(i = 0; i < num; i++) arr[i] = (arr[i]%multis);

    struct list *htable = create_htable();
    int sum = 0;
    for(i = 0; i < num; i++) {
        sum = (sum + arr[i])%multis;
        add_elem(htable, sum);
    }

    // remove
    int offset = 0;
    int64_t ans = find_cnt(htable, offset);

    sum = 0;
    for(i = 0; i < num-1; i++) {
        sum = (sum + arr[i])%multis;
        put_elem(htable, sum);
        ans += find_cnt(htable, sum);
    }

    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3584
n,*l=map(int,open(0).read().split())
a=b=c=0;f=1;l+=[0,1]
while f:
	while l[a]<=l[a+1]:a+=1
	while l[b]>=l[b+1]:b+=1
	a=b=max(a,b)+1
	c+=1;f=a<n
print(c)

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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
// #define INF 1e9
const ll INF = 1LL << 60;

struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    REP(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

struct Edge{
  int a, b;
  double cost;
  Edge(int a = 0, int b= 0, double cost = 0){
    this->a = a;
    this->b = b;
    this->cost = cost;
  }
  bool operator<(const Edge& o) const{
    return cost < o.cost;
  }
};

struct Point{
  double x, y, z;
  Point(double x = 0, double y = 0, double z=0){
    this->x = x;
    this->y = y;
    this->z = z;
  }
};
double square(double a){
  return a * a;
}
double calcDist(Point a, Point b){
  return sqrt(square(a.x-b.x)+square(a.y-b.y)+square(a.z-b.z));
}

bool isCoverd(Point a, double ar, Point b, double br){
  return calcDist(a, b) <= ar+br;
}
int main(){
  while(true){
    int n;
    cin >> n;
    if(n==0) break;
    vector<double> x(n), y(n), z(n), r(n);
    vector<Point> pt(n);
    REP(i, n){
      cin >> x[i] >> y[i] >> z[i] >> r[i];
      pt[i] = Point(x[i], y[i], z[i]);
    }
    
    UnionFind uf(n);
    vector<Edge> edges;
    REP(i, n){
      FOR(j, i+1, n){
        if(isCoverd(pt[i], r[i], pt[j], r[j])){
          // cout << "i:" << i << " j:" << j << " isCoverd" << endl;
          uf.unite(i, j);
        }
        else{
          // cout << "i:" << i << " j:" << j << " isNotCovered" << endl;
          edges.push_back(Edge(i, j, calcDist(pt[i], pt[j])-r[i]-r[j]));
        }
      }
    }
    sort(edges.begin(), edges.end());
    // for(auto e: edges){
    //   cout << "a:" << e.a << " b:" << e.b << " cost:" << e.cost << endl;
    // }
    // cout << "--------------------------------------" << endl;
    double ans = 0;
    for(auto e : edges){
      if(!uf.same(e.a, e.b)){
        ans += e.cost;
        uf.unite(e.a, e.b);
        // cout << "a:" << e.a << " b:" << e.b << " cost:" << e.cost << endl;
      }
    }
    printf("%.3f\n", ans);
  }
  return 0;
}




Measured memory_bytes: 3304
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    cout << 180*(N - 2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);

signed main(){
    int a,b,c,d,e,f,cap;cin>>a>>b>>c>>d>>e>>f;
    double water,sugar,am=1,as=-1;//初期値as=0だと0%でバグる
    double ans=0;

    cap=0;water=0;sugar=0;

    for(int i=0;cap+i*a*100<f+1;i++)
    {
        cap+=i*a*100;
        water+=100*a*i;

        for(int j=0;cap+j*b*100<f+1;j++)
        {
            cap+=j*b*100;
            water+=100*b*j;

            double capp=cap,suga=sugar;

            for(int k=0;cap+c*k<f+1;k++)
            {           
                cap+=c*k;
                sugar+=c*k;
                
                while(cap+d<f+1 && e*water>=100*(sugar+d))
                {
                    cap+=d;
                    sugar+=d;
                    
                }

                if(as*cap<sugar*am && e*water>=100*sugar){
                    am=cap;
                    as=sugar;
                }
                
                cap=capp;
                sugar=suga;
            }
            cap-=j*b*100;
            water-=100*b*j;
        }
        cap-=i*a*100;
        water-=100*a*i;
    }
    cout<<(int)am<<" "<<(int)as<<endl;
}

Measured memory_bytes: 256
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    let mut xs = vec![];
    for i in 1..n+1 {
    	let a = get!()-i;
        xs.push(a);
    }
    xs.sort();
    let b = xs[n as usize / 2];
    let mut ans = std::i64::MAX;
    let mut tmp = 0;
    for &x in xs.iter() {
    	tmp += (x - b).abs();
	}
    if tmp < ans {
    	ans = tmp;
	}
    if n > 1 {
	    let b = xs[(n as usize + 1) / 2];
    	let mut tmp = 0;
    	for &x in xs.iter() {
    		tmp += (x - b).abs();
		}
    	if tmp < ans {
    		ans = tmp;
		}
	}
    println!("{}", ans);
}

Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<string,ll> P;
map<P,ll> M;
map<string,ll> upper;
string s;
int p,flg;
ll program();

string getName(){
  string res;
  while(s[p]!='[')res+=s[p++];
  return res;
}

ll getNum(){
  ll res=0;
  while(isdigit(s[p]))res=res*10+s[p++]-'0';  
  return res;
}

ll getIdx(){
  ll res=0;
  if(isdigit(s[p])) res=getNum(),p++;
  else res=program(),p++;
  return res;  
}

ll program(){
  if(isdigit(s[p]))return getNum();
  string name=getName();p++;
  int idx=getIdx();
  if(!M.count(P(name,idx))) flg=0;
  return M[P(name,idx)];
}

void start(){
  flg=1;
  p=0;
  string name=getName();p++;
  ll idx=getIdx();
  ll cnt = upper.count(name);
  if((cnt&&idx>upper[name])||(!cnt&&p!=s.size()))flg=0;
  if(!cnt)upper[name] = idx-1;
  if(p==s.size()) return;
  p++;
  ll res=program();
  M[P(name,idx)]=res;
}

int main(){
  while(1){
    int ans=0;
    M.clear();
    upper.clear();
    for(int i=1;;i++){
      cin>>s;
      if(i==1&&s==".")return 0;
      if(s==".")break;
      if(ans)continue;
      start();
      if(!flg)ans=i;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3164
# -*- coding: utf-8 -*-
import sys
from collections import deque
import copy

N,M,Q=map(int, sys.stdin.readline().split())
X=[ map(int, sys.stdin.readline().split()) for _ in range(Q) ]

qq=deque()
for m in range(1,M+1):
    q=deque()
    q.append([m])
    while q:
        if N<len(q[0]):
            qq+=q
            break
        fro=q.popleft()
        last=fro[-1]
        for to in range(last,M+1):
            q.append(fro+[to])

ans=float("-inf")
for L in qq:
    temp_ans=0
    for a,b,c,d in X:
        if L[b-1]-L[a-1]==c:
            temp_ans+=d
    ans=max(ans,temp_ans)
print ans


Measured memory_bytes: 135828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
ll power(ll x,ll y,ll p) 
{ 
    ll res=1;  
    x=x%p;
    while (y > 0) 
    { 
        if(y&1) 
            res=(res*x)%p; 
        y=y>>1;
        x=(x*x)%p;   
    } 
    return res; 
}
ll arr[30][30], n;
const ll L = 3e6 + 5;
ll dp[30][L];
ll rec(ll p, ll m)
{
    ll i;
    if(dp[p][m] != -1)
        return dp[p][m];
    if(p == 1)
    {
        for(i=0;i<n;i++)
        {
            if(!(m&(1<<i)))
                if(arr[p-1][i] == 1)
                    return 1;
                else
                    return 0;
        }
    }
    ll ans = 0;
    for(i=0;i<n;i++)
    {
        if(arr[p-1][i] == 1 && !(m&(1<<i)))
            ans += rec(p-1, m|1<<i) % mod;            
    }
    return dp[p][m] = ans % mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll i,j;
    cin >> n;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            cin >> arr[i][j];
    ll M = 1<<n;
    for(i=0;i<=n;i++)
        for(j=0;j<=M;j++)
            dp[i][j] = -1;
    cout << rec(n, 0) << endl;
    return 0;
}

Measured memory_bytes: 405760
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

string x;
char card;

int main(){
    stack<char> a;
    stack<char> b;
    stack<char> c;

    cin >> x;
    for(int j = x.length()-1; j > -1 ; j--){
        a.push(x[j]);
    }
    cin >> x;
    for(int j = x.length()-1; j > -1 ; j--){
        b.push(x[j]);
    }
    cin >> x;
    for(int j = x.length()-1; j > -1 ; j--){
        c.push(x[j]);
    }
    // cout << a.size() << " " << b.size()  << " " << c.size() << endl;

    card = a.top();
    a.pop();

    // cout << card;

    // cout << a.size() << " " << b.size()  << " " << c.size() << endl;

    while(true){
        // cout << a.size() << " " << b.size()  << " " << c.size() << endl;
        if(card == 'a'){
            if(a.size() == 0){
                cout << 'A';
                break;
            } else{
                card = a.top();
                a.pop();
            }
        } else if(card == 'b'){
            if(b.size() == 0){
                cout << 'B';
                break;
            } else{
                card = b.top();
                b.pop();
            }
        } else{ //card = 'c'
            if(c.size() == 0){
                cout << 'C';
                break;
            } else{
                card = c.top();
                c.pop();
            }
        }
    }



    // if(a.size() == 0){
    //     cout << 'A';
    // } else if(b.size() == 0){
    //     cout << 'B';
    // } else{
    //     cout << 'C';
    // }



}



Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include<cstdio>
#include <vector>
#include<queue>
#include<limits.h>
#include<string.h>
#include<functional>
using namespace std;

signed main() {
	int a, b, c; cin >> a >> b >> c;
	if (a < b&&b < c)puts("Yes");
	else puts("No");
}

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

int main()
{
	int a[4][3][10] = {0}, b[100000][4], i, I, n, x;
	scanf("%d", &n);
	for(i = 0 ; i < n ; i++)
	{
		scanf("%d%d%d%d", &b[i][0], &b[i][1], &b[i][2], &b[i][3]);
	}
	for(i = 0 ; i < n ; i++)
	{
		a[b[i][0]-1][b[i][1]-1][b[i][2]-1] += b[i][3];
	}
	for(i = 0 ; i < 4 ; i++)
	{
		for(I = 0 ; I < 3 ; I++)
		{
			for(x = 0 ; x < 10 ; x++)
			{
				printf(" %d", a[i][I][x]);
			}
			printf("\n");
		}
		if(i != 3)
		{
			printf("####################\n");
		}
	}
	return 0;
}



Measured memory_bytes: 2140
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for(int i=0; i<n; i++){
			int a = in.nextInt();
			int b = in.nextInt();
			int c = in.nextInt();
			if(a*a+b*b==c*c || b*b+c*c==a*a || c*c+a*a==b*b) System.out.println("YES");
			else System.out.println("NO");
		}
	}
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define MOD 1e9+7
#define sp ' '


using ll = long long;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n){
        cin >> h[i];
    }

    int ans = 0;
    int prev = 0;
    for(int i = 0; i < n; ++i){
        if(prev < h[i]) ans += h[i]-prev;
        prev = h[i];
    }
    ppp(ans);


    return 0;
}


Measured memory_bytes: 256
from bisect import bisect
n, m, k = map(int, input().split())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))

list_AS = []
list_BS = []
a = 0
b = 0
list_AS.append(0)
for i in list_A:
    a += i
    list_AS.append(a)
list_BS.append(0)
for i in list_B:
    b += i
    list_BS.append(b)
ans = 0
for i in range(n+1):
    j = bisect(list_BS, k-list_AS[i])
    if list_AS[i] + list_BS[j-1] <= k:
        ans = max(ans, i+j-1)

print(ans)

Measured memory_bytes: 49176
Scanf.scanf "%d %d" (fun n l ->
    let s = Array.init n (fun _ -> Scanf.scanf " %s" (fun s -> s)) in
    Array.sort compare s;

    let rec loop i acc =
        if i = n then acc else loop (i + 1) (acc ^ s.(i))
    in
    loop 0 "" |> print_endline
)

Measured memory_bytes: 4252
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i = (begin); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
using ll = long long;
using namespace std;
#define all(x) (x).begin(),(x).end()
using pii = pair<int, int>; using vi = vector<int>; using vl = vector<ll>;

signed main() {
    int x, y, z;
    cin >> x >> y >>z;
    cout << z <<' '<< x<<' '<< y;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  int a,b; cin >> a >> b;
  for(int i=1;i<1.0e+4;i++){
    if(((int)(i*0.08)==a)&&((int)(i*0.10)==b)){
      cout << i << endl;
      return 0;
    }
  }
  puts("-1");
}


Measured memory_bytes: 256