akhauriyash/Code-Regression huggingface dataset:
#include <cstring>
#include <iostream>
using namespace std;
const int M = 1000000007;

int main() {
    int n, m; cin >> n >> m;
    long long dp[2][n+1][n+1];
    int cur = 0, prev = 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            dp[prev][i][j] = int(i == 1 && j == 1);
    for (int i = 0; i < m; i++) {
        memset(dp[cur], 0, sizeof dp[cur]);
        for (int j = 1; j <= n; j++)
            for (int k = j; k <= n; k++) {
                dp[cur][k][k] += j * dp[prev][j][k] % M;
                dp[cur][j][k] += (k - j) * dp[prev][j][k] % M;
                if (k < n) dp[cur][j][k+1] += (n - k) * dp[prev][j][k] % M;
            }
        swap(cur, prev);
    }
    cout << (dp[prev][n][n] % M + M) % M << endl;
}


Measured memory_bytes: 4584
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	circ, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	pointNum, _ := strconv.Atoi(sc.Text())

	var distance []int = make([]int, pointNum)
	var diffNum []int = make([]int, pointNum)
	var maxNum int = 0
	for i := 0; i < pointNum; i++ {
		sc.Scan()
		distance[i], _ = strconv.Atoi(sc.Text())
		if i != 0 {
			diffNum[i] = distance[i] - distance[i-1]
			if diffNum[i] > maxNum {
				maxNum = diffNum[i]
			}
		}
	}
	diffNum[0] = circ + distance[0] - distance[pointNum-1]
	if diffNum[0] > maxNum {
		maxNum = diffNum[0]
	}

	fmt.Println(circ - maxNum)
}


Measured memory_bytes: 4608
let () =
    let main () =
        let n, m = Scanf.sscanf (read_line ()) "%d %d" (fun n m -> n, m) in
        let lrc = Array.init m (fun _ -> Scanf.sscanf (read_line()) "%d %d %d" (fun l r c -> l, r, c)) in
        Array.sort compare lrc;
        let mm = 1_000_000_000_000_000 in
        let dist = Array.make (n + 2) mm in
        dist.(1) <- 0; 
        Array.iter (fun (l, r, c) ->
            if dist.(l) <> mm then (
                let k = dist.(l) + c in
                let rec loop i =
                    if i > l then (
                        if dist.(i) > k then (
                            dist.(i) <- k; loop (i - 1)
                        )
                    )
                in
                loop r
            )
        ) lrc;
        Printf.printf "%d\n" (if dist.(n) = mm then (-1) else dist.(n))
    in
    main ()

Measured memory_bytes: 7936
package main
import (
  // "bufio"
  // "os"
  // "strconv"
  // "strings"
  "fmt"
  // "math"
  // "sort"
)

// 行単位で読み込む場合
// var sc = bufio.NewScanner(os.Stdin)

func main() {
  var N int
  fmt.Scan(&N)

  if N == 3 || N == 5 || N == 7 {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

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

int main() {
	int n;
	cin >> n;
	vector<int> t(n+1), x(n+1), y(n+1);
	for (int i = 1;i <= n;i++) {
		cin >> t[i] >> x[i] >> y[i];
	}
	t[0] = 0;
	x[0] = 0;
	y[0] = 0;
	for (int i = 1;i <= n;i++) {
		int dt = t[i] - t[i - 1];
		int dx = abs(x[i] - x[i - 1]);
		int dy = abs(y[i] - y[i - 1]);
		int d = dt - dx - dy;
		if (d < 0 || d % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;





	return 0;
}

Measured memory_bytes: 1408
package main
 
import(
  "fmt"
  "sort"
)
 
func main(){
  var a,b,c,d int
  fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
  var ary []int
  
  ary = append(ary, a*c)
  ary = append(ary, a*d)
  ary = append(ary, b*c)
  ary = append(ary, b*d)
  
  sort.Ints(ary)
  
  fmt.Printf("%d",ary[3])
  
  
}

Measured memory_bytes: 1840
"""
author : halo2halo
date : 31, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A,B = map(int, readline().decode('utf8').split())

print((A+B)%24)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
static const int MAX =100;
static const int INFTY =(1<<21);
static const int WHITE =0;
static const int GRAY =1;
static const int BLACK =2;

int n, M[MAX][MAX];

int prim(){
  int u,minv;
  int d[MAX],p[MAX],color[MAX];

  for(int i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;

  while(1){
    minv=INFTY;
    u=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i] && color[i] !=BLACK){
        u=i;
        minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(int v=0;v<n;v++){
      if(color[v] != BLACK && M[u][v]!=INFTY){
        if(d[v]>M[u][v]){
          d[v]=M[u][v];
          p[v]=u;
        }
      }
    }
  }
  int sum=0;
  for(int i=0;i<n;i++){
    if(p[i]!=-1)sum+=M[i][p[i]];
  }
  return sum;
}

int main(){
  cin >> n;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    int e; cin >> e;
    M[i][j]= (e==-1)? INFTY:e;
    }
  }

  cout << prim() << endl;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int)n;i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}
 
int main(){
	//in_o();
	int64 n;
	cin>>n;
	VI a(n);
	FOR(i,0,n){
		int x;
		cin>>x;
		a[i]=x;
	}
	VI b(a);
	sort(a.rbegin(), a.rend());
	int64 mx=a[0],second_mx=a[1];
	FOR(i,0,n){
		if(b[i]==mx)
			cout<<second_mx<<endl;
		else
			cout<<mx<<endl;
	}
	return 0;
}


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

const int64_t lot = 1000000000;

signed main () {
    int64_t s;
    cin >> s; 
    int64_t x = (lot - (s % lot)) % lot, y = (s + x) / lot;
    cout << 0 << ' ' << 0 << ' ' << lot << ' ' << 1 << ' ' << x << ' ' << y << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <iomanip>
#include <math.h>

using namespace std;

long long mod = 1000000007;

long long binpow(long long x, long long k)
{
    if (k == 0)
    {
        return 1LL;
    }
    long long temp = binpow(x, k / 2);
    if (k % 2 == 1)
    {
        return (((temp * temp) % mod) * x) % mod;
    }
    else
    {
        return (temp * temp) % mod;
    }
}

long long modular_inverse(long long x)
{
    return binpow(x, mod - 2);
}

long long binomial(long long n, long long k)
{
    long long rez = 1;
    for (long long i = n - k + 1; i <= n; i++)
    {
        rez *= i;
        rez %= mod;
    }
    long long temp = 1;
    for (long long i = 1; i <= k; i++)
    {
        temp *= i;
        temp %= mod;
    }
    rez *= modular_inverse(temp);
    rez %= mod;
    return rez;
}

int fi(int a, vector<int> &p)
{
    if (p[a] != p[p[a]])
    {
        p[a] = fi(p[a], p);
    }
    return p[a];
}

void uni(int a, int b, vector<int> &p)
{
    int x = fi(a, p), y = fi(b, p);
    if (x != y)
    {
        p[x] = y;
    }
}

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(m), b(m), c(k), d(k), p(n), rez(n, 0), cnt(n, 0);
    for (int i = 0; i < n; i++)
    {
        p[i] = i;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        uni(a[i] - 1, b[i] - 1, p);
    }
    for (int i = 0; i < n; i++)
    {
        cnt[fi(i, p)]++;
    }
    for (int i = 0; i < n; i++)
    {
        rez[i] = cnt[fi(i, p)] - 1;
    }
    for (int i = 0; i < m; i++)
    {
        rez[a[i] - 1]--;
        rez[b[i] - 1]--;
    }
    for (int i = 0; i < k; i++)
    {
        cin >> c[i] >> d[i];
        if (fi(c[i] - 1, p) == fi(d[i] - 1, p))
        {
            rez[c[i] - 1]--;
            rez[d[i] - 1]--;
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << rez[i] << ' ';
    }
    return 0;
}


Measured memory_bytes: 4864
#include<iostream>
using namespace std;
int main(){
	long long  a,b,k;
	cin>>a>>b>>k;
	if(a-k<0){
		if(a+b-k<=0){
			cout<<"0"<<" "<<"0";
		}
		else cout<<"0"<<" "<<a+b-k;
	}
	else cout<<a-k<<" "<<b;
	
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define gnr(i,l,r) for(int i=int(r)-1; i>=int(l); i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
#define prip(p) cout<<p.first<<' '<<p.second<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

Int n,m,_,x,y,q;
string s,sb;
bool ok;
char ch;

vector< long long > divisor(long long n) {
  vector< long long > ret;
  for(long long i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

template<typename T>
bool is_prime(T x) {
  for(T i = 2; i * i <= x; i++) {
    if(!(x%i)) return false;
  }
  return true;
}

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

  cin>>n>>m; n=__gcd(n,m);
  V(Int)di=divisor(n);
  x=di.size();
  int ans=0;
  rep(i,x)ans+=is_prime(di[i]);
  END
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll a, b, k;
  cin >> a >> b >> k;
  if(b-a+1 <= 2*k){
    FORe(i, a, b) cout << i << endl;
  }else{
    REP(i, k) cout << a+i << endl;
    REP(i, k) cout << b-k+i+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
void b(int ,int );
int a[100][100]={};
 
int main(){
  while(1){
    int count=0,w,h;
    cin>>w>>h;
    if(w+h==0)break;
     
    for(int i=1;i<=h;i++)
      for(int j=1;j<=w;j++)
    cin>>a[i][j];
 
    for(int i=1;i<=h;i++)
      for(int j=1;j<=w;j++)
    if(a[i][j]==1){
      b(j,i);
      count++;
    }
    cout<<count<<endl;  
  }
  return 0;
}
 
  void b(int x,int y){
    a[y][x]=0;
    int x1,y1;
    int x2[8]={-1,0,1,1,1,0,-1,-1};
    int y2[8]={1,1,1,0,-1,-1,-1,0};
    for(int k=0;k<8;k++){
    x1=x+x2[k];
    y1=y+y2[k];
    if(a[y1][x1]==1)
      b(x1,y1);
    }
  }

Measured memory_bytes: 1400
N=int(input())
A=list(map(int,input().split()))
count=0
for i in range(1,N-1):
    if A[i]!=max(A[i-1],A[i],A[i+1]) and A[i]!=min(A[i-1],A[i],A[i+1]):
        count +=1
print(count)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
   int n;

   bool ans = true;
   for(int i = 0;i<2;i++){
      cin >> n;
      if(n > 8){ ans = false;
         break;
      }
   }

   cout << (ans ? "Yay!" : ":(") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int n, m;
	cin >> n >> m;
	vector<int>a(m), b(m),road(n);
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		road[a[i]]++;
		road[b[i]]++;
	}
	rep(i, n) {
		cout << road[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define pb push_back
#define endl "\n"

using namespace std;

int main()
{    ios::sync_with_stdio(0); cin.tie(0);
    ll k,n;
    cin>>k>>n;
    ll a[n+1];
    for (int i=0 ; i<n ; i++) cin>>a[i];
    a[n]=a[0]+k;
    ll ans=0; ll m=0;
    for (int i=0 ; i<n ; i++)
    {
        ans+=min(a[i+1]-a[i] , a[i]+k-a[1+i]);
        m=max(m,min(a[i+1]-a[i] , a[i]+k-a[1+i]));
    }
    cout<<ans-m;

    return 0;
}


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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int m = max(max(a, b), c);
	m *= 3;
	while(m%3 || (m-(a+b+c))%2){
		m++;
	}
	m = m-(a + b + c);
	int ans = m/2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val ls = in.map(_.split(' ').map(_.toInt).toIndexedSeq).tail.head

  var ss = ls.distinct.sorted
  var lastMin = Int.MaxValue
  var min = Int.MaxValue
  //var ss = s//.toIndexedSeq
  do {
    //lastMin = min
    lastMin = ss.size
    val d = (1 until ss.size).map(i => ss(i) - ss(i-1))
    //ss ++= d
    //ss = ss.sorted.distinct
    ss = (ss ++ d).distinct.sorted
    min = ss.head
    //println(ss.toSeq)
  //}while(lastMin != min.size)
  }while((lastMin != ss.size) && (min != 1) && (ss.count(e => e % min != 0) != 0))
  println(min)
}


Measured memory_bytes: 48764
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int a=s[0]-'0'; int b=s[1]-'0'; int c=s[2]-'0'; int d=s[3]-'0';
  if(a+b+c+d==7){
    cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
    return 0;
  }
else if(a+b+c-d==7){
    cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
    return 0;
  }
else if(a+b-c+d==7){
    cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
    return 0;
  }
else if(a-b+c+d==7){
    cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
    return 0;
  }
 else if(a+b-c-d==7){
    cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
    return 0;
  }
else if(a-b+c-d==7){
    cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
    return 0;
  }
else if(a-b-c+d==7){
    cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
    return 0;
  }
else if(a-b-c-d==7){
    cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
    return 0;
  }
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        
        int kaisuu = 0;
        for(int i = 0; i < n; i++){
            kaisuu += narabekae(i,a);
        }
        
        for(int i = 0; i < n; i++){
            if(i != n-1){
                System.out.print(a[i]+" ");
            }else{
                System.out.println(a[i]);
            }
        }
        System.out.println(kaisuu);
    }
    
    private static int narabekae(int i, int a[]){
        int kaisuu = 0;
        for(int x = i; x > 0; x--){
            if(a[x-1] > a[x]){
                int a0;
                a0 = a[x-1];
                a[x-1] = a[x];
                a[x] = a0;
                kaisuu += 1;
            }
        }
    	return kaisuu;
    }
}


Measured memory_bytes: 26392
//Pradeep_7
//double tt = clock();
//if((clock()-tt)/CLOCKS_PER_SEC > 1) break;
#include<bits/stdc++.h>
#define mp make_pair 
#define pb push_back
#define fi first
#define se second 
#define IO ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define ll long long int
#define nn cout<<"\n"
#define tcc int tc;	cin>>tc; while(tc--)
#define arr(a,n)	for(int i=0;i<n;i++)		cin>>a[i]
#define all(a)	a.begin(),a.end()
#define rall(a)	a.rbegin(),a.rend()
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	vector<string> a(n);
	arr(a,n);
	sort(all(a));
	for(auto x : a)
	{
		cout<<x;
	}
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin >> H >> W;
  string mas[26][26];
  int px,py;
  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      cin >> mas[i][j];
      if(mas[i][j] == "snuke"){
	px = j;
	py = i;
      }
    }
  }
  cout << (char)(px + 'A') << py + 1<< endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{  long long int a,h[100009];
cin>>a;
long long int Max=0;
cin>>h[1];
long long int count=0;
for(long long int i=2;i<=a;i++)
{
    cin>>h[i];
    if(h[i]<=h[i-1])
         count++;
    else
       {

         Max=max(count,Max);
        count=0;}
        

}
     Max=max(count,Max);
      cout<<Max<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

stack<int> num;
stack<char> cal;

void calc_and(int x,int y){
	if(x==0||y==0) num.push(0);
	else if(x==1||y==1) num.push(1);
	else num.push(2);
}
void calc_or(int x,int y){
	if(x==2||y==2) num.push(2);
	else if(x==1||y==1) num.push(1);
	else num.push(0);
}
void calc_not(){
	int x=num.top(); num.pop();
	if(x==0) num.push(2);
	if(x==1) num.push(1);
	if(x==2) num.push(0);
}
void calc(){
	int x=num.top(); num.pop();
	int y=num.top(); num.pop();
	char c=cal.top(); cal.pop();
	if(c=='+') calc_or(x,y);
	if(c=='*') calc_and(x,y);
}

int main(){
	string s;
	while(cin>>s&&s!="."){
		reverse(s.begin(),s.end());
		int cnt=0;
		for(int p=0;p<3;p++){
			for(int q=0;q<3;q++){
				for(int r=0;r<3;r++){
					for(int i=0;i<(int)s.size();i++){
						if('0'<=s[i]&&s[i]<='2') num.push(s[i]-'0');
						if(s[i]=='P') num.push(p);
						if(s[i]=='Q') num.push(q);
						if(s[i]=='R') num.push(r);
						if(s[i]=='+') cal.push('+');
						if(s[i]=='*') cal.push('*');
						if(s[i]=='-') calc_not();
						if(s[i]=='(') calc();
					}
					int x=num.top(); num.pop();
					if(x==2) cnt++;
				}
			}
		}
		cout<<cnt<<endl;
	}
    return 0;
}



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

int main(){
    int n,m;
    cin>>n>>m;
    int s[m],c[m];
    int a=1,b=0,d=0;
    for(int i=0;i<m;i++){
        cin>>s[i]>>c[i];
        if(s[i]==1)
        a=c[i];
        if(s[i]==2)
        b=c[i];
        if(s[i]==3)
        d=c[i];
    }
    for(int i=0;i<m;i++){
        if(s[i]==1){
            if(c[i]!=0&&a==c[i]){
                a=c[i];
            }
            if(a!=c[i]){
                cout<<-1<<endl;
                return 0;
            }
        }
        if(s[i]==2){
            if(b==c[i]){
                b=c[i];
            }
            if(b!=c[i]){
                cout<<-1<<endl;
                return 0;
            }
        }
        if(s[i]==3){
            if(d==c[i]){
                d=c[i];
            }
            if(d!=c[i]){
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    if(a==1){
        if(n==1&&m==0){
            cout<<0<<endl;
            return 0;
        }
    }
    if(a!=0){
    if(n==3)
    cout<<a<<b<<d<<endl;
    if(n==2)
    cout<<a<<b<<endl;
    if(n==1)
    cout<<a<<endl;
    }
    if(a==0){
        if(n==1)
        cout<<0<<endl;
        if(n==2||n==3)
        cout<<-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
//In the Name of God
//Ya Ali

#include<bits/stdc++.h>

#define int long long

#define err(A) cout<<#A<<" = "<<(A)<<endl

using namespace std;

const int maxn=100100;

int n;

vector<int> g[maxn];

int dfs(int v)
{
  vector<int> q;
  for(int u:g[v])
    q.push_back(dfs(u));
  sort(q.rbegin(),q.rend());
  int ret=0;
  for(int i=0;i<q.size();i++)
    ret=max(ret,q[i]+i+1);
  return ret;
}

int32_t main()
{
  ios::sync_with_stdio(0);cin.tie(0);
  
  cin>>n;

  for(int p,i=1;i<n;i++)
    {
      cin>>p;
      g[p-1].push_back(i);
    }

  cout<<dfs(0)<<endl;
  
  return 0;
}


Measured memory_bytes: 15104
#! /usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)



def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def solve(N: int, A: "List[int]"):
    mx = 0
    ans = 0
    for i in range(N):
        if mx > A[i]:
            ans += mx - A[i]
            A[i] = mx
        
        mx = max(mx,A[i])
 
    print(ans)
 
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)



if __name__ == "__main__":
    main()


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

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

  // vector化すると綺麗だったかもしれない。
  string dream = "dream";
  string dreamer = "dreamer";
  string erase = "erase";
  string eraser = "eraser";

  reverse(s.begin(), s.end());
  reverse(dream.begin(), dream.end());
  reverse(dreamer.begin(), dreamer.end());
  reverse(erase.begin(), erase.end());
  reverse(eraser.begin(), eraser.end());

  string t = "";
  int next = 0;

  while (1) {
    if (next == s.size()) {
      cout << "YES" << endl;
      return 0;
    }
    int i = s.find(dream, next);
    if (i == next) {
      next += dream.size();
      continue;
    }
    i = s.find(dreamer, next);
    if (i == next) {
      next += dreamer.size();
      continue;
    }
    i = s.find(erase, next);
    if (i == next) {
      next += erase.size();
      continue;
    }
    i = s.find(eraser, next);
    if (i == next) {
      next += eraser.size();
      continue;
    }
    cout << "NO" << endl;
    return 0;
  }
}


Measured memory_bytes: 3728
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
#define ll               long long
int main(){
  double a,b,c,d,e,f,g=acos(-1);
  cin>>a>>b>>c>>d;
  e=2*g/12*c+2*g/12/60*d-2*g/60*d;
  f=a*a+b*b-2*a*b*cos(e);
  cout<<fixed<<setprecision(19)<<sqrt(f);
  }


Measured memory_bytes: 4200
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	long long k,a,b;
	cin >> k >> a >> b;

	long long max = 1;

	if(a>=b){
		max = 1 + k;
	}else{
		max = 1 + k;
		long long t1 = a;
		t1 += (k-a+1)/2*(b-a);
		if((k-a+1)%2==1){
			t1++;
		}
		if(max < t1) max = t1;
	}

	printf("%lld\n",max);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long ans=0;
  int n; cin>>n;
  int a[n+1],b,c=0;
  for(int i=0;i<n+1;i++) cin>>a[i];
  for(int i=0;i<n;i++){
    cin>>b;
    ans+=min(c,a[i]);
    a[i]=max(a[i]-c,0);
    ans+=min(b,a[i]);
    c=max(b-a[i],0);
  }
  ans+=min(a[n],c);
  cout<<ans;
}

Measured memory_bytes: 3956
#include <iostream>
            #include <cstdio>
             #include <cstring>
            #include <set>
            using namespace std;
            int main()
            {
               int i=0;
            	char str[30];
            	scanf("%s",str);
                set <char> s;
                while(str[i])
                {
                  s.insert(str[i]);
                  i++;
                }
               if(s.size()==strlen(str))
               printf("yes");
               else
               printf("no");

               
            return 0;
            }

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long N = I.nextLong();
		long A = I.nextLong();
		long B = I.nextLong();
		long ans = Long.MAX_VALUE;
		long diff = B-A;
		if (diff%2==0) ans=Math.min(ans, diff/2);
		ans=Math.min(ans, B-1); //The larger table dude just wins all
		ans=Math.min(ans, N-A); //The smaller table dude just loses all
		
		//Smaller table wins
		if (B-A>=3) {
			long t1 = A; //Time for smaller player to construct an even difference
			long curans = t1;
			long tempB = B-t1;
			curans+=(tempB-1)/2; //The smaller player is at table one and bigger player is at
			//table 1 + 2x for any natural number x
			ans=Math.min(curans, ans);
			//Bigger table loses
			curans = 0;
			long t2 = N-B+1;
			curans+=t2;
			A+=t2;
			curans+=(N-A)/2;
			ans=Math.min(curans, ans);
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(double x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
	}
}


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

int main() {
long long n,k;
cin >> n >>k;
long long h[n];
for(long long i=0;i<n;i++){
    cin >> h[i];
}
sort(h,h+n);
long long ans=0;
for(long long i=0;i<n-k;i++){
    ans+=h[i];
}
cout << ans;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const int N=5e5;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
pair<int,int>p[N];
int bug[N];
int main()
{
	int n=gi(),i,len=0,a,b,Rmax=-1,Rmin=1<<30,Bmax=-1,Bmin=1<<30,k=0,l,r;LL ans;
	for (i=1;i<=n;i++) {
		p[++len]=make_pair(a=gi(),i);
		p[++len]=make_pair(b=gi(),i);
		if (a>b) swap(a,b);
		Rmax=max(Rmax,b);
		Rmin=min(Rmin,b);
		Bmax=max(Bmax,a);
		Bmin=min(Bmin,a);
	}
	ans=1LL*(Rmax-Rmin)*(Bmax-Bmin);
	sort(p+1,p+1+len);
	for (l=r=1;(k+=!bug[p[r].second]++)<n;r++);
	for (;r<=len;++bug[p[++r].second]) {
		while (bug[p[l].second]>1) bug[p[l++].second]--;
		ans=min(ans,1LL*(Rmax-Bmin)*(p[r].first-p[l].first));
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4096
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int x,y;
        for(;;){
            x=sc.nextInt();
            y=sc.nextInt();
            if(x==0&&y==0) break;
            if(x>y){
                System.out.println(y+" "+x);
            }
            if(x<=y){
                System.out.println(x+" "+y);
            }
        }
    }
}


Measured memory_bytes: 35436
X,Y = map(int,input().split())

flag = 0
for i in range(X+1):
    for j in range(X - i +1):
        if((2*i) + (4*j) == Y)&(i+j == X):
            flag = 1
if(flag == 1):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9180
#include "bits/stdc++.h"
using namespace std;


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

	vector<int> arr;
	arr = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

	cout << arr.at(k - 1) << endl;
}



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

class DisjointSet {
public:
    vector<int> p;

    DisjointSet(int n) {
        p.resize(n, 0);
        iota(p.begin(), p.end(), 0);
    }

    int findSet(int x) {
        if (p[x] == x) return x;
        return findSet(p[x]);
    }

    bool same(int x, int y) {
        return (findSet(x) == findSet(y));
    }

    void unite(int x, int y) {
        if (x % 2) {
            p[findSet(x)] = findSet(y);
        } else {
            p[findSet(y)] = findSet(x);
        }
    }
};

int main() {
    ios::sync_with_stdio(false);

    int n, q;
    cin >> n >> q;

    DisjointSet obj(n);
    int com, x, y;
    while (q --) {
        cin >> com >> x >> y;
        if (com == 0) {
            obj.unite(x, y);
        } else {
            cout << (int)obj.same(x, y) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1244
using System;
using System.Collections.Generic;

namespace ProgramingStydying
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var set = new HashSet<int>(); 
            for(int i = 0; i < n; i++)
            {
                set.Add(int.Parse(Console.ReadLine()));
            }
            Console.WriteLine(set.Count);
        }
    }
}

Measured memory_bytes: 27664
#include <stdio.h>
int main(){
int x[50000],i,n,j,sum=1;
for(i=0;i<50000;i++){x[i]=1;}
for(i=2;i*i<50000;i++){
if(x[i]==1){
for(j=2;i*j<50000;j++){
x[i*j]=0;
}}}
while(1){
scanf("%d",&n);
if(n==0) break;
for(i=2;i<n-1;i++){
if(x[i]==1&&x[n-i]==1){
sum++;
continue;
}}
printf("%d\n",sum/2);
sum=1;
}
return 0;
}

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

int calc(int x) {
    int ret = 0;
    while (x > 0) {
        ret += x % 10;
        x /= 10;
    }
    return ret;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int sum = calc(i);
        if (sum >= a && sum <= b)
            ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N, M = tuple(map(int, input().split()))
coins = sorted(tuple(map(int, input().split())))

counts = [float("inf") for _ in range(N+1)]
counts[0] = 0

for m in range(M):
    coin = coins[m]
    for n in range(coin, N+1):
        counts[n] = min(counts[n], counts[n-coin] + 1)

print(counts[-1])

Measured memory_bytes: 9592
c,n = 0,int(raw_input())
def check(v,n):
	return v and n/v == n%v

for d in range(1, (int(n **0.5) +1)):
	if n % d == 0:
		for v in set([d, n/d]):
			if check(v-1,n):
				c += v-1

print c

Measured memory_bytes: 85164
#include <cstdio>

int n;

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;

const int coin[4] = { 1, 5, 10, 25 };

void greedy(int& minv, int& acc, int coin)
{
    minv += acc / coin;
    acc %= coin;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int mincoin = 0;
    rep(i, 4) {
        greedy(mincoin, n, coin[3- i]);
    }
    cout << mincoin << endl;

    return 0;
}


Measured memory_bytes: 3204
N, K = map(int, input().split())
A = list(map(int, input().split()))

def is_ok(x):
    cnt = 0
    for a in A:
        cnt += a // x
        if a % x == 0:
            cnt -= 1
    return cnt <= K

ng = 0
ok = 10**9
while ok - ng > 1:
    mid = (ok + ng) // 2
    if is_ok(mid):
        ok = mid
    else:
        ng = mid
print(ok)

Measured memory_bytes: 93928
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

struct rest
{
   string name;
   int point;
   int num;
};

bool cmp(rest a,rest b)
{
   for(int i = 0;i<a.name.size()&&i<b.name.size();i++)
   {
      if(a.name[i]!=b.name[i])return a.name[i]<b.name[i];
   }
   if(a.name.size()!=b.name.size())return a.name.size()<b.name.size();
   return a.point > b.point;
}



int main()
{
   int n;cin >> n;
   vector<rest> vec(n);
   vector<rest> odr(n);
   rep(i,n)
   {
      string foo;
      int hoge;
      cin >> foo >> hoge;
      vec[i].name=foo;
      vec[i].point=hoge;
      odr[i].name=foo;
      odr[i].point=hoge;
      vec[i].num=i;
   }
   sort(ALL(vec),cmp);
   rep(i,n)
   {
      //cout<<vec[i].name<<vec[i].point<<endl;
      cout<<vec[i].num+1<<endl;
   }
   /*
   rep(i,n)rep(j,n)
   {
      if(odr[i].name==vec[j].name&&odr[i].point==vec[j].point)cout<<vec[j].num+1<<endl;
   }*/


   return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;

/*
ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}*/

int n;
vector<bool>ans;
int main(){
	cin >> n;
	if (n == 0) {
		cout << 0 << endl;
		return 0;
	}
	while (n != 0) {
		if (n < 0) {
			n = -n;
			if (n % 2 == 0) {
				ans.push_back(false);
				n = n / 2;
			}
			else {
				ans.push_back(true);
				n = n / 2 + 1;
			}
		}
		else {
			if (n % 2 == 0) {
				ans.push_back(false);
				n = n / 2;
				n = -n;
			}
			else {
				ans.push_back(true);
				n = n / 2;
				n = -n;
			}
		}
	}
	for (int i = ans.size() - 1; i >= 0; i--) {
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
/*
 * Author : Sadi
 * Fri 03/07/2020
 * 23:09:31.01
 */
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int a, b, c;
    cin >> a >> b >> c;
    cout << .5 * a * b << endl;

    return 0;
}


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

ll C, D;

ll warikirenai(ll x){
    ll c = x / C;
    ll d = x / D;
    ll e = __gcd(C, D);
    e = C*D / e;
    e = x / e;
    return x - c - d + e;
}

int main() {
    ll A, B; cin >> A >> B;
    cin >> C >> D;

    ll ans = warikirenai(B) - warikirenai(A-1);

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
	int q;
	vector<int> res;
	cin >> q;
	res.resize(q);
	for (int i = 0; i < q; i++) {
		int L[1001][1001];
		string x, y;
		cin >> x >> y;
		for (int j = 0; j <= x.length(); j++) {
			for (int k = 0; k <= y.length(); k++) {
				if (j == 0 || k == 0)
					L[j][k] = 0;
				else if (x.at(j-1) == y.at(k-1))
					L[j][k] = L[j - 1][k - 1] + 1;
				else
					L[j][k] = max(L[j][k - 1], L[j - 1][k]);
			}
		}
		res[i] = L[x.length()][y.length()];
	}
	for (int i = 0; i < q; i++)
		cout << res[i] << endl;
}

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

int main(){
  int n,taro=0,hanako=0;
  cin>>n;
  string  s1,s2;
  for(int i=0;i<n;i++){
    cin>>s1>>s2;
    if(s1>s2){
      taro+=3;
    }else if(s1==s2){
      taro++;
      hanako++;
    }else{
      hanako+=3;
    }
  }
  cout<<taro<<" "<<hanako<<endl;
  return 0;
}
      

  


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> s(A), t(B), x(Q);
    REP(i, A)
    {
        cin >> s[i];
    }
    REP(i, B)
    {
        cin >> t[i];
    }
    REP(i, Q)
    {
        cin >> x[i];
    }
    
    REP(i, Q)
    {
        vector<ll> indexS, indexT;

        auto itS = lower_bound(ALL(s), x[i]);
        if (itS == s.end())
        {
            indexS.push_back(A - 1);
        }
        else if (itS == s.begin())
        {
            indexS.push_back(0);
        }
        else
        {
            ll dist = distance(s.begin(), itS);
            indexS.push_back(dist);
            indexS.push_back(dist - 1);
        }

        auto itT = lower_bound(ALL(t), x[i]);
        if (itT == t.end())
        {
            indexT.push_back(B - 1);
        }
        else if (itT == t.begin())
        {
            indexT.push_back(0);
        }
        else
        {
            ll dist = distance(t.begin(), itT);
            indexT.push_back(dist);
            indexT.push_back(dist - 1);
        }

        ll ans = LONG_MAX;
        REP(j ,2)
        {
            REP(k, indexS.size())
            {
                REP(l, indexT.size())
                {
                    if (j == 0)
                    {
                        ans = min(ans, abs(x[i] - s[indexS[k]]) + abs(s[indexS[k]] - t[indexT[l]]));
                    }
                    else
                    {
                        ans = min(ans, abs(x[i] - t[indexT[l]]) + abs(t[indexT[l]] - s[indexS[k]]));
                    }
                }
            }
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 3712
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

const int MOD = 1000000007;

ll modpow(ll a, ll n) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        ll h = modpow(a, n / 2);
        return h * h % MOD;
    } else {
        return a * modpow(a, n - 1) % MOD;
    }
}

ll comb(int a, int b) {
    if (b > a - b) {
        return comb(a, a - b);
    }
    ll m = 1, d = 1;
    REP(i, b) {
        m *= (a - i);
        d *= (b - i);
        m %= MOD;
        d %= MOD;
    }
    return m * modpow(d, MOD - 2) % MOD;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M, K;
    cin >> N >> M >> K;
    ll res = 0;
    REP(i, M) {
        res += N * N * i * (M - i);
        res %= MOD;
    }
    REP(j, N) {
        res += M * M * j * (N - j);
        res %= MOD;
    }
    cout << res * comb(N * M - 2, K - 2) % MOD << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import bisect
n = ni()
s = ns()

r,g,b = [],[],[]

for i in range(n):
    if s[i] == 'R':
        r.append(i)
    elif s[i] == 'G':
        g.append(i)
    else:
        b.append(i)

ans = 0


for i in range(n):
    if s[i] == 'R':
        p = bisect.bisect_right(g,i)
        for j in range(p,len(g)):
            q = bisect.bisect_right(b,g[j])
            ans += (len(b)-q)
            if g[j]*2-i < n and s[g[j]*2-i] == 'B':
                ans -= 1
        y = bisect.bisect_right(b,i)
        for j in range(y,len(b)):
            q = bisect.bisect_right(g,b[j])
            ans += (len(g)-q)
            if b[j]*2-i < n and s[b[j]*2-i] == 'G':
                ans -= 1
    elif s[i] == 'G':
        p = bisect.bisect_right(r,i)
        for j in range(p,len(r)):
            q = bisect.bisect_right(b,r[j])
            ans += (len(b)-q)
            if r[j]*2-i < n and s[r[j]*2-i] == 'B':
                ans -= 1
        p = bisect.bisect_right(b,i)
        for j in range(p,len(b)):
            q = bisect.bisect_right(r,b[j])
            ans += (len(r)-q)
            if b[j]*2-i < n and s[b[j]*2-i] == 'R':
                ans -= 1
    else:
        p = bisect.bisect_right(g,i)
        for j in range(p,len(g)):
            q = bisect.bisect_right(r,g[j])
            ans += (len(r)-q)
            if g[j]*2-i < n and s[g[j]*2-i] == 'R':
                ans -= 1
        p = bisect.bisect_right(r,i)
        for j in range(p,len(r)):
            q = bisect.bisect_right(g,r[j])
            ans += (len(g)-q)
            if r[j]*2-i < n and s[r[j]*2-i] == 'G':
                ans -= 1
    
print(ans)

Measured memory_bytes: 72684
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  string s; cin >> s;
  int n = s.size();
  int ans = 0;
  for(int i = 0; i < n/2; i++){
    if(n%2 == 1 && i == n/2) continue;
    if(s[i] != s[n-i-1]) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256