akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		
		while(true){
			var d=int.Parse(Console.ReadLine());
			if(d==0)break;
			Sol mySol=new Sol(d);
			Console.WriteLine(mySol.Ans);
		}
	}
}

class student{
	int height;
	bool left;
	bool right;
	public int Height{
		get{return height;}
		set{this.height=value;}
	}
	public bool Left{
		get{return left;}
		set{this.left=value;}
	}
	public bool Right{
		get{return right;}
		set{this.right=value;}
	}
	public student(int d){
		height=d;
		left=false;
		right=false;
	}
}

class Sol{
	int ans;
	public int Ans{
		get{return ans;}
		set{this.ans=value;}
	}
	public Sol(int d){
		student[][] Students=new student[d][];
		for(int i=0;i<d;i++){
			var s=Console.ReadLine();
			var ss=s.Split(' ');
			Students[i]=Array.ConvertAll(ss,elem=>new student(int.Parse(elem)));
		}
		for(int i=0;i<d;i++){
			int h=Students[i][0].Height;
			for(int j=0;j<d;j++){
				if(h>=Students[i][j].Height)h=Students[i][j].Height;
			}
			for(int j=0;j<d;j++){
				if(h==Students[i][j].Height)Students[i][j].Left=true;
			}
		}
		for(int j=0;j<d;j++){
			int h=Students[0][j].Height;
			for(int i=0;i<d;i++){
				if(h<=Students[i][j].Height)h=Students[i][j].Height;
			}
			for(int i=0;i<d;i++){
				if(h==Students[i][j].Height)Students[i][j].Right=true;
			}
		}
		ans=0;
		for(int i=0;i<d;i++){
			for(int j=0;j<d;j++){
				if(Students[i][j].Left&&Students[i][j].Right)ans=Students[i][j].Height;
			}
		}
	}
}

Measured memory_bytes: 5740
#include <stdio.h>
int cnt;
void ksubset(int n,int k,int i,int ans,int s){
  if (k==0){
    if (ans==s)
      cnt++;
    return ;
  }
  if (n==0){
    return ;
  }
  ksubset(n-1,k-1,i+1,ans+i,s);
  ksubset(n-1,k,i+1,ans,s);
}

int main(){
  int n,s;
  while (scanf("%d %d",&n,&s)){
    if ((n==0) && (s==0))
      break;
    cnt=0;
    ksubset(10,n,0,0,s);
    printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn=1e5+600;

ll zaa[maxn];
ll zbb[maxn];
ll zab[maxn];
ll zba[maxn];
ll bagh(ll a)
{
      if (a>0)
      {
            return a%3;
      }
      else
      {
         return (-1*(abs(a)%3)+3)%3;
      }
}
int main()
{
    string a,b;
    cin>>a>>b;
    for (ll i=0; i<a.size(); i++)
    {
        zab[i+1]=zab[i];
        if (a[i]!='A')
        {
            zab[i+1]++;
        }
        zaa[i+1]=zaa[i];
        if (a[i]=='A')
        {
            zaa[i+1]++;
        }
    }
    for (ll i=0; i<b.size(); i++)
    {
        zbb[i+1]=zbb[i];
        if (b[i]!='A')
        {
            zbb[i+1]++;
        }
        zba[i+1]=zba[i];
        if (b[i]=='A')
        {
            zba[i+1]++;
        }
    }
    ll q,s,t,ss,tt;



    cin>>q;
    for (ll i=0; i<q; i++)
    {
        cin>>s>>t>>ss>>tt;
        if (bagh(zaa[t]-zaa[s-1]-(zab[t]-zab[s-1]))==bagh(zba[tt]-zba[ss-1]-(zbb[tt]-zbb[ss-1])))
        {
              cout<<"YES\n";
        }
        else
        {
              cout<<"NO\n";
        }
    }
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))
 
typedef long long ll;
 
const int INF = 1000000000;
const int MOD = 1000000007;
 
string str[4] = {"dream", "dreamer", "erase", "eraser"};
 
int main () {
	string s; cin >> s;
    reverse(all(s));
    rep(i, 4) reverse(all(str[i]));
 
    while (s.size() != 0) {
        bool flg = false;
        rep(i, 4) {
            string sub = s.substr(0, str[i].size());
            if (sub == str[i]) {
                s = s.substr(str[i].size());
                flg = true;
            }
        }
        if (!flg) {cout << "NO" << endl; return 0;}
    }
    cout << "YES" << endl;
}

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

int nankai(long long int p){
  int w=0;
  for(int i=0;p%2==0;i++){
    p/=2;
    w++;
  }
  return w;
}

int main(){
  int N;
  cin >>N;
  long long int ans = 0;
  for(int i=0;i<N;i++){
    long long int a;
    cin >>a;
    ans += nankai(a);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
an = [int(x) for x in input().split()]

dp_0 = an[0]
dp_1 = -an[0]

for i in range(1,n):
  dp_0, dp_1 = [max(dp_0 + an[i], dp_1 - an[i]), max(dp_0 - an[i], dp_1 + an[i])]

print(dp_0)


Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,maxv=-1,s=0;
cin>>n;
int a[n+1];
for(int i=1;i<=n;i++){
	cin>>a[i];
	if(a[i]>=maxv){
		maxv=a[i];
		s++;
	}
} 
cout<<s;
}


Measured memory_bytes: 256
#include<atcoder/segtree>
#include<iostream>
#include<algorithm>
#include<vector>

int op(int a, int b) {
  return std::max(a, b);
}
int e() {
  return -1;
}
int main() {
  int N, K;
  std::cin >> N >> K;
  std::vector<int> dp(300001);
  atcoder::segtree<int, op, e> seg(dp);
  for (int i = 0; i < N; i++) {
    int a;
    std::cin >> a;
    seg.set(a, seg.prod(std::max(0, a - K), std::min(300001, a + K + 1)) + 1);
  }
  
  std::cout << seg.all_prod() << std::endl;
  
}
  

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

int main(){

    int n, m;
    cin >> n >> m;
    vector<bool> problem(n,false);
    vector<int> penalty(n,0);
    int AC=0,WA=0;

    int p;
    string s;
    for(int i=0; i<m; i++){
        cin >> p >> s;
        if(!problem.at(p-1)){
            if(s=="AC"){
                problem.at(p-1)=true;
                AC++;
            }
            if(s=="WA"){
                penalty.at(p-1)++;
            }
        }
        //cout << AC << ' ' << WA << endl;
    }
    for(int i=0; i<n; i++){
        if(problem.at(i)) WA+=penalty.at(i);
    }

    cout << AC << ' ' << WA << endl;
}

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


int main(){

    long long int a,b,c,d;
    cin >> a>> b>> c>> d;


    vector<long long int> v;
    v.push_back(a*c);
    v.push_back(a*d);
    v.push_back(b*c);
    v.push_back(b*d);
    sort(v.begin(), v.end());

    cout<<v[3]<<endl;
}


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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;

#define N 100010
#define M 200010
#define endl "\n"
#define mod 1000000007 

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	ll a, b, c, k;
	
	cin >> a >> b >> c >> k;
	
	if(k <= a){
		cout << k << endl; 
	}
	else{
		
		a = min(a, k);
		
		k -= a;
		k -= b;
		
		if(k < 0) k = 0;
		ll ans = a - k;
		
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!





void solve(){
    int n,k;
    cin>>n>>k;
    
    vi ht(n);
    for(int i=0;i<n;i++){cin>>ht[i];}
    sort(all(ht));
    
    int i=0,j=k-1;
    int ans=ht[j]-ht[i];
    while(j<n){
        ans=min(ht[j++]-ht[i++],ans);
    }
    cout<<ans<<endl;
}





int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define debug(a) cout << #a ": " << a << endl
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
const double eps = 1e-6;
ll n, k, a[N];
bool judge(ll mid){
    ll cnt = 0;
    for (int i = 1; i <= n; ++i){
        cnt += (a[i]-1)/mid;
        if (cnt > k) return false;
    }
    return true;
}
int main(void){
    IOS;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    ll l = 1, r = 1000000000, ans = 0;
    while (l <= r){
        ll mid = (l+r) >> 1;
        if (judge(mid)){
            ans = mid;
            r = mid-1;
        }else{
            l = mid+1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5120
s = input()
n = len(s)

ans = [1]*n
for i,a in enumerate(s):
    if a =="R":
        a2 = s[i+1]
        if a2 =="R":
            ans[i+2] += ans[i]
            ans[i] = 0

for i in range(n-1,-1,-1):
    a = s[i]
    if a =="L":
        a2 = s[i-1]
        if a2 =="L":
            ans[i-2] += ans[i]
            ans[i] = 0
print(*ans)

Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  string s;
  cin >> s;
  int q;
  cin >> q;
  int rev=0;
  string pre;
  string next;
  rep(i, q){
    int t;
    cin >> t;
    if(t==1){
      rev++;
    } else {
      int f;
      string c;
      cin >> f >> c;
      if((f==1 && rev%2==0) ||(f==2 && rev%2==1)){
        pre=c+pre;
      } else {
        next=next+c;
      }
    }
  }
  s=pre+s+next;
  if(rev%2==1){
    reverse(s.begin(), s.end());
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 4568
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string sp=" ";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;
    string st[3];
    while(cin>>st[0]>>st[1]>>st[2])
    {
        i=j=k=p=0;
        char ch='A';
        while(1)
        {
            if(p==0)
            {
                if(i>=st[p].sz) break;
                p=st[p].at(i)-'a';
                i++;
            }
            if(p==1)
            {
                if(j>=st[p].sz) break;
                p=st[p].at(j)-'a';
                j++;
            }
            if(p==2)
            {
                if(k>=st[p].sz)break;
                p=st[p].at(k)-'a';
                k++;
            }
        }
        ch+=p;
        cout<<ch<<en;
    }
}





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

int main() {
	int i, j, n, m;
	char be, af, tmp;

	while (1) {
		cin >> n;
		if (n == 0)break;
		char cvrt[128] = {};
		for (i = 0; i < n; i++) {
			cin >> be >> af;
			cvrt[be] = af;
		}
		cin >> m;
		for (i = 0; i < m; i++) {
			cin >> tmp;
			if (cvrt[tmp] == 0) {
				cout << tmp;
			} else {
				cout << cvrt[tmp];
			}
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

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

	Scanner std = new Scanner(System.in);


	//List<Integer> list = new ArrayList<>();
	int W = std.nextInt();
	int H = std.nextInt();
	int x = std.nextInt();
	int y = std.nextInt();

	//四角形の中心の場合 1
	double full = (double)W*(double)H;
    double half = (double)full/2;
	System.out.println(half);

	double halfx = (double)W/2;
	double halfy = (double)H/2;




	if((double)x == halfx && (double)y == halfy) {
		System.out.println('1');
	}
	else {
	System.out.println('0');
	}

	}


	}




Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,k;
    cin>>n>>k;
    vector<int> p(n,0);
    rep(i,k){
        int d;
        cin>>d;
        rep(j,d){
            int a;
            cin>>a;
            p[a-1]++;
        }
    }
    int ans=0;
    rep(i,n){
        if(p[i]==0) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100010;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int main(){
    ll n; cin >> n;

    vector<ll> plus;
    vector<ll> minus;

    rep(i, n){
        ll a; cin >> a;
        if(a >= 0) plus.push_back(a);
        else minus.push_back(a);
    }
    
    sort(plus.begin(), plus.end(), greater<>());
    sort(minus.begin(), minus.end());

    if(plus.size() == n){
        minus.push_back(plus.back());
        plus.pop_back();
    }else if(minus.size() == n){
        plus.push_back(minus.back());
        minus.pop_back();
    }
    ll cur = minus[0];
    vector<P> ans;
    for(int i = 0; i < plus.size() - 1; ++i){
        ans.push_back({cur, plus[i]});
        cur -= plus[i];
    }
    ans.push_back({plus[plus.size() - 1], cur});
    cur = plus[plus.size() - 1] - cur;

    for(int i = 1; i < minus.size(); ++i){
        ans.push_back({cur, minus[i]});
        cur -= minus[i];
    }

    cout << cur << endl;
    for(auto it : ans) cout << it.first << " " << it.second << endl;
    return 0;    
}

Measured memory_bytes: 4340
#include <iostream>
#include <sstream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  ll N;
  string S;
  cin>>N>>S;
  vector<ll> num_kuro(N);//順方向
  vector<ll> num_siro(N);
  ll numk=0,nums=0;
  FORi(N){
    if(S[i]=='#')numk++;
    num_kuro[i]=numk;
    if(S[i]=='.')nums++;
    num_siro[i]=nums;
  }
  ll m=nums;
  FORi(N){
    ll tmp=num_kuro[i]+(nums-num_siro[i]);
    if(m>tmp)m=tmp;
  }
  cout<<m<<endl;
  return 0;
}


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

public class Main {

	public static void printArray(int[] intArray){
		for (int i = 0; i < intArray.length; i++){
			System.out.print(intArray[i]);

			if (i == intArray.length - 1){
				break;
			}
			System.out.print(" ");
		}
		System.out.println();
	}

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

		int progNumLength = Integer.parseInt(br.readLine());

		String[] progNum = br.readLine().split(" ");

		int[] progNumResult = new int[progNumLength];

		for(int i = 0; i < progNumLength; i++) {
			progNumResult[i] = Integer.parseInt(progNum[i]);
		}

		int sortCount = 0;
		int sortFlag = 1;

		while(sortFlag == 1) {
			sortFlag = 0;

			for(int i = progNumLength - 1; i > 0; i--) {
				if(progNumResult[i] < progNumResult[i - 1]) {
					int tmp = progNumResult[i - 1];
					progNumResult[i - 1] = progNumResult[i];
					progNumResult[i] = tmp;
					sortCount++;
					sortFlag = 1;
				}
			}
		}
		printArray(progNumResult);
		System.out.println(sortCount);
	}
}

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

#define ll long long int

int main() {

    ll N, M;
    cin >> N >> M;

    ll tmp;
    vector<ll> a;
    for (int i = 0; i < M; i++) {
        cin >> tmp;
        a.push_back(tmp);
    }


    vector<ll> S(100010);
    S[0] = 1;

    int j = 0;
    if (M > 0 && a[0] == 1) {
        S[1] = 0;
        j++;
    }
    else {
        S[1] = 1;
    }

    for (int i = 2; i <= N; i++) {
        if (j < M && i == a[j]) {
            S[i] = 0;
            while (j < M && i == a[j]) {
                j++;
            }
        }
        else {
            S[i] = S[i-1] + S[i-2];
            S[i] %= 1000000007;
        }
    }

    cout << S[N] << endl;


    return 0;
}


Measured memory_bytes: 1908
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  int r,D,x;
  cin>>r>>D>>x;
  for(int i=0;i<10;i++){
    x=r*x-D;
    cout<<x<<endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
const int P=1e9+7,maxn=310;
typedef pair<int,int> pi;
vector<pi> v[maxn];int n,m,dp[maxn][maxn][maxn],ans;
inline void upd(int &x,int y){x+=y;(x>=P)&&(x-=P);}
int main(){
    scanf("%d%d",&n,&m);
    rep(i,1,m){
        int l,r,x;
        scanf("%d%d%d",&l,&r,&x);if(r-l+1<x) return puts("0"),0;
        v[r].pb(mp(l,x));
    }
    dp[1][0][0]=1;
    rep(i,1,n){
        for(auto x:v[i]){
            rep(j,0,i-1) rep(k,0,max(0,j-1)){
                int cnt=1+(j>=x.fi)+(k>=x.fi);
                if(cnt!=x.se) dp[i][j][k]=0;
            }
        }
        rep(j,0,i-1) rep(k,0,max(0,j-1)) if(dp[i][j][k]){
            upd(dp[i+1][j][k],dp[i][j][k]);
            upd(dp[i+1][i][j],dp[i][j][k]);
            upd(dp[i+1][i][k],dp[i][j][k]);
        }
    }
    rep(i,0,n-1) rep(j,0,max(0,i-1)) upd(ans,dp[n][i][j]);
    printf("%lld\n",1ll*ans*3%P);
    return 0;
}

Measured memory_bytes: 112896
#include<iostream> 
#include<bits/stdc++.h> 
using namespace std; 
int main()
{
    int n,l,i;
    cin>>n>>l;
    if(n<l)
    for(i=0;i<l;i++)
       cout<<n;
    else
    for(i=0;i<n;i++)
       cout<<l;
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>	
#define pb push_back
#define MAX 200005
typedef long long ll;
const int inf = 2e9;
using namespace std;


//char S[MAX];
//for(int i=0; i<n; i++) scanf("%d",&A[i]);

int n,a,b,c,d,e,ans,x,y,k,t,maximo=1;

int sumaDigitos(int x){
	int r = 0;
	while(x!=0){
		r+=x%10;
		x/=10;
	}
	return r;
}

int main(){
	
	int n;
	scanf("%d",&n);

	int a,b,minimo = inf;

	for (int i = 1; i < n; ++i)
		minimo = min(minimo,sumaDigitos(i) + sumaDigitos(n-i));
	printf("%d\n", minimo);
	return 0;
}	

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

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

    cout << ans << endl;
    return 0;


}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#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 = 998244353;
const ll INF = 1e16;
const double pi = acos(-1);

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

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }
    
    // T ⊃ U = {x_1, x_2, …, x_k} は
    // a_(x_1) + a(x_2) + … + a(x_k) = S を満たすとする。
    // 各a_iに対して、①Tに含めない ②Tに含めてUに含めない ③Uに含める
    // の3通りがあり得る。

    vvl dp(n+1, vl(S+1));  // dp[i+1][j] : a[i]まででUに含めたものの合計がjとなる場合の数
    dp[0][0] = 1;
    rep(i, n) {
        exrep(j, 0, S) {
            dp[i+1][j] += dp[i][j];  // ①の場合
            dp[i+1][j] += dp[i][j];  // ②の場合
            dp[i+1][j] %= mod;
            if(j + a[i] <= S) {
                dp[i+1][j + a[i]] += dp[i][j];  // ③の場合
                dp[i+1][j + a[i]] %= mod;
            }
        }
    }

    out(dp[n][S]);
    re0;
}

Measured memory_bytes: 73752
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

typedef vector < vector <int> > vv;

const int N = 55;
const int mod = (int) 1e9 + 7;

int n;
long long k;
vv mat;

vv mul(vv a, vv b) {
  int m = a.size();
  vv ans(m, vector <int> (m, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        ans[i][j] = (ans[i][j] + 1ll * a[i][k] * b[k][j]) % mod;
      }
    }
  }
  return ans;
}

vv fp(vv a, long long b) {
  int m = a.size();
  vv ans(m, vector <int> (m, 0));
  for (int i = 0; i < m; i++) ans[i][i] = 1;
  while (b > 0) {
    if (b & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return ans;
}

int main() {
  cin >> n >> k;
  mat.resize(n, vector <int> (n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> mat[i][j];
    }
  }
  vv ans = fp(mat, k);
  int here = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      here = (here + ans[i][j]) % mod;
    }
  }
  cout << here << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n,max,min;
    long sum;
    scanf("%d",&n);
    int a;
    scanf("%d",&a);
    sum = min = max = a;
    for (int i=1;i<n;i++){
        scanf("%d",&a);
        sum=sum+a;
        if (max<a)
            max=a; 
        if (min>a)
             min=a;
    }
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}
    
    


Measured memory_bytes: 2140
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
xy = []

for i in range(N):
	A = INT()
	xy.append([LIST() for _ in range(A)])

ans = 0
for i in range(1<<N):
	i = list("{:b}".format(i).zfill(N))
	for j in range(N):
		if i[j] == "1":
			for x, y in xy[j]:
				if y != int(i[x-1]):
					break
			else:
				continue
			break
	else:
		tmp = sum([int(x) for x in i])
		ans = max(ans, tmp)
print(ans)


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

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

  int t;
  int ans = 0;
  int ma = 0;
  for(int i = 0;i < n;i++){
    cin >> t;
    ans += t;
    ma = max(t, ma);
  }

  cout << ans-ma/2 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
const int inf = 1e9;

pair<int, int> dfs(int node, vector<bool> &used, vector<vector<pair<int, int> > > &adj){
	used[node] = true;
	pair<int, int> ret(0, 0);
	for(int i=0; i<(int)adj[node].size(); i++){
		int newnode = adj[node][i].first;
		int newcost = adj[node][i].second;
		if(!used[newnode]){
			if((int)adj[newnode].size() == 1){
				ret.first += newcost;
			}else{
				pair<int, int> rec = dfs(newnode, used, adj);
				ret.first += newcost*3 + rec.first;
				ret.second = max(ret.second, newcost +rec.second);
			}
		}
	}
	return ret;
}
int solve(int root, vector<vector<pair<int, int> > > &adj){
	vector<bool> used(adj.size(), false);
	pair<int, int> ret = dfs(root, used, adj);
	return ret.first -ret.second;
}

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		vector<int> p(n), c(n);
		for(int i=1; i<n; i++) { cin >> p[i]; p[i]--; }
		for(int i=1; i<n; i++) { cin >> c[i]; }
		
		vector<vector<pair<int,int> > > adj(n);
		for(int i=1; i<n; i++){
			adj[i].push_back(make_pair(p[i], c[i]));
			adj[p[i]].push_back(make_pair(i, c[i]));
		}
		
		int ans = inf;
		for(int i=0; i<n; i++){
			ans = min(ans, solve(i, adj));
		}
		cout << ans << endl;
	}
	return 0;
}



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

int main(){
  int n;
  cin >> n;
  int h[n], cnt[n];
  for(int i = 0; i < n; i++){
    cin >> h[i];
    cnt[i] = 0;
  }
  if(h[n-2] >= h[n-1]) cnt[n-2] = 1;
  for(int i = n-3; i >= 0; i--){
    if(h[i] >= h[i+1]) cnt[i] += cnt[i+1]+1;
  }
  sort(cnt, cnt+n);
  cout << cnt[n-1] << endl;
  return 0;
}

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

int main()
{
    int a[55],b[55],c[55],d[55],n,m,i,dis,mindis,x,y;

    scanf("%d %d",&n,&m);

    for(i=0; i<n; i++)
    {
        scanf("%d %d",&a[i],&b[i]);
    }

    for(i=0; i<m; i++)
    {
        scanf("%d %d",&c[i],&d[i]);
    }

    for(i=0; i<n; i++)
    {
        mindis=1000000000;

        for(int j=0; j<m; j++)
        {
            dis=abs(a[i]-c[j])+abs(b[i]-d[j]);

            if(mindis>dis)
            {
                x=j+1;
                mindis=dis;
               // y=d[i];
            }
        }

        printf("%d\n",x);
    }
    return 0;

}


Measured memory_bytes: 256
#!/usr/bin/env python3

N, M = map(int, input().split())
a = [0]*M
b = [0]*M
c = [0]*M
for m in range(M):
    a[m], b[m], c[m] = map(int, input().split())
    if a[m] > b[m]:
        a[m], b[m] = b[m], a[m]
        assert(a[m] < b[m])
    a[m] -= 1
    b[m] -= 1
#
temp = [10**7] * N
d = [temp[:] for i in range(N)]

for i in range(N):
    for j in range(i, N):
        assert(i<=j)
        if i == j:
            d[i][j] = 0
        else:
            for m in range(M):
                if a[m]==i and b[m]==j:
                    d[i][j] = c[m]

for k in range(N):
    for i in range(N):
        for j in range(i, N):
            assert(i<=j)
            if i <= k:
                dik = d[i][k]
            else:
                dik = d[k][i]
            if k <= j:
                dkj = d[k][j]
            else:
                dkj = d[j][k]
            if d[i][j] > dik + dkj:
                d[i][j] = dik + dkj

ans = 0
for m in range(M):
    if c[m] > d[a[m]][b[m]]:
        ans += 1
    elif c[m] < d[a[m]][b[m]]:
        raise Exception()
print(ans)


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>s;
	if(s=="RRR") cout<<3<<endl;
	if(s=="RRS") cout<<2<<endl;
	if(s=="RSR") cout<<1<<endl;
	if(s=="SRR") cout<<2<<endl;
	if(s=="RSS") cout<<1<<endl;
	if(s=="SRS") cout<<1<<endl;
	if(s=="SSR") cout<<1<<endl;
	if(s=="SSS") cout<<0<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 
 
   
int main(){
  VI a(6);
  rep(i,6)cin >> a.at(i) ;
  int sum=0;
  int cnt1=0;
  int cnt2=0;
  int cnt3=0;
  int cnt4=0;
  rep(i,6){
    if(a.at(i)==1)cnt1++;
    else if(a.at(i)==2)cnt2++;
    else if(a.at(i)==3)cnt3++;
    else if(a.at(i)==4)cnt4++;
  }
  if(cnt1==3 || cnt2==3 || cnt3==3 ||cnt4==3)cout << "NO" << endl;
  else cout << "YES" << endl;

} 
    

Measured memory_bytes: 3596
// Reference: editorial and answer from youtube
#include <bits/stdc++.h>
//#include <iostream>
//#include <vector>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll x2 = 0;
  rep(i,n){
    if(i%2) x2 -= a[i];
    else x2 += a[i];
  }
  vector<int> ans(n);
  ans[0] = x2/2;
  rep(i,n-1) ans[i+1] = a[i] - ans[i];
  rep(i,n){
    ans[i] *= 2;
    cout << ans[i] << " ";
  }
}


Measured memory_bytes: 2048
package main

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

func main() {
	err := Main(os.Stdin, os.Stdout)
	if err != nil {
		panic(err)
	}
}

func Main(r io.Reader, w io.Writer) error {
	scanner := bufio.NewScanner(r)
	scanner.Scan()
	line := scanner.Text()
	s := strings.Fields(line)
	num, err := strconv.Atoi(s[0])
	if err != nil {
		return err
	}

	total, err := strconv.Atoi(s[1])
	if err != nil {
		return err
	}

	for x := 0; x <= num; x++ {
		for y := 0; y+x <= num; y++ {
			z := num - (x + y)
			sum := 10000*x + 5000*y + 1000*z
			if sum == total {
				fmt.Fprintf(w, "%d %d %d", x, y, z)
				return nil
			}
		}
	}
	fmt.Fprint(w, "-1 -1 -1")

	return nil
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i=0; i<(int64_t)(n); i++)
#define all(v) v.begin(), v.end()
//4
int main(){
  
  int N;
  cin >> N;
  vector<int64_t> A(N), B(N);
  rep(i, N) cin >> A[i] >> B[i];
  
  int64_t cnt=0;
  rep(i, N){
    if((A[N-1-i]+cnt)%B[N-1-i]==0) continue;
    cnt += B[N-1-i]-((A[N-1-i]+cnt)%B[N-1-i]);
  }
  
  cout << cnt << endl;
  
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
       string s;
       cin>>s;
       if(s=="ARC")
       cout<<"ABC";
       else
       cout<<"ARC";
return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> vpll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define yes(a) printf(a ? "yes\n" : "no\n")
#define Yes(a) printf(a ? "Yes\n" : "No\n")
#define YES(a) printf(a ? "YES\n" : "NO\n") 
const long double PI = acos(-1);
const long long INF = (1 << 30);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  ll n, p;
  cin >> n >> p;
  vector<ll> a(n);
  for(ll i = 0; i < n; i++) cin >> a[i];

  ll even = 0, odd = 0;
  for(ll i = 0; i < n; i++){
    if(a[i] % 2 == 0) even++;
    else odd++;
  }

  if(p == 0){
    if(odd == 0) cout << (ll)pow(2, n) << endl;
    else cout << (ll)pow(2, n-1) << endl;
  }else{
    if(odd == 0) cout << 0 << endl;
    else cout << (ll)pow(2, n-1) << endl;
  }
	return 0;
}

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

int main(){
    int x,y,z;
    string s1, s2;
    char s;

    cin >> x >> y;
    
    if (y * 2 < x ){
        cout << x - (2*y) << endl;
    }else{
        cout << 0 << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <stdlib.h>
#include <ctime>
typedef long long ll;
typedef long double ld;

using namespace std;
int inf=1e9;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(100);
  //  freopen("input.txt","r",stdin);
    int x,y;
    cin>>x>>y;
    if((x+y)%2!=0) cout<<"IMPOSSIBLE";
    else cout<<(x+y)/2;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
main(){
  int i,j,n,code;
  char cm[7],op,dict[262145];
  for(i=0,scanf("%d %s",&n,cm);i<n;i++,scanf("%s",cm)){
    for(j=code=op=0;op!='\n';scanf("%c",&op))
      if(op=='A') code+=1*pow(4,j++);
      else if(op=='C') code+=2*pow(4,j++);
      else if(op=='G') code+=3*pow(4,j++);
      else if(op=='T') code+=4*pow(4,j++);
    cm[0]=='i' ? dict[code] = 1 : (dict[code] ? printf("yes\n") : printf("no\n"));
  }
  return 0;
}

Measured memory_bytes: 500
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define int long long
typedef pair<int,int>pii;
const int mxN=25,M=1e9+7;
int n,tot;
int matriz[mxN][mxN];
int dp[(1<<21)];
int mod(int a){int ret=a%M;if(ret<0)ret+=M;return ret;}
// LONG LONG CASE
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    tot=(1<<n)-1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>matriz[i][j];
        }
    } 
    dp[0]=1;
    for(int mask=0;mask<(1<<n)-1;mask++){
        int a=__builtin_popcount(mask);
        for(int b=0;b<n;b++){
            if(matriz[a][b] && !(mask & (1<<b))){
                int m=mask|(1<<b);
                dp[m]=mod(dp[m]+dp[mask]);
            }
        }
    }
    cout<<dp[(1<<n)-1];
    
}

Measured memory_bytes: 16640
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;

int gcd(int n, int m) {
    if (n == 0)
        return m;
    return gcd(m % n, n);
}

int bit_count(int i) {
    i = i - ((i >> 1) & 0x55555555);
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
    i = (i + (i >> 4)) & 0x0f0f0f0f;
    i = i + (i >> 8);
    i = i + (i >> 16);
    return i & 0x3f;
}

int main() {
    int n;
    cin >> n;
    vector<vector<bool>> edges(n, vector<bool>(n, false));
    vector<pair<int, int>> n_edges(n, make_pair(0, 0));
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[a][b] = edges[b][a] = true;
        n_edges[a].second = a;
        n_edges[a].first++;
        n_edges[b].second = b;
        n_edges[b].first++;
    }
    sort(n_edges.rbegin(), n_edges.rend());
    vector<int> c(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }
    sort(c.begin(), c.end());

    vector<int> vertices(n);
    queue<int> q;
    q.push(n_edges[0].second);
    while(!q.empty()) {
        int v = q.front(); q.pop();
        if (vertices[v] > 0) continue;
        vertices[v] = c.back(); c.pop_back();
        for (int i = 0; i < n; ++i) {
            if (edges[v][i]) q.push(i);
        }
    }

    int score = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (edges[i][j]) score += min(vertices[i], vertices[j]);
        }
    }
    cout << score << endl;
    cout << vertices[0];
    for (int i = 1; i < n; ++i) {
        cout << ' ' << vertices[i];
    }
}


Measured memory_bytes: 13312
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<numeric>

using namespace std;

int main(){
  int n;cin>>n;
  int a[104];
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  cout<<abs(a[n-1]-a[0])<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

long long int gcd(long long int x, long long int y)
{
	long long int r;

	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}



int main()
{
	int i;
	long long int buff;
	long long int lcm = 1;

	scanf("%d", &i);

	for (int j = 0; j < i; j++) {
		scanf("%lld", &buff);
		if (lcm % buff == 0) {
			continue;
		}
		lcm *= buff / gcd(buff, lcm);
	}

	printf("%lld", lcm);
	return 0;
}



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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b < c + d) cout << "Right" << endl;
  else if (a + b == c + d) cout << "Balanced" << endl;
  else cout << "Left" << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(a) (a).begin(), (a).end()
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    long ans = 0;
    rep(i,n){
        auto x = lower_bound(All(a), b[i]) - a.begin();
        auto y = n - (lower_bound(All(c), b[i]+ 1) - c.begin());
        ans += x * y;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main(void){
  int i,m,f,r;
  while(1){
    scanf("%d %d %d",&m,&f,&r);
    if(m == -1 && f == -1 && r == -1){
      break;
    }
    else if(m == -1 || f == -1){
      printf("F\n");
    }
    else{
      if(m + f >= 80){
      printf("A\n");
    }
    else if(m + f >= 65){
      printf("B\n");
    }
    else if(m + f >= 50 || r >= 50){
      printf("C\n");
    }
    else if(m + f >= 30){
      printf("D\n");
    }
    else{
      printf("F\n");
    } 
    }
  }
  return 0;
}


Measured memory_bytes: 2044
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>
#include<utility>
#include<map>

using namespace std;

int main() {
	int an = 0, bn = 0, cn = 0;
	char cur = 'a';
	string A, B, C;
	cin >> A >> B >> C;
	while (1) {
		switch (cur){
		case 'a':
			if (an == A.length()) {
				cout << "A" << endl;
				return 0;
			}
			cur = A[an];
			an++;
			break;
		case 'b':
			if (bn == B.length()) { 
				cout << "B" << endl; 
				return 0;
			}
			cur = B[bn];
			bn++;
			break;
		case 'c':
			if (cn == C.length()) {
				cout << "C" << endl;
				return 0;
			}
			cur = C[cn];
			cn++;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define f first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>


using namespace std;

const int N = 2e5 + 123;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const int p = 1e9 + 7;


ll md(ll x, ll y) {
	x %= y;
	return (x + 2 * y) % y;
}


ll gcd(ll x, ll y) {
	if (x != 0 && y != 0)	
		return gcd(y, x % y);
	return x + y;
}


ll a, b, c, d;


int main() {
	ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
// 	freopen("input.txt", "r", stdin);
	ll test;
	cin >> test;
	while (test--) {
		cin >> a >> b >> c >> d;
		if (b > a || b > d) {
			cout << "No\n";
			continue;
		}
		ll tmp = gcd(max(b, d), min(b, d)), t, mn, t1, pls;
		t = md(a, tmp);
		mn = c - b + 1;
		t1 = md(mn, __gcd(b, d));
		if (t < t1)
			pls = __gcd(b, d) - t1 + t;
		else if (t > t1)
			pls = t - t1;
		else
			pls = 0;
		if (mn + pls >= 0)
			cout << "Yes\n";
		else
			cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
#define int long long
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int x=read(),cur=100,cnt=0;
signed main(){
	while(cur<x){
		cur=(int)(1.01*cur);
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define md (ll)(1e9+7)
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str */

const int M=1e6+6;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll dp[3002][3002],mrk[3002][3002],lx[3002][3002],ly[3002][3002];

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

	ll i,j,n,m,d,u,l,x,y,cx,cy;
	string str,qtr,adj;

	cin >> str;
	cin >> qtr;

	n = str.size();
	m = qtr.size();

	for(i=1;i<=n;++i)
	{
		for(j=1;j<=m;++j)
		{
			d = dp[i-1][j-1] + (str[i-1]==qtr[j-1]);
			u = dp[i-1][j];
			l = dp[i][j-1];

			if(d>=max(u,l))
			{
				if(str[i-1]==qtr[j-1])
					mrk[i][j] = 1;
				dp[i][j] = d;
				lx[i][j] = i-1;
				ly[i][j] = j-1; 
			}
			else if(u>=max(d,l))
			{
				dp[i][j] = u;
				lx[i][j] = i-1;
				ly[i][j] = j;
			}
			else
			{
				dp[i][j] = l;
				lx[i][j] = i;
				ly[i][j] = j-1;
			}
		}
	}

	x = n;
	y = m;
	while(x>=1 && y>=1)
	{
		if(mrk[x][y])
			adj.pb(str[x-1]);
		cx = lx[x][y];
		cy = ly[x][y];
		x = cx;
		y = cy;
	}

	reverse(all(adj));

	cout << adj << endl;
	return 0;
}

	


Measured memory_bytes: 281856
p = 10**9+7
N = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))
H = [0 for _ in range(N)]
cnt = 1
H[0] = T[0]
for i in range(1,N):
    if T[i]>T[i-1]:
        H[i] = T[i]
if H[-1]>0 and H[-1]!=A[-1]:
    cnt = 0
else:
    H[-1] = A[-1]
    for i in range(-2,-N-1,-1):
        if H[i]==0 and A[i]>A[i+1]:
            if A[i]<=T[i]:
                H[i] = A[i]
            else:
                cnt = 0
                break
        elif H[i]>0 and A[i]>A[i+1]:
            if H[i]==A[i]:continue
            else:
                cnt = 0
                break
    if cnt==1:
        for i in range(1,N-1):
            if H[i]==0:
                cnt = (cnt*min(T[i],A[i]))%p
print(cnt) 

Measured memory_bytes: 18924
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
ll n,k = 2;
ll h[100000],memo[100000];
ll dp(ll i){
	if(i == n-1) return 0;
	if(memo[i] != -1) return memo[i];
	ll ret = INT_MAX;
	for(int j=1;j<=k;j++){
		if(i+j<n)
			ret = min(ret,dp(i+j)+abs(h[i]-h[i+j]));
	}
	memo[i] = ret;
	return ret;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	memset(memo,-1,sizeof(memo));
	cin>>n;
	for(int i=0;i<n;i++) cin>>h[i];
	dp(0);
	cout<<memo[0]<<"\n";
	return 0;
}

Measured memory_bytes: 6528