akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int n, m, x;

bool good(vector<int>& b){
    for(int i : b){
        if(i < x){
            return false;
        }
    }
    return true;
}

void solve(){
    cin >> n >> m >> x;
    vector<vector<int>> v(n, vector<int>(m+1));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m+1; j++){
            cin >> v[i][j];
        }
    }
    
    int mi = INT_MAX;
    for(int c = 1; c < pow(2, n); c++){
        vector<int> b(m, 0);
        int cost = 0;
        for(int i = 0; i < n; i++){      
            if((c>>i) & 1){
                //cout << i << " ";
                cost += v[i][0];
                for(int j = 1; j < m+1; j++){
                    b[j-1] += v[i][j];
                }
            }
        }
        // cout << endl << "b ";
        // for(int i : b){
        //     cout << i << " ";
        // }cout << endl;
        if(good(b)){
            mi = min(mi, cost);
        }  
    }

    if(mi == INT_MAX){
        cout << "-1\n";
    }
    else{
        cout << mi << '\n';
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 4020
#include <bits/stdc++.h>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn = 1e5 + 10;
using namespace std;
int n, m, k, t, h[maxn], tot, ans[maxn];
set<int>comp[maxn];
struct node
{
        int to, nxt, com;
} e[maxn << 2];
void add(int x, int y, int z)
{
        tot++;
        e[tot].to = y;
        e[tot].com = z;
        e[tot].nxt = h[x];
        h[x] = tot;
}
priority_queue<pair<int, int> >p;
int main()
{
        int i, j;
        while (scanf("%d %d", &n, &m) == 2)
        {
                //cout << n << " " << m << endl;
                for (int i = 1; i <= n; i++)
                {
                        h[i] = 0;
                        ans[i] = inf;
                        comp[i].clear();
                }
                tot = 0;
                while (m--)
                {
                        int a, b, c;
                        scanf("%d%d%d", &a, &b, &c);
                        add(a, b, c);
                        add(b, a, c);
                }
                p.push({0, 1});
                ans[1] = 0;
                while (!p.empty())
                {
                        int now = p.top().se, ca = -p.top().fi;
                        p.pop();
                        if (ans[now] < ca)
                        {
                                continue;
                        }
                        for (i = h[now]; i; i = e[i].nxt)
                        {
                                int to = e[i].to, to_com = e[i].com;
                                int to_ca = ca + (!comp[now].count(to_com));
                                if (ans[to] > to_ca)
                                {
                                        ans[to] = to_ca;
                                        p.push({ -to_ca, to});
                                        comp[to].clear();
                                        comp[to].insert(to_com);
                                }
                                else if (ans[to] == to_ca)
                                {
                                        comp[to].insert(to_com);
                                }
                        }
                }
                printf("%d\n", ans[n] == inf ? -1 : ans[n]);
        }
        //system("Pause");
        return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> qq(81);
    for (int i=0; i<9; i++){
        for (int j=0; j<9; j++){
            qq.at(i * 9 + j) = (i+1) * (j+1);
        }
    }
    for (int i=0; i<81; i++){
        if (N == qq.at(i)){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	while(cin >> n && n)
	{
		int m, e, j, p;
		rep(i, n)
		{
			cin >> m >> e >> j;

			p = m + e + j;

			if((m == 100 || e == 100 || j == 100) || (90 <= (m + e) / 2) || (80 <= p / 3))
				cout << "A" << endl;
			else if(70 <= p / 3 || (50 <= p / 3 && (80 <= m || 80 <= e)))
				cout << "B" << endl;
			else
				cout << "C" << endl;
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    int cou = 0;
    rep(i, n) {
        if(s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G') {
            cou++;
            ans = max(ans, cou);
        }
        else {
            cou = 0;
        }
    }

    cout << ans << endl;

    return 0;
}

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

ll a, b, x;

ll f(ll n) {
  if (n == -1) return 0;
  return n / x + 1;
}

int main() {
  cin >> a >> b >> x;
  cout << f(b) - f(a - 1) << endl;
  return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define F               first
#define S               second
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18 + 1
#define endl            '\n'
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define forI(i,a,n)     for(int i=a;i<=n;i++)
#define forD(i,a,n)     for(int i=n;i>=a;i--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void init(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

int dp[3005][3005];

int compute(string& s, string& t, int i, int j){
    if(i >= s.length() || j >= t.length())    return 0;

    if(dp[i][j] != -1)  return dp[i][j];

    if(s[i] == t[j])    return dp[i][j] = 1 + compute(s, t, i+1, j+1);
    
    return dp[i][j] = max(compute(s, t, i+1, j), compute(s, t, i, j+1));
}

string getLCS(string& s, string& t, int len){
    string lcs; 
    int i=0, j=0;
    while(len > 0){
        if(s[i] == t[j]){
            lcs.pb(s[i]);
            i++, j++, len--;
        }
        else{
            dp[i+1][j] > dp[i][j+1] ? i++ : j++;
        }
    }
    return lcs;
}

void solve(){
    string s, t;    cin>>s>>t;
    memset(dp, -1, sizeof dp);
    int len = compute(s, t, 0, 0);
    cout<<getLCS(s, t, len);
}

int32_t main(){
    init();
    // w(t) 
    solve();
    return 0;
}

Measured memory_bytes: 74496
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
typedef long long ll;
using namespace std;

bool cmp(const pair<ll, ll> a, const pair<ll, ll> b){
	return a.first + a.second < b.first + b.second;
}

int main(){
	ll n;
	cin>>n;
	vector<pair<ll, ll>> person;
	for (ll i=0; i<n; i++){
		ll x, y;
		cin>>x>>y;
		person.push_back({x, y});
	}
	sort(person.begin(), person.end(), &cmp);
	vector<vector<ll>> dp(n+1, vector<ll>(n+1, LONG_MAX));
	for (ll i=0; i<=n; i++)
		dp[i][0] = 0;
	for (ll i=1; i<=n; i++){
		for (ll j=1; j<=n; j++){
			dp[i][j] = dp[i-1][j];
			if (dp[i-1][j-1] <= person[i-1].first){
				dp[i][j] = min(dp[i][j], dp[i-1][j-1] + person[i-1].second);
			}
		}
	}
	for (ll i=n; i>=0; i--){
		if (dp[n][i] != LONG_MAX){
			cout<<i<<endl;
			break;
		}
	}
}

Measured memory_bytes: 198940
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int main()
{
	//FAST;
	int n, wt, i, j;
	cin >> n >> wt;
	ll w[n], v[n];
	fr(i,0,n)
		cin >> w[i] >> v[i];
	ll ans[2][100001];
	fr(j,0,n+1)
	{
		fr(i,0,100001)
		{
			if((i == 0))	
				ans[1][i] = 0;
			else if(j == 0)
				ans[1][i] = 10000000000000;	
			else 
				ans[1][i] = min(ans[0][i], ans[0][max((ll)0, i - v[j-1])] + w[j-1]);
		}
		fr(i,0,100001)
			ans[0][i] = ans[1][i];
	}
	for(j=100000;j>=0;j--)
	{	
		if(ans[0][j] <= wt)
		{
			cout << j;
			break;
		}
	}
}

Measured memory_bytes: 1920
/*  
    Talkin' to myself and feelin' old
    Sometimes I'd like to quit, nothin' ever seems to fit
    Hangin' around, nothin' to do but frown
    Rainy days and Mondays always get me down
    _________________________
    _________________________
    912 Hours of Solitude
    Quarantine_Day : 38
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int       ll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef pair<int, int>      pii;
typedef pair<ll, ll>		pll;

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<int>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 90

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

    ll n; cin>>n;
    ll sum = 0, temp = n;
    while(temp){sum += temp % 10; temp /= 10;}
    cout<<(n % sum == 0?"Yes\n":"No\n");

    return 0;
}


Measured memory_bytes: 256
using System;
// using System.Collections.Generic;
// using System.Linq;

class Program
{
    static void Main()
    {
        long X = long.Parse(Console.ReadLine());
        long cur = 100L;
        long ans = 0L;
        while (cur < X)
        {
            cur += cur / 100;
            ans++;
        }
        Console.WriteLine(ans);
        return;
    }
}

Measured memory_bytes: 27464
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S, T;
    cin >> S >> T;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] != T[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
char fir, sec;
  cin >> fir >> sec;
  if(fir > sec)
    cout << '>' << endl;
  if(fir == sec)
    cout << '=' << endl;;
  if(fir < sec)
    cout << '<' << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
    int N,a=0;
    cin>>N;
    vector<int>T(N,0),F(N,0);
    for(int i=0;i<N;++i){
        int A,X,Y;
        cin>>A;
        for(int j=0;j<A;++j){
            cin>>X>>Y;
            if(Y)T[i]|=1<<(X-1);
            else F[i]|=1<<(X-1);
        }
    }
    int iMax=(1<<N)-1;
    for(int i=1;i<=iMax;++i){
        int t=0,f=0;
        for(int j=0;j<N;++j){
            t|=T[j]*((i>>j)%2);
            f|=F[j]*((i>>j)%2);
        }
        if((t&i&iMax)==t && (f&~i&iMax)==f){
            a=max(a,__builtin_popcount(i));
        }
    }
    printf("%d",a);
}

Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#pragma endregion

void solve() {
    char c;
    cin >> c;
    cout << (char)(c + 1) << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		while(true) {
			String card = sc.next();
			if(card.equals("-"))
				break;

			int	count = sc.nextInt();
			for(int i=0; i<count; i++){
				int shuffle = sc.nextInt();
				String head=card.substring(0,shuffle);
				String tail=card.substring(shuffle);
				card=tail + head;
			}
			System.out.println(card);
		}
	}
}



Measured memory_bytes: 26524
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();

		if(n % 2 == 0) {
			if(k <= n/2) {
				System.out.println("YES");
				return;
			}
		} else {
			if(k <= n/2 + 1) {
				System.out.println("YES");
				return;
			}
		}

		System.out.println("NO");

	}

}


Measured memory_bytes: 25044
import java.util.*;
 
class Main {
    
	static int res=0,d,w,E[][]=new int[10][10];
	
    public static void main(String[] args) {
         
       Scanner cin=new Scanner(System.in);
       
       while(true) {
    	   int n=cin.nextInt();
    	   if(n==0)break;
    	   
    	   List<Integer> list=new ArrayList<>();
    	   for(int i=0;i<n;i++)list.add(cin.nextInt());
    	   
    	   Collections.sort(list);
    	   
    	   int res=0;
    	   for(int i=1;i<n-1;i++)res+=list.get(i);
    	   
    	   System.out.println(res/(n-2));
       }
    }
}


Measured memory_bytes: 29216
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 2e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);	
	int n;
	cin >> n;
	int mx = 0, sum = 0;
	for(int i = 0; i < n; i++){
		int num;
		cin >> num;
		sum += num;
		mx = max(mx, num);
	}
	sum -= mx;
	if(sum > mx){
		cout << "Yes";
	}else{
		cout << "No";
	}
}

Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void pickV(R,T...)(ref R r,ref T t){foreach(ref v;t)pick(r,v);}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, m; readV(n, m);

  auto c = new int[](m+1);
  foreach (i; 0..n) {
    auto rd = rdsp;
    int k; pickV(rd, k);
    foreach (j; 0..k) {
      int a; pickV(rd, a);
      ++c[a];
    }
  }

  writeln(c.count(n));
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
#define eps 1e-7
#define PI acos(-1)
#define de(x) cout<<#x<<'='<<x<<" , "
#define dee(x) cout<<#x<<'='<<x<<endl
#define sz(x) (int)x.size()
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=a;i>(b);--i)
#define mset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define random(a,b) ((a)+rand()%((b)-(a)+1))
typedef long long LL;
typedef pair<int,char> pii;
typedef vector<int> vi;
const int maxn=100055;
int bridgecnt=0,cutcnt=0;
int clk,dfn[maxn],low[maxn];
vi e[maxn];
void tarjan(int u,int par){
    dfn[u]=low[u]=++clk;
    bool tag=0; int child=0;
    rep(i,0,sz(e[u])){
        int v=e[u][i]; if(v==par) continue;
        if(!dfn[v]){
            child++;
            tarjan(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>=dfn[u]) tag=1;
            if(low[v]>dfn[u] ) bridgecnt++;
        }
        else low[u]=min(low[u],dfn[v]);
    }
    if(tag||(par==-1&&child>=1)) cutcnt++;
}
int main(){
    int n,m; cin>>n>>m;
    while(m--){
        int u,v; scanf("%d %d",&u,&v);
        e[u].pb(v);  e[v].pb(u);
    }
    rep(i,1,n+1) if(!dfn[i]) tarjan(i,-1);
    cout<<bridgecnt<<endl;
}


Measured memory_bytes: 2560
N, M = map(int, input().split())
List = [int(input()) for _ in range(M)]

P = 10**9+7
dp = [1]*(N+1)

for i in List:
    dp[i]=0

for j in range(1, N):
    if dp[j+1]!=0:
        dp[j+1] = (dp[j]+dp[j-1])%P
        
print(dp[N])

Measured memory_bytes: 7824
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
 
//思路：并?集 + ? + ?列 （??取出方式） 

int parent[100016];
int height[100016];

//并?集 
void init(int n)
{
	for(int i = 1; i <= n; i++){
		parent[i] = i;
		height[i] = 0;
	}
}
 
int find(int x)
{
	if(parent[x] == x)  return x;
	else  return parent[x] = find(parent[x]);
}
 
void unite(int x, int y)
{
	x = find(x);
	y = find(y);
	if(x == y)  return;
	if(height[x] < height[y])  parent[x] = y;
	else{
		parent[y] = x;
		if (height[x] == height[y])  height[x]++;
	}
}
 
//用来描述原始? 
vector<int> children[100016];
int parent_tree[100016];
bool marked[100016];
int ancestor[100016];
// ?条指令被拆分? 操作 + 目?
stack<char> operation;
stack<int>  target;
 
void bfs(int index, int the_ancestor)
{
	queue<int> q_index;
	queue<int> q_ancestor;
	q_index.push(index);
	q_ancestor.push(the_ancestor);
	while (!q_index.empty())
	{
		the_ancestor = q_ancestor.front(); 
		q_ancestor.pop();
		index = q_index.front(); 
		q_index.pop();
		if(marked[index] == true)  the_ancestor = index;  //如果?点自身被??，?它的染色祖先是自己，它的自己不??的儿子的最近染色祖先是它
		ancestor[index] = the_ancestor;  //??index的最近染色祖先 
		for(vector<int>::iterator it = children[index].begin(); it != children[index].end(); it++){  //将index的儿子加入?列 
			q_index.push(*it);
			q_ancestor.push(the_ancestor);
		}
	}
}
 
int main()
{
 
	int N, Q;
	while(scanf("%d %d", &N, &Q) && (N || Q)){
		for(int i = 1; i <= N; i++){
			children[i].clear();
			marked[i] = false;
		}
		marked[1] = true;
		parent_tree[1] = 1;
		int p;
		for(int i = 2; i <= N; i++){
			scanf("%d", &p);
			parent_tree[i] = p;
			children[p].push_back(i);
		}
		getchar(); 
		for(int i = 0; i < Q; i++){
			char ch;
			int t;
			scanf("%c %d", &ch, &t);
			getchar();
			if(ch == 'M'){
				if(marked[t])  continue;  //不?存重?的 "M v"，防止之后重?反染色 
				else  marked[t] = true;
			}
			operation.push(ch);
			target.push(t);
		}
		bfs(1, 1);
		init(N);
		for(int i = 1; i <= N; i++){
			unite(i, ancestor[i]);
		}
		unsigned long long result = 0;
		while(!operation.empty()){  //从后往前取出操作
			char ch = operation.top(); 
			operation.pop();
			int t = target.top(); 
			target.pop();
			if(ch == 'Q')  result += ancestor[find(t)];  //?目index从1?始
			else{  //??点t反染色（取消染色），t的祖先??其父?点的祖先
				int p = ancestor[find(parent_tree[t])];
				unite(t, parent_tree[t]);
				ancestor[find(t)] = p;
			}
		}
		printf("%lld\n", result);
	}
	return 0;
}

Measured memory_bytes: 11724
s=input()
if(s[0]!=s[1]):
    if(s.count(s[0])==2 and s.count(s[1])==2):
        print('Yes')
    else:
        print('No')
else:
    if(s.count(s[0])==2 and s.count(s[2])==2):
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

struct edge {
    int to, cost;
};

using Graph = vector<vector<edge>>;
Graph G;

ll d[100005];

void dfs(int v, int p){
    for(auto e: G[v]){
        if(e.to == p) continue;
        d[e.to] = d[v] + e.cost;
        dfs(e.to, v);
    }
}

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

    G.assign(n, vector<edge>());
    rep(i, n-1){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }

    int q, k;
    cin >> q >> k;

    dfs(k-1, -1);

    rep(i, q){
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << (d[x] + d[y]) << endl;
    }
}

Measured memory_bytes: 12800
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  ll n;
  vector <ll> a;
  cin >> n;
  if(n != 1){
    REP(i,n){
      ll b;
      cin >> b;
      a.pb(b);
      //cout << "sdfafg" << endl;
    }
    vector <ll> b;
    REP(i,a.size()-1){
      if(a[i]-a[i+1]>0){
	b.pb(1);
      }
      else if(a[i] - a[i+1] < 0)
	b.pb(-1);
      else
	b.pb(0);
    }
    
    int x = 0;
    while(b[x] == 0){
      x++;
    }
    ll c = b[x];
    ll sum = 0;
    for(ll i = x+1;i < b.size();i++){
      if(c != b[i] && b[i] != 0){
	//cout << i << endl;
	sum++;
	ll t = i+1;
	while(b[t] == 0){
	  t++;
	}
	c = b[t];
	i++;
      }
    }
    cout << sum+1 << endl;
  }
  else
  cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 2548
#include <iostream>
#define ll long long
using namespace std;

ll nums[100005];

int main() {
    ll sum = 0;
    ll n;
    cin >> n;
    for (ll i = 1; i <= n; ++i) {
        ll temp;
        cin >> temp;
        nums[temp]++;
        sum += temp;
    }

    ll q;
    cin >> q;
    for (ll i = 1; i <= q; ++i) {
        ll b, c;
        cin >> b >> c;
        ll temp = nums[b];
        nums[b] = 0;
        nums[c] += temp;

        sum -= temp * b;
        sum += temp * c;
        cout << sum << "\n";
    }
}

Measured memory_bytes: 4340
#include <stdio.h>

int main(void){
    int n, k, loop, num;

    scanf("%d %d", &n, &k);   
    num = k;
    for(loop = 0; loop < n - 1; loop++){
        num *= (k - 1);
    }
    printf("%d\n", num);
    return 0;
}

Measured memory_bytes: 128
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;

void main(){
	auto a=readln.chomp.to!int;
	auto b=readln.chomp.to!int;
	auto h=readln.chomp.to!int;
	writeln((a+b)*h/2);
}

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

int main(){
    ll N; cin >> N;
    rep(i, 1, 50000){
        if((int)((double)i * (1.08)) == N){
            cout << i << endl;
            return 0;
        }  
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
int main(){
    int n;
    while(cin>>n){
	     
	 string s="";

        if(n==0){
            break;
        }
        map<char, char> m;
        char a,b;
        for(int i=0;i<n;i++){
            cin>>a>>b;
            m[a]=b;
        }
        int d;
        cin>>d;
        for(int i=0;i<d;i++){
            cin>>a;
            if(m.count(a)){
                    a=m[a];
                }
            s+=a;
        }
        cout<<s<<endl;
    }
    return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<string> s(N);
  for(string &S:s){
    cin>>S;
    sort(S.begin(),S.end());
  }
  sort(s.begin(),s.end());
  string k="";
  int64_t j=0,l=0;
  for(string &S:s){
    if(k==S)
      l++;
    else{
      j+=l*(l-1)/2;
      k=S;
      l=1;
    }
  }
  j+=l*(l-1)/2;
  cout<<j<<endl;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
long long int c_n_2(long long int n)
{
    if(n < 2)
        return 0;
    return n * (n - 1) / 2;
}
int main()
{
    long long int n;
    cin >> n;
    vector<long long int> vec;
    map<long long int, long long int> mp;
    for(long long int i = 0; i < n; i++)
    {
        long long int get;
        cin >> get;
        vec.push_back(get);
        map<long long int,long long int>::iterator iter = mp.find(get);
        if(iter != mp.end())
        {
            mp[get]++;
        }
        else
        {
            mp.insert(pair<long long int, long long int>(get, 1));
        }
    }
    map<long long int, long long int>::iterator iter;
    long long int sum = 0;
    for(iter = mp.begin(); iter != mp.end(); iter++)
    {
        //cout << iter -> first << " " << iter -> second << endl;
        sum += c_n_2(iter -> second);
    }
    for(long long int i = 0; i < n; i++)
    {
        cout << sum - mp.find(vec.at(i)) -> second + 1 << endl;
    }
}

Measured memory_bytes: 12272
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  std::string S;

  std::cin >> N >> S;

  std::cerr << "N=" << N << " S=" << S << std::endl;

  std::map<std::string, int> map;

  for (int i = 0, size = 1 << N; i < size; i ++) {
    std::string s, t;

    for (int j = 0, b = 1; j < N; j ++, b <<= 1)
      (b & i ? s : t).push_back(S[j]);

    map[s + '.' + t] ++;
  }

  long long c = 0;

  for (int i = 0, size = 1 << N; i < size; i ++) {
    std::string s, t;

    for (int j = 0, b = 1; j < N; j ++, b <<= 1)
      (b & i ? s : t).push_back(S[N + N - 1 - j]);

    c += map[s + '.' + t];
  }

  std::cout << c << std::endl;

  return 0;
}


Measured memory_bytes: 67200
//
//  main.cpp
//  exhaustive_serach
//
//  Created by ???????????? on 2017/10/07.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>

using namespace std;

int n, A[50];

bool solve(int i, int m){
    if(m == 0){
        return true;
    }
    if(i >= n){
        return false;
    }
    bool res = solve(i+1, m) || solve(i+1, m - A[i]);
    return res;
}


int main(int argc, const char * argv[]) {
    int i, q, m;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%d", &m);
        bool is_solve = solve(0, m);
        if(is_solve) cout << "yes" <<endl;
        else cout << "no" <<endl;
        
    }
//    std::cout << "Hello, World!\n";
    return 0;
}

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, ll> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll segtree[816225][2],s[225816];

void eval(int i, int l, int r){
	if(segtree[i][1]){
		segtree[i][0] += segtree[i][1];
		if(r-l>1){
			segtree[2*i+1][1] += segtree[i][1];
			segtree[2*i+2][1] += segtree[i][1];
		}
		segtree[i][1] = 0ll;
	}
}

void update(int a, int b, int i, int l, int r, ll v){
	eval(i,l,r);
	if(b<=l || r<=a){
		return;
	}
	if(a<=l && r<=b){
		segtree[i][1] += v;
		eval(i,l,r);
	}else{
		update(a,b,2*i+1,l,(l+r)/2,v);
		update(a,b,2*i+2,(l+r)/2,r,v);
		segtree[i][0] = max(segtree[2*i+1][0],segtree[2*i+2][0]);
	}
}

ll query(int a, int b, int i, int l, int r){
	ll vl,vr;
	eval(i,l,r);
	if(b<=l || r<=a){
		return -INFLL;
	}
	if(a<=l && r<=b){
		return segtree[i][0];
	}else{
		vl = query(a,b,2*i+1,l,(l+r)/2);
		vr = query(a,b,2*i+2,(l+r)/2,r);
		return max(vl,vr);
	}
}

vector<P> t[225816];

int main(void){
	int n,m,l,r,i,j;
	ll a,ans=0ll;
	fill(s,s+225816,0ll);
	fill(segtree[816225],segtree[816225],0ll);
	cin >> n >> m;
	for(i=0; i<m; ++i){
		cin >> l >> r >> a;
		s[l] += a;
		t[r].push_back(P(l,a));
	}
	for(i=1; i<=n; ++i){
		update(0,i,0,0,n+1,s[i]);
		a = query(0,i,0,0,n+1);
		ans = max(a,ans);
		update(i,i+1,0,0,n+1,a);
		for(j=(t[i].l_ength()-1); j>=0; --j){
			update(0,t[i][j].first,0,0,n+1,-t[i][j].second);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 22912
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

int main(){
	int N, mx = 0;
	cin >> N;
	vector<ll> A(N + 1, 0), mv = A, mxv = { 0 }, mxvr(N + 1, -1);
	for (int i = 1;i <= N;i++) {
		cin >> A[i];
		mv[i] = A[i];
		if (mx < A[i]) {
			mx = A[i];
			mxv.push_back(i);
			mxvr[i] = mxv.size() - 1;
		}
	}
	sort(all(mv));

	ll cnt = 0;
	for (int i = 1;i <= N;i++) {
		cnt = 0;
		if (mxvr[i] >= 0) {
			int a = mxvr[i];
			auto it1 = upper_bound(all(mv), A[mxv[a - 1]]);
			auto it2 = upper_bound(all(mv), A[mxv[a]]);
			cnt += (mv.end() - it2)*(A[mxv[a]] - A[mxv[a - 1]]);
			while (it1 != it2) {
				cnt += *it1 - A[mxv[a - 1]];
				it1++;
			}
		}
		cout << cnt << endl;
	}
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

ll N, K;
ll ANS[100100];
vector<ll> G[100100];

void dfs(ll v, ll num, bool first){
    ANS[v] = K - num;
    ll visit = 1 + (!first);
    for(auto&& n : G[v]){
        if(ANS[n] != -1) continue;
        dfs(n, visit, false);
        visit++;
    }
}

int main(){
    cin >> N >> K;
    REP(i,N-1){
        ll a,b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    fill(ANS, ANS+N, -1);
    dfs(0, 0, true);

    ll ans = 1;
    REP(i,N){
        ans *= max(0LL, ANS[i]);
        ans %= MOD;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8872
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
typedef long long ll;

int main()
{
	ll n, m;
	cin >> n >> m;
	ll a, b;
	vector<bool> c(n, false), d(n, false);
	REP(i, m) {
		cin >> a >> b;
		if (a == 1) c[b - 1] = true;
		if (b == n) d[a - 1] = true;
	}
	bool ans = false;
	REP(i, n) {
		if (c[i] && d[i]) {
			ans = true;
			break;
		}
	}
	if (ans) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main(){
	/*for(int i=0;i<5;i++){
		int B[10];
		for(int i=0;i<10;i++){
			cin >> B[i];
			if(B[i] == 0){
				return 0; //プログラムの強制終了
			}
		}

		int sum = 0;

		for(int i=1;i<10;i++){
			sum += B[i];
		}

		cout << B[0] - sum << endl;
	}*/
	/*int s,h,o,p;
	cin >> s >> h >> o >> p;

	cout << (s+h+o+p)/60 << endl << (s+h+o+p)%60 << endl;*/
	int P, A, S, j, u;
	cin >> P >> A >> S >> j >> u;

	int minP=min(P,A);//最も代金が安いパスタ
	int minA=min(minP,S);
	int minj=min(j,u);//最も代金が安いジュース

	cout << (minA + minj)-50 << endl;
	//最も代金が安いパスタとジュースの代金の合計

	return 0;

}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    cin>>N;
    vi H(N);
    rep(i,N) cin>>H.at(i);
    int ans=-999;
    bool ok=true;
    rep(i,N) {
        if(ans<=H.at(i)-1) ans=H.at(i)-1;
        else if(ans<=H.at(i)) ans=H.at(i);
        else ok=false;
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int W,H;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>W>>H;
    vector<pii> vec;
    rep(i,W){
        int x;cin>>x;
        vec.push_back({x,0});
    }
    rep(i,H){
        int x;cin>>x;
        vec.push_back({x,1});
    }
    sort(all(vec));
    
    W++,H++;
    ll sum=0;
    rep(i,vec.size()){
        if(vec[i].second){
            sum+=1ll*vec[i].first*W;
            H--;
        }else{
            sum+=1ll*vec[i].first*H;
            W--;
        }
    }
    cout1(sum)
}

Measured memory_bytes: 2420
#include <stdio.h>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int,int> pi;
typedef long long int ll;
#define F first
#define S second
#define MP make_pair
const int N=5e5+10;
const ll INF=1LL<<60;
ll dis(pi a,pi b){
    ll x=a.F-b.F,y=a.S-b.S;
    return x*x+y*y;
}
int main(){
    int n,lim;
    ll ans=INF;
    pi a[N];
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d%d",&a[i].F,&a[i].S);
    sort(a,a+n);
    lim=min(50,n);
    for(int i=0;i<lim;i++)for(int j=i+1;j<lim;j++)ans=min(ans,dis(a[i],a[j]));
    for(int i=lim;i<n;i++)for(int j=1;j<lim;j++)ans=min(ans,dis(a[i],a[i-j]));
    printf("%lld\n",ans);
}


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

int main()
{
  map<char,int> a;
  a['I'] = 1;
  a['V'] = 5;
  a['X'] = 10;
  a['L'] = 50;
  a['C'] = 100;
  a['D'] = 500;
  a['M'] = 1000;

  string s;
  while(cin >> s)
    {
      int ans = 0;
      for(int i=0;i<s.length();i++)
	{
	  if(i == s.length()-1)
	    {
	      ans += a[s[i]];
	      continue;
	    }
	  if(a[s[i]] >= a[s[i+1]])
	    ans += a[s[i]];
	  else if(a[s[i]] < a[s[i+1]])
	    ans -= a[s[i]];
	}
      cout << ans << endl;
    }
  return 0;
}

Measured memory_bytes: 1184
// 問題URL
//

import java.util.Scanner;
import java.util.Arrays;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer x = Integer.parseInt(scanner.next());
        Integer y = Integer.parseInt(scanner.next());

        Integer kakeru = x * y;
        Integer tasu = x + y;
        Integer hiku = x - y;
        Integer kekka= Math.max(kakeru,tasu);
        System.out.println(Math.max(kekka, hiku));

    }
}

Measured memory_bytes: 21716
def run(N, h):
    start_flg = False
    ret = 0
    for i in range(max(h)):
        start_flg = False
        for j in range(N):
            if h[j] > 0:
                h[j] -= 1
                if not start_flg:
                    start_flg = True
                    ret += 1
            else:
                start_flg = False
    return ret


def main():
    N = int(input())
    h = list(map(int, input().split()))
    print(run(N, h))


if __name__ == '__main__':
    main()


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

int ss[100001];
int tt[100001];

int main(){
	string s,t;
	cin>>s>>t;
	int q;
	cin>>q;
	for(int i=1;i<=s.length();i++){
		if(s[i-1]=='A'){
			ss[i]=ss[i-1]+1;
		}else{
			ss[i]=ss[i-1]+2;
		}
	}
	for(int i=1;i<=t.length();i++){
		if(t[i-1]=='A'){
			tt[i]=tt[i-1]+1;
		}else{
			tt[i]=tt[i-1]+2;
		}
	}
	int a,b,c,d;
	while(q--){
		cin>>a>>b>>c>>d;
		if(abs(ss[b]-ss[a-1]-tt[d]+tt[c-1])%3==0){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
}

Measured memory_bytes: 1664
n, q = gets.split.map(&:to_i)
s = gets.chomp
lrs = [0]
(0..n-2).each{|i| lrs << lrs.last + (s[i,2] == 'AC' ? 1 : 0) }
q.times do
  l, r = gets.split.map(&:to_i)
  puts lrs[r-1] - lrs[l-1]
end


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


signed main() {
  int w, h, c;
  cin >> w >> h >> c;

  if(w == h) {
    cout << c << endl;
    return 0;
  }
  int ans = 1145141919;
  for(int i = 1; i <= min(w, h); i++) {
    if(w % i == 0 && h % i == 0) ans = min(ans, (w / i) * (h / i));
  }
  cout << ans * c << endl;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

const ll N=1e3+10;
ll h,w;
vec idx={1,0};
vec idy={0,1};
vector<string> maze(N);
mat d(N,vec(N,-1));

ll dfs(ll y, ll x) {
  if(d[y][x]>=0) return d[y][x];
  ll res=0;
  for(ll i=0;i<2;i++) {
    ll ny=y+idy[i];
    ll nx=x+idx[i];
    if(ny<h&&nx<w&&maze[ny][nx]=='.') (res+=dfs(ny,nx))%=mod;
  }
  return d[y][x]=res;
}

int main() {
  cin >> h >> w;
  for(ll i=0;i<h;i++) cin >> maze[i];
  d[h-1][w-1]=1;
  cout << dfs(0,0) << endl;
}

Measured memory_bytes: 9472
#include <iostream>
#include <cstdio>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>

using namespace std;

void solve()
{
	int n, m, l;
	cin >> n >> m >> l;
	vector<vector<long long int> > matrix1(n, vector<long long int>(m));
	vector<vector<long long int> > matrix2(m, vector<long long int>(l));
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			cin >> matrix1[i][j];
		}
	}
	for (int i = 0; i < m; ++i)
	{
		for (int j = 0; j < l; ++j)
		{
			cin >> matrix2[i][j];
		}
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < l; ++j)
		{
			long long int sum = 0;
			for (int k = 0; k < m; ++k)
			{
				sum += matrix1[i][k] * matrix2[k][j];
			}
			if (j == l - 1)
			{
				cout << sum;
			}
			else
			{
				cout << sum << " ";
			}
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1376
#include <stdio.h>
int main() {
	int h,i,key[250];
	
	scanf("%d",&h);
	
	for(i=1;i<=h;i++) scanf("%d",&key[i]);
	
	for(i=1;i<=h;i++){
		if(i==1) printf("node 1: key = %d, left key = %d, right key = %d, ",key[i],key[i*2],key[i*2+1]);
		else if((i*2+1)<=h) printf("node %d: key = %d, parent key = %d, left key = %d, right key = %d, ",i,key[i],key[i/2],key[i*2],key[i*2+1]);
		else if(i*2==h) printf("node %d: key = %d, parent key = %d, left key = %d, ",i,key[i],key[i/2],key[i*2]);
		else printf("node %d: key = %d, parent key = %d, ",i,key[i],key[i/2]);
		printf("\n");
	}
	
	return 0;
}



Measured memory_bytes: 2044
object Main extends App {

  import scala.io.StdIn._

  val mod = 1000000007L

  val Array(h, w, k) = readLine.trim.split(' ').map(_.toInt)

  implicit val fibonacci = Array.tabulate(w + 1){_ ⇒ 1L}
  fibonacci(1) = 2L
  for (i ← 2 to w){
    fibonacci(i) = (fibonacci(i - 2) + fibonacci(i - 1)) % mod
  }
  println(
    calPat(h, w, k)
  )
  implicit class ScopeFunc[T](val value: T) {
    def let[A](func: T ⇒ A): A = func(value)
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
  def calUseHorizontal(w: Int, pos: Int)(implicit fibonacci: Array[Long]): Long = {
    if (!(1 until w).contains(pos)) 0L
    else {
      if (pos == 1 || pos == w - 1) if (w >= 3) fibonacci(w - 3) else 1L
      else fibonacci(pos - 2) * fibonacci(w - pos - 2) % mod
    }
  }
  def calNotUse(w: Int, pos: Int)(implicit fibonacci: Array[Long]): Long = {
    if (!(1 to w).contains(pos)) 0L
    else {
      if (pos == 1 || pos == w) if (w >= 2) fibonacci(w - 2) else 1L
      else fibonacci(pos - 2) * fibonacci(w - 1 - pos) % mod
    }
  }
  def calPat(h: Int, w: Int, k: Int)(implicit memo: Array[Array[Option[Long]]] = Array.tabulate(h + 1){_ ⇒ Array.tabulate(w + 1){_ ⇒ None:Option[Long]}}): Long = {
    if (h == 0) if (k == 1) 1L else 0L
    else if (!(1 to w).contains(k)) 0L
    else {
      memo(h)(k) match {
        case Some(r) ⇒ r
        case None ⇒ {
          (calPat(h - 1, w, k + 1) * calUseHorizontal(w, k) + calPat(h - 1, w, k - 1) * calUseHorizontal(w, k - 1) + calPat(h - 1, w, k) * calNotUse(w, k)).let{_ % mod}.also(it ⇒ memo(h)(k) = Some(it))
        }
      }
    }
  }

}


Measured memory_bytes: 25420
#include<iostream>
using namespace std;
int main()
{
    int n, d, x, s = 0, k, p;
    cin >> n >> d >> x;
    int a[n];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++)
    {
        k = 0;
        for(int j = 0; j < d; j++)
        {
            p = a[i] * j + 1;
            if(p <= d)
            k++;
        }
        s = s + k;
    }
    cout << s + x;
    return 0;
}

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

#define mp make_pair
#define pb push_back

#define int int64_t

const int MOD = 998244353;
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,s;
    cin>>n>>s;
    int arr[n+1];
    arr[0]=0;
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
    }

    int ans=0;
    int dp[n+1][s+1];
    for(int i=0;i<=n;i++) {
        for(int j=0;j<=s;j++) {
            dp[i][j]=0;
        }
    }
    for(int i=1;i<=n;i++) {
        if(arr[i]<=s)
            dp[i][arr[i]]+=i;
        for(int j=0;j<=s;j++) {
            if(j+arr[i]<=s) {
                dp[i][j+arr[i]]+=dp[i-1][j];
                dp[i][j+arr[i]]%=MOD;
            }
            dp[i][j]+=dp[i-1][j];
            dp[i][j]%=MOD;
            //cout<<dp[i][j]<<" ";
        }
        //cout<<"\n";
        ans+=(dp[i][s]*(n-i+1));
        ans%=MOD;
        dp[i][s]=0;
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
  
  long long A,B;
  int K;
  cin >> A >> B >> K;

  for(int i = 0;i < K;i++) {
    if(i%2==0) {
      if(A%2!=0) A--;
      B += A/2;
      A /= 2;
    }else {
      if(B%2!=0) B--;
      A += B/2;
      B /= 2;
    }
  }

  cout << A << " " << B << endl;
  
}



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

ans=0

g=0 ; p=0
for  i in range(n):
    if g==p:
        g+=1
        if s[i]=="p": ans-=1
    else:
        if s[i]=="p":
            p+=1 
        else:
            p+=1
            ans+=1
print(ans)


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define MOD 1000000007
typedef long long ll;

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

	ll ans = 1;
	ll cou = 0;
	REP(i, str.size()){
		int now = ((cou % 2 == 0) + (str[i] == 'B')) % 2;

		if(now){
			ans *= cou;
			ans %= MOD;
			cou--;
		}
		else {
			cou++;
		}

		if(cou < 0){
			cout << 0 << endl;
			return 0;
		}
	}

	if(cou != 0){
		cout << 0 << endl;
		return 0;
	}

	for(int i = 1;i <= n;i++){
		ans = (ans * i) % MOD;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
bool overlap(int a, int b, int c, int d){
    if ( d <= a ) return false;
    if ( b <= c ) return false;
    return true;
}
 
int main(void){
  int a, b, s, f, n;
  cin >> a >> b >> n;
  for ( int i = 0; i < n; i++ ){
    cin >> s >> f;
    if ( overlap(a, b, s, f) ){
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 3088
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	char a, b;
	cin >> a >> b;
	if(a < b) cout << "<" << endl;
	else if (a > b) cout << ">" << endl;
	else cout << "=" << endl;
}

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

using namespace std;
const int N=100+10;
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};
int n,a,b;



int main()
{
    cin>>n>>a>>b;
    if(n==1)
    {
        printf("Hello World\n");
    }
    else
    {
        printf("%d\n",a+b);
    }
    return 0;


}


Measured memory_bytes: 256
s = input()

m = False

f_h = s[0:3]
s_h = s[1:4]
               
if f_h.count(f_h[0]) ==3 or s_h.count(s_h[0]) ==3:
    m = True
    
if m:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940