akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
#define INFTY 9000000000000000000
#define MAX 105
#define BLACK 2
#define WHITE 0
#define GRAY 1

long long n,M[105][105];
long long dijkstra(long long a,long long b){
    long long minv;
    long long d[MAX],color[MAX];
    for(int i=1; i<=n; i++){
        d[i]=INFTY;
        color[i]=WHITE;
    }
    d[a]=0;
    color[a]=GRAY;
    while(1){
        minv=INFTY;
        int u=-1;
        for(int i=1; i<=n; i++){
            if(minv>d[i]&&color[i]!=BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1) break;
        color[u]=BLACK;
        for(int v=1; v<=n; v++){
            if(color[v]!=BLACK&&M[u][v]!=INFTY){
                if(d[v]>d[u]+M[u][v]){
                    d[v]=d[u]+M[u][v];
                    color[v]=GRAY;
                }
            }
        }
    }
    if(d[b]==INFTY) return -1;
    else return d[b];
}
int main(){
    while(1){
        int k;
        cin>>n>>k;
        if(n==0&&k==0) break;
        for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) M[i][j]=INFTY;
        for(int i=0; i<k; i++){
            int whi;
            cin>>whi;
            if(whi==0){
                long long a,b,ans;
                cin>>a>>b;
                ans=dijkstra(a,b);
                cout<<ans<<endl;
            }else if(whi==1){
                long long c,d,e;
                cin>>c>>d>>e;
                M[c][d]=min(e,M[c][d]);
                M[d][c]=M[c][d];
            }
        }
    }
}

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

int N;
int A[210];

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];
    
    int res = 0;
    
    while (true) {
        bool exist_odd = false;
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;
        }
        
        if (exist_odd) break;

        for (int j = 0; j < N; ++j) {
            A[j] /= 2;
        }
        ++res;
    }
    
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<set>
using namespace std;
const int maxn=200005;
int sz[maxn];
int a[maxn];
int cvr[maxn],cntcvr=0;
int main(){
  int n,m;scanf("%d%d",&n,&m);
  for(int i=1;i<=n;++i)scanf("%d",a+i);
  for(int i=1;i<=n;++i){
    if(1<=a[i]-sz[a[i]]&&a[i]-sz[a[i]]<=n){
      cvr[a[i]-sz[a[i]]]++;
      if(cvr[a[i]-sz[a[i]]]==1)cntcvr++;
    }
    sz[a[i]]++;
  }
  int x,y;
  while(m--){
    scanf("%d%d",&x,&y);
    sz[a[x]]--;
    if(1<=a[x]-sz[a[x]]&&a[x]-sz[a[x]]<=n){
      cvr[a[x]-sz[a[x]]]--;
      if(cvr[a[x]-sz[a[x]]]==0)cntcvr--;
    }
    a[x]=y;
    if(1<=a[x]-sz[a[x]]&&a[x]-sz[a[x]]<=n){
      cvr[a[x]-sz[a[x]]]++;
      if(cvr[a[x]-sz[a[x]]]==1)cntcvr++;
    }
    sz[a[x]]++;
    printf("%d\n",n-cntcvr);
  }
  return 0;
}


Measured memory_bytes: 3712
S = str(input())
if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)

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

int main() {
  int N;
  cin >> N;
  vector<int> a(3*N);
  for(int i=0;i<3*N;i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  long long result = 0;
  for(int i=0;i<N;i++){
    result += a.at(2*i + 1);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	set<int> mys;
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; i++) mys.insert(i + 1);

	for(int i = 0; i < k; i++) {
		int sz;
		cin >> sz;
		while(sz--) {
			int inp;
			cin >> inp;
			mys.erase(inp);
		}
	}
	cout << mys.size() << '\n';
}




Measured memory_bytes: 3688
import math

def getPrimeFactorsDict(num):
  pn = 2 #素数は2から
  pfdict = {} #素因数のリスト
  while pn * pn <= num: #√numまで調べる
    while num % pn == 0: #現在の素数で割り切れる範囲でループ
      num = num / pn
      pfdict[pn] = pfdict.get(pn, 0) + 1
    pn += 1 #割り切れなくなったら次の素数へ
  if num > 1:
    pfdict[int(num)] = pfdict.get(int(num), 0) + 1
    
  return pfdict


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

d = getPrimeFactorsDict(M)

ans = 1
for key in d.keys():

  if d[key] == 1:
    ans *= N
  else:
    ans *= math.factorial(N+d[key]-1) // (math.factorial(N-1) *  math.factorial(d[key]))

  
print(ans % (10**9+7))

Measured memory_bytes: 4400
n,k = map(int,input().split())

if k%2==1:
    num=0
    for i in range(1,n+1):
        if i%k==0:
            num+=1
    print(num**3)
else:
    num1=0
    num2=0
    for i in range(1,n+1):
        if i%k==0:
            num1+=1
        elif i%k==int(k/2):
            num2+=1
    print(num1**3+num2**3)

Measured memory_bytes: 39024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;

bool statusCheck(vector<int> status, int X)
{
    int M = status.size() - 1;

    for (int i = 1; i <= M; i++)
    {
        if (status[i] < X)
        {
            return false;
        }
    }

    return true;
}

void Main() {
    // input
    int N, M, X;
    cin >> N >> M >> X;
    vector<vector<int>> books(N+1);

    // 添字に注意, -1 をしなくていいようにしている
    for (int i = 1; i <= N; i++) {
        int C;
        cin >> C;
        books[i].push_back(C); 
        for (int j= 1; j <= M; j++) {
            int A;
            cin >> A;
            books[i].push_back(A);
        }
    }

    // translate
    int ans = INT32_MAX;
    

    // 2^12 なら総当りで間に合う
    int LOOP_NUM = 1 << N; //2^12
    for (int i = 0; i < LOOP_NUM; i++) {
        vector<int> status(M + 1); // status[0] は書籍代

        for (int j = 1; j <= N; j++) {
            if (i & (1 << (j-1))) {
                for (int k = 0; k <= M; k++) {
                    status[k] += books[j][k];
                }
            }
        }
        
        if(statusCheck(status, X)) {
            ans = min(ans, status[0]);
        }
        
    }

    // output
    if (ans == INT32_MAX) {
        ans = -1;
    }
    cout << ans << endl;

}



int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3568
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=2050;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	int node[60]={};
	int N,M;
	cin>>N>>M;
	for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		node[a]++,node[b]++;
	}
	for(int i=1;i<=N;i++){
		cout<<node[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	string s;
  	cin >> s;
  	for(int i=0; i<s.size(); i+=2){
		cout << s.at(i);
    }
  	cout << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int A, B, K;
    cin >> A >> B >> K;

    vector<int> v;

    for(int i = 1; i <= min(A, B); i++) {
        if(A % i == 0 && B % i == 0) {
            v.push_back(i);
        }
    }

    sort(v.begin(), v.end(), greater<int>());

    cout << v[K - 1] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll a,b;
    if(n%1000==0)cout<<"0"<<endl;
    else
    {
        a=n/1000;
        b=(a+1)*1000;
        cout<<b-n<<endl;
    }
}


Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
int a;
  scanf("%d",&a);
if(a<10) printf("%d",a);
else if(a<100) printf("9");
else if(a<1000) printf("%d",a-90);
else if(a<10000) printf("909");
else if(a<100000) printf("%d",a-9090);
else printf("90909");
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;



const int N = (int) 1e5;
int l[N];

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n;
    scanf("%d", &n);
    n *= 2;
    for (int i = 0; i < n; i++)
        scanf("%d", &l[i]);
    sort(l, l + n);
    reverse(l, l + n);

    int ans = 0;
    for (int i = 0; i < n; i += 2)
    {
        ans += l[i + 1];
    }
    printf("%d\n", ans);


	return 0;
}




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

using namespace std;

typedef long long ll;
int n , m ;



typedef complex<double> point ;

point points[2000];


#define X real()
#define Y imag()
#define angle(a)                (atan2((a).imag(), (a).real()))
#define vec(a,b)                ((b)-(a))
#define same(p1,p2)             (dp(vec(p1,p2),vec(p1,p2)) < EPS)
#define dp(a,b)                 ( (conj(a)*(b)).real() )	// a*b cos(T), if zero -> prep
#define cp(a,b)                 ( (conj(a)*(b)).imag() )	// a*b sin(T), if zero -> parllel
#define length(a)               (hypot((a).imag(), (a).real()))
#define normalize(a)            (a)/length(a)
#define rotateO(p,ang)          ((p)*exp(point(0,ang)))
#define rotateA(p,ang,about)  (rotateO(vec(about,p),ang)+about)
#define reflectO(v,m)  (conj((v)/(m))*(m))


struct event {

  double a ;
  int type ;
  event(double a , int type) : a(a) , type(type) {}

  bool operator < (const event& op) const{

    if(op.a != a) return a < op.a ;
    return type < op.type ;
  }

};

bool check(double r){

  int maxn = 0 ;
  for(int i = 0 ; i < n ; i ++ ) {
    vector<event> angles ;
    point& a = points[i];
    int s = 1 ;
    for(int j = 0; j < n ; j ++) {
      if( i == j ) continue ;
      point& b = points[j];

      double d = length(vec(b,a));
      if(d > 2 * r ) continue;
      double teta = angle(vec(b,a));
      double alpha = acos(d/(2.0 *r));

      angles.emplace_back(teta - alpha , 0);
      angles.emplace_back(teta + alpha , 1);
    }

    sort(angles.begin() , angles.end());
    for(auto ev : angles){
      if(ev.type == 0 ) s ++ ;
      else s-- ;
      maxn = max(maxn , s);
    }

  }
  return maxn >= m ;
}

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

  cin >> n;
  m = n;
  for(int i = 0 ; i < n ; i ++) {
    double x , y;
    cin >> x >> y;
    points[i] = point(x,y);
  }
  double l = 0 , r = 2e3 + 10 ;

  double ans =  -1 ;
  for(int  i =  0 ; i < 100 ; i++) {
    double mid = (l + r ) / 2;

    if(check(mid)){
      r = mid ;
      ans = mid ;
    }else {
      l = mid ;
    }

  }

  cout << setprecision(8) << fixed <<  ans << endl ;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<<a[0]+a[1]<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());

        bool ans = false;

        foreach(var x in  Enumerable.Range(0, 100).Select(n => n * 7).TakeWhile(n => n <= N))
        {
            if ((N - x) % 4 == 0)
            {
                ans = true;
            }
        }


        Console.WriteLine(ans ? "Yes": "No");

    }
}



static class MathUtil
{
    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(vector<LL>& a, vector<LL>& b) {
	return a[0] < b[0];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;

int main() {
	LL n;
	cin >> n;
	vector<LL> v(3 * n, 0);
	REP(i, n * 3) {
		cin >> v[i];
	}
	SORT(v);
	LL sum = 0;
	REP(i, n) {
		sum += v[n + 2 * i];
	}
	cout << sum << endl;
}


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    private int N;
    private int[]a;
    private void Scan()
    {
        N=int.Parse(Console.ReadLine());
        
        var l=Console.ReadLine().Split(' ');
        a=new int[N];
        for(int i=0;i<N;i++)
        {
            a[i]=int.Parse(l[i]);
        }
        
    }
    public void Solve()
    {
        Scan();
        int[]cnt=new int[9];
        foreach(int i in a)
        {
            cnt[Math.Min(8,i/400)]++;
        }
        int col=0;
        for(int i=0;i<8;i++)
        {
            if(cnt[i]>0)
                col++;
        }
        int max=col+cnt[8];
        int min=col==0?1:col;
        Console.WriteLine($"{min} {max}");
    } 
    
    static void Main()
    {
        new Program().Solve();
    }
}

Measured memory_bytes: 13140
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int count = 0;
    int l = sc.nextInt();
    int r = sc.nextInt();
    int d = sc.nextInt();

    for(int i = l; i <= r; i++) {
      if(i%d == 0) count++;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 35620
a, b, c = map(int,input().split())
ans = 3
if a == b:
    ans = 2
    if a == c:
        ans = 1
if a == c:
    ans = 2
    if b == c:
        ans = 1
if c == b:
    ans = 2
    if a == c:
        ans = 1
print(ans)

Measured memory_bytes: 2940
#include<stdio.h>
#include<stdlib.h>
int main()
{
  int N,M;
  char **A;
  char **B;
  int flag=0;
  
  scanf("%d %d",&N,&M);
  A=(char**)malloc(sizeof(char*)*N);
  for(int i=0;i<N;i++){
    A[i]=(char*)malloc(sizeof(char)*N);
  }
  B=(char**)malloc(sizeof(char*)*M);
  for(int i=0;i<M;i++){
    B[i]=(char*)malloc(sizeof(char)*M);
  }
  for(int i=0;i<N;i++)
    scanf("%s",A[i]);
  for(int i=0;i<M;i++)
    scanf("%s",B[i]);
  
  for(int y=0;y<N;y++){
    for(int x=0;x<N;x++){
      if(y+M-1>=N||x+M-1>=N) continue;
      flag=1;
      
      for(int by=0;by<M;by++){
        for(int bx=0;bx<M;bx++){
          if(A[y+by][x+bx]!=B[by][bx]) flag=0;
          if(flag==0) break;
        }
        if(flag==0) break;
      }
      if(flag==1) break;
    }
    if(flag==1)break;
  }
  if(flag==1) printf("Yes");
  else printf("No");
  
  return 0;
}

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

using namespace std;

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector <int> a(n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &a[i]);
  vector <int> dp(n);
  for (int i = 1; i < n; ++i)
    dp[i] = (int)1e9 + 7;
  for (int i = 1; i < n; ++i) {
    for (int j = i - 1; j >= max(0, i - k); j--)
      dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
  }
  printf("%d", dp[n - 1]);
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<stdio.h>
#include<queue>
#include<map>
#include<stack>
using namespace std;
int dx[] = { -1,0,0,1,-1,-1,1,1,0 };
int dy[] = { 0,1,-1,0,1,-1,1,-1,0 };
/*
int main()
{
int r, c;
cin >> r >> c;
int sy, sx, gy, gx;
vector<vector<char>>field(r,vector<char>(c));
sy--, sx--, gy--, gx--;
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
cin >> field[i][j];
}
}
queue<pair<int,int>>q;
q.push({ sx,sy });
vector<vector<int>>d(c, vector<int> (r, -1));
d[sx][sy] = 0;

while (!q.empty())
{
pair<int, int>p = q.front;
q.pop();
for (int i = 0; i < 4; i++)
{
int nx = p.first + dx[i], ny = p.second + dy[i];
if (nx < 0 || ny < 0 || nx >= c || ny >= r || d[nx][ny] != -1 || field[nx][ny] == '#')continue;
q.push({ nx,ny });
d[nx][ny] = d[p.first][p.second] + 1;
}
}

cout << d[gx][gy] << endl;
}*/


int main()
{
	int  n, m, x;
	cin >> n >> m >> x;
	vector<int>a(m);
	for (int i = 0; i < m; i++)
	{
		cin >> a[i];
	}

	int ans1 = 0, ans2 = 0;

	for (int i = 0; i < m; i++)
	{
		if (a[i] < x)
		{
			ans1 += 1;
		}
		else
		{
			ans2 += 1;
		}
	}

	cout << min(ans1, ans2) << endl;
	


}



Measured memory_bytes: 3164
s=list(input().split())
a=int(s[0])
b=int(s[1])
if a==1:
  if b==1:
    print('Draw')
  else:
    print('Alice')
elif b==1:
  if a!=1:
    print('Bob')
else:
  if a-b>0:
    print('Alice')
  elif a-b<0:
    print('Bob')
  else:
    print('Draw')

Measured memory_bytes: 38384
N=int(input())
a=list(map(int,input().split()))

cnt=1
flag=False
renzoku=[]
for i in range(N):
    if i==N-1:
        renzoku.append(cnt)
    elif a[i]==a[i+1]:
        cnt+=1
    else:
        flag=False
        renzoku.append(cnt)
        cnt = 1

cnt=0
for i in renzoku:
    if i==1:
        continue
    else:
        cnt+=i//2

print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MAXN 200005
using namespace std;
typedef long long ll;
int n;
ll ans=10000000000000000;
ll a[MAXN];
ll b[MAXN];
ll c[MAXN];
int main()
{

    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%lld",a+i);
    for(int i=1;i<=n;++i)
    {
        b[i]=b[i-1]+a[i];
        c[n-i+1]=c[n-i+2]+a[n-i+1];
    }

    for(int i=1;i<=n-1;++i)
        ans=min(ans,abs(b[i]-c[i+1]));
    printf("%lld",ans);
}


Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>

using namespace std;
typedef long long ll;
typedef double db;
#define inf 0x3f3f3f3f

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main() {
	int n;
	cin >> n;
	string s;
	int a[5] = {};
	while (n--) {
		cin >> s;
		if (s[0] == 'A')++a[0];
		else if (s[0] == 'W')++a[1];
		else if (s[0] == 'T')++a[2];
		else if (s[0] == 'R')++a[3];
	}
	string sc[5] = { "AC","WA","TLE","RE" };
	for (int i = 0; i < 4; ++i) {
		cout << sc[i] << " " << "x" << " " << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

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

    int ss[24] = { 0 };

    for (const auto& c : s) { ++ss[c - 'A']; }

    bool ok = true;
    int count = 0;

    rep (i, 24)
    {
        if (!(ss[i] == 0 || ss[i] == 2)) { ok = false; }
        if (ss[i] == 2) { ++count; }
    }

    if (ok && count == 2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<climits>
#include<algorithm>
#include<numeric>
#include<iomanip>
#include<map>
#include<random>
#include<cassert>
using namespace std;
#define ll long long int
#define ld long double
const ll Mod = 1000000007;
ll CaseN=1;
const ld PI = 22/7.0;

bool mycmp(string s,string t)
{
if(s.size()<t.size())
{
return true;	
}		
return false;
}


void solve()
{
	ll a[4];
	cin>>a[0]>>a[1]>>a[2];
	bool ans=false;
	
	sort(a,a+3);
	if(a[0]==5 && a[1]==5 && a[2]==7)
	{
	ans = true;	
	}
	// cout<<"Case #"<<CaseN<<": ";
   CaseN++;
	// print your ans below;
     if(ans)
  {
  cout<<"YES"<<endl; 
  }
  else
   {
  cout<<"NO"<<endl;
  }
 
    
return ;
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
	solve();	
	}
}


Measured memory_bytes: 256
from math import gcd as gcd
a, b, c, d = map(int,input().split())
#cでわれるもの
s = gcd(c, d)
p = c * d // s
divide_c = b // c - (a - 1) // c
divide_d = b // d - (a - 1) // d
divide_cd = b // p - (a - 1) // p
print(int(b - a + 1 - divide_c - divide_d + divide_cd))

Measured memory_bytes: 9188
//ios::sync_with_stdio
#include<iostream>
#include<algorithm>
int ans[1001];
int num[1001];

int main(){
	int n, m;
	while (std::cin >> n >> m){
		if (n == 0)break;
		for (int i = 0; i < n; ++i){
			for (int j = 0; j < m; ++j){
				int a;
				std::cin >> a;
				ans[j] += a;
			}
		}
		//std::sort(num, num + m);
		int max = 0;
		int a = 1;
		while (a <= m){
			max = 0;
			for (int j = 0; j < m; ++j){
				max = std::max(ans[j], max);
			}
			for (int i = 0; i < m; ++i){
				if (ans[i] == max){
					std::cout << i + 1;
					ans[i] = 0;
					if (a < m)std::cout << " ";
					a++;
				}
			}
		}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
#define INF 1000000000000
#define EPS 0.00000000001
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    int h,w;
    cin>>h>>w;
    int n;
    cin>>n;
    vector<pair<int,int>> a(n);
    rep(i,n){
        cin>>a[i].first;
        a[i].second=i+1;
    }
    sort(all(a));
    vector<int> x(w);
    int c=0;
    int memo=0;
    rep(i,n){
        rep(j,a[i].first){
            x[c]=a[i].second;
            c++;
            if(c==w){
                c=0;
                if(memo%2==1){
                    reverse(all(x));
                }
                rep(k,w){
                    cout<<x[k]<<" ";
                }
                cout<<endl;
                memo++;
            }
        }
    }
    

    
}



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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

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

#define maxn 300005

/*
     *os.find_by_order(k) -> returns the k'th smallest element (indexing starts from 0)
      os.order_of_key(v)  -> returns how many elements are strictly smaller than v
*/

int col[205] ;
char s[205][205] ;

int main()
{
    int n ;
    scanf("%d",&n) ;

    for(int i=1 ; i<=n ; i++) scanf("%s",s[i]+1) ;

    queue<int> q ;

    memset(col,-1,sizeof(col)) ;

    col[1] = 1 ;
    q.push(1) ;

    while( !q.empty() )
    {
        int u = q.front() ;
        q.pop() ;
        for(int v=1 ; v<=n ; v++)
        {
            if( s[u][v]=='0' ) continue ;
            if( col[v]==col[u] )
            {
                printf("-1\n") ;
                return 0 ;
            }
            if( col[v]==-1 ) q.push(v) ;
            col[v] = (col[u]^1) ;
        }
    }

    int dis[205][205] ;

    for(int i=1 ; i<=n ; i++)
    {
        for(int j=1 ; j<=n ; j++)
        {
            dis[i][j] = n*10 ;
            if( s[i][j]=='1' ) dis[i][j] = 1 ;
        }
        dis[i][i] = 0 ;
    }

    for(int k=1 ; k<=n ; k++)
    {
        for(int i=1 ; i<=n ; i++)
        {
            for(int j=1 ; j<=n ; j++)
            {
                dis[i][j] = min( dis[i][j] , dis[i][k]+dis[k][j] ) ;
            }
        }
    }

    int mx = 0 ;

    for(int i=1 ; i<=n ; i++)
    {
        for(int j=1 ; j<=n ; j++) mx = max( mx , dis[i][j] ) ;
    }

    printf("%d\n",mx+1) ;

    return 0 ;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll N, D, X;
  cin >> N >> D >> X;
  ll answer = X;
  for(int i=0;i<N;i++){
    ll A;
    cin >> A;
    answer += (D-1) / A + 1;
  }
  cout << answer << endl;
  return 0;
}

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

int N, K, A[100009], S;

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> A[i]; if (A[i] == 1) S = i;
	}
	cout << (N - 1 + K - 2) / (K - 1) << endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 4
#define LIM 46
#define O 0
#define I 1

int ans[N][N]={{I,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,O}};
int x[N*N]={3,O,I,2,3,O,I,2,3,O,I,2,3,O,I,2},
    y[N*N]={3,O,O,O,O,I,I,I,I,2,2,2,2,3,3,3};
int Min=LIM;



void dfs(int p[N][N],int pr[N][N],int n)
{
  int i,j,i0,j0,d=O,f=O,t[N][N];
  for(i=O;i<N;i++){
    for(j=O;j<N;j++){
      if(ans[i][j]!=p[i][j]){
	f++;
      }
      if(p[i][j]==O){
	i0 = i;
	j0 = j;
      }
      else{
	d+=abs(j-x[p[i][j]])+abs(i-y[p[i][j]]);
      }
    }
  }
  if(f==O){
      if(Min>n){
	  Min=n;
      }
      return;
    }
  if(d+n>Min){
    return;
  }
  if(i0>O && i0<N){
      memcpy(t,p,sizeof(int)*N*N );
      f=t[i0][j0];
      t[i0][j0]=t[i0-I][j0];
      t[i0-I][j0]=f;
      if(memcmp(t,pr,sizeof(int)*N*N)!=O)
	dfs(t,p,n+I);
    }
  if(j0>O && j0<N){
      memcpy(t,p,sizeof(int)*N*N);
      f=t[i0][j0];
      t[i0][j0]=t[i0][j0-I];
      t[i0][j0-I]=f;
      if(memcmp(t,pr,sizeof(int)*N*N)!=O){
	dfs(t,p,n+I);
      }
  }
    if(i0>=O && i0<N-I){
        memcpy(t,p,sizeof(int)*N*N);
        f=t[i0][j0];
        t[i0][j0]=t[i0+I][j0];
        t[i0+I][j0]=f;
        if(memcmp(t,pr,sizeof(int)*N*N)!=O)
            dfs(t,p,n+I);
    }
    if(j0>=O && j0<N-I){
        memcpy(t,p,sizeof(int)*N*N);
        f=t[i0][j0];
        t[i0][j0]=t[i0][j0+I];
        t[i0][j0+I]=f;
        if(memcmp(t,pr,sizeof(int)*N*N)!=O)
            dfs(t,p,n+I);
    }
}

int main(){
  int i,j,p[N][N];

    for(i=O;i<N;i++){
        for(j=O;j<N;j++){
            scanf("%d",&p[i][j]);
        }
    }
    dfs(p,p,O);
    printf("%d\n",Min);
    return O;
}



Measured memory_bytes: 2096
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000;

typedef long long ll;
typedef unsigned long long ull;

ull powMod(ull x, ull n) {
  if (n == 0) return 1;
  if (n == 1) return x;
  ull tmp = powMod(x, n / 2);
  if (n % 2 == 0) return (tmp * tmp) % MOD;
  return ((ull)2) * (tmp * tmp) % MOD;
}

int main(void) {
  string s;
  cin >> s;
  int n = s.length();

  int ans = 0;
  int c[300] = {};
  rep(i, n) {
    if (c[i] == 1) break;
    if (s[i] != s[n - 1 - i]) ans++;
    c[n - 1 - i]++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
         
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007  
const int N = 100001; 



void solve(){
	int n;cin>>n;
	if(n>=30)cout<<"Yes";
	else cout<<"No";
    return;
}
         
signed main(){
        IOS;    
        

        int t=1;
        // cin>>t;
        // fac[0] = 1; 
        // for (int i=1 ; i<=2000001; i++) fac[i] = fac[i-1]*i%mod; 
        rep(i,0,t){
            solve();
            cout<<"\n";
        //   cout<<" * "<<t<<"\n";
        }
    //    return 0;
}

Measured memory_bytes: 3636
import numpy as np
N = int(input())
M = np.zeros((N, 3), dtype='int32')
for i in range(N):
    M[i, 0:3] = list(map(int, input().split()))
H = np.zeros((N, 3), dtype='int32')
H[N - 1, 0] = M[N - 1, 0]
H[N - 1, 1] = M[N - 1, 1]
H[N - 1, 2] = M[N - 1, 2]
for i in range(1, N):
    current_index = N - 1 - i
    H[current_index, 0] = max(M[current_index, 0] +
                              H[current_index + 1, 1], M[current_index, 0] + H[current_index + 1, 2])
    H[current_index, 1] = max(M[current_index, 1] +
                              H[current_index + 1, 0], M[current_index, 1] + H[current_index + 1, 2])
    H[current_index, 2] = max(M[current_index, 2] +
                              H[current_index + 1, 0], M[current_index, 2] + H[current_index + 1, 1])
print(max(H[0, :]))


Measured memory_bytes: 16220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    set<char> st;
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        char c; cin >> c;
        st.insert(c);
    }
    
    if (st.size() == 3) {
        cout << "Three" << endl;
    }
    if (st.size() == 4) {
        cout << "Four" << endl;
    }
    return 0;
}

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

int main(){
    while(1){
        int n,x;
        cin >> n >> x;
        if(n==0) break;
        
        int count=0;
        for(int i=1; i<=n; i++){
            for(int j=i+1; j<=n; j++){
                for(int k=j+1; k<=n; k++){
                    if(i+j+k==x) count++;
                }
            }
        }
        cout << count << endl;
    }
    return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H, N;
    cin >> H >> N;
    int sum = 0, temp;
    for (int i = 0; i < N; ++i) {
        cin >> temp;
        sum += temp;
    }
    if (sum >= H)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <list>
#include <math.h>
#include <map>
using namespace std;
#define REP(i, k, n) for(int i = k;i < n; i++)
#define rep(i, n) REP(i,0,n)
#define ll long long int
int dx[4] = {0,-1,1,0};
int dy[4] = {-1,0,0,1};
#define eps 10e-6
#define mod 1000000007
int main(void){
	ll a,b,c,k;
	cin >> a >> b >> c >> k;
	if(a <= b){
		if(k%2 == 0){
			cout << a - b << endl;
		}else{
			cout << b - a << endl;
		}
	}else{
		if(k%2 == 0){
			cout << a - b << endl;
		}else{
			cout << b - a << endl;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
int main()
{
	int num[101]={},a;
	while(cin>>a)num[a]++;
	int m=0;
	queue<int> que;
	for(int i=1;i<=100;i++){
		if(num[i]>m){
			m=num[i];
			while(!que.empty())que.pop();
			que.push(i);
		}else if(num[i]==m){
			que.push(i);
		}
	}
	while(!que.empty()){
		cout<<que.front()<<endl;
		que.pop();
	}
    return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void)
{ long x;
  long double a,b,c,a1,b1,c1,a2,b2,c2,d,e,f,g,i,k;
  scanf("%Lf %Lf %Lf %Lf",&a1,&b1,&c1,&k);
    d=a1-b1;
    f=pow(10,18);
      if(fabsl(d)<=f){
        x=powl(-1,k)*d;
        printf("%ld",x);
      }
        else
        printf("Unfair");
    return(0);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < (n); i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REPEACH(itr, k) for (auto &&itr : k)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;


const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int n,k;
    cin >> n >> k;
    ll ans=0;
    ll j=0;
    for(int i=k+1;i<=n;i++){
        ans+=(n/i)*(i-k);
        int tmp=n%i;
        ans+=max(0,tmp-k+1);
        if(k==0){
            ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans=1
bool=True
for i in range(n):
    if a[i]==0:
        bool=False
for i in range(n):
    ans*=a[i]
    if ans>pow(10,18):
        ans=-1
        break
if bool:
    print(ans)
else:
    print(0)

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

int main() {
  int A, B;
  cin >> A >> B;
  if (B == 1) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 1, cur = A;
  while (cur < B) {
    cur += A - 1;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
int ans1[200'000],ans2[200'000];
signed main(){
    int n,k,c;
    string s;
    cin>>n>>k>>c>>s;
    for(int i=0;i<n;i++)
        ans1[i]=ans2[i]=-1;
    int cnt=0,cnt2=0;
    for(int i=0;i<n;i++){
        if(cnt2==0&&cnt<k&&s[i]=='o'){
            ans1[i]=cnt;
            cnt++;
            cnt2=c+1;
        }
        if(cnt2!=0)
            cnt2--;
    }
    cnt=0,cnt2=0;
    for(int i=n-1;i>=0;i--){
        if(cnt2==0&&cnt<k&&s[i]=='o'){
            ans2[i]=k-1-cnt;
            cnt++;
            cnt2=c+1;
        }
        if(cnt2!=0)
            cnt2--;
    }
    for(int i=0;i<n;i++)
        if(ans1[i]==ans2[i]&&ans1[i]!=-1)
            cout<<i+1<<endl;
}


Measured memory_bytes: 4996
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int n;
  int max = -1;
  stringstream ss;
  cin >> n;
  int sum = 0;
  for(int i=0;i<n;i++){
    int po;
    cin >> po;
    if(po>max) max = po;
    sum += po;
  }
  cout << sum - max/2 << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
p_list = list(map(int, input().split()))

min_num = 10000000
ret = 0

for i in range(n):
    if p_list[i] < min_num:
        min_num = p_list[i]
        ret = ret + 1

print(ret)


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

ll a[maxn],n,k,ans=0;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		a[i%k]++;
	ans=a[0]*a[0]*a[0];
	if(~k&1)
		ans+=a[k/2]*a[k/2]*a[k/2];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
int main(){ 
   int a,b;
   cin>>a>>b;
   int count=0;
   for(int i=a;i<=b;i++){
      string c=to_string(i);
      int flag=1;
      for(int j=0;j<2;j++){
         if(c[j]!=c[4-j]) flag=0;
      }
      if(flag==1) count++;
   }
   cout<<count;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstring>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0; i<(int)n; i++)
#define all(c) c.begin(), c.end()

map<int, int> compress(vector<int>& from){
    map<int, int> f;
    sort(all(from));
    from.erase(unique(all(from)), from.end());
    int cur = 0;
    for (int i = (from[0] == 0 ? 1 : 0); i < from.size(); i++){
        if (from[i] == cur + 1)cur++;
        else cur += 2;
        f[from[i]] = cur;
    }
    return f;
}

int w, h;
bool in(int x, int y){
    return 0 <= x&&x < w && 0 <= y&&y < h;
}

bool mask[2000][2000];

void dfs(int x, int y){
    typedef pair<int, int> P;
    stack<P> s;
    s.push(P(x, y));
    const int dx[] = { 1, -1, 0, 0 };
    const int dy[] = { 0, 0, 1, -1 };
    while (s.size()){
        auto p = s.top();
        s.pop();
        if (!in(p.first, p.second) || mask[p.second][p.first] == 1) continue;
        mask[p.second][p.first] = 1;
        rep(i, 4){
            int xx = p.first + dx[i];
            int yy = p.second + dy[i];
            s.push(P(xx, yy));
        }
    }
    /*
        if (!in(x, y) || mask[y][x] == 1) return;
        mask[y][x] = 1;
        const int dx[] = { 0, 0, 1, -1 };
        const int dy[] = { 1, -1, 0, 0 };
        rep(i, 4){
        int xx = x + dx[i];
        int yy = y + dy[i];
        if (in(xx, yy) && mask[yy][xx] == 0) dfs(xx, yy);
        }*/
}

int main(){
    while (1){
        cin >> w >> h;
        if (w == 0 && h == 0) break;
        int n; cin >> n;
        vector<int> x1(n), y1(n), x2(n), y2(n);
        vector<int> ax(n + n + 2), ay(n + n + 2);
        rep(i, n){
            cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
            ax[i + i] = x1[i]; ax[i + i + 1] = x2[i];
            ay[i + i] = y1[i]; ay[i + i + 1] = y2[i];
        }
        ax.push_back(0); ax.push_back(w);
        ay.push_back(0); ay.push_back(h);
        auto fx = compress(ax);
        auto fy = compress(ay);
        w = fx[w];
        h = fy[h];
        rep(i, n){
            x1[i] = fx[x1[i]];
            x2[i] = fx[x2[i]];
            y1[i] = fy[y1[i]];
            y2[i] = fy[y2[i]];
        }
        memset(mask, 0, sizeof(mask));
        rep(i, n){
            for (int x = x1[i]; x < x2[i]; x++){
                for (int y = y1[i]; y < y2[i]; y++){
                    mask[y][x] = 1;
                }
            }
        }
        int ans = 0;
        rep(x, w){
            rep(y, h){
                if (mask[y][x] == 0){
                    ans++;
                    dfs(x, y);
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 13532
#include <iostream>
#include <cstdio>
#include <cctype>

using namespace std;

int main(){
	char ch;
	
	while(1){
		scanf("%c", &ch);
		
		if(islower(ch)) ch = toupper(ch);
		else if(isupper(ch)) ch = tolower(ch);
		printf("%c", ch);
		if( ch == '\n') break;
	}
	
	return 0;
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin>>a;
	string b=a;
	reverse(a.begin(),a.end());
	for(int i=0;i<a.size();++i)
	{
		if(a[i]=='b') a[i]='d';
		else if(a[i]=='d') a[i]='b';
		else if(a[i]=='p') a[i]='q';
		else if(a[i]=='q') a[i]='p';
	}
	if(a==b) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
#define data data1
// std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// int myRand(int R) {
// 	int val=rng() % R;
//       assert(val>=0);
//       return val;
// }
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=3e18;
const int32_t LOG=21;
const int MOD=MOD1;

int cnt[100005];

int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      { 
           int n;
           cin>>n;
           int a[n];
           int sum=0;
           rep(i,0,n)
           {
                 cin>>a[i];
                 cnt[a[i]]++;
                 sum+=a[i];
           }
           int q;
           cin>>q;
           rep(i,0,q)
           {
                 int x,y;
                 cin>>x>>y;
                 cnt[y]+=cnt[x];
                 sum-=(cnt[x]*x);
                 sum+=(cnt[x]*y);
                 cnt[x]=0;
                 cout<<sum<<endl;
           }
                      
      }      
      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

Measured memory_bytes: 5212
sx, sy, tx, ty = [int(i) for i in input().split()]

dx = tx - sx
dy = ty - sy

ans = 'U' * dy + 'R' * dx
ans += 'D' * dy + 'L' * dx
ans += 'L' + 'U' * (dy+1) + 'R' * (dx+1) + 'D'
ans += 'R' + 'D' * (dy+1) + 'L' * (dx+1) + 'U'

print(ans)

Measured memory_bytes: 3060
#coding:utf-8
 
 
def main():
    list1  = list(map(int, input().split(' '))) 
    a, b, k = list1
  
    if a > k:
        a = a - k
      
    elif a + b >= k:
        b = b - (k - a)
        a = 0
        
    else:
        a = 0
        b = 0
        
    print(a, b)
  
    return 0
 
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define maxn 2000000
using namespace std;
char s[maxn];
int n;
int main() {
	scanf("%s",s);
	n=strlen(s);
	for(int i=0;i<n;i++) if(s[i]=='?') s[i]='D';
	printf("%s",s);
	return 0;
}


Measured memory_bytes: 3944
// MatrixVectorMultiplocation.cc
// n × mの行列 A と、m × 1 の列ベクトルb を読み込み、Aとb の積を
// 出力するプログラムを作成してください。
//
// m個の数を縦に並べたものを m × 1の列ベクトルと呼びます。
// n個の数を含む列ベクトルを m個横に並べたものを n × m の行列と呼びます。
//
// ベクトルまたは行列の中に含まれる数のことを要素と呼び、m×1の列ベクトル b の上から
// i番目の要素は bi(i=1,2,...,m)、n×mの行列 Aには n×m個の要素が含まれ、
// i行 j列目の要素は aij(i=1,2,...,n,j=1,2,...,m)で示されます。
//
// n×mの行列 Aとm×1の列ベクトル bの積は、n×1の列ベクトル cとなり、
// cの i番目の要素 ci は次の式で得られます：
//
// ci = Σj=1,m aij bj = ai1b1 + ai2b2 + … + aimbm
// 【入力】
// １行目に nと mが空白区切りで与えられます。
// 続く n行に行列 Aの要素 aijが空白区切りで与えられます。
// 続く m行にベクトル bの要素 biがそれぞれ１行に与えられます。
// 【出力】
// 出力は n行からなります。ベクトル cの要素 ci をそれぞれ１行に出力してください。
// 【制約】
// ・1≤n,m≤100
// ・0≤bi,aij≤1000
// 【例】
// 入力：
// 3 4
// 1 2 0 1
// 0 3 0 1
// 4 1 1 0
// 1
// 2
// 3
// 0
// 出力：
// 5
// 6
// 9
#include<iostream>
using namespace std;

int main( void) {
  int n, m;
  int A[100][100] = {};
  int b[100] = {};
  int c[100] = {};

  // 行列データを読み込む
  cin >> n >> m;
  for ( int i = 0; i < n; i++) {
    for ( int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }

  for ( int j = 0; j < m; j++) {
    cin >> b[j];
  }

  // Aとbの積を計算する。
  for ( int i = 0; i < n; i++) {
    for ( int j = 0; j < m; j++) {
      c[i] += A[i][j] * b[j];
    }
  }

  // 結果を出力する。
  for ( int i = 0; i < n; i++) {
    cout << c[i] << endl;
  }
}



Measured memory_bytes: 3160
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

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

			if (word.length() < 26) {
				for (char c = 'a'; c <= 'z'; c++) {
					if (word.indexOf(c) >= 0) {
						continue;
					}

					System.out.println(word + c);
					return;
				}
			}

			Set<Character> set = new TreeSet<>();
			set.add(word.charAt(word.length() - 1));
			for (int i = word.length() - 2; i >= 0; i--) {
				char check = word.charAt(i);
				for (Character val : set) {
					if (check < val) {
						System.out.println(word.substring(0, i) + val);
						return;
					}
				}
				set.add(check);
			}

			System.out.println(-1);
		}
	}
}


Measured memory_bytes: 23764
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($N,$M) =  explode(" ",trim(fgets(STDIN)));
//$A = explode(" ",trim(fgets(STDIN)));

if ($N<="2019/04/30") {
  printf("Heisei\n");
}
else {
  printf("TBD\n");
}


Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
int ans;
int main(){
    int N,K,X,Y;
    cin>>N>>K>>X>>Y;
    for(int i=1;i<=N;i++){
        if(i<=K)ans+=X;
        else ans+=Y;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
S = input()
S += "UUU"
humiyasui = True
for i in range(0,len(S)-1,2):
    if S[i] == "L":
        humiyasui = False
    if S[i+1] == "R":
        humiyasui = False

if humiyasui:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#define MN 500
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
bool B[MN+5][MN+5];
int n,m,a,b,num1,num2;
int main()
{
	n=read();m=read();a=read();b=read();num1=n*m;
	for(int i=a;i<=n;i+=a)
		for(int j=b;j<=m;j+=b)
			B[i][j]=1,--num1,++num2;
	//ax+b(-(a*b-1)*x-1)
	
	if(num1-num2*(a*b-1)<=0)  return 0*puts("No");
	else puts("Yes");
	int l=1,r=1e9,mid,res=-1;
	while(l<=r)
	{
		int mid=l+r>>1;
		if(-1LL*(a*b-1)*mid-1<-1e9) r=mid-1;
		else if(1LL*num1*mid+1LL*num2*(-(a*b-1)*mid-1)<=0) l=mid+1;
		else res=mid,r=mid-1;
	}
	for(int i=1;i<=n;++i,puts("")) for(int j=1;j<=m;++j) printf("%d ",B[i][j]?-res*(a*b-1)-1:res);
	return 0;
}



Measured memory_bytes: 1536