akhauriyash/Code-Regression huggingface dataset:
n=int(input())
s=[int(x) for x in list(input())]
ans=0
for a in range(10):
  for i in range(n):
    if s[i]==a:
      a_dx=i
      break
  else:
    continue
  for b in range(10):
    for i in range(a_dx+1,n):
      if s[i]==b:
        b_dx=i
        break
    else:
      continue
    for c in range(10):
      for i in range(b_dx+1,n):
        if s[i]==c:
          ans+=1
          break
      else:
        continue

print(ans)

Measured memory_bytes: 75184
from collections import defaultdict

n = int(input())
nums = [int(i) for i in input().split()]

d = defaultdict(int)
for num in nums:
    d[num] += 1

all_sum = 0
diff_d = {}
for num, freq in d.items():
    # 一回しか出てきてなければ0がたされる
    all_sum += freq * (freq-1) // 2
    # tmp = (freq - 1) * (freq - 2) // 2
    tmp = freq - 1
    diff_d[num] = tmp

for num in nums:
    print(all_sum - diff_d[num])


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

n = int(input()) * 2
D = []

for i in range(2, int(n**0.5) + 1):
    d = 1
    while n%i == 0:
        n //= i
        d *= i
    if d != 1:
        D.append(d)
    if n == 1:
        break
if n != 1:
    D.append(n)
# print(D)

# 拡張Euclidの互除法。ap + bq = gcd(a, b) となる p, q, d=gcd(a, b) を返す。
def extgcd(a, b):
    if b == 0:
        return 1, 0, a
    q, p, d = extgcd(b, a%b)
    q -= (a // b) * p
    return p, q, d

def crt(R, M):  # 中国剰余定理。Rは余り、Mは割る数の配列。不定なら(0,1)、不能なら(0,0)が返る。
    r = 0
    m = 1
    for i in range(len(R)):
        p, _, d = extgcd(m, M[i])
        if (R[i] - r) % d != 0:
            return (0, 0)
        tmp = (R[i] - r) // d * p % (M[i] // d)
        r += m * tmp
        m *= M[i] // d
    return (r % m, m)


ans = float("inf")

# Rs = []

for i in range(1, 2**len(D)):
    ib = format(i, "b").zfill(len(D))
    R = [0] * len(D)
    for j in range(len(D)):
        if ib[j] == "1":
            R[j] = D[j]-1
    ans = min(ans, crt(R, D)[0])
print(ans)

Measured memory_bytes: 76272
#include<stdio.h>
int main(){
int a,b,c;
while(scanf("%d %d %d\n",&a,&b,&c)!=EOF){
if(a<1868){
printf("pre-meiji\n");
}
else if(a==1868 && b<9){
printf("pre-meiji\n");
}
else if(a==1868 && b==9 && c<8){
printf("pre-meiji\n");
}
else if(a<1912){
printf("meiji %d %d %d\n",a-1867,b,c);
}
else if(a==1912 && b<7){
printf("meiji %d %d %d\n",a-1867,b,c);
}
else if(a==1912 && b==7 && c<30){
printf("meiji %d %d %d\n",a-1867,b,c);
}
else if(a<1926){
printf("taisho %d %d %d\n",a-1911,b,c);
}
else if(a==1926 && b<12){
printf("taisho %d %d %d\n",a-1911,b,c);
}
else if(a==1926 && b==12 && c<25){
printf("taisho %d %d %d\n",a-1911,b,c);
}
else if(a<1989){
printf("showa %d %d %d\n",a-1925,b,c);
}
else if(a==1989 && b<1){
printf("showa %d %d %d\n",a-1925,b,c);
}
else if(a==1989 && b==1 && c<8){
printf("showa %d %d %d\n",a-1925,b,c);
}
else{
printf("heisei %d %d %d\n",a-1988,b,c);
}
}
return 0;
}


Measured memory_bytes: 2064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> b;
int main() {
  cin >> n;
  read_n(b, n - 1);
  i64 ans = b[0] + b[n - 2];
  for (i64 i = 1; i < n - 1; ++i) {
    ans += min(b[i - 1], b[i]);
  }
  cout << ans << endl;
  return 0;
}

//2 2 5
// 2 5


Measured memory_bytes: 256
S = list(map(int, input()))
ans1 = 0
ans2 = 0
for i in range (len(S)):
  if i % 2 == 0 and S[i] == 0:
      ans1 += 1
  elif i %2 ==1 and S[i] == 1:
      ans1 += 1
for i in range(len(S)):
  if i % 2 == 0 and S[i] == 1:
      ans2 += 1
  elif i % 2 ==1 and S[i] == 0:
      ans2 += 1
print(min(ans1, ans2))



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

using namespace std;  

typedef long long ll;

bool judge(ll k, int n, int a, int b, vector<int> h) {
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    ll t = (ll)h[i] - k*b;
    if (t > 0) {
      sum += (t+a-b-1) / (a-b);
      if (sum > k) { return false; }
    }
  }
  return true;
}
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, a, b;
  cin >> n >> a >> b;

  vector<int> h(n);

  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  ll low = 0, high = (ll)1e9;

  while (low < high) {
    ll mid = (low + high) / 2;
    if (judge(mid, n, a, b, h)) {
      high = mid;
    } else {
      low = mid+1;
    }
  }

  cout << low << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define rep(x,n) for( x; i < n; x++)



int main() {
	int N, X;
	cin >> N >> X;
	int i =0;
	i = X - (N - 1);

	rep(i, X + (N)) {
		if (i > 1000000 || i < -1000000) {
			continue;
		}
		cout << i << " ";

	}
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e11;
int H,W,K;
char cake[301][301];
int ans[301][301];
int main(){
    cin >> H >> W >> K;
    char a;
    rep(i,H) rep(j,W){
        cin >> a;
        cake[i][j] = a;
    }
    int l=0,r=0,h=1,paint=1;
    rep(i,H){
        rep(j,W){
            r++;
            ans[i][j] = paint;
            if (cake[i][j] == '#'){
                paint++;
                l = j+1;
            }
            if (r == W){
                if (l < W){
                    FOR(k,l,r) ans[i][k] = paint-1;
                }
            }
        }
        if (l == 0){
            if (i == H-1){
                rep(k,h) rep(j,W){
                    ans[i-h+k+1][j] = ans[i-h][j];
                }
                break;
            }
            h++;
        }
        else if(h > 1){
            rep(k,h) rep(j,W){
                ans[i+1-h+k][j] = ans[i][j];
            }
            h = 1;
        }
        l = 0;
        r = 0;
    }
    rep(i,H){
        rep(j,W){
            if (j < W-1) cout << ans[i][j] << ' ';
            else cout << ans[i][j];
        }
        if (i < H-1) cout << '\n';
    }
}

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

using namespace std;

int f(int n){
    int ans = 0;
    while (n > 0){
        ans += n % 10;
        n /= 10;
    }
    return ans;
}

int main() {
    int n;
    cin >> n;
    int x = f(n);
    if (n % x == 0)
        puts("Yes");
    else
        puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
typedef long long ll;
const ll mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<deque<int>> A(N + 1, deque<int>());
    for (int i: irange(1, N + 1)) {
        for (int j: irange(0, N - 1)) {
            int val;
            cin >> val;
            A[i].push_back(val);
        }
    }

    vector<int> day(N + 1, 1);
    int empty_queues = 0;
    while (empty_queues < N) {
        bool matched = false;
        for (int i: irange(1, N + 1)) {
            int competitor = A[i].front();
            if (A[competitor].front() == i) {
                matched = true;
                A[i].pop_front();
                A[competitor].pop_front();
                int date = max(day[i], day[competitor]) + 1;
                day[i] = date;
                day[competitor] = date;
                if (A[i].empty()) {
                    empty_queues++;
                }
                if (A[competitor].empty()) {
                    empty_queues++;
                }
            }
        }
        if (!matched) {
            cout << -1 << endl;
            exit(0);
        }
    }
    int ans = 0;
    for (int i: irange(1, N + 1)) {
        ans = max(ans, day[i]);
    }
    cout << ans - 1 << endl;
}

Measured memory_bytes: 4736
#include <stdio.h>
int main(){
  int len;
  int count = 0;
  char S[200];
  scanf("%d%s",&len,S);
  if(len & 1 == 1)printf("No");
  else{
    for(int i = 0;i<len/2;i++){
      if(S[i] == S[len/2+i])count++;
    }
      if(count == len/2)printf("Yes");
      else printf("No");
  }
}

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

int main()
{
    int b, f, r, v, n;
    cin >> n;
    vector<vector<int>> build1(3, vector<int>(10, 0));
    vector<vector<int>> build2(3, vector<int>(10, 0));
    vector<vector<int>> build3(3, vector<int>(10, 0));
    vector<vector<int>> build4(3, vector<int>(10, 0));

    for (int i = 0; i < n; i++) {
        cin >> b >> f >> r >> v;
        if (b == 1) build1.at(f - 1).at(r - 1) += v;
        if (b == 2) build2.at(f - 1).at(r - 1) += v;
        if (b == 3) build3.at(f - 1).at(r - 1) += v;
        if (b == 4) build4.at(f - 1).at(r - 1) += v;
    }

    for (int i = 0; i < build1.size(); i++) {
        for (int j = 0; j < build1.at(0).size(); j++) {
            cout << " " << build1.at(i).at(j);
        }
        cout << "\n";
    }
    cout << "####################" << endl;

    for (int i = 0; i < build2.size(); i++) {
        for (int j = 0; j < build2.at(0).size(); j++) {
            cout << " " << build2.at(i).at(j);
        }
        cout << "\n";
    }
    cout << "####################" << endl;

    for (int i = 0; i < build3.size(); i++) {
        for (int j = 0; j < build3.at(0).size(); j++) {
            cout << " " << build3.at(i).at(j);
        }
        cout << "\n";
    }
    cout << "####################" << endl;
    ;

    for (int i = 0; i < build4.size(); i++) {
        for (int j = 0; j < build4.at(0).size(); j++) {
            cout << " " << build4.at(i).at(j);
        }
        cout << "\n";
    }
}


Measured memory_bytes: 3088
#include <iostream>

struct Vec {
    double x;
    double y;

    double operator*(Vec& vec)
    {
        return (x * vec.y - y * vec.x);
    }
};

int sgn(double x);

int main()
{
    double x1, y1, x2, y2, x3, y3, x4, y4;
    char ch;

    while (std::cin >> x1 >> ch >> y1 >> ch >> x2 >> ch >> y2 >> ch
                    >> x3 >> ch >> y3 >> ch >> x4 >> ch >> y4) {
        Vec vec12{x2 - x1, y2 - y1};
        Vec vec23{x3 - x2, y3 - y2};
        Vec vec34{x4 - x3, y4 - y3};
        Vec vec41{x1 - x4, y1 - y4};

        double cross01 = vec12 * vec23;
        double cross02 = vec23 * vec34;
        double cross03 = vec34 * vec41;
        double cross04 = vec41 * vec12;
        int judge = sgn(cross01) + sgn(cross02) + sgn(cross03) + sgn(cross04);

        if (judge == 1 + 1 + 1 + 1 || judge == -1 - 1 - 1 - 1) {
            std::cout << "YES" << std::endl;
        } else {
            std::cout << "NO" << std::endl;
        }
    }

    return 0;
}

int sgn(double x)
{
    return ((x >= 0)? 1: (-1));
}

Measured memory_bytes: 1220
#                          JAI SHREE RAM

import math; from collections import *
import sys; from functools import reduce

# sys.setrecursionlimit(10**6)
def get_ints(): return map(int, input().strip().split())
def get_list(): return list(get_ints())
def get_string(): return list(input().strip().split())
def printxsp(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")

UGLYMOD = int(1e9)+7; SEXYMOD = 998244353; MAXN = int(1e5)
import copy
# sys.stdin=open("input.txt","r");sys.stdout=open("output.txt","w")

# for _testcases_ in range(int(input())):
r, c, k = get_ints()
matr = []
for i in range(r):
    matr.append(list(input()))
ans = 0
for i in range(2**r):
    for j in range(2**c):
        matrc = copy.deepcopy(matr)
        ii = bin(i)[2:].zfill(r)
        for indu in range(r):
            if ii[indu] == '1':
                matrc[indu] = ['r'] * c
        jj = bin(j)[2:].zfill(c)
        for indu in range(c):
            if jj[indu] == '1':
                for jks in range(r):
                    matrc[jks][indu] = 'r'
        temp = 0
        for ud in range(r):
            for it in range(c):
                if matrc[ud][it] == '#':
                    temp += 1
        if temp == k:
            ans += 1
        # print(ii, jj)
        # for irctc in matrc:
        #     print(*irctc)
print(ans)
        


'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA )
Link may be copy-pasted here if it's taken from other source.
DO NOT PLAGIARISE.
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

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

using namespace std;

// rep
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define rep(i,n) REP(i,0,n)

void division(string const &raw, string &left, string &right) {
  
  int const N = raw.size();
  int retain = 0;
  REP(pos, 1, N) {
    if(raw[pos] == '(') retain++;
    else if(raw[pos] == ')') retain--;
    else if(retain == 0) {
      //assert(raw[pos] == ',');
      left  = raw.substr(1, pos-1);
      right = raw.substr(pos+1, N-pos-2);
      break;
    }
  }
  
}

string solve(char op, string const &s, string const &t) {
  if(s.empty() || t.empty()) {
    if(op == 'i') return min(s, t);
    else return max(s, t);
  }
  
  string sL, sR, tL, tR;
  division(s, sL, sR);
  division(t, tL, tR);
  
  return '(' + solve(op, sL, tL) + ',' + solve(op, sR, tR) + ')';
}

int main() {
  
  char op; string s, t;
  while(cin >> op >> s >> t) {
    cout << solve(op, s, t) << endl;
  }
  
  return 0;
}

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

int main(){
  int n,ansc[100]={},o=0,hr=0,h=0,o2=0;
  string event;
  cin>>n;
  int i=0;
  int j=0;
  while(1){
    cin>>event;
    if(event=="OUT"){
      o++;
      o2++;
    }
    if(event=="HIT")h++;
    if(event=="HOMERUN")hr++;

    if(o2==3*n)break;

    if(h==4){
      ansc[j]++;
      h--;
    }
    else if(o==3){
      o=0;
      h=0;
      hr=0;
      j++;
    }
    else if(hr==1){
      ansc[j]+=h+1;
      h=0;
      hr=0;
    }
    i++;
  }
  for(int j=0;j<n;j++)
  cout<<ansc[j]<<endl;
  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF = 2e9
#define LINF = 1e18
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << "=" << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO")
#define Yes(n) cout << ((n) ? "Yes" : "No")
#define PI 3.141592653589793

int main(){

    int n;
    cin >> n;
    vector<int> p(n);
    int maxi = 0;
    rep(i,n){
        cin >> p[i];
        if(p[maxi] < p[i])maxi = i;
    }

    int ans = 0;
    rep(i,n){
        ans += (i != maxi ? p[i] : p[i]/2);
    }

    cout << ans << endl;

}

Measured memory_bytes: 3596
import numpy as np
N,W=map(int,input().split())
Weight=[]
Value=[]

for i in range(N):
  w,v = map(int,input().split())
  Weight += [w]
  Value += [v]
  
DP = np.zeros(W+1, dtype=int)

for i in range(N):
  DP[Weight[i]:]=np.maximum(DP[:-Weight[i]]+Value[i],DP[Weight[i]:])
  #print(DP)
print(DP[-1])

Measured memory_bytes: 15496
import sys
import math as m
input = sys.stdin.buffer.readline

def main():
    n=int(input())
    d=[[[None]*n for i in range(n)]for j in range(n)]
    ans=0

    for i in range(n):
        for j in range(i,n):
            ij=m.gcd(i+1,j+1)
            for k in range(j,n):
                d[i][j][k]=m.gcd(ij,k+1)
    #print(d)

    for i in range(n):
        for j in range(n):
            for k in range(n):
                #print(ans,i,j,k)
                if i<=j and j<=k:
                    ans+=d[i][j][k]
                elif i<=k and k<=j:
                    ans+=d[i][k][j]
                elif j<=i and i<=k:
                    ans+=d[j][i][k]
                elif j<=k and k<=i:
                    ans+=d[j][k][i]
                elif k<=i and i<=j:
                    ans+=d[k][i][j]
                elif k<=j and j<=i:
                    ans+=d[k][j][i]
    print(ans)

main()

Measured memory_bytes: 74880
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
 	Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    if (n % 2 == 0)
      System.out.println(n/2);
   	else
      System.out.println((n+1)/2);
  }
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

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

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int ans = min(B, D)-max(A, C);

    if (ans < 0) {
        cout << 0 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

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


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

  int max=100;
  int sum=0;
  for(int i=0;i<n;i++){
    int p;
   cin>>p;
    if(p>max)max=p;
    sum+=p;
  }
   cout<<sum-max/2<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        double ans = 0.0;
        for (int j = 1; j <= n; j++) {
            double tmp = 1.0 / (double)n;
            int i = j;
            while(i < k) {
                i *= 2;
                tmp /= 2.0;
            }
            ans += tmp;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35856
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    cin >> S;
    for(int i=0; i<S.size(); i++){
        S[i] = (S[i] - 'A'- 3 + 26)%26 + 'A';
    }
    cout << S << enld;
    return 0;
}



Measured memory_bytes: 3236
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    ll n; cin >> n;
    ll ans = n+2;
    for(ll i = 1LL; i*i <= n; ++i){
        if(n%i == 0) ans = min(ans, n/i + i - 2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 21

string data[10] = {
  "",
  ".,!? ",
  "abc",
  "def",
  "ghi",
  "jkl",
  "mno",
  "pqrs",
  "tuv",
  "wxyz",
}; 


void calc(){
  string s,ans;
  vector<pair<int,int> > vec;
  
  cin >> s;

  int last = -1;
  for(int i=0;i<s.size();i++){
    if(i>0 && s[i-1]!='0' && s[i]=='0') vec.push_back({i,i-(last+1)});
    if(s[i]=='0') last = i;
  }
  
  for(int i=0;i<vec.size();i++){
    ans += data[s[vec[i].first-1]-'0'][(vec[i].second-1)%(int)(data[s[vec[i].first-1]-'0'].size())];
  }
    
  cout << ans << endl;
  
  return;
}

int main(){
  int n;

  scanf("%d",&n);
  
  for(int i=0;i<n;i++){
    calc();
  }

  return 0;
}

Measured memory_bytes: 3096
A, B, K = map(int, input().split())
cnt = 0
while True:
    if A % 2:
        A -= 1
    B += A//2
    A //= 2
    cnt += 1
    if cnt == K:
        break
    if B % 2:
        B -= 1
    A += B//2
    B //= 2
    cnt += 1
    if cnt == K:
        break

print(A, B)


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

int main(){
	int N;
	cin >> N;
	int A[N];
	long long total = 0;
	for(int a = 0; a < N; a++){
		cin >> A[a];
		total += A[a];
	}
	long long cnt[100001];
	memset(cnt, 0, sizeof(cnt));
	for(int a = 0; a < N; a++)
		cnt[A[a]]++;
	int Q;
	cin >> Q;
	for(int a = 0; a < Q; a++){
		int B, C;
		cin >> B >> C;
		total -= cnt[B] * B;
		total += cnt[B] * C;
		cnt[C] += cnt[B];
		cnt[B] = 0;
		cout << total << endl;
	}
}

Measured memory_bytes: 4792
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 

const long long mod=1e9+7;

long long calc(long long a,long long b,long long c,long long d){

	if(b<c || d<a) return 0;
	else if(a<=c && d<=b) return d-c+1;
	else if(c<=a && b<=d) return b-a+1;
	else if(c<=a && a<=d) return d-a+1;
	else if(a<=c && c<=d) return b-c+1; 

}

int main(){

	int n;
	cin>>n;

	vector<long long> a(n),t(n);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	} 
	for(int i=0;i<n;i++){
		scanf("%lld",&t[n-1-i]);
	} 

	vector<long long> mi1(n),ma1(n);
	mi1[0]=ma1[0]=a[0];
	long long x=a[0],y=a[0];
	for(int i=1;i<n;i++){
		if(a[i]>a[i-1]) mi1[i]=ma1[i]=a[i],y=a[i];
		else mi1[i]=1,ma1[i]=y;
	}

	vector<long long> mi2(n),ma2(n);
	mi2[0]=ma2[0]=t[0];
	x=t[0],y=t[0];
	for(int i=1;i<n;i++){
		if(t[i]>t[i-1]) mi2[i]=ma2[i]=t[i],y=t[i];
		else mi2[i]=1,ma2[i]=y;
	}
	reverse(mi2.begin(),mi2.end());
	reverse(ma2.begin(),ma2.end());

/*
	for(int i=0;i<n;i++) cout<<mi1[i]<<" ";
	cout<<endl;
	for(int i=0;i<n;i++) cout<<ma1[i]<<" ";
	cout<<endl;
	cout<<endl;
	for(int i=0;i<n;i++) cout<<mi2[i]<<" ";
	cout<<endl;
	for(int i=0;i<n;i++) cout<<ma2[i]<<" ";
	cout<<endl;
*/
	long long res=1;
	for(int i=0;i<n;i++){
		res=(res*calc(mi1[i],ma1[i],mi2[i],ma2[i]))%mod;
	}
	cout<<res<<endl;

}

Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.length();
  int ans[20] = { 0 };
  int cnt = 0;
  
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') {
      ans[cnt]++;
    }
    else cnt++;
  }
  sort(ans, ans+20, greater<>());
  cout << ans[0] << endl;
}

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

int main()
{
    int n,m;
    cin >> n >> m;
    int c,d;
    if( n != 1 && m != 1 )
    {
       c = n*(n-1) / 2;
       d = m*(m-1) / 2;
    }
    else if( n == 1 && m == 1 )
    {
       c = 0;
       d = 0;
    }    
    else if( n == 1 )
    {
        c = 0;
        d = m*(m-1) / 2;
    }
    else if( m == 1 )
    {
        c = n*(n-1) / 2;
        d = 0;
    }

    cout << int(c + d) << endl;
    return 0;
}



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

int main(void){

  int n;
  scanf("%d", &n);
  char w[n][11];
  for (int i = 0; i < n; i++) {
    scanf("%s", w[i]);
  }
  int length;
  for (int i = 1; i < n; i++) {
    length = strlen(w[i-1]);
    if (w[i][0] != w[i-1][length-1]) {
      printf("No\n");
      return 0;
    }
    for (int j = 0; j < i; j++) {
      if (strcmp(w[j],w[i]) == 0) {
        printf("No\n");
        return 0;
      }
    }
  }
  printf("Yes\n");

  return 0;
}

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

typedef long long int ll;

int main()
{
    ll a, b, ans = 0;
    cin >> a >> b;
    for(ll i = a;i <= b;i++){
        string s;
        s = to_string(i);
        bool f = true;
        for(ll i = 0;i < 2;i++){
            if(s[i] != s[4 - i]){
                f = false;
            }
        }
        if(f){
            ans++;
        }

    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cstring>
#include <cstdio>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e3+5;
int n, m, a, b; char s[N][N];
int main()
{
    n = read(), m = read(), a = read(), b = read();
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            s[i][j] = '.';
    if(n&1) for(int i = 1; i < m&&a; i += 2) --a, s[n][i] = '<', s[n][i+1] = '>';
    if(m&1) for(int i = 1; i < n&&b; i += 2) --b, s[i][m] = '^', s[i+1][m] = 'v';
    for(int i = 1; i < n; i += 2)
        for(int j = 1; j < m; j += 2)
            if(a >= 2) a -= 2, s[i][j] = s[i+1][j] = '<', s[i][j+1] = s[i+1][j+1] = '>';
            else if(b >= 2) b -= 2, s[i][j] = s[i][j+1] = '^', s[i+1][j] = s[i+1][j+1] = 'v';
            else if(a&&b&&i == n-2&&j == m-2) 
                --a, --b,
                s[i][j] = '<', s[i][j+1] = '>', s[i][j+2] = '^', 
                s[i+1][j] = '^', s[i+1][j+2] = 'v',
                s[i+2][j] = 'v', s[i+2][j+1] = '<', s[i+2][j+2] = '>';
            else if(a)  --a, s[i][j] = '<', s[i][j+1] = '>';
            else if(b) --b, s[i][j] = '^', s[i+1][j] = 'v';
    if(a||b) return puts("NO"), 0;
    puts("YES"); for(int i = 1; i <= n; ++i) puts(s[i]+1);
    return 0;
}

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

MOD = 10**9+7
MAX = max(n, m)+2
fact = [0]*(MAX)
fact[0] = 1
for i in range(1, MAX):
  fact[i] = (fact[i-1]*i)%MOD

if abs(n-m)>1:
  ans = 0
else:
  if n==m:
    ans = fact[n]*fact[m]*2%MOD
  else:
    ans = fact[n]*fact[m]%MOD
print(ans)

Measured memory_bytes: 6900
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
  ll a, b, c, d;
  scanf("%ld %lld %lld %lld", &a, &b, &c, &d);
  printf("%lld\n", max(a * b, c * d));
  return 0;
}


Measured memory_bytes: 256
#EDPC-O Matching
"""
bit DP
集合Sを、(s>>i)&1==1とした時,i番目の女性はマッチング済であるとし、男をループさせる。
dp[i] = 集合iから始めた場合の数(既にi状態のマッチングが終わっている場合の数)
"""
import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
n = int(readline())
mens = []
for i in range(n):
    s = readline().rstrip().decode('utf-8')
    s = "".join(s.split(" "))
    res = int(s,2)
    mens.append(res)

dp = [-1 for _ in range(1<<n)]
dp[-1] = 1 #全マッチングが終わった時、+1する為
def rec(s,v): #使用済みの集合、今の深さ
    if dp[s] != -1: #既に確定しているなら
        return dp[s]
    res = 0
    for u in range(n): #それぞれの女性について
        #その女性がマッチング済でないかつ、vと相性がいいなら
        if s>>u&1==0 and mens[v]>>u&1==1:
            res += rec(s|(1<<u),v+1)
    dp[s] = res%mod
    return dp[s]
        
print(rec(0,0))

Measured memory_bytes: 123528
#include <iostream>
#include<vector>
#include<utility>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
typedef long long ll;

using namespace std;



int main() {
    int D;
    cin>>D;
    vector<int>c(27);
    rrep(i,26)cin>>c[i];
    vector<vector<int>>s(D+1,vector<int>(27));
    rrep(d,D){
        rrep(i,26)cin>>s[d][i];
    }
    vector<vector<int>>last(D+1,vector<int>(27));
    vector<int>C(D+1);
    vector<int>v(D+1);
    vector<int>t(D+1);
    vector<int>S(D+1);
    rrep(d,D){
        pair<int,int> ans = make_pair(-2e9,0);
        rrep(T,26){
            C[d] = 0;
            last[d][T] = d;
            rrep(i,26){
                C[d] += c[i]*(d-last[d][i]);
            }
            v[d] = S[d-1]+s[d][T]-C[d];
            ans = max(ans, pair<int,int>(v[d],T));
            if(ans != pair<int,int>(v[d],T))last[d][T]=last[d-1][T];
            S[d] = ans.first;
        }
        t[d] = ans.second;
    }
    rrep(d,D){
        cout<<t[d]<<endl;
    }

    return 0;
}

Measured memory_bytes: 3712
while True:
    x=int(input())
    if x==0:
        break
    y=1000-x;
    a=y%500
    b=a%100
    c=b%50
    d=c%10
    e=d%5
    z=y//500+a//100+b//50+c//10+d//5+e
    print(z)


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

#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

int h,w,ch,cw,dh,dw;

const int N = 1005;
char a[N][N];
ll dis[N][N];

void djikstra()
{
	dis[ch][cw]=0;
	set<pair<pll,ll>> s;
	s.insert({{ch,cw},0});
	while(!s.empty())
	{
		auto x = *s.begin();
		s.erase(s.begin());
		auto p=x.F;
		for(int i=p.F-2;i<=p.F+2;++i)
		{
			for(int j=p.S-2;j<=p.S+2;++j)
			{
				if(i==p.F && j==p.S)continue;
				if(i>=1 && i<=h && j>=1 && j<=w)
				{
					if(a[i][j]=='.' && dis[i][j]>x.S+1)
					{
						if(s.count({{i,j},dis[i][j]}))
						{
							s.erase({{i,j},dis[i][j]});
						}
						dis[i][j]=x.S+1;
						s.insert({{i,j},dis[i][j]});
					}
				}
				if(((i==p.F && abs(j-p.S)==1) || (j==p.S && abs(i-p.F)==1))  && a[i][j]=='.' && dis[i][j]>x.S)
				{
					if(s.count({{i,j},dis[i][j]}))
					{
						s.erase({{i,j},dis[i][j]});
					}
					dis[i][j]=x.S;
					s.insert({{i,j},dis[i][j]});	
				}
			}
		}
	}
}


int _runtimeTerror_()
{
	cin>>h>>w>>ch>>cw>>dh>>dw;
	for(int i=1;i<=h;++i)
	{
		for(int j=1;j<=w;++j)
		{
			cin>>a[i][j];
			dis[i][j]=INF;
		}
	}
	djikstra();
	cout<<(dis[dh][dw]==INF?-1:dis[dh][dw]);
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	return 0;
}

Measured memory_bytes: 12572
import java.util.*
import kotlin.math.abs

fun main() {
    var (n,k) = readLine()!!.split(" ").map { it.toInt() }
    val arr = readLine()!!.split(" ").map { it.toLong() }.toLongArray()
    val mod = (1e9+7).toLong()
    val po = arr.count { it >= 0 }
    val no = arr.size - po
    var ans = 1L

    if((po == 0 && k % 2 != 0) || k == n) {
        arr.sortDescending()
        for(i in 0 until k) {
            ans *= (mod + arr[i])
            ans %= mod
        }
    } else {
        val aa = arr.sortedByDescending { abs(it) }.toLongArray()
        var negCnt = 0

        for(i in 0 until k) {
            if(aa[i] < 0)
                negCnt++
        }

        if(negCnt % 2 != 0) {
            //swap
            var pi = -1
            var ni = -1
            var pii = -1
            var nii = -1
            var lastP = 0L
            var lastN = 0L
            var fstP = 0L
            var fstN = 0L

            for(i in k - 1 downTo 0) {
                if(aa[i] >= 0) {
                    lastP = aa[i]
                    pi = i
                    break
                }
            }

            for(i in k - 1 downTo 0) {
                if(aa[i] < 0) {
                    lastN = abs(aa[i])
                    ni = i
                    break
                }
            }
            for(i in k until n) {
                if(aa[i] >= 0) {
                    fstP = aa[i]
                    pii = i
                    break
                }
            }
            for(i in k until n) {
                if(aa[i] < 0) {
                    fstN = abs(aa[i])
                    nii = i
                    break
                }
            }
            val ad = fstP * lastP
            val bc = fstN * lastN

            // 음수가 전부 몰려있는 경우
            // 양수 전부에 음수 일부,
            if((ad > bc || nii == -1 || pi == -1) && (pii != -1 && ni != -1)) {
                // 음수를 양수로 바꿈.
                aa[ni] = aa[pii]
            } else {
                // 양수를 음수로 바꿈.
                aa[pi] = aa[nii]
            }

        }

        for(i in 0 until k) {
            ans *= (mod + aa[i])
            ans %= mod
        }


        // 음 -> 양
        // 양 -> 음
//        var poArr = arr.filter { it >= 0 }.sortedDescending()
//        val negArr = arr.filter { it < 0 }.sorted()
//        var pp = 0
//        var np = 0
//        var cnt = 0
//
//
//
//        if(k % 2 != 0) {
//            //poArr 에서 하나 뽑는다.
//            ans *= poArr[0]
//            poArr = poArr.subList(1, poArr.size)
//            k--
//        }
//
//        val pq = PriorityQueue<Long>(compareByDescending { it })
//
//        while ( poArr.size - pp >= 2) {
//            val v = (poArr[pp] * poArr[pp + 1]) % mod
//            pq.add(v)
//            pp+=2
//        }
//
//        while ( negArr.size - np >= 2) {
//            val v = (negArr[np] * negArr[np + 1]) % mod
//            pq.add(v)
//            np+=2
//        }
//
//        while(cnt * 2 < k) {
//            val v = pq.poll()
//            ans *= v
//            ans %= mod
//            ++cnt
//        }
    }
    print(ans)

}

Measured memory_bytes: 83100
/*
	 AOJ DSL_1
	 ??????????´??????????
	 2??????????´????????????????????±??????????????????¶=2??????????´??????????????????§??????
	 ?????????????????¨???father[]?????´??\?????§???????????§????????????find??¢??°??§??¢?´¢??????????????????
	 ??????????????????????????¨?????¨??????????????????
	 */
#include<iostream>
#include <string>
#define maxn 100100
using namespace std;
int n,q,m;
int father[maxn];

void init(){
	for(int i=0;i<n;i++)father[i]=i;
}

int find(int x){ // x?????????????????¢??°
	if(father[x]==x)return x; // ?????????????????????????????´??????x???????????????
	return father[x]=find(father[x]); // ??????????????§????????°??????????????????????????????(????????§?????????)
}

void unite(int x,int y){
	father[find(x)]=find(y); // x????????¨y????????????????????????
}

string same(int x,int y){
	if(find(x)==find(y))return "yes"; // ????????????????????????
	else return "no";
}

int main(void){
	cin>>n>>m;
	init();
	while(m--){
		int x,y;
		cin>>x>>y;
		unite(x,y);
	}
	cin>>q;
	while(q--){
		int x,y;
		cin>>x>>y;
		cout<<same(x,y)<<endl;
	}
	return 0;
}

Measured memory_bytes: 4140
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)

typedef long long ll;

int main(void) {
    int n;
    while (cin>>n && n){
        int sum=0 , h=0 , l=1000;
        REP(i,n){
            int s;
            cin >> s;
            sum+=s;
            h = max(h,s);
            l = min(l,s);
        }
        sum -= h+l;
        cout << sum/(n-2) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

using P = pair<int, int>;

vector<vector<int>> use;
int n, m, q;

void dfs(vector<int>& now) {
	if (now.size() == n) {
		use.pb(now);
		return ;
	}
	int las = now[now.size()-1];
	
	for (int i = las; i <= m; i++) {
		vector<int> vec = now;
		vec.pb(i);
		dfs(vec);
	}
}

int main() {

	cin >> n >> m >> q;
	int a[q], b[q], c[q], d[q];
	rep (i, q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}

	vector<int> e(1);
	for (int i = 1; i <= m; i++) {
		e[0] = i;
		dfs(e);
	}


	
	
	
	//cout << use.size() << endl;
	
	ll ans = 0;
	int szuse = use.size();
	rep (i, szuse) {
		ll sum = 0;
		rep (j, q) {
			if (use[i][b[j]] - use[i][a[j]] == c[j]) sum += d[j];
		}
		chmax(ans, sum);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 9856
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  cout << min(b/a,c) << endl;
}

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

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

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

long long stoi(string str) {
	long long ret;
	stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

ull gcd(ull a, ull b) {
	if (b > a)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a%b);
}
void solve() {
	int h, w;
	int n;
	int field[111][111];
	int x = 0, y = 0;
	int dirx = 1;
	cin >> h >> w;
	cin >> n;
	int ori = w - 1;
	rep(i, n) {
		int a;
		cin >> a;
		rep(j, a) {
			field[y][x] = i + 1;
			if (x == ori) {
				y++;
				dirx *= -1;
				ori ^= w - 1;
			}
			else {
				x += dirx;
			}
		}
	}
	rep(i, h) {
		rep(j, w) {
			cout << field[i][j];
			if (j != w) {
				cout << " ";
			}
		}
		cout << endl;
	}
}

int main() {
	solve();
	return 0;
}


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

string s, t;
int ans = 1e9;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> s >> t;

	for(int i=0;i<s.size()-t.size()+1;i++){
		int cnt = 0;
		for(int j=0;j<t.size();j++) if(s[i+j] != t[j]) cnt++;
		ans = min(ans, cnt);
	}
	cout << ans;
}

Measured memory_bytes: 3656
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

ll L, N;

ll calc(const V<ll> &X) {
    V<ll> lsum(N + 1), rsum(N + 1);
    for(ll i = 0; i < N; i++) lsum[i + 1] = lsum[i] + X[i];
    for(ll i = 0; i < N; i++) rsum[i + 1] = rsum[i] + (L - X[N - 1 - i]);

    ll ret = 0;
    for(ll i = 0; i <= N; i++) {
        ll val = (i ? X[i - 1] : 0);
        ll rest = N - i;
        if(rest) val *= 2;
        if(2 <= rest) val += rsum[rest / 2] * 2;
        if(rest % 2 == 1) val += (rsum[rest / 2 + 1] - rsum[rest / 2]);
        if(3 <= rest) val += (lsum[i + (rest - 1) / 2] - lsum[i]) * 2;
        if(rest && rest % 2 == 0) val += (lsum[rest / 2 + i] - lsum[rest / 2 + i - 1]);
        chmax(ret, val);
        DEBUG(make_tuple(i, val, lsum[i], rsum[rest/2]*2, rsum[rest/2+1]-rsum[rest/2], (lsum[i+(rest-1)/2]-lsum[i])*2, lsum[rest/2+i]-lsum[rest/2+i-1]));
    }

    return ret;
}

int main() {
    cin >> L >> N;
    V<ll> X(N);
    for(auto &&ele : X) cin >> ele;

    ll ans = calc(X);
    reverse(ALL(X));
    for(auto &&ele : X) ele = L - ele;
    chmax(ans, calc(X));

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


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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

lnt dp[2010][2010];

int main(){
    summon_tourist;

	lnt N, A[2000]; cin >> N;
    multimap<lnt, lnt, greater<lnt> > mp;
    REP(i, N) {
        cin >> A[i];
        mp.emplace(A[i], i);
    }
    REP(i, N+5) REP(j, N+5) dp[i][j] = -BBIG;
    dp[0][0] = 0;
    sort(A, A+N); reverse(A, A+N);
    auto itr = mp.begin();
    REP(i, N){
        lnt num = itr->first, idx = itr->second;
        // cerr << num << ' ' << idx << endl;
        REP(left, i+1){
            lnt right = i-left;
            chmax(dp[left+1][right], dp[left][right] + num*abs(idx-left));
            chmax(dp[left][right+1], dp[left][right] + num*abs(idx-(N-right-1)));
        }
        itr++;
    }
    lnt ans = 0;
    REP(i, N+1){
        chmax(ans, dp[i][N-i]);
    }
    cout << ans << ln;
}


Measured memory_bytes: 35276
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int n;
	cin >> n;
	cout << "ABC" << n << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n,m;
    int a[100][100]={0},b[100]={0},c[100]={0},i,j;
    
    scanf("%d %d",&n,&m);
    
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    
    for(i=0;i<m;i++){
        scanf("%d",&b[i]);
    }
    
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c[i] = c[i] + (a[i][j] * b[j]);
        }
        printf("%d\n",c[i]);
    }
    
    return 0;
}

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

string s,a,b;
int n,mid;

bool pal(string a)
{
    string b = a;
    reverse(b.begin(),b.end());
    if(b==a)
        return true;
    else
        return false;
}

int main()
{

        cin>>s;
        n = s.length();
        mid = n/2;
        a = s.substr(0,mid);
        b = s.substr(mid+1);

        if(pal(s) and pal(a) and pal(b))
            cout<<"Yes";
        else
            cout<<"No";
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, a, b = map(int, input().split())
    S = input()

    cnt = 0
    cnt_b = 0
    for s in S:
        if cnt < a + b:
            if s == "a":
                print("Yes")
                cnt += 1
            elif s == "b":
                if cnt_b < b:
                    print("Yes")
                    cnt += 1
                    cnt_b += 1
                else:
                    print("No")
            else:
                print("No")
        else:
            print("No")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 49112
x = gets
y = x.split(",")
a = y[0].to_i
b = y[1].to_i

scorebord = Hash.new
score = []
until a == 0 && b == 0
 scorebord[a.to_s] = b 
 score << b
 x = gets
 y = x.split(",")
 a = y[0].to_i
 b = y[1].to_i
end

score1 = score.sort.reverse
score2 = score1.uniq

nn = gets
until nn.nil?
 n = nn.chomp
 point = scorebord[n]
 indexnum = score2.index(point)
 puts indexnum + 1
 nn = gets
end


Measured memory_bytes: 6860
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        int N = ReadLineParseInt();
        int[] HPs = ReadLineParseIntArray();
        int ans = HPs[0];
        for(int i = 1; i < N; i++)
        {
            ans = (int)Gcd(ans, HPs[i]);
        }
        WriteLine(ans);
    }

    static int ReadLineParseInt() => int.Parse(ReadLine());
    static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray();
    static long Gcd(long n, long m)
    {
        if (n < m) return Gcd(m, n);
        while(m != 0)
        {
            long r = n % m;
            n = m;
            m = r;
        }
        return n;
    }
}

Measured memory_bytes: 21728