akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

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

char cube[6][8] = { {'.','.','r','r','.','.','.','.'},
					{'.','.','r','r','.','.','.','.'},
					{'g','g','y','y','b','b','w','w'},
					{'g','g','y','y','b','b','w','w'},
					{'.','.','o','o','.','.','.','.'},
					{'.','.','o','o','.','.','.','.'},};

void rotate(char c) {
	char field[6][8];
	REP(i, 6) {
		REP(j, 8) {
			field[i][j] = cube[i][j];
		}
	}

	switch(c) {
	case 'U':
		REP(d, 4) {
			cube[0+dy[d+1]][2+dx[d+1]] = field[0+dy[d]][2+dx[d]];
		}
		REP(i, 8) {
			cube[2][i] = field[2][(i+2)%8];
		}
		break;
	case 'F':
		REP(d, 4) {
			cube[2+dy[d+1]][2+dx[d+1]] = field[2+dy[d]][2+dx[d]];
		}
		cube[1][2] = field[3][1];
		cube[1][3] = field[2][1];
		cube[2][4] = field[1][2];
		cube[3][4] = field[1][3];
		cube[4][2] = field[3][4];
		cube[4][3] = field[2][4];
		cube[2][1] = field[4][2];
		cube[3][1] = field[4][3];
		break;
	case 'R':
		REP(d, 4) {
			cube[2+dy[d+1]][4+dx[d+1]] = field[2+dy[d]][4+dx[d]];
		}
		cube[0][3] = field[2][3];
		cube[1][3] = field[3][3];
		cube[2][3] = field[4][3];
		cube[3][3] = field[5][3];
		cube[4][3] = field[3][6];
		cube[5][3] = field[2][6];
		cube[2][6] = field[1][3];
		cube[3][6] = field[0][3];
		break;
	case 'D':
		REP(d, 4) {
			cube[4+dy[d+1]][2+dx[d+1]] = field[4+dy[d]][2+dx[d]];
		}
		REP(i, 8) {
			cube[3][i] = field[3][(i+6)%8];
		}
		break;
	case 'B':
		REP(d, 4) {
			cube[2+dy[d+1]][6+dx[d+1]] = field[2+dy[d]][6+dx[d]];
		}
		cube[0][2] = field[2][5];
		cube[0][3] = field[3][5];
		cube[2][5] = field[5][3];
		cube[3][5] = field[5][2];
		cube[5][2] = field[2][0];
		cube[5][3] = field[3][0];
		cube[2][0] = field[0][3];
		cube[3][0] = field[0][2];
		break;
	case 'L':
		REP(d, 4) {
			cube[2+dy[d+1]][0+dx[d+1]] = field[2+dy[d]][0+dx[d]];
		}
		cube[0][2] = field[3][7];
		cube[1][2] = field[2][7];
		cube[2][2] = field[0][2];
		cube[3][2] = field[1][2];
		cube[4][2] = field[2][2];
		cube[5][2] = field[3][2];
		cube[2][7] = field[5][2];
		cube[3][7] = field[4][2];
		break;
	default:
		break;
	}
}

int main() {
	string s;
	cin >> s;

	REP(i, s.size()) {
		rotate(s[i]);
	}

	REP(i, 6) {
		REP(j, 8) {
			cout << cube[i][j];
		}
		cout << endl;
	}

	return 0;
}

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

using namespace std;

int main(void)
{
  int n; cin>>n;
  int count=0;
  vector<long int> a(n);
  for(int i=0;i<n;i++){ cin>>a[i]; }
  
  for(;;){
    for(int i=0;i<n;i++){
      if(a[i]%2==0){ a[i]/=2; }
      else{goto END;}
    }
    count++;
  }
  END:
  
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N,A,B;
  
  cin>>N>>A>>B;
  
  if(N*A>=B){
    cout<<B<<endl;
  }
  
  else{
    cout<<N*A<<endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  if(S=="RRR") cout<<3<<endl;
  else if(S=="SSS") cout<<0<<endl;
  else if(S=="RRS"||S=="SRR") cout<<2<<endl;
  else cout<<1<<endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int x, y;

signed main() {
	cin >> x >> y;
	if (x == 0) {
		if (x < y)cout << y - x << endl;
		else cout << x - y + 1 << endl;
	}
	else if (y == 0) {
		if (x < y)cout << y - x << endl;
		else cout << x - y + 1 << endl;
	}
	else if (x <= 0 && y <= 0) {
		if (x < y)cout << y - x << endl;
		else cout << x - y + 2 << endl;
	}
	else if (0 <= x && 0 <= y) {
		if (x < y)cout << y - x << endl;
		else cout << x - y + 2 << endl;
	}
	else cout << 1 + abs(abs(x) - abs(y)) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int a,b,c;
    
    scanf("%d %d %d", &a, &b, &c);
    
    if(a < b && a < c && b < c)
     printf("Yes\n");
     
    else
     printf("No\n");
     
    return (0); 
     
}


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

#define int long long

#define F first
#define S second
#define all(x) (x).begin(), (x).end()

using namespace std;

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

//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    int n, cnt = 0;
    cin >> n;
    int a[n];

    for(int i = 0; i < n; i++)
        cin >> a[i];

    for(int i = 0; i < n; i++)
        for(int j = i+1; j < n; j++)
            for(int k = j+1; k < n; k++)
                if(a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i] && a[i] != a[j] && a[i] != a[k] && a[j] != a[k])
                    cnt++;

    cout << cnt;

    return 0;
}


Measured memory_bytes: 3648
from collections import deque
from typing import List, Optional


def topological_sort(
    graph: List[List[int]], in_degrees: List[int], first_index: int = 0
) -> Optional[List[int]]:
    """Topological sort that uses Kahn's algorithm and is able to detect cycles.
    Returns:
        If the given graph is DAG, a list of sorted vertices is returned.
        Otherwise, if loops are detected, None is returned.
    """
    V = len(graph) + first_index
    order = [i for i in range(first_index, V) if not in_degrees[i]]
    queue = deque(order)

    while queue:
        u = queue.popleft()
        for v in graph[u]:
            in_degrees[v] -= 1
            if not in_degrees[v]:
                queue.append(v), order.append(v)

    return order if len(order) + first_index == V else None


def grl_4_b():
    # https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/4/GRL_4_B
    V, _, *ST = map(int, open(0).read().split())
    graph = [[] for _ in range(V)]
    in_degrees = [0] * V
    for s, t in zip(*[iter(ST)] * 2):
        graph[s].append(t)
        in_degrees[t] += 1

    res = topological_sort(graph, in_degrees)
    print("\n".join(map(str, res)))


if __name__ == "__main__":
    grl_4_b()



Measured memory_bytes: 16992
#include<iostream>
#include<stack>
#include<string>
#include<stdlib.h>

using namespace std;

int main()
{
    stack<int> D;
    string S;

    while(cin>>S)
    {
        if(S=="+" || S=="-" || S=="*")
        {
            int a = D.top();
            D.pop();
            int b = D.top();
            D.pop();

            if(S=="+")
            {
                D.push(a+b);
            }
            if(S=="-")
            {
                D.push(b-a);
            }
            if(S=="*")
            {
                D.push(a*b);
            }
        }else
        {
            D.push(atoi(S.c_str()));
        }
    }
    cout << D.top()<<endl;
    return 0;
}


Measured memory_bytes: 3188
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;

#define MAXN 100000
int N;
int Height[MAXN+5];
vector<int> G[MAXN+5];

bool cmp(int x,int y){
    return Height[x]>Height[y];
}
void dfs(int u){
    for(int i=0;i<int(G[u].size());i++)
        dfs(G[u][i]);
    sort(G[u].begin(),G[u].end(),cmp);
    for(int i=0;i<int(G[u].size());i++)
        Height[u]=max(Height[u],Height[G[u][i]]+i+1);
}

int main(){
    scanf("%d",&N);
    for(int i=2;i<=N;i++){
        int fa;
        scanf("%d",&fa);
        G[fa].push_back(i);
    }
    dfs(1);
    printf("%d",Height[1]);
}


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

typedef long long int Long;
typedef long double Double;
const int MAXN = 1e5 + 3;
const int MOD = 1e9 + 7;

Long a, b, c, d, e, f, MXW;
map<pair<Long,Long>, pair<Long,Long>> M;

bool better(pair<Long,Long> &p, pair<Long,Long> &q) {
	return q.first * p.second >= q.second * p.first;
}

pair<Long,Long> solve(Long sugar, Long total) {
	if(total > f) return { MXW, 0 };

	pair<Long,Long> state(total, sugar);
	if(M.find(state) != M.end()) return M[state];

	Long y = (total - sugar) / 100;

	pair<Long,Long> ans(total, sugar), p;
	p = solve(sugar, total + 100 * a);
	if(better(p, ans)) {
		ans = p;
	}

	p = solve(sugar, total + 100 * b);
	if(better(p, ans)) {
		ans = p;
	}

	if(sugar + c <= y * e) {
		p = solve(sugar + c, total + c);
		if(better(p, ans)) {
			ans = p;
		}
	}

	if(sugar + d <= y * e) {
		p = solve(sugar + d, total + d);
		if(better(p, ans)) {
			ans = p;
		}
	}

	M[state] = ans;
	return ans;
}

int main() {
	scanf("%lld%lld%lld%lld%lld%lld", &a, &b, &c, &d, &e, &f);
	MXW = max((a * 100) * (f / (a * 100)), (b * 100) * (f / (b * 100)));
	pair<Long,Long> ans = solve(0, 0);
	printf("%lld %lld\n", ans.first, ans.second);
	return 0;
}


Measured memory_bytes: 896
import sys

n = int( sys.stdin.readline() )
s = [ False ] * 13
h = [ False ] * 13
c = [ False ] * 13
d = [ False ] * 13
for i in range( 0, n ):
	pattern, num = sys.stdin.readline().split( " " )
	if "S" == pattern:
		s[ int( num )-1 ] = True
	elif "H" == pattern:
		h[ int( num )-1 ] = True
	elif "C" == pattern:
		c[ int( num )-1 ] = True
	elif "D" == pattern:
		d[ int( num )-1 ] = True

for i in range( 0, 13 ):
	if not s[i]:
		print( "S {:d}".format( i+1 ) )
for i in range( 0, 13 ):
	if not h[i]:
		print( "H {:d}".format( i+1 ) )
for i in range( 0, 13 ):
	if not c[i]:
		print( "C {:d}".format( i+1 ) )
for i in range( 0, 13 ):
	if not d[i]:
		print( "D {:d}".format( i+1 ) )

Measured memory_bytes: 4272
#include <iostream>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

  string s; cin >> s;
  int ans = 0;
  rep(i, s.size()-1) {
    if(s[i] != s[i+1]) ans++;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 512
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll a, b;

void solve() {
    if (a * b <= 0) cout << "Zero" << endl;
    else if (a > 0 && b > 0) cout << "Positive" << endl;
    else {
        if (abs(b - a) % 2 != 0) cout << "Positive" << endl;
        else cout << "Negative" << endl;
    }
}

int main() {
    cin >> a >> b;
    solve();
    return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  long long v[n];
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  int a,b,m;
  long long ans = 0;
  for(m=0;m<k;m++){
    for(a=0;a<min(n,k-m)+1;a++){
      for(b=0;b<min(n,k-m)+1-a;b++){
        vector<long long> t;

        for(int i=0;i<a;i++){
          t.push_back(v[i]);
        }
        for(int i=0;i<b;i++){
          t.push_back(v[n-i-1]);
        }

        if(a+b == 0) continue;
        sort(t.begin(),t.end());
        for(int i=0;i<m;i++){
          if(i >= t.size()) break;
          if(t[i] < 0) t[i] = 0;
        }
        long long count = 0;
        for(int i=0;i<t.size();i++) count += t[i];
        ans = max(ans,count);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main(int argc, char *argv[])
{
	int i, total;
	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	for (i = a, total = 0; i < b + 1; i++) {
		if (c%i == 0)
			total++;
	}

	printf("%d\n", total);

	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	long long int n;
	cin >> n;
	if(n == 1){
		int a;
		cin >> a;
		if(a == 0){
			cout << 1 << endl;
			return 0;
		}else{
			cout << 0 << endl;
			return 0;
		}
	}
	vector<long long int> d(n);
	vector<long long int> l(n);
	for(int i=0;i<n;i++){
		l.at(i) = 0;
	}
	for(int i=0;i<n;i++){
		cin >> d.at(i);
		l.at(d.at(i))++;
	}
	if(d.at(0) != 0){
		cout << 0 << endl;
		return 0;
	}
	for(int i=1;i<n;i++){
		if(d.at(i) == 0){
			cout << 0 << endl;
			return 0;
		}
	}
	long long int ans = 1;
	sort(d.begin(),d.end());
	for(int i=1;i<n;i++){
		if(d.at(i) > d.at(i-1)+1){
			cout << 0 << endl;
			return 0;
		}else if(d.at(i) == d.at(i-1)){
			ans *= l.at(d.at(i-1)-1);
			ans %= 998244353;
		}else{
			ans *= l.at(d.at(i)-1);
			ans %= 998244353;
		}
	}
	cout << ans%998244353 << endl;
	return 0;
}

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

using namespace std;

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

	int h,w;

	cin >> h >> w;

	map <int,int> s;
	multiset <int> vals;

	for(int i=0;i<w;i++)
	{
		s[i] = i;
	}
	for(int i=0;i<w;i++)
	{
		vals.insert(0);
	}

	for(int i=0;i<h;i++)
	{
		int l,r;
		cin >> l >> r;
		l-=1;
		auto it = s.lower_bound(l);
		int mr = -1;
		while(it!=s.end() && it->first <= r)
		{
			mr = max(mr,it->second);
			int x = it->first - it->second;
			vals.erase(vals.find(x));
			s.erase(it++);
		}
		if(mr!=-1 && r < w)
		{
			vals.insert(r-mr);
			s[r] = mr;
		}
		int ans = -1;
		if(vals.size() > 0)
		{
			ans = *vals.begin() + i + 1;
		}
		cout << ans << '\n';
	}
	return 0;	
}


Measured memory_bytes: 22384
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>

using namespace std;

int main() 
{
	int n;

	cin >> n;

	cout << (long long)(pow(n, 3.0)) << endl;

	return 0;
}


Measured memory_bytes: 1016
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int[][][] ar = new int[4][3][10];
		int n = sc.nextInt();
		for (int i=0; i<n; i++) {
			int b = sc.nextInt(); int f = sc.nextInt(); int r = sc.nextInt(); int v = sc.nextInt();
			ar[b-1][f-1][r-1] += v;
		}
		
		for (int i=0; i<4; i++) {
			for (int j=0; j<3; j++) {
				StringBuilder sb = new StringBuilder();
				for (int k=0; k<10; k++) {
					sb.append(" "+ar[i][j][k]);
				}
				System.out.println(sb);
			}
			if (i!=3) System.out.println("####################");
		}
	}
}


Measured memory_bytes: 29228
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

const int INF = 1e9;
double w, h;

int main() {
  while(1){
    cin>>h>>w;
    if(w==0&&h==0) break;

    int ansh=h, answ=w;
    bool flag =false;
    for(int th = 1; th <= 150; th++){
      for(int tw = 1; tw <= 150; tw++){
        if(tw <= th) continue;
        int sqSize = tw*tw+th*th;
        if(flag){
          if(answ*answ+ansh*ansh > sqSize || (answ*answ+ansh*ansh==sqSize && th < ansh)){
            if(w*w+h*h > sqSize || (w*w+h*h == sqSize && h >= th)) continue;
            ansh = th; answ = tw;
          }
        }else{
          if(answ*answ+ansh*ansh < sqSize || (answ*answ+ansh*ansh==sqSize && th > ansh)){
            ansh = th; answ = tw;
            flag = true;
          }
        }
      }
    }
    cout<<ansh<<" "<<answ<<endl;
  }
  return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;
const long long INF = 1LL << 60;

int N;
int sum = 0,c = 0;
int a[100010];
bool colors[8];
int main(){
  cin >> N;
  rep(i,N) cin >> a[i];
  rep(i,8) colors[i] = false;
  rep(i,N){
    if(a[i] >= 3200) c++;
    else if(colors[a[i]/400] == false ){
      sum++;
      colors[a[i]/400] = true;
    }
  }
  if(sum == 0){
    sum++;
  	cout << sum << " ";
  	sum = 0;
  }
  else cout << sum << " ";
  //色が8色以上ある時もあるので以下の処理は不必要
  //if(sum + c >= 8) cout << "8" << endl;
  cout << sum + c << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools

N = int(input())
T = list(range(1,N+1))
S = list(itertools.permutations(T, N))
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]

A = S.index(tuple(P))
B = S.index(tuple(Q))
print(abs(A-B))

Measured memory_bytes: 8052
#include <iostream>
#include <string.h>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int ll;
const int MOD = 1e9+7;
int h,w,a,b;
ll f[200010];
ll finv[200010];

ll c(ll n,ll m) {
    ll ret=f[n];
    ret=(ret*finv[n-m])%MOD;
    ret=(ret*finv[m])%MOD;
    return ret;
}

ll calc(ll i,ll j) {
    return c(i+j-2,i-1);
}

ll qp(ll x,ll n) {
    ll ret=1;
    while (n) {
        if (n&1) ret=(ret*x)%MOD;
        n=n>>1;
        x=(x*x)%MOD;
    }
    return ret;
}

int main() {
    scanf("%d%d%d%d",&h,&w,&a,&b);
    memset(f,0,sizeof(f));
    memset(finv,0,sizeof(finv));
    f[0]=finv[0]=1;
    for (int i=1;i<=200000;i++) {
        f[i]=(f[i-1]*i)%MOD;
        finv[i]=qp(f[i],MOD-2);
    }
    ll ans=0;
    for (int i=1;i<=w-b;i++) {
        ans=(ans+(calc(a,i)*calc(h-a,w-i+1))%MOD)%MOD;
        ans=(ans+MOD)%MOD;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 3328
/*
      author : nishi5451
      created: 11.08.2020 23:10:18
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    string s;
    cin >> s;
    if(s[0]=='7' || s[1]=='7' || s[2]=='7')
        cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n); rep(i,n) cin >> a[i];

    bool miman = false;
    ll x = 0;
    for(int i=62;i>=0;i--){
        if(miman || (k & (1ll << i))){
            int one = 0;
            rep(j,n){
                if(a[j] & (1ll << i)){
                    one++;
                }
            }
            int zero = n - one;

            if(zero > one){ // oneにする
                x |= (1ll << i);
            }else{ // zeroにする
                if(k & (1ll<<i)){
                    miman = true;
                }
            }
        }
    }

    //cout << x << endl;
    assert(x <= k);

    ll ans = 0;
    for(int i=0;i<n;i++){
        ans += (x ^ a[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

bool solve(){
	int h, w, n, sr, sc;
	cin >> h >> w >> n >> sr >> sc;
	string s, t;
	cin >> s >> t;
	int rlo = 1, rhi = h, clo = 1, chi = w;

	rrep(i,0,n){
		switch(t[i]){
			case 'U': rhi = min(rhi+1, h); break;
			case 'D': rlo = max(rlo-1, 1); break;
			case 'L': chi = min(chi+1, w); break;
			case 'R': clo = max(clo-1, 1); break;
		}
		switch(s[i]){
			case 'U': rlo++; break;
			case 'D': rhi--; break;
			case 'L': clo++; break;
			case 'R': chi--; break;
		}
		if(rlo > rhi || clo > chi) return false;
	}

	return rlo <= sr && sr <= rhi &&
	   clo <= sc && sc <= chi;
}

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

	cout << (solve() ? "YES" : "NO") << endl;
}


Measured memory_bytes: 920
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
int a[200005];
int ans[200005];
vector<bool> vis(200005);
vector<vector<int>> v(200005);

void dfs(int now, vector<int>& state) {
	vis[now] = true;
	int start_len = state.size();
	pii edit;
	if(start_len == 0 || state.back() < a[now]) {
		state.pb(a[now]);
	}
	else {
		auto it = lower_bound(state.begin(), state.end(), a[now]);
		edit = {it - state.begin(), state[it - state.begin()]};
		state[it - state.begin()] = a[now];
	}
	for(int i : v[now]) {
		if(vis[i]) continue;
		dfs(i, state);
	}
	ans[now] = state.size();
	if(state.size() > start_len) {
		state.pop_back();
	}
	else {
		state[edit.first] = edit.second;
	}
}

int main(void)
{
	int n; cin >> n;
	for(int i=1;i<=n;i++) 
		cin >> a[i];
	for(int i=1;i<n;i++) {
		int x, y;

		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}

	vector<int> state; state.reserve(n+1);
	dfs(1, state);

	for(int i=1;i<=n;i++) {
		cout << ans[i] << endl;
	}


	return 0;
}


Measured memory_bytes: 30164
#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=1e18;

vector<ll>par(2e5+10);
map<ll,ll> si;
void init(ll n) {
  for(ll i=0;i<n;i++) {
    par[i]=i;
    si[i]++;
  }
}

ll root(ll x) {
  if(par[x]==x) {
    return x;
  }
  else {
    return par[x]=root(par[x]);
  }
}

ll size(ll x) {
  return si[root(x)];
}

bool same(ll x, ll y) {
  return root(x)==root(y);
}

void unite(ll x, ll y) {
  if(same(x,y)) return;
  ll temp=size(x);
  si[root(y)]+=temp;
  si[root(x)]=0;
  par[root(x)]=root(y);
}

int main() {
  ll n,m;
  cin >> n >> m;
  init(n+m);
  for(ll i=0;i<n;i++) {
    ll k;
    cin >> k;
    while(k--) {
      ll l;
      cin >> l;
      l--;
      unite(i,l+n);
    }
  }
  for(ll i=0;i<n;i++) {
    if(!same(0,i)) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

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

int main()
{
    long long a,b,c;
    int k;
    cin >> a >> b >> c >> k;
    while(b<=a){
        b=b*2;
        k--;
    }
    while(c<=b){
        c=c*2;
        k--;
    }
    if(k<0){
        cout << "No";
    }
    else
        cout <<"Yes";
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <set>
#include <algorithm>
#include <string>

using namespace std;




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


	set<string> su;

string sy1;
cin.get();
	for(int i=0;i<num;i++)
	{
	
		getline(cin,sy1);
		su.insert(sy1);
	}
	cout<<su.size();
}

Measured memory_bytes: 19204
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

const int mod = 1000000007;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main(){
	FIO
	
	combination C(1e5 + 10);
	int n, m;cin >> n >> m;
	if(n < m)swap(n, m);
	if(n - m > 1)cout << 0;
	else{
		mint choose;
		if(m == n){
			choose = C.fact[n] * C.fact[n] * 2;
		}
		else{
			choose = C.fact[m] * C.fact[n];
		}
		cout << choose.x;
	}
	return 0;
}


Measured memory_bytes: 1792
A,B=map(int,input().split())
if A%2==0:
    if (B*10+9)<25*A//2 or (25*A//2+12)<B*10:
        print("-1")
    else:
        print(max(B*10,25*A//2))
else :
    if (B*10+9)<int(25*A/2)+1 or 25*(A+1)//2-1<B*10:
        print("-1")
    else:
        print(max(B*10,int(25*A/2)+1))
        

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define INF 1000000000

int main()
{
	int n;

	int room[4][3][10] = { 0 };

	int i, j,k;
	int b, f, r, v;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%d%d%d%d", &b, &f, &r, &v);
		room[b-1][f-1][r-1] += v;
	}

	for (i = 0; i < 4; i++)
	{
		for (j = 0; j < 3; j++)
		{
			for (k = 0; k < 10; k++)
			{
				printf(" ");
				printf("%d", room[i][j][k]);
			}
			printf("\n");
		}
		if(i!=3)
			printf("####################\n");
	}

	return 0;
}


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

int main(){
	int a, b, c, d, n, cnt;
	while(cin >> n){
		cnt = 0;
		for(a=0;a<10;a++){
			for(b=0;b<10;b++){
				for(c=0;c<10;c++){
					for(d=0;d<10;d++){
						if(a+b+c+d == n) cnt++;
					}
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
N=int(raw_input())
for i in range(N):
    hand=raw_input().split()
    deck=raw_input().split()
    #defaulthand
    d=0
    points=0
    for i in range(len(hand)):
        if hand[i] in ['T','J','Q','K']:
            hand[i]=10
        elif hand[i]=='A':
            hand[i]=11
        else:
           hand[i]=int(hand[i])
    for i in range(len(deck)):
        if deck[i] in ['T','J','Q','K']:
            deck[i]=10
        elif deck[i]=='A':
            deck[i]=11
        else:
           deck[i]=int(deck[i])
    points=sum(hand)
    if points==21:
        print 'blackjack'
    else:
        while(1):
            if points>21 and 11 in hand:
                hand.remove(11)
                hand.append(1)
                points=points-10
            if (points<17) or (points<18 and 11 in hand):
            	hand.append(deck[d])
            	points=points+deck[d]
                d=d+1
            else:
                break
        if points>21:
            print 'bust'
        else:
            print points

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

int main() {
  int S;
  cin >> S;
  int Hyaku , Ju , Ichi;
  Hyaku = S / 100;
  Ju = S % 100 / 10;
  Ichi = S % 100 % 10;
  cout << Hyaku + Ju + Ichi << endl;
}

Measured memory_bytes: 256
import fractions

#inp = [int(i) for i in input().split()]
inp_ = int(input())

co =0
inp = [int(i) for i in input().split()]

for i in range(len(inp)-2):
    d = []
    d.append(inp[i])
    d.append(inp[i+1])
    d.append(inp[i+2])

    d.sort()

    n = d.index(inp[i+1])

    if n == 1:
        co += 1



print(co)

Measured memory_bytes: 5688
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
  
using namespace std;
  
int main(){
  
    int w,n,left,right;
    scanf("%d",&w);
    int array[w+1];
    for(int i=0;i<w+1;i++)array[i]=i;
    scanf("%d",&n);
  
    for(int i=0;i<n;i++){
        scanf("%d,%d",&left,&right);
        swap(array[left],array[right]);
    }
  
    for(int i=1;i<=w;i++){
        printf("%d\n",array[i]);
    }
  
    return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define maxn 100001
#define mod 1000000007
#define pb push_back
using namespace std;
typedef long long LL;

int n;
LL dp[maxn][2];
vector<int>adj[maxn];

LL f( int u , int dad , int color ) {
	if( dp[u][color] != -1 )
		return dp[u][color];
	dp[u][color] = 1;
	for( int i = 0 ; i < (int) adj[u].size() ; i++ ) {
		LL sum = 0;
		int to = adj[u][i];
		if( to != dad ) {
			sum = f( to , u , 0 );
			if( color == 0 )
				sum = ( sum + f( to , u , 1 ) ) % mod;
			dp[u][color] = ( dp[u][color] * sum ) % mod;
		}
	}
	return dp[u][color];
}

int main() {
	cin >> n;
	for( int i = 1 , x , y ; i < n ; i++ ) {
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	memset( dp , -1 , sizeof(dp) );
	cout << ( f(1,0,0) + f(1,0,1) ) % mod << endl;
}


Measured memory_bytes: 15616
"""
Author: guiferviz
Time: 2020-03-27 14:59:20
"""

import math


def c(n, r):
    if r > n:
        return 0
    return math.factorial(n) / ( math.factorial(r) * math.factorial(n - r) )


def main():
    n, m = map(int, input().split())
    print(int(c(n, 2) + c(m, 2)))


if __name__ == "__main__":
    main()



Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var q = new long[N];
            for (var i = 0; i < N; i++)
            {
                q[i] = ReadLong();
            }

            return q.Sum() - q.Max() / 2;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 27792
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    ll n,m;
    
    cin>>n>>m;
    vector<pair<ll,ll>> v;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        v.push_back(make_pair(a,b));
    }
    sort(v.begin(),v.end());
    ll ansm=0;ll anss=m;
    
    rep(i,v.size()){
        ansm+=(v[i].first)*min(v[i].second,anss);
        anss-=min(v[i].second,anss);
        if(anss==0){
            break;
        }
        
    }
    cout<<ansm<<endl;
return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

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

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

int main() {
	int N; cin >> N;
	vint A(1<<N); cin >> A;

	for (int i = 0; i < N; i++) {
		vint B(1 << (N-i-1));
		for (int j = 0; j < (1<<(N-i)); j += 2) {
			if (A[j] > A[j+1]) {
				B[j>>1] = A[j] - A[j+1];
			} else if (A[j] == A[j+1]) {
				B[j>>1] = A[j];
			} else {
				B[j>>1] = A[j+1] - A[j];
			}
		}
		A = B;
	}
	cout << A[0] << endl;
	return (0);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define rmin(r, x) r = min(r, x);
#define rmax(r, x) r = max(r, x);
#define ends ' '
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main(void) {
    fastio;
    int d, t, s;
    cin >> d >> t >> s;
    cout << (d <= t * s ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 3648
#######################################
def csi(s=gets,spst=" ")
  if s==nil
    return 0
  end
  return s.chomp.split(spst).map(&:to_i)
end
def css(s=gets,spst=" ")
  if s == nil
    raise "nil!"
  end
  return s.chomp.split(spst).map(&:to_s)
end
def ml(n,datatype=:int)
  t = []
  case datatype
  when :int
    n.times do
      t.push(gets.to_i)
    end
  when :str
    n.times do
      t.push(gets.chomp.to_s)
    end
  else
    raise "n!"
  end
end
#######################################

h,a = csi
puts (h.to_f/a.to_f).ceil

Measured memory_bytes: 1788
import sys
import heapq
n, m = map(int, input().split())

nextL = [[] for _ in range(n+1)]
for i in range(2, n+1):
    nextL[i].append([i-1, 0])

INF = 10**18

costs = [INF] * (n+1)
costs[1] = 0

for i in range(m):
    l, r, c = map(int, sys.stdin.readline().split())
    nextL[l].append([r, c])

pc = []
heapq.heappush(pc, (0, 1))

unreach = set(range(1, n+1))

while len(pc) > 0 :
    cost, target = heapq.heappop(pc)
    if cost > costs[target]:
        continue
    for i in nextL[target]:
        nex = i[0]
        cos = i[1]
        if nex in unreach and cost + cos < costs[nex]:
            costs[nex] = cost + cos
            heapq.heappush(pc, (cost+cos, nex))
    unreach.remove(target)

if costs[n] == INF:
    print(-1)
else:
    print(costs[n])

Measured memory_bytes: 89900
#include<cstdio>
#include<string>
using namespace std;

void swap(int *x,int *y){

    int tmp;
    
    tmp=*x;
    *x=*y;
    *y=tmp;
    return;
}

int main(void){
    
    int a[5];
    
    for(int i=0;i<5;i++){
        scanf("%d",&a[i]);
    }
    
    for(int i=0;i<4;i++){
        for(int j=0;j<4-i;j++){
            if(a[j]<a[j+1]) swap(&a[j],&a[j+1]);
        }
    }
    for(int i=0;i<5;i++){
        if(i!=4) printf("%d ",a[i]);
        else printf("%d",a[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1028
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine().Select(x => x - '0').ToArray();

        var dp = new int[4][];
        for (int i = 0; i < dp.Length; ++i)
        {
            dp[i] = new int[10];
        }
        dp[0][0] = 1;
        for (int i = 0; i < s.Length; ++i)
        {
            for (int j = Math.Min(dp.Length - 1, i + 1); j > 0; --j)
            {
                dp[j][s[i]] = 0;
                for (int k = 0; k < dp[j - 1].Length; ++k)
                {
                    dp[j][s[i]] += dp[j - 1][k];
                }
            }
        }
        Console.WriteLine(dp[3].Sum());
    }
}


Measured memory_bytes: 13664
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static int count = 0;
	static int firstCount = 0;
	static int finalCount = 0;

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		String firstNumbers = "";
		String finalNumbers = "";
		for (int i = 0; i < x; i++) {
			int y = sc.nextInt();
			firstNumbers = firstNumbers + y;
		}
		for (int i = 0; i < x; i++) {
			int y = sc.nextInt();
			finalNumbers = finalNumbers + y;
		}
		sc.close();
		sortAllNumbers("", x, new ArrayList<>(), firstNumbers, finalNumbers);
		System.out.println(Math.abs(finalCount - firstCount));
	}

	static String sortAllNumbers(String number, int size, List numberList, String firstNumbers, String finalNumbers) {
		for (int i = 1; i <= size; i++) {
			if (numberList.contains(i))
				continue;
			String numbers = number + i;
			if (numbers.length() == size) {
				numberList.remove(numberList.size() - 1);
				count++;
				if (numbers.equals(firstNumbers)) {
					firstCount = count;
				}
				if (numbers.equals(finalNumbers)) {
					finalCount = count;
				}
				return numbers;
			}
			numberList.add(i);
			numbers = sortAllNumbers(numbers, size, numberList, firstNumbers, finalNumbers);
		}
		if (!numberList.isEmpty())
			numberList.remove(numberList.size() - 1);
		return number;
	}

}


Measured memory_bytes: 39916
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define sortall(obj) sort(ALL(obj));
typedef string str;

#define sts(a) string (a);cin >> a
#define For(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) For(i,0,n)
#define print(a) cout << a << endl

int check(int n){
    if(n==1||n==3||n==5||n==7||n==8||n==10||n==12){
        return 1;
    }else if(n==2){
        return 2;
    }else{
        return 3;
    }
}

int main(){
    int x,y;cin >> x >> y;
    if(check(x)==check(y)){
        print("Yes");
    }else{
        print("No");
    }
    return 0;
}


Measured memory_bytes: 256
a = input()
list_a = a.split(" ")
b = [] #リスト作成
for i in range(len(list_a)):
    b.append(list(list_a[i]))
if b[0][-1] == b[1][0] and b[1][-1] == b[2][0]:
    print("YES")
else:
    print("NO")

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


const int V = 100005;
vector<vec> to(V*2);
bool visited[V*2];
vec cnt;
void dfs(int v){
    if(visited[v]) return;
    visited[v] = true;
    cnt[v/V]++;
    for(auto u: to[v]) dfs(u);
}


void solve() {
    int N; cin >> N;
    rep(i, N){
        int x, y; cin >> x >> y;
        y += V;
        to[x].push_back(y);
        to[y].push_back(x);
    }
    ll ans = 0;
    rep(i, V*2){
        if(visited[i]) continue;
        cnt = vec(2, 0);
        dfs(i);
        ans += (ll)cnt[0]*cnt[1];
    }
    cout << ans - N << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

#pragma GCC optimize("O3")
#pragma GCC target("sse2,avx,avx2,fma")

const long long MOD = 998244353;

long long inv[10000005];
long long invFact[10000005];
//long long fact[10000005];

long long powmod(long long a, long long b){
    long long x = 1;
    long long y = a;
    while(b){
        if(b&1){ x = (x*y)%MOD; }
        y = (y*y)%MOD;
        b >>= 1;
    }
    return x;
}

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

    inv[1] = 1;
    for(int i = 2; i <= N; i ++){
        inv[i] = inv[MOD%i]*(MOD-MOD/i)%MOD;
    }

    //fact[0] = 1;
    //long long factN = 1;
    invFact[0] = 1;
    for(int i = 1; i <= N; i ++){
        //factN = (factN*i)%MOD;
        //fact[i] = (fact[i-1]*i)%MOD;
        invFact[i] = (invFact[i-1]*inv[i])%MOD;
    }

    long long tempPow2 = 1;
    long long ans = 0;
    for(int i = N; i > (N>>1); i --){
        ans += (((tempPow2*invFact[N-i])%MOD) * invFact[i])%MOD;

        tempPow2 <<= 1;
        if(tempPow2 >= MOD){tempPow2 -= MOD;}
    }

    long long factN = powmod(invFact[N], MOD-2);

    ans = (ans+ans)%MOD;
    ans = ans*factN%MOD;
    long long finalAns = (powmod(3, N)-ans+MOD)%MOD;

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


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

int main(){
    int data[4],n[5];
    while(1){
        memset(data,0,sizeof(data));
        cin >> n[0];
        data[n[0]] = 1;
        if(n[0] == 0) break;
        for(int i=1;i<5;i++){
            cin >> n[i];
            data[n[i]] = 1;
        }
        if((data[1] == 1 && data[2] == 1 && data[3] == 1) || (data[1] == 1 && data[2] == 0 && data[3] == 0) || (data[1] == 0 && data[2] == 1 && data[3] == 0) || (data[1] == 0 && data[2] == 0 && data[3] == 1)){
            for(int i=0;i<5;i++) cout << 3 << endl;
        }
        else if(data[1] == 1 && data[2] == 1){
            for(int i=0;i<5;i++){
                if(n[i] == 1) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
        else if(data[2] == 1 && data[3] == 1){
            for(int i=0;i<5;i++){
                if(n[i] == 2) cout << 1 <<endl;
                else cout << 2 <<endl;
            }
        }
        else if(data[1] == 1 && data[3] == 1){
            for(int i=0;i<5;i++){
                if(n[i] == 1) cout << 2 << endl;
                else cout << 1 << endl;
            }
        }
    }
}

Measured memory_bytes: 1160
#include<iostream>

using namespace std;

int n, tu[3][101];

int dp[3][101];

int main(){
	cin>>n;
	for(int i = 1; i <= 2; i++){
		for(int j = 1; j <= n; j++){
			cin>>tu[i][j];
		}
	}
	dp[1][1] = tu[1][1];
	dp[2][1] = dp[1][1] + tu[2][1];
	for(int i = 1; i <= 2; i++){
		for(int j = 2; j <= n; j++){
			if(i == 1){
				dp[i][j] = dp[i][j - 1] + tu[i][j];
			}
			else{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + tu[i][j];
			}
		}
	}
	cout<<dp[2][n]<<endl;
	return 0;
} 

Measured memory_bytes: 256