akhauriyash/Code-Regression huggingface dataset:
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]); var wmax = int.Parse(line[1]);
        var vaL = new int[n + 1]; var w = new int[n + 1];
        var vmax = readData(vaL, w);
        var dp = new long[n + 1, n * vmax + 1];
        setDP(dp);
        for (int i = 0; i < n; i++)
            for (int j = 0; j <= n * vmax; j++)
                if (j < vaL[i]) dp[i + 1, j] = dp[i, j];
                else dp[i + 1, j] = Math.Min(dp[i, j], dp[i, j - vaL[i]] + w[i]);
        var ans = 0;
        for (int i = 0; i <= n * vmax; i++)
            if (dp[n, i] <= wmax) ans = i;
        Console.WriteLine(ans);
    }
    public static int readData(int[] vaL, int[] w)
    {
        for (int i = 0; i < vaL.Length - 1; i++)
        {
            string[] line2 = Console.ReadLine().Trim().Split(' ');
            vaL[i] = int.Parse(line2[0]);
            w[i] = int.Parse(line2[1]);
        }
        return vaL.Max();
    }
    public static void setDP(long[,] dp)
    {
        for (int i = 0; i < dp.GetLength(1); i++)
            dp[0, i] = 9999999999;
        dp[0, 0] = 0;
    }
}

Measured memory_bytes: 17376
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <cstdio>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;
typedef pair<pll,pll> plll;
template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}


pair<plll,plll> cakecut(plll a,int s){
	ll b=a.F.F,c=a.F.S,w=a.S.F,d=a.S.S;
	// cout<<w<<" "<<d<<endl;
	plll ansa,ansb;
	while(1){
		// cout<<s<<" "<<w<<" "<<d<<endl;
		if(s<=w){
			ansa.S.F=s;
			ansa.S.S=d;
			ansb.S.F=w-s;
			ansb.S.S=d;
			ansa.F.S=s*d;
			ansb.F.S=d*(w-s);
			break;
		}
		else s-=w;
		if(s<=d){
			ansa.S.F=w;
			ansa.S.S=s;
			ansb.S.F=w;
			ansb.S.S=d-s;
			ansa.F.S=w*s;
			ansb.F.S=w*(d-s);
			break;
		}
		else s-=d;
	}
	return mkp(ansa,ansb);
}

int main(){
	ll n,w,d;
	while(cin>>n>>w>>d,n||w||d){
		vector<plll>  v;
		v.PB(mkp(mkp(-1,w*d),mkp(w,d)));
		rep(i,n){
			ll p,s;
			cin>>p>>s;
			p--;
			// cout<<w<<" "<<d<<endl;
			pair<plll,plll> t = cakecut(v[p],s);
			// cout<<"t "<<t.F.F.F<<" "<<t.F.F.S<<" "<<t.F.S.F<<" "<<t.F.S.S<<" - "<<t.S.F.F<<" "<<t.S.F.S<<" "<<t.S.S.F<<" "<<t.S.S.S<<endl;
			t.F.F.F=i;
			t.S.F.F=i;
			v[p]=t.F;
			v.PB(t.S);
			sort(ALL(v));
		}
		vector<ll> vv;
		rep(i,v.size()){
			// if(i) cout<<" ";
			vv.PB(v[i].F.S);
		}
		sort(ALL(vv));
		rep(i,vv.size()){
			if(i) cout<<" ";
			cout<<vv[i];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1228
// ------------------------------------
// Date:2018/ 3/ 7
// Problem:ABC 078 HEX a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

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

  char X, Y;
  cin >> X >> Y;

  char ans;
  if (X == Y) ans = '=';
  else if (X < Y) ans = '<';
  else ans = '>';

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 5;
ll pos[maxn], arr[maxn];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    ll ans = 1, zero = 0;
    bool flag = 1;
    for (int i = 0; i < n && flag; ++i) {
        cin >> arr[i];
        if (arr[i] == 0)
            ++zero;
        ++pos[arr[i]];
        if (pos[arr[i]] > 3)
            flag = 0;
        if (arr[i]) {
            ans = ans * pos[arr[i] - 1] % mod;
            --pos[arr[i] - 1];
            if (pos[arr[i] - 1] == -1)
                flag = 0;
        }
    }
    if (zero < 1 || zero > 3)
        flag = 0;
    if (zero == 1)
        ans = ans * 3LL % mod;
    else if (zero > 1)
        ans = ans * 6LL % mod;
    if (!flag)
        cout << 0 << '\n';
    else
        cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1792
import sys
readline = sys.stdin.buffer.readline

N = int(readline())
H = list(map(int, readline().split()))

if N == 1:
    print(0)
    exit()

dp = [0] * N

for i in range(N-2, -1, -1):
    if H[i] >= H[i+1]:
        dp[i] = 1 + dp[i+1]

print(max(dp))

Measured memory_bytes: 12528
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner stdIn = new Scanner(System.in);
		
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		
		System.out.print(a/b+" ");
		System.out.print(a%b+" ");
		System.out.printf("%.5f",(double)a/b);
	}

}

Measured memory_bytes: 17344
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <numeric>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

#define rep(i,n) for(int i = 0; i<n ; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)
#define REPSTR(i,s) for(int i=0; (s)[i]; i++)
#define REPITR(i,s) for(auto i=(s)begin(); i!=(s).end();i++)

#define RANGE(a,i,b) ((a)<=(i)&&(i)<=(b))

#define pb push_back
#define mp make_pair

#define ALL(a) (a).begin(), (a).end()

#define EXIST(s,x) ((s).find(x)!=(s).end())

#define SET(a,c) memset(a,c,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))

#ifdef _DEBUG
#define DEBUG(x) cerr<<#x<<":"<<x<<endl
#else
#define DEBUG(x)
#endif

#define PRINTJOIN(x,n) rep(i,n){if(i)cout<<" ";cout<<x[i];}cout<<endl 

#define INF 1001001001
#define LLINF 1001001001001001001LL

typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef stringstream SS;

#define PQ priority_queue

#define FST first
#define SEC second

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

//------------------HEAD---------------------

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	cout<<n*800-(n/15*200)<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
L = [0]*N
for X in range(1,101):
    for Y in range(1,101):
        for Z in range(1,101):
            Num = X*X+Y*Y+Z*Z+X*Y+X*Z+Y*Z
            if Num>N: break
            else: L[Num-1] += 1
print('\n'.join(str(X) for X in L))

Measured memory_bytes: 9452
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

int main(){
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.rbegin(),t.rend());
  if(s<t){ cout << "Yes" << endl; }else{cout << "No" << endl;}
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> G[n];
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    cout << "Yes\n";
    vector<int> ans(n, 0);
    ans[0] = 1;

    queue<int> que;
    que.push(0);

    while(que.size()) {
        int p = que.front();
        que.pop();
        for (auto &v : G[p]) {
            if (ans[v]) continue;
            que.push(v);
            ans[v] = p + 1;
        }
    }

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

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

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

int main (){
    int d;
    cin >> d;
    if(d==25){cout << "Christmas" << endl;}
    if(d==24){cout << "Christmas Eve" << endl;}
    if(d==23){cout << "Christmas Eve Eve" << endl;}
    if(d==22){cout << "Christmas Eve Eve Eve" << endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define M 1000000
using namespace std;

//vector<ll> ;

void answer(){
    ll n,m,ans1=0,x;
    cin>>n>>m;
    std::vector<ll> v;
    for(int i=0;i<m;i++){
        cin>>x;
        v.pb(x);
    }
    sort(v.begin(),v.end());
    v.pb(n+v[0]);
    
    ll ma=0;
    for(int i=0;i<m;i++){
        ma = max(ma,abs(v[i]-v[i+1]));
    }
    
    cout<<n-ma;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int q;
    //cin>>q; while(q--)
        answer();
    return 0;
}

Measured memory_bytes: 2420
N=int(input())
T,A=map(int, input().split())
H=list(map(int, input().split()))
c=10000000
n=0
for i in range(N):
  d=abs(A-(T-(H[i]*0.006)))
  if c>d:
    c=d
    n=i+1
print(n)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
long long int a,b;
int main()
{
    cin>>a>>b;
    if((a-b)<0)
    {
    	cout<<"0"<<endl;
    	return 0;
	}
    cout<<a-b<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <limits>

using namespace std;

static int INF = numeric_limits<int>::max();

bool done(const vector<int>& U, int X) {
  for (int i = 0; i < U.size(); i++) {
    if (U[i] < X) {
      return false;
    }
  }
  return true;
}

int dfs(const vector<vector<int>>& v, vector<int> U, int X, int idx, int sum, int N) {
  if (idx == N) {
    if (done(U, X)) {
      return sum;
    } else {
      return -1;
    }
  }
  // donot buy
  // int db = dfs(v, U, X, idx + 1, sum, N, result);
  int db = dfs(v, U, X, idx + 1, sum, N);
  // if (db != -1) {
  //   result = min(result, db);
  // }

  // buy
  // cout << idx << endl;
  const vector<int>& CA = v[idx];
  // cout << CA[0] << endl;
  for (int i = 1; i < CA.size(); i++) {
    U[i-1] += CA[i];
  }
  // int buy = dfs(v, U, X, idx + 1, sum + CA[0], N, result);
  int buy = dfs(v, U, X, idx + 1, sum + CA[0], N);
  // cout << "buy: " << buy << endl;

  // if (buy != -1) {
  //   result = min(result, buy);
  // }

  // cout << "db " << db << "vs buy " << buy << endl;

  if (db == -1) {
    db = INF;
  }
  if (buy == -1) {
    buy = INF;
  }
  int result = min(db, buy);

  return (result == INF) ? -1 : result;
  // return result;
}

int main() {
  int N, M, X;

  cin >> N >> M >> X;

  vector<vector<int>> v(N);
  vector<int> U(M, 0);

  for (int i = 0; i < N; i++) {
    int C;
    cin >> C;
    vector<int> CA(M+1);
    CA[0] = C;
    for (int j = 1; j <= M; j++) {
      int A;
      cin >> A;
      CA[j]= A;
    }
    v[i] = CA;
  }

  // for (int i = 0; i < v.size(); i++) {
  //   const vector<int>& CA = v[i];
  //   for (int j = 0; j < CA.size(); j++) {
  //     cout << CA[j] << " ";
  //   }
  //   cout << endl;
  // }

  // dfs(v, U, X, 0, 0, N, numeric_limits<int>::max());
  int result = dfs(v, U, X, 0, 0, N);

  cout << result << endl;
  
  return 0;
}
 


Measured memory_bytes: 3220
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s1, s2, s3 string
	fmt.Scan(&s1, &s2, &s3)
	ans := ""
	ans = s1[0:1] + s2[0:1] + s3[0:1]
	final_ans := strings.ToUpper(ans)
	fmt.Println(final_ans)
}

Measured memory_bytes: 640
import sys

def I(): return int(sys.stdin.readline().rstrip())

T = I()
mod = 10**9+7

for i in range(T):
    N = I()
    if N % 2 == 0:
        M = N//2+1
        a = pow(M,15,mod)*pow(1277025750,mod-2,mod)
        a %= mod
        a += pow(M,14,mod)*pow(48648600,mod-2,mod)
        a %= mod
        a += pow(M,13,mod)*29*pow(145945800,mod-2,mod)
        a %= mod
        a += pow(M,12,mod)*pow(1425600,mod-2,mod)
        a %= mod
        a += -pow(M,11,mod)*571*pow(449064000,mod-2,mod)
        a %= mod
        a += -pow(M,10,mod)*pow(62208,mod-2,mod)
        a %= mod
        a += -pow(M,9,mod)*6269*pow(228614400,mod-2,mod)
        a %= mod
        a += pow(M,8,mod)*109*pow(1360800,mod-2,mod)
        a %= mod
        a += pow(M,7,mod)*23227*pow(81648000,mod-2,mod)
        a %= mod
        a += -pow(M,6,mod)*7*pow(518400,mod-2,mod)
        a %= mod
        a += -pow(M,5,mod)*301729*pow(359251200,mod-2,mod)
        a %= mod
        a += -pow(M,4,mod)*4409*pow(8553600,mod-2,mod)
        a %= mod
        a += pow(M,3,mod)*1081139*pow(1513512000,mod-2,mod)
        a %= mod
        a += pow(M,2,mod)*10037*pow(21621600,mod-2,mod)
        a %= mod
        a += -pow(M,1,mod)*47*pow(360360,mod-2,mod)
        a %= mod
        print(a)
    else:
        M = N//2+1
        a = pow(M,15,mod)*pow(1277025750,mod-2,mod)
        a %= mod
        a += pow(M,14,mod)*pow(37837800,mod-2,mod)
        a %= mod
        a += pow(M,13,mod)*53*pow(145945800,mod-2,mod)
        a %= mod
        a += pow(M,12,mod)*pow(399168,mod-2,mod)
        a %= mod
        a += pow(M,11,mod)*319*pow(40824000,mod-2,mod)
        a %= mod
        a += -pow(M,10,mod)*11*pow(3628800,mod-2,mod)
        a %= mod
        a += -pow(M,9,mod)*21893*pow(228614400,mod-2,mod)
        a %= mod
        a += -pow(M,8,mod)*31*pow(141120,mod-2,mod)
        a %= mod
        a += pow(M,7,mod)*9307*pow(81648000,mod-2,mod)
        a %= mod
        a += pow(M,6,mod)*3769*pow(3628800,mod-2,mod)
        a %= mod
        a += pow(M,5,mod)*297287*pow(359251200,mod-2,mod)
        a %= mod
        a += -pow(M,4,mod)*4841*pow(3991680,mod-2,mod)
        a %= mod
        a += -pow(M,3,mod)*87223*pow(56056000,mod-2,mod)
        a %= mod
        a += pow(M,2,mod)*6631*pow(16816800,mod-2,mod)
        a %= mod
        a += pow(M,1,mod)*23*pow(32760,mod-2,mod)
        a %= mod
        print(a)


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

typedef long long int ll;

int main()
{
    ll h, w, n;
    cin >> h >> w >> n;
    ll t = max(h ,w);
    ll ans = n / t;
    if(n % t != 0){
        ans++;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 200010;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1e25;
const int MOD = 1000000007;

ll cards[MAX];

void solve(void){
    int N;
    cin >> N;
    ll sum = 0LL;
    rep(N, i) {
        scanf("%lld\n", &cards[i]);
        sum += cards[i];
    }
    ll dif = INF, asum = 0LL;
    Rep(0, N-2, n) {
        asum += cards[n];
        dif = min(dif, abs((sum-asum)-asum));
    }
    cout << dif << '\n';
}

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


Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){

  vector<int> a, b;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++){
    int k;
    cin >> k;
    a.push_back(k);
  }
  for (int i = 0; i < n; i++){
    int k;
    cin >> k;
    b.push_back(k);
  }

  int d[51][51];
  for (int i = 0; i < 51; i++) {
    //printf("%2d: ", i);
    for (int j = 0; j < 51; j++) {
      d[i][j] = 100;
      if (j == 0) d[i][j] = 1;
      if (i < j) d[i][j] = -1;
      else if (i == j) d[i][j] = 0;
      else {
        for (int k = 2; k < i; k++) {
          if (d[i%k][j] >= 0) {
            d[i][j] = min(d[i][j], k);
          }
        }
        if (d[i][j] == 100) d[i][j] = -1;
      }
      //printf("%2d ", d[i][j]);
    }
    //printf("\n");
  }

  long long ans = 0;
  vector<int> v[51];
  for (int i = 0; i < n; i++){
    v[i].push_back(a[i]);
  }

  while (true) {
    int ma = -1;
    //printf("\n");
    for (int i = 0; i < n; i++){
      int jmi = 100;
      for (int j = 0; j < v[i].size(); j++){
        //printf("%d\t", v[i][j]);
        int q = d[v[i][j]][b[i]];
        if (q == -1) {
          ma = -1;
          break;
        }
        jmi = min(jmi, q);
      }
      //printf("\n");
      if (jmi == 100){
        ma = -1;
        break;
      }
      ma = max(jmi, ma);
    }
    if (ma == 0) break;
    if (ma == -1) {
      printf("-1\n");
      return 0;
    }
    ans += pow(2, ma);
    for (int i = 0; i < n; i++){
      int u = v[i].size();
      for (int j = 0; j < u; j++){
        if (d[v[i][j]%ma][b[i]] == -1) continue;
          v[i].push_back(v[i][j]%ma);
      }
      sort( v[i].begin(), v[i].end() );
	    v[i].erase( unique( v[i].begin(), v[i].end() ), v[i].end() );
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import itertools
 
n = int(input())
A = list(map(int,input().split()))
A.sort()
 
def binary_search(l,r,v):
    while r >= l:
        h = (l+r) // 2
        if A[h] < v:
            l = h+1
        else:
            r = h-1
    return r
 
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = binary_search(j,n-1,A[i]+A[j])
        ans += a-j
 
print(ans)

Measured memory_bytes: 73744
# coding: utf-8
def calculate_msb(maximum):
    msb = 0
    while (maximum // 2) != 0:
        maximum = maximum // 2
        msb += 1
    return msb
    
def examine(beauties, msb, threshold):
    count = 0
    mask = 2 ** msb
    passed = []
    for beauty in beauties:
  	    if (beauty & mask) == mask:
  	        passed.append(beauty)
  	        count += 1
    return (passed, mask) if count >= threshold else (beauties, 0)

n, threshold = map(int, input().split())
array = [int(element) for element in input().split()]
beauties = []
for i in range(n):
    for j in range(i+1):
	    beauties.append(sum(array[j:j+n-i]))

msb = calculate_msb(beauties[0])

answer = 0
while msb >= 0:
    beauties, add = examine(beauties, msb, threshold)
    answer += add
    msb -= 1
print(answer)

Measured memory_bytes: 23880
import java.util.*;
import java.lang.*;

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

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        String s = Integer.toString(n);
        
        for (int i = 0; i < 4; i++) {
            if (s.charAt(i) == '2')
                ans ++;
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/numeric/ublas/vector.hpp>
// ↓これいる？
#include <boost/graph/strong_components.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;
using namespace boost::numeric;

using ll = long long;
namespace bst = boost;
template<class T> void fill(T& v) { for (auto&& i : v) cin >> i; }

//#include "atcoder.hpp"

int main() {
    int N;
  string S;
    
    cin >> N >> S;
  
  vector<int> r1(N, 0), r2=r1, r3=r1;
  bool found[10] = {false};
  
  
  int r = 0;
  
  for (int i = 0; i < 1000; i++){
    int i1 = i %10, i2=i/10%10, i3=i/100;
    
    int j = 0;
    for(j = 0; j < N; j++)
      if (S[j] - '0' == i3)
      { j++; break; }
    for(; j < N; j++)
      if (S[j] - '0' == i2)
      { j++; break; }

    for(; j < N; j++)
      if (S[j] - '0' == i1)
      { r++; break; }

  }

    
    cout << r << endl;
    
    return 0;
}







Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	long long inf = 1e18; 
	long long A[200010] = {}; 
	for(int i = 1; i <= N; i++) cin >> A[i]; 
	long long dp[200010][2] = {}; // 最後に選んだのがi番目で最適個数からのロスがj個
	dp[1][0] = A[1]; dp[1][1] = -inf; 
	dp[2][0] = A[2]; dp[2][1] = -inf; 
	if(N >= 3){
		dp[3][0] = A[1] + A[3]; dp[3][1] = A[3]; 
	}
	if(N >= 4){
		dp[4][0] = max(A[1], A[2]) + A[4]; 
		dp[4][1] = A[4]; 
	}
	for(int i = 5; i <= N; i++){
		if(i % 2){
			dp[i][0] = dp[i-2][0] + A[i]; 
			dp[i][1] = max({dp[i-2][1], dp[i-3][0], dp[i-4][0]}) + A[i]; 
		}
		else{
			dp[i][0] = max(dp[i-2][0], dp[i-3][0]) + A[i]; 
			dp[i][1] = max({dp[i-2][1], dp[i-3][1], dp[i-4][0], dp[i-5][0]}) + A[i]; 
		}		
	}
	if(N % 2 == 0) cout << max(dp[N-1][0], dp[N][0]) << endl; 
	else cout << max({dp[N][1], dp[N-1][0], dp[N-2][0]}) << endl; 
}

Measured memory_bytes: 8268
#include <iostream>

using namespace std;

int main()
{
int H,N,i,j,s;
int ar[100000];
s=0;
cin>>H;
cin>>N;
for(i=0;i<N;i++)
{
    cin>>ar[i];
}
for (j=0;j<N;j++){
    H=H-ar[j];
    s=s+1;}
if (H<=0&&s<=N){
    cout<<"Yes";

    }
else{
    cout<<"No";
    }


    return 0;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main(void) {
	int d;
	long long res;
	int i;

	while(!cin.eof()) {
		cin >> d;
		res = 0;
		for(i = d; i < 600; i+=d) {
			res += i*i*d;
		}
		if(!cin.eof()) { cout << res << endl; }
	}

	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        System.out.println(a == 0 ? f(b) : xor(f(a - 1), f(b)));
    }

    static long xor(long a, long b) {
        return a ^ b;
    }

    static long f(long a) {
        if (a % 2 == 0) {
            long oddCount = a / 2;
            int sum = oddCount % 2 == 0 ? 0 : 1;
            return sum + a;
        } else {
            long oddCount = a / 2 + 1;
            int sum = oddCount % 2 == 0 ? 0 : 1;
            return sum;
        }
    }
}


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


int main(){
  string tmp;
  cin >> tmp;
  list<char> S;
  for(auto& t : tmp){
    S.push_back(t);
  }
  int Q;
  cin >> Q;
  bool flip=false;
  for(int ii=0; ii<Q; ii++){
    int t;
    int f;
    char c;
    cin >> t;
    if(t==1){
      flip=!flip;
    }else{
      cin >> f >> c;
      if((f==1&&flip==false)||(f==2&&flip==true)){
        S.push_front(c);
      }else{
        S.push_back(c);
      }
    }
  }
  if(flip){
    reverse(S.begin(), S.end());
  }
  for(auto& s : S){
    cout << s;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 9984
N = input()
A = []
for i in xrange(N):
	A.append(input())
ans = 0
start = 0
for i in xrange(N):
	if A[i] > i - start:
		ans = -1
		break
	if A[i] > A[i-1] + 1:
		ans = -1
		break
	if i == 0:
		continue
	if A[i] == A[i - 1] + 1:
		ans += 1
		continue
	if A[i] == 0:
		start = i
		continue
	ans += A[i]
print ans



Measured memory_bytes: 8964
eval'N,K,*A='+`dd`.split*?,
[K,41].min.times{b=[t=0]*N*3
N.times{b[[0,_1-A[_1]].max]+=1
b[_1-~A[_1]]-=1}
A=b[0...N].map{t+=_1}}
p *A

Measured memory_bytes: 116092
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {

  int n;
  cin >> n;

  int l, r;

  int ans = 0;
  for(int i = 0; i < n; i++) {
    cin >> l >> r;

    int a = r - l + 1;

    ans += a;
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int a[2100],n,i;
double ans,m;
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{
	m+=1.0/a[i];
}	
ans=1.0/m;
cout<<ans;	
return 0;
}
 

Measured memory_bytes: 256
<?php
$s=fgets(STDIN);
function check($input){
	$s=explode(" ",$input);
	sort($s);
	if(intval($s[0])===5 && intval($s[1])===5 && intval($s[2])===7){
		return true;
	}else{
		return false;
	}
}
if(check($s)){
	echo "YES";
}else{
	echo "NO";
}

Measured memory_bytes: 3828
from numpy import arctan, pi

def main():
    a, b, x = map(int, input().split())
    if a * a * b > 2 * x:
        ans = arctan(2*x/(a*b*b))
    elif a * a * b < 2 * x and a * a * b != x:
        ans = arctan(a*a*a/2/(a*a*b-x))
    elif a * a * b < 2 * x:
        print(0)
        exit()
    else:
        ans = arctan(a/b)
    print(90 - ans*180/pi)


if __name__ == '__main__': main()

Measured memory_bytes: 21368
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> r(n+1);
    rep(i, n) r[i+1] += r[i] + (a[i] % m), r[i+1] %= m;
    map<ll, int> mp;
    ll ans = 0;
    rep(i, n+1) {
        ans += mp[r[i]];
        mp[r[i]]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8392
//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=20010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    string a,b,c;
    cin>>a>>b>>c;
    int A=a.length(), B=b.length(), C=c.length();
    if(a[A-1]==b[0] && b[B-1]==c[0]) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 3596
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

int N, M,K;
int t[100000];
int ans;
int box;
int num;

int main() {
	cin >> N >> M >> K;
	for (int i = 0; i < N; i++)cin >> t[i];
	sort(t, t + N);
	ans++;
	num = t[0] + K;
	box++;
	for (int i = 1; i < N; i++) {
		if (box < M&&t[i]<=num) {
			box++;
		}
		else {
			box = 1;
			ans++;
			num = t[i] + K;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <cmath>
#include <map>

using ll = long long;

int main()
{
    int N, M;
    std::cin >> N >> M;

    std::map<int, int> shops;
    for (int i = 0; i < N; i++)
    {
        int a, b;
        std::cin >> a >> b;
        shops[a] += b;
    }

    ll ans = 0;
    int cnt = 0;
    auto it = shops.begin();
    while (cnt < M)
    {
        if (it->second == 0)
        {
            ++it;
        }
        ans += it->first;
        cnt++;
        it->second--;
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 4992
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main p = new Main();
	}

	public Main() {
		Scanner sc = new Scanner(System.in);
		
		int c = 0;
		double[] x = new double[100];
		double[] y = new double[100];
		while(sc.hasNext()){
			String[] s = sc.next().split(",");
			x[c] = Double.parseDouble(s[0]);
			y[c] = Double.parseDouble(s[1]);
			c++;
		}
		solve(c, x, y);
	}

	public void solve(int n, double[] x, double[] y) {
		double res = 0;
		double a = Math.hypot(x[1]-x[0], y[1]-y[0]); 
		for(int i=1;i<n-1;i++){
			double b = Math.hypot(x[i+1]-x[0], y[i+1]-y[0]);
			double c = Math.hypot(x[i+1]-x[i], y[i+1]-y[i]);
			double z = (a+b+c)/2;
			
			res += Math.sqrt(z*(z-a)*(z-b)*(z-c));
//			System.out.println(res);
			a = b;
		}
		
		System.out.println(String.format("%.6f", res));
	}

}

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

int a[200010];
int b[200010];

int main() {
	long long n;
	long long x,m;
	long long ans;
	long long  p,p_max,p_round;
	long long ansm;
	long long mm,mn;

	cin >> n >> x >> m ;
	rep(i, m) b[i]=-1;

	p=x;
	rep(i, m){
		b[p]=i;
		p=p*p;
		p%=m;
		if (b[p]>=0){
			p_max=i+1;
			p_round=i+1-b[p];
            break;
		}
	}
	if (n<2*p_max){
		p=x;
		ans=0;
		rep(i, n){
			ans+=p;
			p=p*p;
			p%=m;
		}
		cout << ans << endl;
		return 0;
	}
	ansm=0;
	rep(i,p_round){
      	ansm+=p;
		p=p*p;
		p%=m;
	}
	mm=n-2*p_round;
	mm/=p_round;
	mn=n-mm*p_round;
 	ans=mm*ansm;
	p=x;
	rep(i,mn){
      	ans+=p;
		p=p*p;
		p%=m;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4012
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a){
    int s[1000000]={};
    int c=0,g=__gcd(a,b);
    a/=g,b/=g;
    while(!s[a]){
      s[a]=(++c);
      a=(a*10)%b;
      if(a<0)return 0;
    }
    if(a)c++;
    cout<<s[a]-1<<' '<<c-s[a]<<endl;
  }
}

Measured memory_bytes: 6940
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=1<<31-1=2147483647
constexpr ll INF = (ll)1e18;//1<<63-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

constexpr ll N_MAX = 100000;
constexpr ll W_I_MAX = 1000000000;

class Edge{
public:
	ll to;
	ll distance;
	Edge (ll to, ll distance) : to(to), distance(distance){}
};

vector<bool> seen;
vector<vector<Edge>> g;
ll N,M;


void input() {
	scanf("%lld%lld", &N, &M);
	g=vector<vector<Edge>>(N);
	rep(i, M) {
		ll t1,t2,t3;
		scanf("%lld%lld%lld", &t1,&t2,&t3);
		t1--;t2--;
		Edge e1(t2,t3);
		g[t1].push_back(e1);
		Edge e2(t1,t3);
		g[t2].push_back(e2);
	}
	seen.assign(N,false);
}



void dfs(vector<vector<Edge>> &g, ll v) {
	seen[v]=true;

	for(Edge nextv : g[v]){
		if(seen[nextv.to])continue;
		dfs(g,nextv.to);
	}

}

signed main() {
	input();
	ll count=0;
	rep(i,N){
		if(!seen[i]){
			dfs(g,i);
			count++;
		}
	}
	printf("%lld\n",count);

	return 0;
}


Measured memory_bytes: 12544
using System;
using System.Linq;
using System.Collections.Generic;
 
class P
{
    static void Main(string[] _)
    {
        int n = int.Parse(Console.ReadLine());
        string[] s = new string[n];
        string ans = "";
        for (int i = 0; i < n; i++)
        {
            s[i] = Console.ReadLine();
        }
        for (char c = 'a'; c <= 'z' ; c++)
        {
            int small = int.MaxValue;
            for (int i = 0; i < n; i++)
            {
                int cnt = 0;
                for (int j = 0; j < s[i].Length; j++)
                {
                    if (c == s[i][j])
                    {
                        cnt++;
                    }
                }
                small = Math.Min(cnt, small);
            }
            for (int i = 0; i < small; i++)
            {
                ans += c;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

void func(int n){
	int count = 0;
	char tmp[2],pre[2],pre_pre[2],buf[3];

	pre_pre[0] = 'd';
	pre_pre[1] = 'd';

	scanf("%s",buf);

	if(buf[0] == 'l'){
		pre[0] = buf[1];
		pre[1] = pre_pre[1];
	}else{
		pre[1] = buf[1];
		pre[0] = pre_pre[0];
	}

	if(n == 1){
		printf("0\n");
		return;
	}

	for(int i = 1; i < n; i++){
		scanf("%s",buf);

		if(buf[0] == 'l'){
			tmp[0] = buf[1];
			tmp[1] = pre[1];
		}else{
			tmp[1] = buf[1];
			tmp[0] = pre[0];
		}

		if(tmp[0] == 'd' && tmp[1] == 'd' && pre_pre[0] == 'u' && pre_pre[1] == 'u'){
			count++;
		}else if(tmp[0] == 'u' && tmp[1] == 'u' && pre_pre[0] == 'd' && pre_pre[1] == 'd'){
			count++;
		}

		pre_pre[0] = pre[0];
		pre_pre[1] = pre[1];
		pre[0] = tmp[0];
		pre[1] = tmp[1];
	}

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

}


int main(){

	int n;
	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		func(n);
	}

	return 0;
}

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

int main()
{
    int N, M;

    scanf("%d %d", &N, &M);

    // 0<=N+M<=100
    if(!((0 <= N) && (N <= 100))) return -1;
    if(!((0 <= M) && (M <= 100))) return -1;
    // 2<N+M
    if(!(2 <= (N + M))) return -1;

    int i, Z;

    Z = 0;  // Zは答え
    // 偶数の計算
    for(i = 2; i <= N; i++){
        Z += i - 1;
    }
    // 奇数の計算
    for(i = 2; i <= M; i++){
        Z += i - 1;
    }

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

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int N;
    cin>>N;
    char str[N];
    for(int i=0;i<N;i++){
        cin>>str[i];
    }
    bool check=false;
    for(int i=0;i<N;i++){
        if(str[i]=='Y') check=true;
    }
    if(check==true) cout<<"Four";
    else cout<<"Three";
    return 0;
}


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

int main() {
    char s[5];
    int y;
    int m;
    int ym = 0;
    int mm = 0;
    
    scanf("%s\n", s);
    y = (int)strtol(s, NULL, 10) / 100;
    m = (int)strtol(s, NULL, 10) % 100;
    //printf("%d %d\n", y, m);
    if(1 <= y && y <= 12){
        ym = 1;
    }
    if(1 <= m && m <= 12){
        mm = 1;
    }
    if(ym + mm == 2){
        printf("AMBIGUOUS\n");
    }else if(ym + mm == 0){
        printf("NA\n");
    }else if(ym == 1){
        printf("MMYY\n");
    }else{
        printf("YYMM\n");
    }
    return 0;
}

/*YYMM, MMYY, AMBIGUOUS, NA */


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

using namespace __gnu_pbds;
using namespace std;
using namespace std::chrono;

#define ll long long
#define ld long double
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#ifdef LL
const ll inf = 1e9;
#else 
const ll inf = 1e18;
#endif

const int mod = 1e9 + 7;
const int mod2 = 998244353;

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

high_resolution_clock::time_point curTime() { return high_resolution_clock::now(); }
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);} //Just add this as a third argument to sort() while sorting an array of pairs; NO NEED FOR ANY ARGUMENTS;
template <typename T>
T fact(T a, T mod){ int res = 1, i; for (i = 2; i <= a; i++){ res *= i; res%=mod;} return res; }
template <typename T>
ll powmod(T a,T b,ll m){ ll ans=1; while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;} return ans; }
template <typename T>
ll power(T a, T b){ ll ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}
template <typename T>
T gcd(T a,T b){ return (b?__gcd(a,b):a); }
template <typename T>
T lcm(T a, T b){ return (a*(b/gcd(a,b))); }
template <typename T>
T cl(T a, T b){ return (a+b-1)/b; }
template <typename T>
T set_bits(T a)
{ return __builtin_popcount(a); }
template <typename T>
T add_self(T& a, T b, T mod){ a+=b; if(a>=mod){ a-=mod; } }
template <typename T>
T to_upper(T s){ transform(s.begin(), s.end(), s.begin(), ::toupper); return s; }
template <typename T>
T to_lower(T s){ transform(s.begin(), s.end(), s.begin(), ::tolower); return s; }

vvi adj;
vi dp;
vector<bool> vis;
void dfs(int u)
{
    vis[u] = true;
    for(auto v : adj[u])
    {
        if(!vis[v])
        {
            dfs(v);
        }
        dp[u] = max(dp[u], dp[v]+1);
    }
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    auto startTime = curTime();

    int n,m;
    cin>>n>>m;
    adj.resize(n);
    vis.resize(n,false);
    dp.resize(n,0);

    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        u--;v--;

        adj[u].pb(v);
    }

    for(int i=0;i<n;i++) dfs(i);
    ll mx=0;
    for(int i=0;i<n;i++) mx = max(mx, dp[i]);

    cout<<mx<<endl;

    auto stopTime = curTime();
    auto duration = duration_cast<microseconds>(stopTime - startTime);
    //cout<<"Program ran for "<<(ld)duration.count()/1e6<<" "<<"seconds"<<endl;
}


Measured memory_bytes: 12116
mod=10**9+7
n, m=map(int,input().split())
x=tuple(map(int,input().split()))
y=tuple(map(int,input().split()))

lx, ly=0, 0
for i in range(n):
    lx+= i*x[i]-(n-i-1)*x[i]
    lx%=mod
for i in range(m):
    ly+= i*y[i]-(m-i-1)*y[i]
    ly%=mod

print((lx*ly)%mod)

Measured memory_bytes: 19648
def main():
    N = int(input())
    s = [input() for i in range(N)]
    M = int(input())
    t = [input() for i in range(M)]
    from collections import Counter
    s_counted = Counter(s)
    t_counted = Counter(t)
    ans = 0
    for key, val in s_counted.items():
        ans = max(ans, val - t_counted[key])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/priank/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    bool fl;
    string s;
    vector<vi> e;
    vector<lli> col;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

void dfs(lli u,lli c)
{
    if(col[u])
    {
        if(col[u]!=c)
            fl=false;
        return;
    }
    col[u]=c;
    for(auto x:e[u])
        dfs(x,3-c);
}

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n>>m;

    e.resize(n+1,vi());
    col.resize(n+1,0);

    while(m--)
    {
        cin>>u>>v;
        e[u].pb(v);
        e[v].pb(u);
    }

    lli s=0,b=0,nb=0;

    repA(i,1,n)
    {
        if(col[i])
            continue;
        if(sz(e[i])==0)
        {
            s++;
            continue;
        }

        fl=true;
        dfs(i,1);
        if(fl)
            b++;
        nb++;
    }

    lli cnt=0;

    dbg(s,b,nb);

    cnt+=n*n-(n-s)*(n-s);
    cnt+=b*b;
    cnt+=nb*nb;

    cout<<cnt<<endl;

}   aryanc403();
    return 0;
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N;cin>>N;
  vector<int> arr0(N),arr1(N,0);
  REP(i,0,N)cin>>arr0[i];
  sort(ALL(arr0));
  arr1[0]=arr0[0];
  REP(i,1,N)arr1[i]=(arr1[i-1]+arr0[i]);
  REP(i,0,N)arr1[i]*=2;
  // sort(ALL(arr0),greater<int>());
  // sort(ALL(arr1),greater<int>());
  // debug(arr0);
  // debug(arr1);
  RREP(i,N-2,-1){
    if(arr0[i+1]>arr1[i]){
      print(N-i-1);
      re 0;
    }
    
  }
  print(N);
}


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

typedef std::pair<int, int> ipair;
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k;i--)
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define mp make_pair

const int mod = 1000000007;
const ld pi = acos(-1);
const int maxn = 200006;

template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}
#define IOS  std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

bool isodd(string str){
  int n = str.size();
  for(int i=0;i<n;i+=2){
    char x = str[i];
    if(x != 'R' and x != 'U' and x != 'D') return false;
    }
    return true;
  }
bool iseven(string str){
  int n = str.size();
  for(int i=1;i<n;i+=2){
    char x = str[i];
    if(x != 'L' and x != 'U' and x != 'D') return false;
  }
    return true;
}

int32_t main(){
  string str; cin>>str;
  puts((isodd(str) and iseven(str)) ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
#define N 212345
int a[N], b[N];

int main(){
	int n; long long k; scanf("%d%lld", &n, &k);
	FOR(i, 1, n+1) scanf("%d", a+i);
	int ans = 1;
	do {
		if(k&1) ans = a[ans];
		REP(i, N) b[i] = a[a[i]];
		swap(a, b);
	}while(k /= 2);
	printf("%d\n", ans);
}


Measured memory_bytes: 5492
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n;
  cin >> n;
  vector<int> l(n);
  int sum = 0;
  REP(i,n){
    cin >> l[i];
    sum += l[i];
  }

  sort(ALL(l));
  if(l[n-1] >= sum - l[n-1]){
    cout << "No" << endl;
  }else{
  	cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256