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

#define MAX 10000
#define INFTY (1 << 29)

class DisjointSet
{
public:
  vector<int> rank, p;

  DisjointSet() {}
  DisjointSet(int size)
  {
    rank.resize(size, 0);
    p.resize(size, 0);
    for (int i = 0; i < size; i++)
      makeSet(i);
  }

  void makeSet(int x)
  {
    p[x] = x;
    rank[x] = 0;
  }

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

  void unite(int x, int y)
  {
    link(findSet(x), findSet(y));
  }

  void link(int x, int y)
  {
    if (rank[x] > rank[y])
    {
      p[y] = x;
      return;
    }
    p[x] = y;
    if (rank[x] == rank[y])
      rank[y]++;
  }

  int findSet(int x)
  {
    if (x != p[x])
      p[x] = findSet(p[x]);
    return p[x];
  }
};

class Edge
{
public:
  int source, target, cost;
  Edge(int source = 0, int target = 0, int cost = 0) : source(source), target(target), cost(cost) {}
  bool operator<(const Edge &e) const
  {
    return cost < e.cost;
  }
};

int kruskal(int N, vector<Edge> edges)
{
  int totalCost = 0;
  sort(edges.begin(), edges.end());
  DisjointSet ds = DisjointSet(N + 1);

  for (int i = 0; i < N; i++)
    ds.makeSet(i);

  int source, target;
  for (int i = 0; i < edges.size(); i++)
  {
    Edge e = edges[i];
    if (!ds.same(e.source, e.target))
    {
      totalCost += e.cost;
      ds.unite(e.source, e.target);
    }
  }
  return totalCost;
}

int main()
{
  int N, M, cost;
  int source, target;

  cin >> N >> M;

  vector<Edge> edges;
  for (int i = 0; i < M; i++)
  {
    cin >> source >> target >> cost;
    edges.push_back(Edge(source, target, cost));
  }

  cout << kruskal(N, edges) << endl;
}


Measured memory_bytes: 5436
using System;
using System.Linq;
//using System.Collections.Generic;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            //input
            int N = Convert.ToInt32(Console.ReadLine());
            int[] A = Console.ReadLine().Split(' ').Select(t => Convert.ToInt32(t)).ToArray();
            int[] B = Console.ReadLine().Split(' ').Select(t => Convert.ToInt32(t)).ToArray();
            int[] C = Console.ReadLine().Split(' ').Select(t => Convert.ToInt32(t)).ToArray();

            int sum = 0;
            int before = -1;
            for(int i = 0; i < N; i++)
            {
                sum += B[A[i]-1];
                if(A[i] == before + 1)
                {
                    sum += C[before-1];
                }
                before = A[i];
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13396
#include<stdio.h>
long long div[100000];
long long inde;
 
void getDiv(long long n){
  inde = 0;
  long long i;
  for(i=1;i*i<=n;i++)
    if(n%i == 0)
    {
      div[inde++] = i;
      if(i != n/i)
        div[inde++] = n/i;
    }
}
 
long long gcd(long long x,long long y)
{
  long long r;
  if(x < y)
    {
      long long tmp = x;
      x = y;
      y = tmp;
    }
  while(y > 0)
    {
      r = x%y;
      x = y;
      y = r;
    }
  return x;
}
 
int main()
{
  long long n;
   
  while(1)
    {
      scanf("%lld",&n);
      if(n == 0)
    break;
      long long cnt = 0;
      long long i,j;
      getDiv(n);
      for(i=0;i<inde;i++)
    {
      for(j=i;j<inde;j++)
        {
          long long a,b;
          a = div[i];
          b = div[j];
          if(a/gcd(a,b)*b == n)
        cnt++;
        }
    }
      printf("%lld\n",cnt);
    }
   
  return 0;
}

Measured memory_bytes: 612
# -*- coding: utf-8 -*-
import math
import sys

import math
import sys


n,k = map(int, sys.stdin.readline().rstrip().split())
xs = list(map(int, sys.stdin.readline().rstrip().split()))

mn = sys.maxsize
for i in range(n-k+1):
  mn = min(mn, abs(xs[i]-xs[i+k-1])+abs(xs[i+k-1]))

for i in range(n-1,k-2,-1):
  mn = min(mn, abs(xs[i]-xs[i-k+1])+abs(xs[i-k+1]))
  
print(mn)


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

vector<int> dw = {1, 0, -1, 0};
vector<int> dh = {0, 1, 0, -1};

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

  ll H; cin >> H;
  ll W; cin >> W;
  ll Ch; cin >> Ch; Ch--;
  ll Cw; cin >> Cw; Cw--;
  ll Dh; cin >> Dh; Dh--;
  ll Dw; cin >> Dw; Dw--;
  vector<vector<ll>> cells(H, vector<ll>(W, 0));
  vector<vector<ll>> times(H, vector<ll>(W, 1e15));
  for (ll i = 0; i < H; i++) {
    string S; cin >> S;
    for (ll j = 0; j < W; j++) {
      if (S[j] == '#') cells[i][j] = 1;
    }
  }

  deque<pair<ll, ll>> q;
  q.push_back({Ch, Cw});
  times[Ch][Cw] = 0;

  while (!q.empty()) {
    pair<ll, ll> p = q.front(); q.pop_front();
    ll ch = p.first, cw = p.second;
    for (ll i = 0; i < 4; i++) {
      ll nh = ch + dh[i];
      ll nw = cw + dw[i];
      if (nh < 0 || nw < 0 || nh >= H || nw >= W) continue;
      if (cells[nh][nw] > 0) continue;
      if (times[nh][nw] <= times[ch][cw]) continue;
      times[nh][nw] = times[ch][cw];
      q.push_front({nh, nw});
    }

    for (ll i = -2; i <= 2; i++) {
      for (ll j = -2; j <= 2; j++) {
        ll nh = ch + i;
        ll nw = cw + j;
        if (nh < 0 || nw < 0 || nh >= H || nw >= W) continue;
        if (cells[nh][nw] > 0) continue;
        if (times[nh][nw] <= times[ch][cw] + 1) continue;
        times[nh][nw] = times[ch][cw] + 1;
        q.push_back({nh, nw});
      }
    }
  }

  ll ans = times[Dh][Dw];
  if (ans >= 1e15) ans = -1;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 19380
local n=io.read("n")
local a={}
for i=1,n do
    a[i]=io.read("n")
end

local dp={{0,-10^12}}
for i=1,n do
    dp[i+1]={}
    dp[i+1][1]=math.max(dp[i][1]+a[i],dp[i][2]-a[i])
    dp[i+1][2]=math.max(dp[i][1]-a[i],dp[i][2]+a[i])
end
print(dp[n+1][1])

Measured memory_bytes: 15352
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;

 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
    int n = sc.nextInt();
    int[] ss = new int[n];
    for(int i  = 0; i < n; i++){
      ss[i] = sc.nextInt();
    }
    int m = sc.nextInt();
    int[] ts = new int[m];
    for(int i = 0; i < m; i++){
      ts[i] = sc.nextInt();
    }

    int ans = 0;
    for(int j = 0; j < m; j++){
      for(int i = 0; i < n; i++){
        if(ss[i] == ts[j]){
          ans++;
          break;
        }
      }
    }

    System.out.println(ans);
  }
 
  
// LinkedList<Integer>[] setsu = new LinkedList[n];
// for(int i = 0; i < n; i++){
//   setsu[i] = new LinkedList<Integer>();
// } 

 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;

      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }

      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

Measured memory_bytes: 20128
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 500500
#define rep(x, a, b) for(int x=a; x<=b; x++)
#define drp(x, a, b) for(int x=a; x>=b; x--)
int n, q, f[N][27], g[N][27];
char s[N];
int main(){
	scanf("%s", s+1);
	n=strlen(s+1);
	drp(i, n, 1)
	{
		f[i][s[i]-'a']=i+1;
		rep(j, s[i]-'a'+1, 25) f[i][j]=f[f[i][j-1]][j-1];
		f[i][26]=f[f[i][25]][25];
		rep(j, 0, 25) if(!f[i][j]) f[i][j]=f[f[i][26]][j];
	}
	rep(i, 1, n) g[i][0]=f[i][26];
	rep(i, 1, 18)
		rep(j, 1, n) g[j][i]=g[g[j][i-1]][i-1];
	scanf("%d", &q);
	while(q--)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		int x=l;
		drp(i, 18, 0) if(g[x][i]<=r && g[x][i]) x=g[x][i];
		if(f[x][26]==r+1) puts("Yes"); else puts("No");
	}
}

Measured memory_bytes: 106496
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

vector<LL> fact;
vector<LL> inver(200001);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=200000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[200000]=fpow(fact[200000],mod-2);
    for(int i=199999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}
 
LL hcombi(int n,int r){
    return combi(n+r-1,r); 
}
vector<LL> divi(LL K){
    vector<LL> v;
    for(int i=1;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        v.pb(K/i);
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)),v.end());
    return v;
}

vector<LL> pdivi(LL K){
    vector<LL> v;
    for(int i=2;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        while(K%i==0){
            K/=i;
        }
    }
    if(K!=1) v.pb(K);
    return v;
}





int main(){
    LL N,M;
    cin >> N >> M;
    vector<LL> t;
    t=pdivi(M);
    set_combi();
    LL ans=1;
    for(int i=0;i<t.size();i++){
        LL p=0;
        while(M%t[i]==0){
            p++;
            M/=t[i];
        }
        ans*=hcombi(N,p);
        ans%=mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3956
n,q = map(int,input().split())

stack = [[] for i in range(n)]

for i in range(q):
    query = [k for k in map(int,input().split())]

    if query[0] == 0:
        stack[query[1]].append(query[2])
    elif query[0] == 1:
        try:
            temp = stack[query[1]].pop()
            print(temp)
            stack[query[1]].append(temp)
        except:
            pass
    elif query[0] == 2:
        try:
            stack[query[1]].pop()
        except:
            pass



Measured memory_bytes: 13444
#include "bits/stdc++.h"
using namespace std;
const int N = 2e5 + 5;
int n;
int p[N];
vector < int > v[N];
int indeg[N];
int outdeg[N];
int mex[N];
queue < int > que;
int val[N];
vector < int > rv[N];
bool done[N];
vector < int > tmp;
int cur[N];
bool check(){
	for(int node = 1 ; node <= n ; ++node){
		for(int next : v[node]){
			mex[val[next]] = node;
		}
		for(int i = 0 ; i < val[node] ; ++i){
			if(mex[i] != node){
				return 0;
			}
		}
		if(mex[val[node]] == node){
			return 0;
		}
	}
	return 1;
}
int get(int node){
	for(int next : v[node]){
		if(done[next]){
			mex[val[next]] = node;
		}
	}
	for(int i = 0 ; ; ++i){
		if(mex[i] != node){
			return i;
		}
	}
}
int main(){
	scanf("%d" , &n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" , p + i);
		v[p[i]].emplace_back(i);
		rv[i].emplace_back(p[i]);
		++indeg[i];
		++outdeg[p[i]];
	}
	for(int i = 1 ; i <= n ; ++i){
		if(!outdeg[i]){
			que.push(i);
		}
	}
	while(!que.empty()){
		int node = que.front();
		que.pop();
		done[node] = 1;
		for(int next : v[node]){
			mex[val[next]] = node;
		}
		for(int i = 0 ; ; ++i){
			if(mex[i] != node){
				val[node] = i;
				break;
			}
		}
		for(int prev : rv[node]){
			--outdeg[prev];
			if(!outdeg[prev]){
				que.push(prev);
			}
		}
	}
	for(int i = 1 ; i <= n ; ++i){
		if(!done[i]){
			tmp.emplace_back(i);
		}
	}
	if(tmp.empty()){
		printf("POSSIBLE\n");
		return 0;
	}
	memset(mex , 0 , sizeof(mex));
	for(int node : tmp){
		for(int next : v[node]){
			if(done[next]){
				mex[val[next]] = node;
			}
		}
		for(int i = 0 ; ; ++i){
			if(mex[i] != node){
				cur[node] = i;
				break;
			}
		}
	}
	memset(mex , 0 , sizeof(mex));
	int who = -1;
	for(int node : tmp){
		if(who == -1 || cur[who] > cur[node]){
			who = node;
		}
	}
	bool ok = 0;
	for(int node : tmp){
		if(cur[node] != cur[who]){
			ok = 1;
		}
	}
	if(ok){
		while(1){
			int nxt;
			for(int next : v[who]){
				if(!done[next]){
					nxt = next;
				}
			}
			if(cur[nxt] == cur[who]){
				who = nxt;
			}
			else{
				break;
			}
		}
	}
	int x = who;
	do{
		val[x] = get(x);
		done[x] = 1;
		x = rv[x].back();
	}while(x != who);
	memset(mex , 0 , sizeof(mex));
	if(check()){
		printf("POSSIBLE\n");
	}
	else{
		printf("IMPOSSIBLE\n");
	}
}

Measured memory_bytes: 26740
import sys
input = sys.stdin.readline
import heapq

H,W=map(int,input().split())
sh,sw=map(int,input().split())
gh,gw=map(int,input().split())
MAP=[input().strip() for i in range(H)]

ANS=[[1<<30]*W for i in range(H)]

sh-=1
sw-=1
gh-=1
gw-=1

ANS[sh][sw]=0

def ca(sc,x,y):
    return sc*(10**8)+x*(10**4)+y

def inv(w):
    sc=w//(10**8)
    w%=(10**8)
    x=w//(10**4)
    y=w%(10**4)

    return sc,x,y

Q=[ca(0,sh,sw)]

while Q:
    sc,x,y=inv(heapq.heappop(Q))

    if sc>ANS[x][y]:
        continue

    for i,j in [(x-2,y-2),(x-2,y-1),(x-2,y),(x-2,y+1),(x-2,y+2),(x-1,y-2),(x-1,y-1),(x-1,y),(x-1,y+1),(x-1,y+2),(x,y-2),(x,y-1),(x,y+1),(x,y+2),(x+1,y-2),(x+1,y-1),(x+1,y),(x+1,y+1),(x+1,y+2),(x+2,y-2),(x+2,y-1),(x+2,y),(x+2,y+1),(x+2,y+2)]:
        if 0<=i<H and 0<=j<W:
            if MAP[i][j]=="." and abs(i-x)+abs(j-y)==1 and ANS[i][j]>sc:
                ANS[i][j]=sc
                heapq.heappush(Q,ca(ANS[i][j],i,j))
            elif MAP[i][j]=="." and abs(i-x)+abs(j-y)>1 and ANS[i][j]>sc+1:
                ANS[i][j]=sc+1
                heapq.heappush(Q,ca(ANS[i][j],i,j))

if ANS[gh][gw]==1<<30:
    print(-1)
else:
    print(ANS[gh][gw])

Measured memory_bytes: 79816
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

// template {{{
using namespace std;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))

using int64 = long long;

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

bool in_field(int W, int H, int x, int y) {
  return (0 <= x && x < W) && (0 <= y && y < H);
}

// pair
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\t";
  }
  return s;
}

// }}}

// url: https://atcoder.jp/contests/abc103/tasks/abc103_d

int N, M;
pair<int, int> P[100000];

bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  cin >> N >> M;
  rep(i, M) { cin >> P[i].first >> P[i].second; }
  sort(P, P + M, comp);

  int ans = 0;
  int remove = 0;
  rep(i, M) {
    // cout << P[i] << endl;
    if (P[i].first > remove) {
      remove = P[i].second - 1;
      // cout << "removed:" << remove << endl;
      ans++;
    } else {
    }
  }
  cout << ans << endl;

  return 0;
}

// vim: foldmethod=marker


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

#pragma warning(disable:4996)

int main()
{
	char str[21] = "\0";
	int X;

	scanf("%s", str);

	for (X = strlen(str)-1; X > 0; X--)
	{
		if (X <= (strlen(str) - 1) - X)
			break; 

		str[(strlen(str)-1) - X] ^= str[X];
		str[X] ^= str[(strlen(str)-1) - X];
		str[(strlen(str)-1) - X] ^= str[X];
	}
	printf("%s\n", str);

	return 0;
}

Measured memory_bytes: 944
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

        int N = sc.nextInt();

        int[][] A = new int[N][N - 1];

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N - 1; j++) {
                A[i][j] = sc.nextInt() - 1;
            }
        }

        List<Integer> candidates = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            candidates.add(i);
        }
        int[] current = new int[N];
        int days = 0;
        while (true) {
            boolean change = false;
            boolean[] paired = new boolean[N];
            List<Integer> newCandidates = new ArrayList<>();
            for (int i : candidates) {
                if (paired[i] || current[i] >= N - 1) continue;
                int j = A[i][current[i]];
                if (paired[j]) continue;
                if (A[j][current[j]] == i) {
                    paired[i] = paired[j] = true;
                    current[i]++;
                    current[j]++;
                    change = true;
                    newCandidates.add(i);
                    newCandidates.add(j);
                }
            }
            if (!change) break;
            days++;
            candidates = newCandidates;
        }

        for (int i = 0; i < N; i++) {
            if (current[i] < N - 1) {
                days = -1;
                break;
            }
        }

        System.out.println(days);
    }
}


Measured memory_bytes: 306760
N=int(input())
A=list(map(int,input().split()))
flag=0

for x in range(30):
  for y in range(N):
    if  A[y]%2==0:
      A[y]=A[y]/2    
    else:
      print(x)
      flag=1
      break
  if flag==1:
    break



Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>

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

  unsigned N = 0, K = 0;
  std::cin >> N;
  std::cin >> K;
  std::vector<int> vec(N, 0); 
  for (unsigned i = 0; i < N; ++i)
  {
    std::cin >> vec[i];
  }

  std::vector<int> cache(vec.size(), 0); 
  cache[0] = 0;
  cache[1] = abs(vec[1] - vec[0]);
  for (size_t i = 2; i < vec.size(); ++i)
  {
    int m = 1<<30;
    for (int j = std::max<int>(0, i-K); j < i; ++j)
    {   
      m = std::min(m, cache[j] + abs(vec[j] - vec[i]));
    }   
    cache[i] = m;
  }
  std::cout << cache.back();

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using namespace std;

long long n;
long long a[200010];
int now,ans,tmp1,tmp2;
vector<int> vans;

int saiki(int k){
  now = 1;
  ans = k;
  //if(n-k > tmp2) return 0;
  FOR(i,k,n){
    if(a[i] != now && a[i] == 1){
      tmp1 = now;
      tmp2 = ans;
      //saiki(i);
      now = tmp1;
      ans = tmp2;
      ans++;
    }
    else if(a[i] != now) ans++;
    else now++;
  }
  vans.push_back(ans);
  
  return 0;
}

int main(){
  cin >> n;
  REP(i,n) cin >> a[i];
  
  saiki(0);
  sort(vans.begin(),vans.end());
  if(vans[0] == n) vans[0] = -1;
  cout << vans[0] << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int X,Y,A,B,C;
    cin >> A >> B >> C >> X >> Y;
    C = min(A+B, 2 * C);
    A = min(A,C);
    B = min(B,C);
    int R = min(X,Y);
    cout << (X - R) * A + (Y - R) * B + R * C << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>
#include<unordered_set>
#include<unordered_map>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

template<typename T>
T modinv(T a, T m) {
	T b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll A, B;
	cin >> A >> B;
	cout << (B % A == 0 ? A + B : B - A) << endl;
	return 0;
}


Measured memory_bytes: 3496
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cctype>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvii;
typedef pair<int, int> ii;
typedef vector<ii> vii;

////////////////////////////////

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, w;
	cin >> n >> w;
	vector<int> weight(n + 1), value(n + 1);
	weight[0] = value[0] = 0;
	for (int i = 0; i < n; ++i) {
		cin >> weight[i + 1] >> value[i + 1];
	}
	vector<vector<ll>> dp(n + 1, vector<ll>(w + 1));
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= w; ++j) {
			if (weight[i] > j) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i]] + value[i]);
		}
	}
	cout << dp[n][w] << endl;
	return 0;
}


Measured memory_bytes: 80256
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back

const ll mod = 1000000007;

int main(){
	int X, A;
    cin >> X >> A;

	int ans = 0;

	ans = X < A ? 0 : 10;

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

Measured memory_bytes: 256
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, M = map(int, input().split())
e = dd(list)
ie = dd(list)
inc = [0] * (N + 1)
for _ in range(N + M - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  ie[v].append(u)
  inc[v] += 1

def topologically(n, e, inc):
  res = []
  s = []
  c = 0
  many = 0
  for i in range(1, n + 1):
    if inc[i] == 0:
      s.append(i)
      c += 1
  many = c > 1
  while len(s):
    p = s.pop()
    res.append(p)
    for q in e[p]:
      inc[q] -= 1
      if inc[q] == 0:
        s.append(q)
    many = many or ((len(s) - c) > 0)
    c = len(s)
  return res
r = topologically(N, e, inc)
rrank = [0] * (N + 1)
#print(r)
for i in range(N):
  rrank[r[i]] = i
#print(rrank)
res = [0] * (N + 1)
for u in range(1, N + 1):
  t = -1
  for v in ie[u]:
    if rrank[v] > t:
      res[u] = v
      t = rrank[v]
for i in range(1, N + 1):
  print(res[i])

Measured memory_bytes: 89692
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,kk=0,minn,p,p1,maxn;
    int a[200]={0};
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(!i){
            minn=a[i];
            maxn=a[i];
            p=p1=i;
        }
        if(i&&a[i]>maxn){
            maxn=a[i];
            p=i;
        }
        if(i&&a[i]<minn){
            minn=a[i];
            p1=i;
        }
    }
    int aa[101],bb[101],k=0,f;
    if(minn>0){
        f=0;
    }else if(maxn<0){
        f=1;
    }else if(fabs(minn)<fabs(maxn)){
        for(i=0;i<n;i++){
            if(a[i]<0){
                a[i]+=maxn;
                aa[k]=p;
                bb[k++]=i;
            }
        }
        f=0;

    }else {
        for(i=0;i<n;i++){
            if(a[i]>0){
                a[i]+=minn;
                aa[k]=p1;
                bb[k++]=i;
            }
        }
        f=1;
    }
   // printf("-->%d\n",k);
    if(f){
        printf("%d\n",k+n-1);
        for(i=0;i<k;i++){
            printf("%d %d\n",aa[i]+1,bb[i]+1);
        }
        for(i=n-1;i>=1;i--){
            printf("%d %d\n",i+1,i);
        }
    }else {
        printf("%d\n",k+n-1);
        for(i=0;i<k;i++){
            printf("%d %d\n",aa[i]+1,bb[i]+1);
        }
        for(i=2;i<=n;i++){
            printf("%d %d\n",i-1,i);
        }
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	map<string, vi> table;
	char str[32];
	int page;
	while(scanf("%s%d", str, &page) != EOF){
		string s(str);
		if(table.count(s))
			table[s].push_back(page);
		else
			table[s] = vi(1, page);
	}

	for(map<string, vi>::iterator itr = table.begin(); itr != table.end(); ++itr){
		sort(itr->second.begin(), itr->second.end());
		puts(itr->first.c_str());
		rep(i, itr->second.size())
			printf("%s%d", i?" ":"", itr->second[i]);
		puts("");
	}

	return 0;
}

Measured memory_bytes: 0
/* ex4_2
   kohei0713 */

#include <stdio.h>
#include <math.h>

int main(void){
    
    int hourHand, minuteHand, hour, minute;
    
    //input
    scanf("%d %d %d %d", &hourHand, &minuteHand, &hour, &minute);

    //長針短針の角度を計算
    double angle_hourHnad = 30 * hour + 0.5 * minute;
    double angle_minuteHand = 6 * minute;

    //角度の差を計算し,ラジアンに変換
    double angle = (angle_hourHnad - angle_minuteHand) * M_PI / 180;

    //余弦定理
    double answer = sqrt(hourHand * hourHand + minuteHand * minuteHand - 2 * hourHand * minuteHand * cos(angle));
    
    //answerを小数点以下10桁表示
    printf("%.10lf\n", answer);

    return 0;
}

Measured memory_bytes: 2640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int  N;
  cin >>N;
  int sen,hyaku,juu,iti;
  iti=N%10;
  juu=((N-iti)/10)%10;
  hyaku=(N-(((N-iti)/10)%10*10+iti))/100%10;
  sen=N/1000;
 // cout <<N<<sen<<hyaku<<juu<<iti;
  if((sen==hyaku&&hyaku==juu)||(hyaku==juu&&juu==iti)){cout << "Yes";}
  else cout << "No";
}


Measured memory_bytes: 256
a = []
a = list(map(int,input().split(' ')))
a.sort()
#print(a)
num = 0
diff1 =0
diff2 =0
if a[2] > a[1]:
    diff1 = a[2]-a[1]

if a[1] > a[0]:
    if (a[1] -a[0]) %2 == 0:
        diff2 = int( (a[1] -a[0])/2 ) 
    else :
        diff2 = int( (a[1] -a[0])/2 ) +2

print(diff1+diff2)


Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j, k;
	int kin = 700;
	
	string str;

	cin >> str;

	for (i = 0; i < 3; i++) {
		if (str[i] == 'o') {
			kin += 100;
		}

	}


	cout << kin << endl;



	getchar();
	getchar();
	return 0;
}

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

const int M = 998244353;

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

    vector<int> arr(n);
    for(int i = 0; i < n; i++) cin>>arr[i];

    vector<int> dp(s+1);

    int res = 0;
    for(int i = 0; i < n; i++){
        for(int j = s - arr[i]; j>=0; j--){
            dp[j+arr[i]]+=dp[j];
            dp[j+arr[i]]%=M;
        }
        if(arr[i]<=s){
            dp[arr[i]]+=i+1;
        }
    
        res += dp[s]%M;
        res%=M;
    }
    cout<<res;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define Print(x) cout << (x) << endl 
#define Min2(a, b) ((a) < (b)) ? (a) : (b)
#define Max2(a, b) ((a) > (b)) ? (a) : (b)

typedef long long ll;

using namespace std;

int H, W;
char grid[50][50];

int main(){
    int white = 0;
    string str;
    cin >> H >> W;
    Rep(i, 0, H){
        cin >> str;
        Rep(j, 0, W){
            grid[i][j] = str[j];
            if(grid[i][j] == '.') white++;
        }
    }
    queue<pair<int, int> > que;
    queue<int> step;
    que.push(make_pair(0, 0));
    step.push(1);
    int i, j, min = 0;
    pair<int, int> p;
    while(!que.empty()){
        p = que.front();
        i = p.first; j = p.second;
        min = step.front();
        que.pop(); step.pop();
        if(i < 0 || i >= H || j < 0 || j >= W || grid[i][j] == '#') continue;
        if(i == H - 1 && j == W - 1) break;
        grid[i][j] = '#';
        que.push(make_pair(i - 1, j));
        que.push(make_pair(i + 1, j));
        que.push(make_pair(i, j - 1));
        que.push(make_pair(i, j + 1));
        Rep(k, 0, 4) step.push(min + 1);
    }
    if(i == H - 1 && j == W - 1) Print(white - min);
    else Print("-1");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main()
{
  string S; ll K;
  cin >> S >> K;
  vector<string> sub;
  for (ll i = 1; i <= K; i++) {
    if (i > S.size()) break;
  	for (ll j = 0; j <= (S.size() - i); j++) {
    	if (notFound(sub, S.substr(j, i))) {
        	sub.push_back(S.substr(j, i));
        }
    }
  }
  vsort(sub);
  cout << sub[K - 1] << endl;
}

Measured memory_bytes: 1024
//
//  main.cpp
//  B - Count Balls
//
//  Created by Hashizo on 2020/03/07.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())


int main(int argc, const char * argv[]) {
	ll ans = 0;
	ll amari = 0;

	ll n,a,b;
	cin >> n >> a >> b;

	ans = n / (a + b) * a;
	
	amari = n % (a + b);
	if (amari >= a) {
		ans += a;
	}
	else {
		ans += amari;
	}
	
	cout << ans << endl;
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string s;cin>>s;
    cout<<count(all(s),'2')<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int digit(int number){
	int digit = 1;
	number /= 10;
	while(number != 0){
		digit++;
		number/= 10;
	}

	return digit;
}
int main(void){
	int a,b;
	int sum;
	while(scanf("%d %d",&a, &b) != EOF){
		sum = a+b;
		printf("%d\n", digit(sum));
	}

	return 0;
}

Measured memory_bytes: 600
main :: IO ()
main = do
  s <- getLine
  if solve s then putStrLn "Yes" else putStrLn "No"

solve :: String -> Bool
solve s = and $ map (isPalindrome) [s, take ((l-1)`div`2) s, drop ((l+3)`div`2-1) s]
  where l = length s

isPalindrome :: String -> Bool
isPalindrome s = s == reverse s

Measured memory_bytes: 508
#include<stdio.h>

int main()
{
    int A, B, C, D, m, n, x= 0, y;
    scanf("%d%d%d%d", &A, &B, &C, &D);
    m=abs(A-B);
    n=abs(B-C);
    y=abs(A-C);
    if(m<=D && n<=D)
        x=1;
    else if(y <= D)
        x=1;
    if(x == 1)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}

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

class Harvest
{
public:
  string L;
  int P, A, B, C, D, E, F, S, M;
  double eff;
};

class GreaterEff
{
public:
  bool operator() (const Harvest& lhs, const Harvest& rhs)
  {
    if (lhs.eff == rhs.eff)
      return lhs.L < rhs.L;
    return lhs.eff > rhs.eff;
  }
};

int main()
{
  int N;
  while (cin >> N) {
    if (N == 0)
      break;

    vector<Harvest> h(N);
    for (int i = 0; i < N; ++i) {
      cin >> h[i].L >> h[i].P >> h[i].A >> h[i].B >> h[i].C 
	  >> h[i].D >> h[i].E >> h[i].F >> h[i].S >> h[i].M;
    }

    for (int i = 0; i < N; ++i) {
      int p = h[i].F * h[i].S * h[i].M - h[i].P;
      int t = h[i].A + h[i].B + h[i].C + h[i].M * (h[i].D + h[i].E);
      h[i].eff = p / static_cast<double>(t);
    }

    sort(h.begin(), h.end(), GreaterEff());
    for (int i = 0; i < N; ++i)
      cout << h[i].L << endl;
    cout << "#" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;


main()
{
  int e;
  while( cin >> e, e ) {
    /*int m = 0;
    int ans;
    int sum = 0;
    
    for(int i=0; ; i++) {
      if( pow(i, 3) > e ) { sum += pow(i-1, 3); m += i-1; break; }
    }
    
    for(int i=0; ; i++) {
      if( pow(i, 2) > e-sum ) { sum += pow(i-1, 2); m += i-1; break; }
    }
    
    ans =  m + e-sum;
    
    m = sum = 0;

    for(int i=0; ; i++) {
      if( pow(i, 2) > e ) { sum += pow(i-1, 2); m += i-1; break; }
    }
    
    for(int i=0; ; i++) {
      if( pow(i, 3) > e-sum ) { sum += pow(i-1, 3); m += i-1; break; }
    }
    
    cout << min( ans, m + e-sum ) << endl;
    */
    int mi = INF;
    for(int i=0; i<1000; i++) {
      for(int j=0; j<1000; j++) {
	int tmp = j*j + i*i*i;
	if( tmp <= e ) {
	  mi = min( mi, i + j + (e-tmp) ); 
	}
      }
    }

    cout << mi << endl;
    
  }
  
}

Measured memory_bytes: 2980
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    list<int> L;
    list<int>::iterator cur = L.end();
    int num_query; 
    scanf("%d", &num_query);
    int command, tmp;
    for (int loop = 0; loop < num_query; loop++) {
        scanf("%d", &command);
        switch (command) {
        case 0:
            scanf("%d", &tmp);
            cur = L.insert(cur, tmp);
            break;
        case 1:
            scanf("%d", &tmp);
            if (tmp > 0) {
                for (int i = 0; i < +tmp; i++) cur++;
            } else {
                for (int i = 0; i < -tmp; i++) cur--;
            }
            break;
        case 2:
            cur = L.erase(cur);
            break;
        }
    }
    for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
        printf("%d\n", *it);
    }
    return 0;
}


Measured memory_bytes: 18740
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll m, k;

int main()
{
    cin>>m>>k;
    if((1 << m) <= k || m == 1 && k == 1)
    {
        printf("-1\n");
        return 0;
    }
    if(m == 1 && k == 0)
    {
        printf("0 0 1 1\n");
        return 0;
    }
    for(ll i = 0; i < (1 << m); i++)
    {
        if(i == k) continue;
        printf("%lld ", i);
    }
    printf("%lld ", k);
    for(ll i = (1 << m) - 1; i >= 0; i--)
    {
        if(i == k) continue;
        printf("%lld ", i);
    }
    printf("%lld", k);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int digit(int n) {
    int ans = 0;
    while(n){
        n/=10;
        ans++;
    }
    return ans;
}
int x[6]={0,9,0,900,0,90000};
int main(void) {
    int n; cin >> n;
    int d = digit(n);
    int ans = 0;
    if(d%2==1) ans = n - pow(10,d-1) + 1, d--;
    d--;
    while(d>0){
        ans += x[d];
        d -= 2;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<stdio.h>

int max(int m1,int m2){
    return m1<m2?m2:m1;
}

int main(){
    int t1,t2,sum,a,i,j;
    for(;scanf("%d %d %d",&t1,&t2,&sum),sum;){
        static int A[10000];
        for(j=0;j<1001;j++)A[j]=0;
        int m=0;
        for(i=1;i<sum;i++){
            a=i*(100+t1)/100;
            A[a]=i;
        }
        for(i=1;i<sum;i++){
            if(A[i]==0&&A[sum-i]==0)continue;
            m=max(A[i]*(100+t2)/100+A[sum-i]*(100+t2)/100,m);
        }
        printf("%d\n",m);
    }
    return 0;
}

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


int main(){
    int n,m;
    cin>>n>>m;
    int X=-101,Y=101;
    int t;
    cin>>t;
    X=max(X,t);
    cin>>t;
    Y=min(Y,t);
    for(int i=0;i<n;i++)
        cin>>t, X=max(X,t);
    for(int i=0;i<m;i++)
        cin>>t, Y=min(Y,t);
    if(X<Y) puts("No War");
    else    puts("War");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

struct UnionFind {
  vector<int> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N) {  //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {  // xとyの木を併合
    int rx = root(x);         // xの根をrx
    int ry = root(y);         // yの根をry
    if (rx == ry) return;  // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] =
        ry;  // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y) {  // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  int count = 0;

  rep(i, m) {
    UnionFind tree(n);
    rep(j, m) {
      if (i == j) continue;
      tree.unite(a[j], b[j]);
    }
    if (!tree.same(a[i], b[i])) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
int a,b,c,w;
scanf("%d %d %d",&a,&b,&c);
if (a>b){
    w=a; 
    a=b; 
    b=w;
}  if (b>c){
    w=b;
    b=c;
    c=w;
}  if (a>b){
    w=a;
    a=b;
    b=w;
}
    printf("%d %d %d\n",a,b,c);  
}



Measured memory_bytes: 2744
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(2e5)+10;
int n,c[maxn],cnt[maxn];
ll C(int x) { return (ll)x*(x-1)/2; }
int tot,head[maxn],nxt[maxn*2],to[maxn*2];
void add(int x,int y) {
	tot++; nxt[tot]=head[x];
	head[x]=tot; to[tot]=y;
}
ll ans[maxn];
int sz[maxn],a[maxn],sum;
void dfs(int u,int p) {
	ll tmp=cnt[c[u]],x,y;
	sz[u]=1;
	for (int i=head[u],v;i;i=nxt[i]) {
		v=to[i];
		if (v==p) continue;
		x=sum-cnt[c[u]];
		dfs(v,u);
		sz[u]+=sz[v];
		y=sum-cnt[c[u]];
		ans[c[u]]-=C(y-x);
	}
	cnt[c[u]]=tmp+sz[u];
	sum++;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) ans[i]=C(n);
	for (int i=1;i<=n;i++) read(c[i]),ans[c[i]]++;
	int x,y;
	for (int i=1;i<n;i++) {
		read(x); read(y);
		add(x,y); add(y,x);
	}
	dfs(1,0);
	for (int i=1;i<=n;i++)
		ans[i]-=C(n-cnt[i]);
	for (int i=1;i<=n;i++) printf("%lld\n",ans[i]);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 30332
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define f first
// #define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

void solve(){

    ll n,q; cin>>n>>q;
    string s; cin>>s;
    s = '+' + s;
    ll dp[n+1];
    ZERO(dp);
    FOR(i,2,n){
        dp[i] = dp[i-1];
        if(s[i] == 'C' && s[i-1] == 'A') dp[i]++; 
    }


    while(q--){
        ll l,r; cin>>l>>r;
        ll ans = dp[r] - dp[l];
        cout<<ans<<endl;
    }
}

signed main(){


    FastRead;    

    ll t;
    t = 1; 
    // cin>>t;
    FOR(tt,1,t){
        solve();
    }
    
}

Measured memory_bytes: 1772
#include<stdio.h>
#include<iostream>
using namespace std;
#include<queue>
int main(){
while(1){
int a,b,n,v,x,y,i,j,m[18][18]={0},c=0,o=0;
pair<int,int> p,t,g;
queue<pair<int,int> > q;
scanf("%d%d",&a,&b);
if(a==0&&b==0){
break;
}
g.first=a;
g.second=b;
for(i=0;i<=a+1;i++){
	for(j=0;j<=b+1;j++){
		if(i==0||i==a+1||j==0||j==b+1){
		m[i][j]=1;
		}
	}
}
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d%d",&a,&b);
m[a][b]=1;
}
p.first=1;
p.second=1;
q.push(p);
while(!q.empty()){
	t=q.front();
	if(m[t.first+1][t.second]!=1){
		t.first++;
		q.push(t);
		t.first--;
	}
	if(m[t.first][t.second+1]!=1){
		t.second++;
		q.push(t);
		t.second--;
	}

	if(q.front()==g){
		c++;
	}
	q.pop();
}
printf("%d\n",c);

}
return 0;
}

Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<ll, ll>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    vector<P> a(n);
    rep(i, n) {
        cin >> a[i].first >> a[i].second;
    }
    ll z = abs(a[0].first + a[0].second) % 2;
    
    rep(i, n) {
        if (i==0) continue;
        if ((abs(a[i].first+a[i].second)%2) != z) {
            cout << -1 << endl;
            return 0;
        }
    }
    

    int m = 32;
    
    vector<ll> d(m);
    
    rep(i, m) {
        d[m-1-i] = 1LL<<i;
    }
    if (z%2==0) cout << m+1 << endl;
    else cout << m << endl;

    if (z%2==0) cout << 1 << " ";
    rep(i, m) cout << d[i] << " ";
    cout << endl;
    
    rep(i, n) {
        ll ix = a[i].first;
        ll iy = a[i].second;
        string ans = "";
        if (z%2==0) {
            ix++;
            ans += 'L';
        }
        rep(i, m) {
            if (ix>0 && ix>abs(iy)) {
                ans += 'R';
                ix -= d[i];
            }
            else if (ix<0 && abs(ix)>abs(iy)) {
                ans += 'L';
                ix += d[i];
            }
            else if (iy>0) {
                ans += 'U';
                iy -= d[i];
            }
            else {
                ans += 'D';
                iy += d[i];
            }
            
        }
        cout << ans << endl;
        //debug(ix);
        //debug(iy);
    }
    return 0;
}


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

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

  if (s == "Sunny") {
    cout << "Cloudy" << endl;
    return 0;
  }
  if (s == "Cloudy") {
    cout << "Rainy" << endl;
    return 0;
  }
  if (s == "Rainy") {
    cout << "Sunny" << endl;
    return 0;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    // 初期化は既に 0 に初期化される
    // 初期条件も既に 0 で OK

    // ループ
    for (int i = 0; i < N; ++i) {    //i日目
        for (int j = 0; j < 3; ++j) {       //i+1日目の行動を選ぶ
            for (int k = 0; k < 3; ++k) {   //i日目の行動
                if (j == k) continue;   //i日目とi+1日目の行動は異なる
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);  //行動kのi日目から行動jのi+1日目までの遷移
            }
        }
    }

    // 答え
    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}

Measured memory_bytes: 4992
import copy
H,W,K = map(int,input().split())
c_ij = []
for i in range(H):
    c_ij.append(list(input()))


ans = 0

for i in range(2**H):
    for j in range(2**W):
        c = copy.deepcopy(c_ij)
        for ii in range(H):
            if ((i>>ii) & 1):
                for jj in range(W):
                    c[ii][jj] = "."

        for jj in range(W):
            if ((j>>jj) & 1):
                for ii in range(H):
                    c[ii][jj] = "."


        memo = 0
        for ii in range(H):
            for jj in range(W):
                if c[ii][jj] == "#":
                    memo+= 1

        if memo == K:
            ans += 1

print(ans)

Measured memory_bytes: 9296