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

int main(){

    long long N, M;
    cin >> N >> M;
    vector<long long> A(N), candy;
    for(int i = 0; i < N; i++) cin >> A[i];
    candy.push_back(0);
    for(int i = 0; i < N; i++) candy.push_back(candy[i] + A[i]);

    map<long long, long long> count; // <mod, num>
    for(int i = 0; i < candy.size(); i++) count[candy[i] % M]++;

    long long ans = 0;
    for(auto itr = count.begin(); itr != count.end(); itr++){
        ans += itr->second * (itr->second - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, k, a, s, t, u, v, w, g;
  in2(n, k);
  vector<ll> c(k);
  rep(i, k)
    in(c[i]);
  rep2(i, n, 10000000){
    a = 0;
    s = 10;
    t = 10;
    u = 10;
    v = 10;
    w = 10;
    g = i;
    if(i < 10){
      s = i;
    }
    else if(i < 100){
      s = i % 10;
      t = i / 10;
    }
    else if(i < 1000){
      s = g % 10;
      g = g / 10;
      t = g % 10;
      u = g / 10;
    }
    else if(i < 10000){
      s = i % 10;
      g = g / 10;
      t = g % 10;
      g = g / 10;
      u = g % 10;
      v = g / 10;
    }
    else{
      s = g % 10;
      g = g / 10;
      t = g % 10;
      g = g / 10;
      u = g % 10;
      g = g / 10;
      v = g % 10;
      w = g / 10;
    }
    rep(j, k){
      g = c[j];
      if(s == g)
        a++;
      if(t == g)
        a++;
      if(u == g)
        a++;
      if(v == g)
        a++;
      if(w == g)
        a++;
    }
    if(a == 0){
      out(i);
      memi;
      return 0;
    }
  }
}

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

using namespace std;
int le[5005],n;

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;++i) scanf("%d",le+i);
    sort(le,le+n);
    long long ans = 0;
    for(int i=0;i<n;++i)
    {
        for(int j=i+1;j+1<n;++j){
            auto pos = lower_bound(le+j+1,le+n,le[i]+le[j]);
            ans += (pos - (le+j))-1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int i, n, pA, pB, tA = 0, tB = 0;
int main () {
    while(cin >> n) {
       if(n == 0) { break; }
       for (i=1; i<=n; i++) {
           cin >> pA >> pB;
           if (pA > pB) {
               tA += pA + pB;
           } else {
               if (pA < pB) {
                   tB += pA + pB;
               } else {
                   tA += pA;
                   tB += pB;
               }
           }
       }
       cout << tA << " " << tB << endl;
       tA = 0; tB = 0;
     }
     return 0;
}

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

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

#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define REP(i,n) for(int i=0;i<n;i++)
#define pb push_back


// vectorの中身をcout << vs;で表示
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
    o << "{";
    for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
    o << "}";
    return o;
}

int main(void) {
	// cin, coutの結びつきを解除し、速くする
	cin.tie(0);
   	ios::sync_with_stdio(false);

	int n, k; cin >> n >> k;
	cout << (n % k == 0 ? 0 : 1) << endl;


}



Measured memory_bytes: 256
#include<stdio.h>

void trace(int A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void insertion(int A[], int n){
  int i;
  int V;
  int j;
  for ( i = 1; i < n; i++ ){
  V=A[i];
  j=i-1;
  while (j>=0 && A[j]>V){
	  A[j+1]=A[j];
      j--;
  }
  A[j+1]=V;
  trace(A,n);
  }
}

int main(){
  int n, i, j;
  int A[100];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);

  trace(A, n);
  insertion(A,n);

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);

  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }

  int count = 0;
  int acs = 1;

  while(count<=N){
    if(vec.at(acs-1)==2){
      count++;
      break;
    }else{
      count++;
      acs = vec.at(acs-1);
    }
  }

  if(count > N){
    cout << "-1" << endl;
  }else{
    cout << count << endl;
  }


}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int N=sc.nextInt();
		int[] a=new int[N];
		int i,k,cnt=0,ans=0,max,t;
		for(i=0;i<N;i++) {
			a[i]=sc.nextInt();
		}
		Arrays.sort(a);
		max=a[N-1];
		i=0;
		for(;;) {
			cnt=0;
			t=a[i];
			for(k=i;k<N;k++) {
				if(cnt>0 && t!=a[k]) break;
				if(t==a[k]) {
					cnt++;
					i++;
				}
			}
			if(cnt>=t)ans+=cnt-t;
			else ans+=cnt;
			if(t==max)break;
		}
		System.out.println(ans);
	}
}


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

int diffh(int a, int b)
{
    if(a > b)
    {
        return a - b;
    }
    else
    {
        return b- a;
    }
}

int main()
{
    int N;
    cin >> N;
    int h[N];
    int dp[N];
    for(int i = 0; i < N; i++)
    {
        cin >> h[i];
        dp[i] = 0;
    }
    for(int i = 1; i < N; i++)
    {
        if(i >= 2 && dp[i - 2] + diffh(h[i - 2], h[i]) < dp[i - 1] + diffh(h[i - 1], h[i]))
        {
            dp[i] = dp[i - 2] + diffh(h[i - 2], h[i]);
        }
        else
        {
            dp[i] = dp[i - 1] + diffh(h[i - 1], h[i]);
        }
    }
    cout << dp[N - 1] << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (n); i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) std::cout << (x) << std::endl
typedef long long ll;

int main() {
    int n, k;
    cin >> n >> k;
    ll h[n];
    REP(i, n) {
        cin >> h[i];
    }
    sort(h, h + n, greater<int>());
    if (k >= n) {
        OUT(0);
    } else {
        ll sum = 0;
        for (int i = k; i < n; i++)
            sum += h[i];
        OUT(sum);
    }
}

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

typedef long long ll;
ll n, s;
int main()
{
//    freopen ("input.txt", "r", stdin);
    cin >> n;
    s = n / 11 * 2;
    if (n % 11 == 0) s += 0;
    else if (n % 11 <= 6) s++;
    else s += 2;
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int H,N,i,sum=0;
  scanf("%d %d",&H,&N);
  int arr[N];
  for(i=0;i<N;i++)
  {
    scanf("%d",&arr[i]);
  }
  for(i=0;i<N;i++)
  {
    sum=sum+arr[i];
  }
  if(sum>=H)
  {
    printf("Yes");
  }
  else
    printf("No");
  return 0;
}
  


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    
    int a,b;
    cin>>a>>b;
    if(a<b){
        cout<<"a < b"<<endl;
    }
    else if(a>b){
        cout<<"a > b"<<endl;
    }
    else{
        cout<<"a == b"<<endl;
    }
}



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

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

Measured memory_bytes: 256
#pragma region header
#include <bits/stdc++.h>
#define int long long
using namespace std;
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int h,w;cin >> h >> w;
    int Dx[]={1,0,-1,0,1,1,-1,-1};
    int Dy[]={0,1,0,-1,-1,1,1,-1};
    vvi ans(h,vi(w));
    rep(i, h) {
        rep(j, w) {
            char c;cin >> c;
            if(c=='#') {
                ans[i][j]=-1;
                rep(k, 8) {
                    int x = i+Dx[k],y=j+Dy[k];
                    if(x<0||x>=h||y<0||y>=w||ans[x][y]==-1) continue;
                    ans[x][y]++;
                }
            }
        }
    }
    rep(i,h) {
        rep(j, w) {
            if(ans[i][j]==-1)cout << "#";
            else cout << ans[i][j];
            if(j==w-1)cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3592
import sys
input = sys.stdin.readline
from collections import Counter

def main():
    input()
    A = [int(c) for c in input().split()]

    c = Counter(A)
    c_ = c.copy()

    for i, n in c.items():
        c_[i-1] += n
        c_[i+1] += n

    print(max(c_.values()))

main()

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

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

  string ans = "No";
  for ( int i = 0; i < s.size(); i++ ) {
    if ( s == t ) { ans = "Yes"; break; }
    char c = s[0];
    s = s.substr(1, s.size()-1) + c;
  }

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


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::cin >> n;
	int f[3] = {0, 0, 0};
	for(int i = 0; i < n; i++) {
		int x;
		std::cin >> x;
		if(x % 4 == 0) f[0]++;
		else if(x % 2 == 0) f[1]++;
		else f[2]++;
	}
	if(f[0] == f[2] - 1 && f[1] == 0) {
		std::cout << "Yes\n";
	} else if(f[0] < f[2]) {
		std::cout << "No\n";
	} else {
		std::cout << "Yes\n";
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional> //sort(A,A.end(),greater<int>());???????????????
#include <queue>
#include <stack>
#include <vector>

#define INF 10 << 10
#define MP make_pair

int map[32][32];

int main() {
	memset(map, -1, sizeof(map));
	int a, b, n;
	while (cin >> a >> b && a != 0 && b != 0) {
		cin >> n;

		for (int i = 1; i <= b; ++i) {
			for (int i2 = 1; i2 <= a; ++i2) {
				map[i][i2] = 0;
			}
		}

		for (int i = 0; i < n; ++i) {
			int xx, yy;
			cin >> xx >> yy;
			map[yy][xx] = -1;
		}

		queue<pair<int, int> > q;
		q.push(MP(1, 1));
		int cnt = 0;
		while (!q.empty()) {
			int x = q.front().second, y = q.front().first;
			q.pop();
			if (x == a && y == b) {
				++cnt;
				continue;
			}
			if (map[y + 1][x] == 0) {
				q.push(MP(y + 1, x));
			}
			if (map[y][x + 1] == 0) {
				q.push(MP(y, x + 1));
			}
		}

		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 9228
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
struct edge {
	int to, cost;
};
// other libs
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);
}

class dijkstra {
  private:
	int V;
	int d[100002];
	priority_queue<P, vector<P>, greater<>> que;

  public:
	dijkstra(int v, int s, vector<edge> G[]) {
		V = v;
		update(s, G);
	}

	void update(int s, vector<edge> G[]) {
		fill(d, d + V + 1, 100000000000ll);
		d[s] = 0;
		que.push(make_pair(0, s));
		while (!que.empty()) {
			P p = que.top();
			que.pop();
			int v = p.second;
			if (d[v] < p.first)
				continue;
			rep(i, G[v].size()) {
				edge e = G[v][i];
				if (d[e.to] > d[v] + e.cost) {
					d[e.to] = d[v] + e.cost;
					que.push(make_pair(d[e.to], e.to));
				}
			}
		}
	}

	int find(int e) {
		return d[e];
	}
};
template<typename T>
class Union_Find {
  private:
	vector<T> t, s;

  public:
	Union_Find(T max_length) {
		rep(i, max_length + 1) {
			t.push_back(i);
			s.push_back(1);
		}
	}

	void Union(T x, T y) {
		if (same(x, y))
			return;
		T tx = Find(x), ty = Find(y);
		if (s[tx] < s[ty]) {
			s[ty] += s[tx];
			t[tx] = ty;
		}
		else if (s[tx] > s[ty]) {
			s[tx] += s[ty];
			t[ty] = tx;
		}
		else if (tx > ty) {
			t[tx] = ty;
			s[ty] += s[tx];
		}
		else {
			t[ty] = tx;
			s[tx] += s[ty];
		}
	}
	T Find(T n) {
		if (t[n] == n)
			return n;
		else
			return t[n] = Find(t[n]);
	}

	bool same(T x, T y) {
		return Find(x) == Find(y);
	}

	T get_Size(size_t a) {
		return s[a];
	}
};
bool ifPrime(int n) {
	if (n == 1)
		return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)
			return false;
	}
	return true;
}
vector<int> primeFactorization(int n) {
	vector<int> re;
	int cnt = 2;
	while (n != 1) {
		if (n % cnt != 0) {
			cnt++;
			continue;
		}
		n /= cnt;
		re.push_back(cnt);
	}
	return re;
}
signed main(signed argc, char* argv[]) {
    int n,k;
    cin>>n>>k;
    int ans=0;
    rep(i,n){
        int in;
        cin>>in;
        if(in>=k)ans++;
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main() {
    // For any new number, check if there's another number smaller
    int n;
    cin >> n;
    int count = 0;
    int curr_min = INT_MAX;

    // Because the ith number has to be smaller than jth number,
    // So any new input should count only if they're smaller

    while (n > 0) {
        int num;
        cin >> num;
        if (num < curr_min) {
            count++;
            curr_min = num;
        }
        n--;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int a[5];
  for(int i = 0; i < 5; i++){
    cin >> a[i];
  }
  int k;
  cin >> k;

  bool found = false;
  for(int i = 0; i < 5; i++){
    for(int j = i + 1; j < 5; j++){
      if(abs(a[i]- a[j]) > k){
        found = true;
        break;
      }
    }
  }

  if(found) cout << ":(" << endl;
  else cout << "Yay!" << endl;

  return 0;
}


Measured memory_bytes: 256
Moji=str(input())
ListNAB=Moji.split() #N,A,Bの順にリストに格納
N=int(ListNAB[0])
A=int(ListNAB[1])
B=int(ListNAB[2])
if A>=B:
  nmax=B

elif A<B:
  nmax=A

if N>A+B:
  nmin=0

if N<=(A+B):
    nmin=A+B-N

print(str(nmax)+" "+str(nmin))


Measured memory_bytes: 3060
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int d;

vector<int> c;
vector<vector<int>> s;
vector<int> t;

int last(int d, int i) {
  int j;

  for (j=d; j>=0; j--) {
    if (t[j] == i) return j+1;
  }
  return 0;
}

int main()
{
  int i, j;
  int conf=0;

  c.resize(26);
  cin >> d;
  for(i=0; i<26; i++) {
    cin >> c[i];
  }

  s.resize(d);
  for (i=0; i<d; i++) {
    s[i].resize(26);
    for (j=0; j<26; j++) {
      cin >> s[i][j];
    }
  }

  t.resize(d);
  for (i=0; i<d; i++) {
    cin >> t[i];
    t[i]--;
    conf += s[i][t[i]];
    for (j=0; j<26; j++) {
      conf -= c[j] * (i+1 - last(i, j));
    }
    printf("%d\n", conf);
  }
  return 0;
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define ll long long
#define int ll
#define BUF 1e5
#define INF 1 << 30
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

int dfs(int n, int k, vi &cnt, vi &sum) {
    int x = (k >> n) & 1;
    if (n == 0) {
        if (x == 1) {
            return max(cnt[n], N - cnt[n]);
        } else {
            return cnt[n];
        }
    }
    if (x == 1) {
        return max((1LL << n) * max(cnt[n], N - cnt[n]) + dfs(n - 1, k, cnt, sum), (1LL << n) * cnt[n] + sum[n - 1]);
    } else {
        return (1LL << n) * cnt[n] + dfs(n - 1, k, cnt, sum);
    }
}

signed main() {
    cin >> N >> K;
    vi a(N);
    cin >> a;
    vi cnt(50, 0);
    for (int i = 0; i < N; i++) {
        for (int bit = 0; bit < 50; bit++) {
            if ((a[i] >> bit) & 1) {
                cnt[bit]++;
            }
        }
    }
    vi sum(50, 0);
    sum[0] = max(cnt[0], N - cnt[0]);
    for (int i = 1; i < 50; i++) {
        sum[i] = (1LL << i) * max(cnt[i], N - cnt[i]) + sum[i - 1];
    }
    cout << dfs(49, K, cnt, sum) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

ll n, m;
ll dp[100100];
vector<vector<ll>> g;
vector<ll> deg;

int main() {
    cin >> n >> m;
    g.assign(n, vector<ll>());
    deg.assign(n, 0);
    for(int i = 0; i < m; i++){
        int s, t;
        cin >> s >> t;
        s--; t--;

        g[s].push_back(t); 
        deg[t]++;
    }


    queue<ll> que;
    for(int i = 0; i < n; i++) if(deg[i] == 0) que.push(i);

    while(!que.empty()){
        int v = que.front(); que.pop();
        for(auto nv : g[v]){
            deg[nv]--;
            if(deg[nv] == 0) {
                que.push(nv);
                dp[nv] = max(dp[nv], dp[v] + 1);
            }
        }
    }

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

    cout << res << endl;
}

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


int main(){
	string s;
	cin>>s;
	int count=0;
	for(int i=0;i<s.length();++i){
		count+=(s[i]-'0');
	}
	if(count%9==0) cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
vector<int> G[MAXN];

int dfs(int node, int par){
	int cnt=0;
	for (int v:G[node]) if (v!=par) cnt+=dfs(v, node);
	if (!cnt) return 1;
	if (cnt==1) return 0;
	cout<<"First\n";
	exit(0);
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	if (n&1) kill("First")
	for (int i=1; i<n; i++){
		cin>>u>>v;
		G[u].pb(v);
		G[v].pb(u);
	}
	dfs(1, 1);
	cout<<"Second\n";
	
	return 0;
}


Measured memory_bytes: 5888
while True:
    try:
        N=int(input())
        for i in range(N):
            a=input()
            b=input()
            if len(a)>80 or len(b)>80:
                print("overflow")
            else:
                a=int(a)
                b=int(b)
                s=a+b
                if len(str(s))>80:
                    print("overflow")
                else:
                    print(s)
    except:break



Measured memory_bytes: 5592
/**
 *    author:  math2do
 *    created: 04.09.2020 17:20:44 IST
**/

#include <bits/stdc++.h>

using namespace std;

const int T = 0;
const int L = 1;
const int D = 2;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string a, b;
  cin >> a >> b;
  int n = a.length();
  int m = b.length();
  vector <vector <int> > dp(n, vector <int>(m));
  vector <vector <int> > from(n, vector <int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i] == b[j]) {
	dp[i][j] = max(dp[i][j], 1 + (i - 1 < 0 || j - 1 < 0 ? 0 : dp[i - 1][j - 1]));
	from[i][j] = D;
      } else {
	dp[i][j] = max(dp[i][j], j - 1 < 0 ? 0 : dp[i][j - 1]);
	dp[i][j] = max(dp[i][j], i - 1 < 0 ? 0 : dp[i - 1][j]);
	
	int LL = j - 1 < 0 ? 0 : dp[i][j - 1];
	int TT = i - 1 < 0 ? 0 : dp[i - 1][j];
	from[i][j] = LL > TT ? L : T;
      }  
    } 
  } 
  
  int i = n - 1, j = m - 1;
  string ans = "";
  while (i >= 0 && j >= 0) {
    if (from[i][j] == D) {
      ans += a[i];
      i--; 
      j--;
    } else if (from[i][j] == L) {
      j--;
    } else if (from[i][j] == T) {
      i--;
    } 
  } 
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}


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

static const int N = 100;

int main()
{
    int n, p[N + 1], m[N + 1][N + 1];
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> p[i - 1] >> p[i];
    }

    for (int i = 1; i <= n; i++)
        m[i][i] = 0;
    for (int l = 2; l <= n; l++)
    {
        for (int i = 1; i <= n - l + 1; i++)
        {
            int j = i + l - 1;
            m[i][j] = (1 << 21);
            for (int k = i; k <= j - 1; k++)
            {
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }

    cout << m[1][n] << endl;
    return 0;
}


Measured memory_bytes: 3132
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,X = map(int,input().split())

def F(x,y):
    """
    x,yの平行四辺形。対角にたどり着くまでの距離
    """
    if x>y:
        x,y = y,x
    q,r = divmod(y,x)
    if r == 0:
        return (2*q-1)*x
    return 2*q*x + F(x,y%x)

answer = N + F(X,N-X)
print(answer)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;

int main(){
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  if(N<=K)
    cout << N*X << endl;
  else
    cout << K*X+(N-K)*Y << endl;
  return 0;
}

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

int main() {

  int N;
  cin >> N;
  string s[110];
  bool ans = true;

  for (int i = 0; i < N; i++) {
  cin >> s[i];
  }

  for (int i = 0; i < N-1; i++) {
    if ( s[i].at(s[i].size() - 1 ) != s[i + 1].at(0) ) ans = false;
  }

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (s[i] == s[j])
        ans = false;
    }
  }

  if (ans) cout << "Yes" << endl;
  else   cout << "No" << endl;
}


Measured memory_bytes: 256
//raja1999

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define int ll

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

//std::ios::sync_with_stdio(false);
map<string,int>mapi;
main(){
	std::ios::sync_with_stdio(false); cin.tie(NULL);
	int t,t1;
	//cin>>t;
	t=1;
	t1=t;
	while(t--){
		string s;
		cin>>s;
		mapi["SUN"]=7;
		mapi["SAT"]=1;
		mapi["FRI"]=2;

		mapi["THU"]=3;
		mapi["WED"]=4;
		mapi["TUE"]=5;

		mapi["MON"]=6;
		cout<<mapi[s]<<endl;
	}
	return 0;
} 
	

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

int main(void) {
    int b, i;
    char S[20], T[20];
    scanf("%s%s", S, T);
    b=1;
    for (i=0; i<strlen(S); i++) {
        if (S[i]!=T[i]) {
            b=0;
            break;
        }
    }
    if (b) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 1728
N = int(input())
A = [int(_) for _ in input().split()]
A += [0]

r = 0
for i in range(N + 1):
    r += abs(A[i] - A[i - 1])

for i in range(N):
    print(r - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1]))


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

#define all(x) x.begin(),x.end()
#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd+nd+1)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()

using namespace std;

typedef long long LL;

typedef vector<int> VI;

typedef pair<int,int> PII;

inline int read(){
    int res=0, f=1;char ch=getchar();
    while(ch<'0'|ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
    return res*f;
}

const int MAXN = 200'005;

const int MOD = 1000000007;

void addmod(int& a, int b){a+=b;if(a>=MOD)a-=MOD;}
int mulmod(int a, int b){return 1ll*a*b%MOD;}

template<typename T>
void chmin(T a, T b){if(a>b)a=b;}

template<typename T>
void chmax(T a, T b){if(b>a)a=b;}

int powmod(int x, int y){
    int res=1;
    while(y){
        if(y&1)
            res=1ll*res*x%MOD;
        x=1ll*x*x%MOD;
        y>>=1;
    }
    return res;
}

int mu[MAXN];
int Prime[MAXN],isNot[MAXN],tol;

void get_mu(int n){
    mu[1]=1;
    for(int i=2;i<=n;++i){
        if(!isNot[i]){
            Prime[++tol]=i;
            mu[i]=-1;
        }
        for(int j=1;j<=tol;++j){
            if(1ll*i*Prime[j]>n)break;
            isNot[i*Prime[j]]=1;
            mu[i*Prime[j]]=-mu[i];
            if(i%Prime[j]==0){
                mu[i*Prime[j]]=0;
                break;
            }
        }
    }

    for(int i=1;i<=n;++i){
        mu[i]+=mu[i-1];
    }
}

int main(){
    int n=read();
    int k=read();

    get_mu(100005);

    LL ans=0;
    for(int l=1,r;l<=k;l=r+1){
        r=k/(k/l);
        LL sum=0;
        for(int l1=1,r1;l1<=k/l;l1=r1+1){
            r1=(k/l)/((k/l)/l1);
            sum+=1ll*(mu[r1]-mu[l1-1])*powmod((k/l)/l1,n);
            sum%=MOD;
        }
        ans+=1ll*(l+r)*(r-l+1)/2*sum;
        ans%=MOD;
    }

    ans=(ans%MOD+MOD)%MOD;
    cout<<ans;

    return 0;
}


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

typedef pair<int, int> P;

int N;
P AB[200000];
vector<int> edges[100000];
bitset<200000> done;
map<P, int> mp;
queue<P> que;

struct UnionFind {
    int par[100000];

    UnionFind(int n=0){
        if(n>0) initialize(n);
    }

    void initialize(int n){
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(edges[x].size() > edges[y].size()) swap(x, y);

        par[x] = y;
        for(int i : edges[x]){
            if(done[i]) continue;
            auto p = AB[i];
            mp.erase(p);
            add(find(p.first), find(p.second), i);
            edges[y].push_back(i);
        }
        edges[x].clear();
    }

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

    void add(int a, int b, int i){
        if(a > b) swap(a, b);
        P p = {a, b};
        AB[i] = p;
        if(mp.count(p)){
            int j = mp[p];
            done[i] = done[j] = 1;
            que.push(p);
            mp.erase(p);
        }else{
            mp[p] = i;
        }
    }

    void solve(){
        for(int i=0; i<2*N-2; i++){
            int a, b;
            cin >> a >> b;
            a--; b--;
            edges[a].push_back(i);
            edges[b].push_back(i);
            add(a, b, i);
        }

        while(que.size()){
            auto p = que.front(); que.pop();
            unite(p.first, p.second);
        }

        for(int i=0; i<2*N-2; i++){
            if(!done[i]){
                cout << "NO" << endl;
                exit(0);
            }
        }
        cout << "YES" << endl;
        exit(0);
    }
};

int main(){
    cin >> N;
    UnionFind uf(N);
    uf.solve();
    return 0;
}


Measured memory_bytes: 23552
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n; cin >> n;
    string s, t; cin >> s >> t;
    string ans = "";
    for (int i = 0; i < n; ++i) {
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
_w = input()
w = [_w[i] for i in range(len(_w))]
if len(w) % 2 == 1:
    print("No")
    exit()
w.sort()
for i in range(int(len(w)/2)):
    if w[i*2] != w[i*2+1]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3060
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
dp=[[0]*3 for _ in range(n)]
dp[0]=l[0]
for i in range(n-1):
    for j in range(3):
        dp[i+1][j]=max(dp[i][(j+1)%3]+l[i+1][j],dp[i][(j+2)%3]+l[i+1][j])
print(max(dp[n-1]))

Measured memory_bytes: 102436
sx, sy, tx, ty = map(int,input().split())
width = tx - sx
depth = ty - sy
st1 = width * 'R' + depth * 'U'
st2 = 'D' + (width + 1) * 'R' + (depth + 1) * 'U' + 'L'
back1 = width * 'L' + depth * 'D'
back2 = 'U' + (width + 1) * 'L' + (depth + 1) * 'D' + 'R'
ans = st1 + back1 + st2 + back2
print(ans)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a==1&&b==1){cout<<"Draw";return 0;}
  if(a==1){cout<<"Alice";return 0;}
  if(b==1){cout<<"Bob";return 0;}
  if(a==b) {cout<<"Draw";return 0;}
  if(a<b) cout<<"Bob";
  else cout<<"Alice";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int n, k, l;

vector<int> par1;
vector<int> par2;
vector<int> siz1;
vector<int> siz2;

int root1(int x) {
  while (x != par1[x]) {
    x = par1[x];
  }
  return x;
}

int root2(int x) {
  while (x != par2[x]) {
    x = par2[x];
  }
  return x;
}

bool merge1(int x, int y) {
  x = root1(x);
  y = root1(y);
  if (x == y) return false;
  if (siz1[x] < siz1[y]) swap(x, y);
  siz1[x] += siz1[y];
  par1[y] = x;
  return true;
}

bool merge2(int x, int y) {
  x = root2(x);
  y = root2(y);
  if (x == y) return false;
  if (siz2[x] < siz2[y]) swap(x, y);
  siz2[x] += siz2[y];
  par2[y] = x;
  return true;
}

int main() {
  cin >> n >> k >> l;
  par1.resize(n);
  par2.resize(n);
  siz1.resize(n);
  siz2.resize(n);
  rep(i, n) {
    par1[i] = i;
    par2[i] = i;
    siz1[i] = 1;
    siz2[i] = 1;
  }
  rep(i, k) {
    int p, q;
    cin >> p >> q;
    p--;
    q--;
    merge1(p, q);
  }
  rep(i, l) {
    int p, q;
    cin >> p >> q;
    p--;
    q--;
    merge2(p, q);
  }
  map<pair<int, int>, int> mp;
  rep(i, n) {
    pair<int, int> P = make_pair(root1(i), root2(i));
    mp[P]++;
  }
  rep(i, n) {
    pair<int, int> P = make_pair(root1(i), root2(i));
    cout << mp[P] << endl;
  }
  return 0;
}

Measured memory_bytes: 16128
s[51],a[51],b[51],t;short*p;Q(){for(p=a;*p=='=Q';p++);}main(i){for(;~scanf("%[^\n]\n",s);i=0)i||puts(sscanf(s,">'%[=]#%[=]%c%c",a,b,&t,a)-3||t-'~'|strcmp(a,b)?sscanf(s,">^%[Q=]~%c%c",a,&t,a)-2||t-'~'|(Q(),*p&255|p==a)?"NA":"B":"A");}

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

typedef long long ll;
//typedef pair<int, int> P;

const int INF = 1000000007;

string S;
ll m,a,r,c,h;
ll D[5]={0};

int P[10]={0,0,0,0,0,0,1,1,1,2};
int Q[10]={1,1,1,2,2,3,2,2,3,3};
int R[10]={2,3,4,3,4,4,3,4,4,4};

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>S;
		if(S[0]=='M')m++;
		if(S[0]=='A')a++;
		if(S[0]=='R')r++;
		if(S[0]=='C')c++;
		if(S[0]=='H')h++;
	}
	D[0] = m; D[1] = a; D[2] = r; D[3] = c; D[4] = h;
	ll res=0;
	for(int d=0;d<10;d++){
		res += D[P[d]]*D[Q[d]]*D[R[d]];
	}

	cout<< res <<endl;

	return 0;
}

Measured memory_bytes: 256
N,K = map(int, input().split())
A_list = [int(e) for e in input().split()]

MOD_BY = 7 + 10**9
ans = 0

for i in range(N):
    for j in range(N):
        Bi = A_list[i]
        Bj = A_list[j]
        #print(Bi,Bj,end="")
        if Bi > Bj:
            if K > 1:
                if i < j:
                    ans += (K+1)*K//2
                else:
                    ans += K*(K-1)//2
            else:
                if i > j:
                    ans += 1
                    
        ans %= MOD_BY
        #print(ans)
print(ans)

Measured memory_bytes: 41836
# coding:utf-8

import sys


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


S = input().rstrip()

dp = [[0] * 4 for _ in range(len(S) + 1)]
dp[0][0] = 1
# print(' ', dp[0][:])
for i in range(len(S)):
    # ABCカウントを更新しない
    for j in range(4):
        if S[i] != '?':
            dp[i + 1][j] += dp[i][j]
        else:
            dp[i + 1][j] += dp[i][j] * 3

        dp[i + 1][j] %= MOD

    # ABCカウントを更新する
    if S[i] in ('A', '?'): dp[i + 1][1] += dp[i][0]
    if S[i] in ('B', '?'): dp[i + 1][2] += dp[i][1]
    if S[i] in ('C', '?'): dp[i + 1][3] += dp[i][2]

    for j in range(1, 4):
        dp[i + 1][j] %= MOD

    # print(S[i], dp[i + 1][:])

print(dp[-1][-1])


Measured memory_bytes: 27608
use std::io::{self, Read};
use std::iter::Sum;

fn main() {
    let mut buf = String::new();
    io::stdin().read_to_string(&mut buf).unwrap();
    println!(
        "{}",
        15 - u64::sum(
            buf.split_ascii_whitespace()
                .map(|x| x.parse::<u64>().unwrap())
        )
    );
}


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

int main() {
  long long N;
  
  cin >>N;
vector<long long>c(N),d(N);
  for(int i=0;i<N;i++){
    cin>>c[i];
    d[i]=c[i];
  }
sort(d.begin(),d.end());
  for(int i=0;i<N;i++){
    if(c[i]<d[N/2]){
      cout<<d[N/2]<<endl;
    }
    else {
      cout<<d[N/2-1]<<endl;
    }
  }
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b; cin >> a >> b;
	if(a>=13){
		cout << b << endl;
		return 0;
	}else if(6<=a && a<=12){
		cout << b/2 << endl;
		return 0;
	}else{
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 764
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
long long int lis[200003];
int main(){
    long long int N,K;
    cin>>N>>K;
    for(int i=0;i<N;i++)cin>>lis[i];
    long long int l=0,r=2100000000,mid;
    for(int i=0;i<100;i++){
        mid=(l+r)/2;
        if(mid==0){
            cout<<1<<endl;
            return 0;
        }
        long long int cou=0;
        for(int i=0;i<N;i++){
            cou+=(lis[i]-1)/mid;
        }
        if(cou<=K)r=mid;
        else l=mid;
        if(mid==0){
            cout<<1<<endl;
            return 0;
        }
    }
    cout<<r<<endl;
    return 0;
}


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

int H, W;
char A[200][200];
bool take[200];
int main() {
	ios_base::sync_with_stdio(0);
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> A[i];
		for (int j = 0; j < W; j++) {
			if (A[i][j] == '#') take[j] = true;
		}
	}
	for (int i = 0; i < H; i++) {
		bool good = false;
		for (int j = 0; j < W; j++) {
			if (A[i][j] == '#') good = true;
		}
		if (!good) continue;
		for (int j = 0; j < W; j++) {
			if (take[j]) cout << A[i][j];
		}
		cout << '\n';
	}

	return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
int a[100005], b[100005];
int from[100005], to[100005];

const int INF = int(1e9) + 1111;
const int MOD = int(1e9) + 7;

int main() {
    cin >> n;
    forn(i, n) scanf("%d", a + i);
    forn(i, n) scanf("%d", b + i);
    forn(i, n) {
        from[i] = 1;
        to[i] = INF;
    }
    int pre = 0;
    forn(i, n) {
        if (a[i] > pre) {
            pre = a[i];
            from[i] = max(from[i], a[i]);
            to[i] = min(to[i], a[i]);
        } else {
            to[i] = min(to[i], a[i]);
        }
    }
    pre = 0;
    for (int i = n - 1; i >= 0; --i) {
        if (b[i] > pre) {
            pre = b[i];
            from[i] = max(from[i], b[i]);
            to[i] = min(to[i], b[i]);
        } else {
            to[i] = min(to[i], b[i]);
        }
    }
    int ans = 1;
    forn(i, n) {
        int cnt = to[i] - from[i] + 1;
        cnt = max(cnt, 0);
        ans = (LL)ans * cnt % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1920
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {

	int n;

	while(cin >> n, n) {
		string s;
		cin >> s;
		while(n--) {
			int i=0;
			char c;
			string r;
			while(i<s.size()) {
				int cnt=0;
				c=s[i];
				for(; i<s.size(); i++) {
					if(c==s[i]) {
						cnt++;
					}
					else {
						break;
					}
				}
				char tmp[100];
				sprintf(tmp, "%d", cnt);
				r.append(tmp);
				r.append(1, c);
			}
			s=r;
		}
		cout << s << endl;
	}

	return 0;

}

Measured memory_bytes: 0
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
const int MOD = 1000000007;

#define v_exists(elem, v) find(v.begin(),v.end(),elem)!=v.end()
#define s_exists(elem, s) s.find(elem)!=s.end()
#define mod_mul(x, y) x*y%MOD
#define mod_add(x, y) (x+y)%MOD
#define mod_sub(x, y) (x-y)%MOD
#define INF_INT 2147483647

long gcd(long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
}

long lcm( long m, long n ){
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}


long nCr(long n, long r){
    if(n==r || r==0){
        return 1;
    } else {
        return mod_add(nCr(n-1,r),nCr(n-1,r-1));
    }
}


int main(){
    
    string s; cin >> s;
    long cur =0;
    long ans =0;

    for(long i=0; i<s.length();i++){
        if(s[i]=='B'){
            cur += 1;
        } else {
            ans += cur;
        }
    }

    cout << ans << endl;

    return 0;

}


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

int main() {
  int x;
  cin>>x;
  while (1) {
    bool ok = true;
    for (int i = 2; i < x; ++i) {
      if (x%i == 0) {
        ok = false;
        break;
      }
    }
    if (ok) break;
    ++x;
  }
  cout<<x<<endl;
  return 0;
}

Measured memory_bytes: 256
s = input()
a = int(s.split()[0])
b = int(s.split()[1])
c = int(s.split()[2])
if a >= b and a >= c:
    ans = a*10 + b+c
if b >= a and b >=c:
    ans = b*10 + c + a
if c >=a and c>=b:
    ans = c*10 + a + b
    
print(int(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    map<string,int> mp;
    for(int i=0;i<n;++i){
        string s; cin >> s;
        mp[s]++;
    }
    cout << mp.size() << endl;
    return 0;
}

Measured memory_bytes: 19120
N = int(input())
vacation = []
for i in range(N):
    vacation.append(list(map(int, input().split())))

activities = 3
schedules = [[None for _ in range(activities)] for _ in range(N)]
schedules[0] = vacation[0]

for i in range(1, N):
    for j in range(activities):
        schedules[i][j] = max(schedules[i - 1][(j + 1) % 3], schedules[i - 1][(j + 2) % 3]) + vacation[i][j]

print(max(schedules[N - 1]))

Measured memory_bytes: 47384
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

#define MAX_D 10000

int dp[MAX_D][MAX_D];

void LS(string a,string b)
{
	REP(i,a.size()+1)dp[i][0] = i;
	REP(i,b.size()+1)dp[0][i] = i;
	
	for(int i = 1;i <= a.size() ;i++)
	{
		for(int j = 1;j <= b.size() ;j++)
		{
			int q = 1;
			if(a[i-1] == b[j-1])q = 0;
			dp[i][j] = min(min(dp[i-1][j-1]+q,dp[i][j-1]+1),dp[i-1][j]+1);
		}
	}	
}


int main()
{
	string a,b;
	cin >> a >> b;
	
	LS(a,b);
	
	cout << dp[a.size()][b.size()] << endl;
	
	
	return 0;
}

Measured memory_bytes: 11116
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int N, A, B, C;
int l[10];

int dfs( int i, int a, int b, int c )
{
  if( i == N )
    return a && b && c ? abs(A-a)+abs(B-b)+abs(C-c) : 100000;

  int ret = 100000;

  ret = std::min( ret, dfs( i+1, a, b, c ) );
  ret = std::min( ret, dfs( i+1, a+l[i], b, c )+(a?10:0) );
  ret = std::min( ret, dfs( i+1, a, b+l[i], c )+(b?10:0) );
  ret = std::min( ret, dfs( i+1, a, b, c+l[i] )+(c?10:0) );

  return ret;
}

int main()
{
  scanf( "%d%d%d%d", &N, &A, &B, &C );
  rep( i, N )
    scanf( "%d", l+i );

  printf( "%d\n", dfs( 0, 0, 0, 0 ) );
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int>vec(N);
    vector<int>hikaku(N);
    for (int i=0; i<N; i++) {
        cin >> vec.at(i);
        hikaku[i] = vec[i];
    }

    sort(hikaku.begin(), hikaku.end(), greater<int>());
    for (int i=0; i<N; i++) {
        int num = hikaku[0];
        if (hikaku[0] == vec[i]) {
            num = hikaku[1];
        }

        cout << num << endl;
    }
    return 0;
}

Measured memory_bytes: 4788
#include <vector>
#include <iostream>
#include <cmath>
#include <numeric>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
    int n,a[26];
    char c[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    cin >> n;
    vector<string>s(n);
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    for(int i=0;i<26;i++){
        int b=51,d;
        for(int j=0;j<n;j++){
            d=count(s[j].begin(),s[j].end(),c[i]);
            b=min(b,d);
        }
        a[i]=b;
    }
    for(int i=0;i<26;i++){
        for(int j=0;j<a[i];j++){
            cout<<c[i];
        }
    }
}

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

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

	vector<vector<long long>> x(8, vector<long long>(N));
	for(int i=0; i<N; ++i){
		long long a, b, c; cin >> a >> b >> c;
		x[0][i] = a + b + c;
		x[1][i] = a + b - c;
		x[2][i] = a - b + c;
		x[3][i] = -a + b + c;
		x[4][i] = a - b - c;
		x[5][i] = -a + b - c;
		x[6][i] = -a - b + c;
		x[7][i] = -a - b - c;
	}

	for(int i=0; i<8; ++i){
		sort(x[i].begin(), x[i].end(), greater<long long>());
	}

	long long ans = 0;
	for(int i=0; i<8; ++i){
		long long sum = 0;
		for(int j=0; j<M; ++j){
			sum += x[i][j];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256