akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

typedef long long ll;

int sum[2010][2010] = {};
int dot[2010][2010] = {};

int findDot(int x1, int y1, int x2, int y2)
{
    if (x2 < x1 || y2 < y1) return 0;
    return sum[x2][y2] - sum[x2][y1-1] - sum[x1-1][y2] + sum[x1-1][y1-1];
}

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

    int x, y;
    char c;
    for (int i = 0; i < N; ++i)
    {
        cin >> x >> y >> c;

        if (c == 'W') y += K;

        dot[x % (2*K) + 1][y % (2*K) + 1] += 1;
    }

    for (int i = 0; i < 2*K + 2; ++i)
    {
        for (int j = 0; j < 2*K + 2; ++j)
        {
            sum[i+1][j+1] = sum[i+1][j] + sum[i][j+1] - sum[i][j] + dot[i+1][j+1];
        }
    }

    int ans = 0;
    int tmp = 0;
    for (int x = 1; x <= K; ++x)
    {
        for (int y = 1; y <= K; ++y)
        {
            tmp = findDot(x, y, x+K-1, y+K-1)
                + findDot(x+K, y+K, 2*K, 2*K)
                + findDot(1, 1, x-1, y-1)
                + findDot(1, y+K, x-1, 2*K)
                + findDot(x+K, 1, 2*K, y-1);
            ans = max(ans, max(tmp, N-tmp));
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 31744
import java.util.*;
public class Main{
 public static void main(String[] args){
 Scanner sc = new Scanner(System.in);
for(int i = 1; i<20000;i++){
 int x = sc.nextInt() ;
 if(x == 0) break;
 if(x != 0){System.out.println("Case " + i +": "  + x);}
}}}


Measured memory_bytes: 42736
#include <bits/stdc++.h>
#include <cstdlib>  //abs()で絶対値を取得する（整数）
#include <cmath>    //abs()かfabs()で絶対値を取得する（少数）
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    ll n;
    ll a;
    ll b = 0;
    ll ans = 0;
    cin >> n;
    rep (i,n){
        cin >> a;
        if (b < a){
            b = a;
        }
        if (b > a){
            ans = ans + b - a;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
import java.util.Scanner;

class Main {

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

        int m = scan.nextInt();
        int f = scan.nextInt();
        int b = scan.nextInt();

        if (m >= b) {
            System.out.println(0);
        } else if (m + f >= b) {
            System.out.println(b - m);
        } else {
            System.out.println("NA");
        }
    }

}


Measured memory_bytes: 26188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n,y;
  cin >> n >> y;
  for(int a=0; a<=n; a++){
    for(int b=0; b<=n; b++){
      int c = n-(a+b);
      if(c<0) continue;
      if(10000*a+5000*b+1000*c==y){
        cout << a << " " <<  b << " " << c << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MOD = 998244353;

int sum(int a, int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int sub(int a, int b) {
    return a - b < 0 ? a - b + MOD : a - b;
}
int mul(int a, int b) {
    return (1LL*a*b)%MOD;
}
int pw(int a, int b) {
	if (!b) return 1;
	int r = pw(a, b/2);
	r = mul(r, r);
	if (b%2) r = mul(r, a);
	return r;
}

const int MAXX = 4007;
int fact[MAXX], ifact[MAXX];

int nCr(int n, int r) {
    if (r < 0 || n < r) return 0;
    return mul(fact[n], mul(ifact[r], ifact[n-r]));
}

int split(int elements, int buckets) {
    return nCr(elements+buckets-1, buckets-1);
}

int p2[MAXX];
int ans[MAXX];

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

    fact[0] = 1;
    for (int i = 1; i < MAXX; i++)      fact[i] = mul(i, fact[i-1]);
    ifact[MAXX-1] = pw(fact[MAXX-1], MOD-2);
    for (int i = MAXX-2; i >= 0; i--)   ifact[i] = mul(i+1, ifact[i+1]);
    p2[0] = 1;
    for (int i = 1; i < MAXX; i++) p2[i] = mul(p2[i-1], 2);

    int k, n;
    cin >> k >> n;

    for (int i = 3; i <= k+1; i += 2) {
        int have = i/2;
        for (int bam = 0; bam <= have && bam <= n; bam++) {
            int tmp = mul(nCr(have, bam), p2[bam]);
            tmp = mul(tmp, split(n-bam, k-have*2+bam));
            ans[i] = sum(ans[i], tmp);
//            cout << "bam: " << bam << " -> " << tmp << endl;
        }
//        cout << "ans[" << i << "] = " << ans[i] << endl;
    }

    for (int i = 2; i <= k+1; i += 2) {
        int have = i/2 - 1;
        for (int bam = 0; bam <= have && bam <= n; bam++) {
            int tmp = mul(nCr(have, bam), p2[bam]);
            int z = split(n-bam, k-have*2+bam-1);
            if (bam < n) {
                z = sum(z, split(n-bam-1, k-have*2+bam-1));
            }
            ans[i] = sum(ans[i], mul(tmp, z));
        }
//        cout << "ans[" << i << "] = " << ans[i] << endl;
    }

//    for (int i = 2; i <= k+k; i++) cout << ans[i] << "\n";

    for (int i = 2; i <= k+1; i++)    cout << ans[i] << "\n";
    for (int i = k; i >= 2; i--)  cout << ans[i] << "\n";


    return 0;
}


Measured memory_bytes: 3676
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int a=0,b=0;
	boolean na = true,first = true;

	while(sc.hasNext()){
	    a = sc.nextInt();
	    b = sc.nextInt();
	    if(a==0 && b==0) break;

	    if(!first) System.out.println();
	    na = true;

	    for(int i = a;i<=b;i++){
		if(i%4==0){
		    if(i%100==0){
			if(i%400==0){ System.out.println(i); na = false; }
		    }else{ System.out.println(i); na = false; }
		}
	    }

	    if(na) System.out.println("NA");
	    first = false;
	}
    }
}

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

typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;
typedef vector<vector<int> > ivve;

#define sp         ' '
#define endl       '\n'
#define F          first
#define S          second
#define pb         push_back
#define mp         make_pair 
#define GCD(x,y)   __gcd(x,y)
#define lb         lower_bound
#define up         upper_bound
#define setp       setprecision
#define bs         binary_search
#define all(x)     x.begin(),x.end()
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define spc(x)     cout<<fixed<<setp(x)

const   long long  inf = 1e18;
const   long long  cs =  200005;
const   long long  mod = 1000000007;
const   double     PI =  2 * acos(0.0);
void solve()
{
    ll t,n,m,a,b,c,d,e,i,j,k,x,y,z,cnt=0,cnt1=0;
    bool flag = false;
    
    string s,s1,s2;
    cin>>s>>s1>>s2;
    cout<<s[0]<<s1[1]<<s2[2]<<endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);

    // freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);

    // int32_t tc;
    // cin>>tc;
    // while(tc--)
    solve();

    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x-r>=0&&x+r<=W&&y-r>=0&&y+r<=H){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1816
d = {}
_ = input()
for x in input().split():
    x = int(x)
    d[x] = d.get(x, 0) + 1
p = []
for k, v in d.items():
    if v >= 4: p.append(k)
    if v >= 2: p.append(k)
if len(p) < 2: print(0)
else:
    p.sort(reverse=True)
    print(p[0] * p[1])


Measured memory_bytes: 23692
N = gets.to_i
D = Array.new N

count = 0
N.times do |i|
    d1, d2 = gets.split.map(&:to_i)
    if d1 == d2
        count += 1
    else
        count = 0
    end
    if count == 3
        puts 'Yes'
        exit
    end
end

puts "No"

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

int main(){
    int people[4][3][10]={0} ;
    int n, b, f, r, v, p, q, s; // b棟f階r番目v人
    cin >> n;
    while(n-- > 0){
        cin >> b >> f >> r >> v;
        for(p=0; p<4; p++){
            for(q=0; q<3; q++){
                for(s=0; s<10; s++){
                    if (p==(b-1)&&q==(f-1)&&s==(r-1)){
                        people[p][q][s]+=v;
                    }
                }
            }
        }
    }
    for(p=0; p<4; p++){
        for(q=0; q<3; q++){
            for(s=0; s<10; s++){
                cout << " " << people[p][q][s];
            }
            cout <<endl;
        }
        if(p<3){
            cout << "####################" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3108
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n;
  cin >> n;

  vector<int> a(n);
  REP(i,n) cin >> a[i];
  
  int ans = 0, now = 0;
  REP(i,n-1){
    if(a[i] >= a[i+1]) now++;
    else ans = max(ans,now), now = 0;
  }

  cout << max(ans,now) << endl;

  return 0;
}

Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    x=II()
    s=set()
    etoa={}
    for a in range(1000000):
        s.add(a**5)
        etoa[a**5]=a
    for b in range(1000000):
        t=x+b**5
        if t in s:
            print(etoa[t],b)
            break
        t=x-b**5
        if t<0:continue
        if t in s:
            print(etoa[t],-b)
            break

main()

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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i=0;i<N;i++) cin >> H[i];
  
  int suc = 0;
  int fail = 0;
  
  for (int i=0;i<N-2;i++){
    if (fail > 0) break;
    if (H[i] >= (H[i+1]+2)){
      //cout << i << "NO1" << endl;//test
      fail ++;
      break;
    }
    if (H[i] == (H[i+1]+1)){
      for (int j=i+2;j<N;j++){
        if (H[j] < H[i+1]){
          fail ++;
          break;
        }
      }
    }
  }
  
  //cout << suc << endl; //test
  //cout << fail << endl; //test
  
  if (fail == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 640
n, m = map(int, input().split())
h = list(map(int , input().split()))

G = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
#print(G)
ans = 0
for i in range(n):
    maxh = 0
    for gi in G[i]:
        maxh = max(h[gi], maxh)
    if maxh < h[i]:
        ans += 1
    #print(maxh, h[i])

print(ans)


Measured memory_bytes: 29436
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  ll N; cin>>N;
  if (N < 3){
    cout<<0<<endl;
    return 0;
  }
  vector<ll> A(N, 0);
  rep(i, N){
    cin>>A[i];
  }
  ll ans = 0;
  for(ll i=0; i<N-2; i++){
    for(ll j=i+1; j<N-1; j++){
      for(ll k=j+1; k<N; k++){
        if (A[i] == A[j] || A[j] == A[k] || A[k] == A[i])
          continue;
        ll a = max(A[i],max(A[j],A[k]));
        ll all = A[i]+A[j]+A[k];
        if (all - a > a) ans++;
      }
    }
  }

	cout<<ans<<endl;

}

Measured memory_bytes: 3660
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1e+9;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


int fac(int num) {
  if(num==1) return 1;
  else return num*fac(num-1);
}


bool a,b,c,ok;
int main() {
  string s;cin >> s;
  rep(i,3) if(s[i] == 'a') a = true;
  rep(i,3) if(s[i] == 'c') c = true;
  rep(i,3) if(s[i] == 'b') b = true;
  if(a && b && c) ok = true;
  cans(ok);
  return 0;
}


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

int main ()
{
    int a,b;
    cin >> a >> b;
    int cnt = 0;

    for(int i = a; i <= b; i++){
        int n = i;
        int k = ((n / 10000) % 10) + ((n / 1000) % 10) * 10 + ((n / 100) % 10) * 100 + ((n /10) % 10) * 1000 + ((n % 10) * 10000);  
        if(k == i){
            cnt++;
        }
    }
    cout << cnt;
}

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

int main(){
    double a, b, x; cin >> a >> b >> x;
    double ans;
    if(a*a*b/2.0 >= x) ans = atan(a*b*b/(2*x));
    else{
        double y = a*a*b - x;
        ans = atan(2*y/(a*a*a));
    }
    ans *= 180/acos(-1.0);
    printf("%.10f", ans);
}

Measured memory_bytes: 512
import java.util.Scanner

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val in = new Scanner(System.in)

  def solve(n: Int): Long = {
    val xyz = (for (_ <- 0 until n) yield {
      Array(in.nextInt(), in.nextInt(), in.nextInt()).sorted
    }).toArray


    val source = n * 2
    val sink = source + 1
    val minimumCostFlow = new MinimumCostFlow(sink + 1)
    for {
      i <- 0 until n
      j <- 0 until n
      if i != j
      if xyz(i)(0) < xyz(j)(0)
      if xyz(i)(1) < xyz(j)(1)
      if xyz(i)(2) < xyz(j)(2)
    } {
      minimumCostFlow.addEdge(i, n + j, 1, 0)
    }
    for (i <- 0 until n) {
      minimumCostFlow.addEdge(source, i, 1, 0)
      minimumCostFlow.addEdge(i, sink, 1, xyz(i)(0) * xyz(i)(1) * xyz(i)(2))
      minimumCostFlow.addEdge(i + n, sink, 1, 0)
    }
    minimumCostFlow.calculateCost(source, sink, n)
  }

  def loop(): Unit = {
    while (true) {
      val n = in.nextInt()
      if (n == 0) {
        return
      }
      val ans = solve(n)
      println(ans)
    }
  }

  loop()

}

class Edge(val to: Int, var cap: Long, val cost: Long, val rev: Int)

class MinimumCostFlow(V: Int) {
  val graph: Array[ArrayBuffer[Edge]] = (for (_ <- 0 until V) yield new ArrayBuffer[Edge]()).toArray
  val prevV = new Array[Int](V)
  val prevE = new Array[Int](V)

  def addEdge(from: Int, to: Int, cap: Long, cost: Long): Unit = {
    graph(from).append(new Edge(to, cap, cost, graph(to).size))
    graph(to).append(new Edge(from, 0, -cost, graph(from).size - 1))
  }

  def calculateCost(source: Int, sink: Int, flow: Long): Long = {
    val INF = Long.MaxValue / 2
    var cost = 0L
    var residue = flow
    val potential = new Array[Long](V)
    while (residue > 0) {
      val dist = Array.fill[Long](V)(INF)
      dist(source) = 0
      val queue = mutable.PriorityQueue.empty[(Long, Int)](implicitly[Ordering[(Long, Int)]].reverse)
      queue.enqueue((0, source))
      while (queue.nonEmpty) {
        val p = queue.dequeue()
        val v = p._2
        if (dist(v) >= p._1) {
          for (i <- graph(v).indices) {
            val e = graph(v)(i)
            val u = e.to
            if (e.cap > 0 && dist(u) > dist(v) + e.cost + potential(v) - potential(u)) {
              dist(u) = dist(v) + e.cost + potential(v) - potential(u)
              prevV(u) = v
              prevE(u) = i
              queue.enqueue((dist(u), u))
            }
          }
        }
      }
      if (dist(sink) == INF) {
        return -1
      }

      for (v <- 0 until V) {
        potential(v) += dist(v)
      }
      var d = residue
      var v = sink
      while (v != source) {
        d = math.min(d, graph(prevV(v))(prevE(v)).cap)
        v = prevV(v)
      }
      residue -= d
      cost += d * potential(sink)

      v = sink
      while (v != source) {
        val e = graph(prevV(v))(prevE(v))
        e.cap -= d
        graph(v)(e.rev).cap += d
        v = prevV(v)
      }
    }
    return cost
  }
}

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

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

    vector<int> cnt(N);
    rep(i, K){
        int d;
        cin >> d;
        rep(j, d){
            int sunuke;
            cin >> sunuke;
            ++cnt.at(sunuke - 1);
        } 
    }
    int ans = 0;
    rep(i, N){
        if (cnt.at(i) == 0) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
function Main(input) {
	var str = input;
	var ans = 1n;
	var flg = true;
	var count = 1;
	var str = str.split("\n");
	var a = str[1].split(" ");
	for(var j = 0;j<a.length;j++){
		a[j]=BigInt(a[j]);
		if(a[j]===0n){
			ans = 0;
			break;
		}
	}
	if(ans !==0){
	for(var i = 0;i<a.length;i++){
		ans = ans*a[i];

		if(ans > 10**18){
			ans = -1;
          break;
			}
    	}
  	if(ans !== -1){
  	ans = ans.toString();
    }
	}
   console.log(ans);
   }
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 43960
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

double num[100003];

int main()
{
    int N,M;
    cin>>N>>M;
    priority_queue<double> array;
    
    double tmp;
    for(int i=0;i<N;i++)
    {
        cin>>tmp;
        array.push(tmp);
    }


    for(int i=0;i<M;i++)
    {
        tmp=array.top();
        array.pop();
        tmp=tmp/2;
        array.push(tmp);
    }

    long long ans=0;
    while(!array.empty())
    {
        ans+=int(array.top());
        array.pop();
    }
    
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <unordered_map>
#include <array>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <random>
#include <numeric>

#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;

const int MAX_N = 100;
int N, x;
int a[MAX_N];

int main() {
  cin >> N >> x;
  rep(i, N) cin >> a[i];

  sort(a, a+N);

  ll sum = 0;
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    sum += a[i];
    if (sum <= x) ++ans;
    else break;
  }

  if (ans == N && sum < x) --ans;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

A, B, C, X, Y = map(int, input().split(' '))
set_price = min(A+B, C*2)
set_num = min(X, Y)

ans = set_price * set_num
if X > Y:
    ans += min(A, C*2) * (X-Y)
elif X < Y:
    ans += min(B, C*2) * (Y-X)
print(ans)

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

int main(){
    int h, a;
    cin >> h >> a;

    int ans = 0;

    while (h > 0) {
        h -= a;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, d: [usize; n]);

    let mut sum = 0;
    for i in 0..n {
        for j in i + 1..n {
            sum += d[i] * d[j];
        }
    }

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


Measured memory_bytes: 2152
while True:
    H,W=map(int,input().split())
    if H!=0 and W!=0:
        for a in range(1):
            for b in range(W):
                print('#',end='')
            print('')
        for a in range(H-2):
            print('#',end='')
            for b in range(W-2):
                print('.',end='')
            print('#')
        for a in range(1):
            for b in range(W):
                print('#',end='')
            print('')
        print('')
    else:break


Measured memory_bytes: 7004
s=gets.strip.split('')

result = nil
(s.length-1).times do|i|
  result = [i, i+1].map {|e| e+1 } if s[i]==s[i+1]
  result = [i, i+2].map {|e| e+1 } if i+2<s.length && s[i]==s[i+2]
  break if result
end

if result
  puts result.join(' ')
else
  puts '-1 -1'
end


Measured memory_bytes: 6908
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g $PROGRAM -o $OUTPUT -DLOCAL -lasan -lubsan
	#include <bits/stdc++.h>
	#include <ext/pb_ds/detail/standard_policies.hpp>
	#include <complex.h>
	#define ll long long
	#define ull unsigned long long
	#define pb push_back
	#define mp make_pair
	#define all(x) (x).begin(), (x).end()
	#define alli(a, n, k) (a + k), (a + n + k)
	#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
	#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
	#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
	#define eps 1e-6
	#define pi 3.141592653589793
	using namespace std;
	using namespace __gnu_pbds;

	template <class T>
	inline T gcd(T x, T y)
	{
		if (!y)
			return x;
		return gcd(y, x % y);
	}
	typedef vector<int> VII;
	typedef vector<ll> VLL;
	typedef pair<int, int> PII;
	typedef vector<pair<int, int>> VPII;
	typedef vector<pair<int, PII>> VPPI;
	const int MOD = 1e9 + 7;
	const int INF = 1e9;

	inline ll modulo(ll a, ll m)
	{
		return (a % m + m) % m;
	}

	inline ll modInverse(ll a, ll m)
	{
		assert(__gcd(a, m) == 1);
		ll m0 = m;
		ll y = 0, x = 1;

		if (m == 1)
			return 0;

		while (a > 1)
		{
			ll q = a / m;
			ll t = m;

			m = a % m, a = t;
			t = y;

			y = x - q * y;
			x = t;
		}

		if (x < 0)
			x += m0;

		return x;
	}

	inline ll modPow(ll x, ll y, ll m)
	{ //x^y % m
		if (y == 0)
			return 1LL;
		else if (y == 1)
			return x;
		else
		{
			ll ans = modPow(x, y / 2, m) % m;
			if (y & 1)
			{
				return (((ans * ans) % m) * x) % m;
			}
			else
			{
				return (ans * ans) % m;
			}
		}
	}

	vector<string> split(char d,string s)
	{
		stringstream ss(s);
		string t;
		vector<string> words;
		while(getline(ss,t,d))
		{
			words.pb(t);
		}

		return words;
	}

	int main(int argc, char *argv[])
	{
	#ifdef LOCAL
		auto start = chrono::high_resolution_clock::now();
	#endif
		
		ios::sync_with_stdio(false);
		cin.tie(NULL);

		double x;
		cin >> x;
		for (int i = -1000; i <= 1000;++i)
		{
			double v1 = pow(i, 5);
			for (int j = -1000; j <= 1000;++j)
			{
				double v2 = pow(j, 5);
				if(v1-v2==x)
				{
					cout << i << ' ' << j;
					return 0;
				}

			}
		}
	#ifdef LOCAL
			auto end = chrono::high_resolution_clock::now();
		double time_taken =
			chrono::duration_cast<chrono::nanoseconds>(end - start).count();

		time_taken *= 1e-9;

		cerr << "\nTime taken by program is : " << fixed
			<< time_taken << setprecision(9);
		cerr << " sec" << endl;
	#endif
		return 0;
	}


Measured memory_bytes: 4220
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int maxn = 1000005;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;

int n, A, B;
int fac[maxn], inv[maxn];
int c[maxn], w[maxn], minci[maxn];
int Gs[maxn];

inline int pow(int a, int b)
{
	int ans = 1;
	for(; b; b >>= 1, a = (LL) a * a % mod)
		if(b & 1)
			ans = (LL) ans * a % mod;
	return ans;
}

inline int C(int n, int m)
{
	if(!n)
		return 1;
	if(m < n)
		return 0;
	return (LL) fac[m] * (LL) inv[m - n] % mod * (LL) inv[n] % mod;
}

int main()
{
//	freopen("keep.in", "r", stdin);
//	freopen("keep.out", "w", stdout);
	scanf("%d%d%d", &n, &A, &B);
	memset(minci, 0x3f, sizeof(minci));
	for(int i = 1; i <= n; ++i)
	{
		scanf("%d%d", &c[i], &w[i]);
		minci[c[i]] = min(minci[c[i]], w[i]);
	}
	int minn = 0, minnn = 0;
	for(int i = 1; i <= n; ++i)
	{
		if(minci[i] < minci[minn])
		{
			minnn = minn;
			minn = i;
		}
		else if(minci[i] < minci[minnn])
			minnn = i;
	}
//	cout << "ys = " << ystop << endl;
//	A = max(A, B);
	int gss = 0;
	for(int i = 1; i <= n; ++i)
	{
		if(w[i] + minci[c[i]] <= A)
			w[i] = minci[c[i]];
		if(c[i] == minn && minci[minnn] + w[i] <= B)
		{
			Gs[c[i]]++;
			gss++;
		}
		if(c[i] != minn && minci[minn] + w[i] <= B)
		{
			Gs[c[i]]++;
			gss++;
		}
	}
	int ans = 1;
	fac[0] = 1;
	for(int i = 1; i <= n; ++i)
		fac[i] = (LL) i * fac[i - 1] % mod;
	inv[n] = pow(fac[n], mod - 2);
	for(int i = n - 1; ~i; --i)
		inv[i] = (LL) inv[i + 1] * (i + 1) % mod;
	for(int i = 1; i <= n; ++i)
	{
		if(Gs[i])
		{
//			cout << i << ' ' << Gs[i] << endl;
//			cout << gs[i] << ' ' << gss << ' ' << ans << endl;
			ans = (LL) ans * (LL) C(Gs[i], gss) % mod;
			gss -= Gs[i];
		}
	}
	printf("%d\n", ans);
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}

/*
4 7 3
3 2
4 3
2 1
4 4
*/

Measured memory_bytes: 19456
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

class unionfind {
	vector<int> par;
	vector<P> sz;
public:
	unionfind(int n, vector<char> a) {
		par = vector<int>(n);
		sz = vector<P>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			if (a[i] == '#') sz[i] = { 1,0 };
			else sz[i] = { 0,1 };
		}
	}
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	int si(int x) {
		return sz[find(x)].first * sz[find(x)].second;
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (sz[x] < sz[y]) {
			par[x] = y;
			sz[y].first += sz[x].first;
			sz[y].second += sz[x].second;
		}
		else {
			par[y] = x;
			sz[x].first += sz[y].first;
			sz[x].second += sz[y].second;
		}
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int h, w;
	cin >> h >> w;
	vector<char> a(h*w);
	rep(i, h*w) cin >> a[i];
	unionfind uni(h*w,a);
	rep(i, h) {
		rep(j, w) {
			if (i != h - 1 && a[i*w + j] != a[i*w + j + w]) uni.unite(i*w + j, i*w + j + w);
			if (j != w - 1 && a[i*w + j] != a[i*w + j + 1]) uni.unite(i*w + j, i*w + j + 1);
		}
	}
	int ans = 0;
	set<int> st;
	rep(i, h*w) {
		if (!st.count(uni.find(i))) {
			ans += uni.si(i);
			st.insert(uni.find(i));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 10228
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int X[100010], Y[100010], V[100010], S[2010][2010], tot = 0;

void add(int x, int y) {
    S[x][y]++;
}

void del(int x, int y) {
    tot++;
    S[x][y]--;
}

int main() {
    int n, K;
    scanf("%d%d", &n, &K);
    for(int i = 1; i <= n; i++) {
        char ch[2];
        scanf("%d%d%s", &X[i], &Y[i], ch);
        if(ch[0] == 'B') V[i] = 1; else V[i] = 0;
        if(V[i] == 1) add(X[i] % (K * 2) + 1, Y[i] % (K * 2) + 1);
        else del(X[i] % (K * 2) + 1, Y[i] % (K * 2) + 1);
    }
    for(int i = 1; i <= K * 2; i++)
        for(int j = 1; j <= K * 2; j++) {
            S[i][j] += S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1];
        }
    int ans = 0;
    for(int i = 1; i <= K; i++)
        for(int j = 1; j <= K; j++) {
            int tmp = S[K * 2][K * 2] - S[i + K - 1][K * 2] - S[K * 2][j + K - 1] + 2 * S[i + K - 1][j + K - 1]
            + S[i - 1][K * 2] + S[K * 2][j - 1] - 2 * S[i - 1][j + K - 1] - 2 * S[i + K - 1][j - 1] + 2 * S[i - 1][j - 1];
            if(ans < tmp + tot) ans = tmp + tot;
            if(ans < S[K * 2][K * 2] - tmp + tot) ans = S[K * 2][K * 2] - tmp + tot;
        }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 17152
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main() {
    long long N, K;
    cin >> N >> K;
    N %= K;
    if (K - N < N) N = K - N;
    cout << N;
  	return 0;
}




Measured memory_bytes: 256
ans = []
while True:
    str_of_text = input()
    if str_of_text == '-':
        break
    m = int(input())
    for i in range(m):
        h = int(input())
        str_of_text = str_of_text[h:] + str_of_text[:h]
    ans.append(str_of_text)

print(*ans, sep='\n')



Measured memory_bytes: 5600
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int mincost[5001];
vector<pii> tx(5001);
vector<vector<int>> way(5001);
int main() {
	int n, k;
	cin >> n >> k;
	fill(mincost, mincost + 5001, 1 << 30);
	for (int i = 1; i <= n; i++)cin >> tx[i].first >> tx[i].second;
	for (int i = 0; i < k; i++) {
		int a, b;
		cin >> a >> b;
		way[a].push_back(b);
		way[b].push_back(a);
	}
	mincost[1] = 0;
	priority_queue<pii, vector<pii>, greater<pii>> que;//cost,town
	que.push(pii(0, 1));
	while (que.top().second != n) {
		int town = que.top().second;
		pii a = que.top();
		que.pop();
		a.first += tx[town].first;
		vector<char> used(n + 1,0);
		queue<pii> addlist;
		addlist.push(pii(town, tx[town].second));
		used[town] = 1;
		while (!addlist.empty()) {
			pii x = addlist.front();
			addlist.pop();
			for (auto b : way[x.first]) {
				if (!used[b]) {
					used[b] = 1;
					if (x.second > 0) {
						if (mincost[b] > a.first) {
							que.push(pii(a.first, b));
							mincost[b] = a.first;
						}
						addlist.push(pii(b, x.second - 1));
					}
				}
			}
		}
	}
	cout << que.top().first << endl;
}

Measured memory_bytes: 3640
import java.util.Scanner;

/**
 * C - Step
 * N  人が 1 列に並んでおり、前から i 番目の人の身長は Ai です。
 * それぞれの人の足元に、高さが 0 以上の踏み台を設置し、全ての人が次の条件を満たすようにしたいです。
 * 条件：踏み台を込めて身長を比較したとき、自分より前に、自分より背の高い人が存在しない
 * この条件を満たす時の、踏み台の高さの合計の最小値を求めてください。
 */
public class Main {

    public static void main( String[] args ) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        int n = sc.nextInt();
        long[] a = new long[n];

        long result = 0;
        long before = 0;
        for( int i = 0; i < n; i++ ) {
            a[i] = sc.nextLong();
            long step = 0;
            if( i > 0 && a[i] < before ) {
                step = before - a[i];
                result += step;
            }
            before = a[i] + step;
        }

        System.out.println( result );

        sc.close();
    }
}

Measured memory_bytes: 61460
// --https://kenkoooo.com/atcoder/#/table/soma62jp

#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[]) {

	char c;

	cin >> c;

	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {

		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;

	}

	return 0;

}

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

static const int MAX = 200000;

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

  string s,t;
  cin >> s >> t;

  string ans = "";
  rep(i,n) {
    ans += s.at(i);
    ans += t.at(i);
  }
  cout << ans << endl;
}


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

namespace Blance
{
    class Program
    {
        static void Main(string[] args)
        {
            string n1 = Console.ReadLine();
            string iw = Console.ReadLine();

            int n = int.Parse(n1);
            string[] w = iw.Split(' ');

            var wi = new List<int>();
            int sum = 0;
            int w2;
            foreach(string ww in w)
            {
                w2 = int.Parse(ww);
                wi.Add(w2);
                sum += w2; 
            }

            int cnt=0;
            int s1 = 0,s2 = 0,s = 0;
            int sumbk = 0, cntbk = 0;

            foreach (int ww in wi)
            {
                if (sum <= cnt)
                {
                    s1 = sum - cnt;
                    s2 = sumbk - cntbk;
                    break;
                }
                else
                {
                    sumbk = sum;
                    cntbk = cnt;
                    sum -= ww;
                    cnt += ww;
 

                }

            }

            if(Math.Abs(s1)>Math.Abs(s2))
            {
                s = s2;
            }
            else
            {
                s = s1;
            }
            Console.WriteLine(Math.Abs(s));
        }
    }
}


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

int main() {
	char a[3][3];
	for(int i = 0;i < 3;i++){
		for(int j = 0;j < 3;j++){
			cin >> a[i][j];
		}
	}
cout << a[0][0]  <<a[1][1]<< a[2][2] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include<complex>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;


int main(){
	ll a, b, c;
	cin >> a >> b >> c;
	cout << (b / c + 1) - (a>0?(a - 1) / c + 1:0);
	return 0;
}
//Ctrl+Aを使わない

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

int main(){
    int x, y;
    
    while(1){
        cin >> x >> y;
        if(x==0 && y==0){break;}
        
        if(x<y){
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2972
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
//#define S set<int>
#define itn int
bool dbg = false;

itn N, C[50], V[50];

void solve() {
    int ans = 0;
    FOR(N) {
        chmax(ans, ans + V[i] - C[i]);
    }
    cout << ans << endl;
}

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

    cin >> N;
    FOR(N)
    cin >> V[i];
    FOR(N)
    cin >> C[i];

    solve();
    return 0;
}


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

using lint = long long;

int main(void)
{
    lint L, R;
    cin >> L >> R;
    lint sm = 0;
    
    if(R % 2019 == 0 || L % 2019 == 0){
        sm = 0;
    }else if(R / 2019 == L / 2019){
        lint min = (L%2019)*((L+1)%2019)%2019;
        for(lint i = L; i <= R; i++){
            for(lint j = i+1; j <= R; j++){
                lint sum = (i%2019)*((j)%2019)%2019;
                if(sum < min){
                    min = sum;
                }
            }
        }
        sm = min;
    }else if(R / 2019 > L / 2019){
        sm = 0;
    }
    
    cout << sm << endl;

    return 0;
}

Measured memory_bytes: 256
// AOJ 2299:   Tiles are Colorful
// 2017.12.10

#include <stdio.h>
#include <string.h>

int m, n;
char map[501][503];
int mv[4][2] = {{-1,0},{1,0},{0,1},{0,-1}};
int rpos['Z'+1], cpos['Z'+1];
int sr[501], sc[501];

int calc()
{
	int r, c, i, r2, c2, a, ans = 0;
	for (r = 0; r < m; r++) for (c = 0; c < n; c++) 
		if ((sr[c] + sc[r]) && map[r][c] == '.' ) {
			memset(rpos, -1, sizeof(rpos));

		    for (i = 0; i < 4; i++) {
				if (!sr[c]) { if (i < 2) continue; }
				if (!sc[r]) { if (i > 2) continue; }

				r2 = r, c2 = c;
				while (1) {
					r2 += mv[i][0], c2 += mv[i][1];
					if (r2 < 0 || r2 >= m || c2 < 0 || c2 >= n) break;
					if (map[r2][c2] == '.') continue;

	                a = map[r2][c2];
					if (rpos[a] >= 0) {
	                    map[r2][c2] = '.', sr[c2]--, sc[r2]--;
						r2 = rpos[a], c2 = cpos[a];
	                    map[r2][c2] = '.', sr[c2]--, sc[r2]--;
	                    ans += 2;
					} else rpos[a] = r2, cpos[a] = c2;
					break;
				}
            }
        }

	return ans;
}

int main()
{
	int r, c, t, k, ans;
	char buf[10];

    fgets(buf, 10, stdin);
	sscanf(buf, "%d%d", &m, &n);
	for (k = 0, r = 0; r < m; r++) {
		fgets(map[r], 503, stdin);
		for (c = 0; c < n; c++) {
			if (map[r][c] != '.') k++, sr[c]++, sc[r]++;
		}
	}
	ans = 0;
	while (1) {
		if (!(t = calc())) break;
		ans += t, k -= t;
		if (!k) break;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2108
#include "algorithm"
#include "iostream"
#include "cmath"
#include "string"
#include "map"
using namespace std;


int main(){
  string S;
  string S1,S2;
  map<string,int> ans;
  int m;
  cin >> m;
  while(m--){
    cin >>S;
    for(int i=1;i<S.size();++i){
      S1=S.substr(0,i);
      string tmp=S1;
      S2=S.substr(i,S.size()-1);

      ans.insert(map<string,int>::value_type(S1+S2,100));
      ans.insert(map<string,int>::value_type(S2+S1,100));
      reverse(S1.begin(),S1.end());
      ans.insert(map<string,int>::value_type(S1+S2,100));
      ans.insert(map<string,int>::value_type(S2+S1,100));
      reverse(S2.begin(),S2.end());
      ans.insert(map<string,int>::value_type(S1+S2,100));
      ans.insert(map<string,int>::value_type(S2+S1,100));

      ans.insert(map<string,int>::value_type(tmp+S2,100));
      ans.insert(map<string,int>::value_type(S2+tmp,100));

    }
    cout << ans.size() <<endl;
    ans.clear();
  }

  return 0;
}

Measured memory_bytes: 3244
#include<cstdio>
int main()
{
    long long a;
    while(scanf("%lld",&a)==1)
    {
        if(a==0)break;
        long long res=1ll;
        for(long long i=2;i*i<=a;i++)
        {
            long long t=0;
            if(a%i==0)
            {
                while(a%i==0)
                {
                    a=a/i;
                    t++;
                }
                res=res*(2*t+1);
            }
        }
        if(a!=1)
        res=res*3;
        printf("%lld\n",(res+1)/2);
    }

    return 0;
}

Measured memory_bytes: 0
package main

import "fmt"

func f(a, b, d int64) int64 {
	return b/d - (a-1)/d
}

func gcd(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func main() {
	var a, b, c, d int64
	fmt.Scan(&a, &b, &c, &d)
	ans := b - a + 1 - f(a, b, c) - f(a, b, d) + f(a, b, lcm(c, d))
	fmt.Println(ans)
}


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;
struct UnionFind {
  vector<ll> par, sizes;
  ll cnt;
  UnionFind(ll N) : par(N), sizes(N, 1), cnt(N) {
    for (ll i = 0; i < N; i++) par[i] = i;
  }

  ll find(ll x) { return par[x] == x ? x : par[x] = find(par[x]); }

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

  ll size(ll x) { return sizes[find(x)]; }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
    cnt--;
  }

  ll count() const { return cnt; }
};
int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  cout << 3 * n * n << endl;

  return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

vii G;
vi value;

void dfs(int now, int par, int score) {
  value[now] += score;
  rep (i, G[now].size()) {
    if (G[now][i] == par) continue;
    dfs(G[now][i], now, value[now]);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  G.resize(n);
  value.resize(n);
  rep (i, n - 1) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  rep (i, q) {
    int u, x;
    cin >> u >> x;
    u--;
    value[u] += x;
  }

  dfs(0, -1, 0);

  rep (i, n) {
    cout << value[i] << " ";
  }
  cout << endl;
}



Measured memory_bytes: 23424