akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100'010
#define MOD 1'000'000'007;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define repr(i, n) for(int i=(n-1); 0<=i; i--)
#define repr2(i, from, to) for(int i=(from-1); (int)(to)<=i; i--)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int to, cost; };
struct Node { int from, to, cost; };

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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}
int combination(int n, int r){
	if(r == 0 || n == r) return 1;
	else if(r == 1) return n;
	return (combination(n - 1, r - 1) + combination(n - 1, r)) % MOD;
}

int main(void){
	int n; cin >> n;
	map<string, ll> map;
	ll ans = 0;
	rep(i, n){
		string str; cin >> str;
		sort(str.begin(), str.end());
		ans += map[str];
		map[str]++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

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

    vector<int> costs(M);
    vector<int> masks(M, 0);

    for (int i = 0; i < M; i++) {
        int cost, num;
        cin >> cost >> num;
        costs[i] = cost;
        for (int j = 0; j < num; j++) {
            int idx;
            cin >> idx;
            idx--;
            masks[i] |= 1 << idx;
        }
    }

    vector<vector<int>> dp(M+1, vector<int>(1 << N, INT_MAX));
    dp[0][0] = 0;

    for (int i = 0; i < M; i++) {
        for (int j = 0; j < (1 << N); j++) {
            if (dp[i][j] == INT_MAX) continue;
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][j | masks[i]] = min(dp[i+1][j | masks[i]], dp[i][j] + costs[i]);
        }
    }

    if (dp[M][(1 << N) - 1] == INT_MAX) cout << -1 << endl;
    else cout << dp[M][(1 << N) - 1] << endl;
    return 0;
}

Measured memory_bytes: 16384
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
const double PI = acos(-1);
const double EPS = 1e-10;
 
int main(){
  int a,b;
  cin >> a >> b;
  cout << a + b/2 << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

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

	int n;
	cin >> n;
	vector<int> b(n);
	rep(i, n-1)
	{
		cin >> b[i];
	}

	ll ans = b[n - 2];

	for (int i = n - 3; i >= 0; i--)
	{
		if (b[i] <= b[i+1])
		{
			ans += b[i];
		}
		else
		{
			ans += b[i + 1];
		}
	}
	ans += b[0];
        cout<<ans<<endl;

}

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

bool checksame(vector<pair<int, int>> &sc, int &M){
  for(int i=0; i<M-1; i++){
    if((sc.at(i).first == sc.at(i+1).first)&&(sc.at(i).second != sc.at(i+1).second)) return true;
  }
  return false;
}



int main(){
  int N, M;
  cin >> N >> M;
  if(M==0) {
    if(N==1) cout << 0;
    else cout <<  pow(10, N-1);
    return 0;
  }
  
  vector<pair<int, int>> sc(M);
  for(int i=0; i<M; i++){
    int s, c;
    cin >> s >> c;
    sc.at(i) = make_pair(s, c);
  }


  sort(sc.begin(), sc.end());
  if(sc.at(0).first==1&&sc.at(0).second==0&&N!=1) cout << -1;
  else if(checksame(sc, M)&&M!=0) cout << -1;
  else if(M==0&&N==1) cout <<0;
  else{
    int ans = pow(10, N-1);
    int last = sc.at(0).first;
    if(last!=1) ans += sc.at(0).second * pow(10, N-last);
    if(last==1) ans += (sc.at(0).second-1) * pow(10, N-last);
    for(int i=1; i<M; i++){
      if(last != sc.at(i).first) ans += sc.at(i).second * pow(10,N-sc.at(i).first);
      last = sc.at(i).first;
    }
    
     cout << ans;
  }
  
}

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

int main() {
    ll int a, b, c;
    cin >> a >> b >> c;
    ll int small = 4*a*b;
    ll int large = (c-a-b)*(c-a-b);
    if(small < large && c-a-b > 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    // ll int d = c-a-b;
    // if (d > 0 and a * a + b * b + c * c > 2 * a * b + 2 * a * c + 2 * b * c) {
    //      cout << "Yes" << endl;
    //  } else {
    //      cout << "No" << endl;
    //  }

    // cout << "small:" << small << " large:" << d*d << " c-b-a:" << c-b-a << endl;

    return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		int n = as.nextInt();
		int m = as.nextInt();
		int[] a,b,d;
		int[][] e;
		a = new int[m];
		b = new int[m];
		d = new int[n];
		e = new int[n][n];
		for(int i=0;i<m;i++){
			a[i] = Integer.parseInt(as.next())-1;
			b[i] = Integer.parseInt(as.next())-1;
		}
		for(int i=0;i<m;i++){
			e[a[i]][b[i]] = 1;
			e[b[i]][a[i]] = 1;
		}
		for(int i=0;i<n;i++){
			d[i] = 0;
		}
		int l = 0;
		for(int i=1;i<n;i++){
			if(e[0][i]==1&&d[i]==0){
				if(n==2){
					l++;
					continue;
				}
				d[i]++;
			for(int i1=1;i1<n;i1++){
				if(e[i][i1]==1&&d[i1]==0){
					if(n==3){
						l++;
						continue;
					}
					d[i1]++;
				for(int i2=1;i2<n;i2++){
					if(e[i1][i2]==1&&d[i2]==0){
						if(n==4){
							l++;
							continue;
						}
						d[i2]++;
					for(int i3=1;i3<n;i3++){
						if(e[i2][i3]==1&&d[i3]==0){
							if(n==5){
								l++;
								continue;
							}
							d[i3]++;
						for(int i4=1;i4<n;i4++){
							if(e[i3][i4]==1&&d[i4]==0){
								if(n==6){
									l++;
									continue;
								}
								d[i4]++;
							for(int i5=1;i5<n;i5++){
								if(e[i4][i5]==1&&d[i5]==0){
									if(n==7){
										l++;
										continue;
									}
									d[i5]++;
								for(int i6=1;i6<n;i6++){
									if(e[i5][i6]==1&&d[i6]==0){
										l++;
									}
								}
								d[i5]--;
								}
							}
							d[i4]--;
							}
						}
						d[i3]--;
						}
					}
					d[i2]--;
					}
				}
				d[i1]--;
				}
			}
			d[i]--;
			}
		}
		System.out.println(l);
	}
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

ll N, A, B;

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

  std::cin >> N >> A >> B;

  ll n = N / (A + B), m = N % (A + B), l = std::min(m, A);
  ll ans = n * A + l;

  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n), idx(n);
    set<int> s;
    ll ans = 0;
    
    rep(i, n) {
        int p;
        cin >> p;
        a[i] = p - 1;
        idx[a[i]] = i;
    }
    
    rrep(i, n) {
        int p = idx[i];
        s.insert(p);
        auto it = s.find(p);
        vector<int> l(2, -1);
        vector<int> r(2, n);
        
        auto tmp = it;
        rep(ii, 2) {
            if (tmp == s.begin()) break;
            tmp--;
            l[ii] = *tmp;
        }
        
        tmp = it;
        rep(ii, 2) {
            tmp++;
            if (tmp == s.end()) break;
            r[ii] = *tmp;
        }
        
        if (l[0] != -1) {
            ans += (l[0] - l[1]) * (r[0] - p) * (i + 1LL);
        }
        
        if (r[0] != n) {
            ans += (r[1] - r[0]) * (p - l[0]) * (i + 1LL);
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
ll n;
vpl v[100009];
ll ans[100009];
ll e[100009];
ll k;
void dfs(ll q,ll c)
{
	e[q]=1;
	ll col=1;
	for(auto i:v[q])
	{
		if(e[i.ff]==1)
			continue;
		if(col==c)
			col++;
		ans[i.ss]=col;
		dfs(i.ff,col);
		col++;
	}
	k=max(col-1,k);
}
int main()
{
	FAST
	#ifdef ayk_16
    freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	cin>>n;
	ll x,y;
	for(ll i=1;i<n;i++)
	{
		cin>>x>>y;
		v[x].pb({y,i});
		v[y].pb({x,i});
	}
	dfs(1,0);
	cout<<k<<endl;
	for(ll i=1;i<n;i++)
	{
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
int n,m;
  cin>>n>>m;
  vector<string> a(n),b(m);
  rep(i,n){
    cin>>a[i];
  }
  rep(i,m){
    cin>>b[i];
  }
  //ぜんたん  
  bool ok=false; 
  for(int i=0;i<=n-m;i++){//hidariue tyoutenn retu
    
      for(int j=0;j<=n-m;j++){//gyou
        bool ng=false;
          for(int k=0;k<m;k++){
            
             for(int l=0;l<m;l++){
               if(ng) break;
                if(a[i+k][j+l]!=b[k][l]) {
                  ng=true;
                }//if
             }//l
            if(ng) break;
          }//k
        
        if(!ng) ok=true;
    }//j
  }//i
  
  if(ok) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}









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

using namespace std;
const int N = 1e5+2;

int f[N];
void mod(int i, int x){
    i = N-i-1;
    for (; i < N; i |= i+1)
        f[i] = max(f[i], x);
}
int get(int i){
    i = N-i-1;
    int res = 0;
    for (; i >= 0; i = (i&(i+1))-1)
        res = max(res, f[i]);
    return res;
}

int a[N], b[N];
int main(){
    int n; cin >> n;
    for (int i = 0; i < n; ++ i)
        cin >> a[i];

    int idx[n];
    iota(idx, idx+n, 0);
    sort(idx, idx+n, [&](int i, int j){
        return a[i] < a[j];
    });

    for (int i = 0, c = 0; i < n; ++ i){
        if (i && a[idx[i]] != a[idx[i-1]])
            ++ c;
        b[idx[i]] = c;
    }

    for (int i = 0; i < n; ++ i)
        mod(b[i], get(b[i])+1);
    cout << get(0) << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int area = a*b;
    int length = 2*(a+b);

    System.out.println(area +" "+length);
    sc.close();
  }
}



Measured memory_bytes: 26212
#include<bits/stdc++.h>
using namespace std;
int arr2[1000005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
    {
        int x;
        cin>>x;
        arr2[x]++;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<arr2[i]<<" ";
    }

}


Measured memory_bytes: 4436
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
bool check(int num){
    string a=to_string(num);
    if(a[0]==a[4]&a[1]==a[3])return true;
    else return false;
}
int main(void){
 int a,b;
 cin>>a>>b;
 int ans=0;
 for (int i=a;i<=b;i++){
     if(check(i)){
         ans++;
     }
 }   
 cout<<ans<<endl;
}

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

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

    int a,b,c;

    a = n/100;
    b = n /10 - a * 10;
    c = n % 10;

    if (a==9) a = 1;
    else a = 9;

    if (b==9) b = 1;
    else b =9;

    if(c==9) c = 1;
    else c = 9; 
    
    cout << 100*a + 10*b + c << endl;

	return 0;
}

Measured memory_bytes: 256
def c_make_a_rectangle(N, A):
    from collections import Counter
    count = Counter(A)  # リストの要素が何回現れたか

    cond = []  # 同じ長さのものが2個ある棒の長さ
    for k, v in count.items():
        if v == 1:  # 1個しかない棒では長方形を作れない
            continue
        else:
            cond.extend([k] * (v // 2))
    if len(cond) <= 1:
        return 0  # 長方形を作れない
    cond = sorted(cond, reverse=True)
    ans = cond[0] * cond[1]  # 長いもの2組を使う
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(c_make_a_rectangle(N, A))

Measured memory_bytes: 18316
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define cyes cout << "YES" << endl
#define cno cout << "NO" << endl
#define f(i, a, n) for(int i = a; i < n; i++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mod 1000000007
int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); }  
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
using namespace std;



int32_t main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  
  int n;cin >> n;

  cout << n + (n*n) + (n*n*n) ;

  return 0;
}

Measured memory_bytes: 3608
# include <iostream>
# include <stdint.h>
# include <stdio.h>
# include <math.h>
using namespace std;


int main(){
	const double pi =3.141592653589;
	 
	double r, a,b; 
	cin >> r;
	a =r *r * pi;
	b =2*r *pi;
	printf("%6lf\n",a ); cout <<" "; printf("%6lf\n",b );
	return 0;
}



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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

template<typename T>
struct Bit {
  int n; // 2のべき乗でなくてもOK
  vector<T> node;
  Bit(int n) : n(n), node(n + 1, 0) {}
  void add(int i, T a) { // node[i] += w
    for (int x = ++i; x <= n; x += x & -x) node[x] += a;
  }
  T sum(int i) { // return sum [0, i)
    T a = 0;
    for (int x = i; x > 0; x -= x & -x) a += node[x];
    return a;
  }
  T sum(int i, int j) { // return sum [i, j)
    return sum(j) - sum(i);
  }
  vector<T> debug() { // for debug
    vector<T> a;
    rep(i, n) a.push_back(sum(i, i + 1));
    return a;
  }
};

void solve() {
  int n;
  cin >> n;
  vi p(n);
  rep(i, n) cin >> p[i];
  Bit<int> bit(n + 1);
  ll ans = 0;
  rep(i, n) {
    if (bit.sum(0, p[i] + 1) == 0)
      ans++;
    bit.add(p[i], 1);
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int a, b, x;
	cin >> a >> b >> x;
	if(a <= x && x <= a + b) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;
    i64 sum = 0, tmp = 0;
    for (i64 i = 0; i < n; i++) {
        i64 a;
        cin >> a;
        if (a) tmp += a; else sum += tmp / 2, tmp = 0;
    }
    cout << sum + tmp / 2 << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 256
import sys
import math
from collections import deque

def insertion_sort(a, n, g):
    ct = 0
    for i in range(g,n):
        v = a[i]
        j = i-g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j = j-g
            ct += 1
        a[j+g] = v
    return ct

n = int(input())
a = list(map(int, sys.stdin.readlines()))
m = 0
b = 0
ct= 0
g = deque()
while True:
    b = 2.25*b+1
    if b > n:
        break
    g.appendleft(math.ceil(b))
    m += 1

for i in g:
    ct += insertion_sort(a, n, i)

print(m)
print(*g, sep=" ")
print(ct)
print(*a, sep="\n")

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<ll> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,h,w;
	string s;
	cin >>n >>h >>w;
	
	
	cout << (n-h +1) * (n-w+1) <<"\n";
	return 0;
}


Measured memory_bytes: 256
//arc074_d.cpp
//Wed Jan 15 08:04:37 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll n;
	cin >> n;

	ll a[3*n];
	priority_queue<ll,vector<ll>,greater<ll>> f;
	priority_queue<ll> r,tempr;
	ll tempftotal = 0;
	ll temprtotal = 0;
	for (int i=0;i<3*n;i++){
		cin >> a[i];
		if (i<n){
			f.push(a[i]);
			tempftotal += a[i];
		}else if (i>2*n-1){
			r.push(a[i]);
			tempr.push(a[i]);
			temprtotal += a[i];
		}
	}

	ll frui[n+1];
	fill(frui,frui+n+1,0);
	frui[0] = tempftotal; //0->n-1;n->2n-1
	for (int i=1;i<n+1;i++){
		ll tempmin = f.top();
		if (tempmin<a[i+n-1]){
			frui[i] = frui[i-1]+a[i+n-1]-tempmin;
			f.pop();
			f.push(a[i+n-1]);
		}else {
			frui[i] = frui[i-1];
		}
	}

	ll rrui[n+1];
	fill(rrui,rrui+n+1,0);
	rrui[n] = temprtotal;
	for (int i=n-1;i>=0;i--){
		ll tempmax = r.top();
		if (tempmax>a[i+n]){
			rrui[i] = rrui[i+1]-tempmax+a[i+n];
			r.pop();
			r.push(a[i+n]);
		}else {
			rrui[i] = rrui[i+1];
		}
	}

	ll ans = LLINF*(-1);
	for (int i=0;i<n+1;i++){
		ans = max(ans, frui[i]-rrui[i]);
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 6684
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

ll r[100002],x[100002];
int main()
{
	int n; cin>>n; ll sum=0;
	for (int i=1; i<=n; i++) 
	{
		cin>>r[i];
		sum+=r[i];
	}
	sum/=2;
	
	ll sum1=0;
    for (int i=2; i<n; i+=2) sum1+=r[i];
    x[1]=sum-sum1;
    for (int i=2; i<=n; i++)
        x[i]=r[i-1]-x[i-1];
        
    for (int i=1; i<=n; i++)
        cout << 2*x[i] << ' ';
 }

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

int main(){
    ll N,K; cin>>N>>K;
    vector<ll> A(N),F(N);
    ll Asum=0;
    for(int i=0;i<N;i++){
        cin>>A.at(i);
        Asum+=A.at(i);
    }
    for(int i=0;i<N;i++) cin>>F.at(i);
    sort(F.begin(),F.end());
    
    sort(A.begin(),A.end());

    ll OK=A.at(N-1)*F.at(N-1), NG=0;
    reverse(F.begin(),F.end()); //Fは大きい順,Aは小さい順

    if(Asum<=K) cout<<0<<endl;
    else{
        while(OK>NG+1){
            ll count=0;
            ll MID=(OK+NG)/2;

            for(int i=0;i<N;i++){
                ll C=MID/F.at(i);
                if(C<A.at(i)) count+=(A.at(i)-C);
                if(count>K) break;
            }

            if(count>K) NG=MID;
            else OK=MID;

        }
        cout<<OK<<endl;
    }


}

Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, bool isFront) {
	if (first_itr < 0 || first_itr > str.size()) {
		return str;
	}
	else {
		if (isFront) {
			std::string tmp;
			for (size_t i = 0; i < first_itr; i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
		else {
			std::string tmp;
			for (size_t i = first_itr; i < str.size(); i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
	}
}


bool dfs(int depth, str s) {
	/*if (depth == n) {
		ans.push_back(s);
		return false;
	}
	for (int i = 0; i < n; i++) {
		if (dfs(depth + 1, s + dic.at(i))) {
			return true;
		}
	}*/
	return false;
}


int main() {
	int a, b, c; cin >> a >> b >> c;
	if (a == b || a == c || b == c) {
		if (a == b && b == c) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
	else {
		cout << "No" << endl;
	}



	return 0;
}

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

int main (){
    int a,b,c;
    cin >> a >> b >> c;

    if(a<b){
        swap(a,b);
    }
    if(b<c){
        swap(b,c);
    }
    if(a<b){
        swap(a,b);
    }
    cout << 10*a+b+c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
 
int main(){
  int n;
  cin>>n;
  for(int i=1;i<n+1;i++){
    if(int(i*1.08)==n){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<":("<<endl;
}


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

using namespace std;

int somai(int n){
    int res = 0;
    while(n != 0){
        res+=n%10;
        n=n/10;
    }
    return res;
}

int main() {
    string c[3];
    cin >> c[0] >> c[1] >> c[2];

    printf("%c%c%c\n", c[0][0], c[1][1], c[2][2]);

    return 0;
}


Measured memory_bytes: 256
def main():
    n,W=map(int,input().split())
    vw=[list(map(int,input().split())) for _ in [0]*n]
    memo=[0]*(W+1)
    for i in range(W):
        for v,w in vw:
            if i+w<=W:
                memo[i+w]=max(memo[i+w],memo[i]+v)
    print(max(memo))  
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 5924
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    MOD = 1000000007
    N, *A = map(int, read().split())
    seq = [-1] * 3
    ans = 1
    try:
        for a in A:
            ans = ans * seq.count(a - 1) % MOD
            seq[seq.index(a - 1)] = a
        print(ans)
    except:
        print(0)
        
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 60068
#include <bits/stdc++.h>
#define loop(n) for(ll i=0;i<n;i++)
#define loop4(i,n) for(ll i=0;i<n;i++)
#define rng(i,a,b,c) for(ll i = a; i<b;i+=c)
#define loop2(i,a,b) for(long long i = a; i>=b;i--)
#define loop3(j,a,b) for(int j = a; j<b;j++)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long   
#define ld long double
#define SET set<ll>
#define pb push_back
#define mp make_pair
#define gc getchar_unlocked

using namespace std; 

//cout<<setprecision(4) << fixed;
/*int compare(string str1, string str2){
   if(str1.length() < str2.length())
   return 1;
   return 0;
}*/
/* int to string-
int c=0;
stringstream ss;
ss<<c;
string str=ss.str();*/
/* STRING TO INT
string s;
	cin>>s;
	reverse(s.begin(),s.end());
	stringstream ss(s);
	ll a=0;
	ss>>a;*/
//about maps
/*unordered_map <int,int> g;
loop(n)
{
	g.insert(make_pair(b[i],i));
}
 int* i1; 
    i1 = std::min_element(v + 2, v + 5); 
    cout<<*i1;
 
//getline

cin.ignore();
getline(cin,s);    

*/
// no getchar_unlocked on Windows so call _getchar_nolock
/*

 ll lcm(ll a, ll b)  
 {  
    return (a*b)/__gcd(a, b);  
 }  

inline int getchar_unlocked() { return _getchar_nolock(); }
inline ll read() {  
 ll n=0;  
 char p=getchar_unlocked();  
 while((p<'0'||p>'9')&&p!=EOF)  
 p=getchar_unlocked();  
 while(p>='0'&&p<='9')  
 {  
 n = (n<< 3) + (n<< 1) + (p - '0');  
 p=getchar_unlocked();}  
 return n;
}

void dfs(vector<ll> adj[],ll vis[],ll u)
{

	if(vis[u]==0)
	{
		cout<<u<<' ';
		vis[u]=1;
		for(auto x:adj[u])
		{
			if(vis[x]==0 )
			{
			dfs(adj,vis,x);
		    }
		}
	}
}
*/

void go()
{
	ll n;
	
	cin>>n;
	
	ll a[n];
	
	loop(n)
	cin>>a[i];
	
	ll ans=0,ma=a[0];
	
	for(ll i=0;i<n;i++)
	{
		if(ma>a[i])
		{
			ans+=ma-a[i];
		}
		else if(ma<a[i])
		{
			ma=a[i];
		}
	}
	cout<<ans<<'\n';
//
}

int main() 
{
ll t;

fast;

//cin>>t; 

//while(t--)
go();
}


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

int main(){
  ll h, w;
  cin >> h >> w;
  if(h == 1 || w == 1) {
    cout << 1 << endl;
    return 0;
  }
  ll ans = (((w+1)/2) * ((h+1)/2)) + ((w/2) * (h/2)); 
  cout << ans << endl;
  return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

int INF = 1e9;
 
using vc = vector<char>;
using vi = vector<int>;
using pii = pair<int, int>;

int N, M;
vector<vector<pii>> graph;
vi loc;

bool isValid = true;
void search(int node, int pos) {
    loc[node] = pos;
    for (pii n : graph[node]) {
        if (loc[n.first] == INF) search(n.first, pos + n.second);
        else if (loc[n.first] != pos + n.second) isValid = false;
    }
}
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> N >> M; graph.resize(N);
    
    F0R(i, M) {
        int a, b, d; cin >> a >> b >> d;
        --a; --b;
        graph[a].push_back({b, d});
        graph[b].push_back({a, -d});
    }

    loc = vi (N, INF);
    F0R(i, N) {
        if (loc[i] != INF) continue;
        search(i, 0);
    }
    cout << ((isValid) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{
  string s;
  cin>>s;
  ll len=s.length();
  cout<<s[0]<<len-2<<s[len-1]<<endl;
  return 0;
}


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

void PrintFunction(int *,int *,int count);

void PrintFunction(int *Harray,int *Warray,int count)
{
    int j;
    int k;
    int l;
    int a,b,c;
 
    for(l=0;l<count-1;l++){
        for(j=0;j<Harray[l];j++)
        {
            if( (j==0) || (j==Harray[l]-1) ) { for(k=0;k<Warray[l];k++){ printf("#"); } }
            else
            {
                printf("#");
                for(a=1;a<Warray[l]-1;a++){ printf("."); }
                printf("#");                
            } 
            printf("\n");
        }
        printf("\n");
    }
}

int main()
{
    int H[100];
    int W[100];
    int count=0;
    int i=0;

    for(i=0;i<100;i++)
    {
        scanf("%d%d",&H[i],&W[i]);
        count++;
        if( H[i]==0 && W[i]==0 ) break;
        if( (H[i]<3 || H[i]>300) || (W[i]<3 || W[i]>300) ) return  1;
    }
    PrintFunction(H,W,count);
    return 0;
}

Measured memory_bytes: 572
#####segfunc#####
def segfunc(x, y):
    return min(x, y)
#################
 
#####ide_ele#####
ide_ele = 10**9
#################
 
class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
 
    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1
 
    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele
 
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res


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



ans = (N-2)**2
yoko = [N-2 for _ in range(N-2)]
tate = [N-2 for _ in range(N-2)] 
yoko = SegTree(yoko, segfunc, ide_ele)
tate = SegTree(tate, segfunc, ide_ele)
miny = N-2
minx = N-2
for k in range(Q):
	n, x = map(int, input().split())
	if n == 1:
		y = x -2
		if y < miny:
			ans -= minx
			miny = y
			yoko.update(min(minx, N-3), miny)
		else:
			ans -= tate.query(y, N-1)
	else:
		x = x - 2
		if x < minx:
			ans -= miny
			minx = x
			tate.update(min(miny, N-3), minx)
		else:
			ans -= yoko.query(x, N-1)
print(ans)


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

int main(){
    string S;
    cin >> S;
    int ans = 1;
    string Si;
    string Sn;
    bool flag;
    Si = "";
    for(int i=0;i<S.length();i++){
        for(int j=1;j<=S.length()-i;j++){
            string tmps = S.substr(i,j);
            if((i+j)==S.length()){
                flag = false;
            }
            if(Si!=tmps){
                flag = true;
                Si = tmps;
                if((i+j)==S.length()){
                    ans--;
                }
                i += j-1;
                ans++;
                break;
            }
        }
    }
    if(flag==false){
        ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline()[:-1]
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def main():
    s=SI()
    t=SI()
    n=len(s)
    m=len(t)
    dp=[[0]*(m+1) for _ in range(n+1)]
    for i in range(n+1):dp[i][0]=i
    for j in range(m+1):dp[0][j]=j
    for i,c0 in enumerate(s):
        for j,c1 in enumerate(t):
            dp[i+1][j+1]=min(dp[i][j+1]+1,dp[i+1][j]+1,dp[i][j]+(c0!=c1))
    print(dp[n][m])

main()



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

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

int main(){
  int n;
  cin >> n;
  std::vector<int> vec(n);
  rep(i,n) {
    cin >> vec.at(i);
  }
  int minCost = 100000000;
  for (int i = 1; i < 101; i++) {
    int cost = 0;
    for (int j : vec) {
      cost += pow((i - j),2);
    }
    minCost = min(minCost, cost);
  }
  cout << minCost << endl;
}


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

int h, w;
vector<vector<int>> mas;
void dfs(int y, int x) {
    mas[y][x] = 0;

    for (int dy = -1; dy <= 1; ++dy) {
        for (int dx = -1; dx <= 1; ++dx) {
            int ny = y + dy;
            int nx = x + dx;

            if (ny < 0 || ny >= h || nx < 0 || nx >= w || mas[ny][nx] == 0)
                continue;

            dfs(ny, nx);
        }
    }
}

int main() {
    while (cin >> w >> h) {
        if (h == 0 || w == 0)
            break;
        mas.assign(h, vector<int>(w, 0));
        rep(i, h) rep(j, w) cin >> mas[i][j];

        int ans = 0;
        rep(i, h) {
            rep(j, w) {
                if (mas[i][j]) {
                    dfs(i, j);
                    ++ans;
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3324
#include <stdio.h>
long l[5001];
int main()
{
  int n,i,j,s;
  for(;;){
    scanf("%d",&n);
    if(n==0)break;
    s=0;
    for(i=1;i<=n;i++){
      scanf("%d",&j);
      s+=j;
      l[i]=s;
    }
    s=0x80000000;
    for(i=1;i<=n;i++){
      for(j=0;j<i;j++){
	if(s<l[i]-l[j]) s=l[i]-l[j];
      }
    }
    printf("%d\n", s);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H;
  char mas[10][5];
  while( cin >> H, H){
    for(int i = 0; i < H; i++){
      for(int j = 0; j < 5; j++){
        cin >> mas[i][j];
      }
    }

    int ret = 0;
    bool changed = true;

    for(int foo = 0; foo < 8; foo++){
      
      for(int q = 0; q < 8; q++){
        for(int i = H - 1; i > 0; i--){
          for(int j = 0; j < 5; j++){
            if(mas[i][j] == '*'){
              swap(mas[i][j],mas[i - 1][j]); //上から持ってくる
            }
          }
        }
      }

      for(int i = 0; i < H; i++){
        char prev = mas[i][0];
        int cnt = 0;
        for(int j = 0; j < 5; j++){
          if(mas[i][j] == '*'){
            cnt = 0;
            continue;
          }
          if(mas[i][j] != prev){
            prev = mas[i][j];
            cnt = 0;
          }
          cnt++;
          if(cnt == 3){
            ret += (mas[i][j] - '0') * 3;
            for(int k = j, l = 0; l < cnt; l++, k--){
              mas[i][k] = '*';
            }
          } else if(cnt > 3){
            ret += (mas[i][j] - '0');
            mas[i][j] = '*';
          }
        }
      }
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 1160
while 1:
	a, b, c = map(int, input().split())
	if a == 0: break
	ans = 0
	for p1 in range(1, c+1):
		for p2 in range(p1, c+1):
			t = p1 + p2 + (p1*a)//100 + (p2*a)//100
			if t > c: break
			if t != c: continue
			t = p1 + p2 + (p1*b)//100 + (p2*b)//100
			if t > ans: ans = t
	print(ans)


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

typedef long long ll;

int main(){
  int h,w,a,b; scanf("%d%d%d%d", &h, &w, &a, &b); 
  
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if( (i < b && j < a) || ( b <= i && a <= j)){ printf("%c", '0');}
      if( (b <= i && j < a) || ( i < b && a <= j)){ printf("%c", '1');} 
    }
    printf("\n");
  }
  
  return 0;
}

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

int main(){
  int cnt=0;
  int s,e;
  int m1,s1,m2,s2;
  int n,m;
  int nn[101]={0},mm[101]={0};
  int teans=0;
  int stans=0;
  int ans=0;
  cin>>cnt; 
  int data[cnt][2];
  for(int i=0;i<cnt;i++){
    scanf("%d:%d-%d:%d",&m1,&s1,&m2,&s2);
    data[i][0]=m1*60+s1,data[i][1]=m2*60+s2;
  }
  cin>>n;
  int teacher[101][101][2]={0};
  for(int i=0;i<n;i++){
    
    cin>>nn[i];
    //teacher[i].pb(
    for(int j=0;j<nn[i];j++){
      scanf("%d:%d-%d:%d",&m1,&s1,&m2,&s2);
      teacher[i][j][0]=m1*60+s1,teacher[i][j][1]=m2*60+s2;
    }
  }
  cin>>m;
  int student[101][101][2]={0};
  for(int i=0;i<m;i++){
    cin>>mm[i];
    for(int j=0;j<mm[i];j++){
      scanf("%d:%d-%d:%d",&m1,&s1,&m2,&s2);
      student[i][j][0]=m1*60+s1,student[i][j][1]=m2*60+s2;
    }
  }
  for(int i=0;i<cnt;i++){
    teans=0;
    stans=0;
    for(int j=0;j<n;j++){
      for(int k=0;k<nn[j];k++){
	if(teacher[j][k][0]<=data[i][0] && teacher[j][k][1]>=data[i][1]){
	  teans++;
	}
      }
    }
    for(int a=0;a<m;a++){
      for(int b=0;b<mm[a];b++){
	if(student[a][b][0]<=data[i][0] && student[a][b][1]>=data[i][1]){
	  stans++;
	}
      }
    }
    ans+=min(teans,stans);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int H = scan.nextInt();
        int W = scan.nextInt();
        int i;
        int U;
        int K = 1;
        while (H != 0 || W != 0) {
            for (U = 1; U <= H; U++) {
                for (i = 1; i <= W; i++) {
                    System.out.print("#");

                }
                System.out.println("");

            }
            System.out.println("");
            H = scan.nextInt();
            W = scan.nextInt();
            K++;
        }
    }
}


Measured memory_bytes: 34720
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define int long long
 



 
 
 signed main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    
    
    
    int T; 
    T=1;
    //cin>>T;
    while(T--)
    {
        
       int n,m;  cin>>n>>m;
       int a[n][m];
       for(int i=0;i<n;i++)
       {
           for(int j=0;j<m;j++)
           {
               char ch; cin>>ch;
               if(ch=='#')a[i][j]=-1;
               else a[i][j]=1;
           }
       }
       int dp[n+1][m+1];
       int mod=1000000007;
       for(int i=0;i<=n;i++)
       {
           for(int j=0;j<=m;j++)
           {
               if(i==1&&j==1)dp[i][j]=1;
               else if(i==0||j==0)dp[i][j]=0;
               else if(a[i-1][j-1]==-1)dp[i][j]=0;
               else
               {
                    dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;   
               }
               //cout<<dp[i][j]<<" ";
           }
          // cout<<endl;
       }
       cout<<dp[n][m];
       
    }
    
        return 0;
	
}

Measured memory_bytes: 19296
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll K, val;

int main() {
	
	ios_base::sync_with_stdio(false);
	cin >> K;
	val = 7;
	for(int i = 1; i <= 10000000; i++) {
		if(val % K == 0) {
			cout << i;
			return 0;
		}
		val = val*10+7;
		val %= K;
	}
	cout << "-1";
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

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

  int cnt=1;
  rep(i,2,n){
    if((int)(log10(i))%2==0) cnt++;
  }

  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
int main(){
  char S[1200];
  int i=0;
  char ch;
  while((ch=getchar())!=EOF){
    char u_ch,l_ch;
    u_ch=toupper(ch);
    l_ch=tolower(ch);
    if(ch!=u_ch)S[i]=u_ch;
    else if(ch!=l_ch)S[i]=l_ch;
    else S[i]=ch;
    i++;
  }
  S[i]='\0';
  printf("%s",S);
  return 0;
}

Measured memory_bytes: 2684
//waz
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
using namespace std;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

const int MaxN = 1e5 + 10, mod = 1e9 + 7;

char str[MaxN];
int n, cnt[26];

int main() {
  scanf("%d", &n);
  scanf("%s", str + 1);
  for (int i = 1; i <= n; ++i) {
  	++cnt[str[i] - 'a'];
  }
  int ans = 1;
  for (int i = 0; i < 26; ++i) {
  	ans = 1LL * ans * (cnt[i] + 1) % mod;
  }
  printf("%d\n", (ans + mod - 1) % mod);
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
using namespace std;
#define S 1000000
typedef struct{char n[10];int t;}QUE;
QUE que[S];
main(){
int i=0,T=0,h=0,t,n,q;
scanf("%d %d",&n,&q);
for(t=n;i<n;)scanf("%s %d",que[i++].n,&que[i].t);
while(h!=t){
bool f=que[h].t<=q||t-h==1;
T+=f?que[h].t:q;
if(f)printf("%s %d\n",que[h].n,T);
else{que[h].t-=q;que[t]=que[h];t=S==t+1?0:t+1;}
h=S==h+1?0:h+1;
}
}


Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    // 入力
    int D;
    cin >> D;   // D = 365
    ll c[26];
    for(int i=0;i<26;i++)
        cin >> c[i];
    ll s[D][26];
    for(int i=0;i<D;i++)
        for(int j=0;j<26;j++)
            cin >> s[i][j];
    // 初期解t[D]
    int t[D];
    for(int i=0;i<D;i++)
        cin >> t[i];
    // クエリ
    int M;
    cin >> M;
    int d[M], q[M];
    for(int i=0;i<M;i++)
        cin >> d[i] >> q[i];


    // 処理部
    for(int query=0;query<M;query++){
        int last[26] = {};
        // コンテスト種別の変更
        t[d[query]-1] = q[query];
        // D日分
        ll v = 0;
        for(int i=1;i<=D;i++){
            // 満足度の増加分
            v += s[i-1][t[i-1]-1];
            last[t[i-1]-1] = i;
            // 満足度の低下分（コンテスト26種分）
            for(int j=0;j<26;j++)
                v -= c[j]*(i - last[j]);
        }
        cout << v << endl;
    }

}

Measured memory_bytes: 4288
import sys

n = int(sys.stdin.readline().rstrip())
s, t = sys.stdin.readline().split()

def main():
    res = [None] * n * 2
    res[::2] = list(s)
    res[1::2] = list(t)
    return ''.join(res)

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 2940
#[allow(dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(dead_code)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(dead_code)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h: usize,
        a:usize
    }
    let result = if h % a == 0 {
        h / a
    } else {
        h / a + 1
    };
    println!("{}", result);
}


Measured memory_bytes: 4352