akhauriyash/Code-Regression huggingface dataset:
class SegTree:
    """ segment tree with point modification and range product. """
    # # https://yukicoder.me/submissions/452850
    def __init__(self, N, data_f = min, data_unit=1<<30):
        self.N = N
        self.data_f = data_f
        self.data_unit = data_unit
        self.data = [self.data_unit] * (N + N)

    def build(self, raw_data):
        data = self.data
        f = self.data_f
        N = self.N
        data[N:] = raw_data[:]
        for i in range(N - 1, 0, -1):
            data[i] = f(data[i << 1], data[i << 1 | 1])

    def set_val(self, i, x):
        data = self.data
        f = self.data_f
        i += self.N
        data[i] = x
        while i > 1:
            data[i >> 1] = f(data[i], data[i ^ 1])
            i >>= 1

    def fold(self, L, R):
        """ compute for [L, R) """
        vL = vR = self.data_unit
        data = self.data
        f = self.data_f
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                vL = f(vL, data[L])
                L += 1
            if R & 1:
                R -= 1
                vR = f(data[R], vR)
            L >>= 1
            R >>= 1
        return f(vL, vR)
      
N=int(input())
S=input()
seg = SegTree(N,set.union,set())
S = [set(S[i]) for i in range(N)]
seg.build(S)
Q=int(input())
for i in range(Q):
  *q, = input().split()
  if q[0] == '1':
    i, c = q[1:]
    seg.set_val(int(i)-1,set(c))
  else:
    l,r = map(int,q[1:])
    print(len(seg.fold(l-1,r)))  


Measured memory_bytes: 373504
#とある世界では、今日はクリスマスイブの前日です。
#高羽氏は、デパートで N 個の品物を買おうとしています。
#i 個目の品物 (1≤i≤N) の定価は pi 円です。
#彼は割引券を持っており、N 個のうち最も定価が高い品物 1 個を定価の半額で買うことができます。
#残りの N−1 個の品物に対しては定価を支払います。
#支払金額は合計でいくらになるでしょうか？
N = int(input())
p = []
for i in range(N):
    P = int(input())
    p.append(P)
    q = sorted(p, reverse=True)

    sum = 0
for i in range(1, N):
    sum+=q[i]


print(int(q[0]/2+sum))

Measured memory_bytes: 38384
"use strict";

function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    let tmp = input[0].split(" ");
    let n = parseInt(tmp[0], 10);
    let k = parseInt(tmp[1], 10);
    let p = input[1].split(" ").map(str => parseInt(str, 10));

    p.sort(compareFunc);    //昇順に並べ替え

    let total = 0;

    for (let i = 0; i < k; i++) {
        total += p[i];
    }

    //出力
    console.log('%d', total);
}

function compareFunc(a, b) {
    return a - b;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29696
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define ld long double
#define pii pair <int,int>
#define pll pair <ll,ll>
#define pil pair <int,ll>
#define pli pair <ll,int>
#define ull unsigned long long
#define pdd pair <double,double>
#define pb push_back
#define mp make_pair
#define puu pair<ull,ull>
#define pvv pair<vector<int>, vector<int> >
#define _bp __builtin_popcount
#define ptt pair <Tree*,Tree*>
#define all(v) v.begin(),v.end()
#define en "\n"
//const long double pi = acos(-1);
void boos()
{
     ios_base :: sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
}
void file()
{
   freopen("max.in","r",stdin);
   freopen("max.out","w",stdout);
}
const ll INF = 1e9 + 7;
const ll INF1 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTmx = (int)1e9;
const ld EPS = (ld)1e-9;
const int N = 3e5 + 100;
int a[N];
int main()
{
    //file();
    boos();
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1;i <= n;i++)
    {
    	cin >> a[i];
	}
	ans = 0;
	int tek = 0;
	for(int i = 2;i <= n;i++)
	{
		if(a[i] <= a[i - 1])tek++;
		else {
			ans = max(ans,tek);
			tek = 0;
		}
	}
	ans = max(ans,tek);
	cout << ans;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for (int i=0,_n=(int)(n); i < _n; i++)
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
 
typedef long long ll;

string ans;

char rev(char c) {
  if (c == 'S') return 'W';
  else return 'S';
}

bool check(string t, string s) {
  int N = (int)s.size();
  for (int i = 2; i < N; i++) {
    char next;
    if (t[i-1] == 'S' && s[i-1] == 'o') next = t[i-2];
    if (t[i-1] == 'S' && s[i-1] == 'x') next = rev(t[i-2]);
    if (t[i-1] == 'W' && s[i-1] == 'o') next = rev(t[i-2]);
    if (t[i-1] == 'W' && s[i-1] == 'x') next = t[i-2];
    t += next;
  }
  // cout << t << endl;
  // cout << s << endl;
  if (t[N-1] == 'S' && s[N-1] == 'o' && (t[N-2] != t[0])) return false;
  if (t[N-1] == 'S' && s[N-1] == 'x' && (t[N-2] == t[0])) return false;
  if (t[N-1] == 'W' && s[N-1] == 'o' && (t[N-2] == t[0])) return false;
  if (t[N-1] == 'W' && s[N-1] == 'x' && (t[N-2] != t[0])) return false;

  if (t[0] == 'S' && s[0] == 'o' && (t[N-1] != t[1])) return false;
  if (t[0] == 'S' && s[0] == 'x' && (t[N-1] == t[1])) return false;
  if (t[0] == 'W' && s[0] == 'o' && (t[N-1] == t[1])) return false;
  if (t[0] == 'W' && s[0] == 'x' && (t[N-1] != t[1]))  return false;

  ans = t;
  return true;
}

int main2() {
  int N;
  string S;
  cin >> N >> S;

  ans = "-1";
  check("SS", S); if (ans != "-1") { cout << ans << endl; return 0; }
  check("SW", S); if (ans != "-1") { cout << ans << endl; return 0; }
  check("WS", S); if (ans != "-1") { cout << ans << endl; return 0; }
  check("WW", S); if (ans != "-1") { cout << ans << endl; return 0; }
  cout << "-1" << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}

Measured memory_bytes: 844
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <complex>

using namespace std;
using pii = pair<int, int>;
using ll = long long;

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

	int n;
	cin >> n;
	vector<pii> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i].first;
		p[i].second = i;
	}
	sort(p.rbegin(), p.rend());
	set<int> s;
	ll answer = 0;
	s.insert(p[0].second);
	for (int i = 1; i < n; i++) {
		auto it = s.insert(p[i].second).first;
		auto nit = it;
		nit++;
		if (it == s.begin()) {
			ll l = *it;
			ll r = *nit;
			ll l2 = 0;
			nit++;
			ll r2 = (nit == s.end()) ? n - 1 : *nit - 1;
			answer += (l - l2 + 1) * (r2 - r + 1) * (ll)(p[i].first);
		}
		else if (nit == s.end()) {
			auto pit = it;
			pit--;
			ll l = *pit;
			ll r = *it;
			ll l2;
			if (pit == s.begin()) l2 = 0;
			else {
				pit--;
				l2 = *pit + 1;
			}
			ll r2 = n - 1;
			answer += (l - l2 + 1) * (r2 - r + 1) * (ll)(p[i].first);
		}
		else {
			auto pit = it;
			pit--;
			ll l = *pit;
			ll r = *it;
			ll l2;
			if (pit == s.begin()) l2 = 0;
			else {
				pit--;
				l2 = *pit + 1;
			}
			ll r2 = *nit - 1;
			answer += (l - l2 + 1) * (r2 - r + 1) * (ll)(p[i].first);

			pit = it;
			pit--;
			l = *it;
			r = *nit;
			l2 = *pit + 1;
			nit++;
			r2 = (nit == s.end()) ? n - 1 : *nit - 1;
			answer += (l - l2 + 1) * (r2 - r + 1) * (ll)(p[i].first);
		}
	}
	cout << answer;

	return 0;
}


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

int main(void) {
  int i, flg[26];
  for(i = 0; i < 26; ++i) flg[i] = 0;
  char s[30];
  scanf("%s", s);
  for(i = 0; i < strlen(s); ++i) {
    if(flg[s[i] - 'a']) {
      printf("no");
      return 0;
    }
    flg[s[i] - 'a'] = 1;
  }
  printf("yes");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<ctime>
#include<cstdlib>
#include<numeric>
#include<typeinfo>
#include<cstdio>
#include<cctype>
#include<list>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
const int inf=1e8;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009

int search(int *s,int t,int left,int right){
	while(left<right){
		int k=(right+left)/2;
		if(s[k]==t){
			return 1;
		}else if(s[k]>t){
			right=k;
		}else{
			left=k+1;
		}
	}
	return 0;
}
	
int main(){
	int n,q,i,j;
	cin>>n;
	int s[n];
	int cnt=0;
	loop(i,0,n){
		cin>>s[i];
	}
	cin>>q;
	int t;
	loop(i,0,q){
		cin>>t;
		if(search(s,t,0,n)!=0){
			cnt++;
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 3384
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

ll cho[107];

int main(){
  ll N,M;cin>>N>>M;
  if(N==2||M==2){
    cout << 0 << endl;
  }
  else if(N==1&&M==1){
    cout << 1 << endl;
  }
  else if(N==1){
    cout << max(M-2,0LL) <<endl;
  }
  else if(M==1){
    cout << max(N-2,0LL) <<endl;
  }
  else{
    cout << (N-2)*(M-2) << endl;
  }
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    os.println(Math.max(0, c - (a - b)));
  }
}

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

#define ll long long int
#define All(a) (a).begin(),(a).end()

void solve(){
  int n,m,count;
  scanf("%d %d",&n,&m);
  vector<vector<char>> A(n,vector<char>(m));
  int x[8]={-1,-1,-1,0,0,1,1,1};
  int y[8]={-1,0,1,-1,1,-1,0,1};
  for(int i=0;i<n;i++){
    for (int  j = 0; j < m; j++){
      cin >> A[i][j];
    }
  }
  for (int i = 0; i < n; i++){
    for (int  j = 0; j < m; j++){
      if(A[i][j]!='#'){
        count=0;
        for (int k = 0; k < 8; k++)
        {
          int xx=y[k]+i;
          int yy=x[k]+j;
          if(xx<0 || xx>=n) continue;
          else if(yy<0 || yy>=m) continue;
          else if(A[xx][yy]=='#')count++;
        }
        printf("%c",'0'+count);
      }else{
        printf("#");
      }
    }
    printf("\n");
  }
}
int main(){
  solve();
  return 0;
}

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

int main(void){

    int x,y,i,x_group,y_group;

    scanf("%d %d",&x,&y);

    switch (x){
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
        x_group = 1;
        break;

    case 4:
    case 6:
    case 9:
    case 11:
        x_group = 2;
        break;

    case 2:
        x_group = 3;
        break;
    }

    switch (y){
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
        y_group = 1;
        break;
        
    case 4:
    case 6:
    case 9:
    case 11:
        y_group = 2;
        break;

    case 2:
        y_group = 3;
        break;
    }

    if(x_group == y_group){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    //static List<string> str = new List<string>();
    static void Main(string[] args)
    {
        // 入力
        string[] input = Console.ReadLine().Split(' ');
        int H = int.Parse(input[0]);
        int W = int.Parse(input[1]);

        List<string> board = new List<string>();
        for(int i = 0; i<H; i++)
        {
            board.Add(Console.ReadLine());
        }

        // .だけの行を削除する
        List<string> comp = new List<string>();
        for(int i=0; i<H; i++)
        {
            string str1 = board[i];
            string str2 = str1.Replace("#", "");
            if(str1.CompareTo(str2) != 0)
            {
                comp.Add(str1);
            }
        }
        //Console.WriteLine("comped");
        // .だけの列を削除したい
        for(int i=0; i<W; i++)
        {
            // i列目
            bool isWhite = true;
            for(int j=0; j<comp.Count; j++)
            {
                if (comp[j][i] != '.')
                    isWhite = false;
            }
            //Console.WriteLine(i + " : " + isWhite);

            if(isWhite)
            {
                for(int j=0; j<comp.Count; j++)
                {
                    comp[j] = (i==0 ? "" : comp[j].Substring(0, i)) + "d" + comp[j].Substring(i + 1);
                }
  
            }
        }

        // 出力
        for(int i=0; i<comp.Count; i++)
        {
            Console.WriteLine(comp[i].Replace("d", ""));
        }
       
    }

}

Measured memory_bytes: 13280
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

//<expr>   :: = <term>[('+' | '-') <term>] *
//<term>   :: = <factor>[('*' | '/') <factor>] *
//<factor> :: = <number> | '(' <expr> ')'
//<number> : == 1?????\????????°???


ll number(string& s, ll& i);
ll term(string& s, ll& i);
ll factor(string& s, ll& i);
ll expr(string& s, ll& i);

ll number(string& s, ll& i) {
	ll n = s[i++] - '0';
	while (isdigit(s[i])) n = n * 10 + s[i++] - '0';
	return n;
}

ll factor(string& s, ll& i) {
	if (isdigit(s[i])) return number(s, i);

	// ????????§?§?????????£???????????° s[i] == '(' ??¨??????
	i++; // '('??????????£???°???
	ll ret = expr(s, i);
	i++; // ')'??????????£???°???
	return ret;
}

ll term(string& s, ll& i) {
	ll val = factor(s, i);
	while (s[i] == '*' || s[i] == '/') {
		char op = s[i];
		i++;
		int val2 = factor(s, i);
		if (op == '*') val *= val2;
		else val /= val2;
	}
	return val;
}

ll expr(string& s, ll& i) {
	ll val = term(s, i);
	while (s[i] == '+' || s[i] == '-') {
		char op = s[i];
		i++;
		int val2 = term(s, i);
		if (op == '+') val += val2;
		else val -= val2;
	}
	return val;
}

int n;
ll pos = 0;
string s;

int main() {
	cin >> n;
	REP(i,n){
		cin >> s;
		pos = 0;
		cout << expr(s, pos) << endl;
	}
}

Measured memory_bytes: 3028
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n,a;
	while(1){
		int d[7]={};
		cin>>n;
		if(n==0) break;
		rep(i,0,n){
			cin>>a;
			if(a/10>=6) d[6]++;
			else d[a/10]++;
		}
		rep(i,0,7) o(d[i]);
	}
}

Measured memory_bytes: 1160
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define N 100000
#define C 1000000
#define E 500000

typedef struct Node{
  int to;
  int from;
  int cost;
} graph;

int n;
int d[N];
graph e[E];
void sp(int r){
  int i;
  int flag = 0;

  for(i=0;i<n;i++){
    d[i] = C;
  }

  d[0] = 0;

 while(1){
    flag = 1;
    for(i=0;i<r;i++){
      if(e[i].cost + d[e[i].from] < d[e[i].to]){
        d[e[i].to] = e[i].cost + d[e[i].from];
        flag = 0;
      }
    }
    if(flag == 1) break;
  }
}

int main(){
  int i;
  int j;
  int u;
  int k;
  int counter;

  scanf("%d",&n);
  counter = 0;
  for(i=0;i<n;i++) {
    scanf(" %d %d",&u,&k);
    for(j=0;j<k;j++){
      e[counter].from = u;
      scanf(" %d %d",&e[counter].to,&e[counter].cost);
      counter++;
    }
  }

  sp(counter);

  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
  return 0;
}



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

int main() {
    long long N; cin >> N;
    
    long long ans = 1100000000000;
    for(long long i = 1; i*i <= N; ++i) {
        long long a = 1, b = 1;
        if(N % i == 0) a = i;
        b = N / a;
        ans = min(ans, a + b - 2);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
def solve():
    H,W=map(int,input().split())
    for i in range(W+2):
        print("#",end='')
    print()
    for i in range(H):
        print("#",end='')
        s=input()
        print(s,end='')
        print("#")
    for i in range(W+2):
        print("#",end='')
    print()

if __name__ == "__main__":
    solve()

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

using namespace std;

typedef long long int ll;

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

  ll n;
  cin >> n;
  vector < ll > a(n + 1), lt(n + 1), rt(n + 1);
  for(int i = 1; i <= n; i++) cin >> a[i];
  lt[1] = a[1];
  rt[n] = a[n];
  for(int i = 2; i <= n; i++) lt[i] = __gcd(a[i], lt[i - 1]);
  for(int i = n - 1; i > 0; i--) rt[i] = __gcd(a[i], rt[i + 1]);

  ll ans = max(rt[2], lt[n - 1]);
  for(int i = 1; i < n; i++){
    ans = max(ans, __gcd(lt[i - 1], rt[i + 1]));
  }

  cout << ans << '\n';
}


Measured memory_bytes: 2560
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		double[] x = new double[3];
		double[] y = new double[3];
		double ansx,ansy;
		double r;
		double a1,a2;
		double b1,b2;
		double c1,c2;
		double temp;
		int n;
		
		n = sc.nextInt();
		
		for(int i=0;i<n;i++){
			for(int j=0;j<3;j++){
				x[j] = sc.nextDouble();
				y[j] = sc.nextDouble();
			}
			
			a1 = 2*(x[1]-x[0]);
			a2 = 2*(x[2]-x[0]);
			b1 = 2*(y[1]-y[0]);
			b2 = 2*(y[2]-y[0]);
			c1 = (x[0]*x[0])-(x[1]*x[1])+(y[0]*y[0])-(y[1]*y[1]);
			c2 = (x[0]*x[0])-(x[2]*x[2])+(y[0]*y[0])-(y[2]*y[2]);
			
			ansx = (b1*c2-b2*c1)/(a1*b2-a2*b1);
			ansy = (c1*a2-c2*a1)/(a1*b2-a2*b1);
			
			temp = (x[0]-ansx)*(x[0]-ansx)+(y[0]-ansy)*(y[0]-ansy);
			
			r = Math.sqrt(temp);
			
			System.out.printf("%.3f %.3f %.3f\n",ansx,ansy,r);
		}
	}
}

Measured memory_bytes: 20492
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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;
}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n; cin >> n;
    vector<int> lis(n);
    REP(i, 0, n){cin >> lis[i];}
    sort(ALL(lis));
    lis.back() /= 2;
    ll ans = 0;
    REP(i, 0, n){
        ans += lis[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

double yogen(double a, double b, double deg){
	double ret;
	ret=pow(a,2.0)+pow(b,2.0);
	ret-=2*a*b*cos(deg*PI/180.0);
	ret=pow(ret,0.5);
	return ret;
}


signed main(){
	double a,b,h,m; cin>>a>>b>>h>>m;
	double kakudo_h=30.0*h+0.5*m;
	double kakudo_m=6.0*m;
	double deg=abs(kakudo_h-kakudo_m);
	cout<<yogen(a,b,deg)<<endl;

	return 0;
}


Measured memory_bytes: 4368
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define YESNO(i) puts((i)?"YES":"NO");
#define YesNo(i) puts((i)?"Yes":"No");
#define yesno(i) puts((i)?"yes":"no");
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k;cin>>k;
  print(k/2*(k+k%2)/2);
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer st = new StringTokenizer(br.readLine(), " ");
		
		long a = Long.parseLong(st.nextToken());
		long b = Long.parseLong(st.nextToken());
		long c = Long.parseLong(st.nextToken());
		long d = Long.parseLong(st.nextToken());

		long ans = Math.max(a * c, a * d);
		ans = Math.max( ans, Math.max(b*c, b * d));
		
		System.out.println(ans);
	}
}

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

using namespace std;

int main(){
    int s,k,i,j;
    while(~scanf("%d%d",&k,&s)){
        if(3*k == s) puts("1");
        else{
            int cot = 0;
            for(i = 0;i <= k;i++){
                for(j = 0;j <= k;j++){
                    if(i+j > s) break;
                    else if(s-i-j <= k&&s-i-j >= 0) cot++;
                }
            }
            printf("%d\n",cot);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >>n;
    vector<int>a(n);
    vector<int>b(n);
    vector<int>c(n-1);
    for(int i=0;i<n;i++)cin >> a[i];
    for(int i=0;i<n;i++)cin >> b[i];
    for(int i=0;i<n-1;i++) cin >> c[i];
    int sum=0;
    int count =0;
    for(int i=0;i<n;i++){
        sum += b[i];
        }
    for(int i=0;i<n-1;i++){    
        if(a[i]+1 == a[i+1])count +=c[a[i]-1];
    }
    cout << sum + count <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int cnt = 0;
        for(int i=0; i<s.length; i++) {
            if(s[i] != t[i]) cnt++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 43364
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18;
struct edge{int from;int to;ll cost;};
int main(){
    int n,m,p;cin >> n >> m >> p;
    vector<edge> g(m);
    vector<bool> f(n);
    vector<vector<int>> h(n);
    for(int i=0;i<m;i++){
        int a,b;ll c;cin >> a >> b >> c;
        a--,b--,c-=p;
        h[b].push_back(a);
        g[i]=(edge{a,b,-c});
    }
    stack<int> st;
    st.push(n-1);
    f[n-1]=true;
    while(!st.empty()){
        int p=st.top();
        st.pop();
        for(auto x:h[p]){
            if(!f[x]){
                st.push(x);
                f[x]=true;
            }
        }
    }
    vector<ll> d(n,INF);
    d[0]=0;
    for(int i=0;i<2*n;i++){
        for(int j=0;j<m;j++){
            if(d[g[j].from]!=INF&&d[g[j].to]>d[g[j].from]+g[j].cost){
                d[g[j].to]=d[g[j].from]+g[j].cost;
                if(i>=n-1&&f[g[j].to]){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }
    cout << max(0LL,-d[n-1]) << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int binarysearch(int);

int n,S[100000000];

int main()
{
  int q,t,c=0;
  int i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t);
    if(binarysearch(t)==1) c++; 
  }
  printf("%d\n",c);
  return 0;
}

int binarysearch(int key){
  int left=0,right=n,mid;

  while(left<right){
    mid = (left + right)/2;
    if(key==S[mid]) return 1;//発見
    
    if(key>S[mid]) left = mid+1;
    else if(key<S[mid]) right = mid;
  }
  return 0;
}



Measured memory_bytes: 2132
import heapq

N=int(input())
rque=[]
rque2=[]
lque=[]
lque2=[]
for i in range(N):
    l,r=map(int,input().split())
    rque.append((-l,i))
    rque2.append((-l,i))
    lque.append((r,i))
    lque2.append((r,i))

heapq.heapify(rque)
heapq.heapify(lque)
used=set([])
pos=0
dir="R"
ans=0
check=set([i for i in range(N)])
while used!=check:
    if dir=="R":
        l,i=heapq.heappop(rque)
        while i in used:
            l,i=heapq.heappop(rque)
        l*=-1
        if l>=pos:
            ans+=(l-pos)
            pos=l
            used.add(i)
            dir="L"
        else:
            break
    else:
        r,i=heapq.heappop(lque)
        while i in used:
            r,i=heapq.heappop(lque)
        if pos>=r:
            ans+=(pos-r)
            pos=r
            used.add(i)
            dir="R"
        else:
            break

test1=ans+abs(pos)

heapq.heapify(rque2)
heapq.heapify(lque2)
used=set([])
pos=0
dir="L"
ans=0
check=set([i for i in range(N)])
while used!=check:
    if dir=="R":
        l,i=heapq.heappop(rque2)
        while i in used:
            l,i=heapq.heappop(rque2)
        l*=-1
        if l>=pos:
            ans+=(l-pos)
            pos=l
            used.add(i)
            dir="L"
        else:
            break
    else:
        r,i=heapq.heappop(lque2)
        while i in used:
            r,i=heapq.heappop(lque2)
        if pos>=r:
            ans+=(pos-r)
            pos=r
            used.add(i)
            dir="R"
        else:
            break

test2=ans+abs(pos)
print(max(test1,test2))

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


public class Main {
	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve(){
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		for(int i=0; i<n; ++i){
			int V = 0, M = 1000000000;
			
			char[] str = sc.next().toCharArray();
			Arrays.sort(str);
			char[] rts = new char[str.length];
			for(int j=0; j<str.length; ++j){
				rts[j] = str[str.length - j -1];
			}
			
			int v = Integer.parseInt(new String(rts));
			int m = Integer.parseInt(new String(str));
			V = Math.max(v, V);
			M = Math.min(m, M);
			
			System.out.println(Math.abs(V-M));
		}
	}
	
	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 11000
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	

    int zahyo[5];
    REP(i,5)
    {
        cin >> zahyo[i];
    }
    int k; cin >> k;
    bool ok = 1;


    if(zahyo[4] - zahyo[0] > k) ok = 0;
    if(ok) cout << "Yay!" << endl;
    else cout << ":(" << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  vector<int> B = A;
  sort(B.begin(),B.end());
  int c = 0;
  for(int i = 0; i < N; ++i){
    c += (A[i] != B[i]);
  }
  int Q;
  cin >> Q;
  vector<int> X(Q), Y(Q);
  for(int i = 0; i < Q; ++i) cin >> X[i] >> Y[i], --X[i], --Y[i];
  if(not c){
    cout << 0 << endl;
    return 0;
  }
  for(int i = 0; i < Q; ++i){
    c -= (A[X[i]] != B[X[i]]);
    c -= (A[Y[i]] != B[Y[i]]);
    swap(A[X[i]],A[Y[i]]);
    c += (A[X[i]] != B[X[i]]);
    c += (A[Y[i]] != B[Y[i]]);
    if(not c){
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}



Measured memory_bytes: 7628
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
const int MAX=2e5+5;


int bit[MAX], N;
int sum(int i){
	int s=0;
	while(i>0){
		s+=bit[i];
		i -= i& -i;
	}
	return s;
}

void add(int i,int x){
	while(i<=N+1){
		bit[i]+=x;
		i+= i& -i;
	}
}

int main(){
	ll K;
	cin>>N>>K;
	vll s(N+1);
	s[0]=0;
	rep1(i,N){
		int a;
		cin>>a;
		a-=K;
		s[i]=s[i-1]+a;
	}
	//s[l]<=s[r]かつl<rな組(l,r)の個数を求めたい
	//BITで出そう
	
	//その前に値を圧縮
	vll v=s;
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	
	vector<int> b(N+1);
	rep(i,N+1)b[i]=lower_bound(v.begin(),v.end(), s[i])-v.begin();
  //0-indexedなのをずらす
  
	vector<int> a(N+2);
	rep1(i,N+1)a[i]=b[i-1]+1;	
  
	ll ans=0;
	rep1(j,N+1){
		ans+=(ll)sum(a[j]);
		add(a[j],1);
	}
	cout<<ans;
}

Measured memory_bytes: 5760
#include<iostream>
#include<vector>

using namespace std;

int n,m;
int ans;

vector<bool> done;
vector<vector<int>> to;

void dfs(int id)
{
  bool flag=true;
  for(int i=0;i<n;i++)
    if(done[i]==false)
      flag=false;
  if(flag)
  {
    ans++;
    return;
  }
  for(int i=0;i<to[id].size();i++)
  {
    int nxid=to[id][i];
    if(done[nxid]==true)continue;
    done[nxid]=true;
    dfs(nxid);
    done[nxid]=false;
  }
  return;
}


int main()
{
  cin>>n>>m;
  to=vector<vector<int>>(n);
  done=vector<bool>(n,false);
  for(int i=0;i<m;i++)
  {
    int a,b;
    cin>>a>>b;
    a--;b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  
  ans=0;
  
  done[0]=true;
  dfs(0);
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int a, b;
	cin >> a >> b;
	if ((a + b) % 3 == 0 or a % 3 == 0 or b % 3 == 0) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == 1)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(vector<int>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}

//CODE
void solve(void)
{

  int A,B,C,D;
  cin>>A>>B>>C>>D;
  cout<<min(A,B) + min(C,D)<<endl;
  
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef pair<int, int> p;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(c > b + a) cout << (b + a) + b + 1 << endl;
  else if(c > b) cout << b + c << endl;
  else cout << c + b << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
inline bool is_prime(int n){
	if (n<=1) return false;
	int m=(int)(floor(sqrt(n)+0.5));
	for (int i=2;i<=m;++i){
		if (n%i==0) return false;
	}
	return true;
}
int main(){
	int x,count=0,m;
	cin>>x;
	for (int i=1;i<=x;++i){
		cin>>m;
		if (m<=1) ;
		else if (is_prime(m)) ++count;
	}
	cout<<count<<endl;
	return 0; 
}

Measured memory_bytes: 3036
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=1e5+10;
int n;
void mul(int *a,int *p) {
    static int b[N];
    for(int i=1;i<=n;++i) b[i]=a[p[i]];
    for(int i=1;i<=n;++i) a[i]=b[i];
}
int vis[N];
void Pow(int *a,int k) {
    static int b[N],c[N],m;
    for(int i=1;i<=n;++i) vis[i]=0;
    for(int i=1;i<=n;++i) if(!vis[i]) {
        m=0; int cur=i;
        while(!vis[cur]) vis[b[m++]=cur]=1,cur=a[cur];
        for(int i=0;i<m;++i) c[b[i]]=b[(i+k)%m];
    }
    for(int i=1;i<=n;++i) a[i]=c[i];
}
int p[N],q[N],rp[N],rq[N];
int a[N],ra[N],b[N],c[N];
int main() {
    int L; rd(n),rd(L),L--;
    for(int i=1;i<=n;++i) rd(p[i]),rp[p[i]]=i;
    for(int i=1;i<=n;++i) rd(q[i]),rq[q[i]]=i;
    for(int i=1;i<=n;++i) a[i]=i;
    mul(a,q),mul(a,rp),mul(a,rq),mul(a,p);
    Pow(a,L/6); L%=6;
    for(int i=1;i<=n;++i) ra[a[i]]=i;
    for(int i=1;i<=n;++i) b[i]=a[i];
    mul(b,q),mul(b,ra);
    mul(a,p),mul(a,ra);
    while(L--) {
        for(int i=1;i<=n;++i) ra[a[i]]=i,c[i]=b[i];
        mul(c,ra);
        for(int i=1;i<=n;++i) a[i]=b[i],b[i]=c[i];
    }
    for(int i=1;i<=n;++i) printf("%d ",a[i]);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n,0);
  vector<int> b(n,0);
  for(int i=1;i<n;i++){
    cin >> a.at(i);
    b.at(a.at(i)-1)++;
  }
  
  for(int i=0;i<n;i++){
    cout << b.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 4776
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#define Set(a, v) memset(a, v, sizeof(a))
#define For(i, l, r) for(int i = (l); i <= (int)(r); ++i)
#define Fordown(i, r, l) for(int i = (r); i >= (int)(l); --i)
#define mid ((l+r) >> 1)
#define lson h<<1, l, mid
#define rson h<<1|1, mid+1, r
using namespace std;

inline int read(){
    int x = 0, fh = 1; char ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
    for(; isdigit(ch); ch = getchar()) x = (x<<1) + (x<<3) + (ch^'0');
    return x * fh;
}

const int M = 200100 << 1, N = 200100;
int to[M], Head[N], Next[M], val[M], e;
void add_edge (int u, int v, int w) {
    to[++e] = v;
    val[e] = w;
    Next[e] = Head[u];
    Head[u] = e;
}

bool vis[N], flag;
int dis[N];
void bellman_ford (int u) {
    vis[u] = true;
    for (int i = Head[u]; i; i = Next[i]) {
        int v = to[i];
        if (dis[v] > dis[u] + val[i] ) {
            if (vis[v]) {flag = true; return;}
            dis[v] = dis[u] + val[i];
            bellman_ford (v);
        }
    }
    vis[u] = false;
}
            
void init () {
    e = 0;
    Set(Head, 0);
    Set(vis, false);
    Set(dis, 0x3f);
    flag = false;
}

int main (){
	init();
	int n = read(), m = read();
	while (m--) {
		int l = read(), r = read(), s = read();
		add_edge (l, r, s);
		add_edge (r, l, -s);
	}
	For (i, 1, n) {
		if (!vis[i]) bellman_ford (i);
		if (flag) break; 
	}
	printf ("%s\n", !flag ? "Yes" : "No");
}


Measured memory_bytes: 9216
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
#include <tuple>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int a, b, m;
int dp[16][16];
void exec()
{
	cin >> a >> b >> m;
	if((a|b)==0)exit(0);
	memset(dp,0,sizeof(dp));
	for(int i=0;i<m;i++){
		int x,y;
		cin >> x >> y;
		x--;y--;
		dp[x][y]=-1;
	}

	if(dp[0][0]==-1)
	{
		cout << 0 << endl;
		return;
	}

	dp[0][0]=1;
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			if(dp[i][j]==-1)continue;
			if(i>0&&dp[i-1][j]>=0){
				dp[i][j]+=dp[i-1][j];
			}
			if(j>0&&dp[i][j-1]>=0){
				dp[i][j]+=dp[i][j-1];
			}
		}
	}

	cout << max(0,dp[a-1][b-1]) << endl;
}
int main() {
	while(1)exec();
}

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

typedef pair<string, int> P;

int main(void){
  int n, qtm, elps = 0;
  queue<P> que;
  
  cin >> n >> qtm;
  string name;
  int val;
  for (auto i = 0; i < n; i++) {
    cin >> name >> val;
    que.push(P(name, val));
  }
  
  while (!que.empty()) {
    auto p = que.front(); que.pop();
    if (p.second <= qtm) {
      elps += p.second;
      cout << p.first << " " << elps << endl;
    } else {
      elps += qtm;
      que.push(P(p.first, p.second - qtm));
    }
  }
  
  return 0;
}

Measured memory_bytes: 6188
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N,M;
    cin >> N >> M;

    vector<int> a(N),b(N);
    for(int i = 0;i < M;i++){
        int x,y;
        cin >> x >> y;
        if(x == 1)a[y-1] = 1;
        if(y == N)b[x-1] = 1;
    }
    for(int i = 0;i < N;i++){
        if(a[i] && b[i]){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    } 
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<stack>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include <iomanip>
#include<unordered_map>
#include<set>
using namespace std;
typedef long long ll;
const int maxn = 105;

int main() {
    //freopen("in.cpp","r",stdin);
    int n;
    string a,b;
    cin>>n>>a>>b;
    int cnt=0;
    for(int i=1;i<=n;i++){
        bool sign=0;
        for(int j=n-i;j<n;j++){
            if(a[j]!=b[j-n+i]){
                sign=1;
                break;
            }
        }
        if(!sign)cnt=i;
    }
    cout<<n + n -cnt<<endl;
    return 0;
}


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

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



int main() {
    int n; cin >> n;
    map<int, int> m;
    rep(i, n) {
        int tmp; cin >> tmp;
        m[tmp]++;
    }

    int ans = 0;
    for(auto itr : m) {
        // 要素残したままにする場合に必要な数
        int tmp = itr.second-itr.first;
        if(tmp < 0) {
            // マイナスの場合は、全て削除しないといけない
            ans += itr.second;
        } else {
            // 差が0か+の場合は、全て削除する場合と残す場合どっちがいいかをしらべて少ない方を実行する
            // 全て取り除いた方が早い場合はそうする
            tmp = min(tmp, itr.second);
            ans += tmp;
        }
    }

    cout << ans << endl;

    return 0;
    
}


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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;

lli a,b,c;
vll s;

int main(){
  cin >> a >> b >> c;
  s = vll(500);
  s[a]++;s[b]++;s[c]++;
  if(s[5] == 2 && s[7]==1) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <complex>
using namespace std;
int main(void) {
  int a, b, c, sqrtnum;
  string number;
  scanf("%d %d", &a, &b);
  number = to_string(a) + to_string(b);
  c = stoi(number);
  sqrtnum = sqrt(c);
  if(sqrtnum * sqrtnum == c) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func pinit(primes []bool) {
	for i := 0; i < len(primes); i++ {
		primes[i] = true
	}
	primes[0] = false
	primes[1] = false
	for i := 2; i*i <= len(primes); i++ {
		for j := i * 2; j < len(primes); j += i {
			if primes[j] {
				primes[j] = false
			}
		}
	}
}

func main() {
	M := int(1e5)
	p := make([]bool, M)
	pinit(p)             // エラトステネスの篩
	pn := make([]int, M) // 2017に似た数の確認
	for i := 2; i < len(pn); i++ {
		if p[i] && p[(i+1)/2] {
			pn[i] = 1
		}
	}
	sum := make([]int, M+1)
	for i := 0; i < M; i++ {
		sum[i+1] = sum[i] + pn[i] // 累積和
	}
	// クエリ処理
	var N int
	fmt.Scan(&N)
	ans := make([]int, N)
	for i := 0; i < N; i++ {
		var L, R int
		fmt.Scan(&L, &R)
		ans[i] = sum[R+1] - sum[L]
	}
	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}


Measured memory_bytes: 5888
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;

int main(){
    int N, M;
    vector<int> V[100001];
    int P[100001] = {};
    int Y[100001] = {};
    cin >> N >> M;
    //cout << "c"<<endl;
    for(int i=0;i<M;i++){
        cin >> P[i] >> Y[i];
        V[P[i]].push_back(Y[i]);
        //cout << i << endl;      
    }
    //cout <<"b"<<endl;
    for(int i=0;i<N;i++){
        sort(V[i+1].begin(), V[i+1].end());
    }
    //cout <<"a"<<endl;
    for(int i=0;i<M;i++){
        printf("%06d%06d\n", P[i],lower_bound(V[P[i]].begin(),V[P[i]].end(),Y[i])-V[P[i]].begin()+1);
    }
}


Measured memory_bytes: 7808
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int h[100010];
    rep(i, N) cin >> h[i];
    int ans = INF;
    sort(h, h + N);
    rep(i, N - K + 1) {
        ans = min(ans, h[K + i - 1] - h[i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string str,gtr,key;
	int q,a,b;
	cin>>str>>q;
	for(int i=0;i<q;i++){
		cin>>key>>a>>b;
		if(key=="replace"){
			cin>>gtr;
			str.replace(a,b-a+1,gtr);
		}else if(key=="reverse"){
			reverse(str.begin()+a,str.begin()+b+1);
		}else{
			cout<<str.substr(a,b-a+1)<<endl;
		}
	}
	return 0;
}


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

int main() {
	int N,K;
	cin >> N >> K;
	vector <int>hei(N);
	for (int i=0;i<N;i++){
		cin >> hei.at(i);
	}
	int count =0;
	for (int i=0;i<N;i++){
		if(hei.at(i)>=K){
			count ++ ;
		}
	}
	cout << count<<endl;
}



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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll MyPow(ll A, ll N){
  if (N == 0) return 1;
  if (N % 2 == 0) return MyPow(A*A%MOD, N/2);
  return MyPow(A*A%MOD, N/2) * A % MOD;
}

ll DP1[int(1e6+5)], DP2[int(1e6+5)];
ll sum1[int(1e6+5)], sum2[int(1e6+5)];

int main(){
  int R1, C1, R2, C2;
  cin >> R1 >> C1 >> R2 >> C2;

  DP1[0] = 1; DP2[0] = 1;
  sum1[0] = 1; sum2[0] = 1;
  for (ll i = 1; i <= R2+1; i++){
    DP1[i] = DP1[i-1] * (i+C1-1) % MOD;
    DP1[i] *= MyPow(i, MOD - 2);
    DP1[i] %= MOD;
    sum1[i] = sum1[i-1] + DP1[i];
    sum1[i] %= MOD;

    DP2[i] = DP2[i-1] * (i+C2) % MOD;
    DP2[i] *= MyPow(i, MOD - 2);
    DP2[i] %= MOD;
    sum2[i] = sum2[i-1] + DP2[i];
    sum2[i] %= MOD;
  }


  ll ans = sum2[R2+1] - sum1[R2+1] - sum2[R1] + sum1[R1];
  ans %= MOD;
  if (ans < 0) ans += MOD;

  cout << ans << endl;

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  string s1,s2;
  cin >> s1;
  cin >> s2;
  int tatecnt = 0;
  int yokocnt = 0;
  vector<int> retsu;
  rep(i,n){
    if(s1.at(i) == s2.at(i)){
      retsu.push_back(1);
    }else{
      retsu.push_back(2);
      i++;
    }
  }
  /*rep(i,retsu.size()){
    cout << retsu.at(i);
  }
  cout << endl;*/
  int64_t CONST = 1000000007;
  int64_t sum = 1;
  for(int i=0;i<retsu.size();i++){
    if(i==0){
      if(retsu.at(0) == 1){
        sum = 3;
      }else{
        sum = 6;
      }
    }else{
      if(retsu.at(i-1) == 1 && retsu.at(i) == 1){
        sum = (sum * 2) % CONST;
      }else if(retsu.at(i-1) == 1 && retsu.at(i) == 2){
        sum = (sum * 2) % CONST;
      }else if(retsu.at(i-1) == 2 && retsu.at(i) == 1){
        sum = sum;
      }else if(retsu.at(i-1) == 2 && retsu.at(i) == 2){
        sum = (sum * 3) % CONST;
      }
    }
  }
  cout << sum << endl;
}

  
  

Measured memory_bytes: 256