akhauriyash/Code-Regression huggingface dataset:
#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--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  cout << (n + 1) / 2 << endl;
}


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>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, k;
    cin >> n >> k;
    vvi edges(n), rev(n);
    int ret = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        a--;
        if (i == 0 && a != 0) {
            ret++;
            a = 0;
        }
        edges[i].push_back(a);
        rev[a].push_back(i);
    }
    vi dist(n, -1);
    queue<int> q;
    q.push(0);
    dist[0] = 0;
    while (!q.empty()) {
        int p = q.front();
        q.pop();
        for (auto &v : rev[p]) {
            if (dist[v] != -1)
                continue;
            dist[v] = dist[p] + 1;
            q.push(v);
        }
    }
    vector<pii> distp;
    for (int i = 0; i < n; ++i) {
        distp.emplace_back(dist[i], i);
    }
    sort(distp.begin(), distp.end(), greater<pii>());
    vector<bool> ok(n, false);
    for (int i = 0; i < n; ++i) {
        int idx = distp[i].second;
        int d   = distp[i].first;
        if (d <= k || ok[idx])
            continue;
        for (int j = 0; j < k - 1; ++j) {
            idx = edges[idx].front();
        }
        queue<int> q;
        q.push(idx);
        ok[idx] = true;
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (auto &u : rev[v]) {
                if (ok[u])
                    continue;
                ok[u] = true;
                q.push(u);
            }
        }
        ret++;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 12668
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long int;

vector<int> NUM;
const int A_MAX = 100005;
vector<ll> ANS;

int main(){
    NUM.assign(A_MAX, 0);
    int n;
    cin >> n;
    ll S = 0;
    for(int i = 0; i < n; i++){
        ll a;
        cin >> a;
        NUM[a]++;
        S += a;
    }

    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        ll b, c;
        cin >> b >> c;
        int now = NUM[b];
        NUM[b] = 0;
        NUM[c] += now;
        S -= b * now;
        S += c * now;
        ANS.push_back(S);
    }
    for(auto s : ANS){
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 4188
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.nextLine();
        while(true){
          int blank = 0;
          String[] Array = n.split("");
          for(int i = 0; i<n.length(); i++){
            blank += Integer.parseInt(Array[i]);
          }
          if(blank == 0)
          break;
          System.out.println(blank);
          n = sc.nextLine();
        }
      }
    }



Measured memory_bytes: 27412
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int X;

int main(){
    cin >> X;
    int temp = 0,ct = 0;
    while(temp < X){
        ct++;
        temp += ct;
    }
    cout << ct << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
// typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;



const int mod = 998244353, MAX = 3e5+5;
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i-1]*i%mod;
        inv[i] = mod-inv[mod%i]*(mod/i)%mod;
        finv[i] = finv[i-1]*inv[i]%mod;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

signed main(){
  COMinit();
  int n, a, b, k;
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  int ans = 0;
  rep(i,n+1){
    int x = i, last = k-a*i;
    if(last < 0 or last%b)continue;
    int y = last/b;
    ans = (ans+COM(n, x)*COM(n, y))%mod;
  }
  printf("%lld\n", ans);
	return 0;
}







Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int N, M, K, H, W, L, R, X;
string S, T;

signed main(){
  rep(i,3){
    cin >> S;
    cout << S[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3572
import java.io.*;
import java.util.*;

public class Main{

	static PrintWriter out=new PrintWriter(System.out);;
	static int [][]memo;
	static int n1,n2;
	static char []s,t;
	static int dp(int i,int j) {
		if(i==n1 || j==n2)
			return 0;
		if(memo[i][j]!=-1)
			return memo[i][j];
		int ans=Math.max(dp(i+1,j+1)+(s[i]==t[j]?1:0), Math.max(dp(i+1,j), dp(i,j+1)));
		return memo[i][j]=ans;
		
	}
	static void print(int i,int j) {
		if(i==n1 || j==n2)
			return;
		int ans=dp(i,j);
		if(ans==dp(i+1,j))
			print(i+1,j);
		else if(ans==dp(i,j+1))
			print(i,j+1);
		else {
			if(s[i]==t[j])
				out.print(s[i]);
			print(i+1,j+1);
		}
		
		
	}
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner();
		
		s=sc.next().toCharArray();
		t=sc.next().toCharArray();
		n1=s.length;
		n2=t.length;
		memo=new int [n1][n2];
		for(int []a:memo)
			Arrays.fill(a, -1);
		dp(0,0);
		print(0,0);
		out.close();

	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		Scanner(String fileName) throws FileNotFoundException{
			br=new BufferedReader(new FileReader(fileName));
		}
		String next() throws IOException {
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		String nextLine() throws IOException {
			return br.readLine();
		}
		int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		long nextLong()  throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


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

N = int(input().split()[0])
w_list = list(map(int, input().split()))
min_diff = float("inf")
for n in range(1, N + 1):
    a = sum(w_list[: n + 1])
    b = sum(w_list[n + 1 :])
    min_diff = min(min_diff, abs(a - b))

ans = min_diff
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll a[300000];
int main() {
	int n; cin >> n;
	rep(i, 3*n) {
		cin >> a[i];
	}
	sort(a, a + 3 * n, greater<ll>());
	ll out = 0;
	rep(i, n) {
		out += a[2 * i + 1];
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007
#define INF 1000000007

int main(){
	string s;
	cin>>s;
	map<ll,ll> ma;
	ll now = 0;
	ma[now] = 0;
	rep(i,0,s.sz){
		ll a = s[i]-'a';
		ll old = now;
		now ^= (1LL<<a);
		if(ma.count(now)==0){
			ma[now] = INF;
		}
		ma[now] = min(ma[now],ma[old]+1);
		rep(j,0,26){
			ll bit = (1LL<<j);
			ll old1 = now^bit;
			if(ma.count(old1)==0){
				continue;
			}
			ma[now] = min(ma[now],ma[old1]+1);
		}
	}
	cout << max(1LL,ma[now]) << endl;
	return 0;
}

Measured memory_bytes: 12932
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    lint n, m;
    cin >> n >> m;
    lint ans;
    if(n*2 == m){
        ans = n;
    }else if(n*2 < m){
        m -= n*2;
        ans = n + m/4;
    }else{
        ans = m/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int n, m;
	int s[100], t[100];
	while(cin >> n >> m, n){
		for(int i=0;i<n;i++) cin >> s[i];
		for(int j=0;j<m;j++) cin >> t[j];
		int es = 200, et = 200; 
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				swap(s[i], t[j]);
				int sumS = 0, sumT = 0;
				for(int k=0;k<n;k++) sumS += s[k];
				for(int k=0;k<m;k++) sumT += t[k];
				swap(s[i], t[j]);
				if(sumS==sumT && s[i]+t[j]<es+et){
					es = s[i];
					et = t[j];
				}
			}
		}
		if(es+et!=400) cout << es << " " << et << endl;
		else           cout << -1 << endl;
	}
}

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

int main(){
    int N,Q;
    while( cin >> N >> Q, N||Q ){
        vector<int> date(100, 0);
        for(int i = 0; i < N; i++){
            int m;
            cin >> m;
            for(int j = 0; j < m; j++){
                int a;
                cin >> a;
                date[a] += 1;
            }
        }
        int most_conv, max_v = 0;
        for(int i = 0; i < 100; i++){
            if( date[i] > max_v ){
                most_conv = i;
                max_v = date[i];
            }
        }
        if( max_v >= Q ) cout << most_conv << endl;
        else cout << 0 << endl;
    }
    return 0;
}

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

int main() {
  string s;
  cin>>s;
  int n=s.size();
  int start[1000005];
  int end[1000005];
  int lr[1000005];
  for(int i=0;i<1000005;i++){
    start[i]=-1;
    end[i]=-1;
    lr[i]=-1;
  }
  int idx=0;
  int box =0;
  bool flgr=false,flgl=false;
  while(idx<n){
    if(s[idx]=='R' && flgr==false){
      start[box]=idx;
      flgr =true;
    }
    if(s.substr(idx,2)=="RL") lr[box]=idx;

  if(s.substr(idx,2)=="LR"||idx==n-1){
    end[box]=idx;
    flgr =false;
    box++;
  }
  idx++;
}

/*
int num=0;
  while(start[num]!=-1){
cout<<start[num]<<endl;
cout<<lr[num]<<endl;
cout<<end[num]<<endl;
num++;
}
*/
int num=0;
while(start[num]!=-1){
  int len= end[num]-start[num] +1;
  int mountr= lr[num] - start[num]+1;
  int mountl= end[num]- lr[num];
  for(int i=1;i<=len;i++){
    if(i!=mountr&& i!=mountr+1) cout<<0<<" ";
    else{
      if(len%2==0){
        cout<<len/2<<" ";
      }
      else{
        if(i==mountr&&mountr%2==1) cout<<len/2+1<<" ";
        else if(i==mountr+1&&mountr%2==1) cout<<len/2<<" ";
        else if(i==mountr&&mountr%2==0) cout<<len/2<<" ";
        else if(i==mountr+1&&mountr%2==0) cout<<len/2+1<<" ";
      }
    }
  }

  num++;
}
cout<<endl;

}


Measured memory_bytes: 12544
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main()
{
    char a1,b1;
    int a2 = 0,b2 = 0;
    auto exchange = [](char b){
        int a;
        if(b == 'A'){
            a = 1;
        }
        if(b == 'B'){
            a = 2;
        }
        if(b == 'C'){
            a = 3;
        }
        if(b == 'D'){
            a = 4;
        }
        if(b == 'E'){
            a = 5;
        }
        if(b == 'F'){
            a = 6;
        }
        return a;
    };
    std::cin >> a1 >> b1;
    a2 = exchange(a1);
    b2 = exchange(b1);
    if(a2 > b2){
        cout <<">"<<std::endl;
    }
    if(a2 < b2){
        cout <<"<"<<endl;
    }
    if(a2 == b2){
        cout <<"="<<endl;
    }
    return 0;
}


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

#define mp make_pair
#define pb push_back

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef vector<int> vi;

int H,W,h,w;

int main()
{
  cin >> H >> W >> h >> w;
  if (H % h == 0 && W % w == 0) {
    cout << "No" << endl;
    return 0;
  }

  bool b = false;
  if (W % w == 0) {
    b = true;
    swap(H, W);
    swap(h, w);
  }

  cout << "Yes" << endl;
  vi s({0});
  int v = 0;
  for (int i = 1; i <= W; i++) {
    if (i % w == 0) s.pb(--v);
    else s.pb(W+1+v);
  }

  if (b) {
    for (int j = 1; j < (int)s.size(); j++) {
      for (int i = 0; i < H; i++) {
        cout << s[j] - s[j-1] << (i+1==H ? "\n" : " ");
      }
    }
  } else {
  for (int i = 0; i < H; i++) {
    for (int j = 1; j < (int)s.size(); j++) {
      cout << s[j] - s[j-1] << (j+1==(int)s.size() ? "\n" : " ");
    }
  }
  }

  return 0;
}


Measured memory_bytes: 1408
import bisect
n,h = map(int,input().split())
a = []
b = []
for i in range(n):
    x,y = map(int,input().split())
    a.append(x)
    b.append(y)
a.sort()
b.sort()
index = bisect.bisect_left(b,a[-1])
ans = 0
count = 0
for i in range(n-1,index-1,-1):
    count += 1
    ans += b[i]
    if ans >= h:
        print(count)
        exit()
print(count + (h-ans+a[-1]-1)//a[-1])



Measured memory_bytes: 11316
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N;
	cin >> N;
	int cnt = 0;
	ll MIN = mod;
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		ll A;
		cin >> A;
		if (A < 0) {
			A = -A;
			cnt++;
		}
		MIN = min(MIN, A);
		sum += A;
	}
	if (cnt % 2 == 0) cout << sum << endl;
	else cout << sum - 2 * MIN << endl;
}

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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  
  unordered_set<char> S2;
  for (char c : S) S2.insert(c);
  for (char c : T) {
    if (S2.count(c) == 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  int N = S.length();
  vector<vector<int>> table(N + 1, vector<int>(26, -1));
  for (int i = N - 1; i >= 0; i--) {
    table[i] = table[i + 1];
    table[i][S[i] - 'a'] = i + 1;
  }

  int64_t result = 0;
  int i = 0;
  int j = 0;
  int M = T.length();
  while (j < M) {
    char c = T[j];
    int64_t next = table[i][c - 'a'];
    if (next == -1) {
      result += S.length() - i;
      i = 0;
    } else {
      result += next - i;
      i = next;
      j++;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 13696
import sys
input = sys.stdin.readline
inf = float("inf")

n,L = map(int,input().split())
a = tuple(map(int,input().split()))

for i in range(1,n):
    if a[i]+a[i-1]>=L:
        print('Possible')
        for j in range(1,i):
            print(j)
        for j in range(n-1,i,-1):
            print(j)
        print(i)
        exit()

print('Impossible')

Measured memory_bytes: 14460
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	int x, y, z;
	cin >> x >> y >> z;
	swap(x, y);
	swap(x, z);
	cout << x << " " << y << " " << z << endl;

	return 0;
}

Measured memory_bytes: 3584
# solution
import io
from collections import Counter

nim, mike, kite, *AB = map(int, open(0).read().split())

move = [
    (-1, -1), (-1, 0), (-1, 1),
    (0, -1),  (0, 0),  (0, 1),
    (1, -1),  (1, 0),  (1, 1),
]

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    C.update(
        (a - i, b - j)
        for i, j in move
        if 2 <= a - i <= nim - 1 and 2 <= b - j <= mike - 1
    )

D = Counter(v for _, v in C.items())

print((nim - 2) * (mike - 2) - sum(D.values()))
for i in range(1, 10):
    print(D[i])


Measured memory_bytes: 178260
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll mod=1e9+7;
const ll N = 2e5+10;




void solve(){
        
        ll n=0,m=0,sum=0,x=0;
        cin>>n>>m;
        for (int i = 0; i < m; i++) {
            cin>>x;
            sum+=x;
        }
        if(sum<=n){
            cout<<n-sum<<"\n";
            return;
        }
        cout<<-1<<"\n";
        
        
       
        
}


int main(){

        
            ios_base::sync_with_stdio(0);
            cin.tie(0);cout.tie(0);

            ll T=1;
            //cin>>T;
            while(T--){
                solve();
            }
            
            
        return 0;
}

Measured memory_bytes: 3656
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

fn main() {
  let mut h: usize = read();

  let mut count: usize = 0;

  while h > 1 {
    h /= 2;
    count += 1;
  }

  let mut ans = 0;
  for i in 0..count+1 {
    ans += 2i64.pow(i as u32);
  }

  println!("{}", ans);
}


Measured memory_bytes: 4352
from math import log, floor
x = int(input())
ans = 1
for b in range(2, x):
    p = floor(log(x,b))
    if p <= 1: continue
    tmp = b**p
    tmp2 = b**(p+1)
    if tmp2 <= x:
        tmp = tmp2
    ans = max(ans, tmp)

print(ans)


            

Measured memory_bytes: 3060
n,m =  map(int,input().split())
wrong = dict()
right = dict()
ac = 0
wa = 0

for i in range(m) :
	p,s = map(str,input().split())
	p = int(p)

	if right.get(p) == None :
		right[p] = 0
		wrong[p]= 0


	if s == 'WA' :
		wrong[p]+=1
	else :
		if right[p] == 0  :
			if wrong[p] == 0 :
				ac+=1
				right[p] = 1
			else :
				ac+=1
				wa+=wrong[p]
				right[p] = 1
		else :
			continue

# print(wrong)
# print(right)
print(ac,wa)


Measured memory_bytes: 21196
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000000ll
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
     
    ll n;
    cin>>n;
    vll a(n);
    rep(i,n) cin>>a[i];

    ll r=0;
    ll sum=0;
    ll ans=0;
    rep(l,n){
      while(r<n && ((sum +a[r])== (sum^a[r]))){
        sum += a[r];
        r++;
      }
      ans += r - l;
      if(l == r) r++;
      else sum -= a[l];
    }

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

Measured memory_bytes: 4756
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
#define MOD 998244353
#define INF 10000000000

vector<pair<ll,ll>> tree;
vector<ll> sum;
int n=1;

void update(int a,int b,ll x,int i,int left,int right){
  if(i<n-1&&tree[i].second!=0){
    tree[2*i+1].second=tree[i].second;
    tree[2*i+2].second=tree[i].second;
    tree[2*i+1].first=(sum[(left+right)/2]-sum[left])*tree[i].second%MOD;
    tree[2*i+2].first=(sum[right]-sum[(left+right)/2])*tree[i].second%MOD;
    tree[i].second=0;
  }
  if(b<=left||right<=a){
    return;
  }
  if(a<=left&&right<=b){
    tree[i].first=(sum[right]-sum[left])*x%MOD;
    tree[i].second=x;
    return;
  }
  update(a,b,x,2*i+1,left,(left+right)/2);
  update(a,b,x,2*i+2,(left+right)/2,right);
  tree[i].first=tree[2*i+1].first+tree[2*i+2].first;
  tree[i].first%=MOD;
}

int main(){
  int N,Q;
  cin>>N>>Q;
  vector<int> L(Q),R(Q);
  vector<ll> D(Q);
  for(int i=0;i<Q;i++){
    cin>>L[i]>>R[i]>>D[i];
    L[i]--;
  }

  while(n<N){
    n<<=1;
  }
  tree.resize(2*n-1);
  vector<ll> res(N);
  res[N-1]=1;
  for(int i=N-2;i>=0;i--){
    res[i]=10*res[i+1];
    res[i]%=MOD;
  }
  sum.resize(n+1,0);
  for(int i=0;i<N;i++){
    sum[i+1]=sum[i]+res[i];
  }
  for(int i=N+1;i<=n;i++){
    sum[i]=sum[N];
  }
  for(int i=0;i<N;i++){
    tree[i+n-1].first=res[i];
    tree[i+n-1].second=0;
  }
  for(int i=n-2;i>=0;i--){
    tree[i].first=tree[2*i+1].first+tree[2*i+2].first;
    tree[i].first%=MOD;
    tree[i].second=0;
  }

  for(int i=0;i<Q;i++){
    update(L[i],R[i],D[i],0,0,n);
    ll ans=tree[0].first;
    cout<<ans<<endl;
  }

}


Measured memory_bytes: 18276
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int Q;

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

  priority_queue<ll> que_l;
  priority_queue<ll, vector<ll>, greater<ll>> que_r;
  ll b_sum = 0;
  ll l_sum = 0, r_sum = 0;

  for (int i = 0; i < Q; i++) {
    int q;
    cin >> q;
    if (q == 1) {
      // update
      int a, b;
      cin >> a >> b;
      b_sum += b;
      if (que_l.empty() || a <= que_l.top()) {
        que_l.push(a);
        l_sum += a;
        if (que_l.size() > que_r.size() + 1) {
          ll t = que_l.top();
          que_l.pop();
          que_r.push(t);
          l_sum -= t;
          r_sum += t;
        }
      } else {
        que_r.push(a);
        r_sum += a;
        if (que_r.size() > que_l.size()) {
          ll t = que_r.top();
          que_r.pop();
          que_l.push(t);
          r_sum -= t;
          l_sum += t;
        }
      }
    } else {
      // print
      ll x = que_l.top();
      cout << x << " ";
      cout << b_sum + (x * (ll)que_l.size() - l_sum) +
                  (r_sum - x * (ll)que_r.size());
      cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]" << endl; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

ll dp[3030][3030];
int main() {
    string S, T;
    cin >> S >> T;
    int N = S.size();
    int M = T.size();
    rep(i,N+1)rep(j,M+1)dp[i][j] = 0;
    rep(i,N)rep(j,M){
        if(S[i] == T[j])chmax(dp[i+1][j+1], dp[i][j] + 1);
        chmax(dp[i+1][j+1], dp[i+1][j]);
        chmax(dp[i+1][j+1], dp[i][j+1]);
    }
    #ifdef DEBUG
    rep(i,N+1){
        rep(j,M+1){
            cerr << dp[i][j] << " ";
        }
        cerr << endl;
    }
    #endif
    string ans;
    int X = N, Y = M;
    while(X > 0 && Y > 0){
        if(dp[X][Y] == dp[X][Y-1]){
            Y--;
        }
        else if(dp[X][Y] == dp[X-1][Y]){
            X--;
        }
        else{
            ans.push_back(S[X-1]);
            X--, Y--;
        }
    }
    reverse(all(ans));
    cout << ans << endl;
}


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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)

using namespace std;

typedef unsigned char byte;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<ll, ll> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }



int n, m;

int main(){
//    int n, l;
//    cin >> n >> k;
//    vector<bool> dislike(10, false);
//
//    FOR(i, 0, k) {
//        int t;
//        cin >> t;
//        dislike[t] = true;
//    }



    cin >>n;

    ll sum = 1;
    ll module = 1e9+7;
    FOR(i, 1, n + 1){
        sum*=i;
        sum%=module;
    }

    cout<<sum <<endl;

    return 0;
}


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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll n, x;
    cin >> n >> x;
    vector<ll> l(n);
    REP(i, n) cin >> l[i];
    ll ans = 0, sum = 0;
    REP(i, n){
        if(sum > x) break;
        ans++;
        sum += l[i];
    }
    if(sum <= x) ans++;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3564
import bisect

n = int(input())
a = sorted( list( map( int, input().split()) ))
b = sorted( list( map( int, input().split()) ))
c = sorted( list( map( int, input().split()) ))

total = 0
for i in b:
  index_a = bisect.bisect_right( a, i-1 )
  index_c = n - bisect.bisect_left( c, i+1 )
  total += index_a * index_c
print(total)
    

Measured memory_bytes: 107108
S = input()
N = len(S)
mod = 2019
num = [0 for i in range(2019)]
num[0] = 1
t = 1
rem = 0

for i in reversed(S):
    rem += int(i) * t
    rem %= mod
    t *= 10
    t %= mod
    num[rem] += 1

print(int(sum([i * (i-1) / 2 for i in num])))

Measured memory_bytes: 9168
h,w = gets.chomp.split(" ").map(&:to_i)
ca = Array.new(h).map{Array.new(w, ".")}
for i in 0..h - 1
  ca[i] = gets.chomp.split("")
end
count1 = 0
count2 = 0

for i in 0..h - 1
  for j in 0..w - 1
    if i != 0
      if ca[i][j] != ca[i - 1][j] && ca[i][j] == "#"
        count1 += 1
      end
      count2 += 1
    end
    if i != h - 1
      if ca[i][j] != ca[i + 1][j] && ca[i][j] == "#"
        count1 += 1
      end
      count2 += 1
    end
    if j != 0
      if ca[i][j] != ca[i][j - 1] && ca[i][j] == "#"
        count1 += 1
      end
      count2 += 1
    end
    if j != w - 1
      if ca[i][j] != ca[i][j + 1] && ca[i][j] == "#"
        count1 += 1
      end
      count2 += 1
    end
    if count1 == count2
      print "No"
      exit
    end
    count1 = 0
    count2 = 0
  end
end

print "Yes"


Measured memory_bytes: 2044
#include<iostream>
#include<cmath>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<deque>
#include<tuple>
#include<iomanip>
using namespace std;
#define int                  int64_t
#define double               long double
#define vi                   vector<int>
#define di                   deque<int>
#define si                   set<int>
#define vpii                 vector<pair<int,int>>
#define pi                   pair<int,int>
#define pub                  push_back
#define puf                  push_front
#define pob                  pop_back
#define pof                  pop_front
#define all(a)               (a).begin(),(a).end()
#define rall(a)              (a).rbegin(),(a).rend()
#define PI                   3.1415926535897932384626433832795
#define read(a)              for(auto& x:a) cin>>x
#define speak(a)             for(auto x:a) cout<<x<<' '
#define rep(i,s,n)           for(int i=s;i<n;++i)
#define repe(i,s,n)          for(int i=s;i<=n;++i)
#define repr(i,n,s)          for(int i=n;i>=s;--i)
#define endl                 '\n'
#define gap                  ' '
#define MAX                  LLONG_MAX
#define MIN                  LLONG_MIN
#define min3(a,b,c)          min(a, min(b, c))
#define max3(a,b,c)          max(a, max(b, c))
#define MOD                  1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b;cin>>a>>b;
    repe(i,1,100000)
    {
        if((int)(i*.08)==a and (int)(i*0.1)==b) return cout<<i,0;
    }
    cout<<"-1";
}


Measured memory_bytes: 3612
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var answer = (int)1e9 + 1;
            var ave = A.Average();
            var arr = new int[] { (int)Math.Floor(ave), (int)Math.Ceiling(ave) };
            foreach (var y in arr)
            {
                var sum = A.Sum(x => (x - y) * (x - y));
                answer = Math.Min(answer, sum);
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 28304
#include <bits/stdc++.h>
#define int long long

using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x,y;
    
    while(1)
    { cin >> x >> y;
        if(!x && !y) break;
        else if(x > y) cout << y << " " << x <<endl;
        else cout << x << " " << y <<endl;
    }

}



Measured memory_bytes: 3220
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

struct Data
{
	string word;
	int count;

	Data()
	{
		
	}

	Data(string word)
	{
		this->word = word;
		this->count = 1;
	}
};

int main()
{
	vector<Data> d;

	string str;
	getline(cin, str);

	stringstream ss;
	ss << str;

	string s;
	for (; ss >> s;)
	{
		int i;
		bool b = false;
		for (i = 0; i < d.size(); i++)
		{
			if (d.at(i).word == s)
			{
				b = true;
				break;
			}
		}

		if (b)
		{
			d.at(i).count++;
		}
		else
		{
			d.push_back(Data(s));
		}
	}

	int maxw = 0;
	int maxl = 0;

	string w, l;
	for (int i = 0; i < d.size(); i++)
	{
		if (d.at(i).count > maxw)
		{
			w = d.at(i).word;
			maxw = d.at(i).count;
		}

		if (d.at(i).word.size() > maxl)
		{
			l = d.at(i).word;
			maxl = d.at(i).word.size();
		}
	}

	cout << w << " " << l << endl;
}


Measured memory_bytes: 3160
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv;

void main() {
  string s = readln.chomp;
  auto cur = s.length / 2;
  char pi = s[cur];

  if (s.length % 2 == 0) {
    while (cur < s.length && pi == s[$ - cur - 1] && pi == s[cur]) {
      ++cur;
    }
  } else {
    ++cur;
    while (cur < s.length && pi == s[$ - cur - 1] && pi == s[cur]) {
      ++cur;
    }
  }
  writeln(cur);
}


Measured memory_bytes: 508
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>

using namespace std;

typedef vector<int> vi;
typedef queue<int> qi;

bool dfs(vi e[], int p[], int h[], int x, bool st[], vi &t) {
    int dmax = -1, dmaxp = -1;
    for (int y : e[x]) {
        if (st[y]) {
            if (h[y] > dmax) {
                dmax = h[y];
                dmaxp = y;
            }
        }
    }

    if (dmaxp != -1) {
        do {
            t.push_back(x);
            x = p[x];
        } while (x != dmaxp);
        t.push_back(x);
        return true;
    }

    st[x] = true;
    for (int y : e[x]) {
        if (p[y] == x) {
            bool f = dfs(e, p, h, y, st, t);
            if (f) {
                return true;
            }
        }
    }

    st[x] = false;
    return false;
}

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

    int n, m;
    cin >> n >> m;
    vi e[n];
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        e[a].push_back(b);
    }

    int p[n];
    fill(p, p+n, -2);
    bool st[n];
    memset(st, false, sizeof(st));
    int h[n];
    fill(h, h+n, -1);
    for (int i = 0; i < n; i++) {
        if (h[i] == -1) {
            qi q;
            q.push(i);
            p[i] = -1;
            h[i] = 0;
            while (!q.empty()) {
                int x = q.front();
                q.pop();

                for (int y : e[x]) {
                    if (h[y] == -1) {
                        h[y] = h[x] + 1;
                        p[y] = x;
                        q.push(y);
                    }
                }
            }

            vi t;
            if (dfs(e, p, h, i, st, t)) {
                cout << t.size() << endl;
                for (int j = t.size() - 1; j >= 0; j--) {
                    cout << t[j] + 1 << endl;
                }
                return 0;
            }
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 384
import java.lang.StringBuilder

fun main(args:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val gakuseiList = (1..n).map { Pos(readLine()!!) }
    val checkPointList = (1..m).map { Pos(readLine()!!) }
    val ans = StringBuilder()
    for(i in gakuseiList) {
        var min = Long.MAX_VALUE
        var minIdx = Int.MAX_VALUE
        for(j in checkPointList.indices.reversed()) {
            if(min >= i.getDiff(checkPointList[j])) {
                min = i.getDiff(checkPointList[j])
                minIdx = j
            }
        }
        ans.appendln(minIdx + 1)
    }
    print(ans.toString())
}

class Pos(input:String) {
    val x = input.split(" ").map { it.toLong() }[0]
    val y = input.split(" ").map { it.toLong() }[1]
    fun getDiff(target:Pos):Long {
        return Math.abs(x-target.x) + Math.abs(y-target.y)
    }
}


Measured memory_bytes: 37912
import java.util.Scanner;
import java.util.TreeSet;
import java.util.Arrays;
public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
           int n=sc.nextInt();
           TreeSet<String> ts=new TreeSet<String>();
           for(int i=0;i<n;i++){
            String s=sc.next();
            String x=sc.next();
            if(s.equals("insert"))ts.add(x);
            else {
                if(ts.contains(x))System.out.println("yes");
                else System.out.println("no");
            }
           }   
}
}



Measured memory_bytes: 207680
#include<bits/stdc++.h>
 
using namespace std;
 
using   ll=long long;
using   ld=long double;
 
#define fast           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl           "\n"
#define int            long long 
#define pb             push_back
#define mp             make_pair
#define vll            vector<ll>
#define ff              first
#define ss              second
#define pll            pair<ll,ll>
#define ALL(v)         v.begin(),v.end()
#define ALLR(v)        v.rbegin(),v.rend()
#define pii            3.14159265358979323
 
void solve()
{
    ll n,m;
    
    cin>>n>>m;
    
    vector<ll> a(n+1);
    
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    
    ll lcm=1;
    
    for(int i=1;i<=n;i++)
    {
        lcm=(lcm*a[i])/(__gcd(lcm,a[i]));
    }
    
    ll tt=2*m/lcm;
    
    for(int i=1;i<=n;i++)
    {
        if((lcm/a[i])%2==0)     tt=0;
    }
    
    cout<<tt-tt/2;
}

 
signed main()
{
 
    fast;
 
    ll t;
    
    t=1;
    
    //cin>>t;
    
    while(t--)
    {
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<algorithm>
#define rep(i,j) for(int i=0;i<(int)(j);i++)
using namespace std;
#define N_MAX 50000
#define M_MAX 20
const int INF=1<<30;
int main(){
  int n,m;
  scanf("%d%d",&n,&m);
  vector<int> c(m);
  rep(i,m)scanf("%d",&c[i]);
  int DP[N_MAX+10];
  DP[0]=0;
  for(int i=1;i<=n;i++){
    DP[i]=INF;
    rep(j,m){
      if(i-c[j]>=0){
        DP[i]=min(DP[i],DP[i-c[j]]+1);
      }
    }
  }
  printf("%d\n",DP[n]);
  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

bool odd(string sl, string sr, int l, int r){
    if(sr==sl) return (r-l)%2 == 1;
    else return (r-l)%2 == 0;
}
void solve(int n){
    
    
    string vac = "Vacant";
    string sl, sr, str;
    int l=0, r=n/2;
    cout << l << endl;
    cin >> sl;
    if(sl==vac) return;
    cout << r << endl;
    cin >> sr;
    if(sr==vac) return;
    //[0, n/2), (n/2, n-1]
    if(!odd(sl, sr, l, r)){
        swap(sl, sr); l = r; r=n;
    }
    while(1<r-l){
        int mid = (l+r)/2;
        cout << mid << endl;
        cin >> str;
        if(str==vac) return;
        if(odd(sl, str, l, mid)){
            sr = str; r=mid;
        }else{
            sl = str; l = mid;
        }

    }

}
int main(){
    int n;
    while(cin >> n) solve(n);
}

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

int main(){
    string n;
    cin >> n;
    for(int i=0; i<n.size(); i++){
        if(n[i] == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3592
s = input()

if s[0] != "A":
    print("WA")
    exit()

if len(s[2:-1]) - len(s[2:-1].replace("C", "")) != 1:
    print("WA")
    exit()

if s[1:].replace("C", "").lower() == s[1:].replace("C", ""):
    print("AC")
else:
    print("WA")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s,t;
  int cnt=0;
  cin>>s;
  cin>>t;
  for(int i=0;i<s.size();i++)
  {
    if(s[i]!=t[i])
    {
        cnt++;}
  }
  cout<<cnt;
}



Measured memory_bytes: 3852
#include <bits/stdc++.h>
#define MAXN 200010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const ll mod = 1e18 + 7;


int main (){
    ios_base::sync_with_stdio(false);
    
    double w, h, x, y;

    cin >> w >> h >> x >> y;

    cout << (w*h)/2 << " ";

    if (x == w/2 and y == h/2) cout << "1\n";
    else cout << "0\n";

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b){
  return *(int*)a - *(int*)b;
}


int main(){
  int n = 0;
  int m = 0;
  int a[200000] = {};
  int b[200000] = {};
  int go[200000] = {};
  int cnt = 0;
  int merged[400000]= {};
  int i = 0;
  int success = 0;
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d %d",&a[i],&b[i]);
  }
  
  for(i=0;i<m;i++){
    if(a[i] == 1){
      go[cnt] = b[i];
      cnt++;
    }
  }
  for(i=0;i<m;i++){
    if(b[i] == n){
      go[cnt] = a[i];
      cnt++;
    }
  }
  qsort(go,cnt,sizeof(int),cmp);
  for(i=1;i<cnt;i++){
    if(go[i-1] == go[i]){
      success = 1;
      break;
    }
  }
  
  if(success){
    printf("POSSIBLE");
  }else{
    printf("IMPOSSIBLE");
  }
  return 0;
}
      
        

Measured memory_bytes: 3324