akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
 
using namespace std;
 
int main(){
  int A[3][3];  //ビンゴカード
  int N;        //何個の数字でビンゴやるか
  int b[10];    //当たりの数字を格納
  //Aにビンゴカードの値を入れていく
  for(int i = 0;i < 3;i++){
    for(int j = 0;j < 3;j++){
      cin >> A[i][j];
    }
  }
  
  cin >> N;
  
  for(int i = 0;i < N;i++){
    
    cin >> b[i];
    
    for(int j = 0;j < 3;j++){
      for(int k = 0;k < 3;k++){
        if(b[i] == A[j][k]){
          A[j][k] = 0;
        }
      }
    }
  }
 
  if(A[0][0] == A[0][1] && A[0][1] == A[0][2] && A[0][0] == 0){
    cout << "Yes";
  }else if(A[1][0] == A[1][1] && A[1][1] == A[1][2] && A[1][0] == 0){
    cout << "Yes";
  }else if(A[2][0] == A[2][1] && A[2][1] == A[2][2] && A[2][0] == 0){
    cout << "Yes";
  }else if(A[0][0] == A[1][0] && A[1][0] == A[2][0] && A[0][0] == 0){
    cout << "Yes";
  }else if(A[0][1] == A[1][1] && A[1][1] == A[2][1] && A[0][1] == 0){
    cout << "Yes";
  }else if(A[0][2] == A[1][2] && A[1][2] == A[2][2] && A[0][2] == 0){
    cout << "Yes";
  }else if(A[0][0] == A[1][1] && A[1][1] == A[2][2] && A[0][0] == 0){
    cout << "Yes";
  }else if(A[0][2] == A[1][1] && A[1][1] == A[2][0] && A[0][2] == 0){
    cout << "Yes";
  }else{
    cout << "No";
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

vvl G = VV(100001, 0, 0, ll);
int main(int argc, char const *argv[]) {
  ll n, m;std::cin >> n >> m;
  vll h(n+1);re(i, n) std::cin >> h[i+1];

  re(i, m){
    ll a, b;std::cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ll ans = 0;
  for(int i=1;i<=n;i++){
    bool f = true;
    for(auto to:G[i]){
      if(h[i]<=h[to]) f = false;
    }
    if(f) ans++;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 9480
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

int main() {
	int a, b, c;
	std::cin >> a >> b >> c;
	if (a <= c && c <= b) {
		std::cout << "Yes" << std::endl;
	} else {
		std::cout << "No" << std::endl;
	}
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(x) cout << x << endl;
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> vec;
    rep(i, n){
        int h; cin >> h;
        vec.push_back(h);
    }

    int ans = 0;
    int tmp = 0;
    rep(i, n - 1){
        if(vec[i] >= vec[i + 1]){
            tmp++;
            ans = max(ans, tmp);
        }else{
            tmp = 0;
        }
    }
    OP(ans);
}


Measured memory_bytes: 892
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		if (a == 1) {
			System.out.println("Hello World");
		}
		if (a == 2) {
			int b = sc.nextInt();
			int c = sc.nextInt();
			System.out.println(b + c);
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
	int n;
	vector<int> A;
	vector<int> B;
	cin >> n;

	for(int i=0;i<n;i++){
		int t;
		cin >> t;
		A.push_back(t);
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i!=j){
				B.push_back(abs(A[i]-A[j]));
			}
		}
	}
	sort(B.begin(),B.end());
	cout << B.back() << endl;
}

Measured memory_bytes: 384
# 2次元imos法

N,M,Q = map(int,input().split())
T = [ [ 0 for _ in range(N+2) ] for _ in range(N+2) ]
for i in range(M):
  L,R = map(int,input().split())
  T[0][R] += 1
  T[L+1][R] -= 1
  T[0][N+1] -= 1
  T[L+1][N+1] += 1
for i in range(N+1):
  for j in range(N+1):
    T[j+1][i] += T[j][i]
for j in range(N+1):
  for i in range(N+1):
    T[j][i+1] += T[j][i]
for i in range(Q):
  p,q = map(int,input().split())
  print(T[p][q])



Measured memory_bytes: 9460
a=list(input())
n=0
while n<len(a):
    oldn=n
    if a[n] == "e":
        if n+4<len(a) and a[n+1]=="r" and a[n+2]=="a" and a[n+3]=="s" and a[n+4]=="e":
            if n+5<len(a) and a[n+5]=="r":
                n=n+6
            else:
                n=n+5
    else:
        if a[n] == "d":
            if n+4<len(a) and a[n+1]=="r" and a[n+2]=="e" and a[n+3]=="a" and a[n+4]=="m":
                if n+6<len(a) and a[n+5]=="e" and a[n+6] == "r":
                    if n+7<len(a) and a[n+7]=="a":
                        n=n+5
                    else:
                        n=n+7
                else:
                    n=n+5
    if oldn == n:
        print("NO")
        break
else:
    print("YES")

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



Measured memory_bytes: 4780
#include <stdio.h>
int main(void) {
 
  int x,y,t;
  int i;
 
  while(1) {
  scanf("%d %d",&x,&y);
  if(x*y == 0) break;
 
  if(y >=x) {
    t = y;
    y = x;
    x = t;
  }
 
 
  i= 0;
  while(1) {
    i++;
    x = x % y;
 
    t =x;
    x = y;
    y = t;
 
    if(y == 0) break;
 
  }
 
  printf("%d %d\n",x,i);
 
  }
 
  return 0;
 
}



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

long long f[6005][6005<<1], mod, ans;
int n;

int main() {
	cin>>n>>mod;
	f[0][3*n] = 1;
	for(int i = 1; i <= 3*n; i++)
	    for(int j = -3*n; j <= 3*n; j++) {
	    	if(i)f[i][j + 3*n] += f[i - 1][j + 3*n - 1];
	    	if(i > 1)f[i][j + 3*n] += (i - 1)*f[i - 2][j + 1 + 3*n];
	    	if(i > 2)f[i][j + 3*n] += (i - 1)*(i - 2)*f[i - 3][j + 3*n];
	    	f[i][j + 3*n] %= mod;
	    }
	for(int i = 3*n; i <= 6*n; i++)
	    ans = (ans + f[3*n][i])%mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 563328
#include<bits/stdc++.h>
using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
#define PI 3.141592653589793
struct node{
    list <int> to;
};
  int main()
{
  int a[100010];
  int N,B,count=1,Count=0;
  cin>>N;

  for(int i=0;i<N;i++){
    cin>>B;
    a[i]=B;
  }
  sort(a,N+a);
  for(int i=0;i<N;i++){
    if(a[i]==a[i+1]){
      count++;
    }else{
      if(count%2!=0)Count++;
      count=1;
    }
  }
  cout<<Count;
  return 0;
}


Measured memory_bytes: 640
//----------ACCIDENTAL COMPETITIVE PROGRAMMER---------------------

#include<bits/stdc++.h>

/*
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
using namespace std;

#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair


const LL MOD = (1e9) + 7 ;
const LD EPS = 0.0000001 ;

struct node {
	string name;
	int idx;
	int p;
};

bool comp (const node a, const node b)
{
	if (a.name == b.name)
		return a.p  > b.p;
	else
		return a.name < b.name;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;

    node arr[n];
    for (int i = 0; i < n; i++){
    	cin >> arr[i].name >> arr[i].p;
    	arr[i].idx = i + 1;
    }

    sort(arr, arr + n, comp);
    for (int i = 0;  i < n; i++)
    	cout << arr[i].idx << endl;

	return 0;

}

Measured memory_bytes: 256
import math as mt
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
count, a = 0, 0
for i in range(n):
    for j in range(i + 1, n):
        for m in range(d):
            a += abs(x[i][m] - x[j][m]) ** 2
        if mt.sqrt(a).is_integer():
            count += 1
        a = 0
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2000 + 5;
int a[5] = {-1,-1,-1,-1,-1};
int main(){
	int n,m;
	cin >> n >> m;
	int flag = 0;
	for(int i = 1; i <= m; i++){
		int x,y;
		cin >> x >> y;
		if(x == 1 && y == 0 && n != 1)
			flag = 1;
		if(a[x] == -1){
			a[x] = y;
		}
		if(a[x] != -1){
			if(y != a[x])
				flag = 1;
		}
		if(x == 1 && y == 0 && n == 1 && flag == 0)
			flag = 2;
	}
	if(flag == 1)
		cout << -1 << endl;
	else if(flag == 2)
		cout << 0 << endl;
	else if(n == 1 && a[1] == -1)
		cout << 0 << endl;
	else{
		int z = 0;
		if(a[1] == -1)
			cout << 1;
		else
			cout << a[1];
		for(int i = 2; i <= n; i++){
			if(a[i] == -1)
				cout << 0;
			else
				cout << a[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
ans = 0
for i in range(1, n+1):
    if i >= k:
        ans += 1 / n
    else:
        p = 1 / n
        while (i < k):
            i *= 2
            p *= (0.5)
        ans += p
print(ans)

Measured memory_bytes: 2940
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

n = ni()
dp = [inf] * (n + 1)
dp[0] = 0

for i in range(n):
    j = 1
    while j <= i + 1:
        dp[i + 1] = min(dp[i + 1], dp[i - j + 1] + 1)
        j *= 6
    j = 1
    while j <= i + 1:
        dp[i + 1] = min(dp[i + 1], dp[i - j + 1] + 1)
        j *= 9

print(dp[n])

Measured memory_bytes: 42220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

int main(){
    string S;
    cin >> S;
    vll t;
    t.push_back(1);
    rep(i, SZ(S)-1){
        t.push_back(t[i] * 10 + pow(2, i));
    }
    rep(i, SZ(S)){
        t[i] *= pow(2, SZ(S)-i-1);
    }
    ll ans = 0;
    rep(i, SZ(S)){
        ans += t[SZ(S)-i-1] * (S[i] - '0');
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int h, w, k;
char a[800][800];
bool used[800][800];
bool ok(int x, int y){
    return 0<= x and x < h and 0 <= y and y < w;
}
int dist[800][800];
int dx[] = {-1,0,0,1};
int dy[] = {0,1,-1,0};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w >> k;
    queue<pii>q;
    rep(i,h)rep(j,w){
        cin >> a[i][j];
        if(a[i][j] == 'S'){
            q.emplace(i,j);
            used[i][j] = true;
            dist[i][j] = k;
        }
    }
    while(q.size()){
        auto p = q.front(); q.pop();
        int x = p.first;
        int y = p.second;
        if(dist[x][y] == 0)break;
        rep(i,4){
            int xx = x + dx[i];
            int yy = y + dy[i];
            if(!ok(xx,yy)){
                cout << 1 << endl;
                return 0;
            }
            if(used[xx][yy] or a[xx][yy] == '#')continue;
            dist[xx][yy] = dist[x][y] - 1;
            used[xx][y] = true;
            q.emplace(xx,yy);
        }
    }
    int ans = 1<<30;
    rep(i,h)rep(j,w){
        if(used[i][j]){
            ans = min({ans,(i+k-1)/k,(h-1-i+k-1)/k,(j+k-1)/k,(w-1-j+k-1)/k});
        }
    }
    cout << ans + 1 << endl;
}

Measured memory_bytes: 2304
N = int(input())
S = input()
lst = []
count = 0
for i in range(1000):
    num = str(i).zfill(3)
    if num[0] in S:
        a1 = S.index(num[0])
        if num[1] in S[a1+1:]:
            a2 = S[a1+1:].index(num[1]) + a1+1
            if num[2] in S[a2+1:]:
                count += 1
print(count)

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

constexpr int mod = 1e9 + 7;
constexpr int32_t inf = 1001001001;
constexpr int64_t infll = 1001001001001001001ll;
constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

// clang-format off
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }

template <typename T> void sort(vector<T> &v) { sort(all(v)); }
template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int n = in(), k = in();
  cout << (n + k - 3) / (k - 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int N, M, T;
string A[100], B[100];
vector<string> S;

int main(void){
	//IO("test.in", "test.out");
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> A[i];
		S.push_back(A[i]);
	}
	cin >> M;
	for(int i = 0; i < M; i++){
		cin >> B[i];
		S.push_back(B[i]);
	}
	for(int i = 0; i < S.size(); i++){
		int t = 0;
		for(int j = 0; j < N; j++)
			if(A[j] == S[i]) t++;
		for(int j = 0; j < M; j++)
			if(B[j] == S[i]) t--;
		if(t > T) T = t;
	}
	printf("%d\n", T);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	std::vector<int> a(n - 1), b(n - 1);
	std::vector<std::vector<int>> g(n);
	for(int i = 0; i < n - 1; i++) {
		scanf("%d%d", &a[i], &b[i]); a[i]--; b[i]--;

		if(b[i] < a[i]) g[a[i]].push_back(b[i]);
		if(a[i] < b[i]) g[b[i]].push_back(a[i]);
	}
	for(int i = 0; i < n; i++) {
		g[i].push_back(-1);
		
		sort(begin(g[i]), end(g[i]));
	}

	i64 ans = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 1; j < (int)g[i].size(); j++) {
			i64 time = g[i][j] - g[i][j - 1];
			i64 cnt  = -(g[i].size() - j - 1);
			ans += time * cnt * (n - i);
		}
		ans += (i64)(i - g[i].back()) * 1 * (n - i);
	}
	
	printf("%lld\n", ans);
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (auto &e : a) cin >> e.second >> e.first;
  sort(begin(a), end(a));
  bool r = true;
  int t = 0;
  for (auto e : a) {
    t += e.second;
    r &= t <= e.first;
    if (!r) break;
  }
  cout << (r ? "Yes" : "No") << endl;
}


Measured memory_bytes: 1792
import math
A, B, C, D, E, F = map(int, input().split())

def calc(a, b):
    if a == 0 or b == 0: return 0
    return 100 * b / (a + b)
ans = (0, 0)
tmp = 0
ret = set()
for i in range(3001):
    for j in range(3001):
        water = i * A * 100 + j * B * 100
        if 1 > water or water > F: break
        for k in range((F-water)//C+1):
            for l in range((F-water)//D+1):
                suger = k * C + l * D
                if water + suger > F: break
                if water * E // 100 < suger: break
                t = calc(water, suger)
                #ret.add((t, water+suger, suger))
                if tmp <= t:
                    tmp = t
                    ans = (water+suger, suger)

#ret = list(ret)
#ret.sort(reverse=True)
print(*ans)


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

int main(void){
    int a, b, k, n, i, j, ans=0;
    scanf("%d %d", &a, &b);
    if(a>=13) printf("%d", b);
    else if(a<=5) printf("0");
    else printf("%d", b/2);
    
}

Measured memory_bytes: 128
//----------------------------------------------------------------
//D

#include <iostream>
using namespace std;
const long long INF = 1LL<<60;

// 入力
int N;
long long W, weight[110], value[110]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[110][100100] = {0};

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {

            // i 番目の品物を選ぶ場合
            if (sum_w - weight[i] >= 0) {
                dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            // i 番目の品物を選ばない場合
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    // 最適値の出力
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 81836
l=[list(map(int,input().split())) for i in range(3)]
n=int(input())
ll=[int(input()) for i in range(n)]

#print("Yes") print("No")

lll=[]
for i in range(3):
    for j in range(3):
        if l[i][j] in ll:
            lll.append([i,j])

a=0
if [0,0] in lll and [0,1] in lll and [0,2] in lll:
    a+=1
if [1,0] in lll and [1,1] in lll and [1,2] in lll:
    a+=1
if [2,0] in lll and [2,1] in lll and [2,2] in lll:
    a+=1
if [0,0] in lll and [1,0] in lll and [2,0] in lll:
    a+=1
if [0,1] in lll and [1,1] in lll and [2,1] in lll:
    a+=1
if [0,2] in lll and [1,2] in lll and [2,2] in lll:
    a+=1
if [0,0] in lll and [1,1] in lll and [2,2] in lll:
    a+=1
if [0,2] in lll and [1,1] in lll and [0,2] in lll:
    a+=1

if a==0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 38384
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

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

char S[100];

int main() {

	scanf("%s", S);

	int C = 0;
	rep(i, strlen(S)) {
		if (S[i] == 'x') C++;
	}

	if (C < 8) printf("YES\n");
	else printf("NO\n");

	return 0;
}


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

using namespace std;

#define sp << " " <<
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define int long long
#define double long double
#define INF 1e18
#define PI 3.14159265359

int power(int p,int y)
{
    int res=1;
    p=p%mod;
    while(y>0)
    {
        if(y&1)
            res=(res*p)%mod;
        y=y>>1;
        p=(p*p)%mod;
    }
    return res;
}

/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int dice()
{
    uniform_int_distribution<int> uid(0,1);//specify l and r.
    return uid(rng) ;
}

int read()
{
       int cc = getc(stdin);
       for (;cc < '0' || cc > '9';)  cc = getc(stdin);
       int dp = 0;
       for (;cc >= '0' && cc <= '9';)
       {
          dp = dp * 10 + cc - '0';
          cc = getc(stdin);
       }
      return dp;
}

inline void print(int n)
{
  if (n == 0)
  {
    putchar('0');
    putchar('\n');
  }
  else if (n == -1)
  {
    putchar('-');
    putchar('1');
    putchar('\n');
  }
  else
  {
    char buf[20];
    buf[19] = '\n';
    int i = 18;
    while (n)
    {
      buf[i--] = n % 10 + '0';
      n /= 10;
    }
    while (buf[i] != '\n')
      putchar(buf[++i]);
  }
}

int n;

vector<vector<int>> mat_mul(vector<vector<int>> a,vector<vector<int>> b)
{
    int n=5;
	vector<vector<int>> t(n,vector<int>(n,0));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<n;k++)
			{
				t[i][j]+=((a[i][k]*b[k][j])%mod);
				t[i][j]%=mod;
			}
		}
	}
	return t;
}

vector<vector<int>> pow_mat(vector<vector<int>> mat_a,int p)
{
	if(p==1)
        return mat_a;
	vector<vector<int>> temp=pow_mat(mat_a,p/2);
	vector<vector<int>> res=mat_mul(temp,temp);
	if(p&1)
        res=mat_mul(res,mat_a);
	return res;
}
*/

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    if(s[0]=='M')
    {
        cout << 6;
    }
    else if(s[0]=='W')
    {
        cout << 4;
    }
    else if(s[0]=='F')
    {
        cout << 2;
    }
    else if(s[0]=='T')
    {
        if(s[1]=='U')
            cout << 5;
        else
            cout << 3;
    }
    else
    {
        if(s[1]=='A')
            cout << 1;
        else
            cout << 7;
    }
    return 0;
}


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

int main() {
    int ans = 0;
    int N;
    cin >> N;
    vector<vector<int>> A(N);
    for(int i = 0; i < N; i++) {
        int a;
        cin >> a;
        A[i] = {a, i + 1};
    }
    sort(A.begin(), A.end(),
         [](const vector<int> &alpha, const vector<int> &beta) {
             return alpha[0] < beta[0];
         });
    for(int i = 0; i < N; i++) {
        if(i == 0)
            cout << A[i][1];
        else
            cout << " " << A[i][1];
    }

    cout << endl;
}

Measured memory_bytes: 6272
N = int(input())
A_list = list(map(int, input().split()))

min_v = 10**9+1
cnt_min = 0
res = 0
for i, a in enumerate(A_list):
    if a < 0:
        cnt_min += 1
        a = -1 * a
    min_v = min(min_v, a)
    res += a

if cnt_min%2 == 1:
    res -= 2*min_v
print(res)

Measured memory_bytes: 14412
import sys
def input(): return sys.stdin.readline().rstrip()
def f(x,y,z):
    return x**2 + y**2 + z**2 + x*y + y*z + z*x
def main():
    n = int(input())
    A = [0]*(n+1)
    for x in range(1,100):
        for y in range(x, 100):
            for z in range(y, 100):
                num = f(x,y,z)
                if num > n:
                    break
                if x == y and y == z:
                    A[num] += 1
                elif x == y or y == z or z == x:
                    A[num] += 3
                else:
                    A[num] += 6
    for i in range(1,n+1):
        print(A[i])

if __name__=='__main__':
    main()

Measured memory_bytes: 74552
import java.util.*;
import java.io.*;
import java.math.*;
class Main{
	static int mod = 998244353;
public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();
		String st = sc.next();
		int n = st.length();
		int mid = n/2;
		
		int ans=0;
		
		for(int i=0,j=n-1;i<mid;i++,j--){
			if(st.charAt(i)!=st.charAt(j))
				ans++;
		}
		System.out.println(ans);
	}
	
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;


		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}

}

Measured memory_bytes: 22612
c = [list(map(int, input().split())) for i in range(3)]
if c[0][0]-c[0][1] == c[1][0]-c[1][1] == c[2][0]-c[2][1] and c[0][1]-c[0][2] == c[1][1]-c[1][2] == c[2][1]-c[2][2]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int m=sc.nextInt();
		long k=sc.nextLong();
		int p=1<<m;
		if(k<p){
			if(m==1 && k==1){
				System.out.println(-1);
				return;
			}
			if(m==1 && k==0){
				System.out.print(0+" "+0+" "+1+" "+1);
				return;
			}
			for(int i=0; i<p; i++){
				if(i==k){
					continue;
				}
				System.out.print(i+" ");
			}
			System.out.print(k+" ");
			for(int i=p-1; i>=0; i--){
				if(i==k){
					continue;
				}
				System.out.print(i+" ");
			}
			System.out.print(k);
		}else{
			System.out.println(-1);
		}
	}
}


Measured memory_bytes: 48060
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int A =sc.nextInt();
    int B =sc.nextInt();
    int H =sc.nextInt();
    int M =sc.nextInt();
    if(H>=12){H =H-12;}
    double K =Math.abs(H*30+M*0.5-M*6);
    double k =Math.cos(Math.toRadians(K));
    double T =A*A+B*B-2*A*B*k;
    double t =Math.sqrt(T);
    System.out.println(t);
  }
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vector<ll> a(N), b(N), c(N);
    rep(i, N) cin >> a[i];
    rep(i, N){
        b[i] = i + a[i];
        c[i] = i - a[i];
    }

    sort(all(c));
    ll res = 0;
    rep(i, N){
        res += upper_bound(all(c), b[i]) - lower_bound(all(c), b[i]);
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 11912
#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/ 
using namespace std;

#define endl "\n"
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define re(i,a) for(int i=0; i<a; ++i)
#define tr(i,v) for(auto &i: v)
#define mem(a,val) memset(a,val,sizeof(a))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define in(v,n) vi v(n);re(i,n) cin>>v[i]
#define printVec(v,s) cout << s; tr(i, v) cout << i << " ";
#define sz(a) int((a).size())
#define dbgv(c, v) cout << c << " = " << v << endl;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef vector< pii > vii;
typedef vector< ll > vll;
typedef complex<double> point;

const long long MOD = 1000000007;
const long long inf = 1e18;

void solve(){
	
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	#endif 
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    int x; cin>>x;

    re(b, 1000){
        rep(a, b+1, 1000){
            if(a-b > x) break;
            if(x % (a - b) == 0){
                ll pa = a * a;
                pa *= pa;
                pa *= a;
                ll pb = b * b;
                pb *= pb;
                pb *= b;
                if(pa - pb == x){
                    cout << a << " " << b;
                    return 0;
                }
            }
            b = -b;
            if(x % (a - b) == 0){
                ll pa = a * a;
                pa *= pa;
                pa *= a;
                ll pb = b * b;
                pb *= pb;
                pb *= b;
                if(pa - pb == x){
                    cout << a << " " << b;
                    return 0;
                }
            }
            b = -b;
        }
    }
    cout << "-1";
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3652
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N;
    R(N);
    int v=0;
    while(N){
        v+=N%10;
        N/=10;
    }
    if(v==1)v=10;
    W(v);
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
char s[N];
ll dp[N];
int pw[N], lst[N], nx[N];

int main() {
  int n, p; scanf("%d %d", &n, &p);
  scanf("%s", s);
  ll ans = 0;
  if (p == 2 || p == 5) {
    for (int i = 0; i < n; i++) {
      if ((s[i]-'0') % p == 0)
        ans += i + 1;
    }
    printf("%lld\n", ans);
    return 0;
  }
  pw[0] = 1;
  for (int i = 1; i < n; i++)
    pw[i] = pw[i-1] * 10 % p;
  ll cur = 0;
  for (int i = 0; i < p; i++)
    lst[i] = -1;
  for (int i = 0; i < n; i++)
    nx[i] = -1;
  lst[0] = n;
  for (int i = n-1; ~i; i--) {
    cur = (cur + pw[n-1-i] * (s[i]-'0')) % p;
    if (~lst[cur])
      nx[lst[cur]-1] = i;
    lst[cur] = i;
  }
  for (int i = 0; i < n; i++) {
    int jj = nx[i];
    dp[i] = jj >= 0 ? (jj>0?dp[jj-1]:0) + 1 : 0;
    ans += dp[i];
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 13312
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

struct hline {
	int h;
	int p, q;
	hline(int h=0, int p=0, int q=0) : h(h), p(p), q(q){}
	bool operator>(const hline &o) const {
		return h > o.h;
	}
};

int main() {
	int n, m, a;
	while (cin >> n >> m >> a , n || m || a) {
		vector<hline> hls(m);
		for (int i = 0; i < m; i++) {
			cin >> hls[i].h >> hls[i].p >> hls[i].q;
		}
		sort(hls.begin(), hls.end(), greater<hline>());
		for (int i = 0; i < m; i++) {
			if (hls[i].p == a) a = hls[i].q;
			else if (hls[i].q == a) a = hls[i].p;
		}
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 920
def gcd(a, b):
    while(b != 0):
        amari = a % b

        a = b
        b = amari
    return(a)


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

X = list(map(int, input().split()))

tmp = abs(X[0] - K)
for i in range(1, N):
    tmp = gcd(tmp, abs(X[i] - K))

print(tmp)

Measured memory_bytes: 14252
#include <stdio.h>

int main(void)
{
	int h , m , s , in;

	scanf("%d", &in);

	h = in / 3600;
	m = in / 60 - 60 * h;
	s = in % 60;

	printf("%d:%d:%d\n", h , m , s);

    return 0;
}

Measured memory_bytes: 592
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
	//N M
	var input = Console.ReadLine();
	var inputs = input.Split();
	int n = int.Parse(inputs[0]);
	int m = int.Parse(inputs[1]);
	//Pm Ym
	City[] cities = new City[m];
	for (int i = 0; i < m; i++) {
	    input = Console.ReadLine();
	    inputs = input.Split();
	    var city = new City {
		Id = i,
		Pref = int.Parse(inputs[0]),
		Year = int.Parse(inputs[1]),
	    };
	    cities[i] = city;
	}
	//結果を出力
	City[] newCities = new City[m];
	var citySorted = cities.OrderBy(c => c.Pref).ThenBy(c => c.Year);
	int count = 1;
	int prevPref = -1;
	int j = 0;
	foreach (var city in citySorted) {
	    if (city.Pref == prevPref) {
		count++;
	    } else {
		count = 1;
		prevPref = city.Pref;
	    }
	    var newCity = new City {
		Id = city.Id,
		Pref = city.Pref,
		Year = count,
	    };
	    newCities[j] = newCity;
	    j++;
	}

	foreach (var city in newCities.OrderBy(c => c.Id)) {
	    Console.WriteLine(String.Format("{0:000000}{1:000000}", city.Pref, city.Year));
	}
    }

    public struct City {
	public int Id;
	public int Pref;
	public int Year;
    }
}


Measured memory_bytes: 24932
#include <stdio.h>

int main(){

  int i,j,N,minj,temp,count=0;

  scanf("%d",&N);

  int A[N];

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  
  for(i=0;i<N-1;i++){
    minj = i;
    
    for(j=i;j<N;j++){
      if(A[j]<A[minj]){
	minj = j;
      }
    }
    if(minj != i)count++;
    temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;
  }

  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[N-1]);
  printf("%d\n",count);
  

  return 0;
}

Measured memory_bytes: 600
from fractions import gcd
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
ans = 0
p = 1
for a in A:
    b = gcd(a,p)
    ans = (ans * (a//b) % MOD + (p//b))%MOD
    p = a*p//b
print(ans)

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

int N,K,L;
map<pair<int,int>,int> m;

// Union Find
struct UnionFind {
	vector<int> parent,rank;
	UnionFind(int n) :parent(n), rank(n) {
		for(int i=0;i<n;++i){
			parent[i] = i;
			rank[i] = 0;
		}
	}
	bool unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y)return false;
		if(rank[x] < rank[y]){
			parent[x] = y;
		} else {
			parent[y] = x;
			if(rank[x]==rank[y]) rank[x]++;
		}
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) { return parent[x] == x ? x : parent[x] = root(parent[x]); } // 経路圧縮
};



int main()
{
	cin >> N >> K >> L;
	UnionFind* doro = new UnionFind(N+1);
	UnionFind* tetsudo = new UnionFind(N+1);
	for(int i=0;i<K;++i){
		int p,q;
		cin >> p >> q;
		p--;q--;
		doro->unite(p,q);
	}
	for(int i=0;i<L;++i){
		int r,s;
		cin  >> r >> s;
		r--;s--;
		tetsudo->unite(r,s);
	}

	// mapへの格納 N
	for(int i=0;i<N;++i){
		m[make_pair(doro->root(i),tetsudo->root(i))]++;
	}

	for(int i=0;i<N;++i){
		cout << m[make_pair(doro->root(i),tetsudo->root(i))];
		if(i!=N) cout << " ";
	}
	 cout << endl;
	
	return 0;
}

Measured memory_bytes: 15872
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

string s;

int ans;

int main() {
	cin >> s;
	for (int i = 0; s[i]; i++) {
		if (s[i] == '1') {
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A, B, C, K, D, E, max = 0, ans;
		A = sc.nextInt();
		B = sc.nextInt();
		D = Math.max(A, B);
		C = sc.nextInt();
		E = Math.max(D, C);
		K = sc.nextInt();
		for (int i = 0; i < K; i++) {
			max = E * 2;
		}
		ans = A + B + C - E;
		ans += E * Math.pow(2.0, (double) K);
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 21716
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll solve()
{
    int n;

    cin >> n;

    vector<int> nums = fetch_vec<int>(n);

    int max = 0;
    int preMax = 0;

    for (int num: nums)
    {
        if (num > max)
        {
            preMax = max;
            max = num;
        }
        else if (num > preMax)
        {
            preMax = num;
        }
    }

    for (int num : nums)
    {
        if (num == max)
            cout << preMax << endl;
        else
            cout << max << endl;
    }

    return 0;
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 2432
#include <stdio.h>
       
int main(void){
       
int W,H,x,y,r;
     
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

if((H>=y+r)&&(W>=x+r)&&(y-r>=0)&&(x-r>=0)) 
printf("Yes\n");
else
printf("No\n");
     
return 0;
}

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

int main(){
    ll n,k;
    cin >> n >> k;
    vector <ll> x(n);
    rep(i,n){
        cin >> x[i];
    }

    ll ans=1000000000000000,ans2;
    rep(i,n-k+1){
        if(x[i]<0){
            if(x[i+k-1]<0){
                ans2=-1*x[i];
                //cout << ans2 << endl;
                ans=min(ans,ans2);
            }
            else{
                ans2=-1*x[i]+x[i+k-1]+min(-1*x[i],x[i+k-1]);
                //cout << ans2 << endl;
                ans=min(ans,ans2);
            }
        }
        else{
            ans2=x[i+k-1];
            ans=min(ans,ans2);
        }
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 3952
// https://atcoder.jp/contests/dp/tasks/dp_v
// V - Subtree

#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>

#include <stdio.h>

using namespace std;

vector< vector<int> > adj;
vector< vector<int> > adj_count;
vector< long long > ans;
vector< bool > visited;


int M;

long long dfs1(int u) {
  // cout << "v1" << u << endl;
  visited[u] = true;
  long long a = 1;
  int c = 0;
  for (auto v: adj[u]) {
    // cout << "ds " << u << " " << v << endl;
    if (!visited[v]) {
      auto r = dfs1(v) + 1;
      a = (a * r) % M;
      adj_count[u][c] = r % M;
    }
    c++;
  }

  return a;
}

void dfs2(int u, long long father) {
  // cout << "v2 " << u << " " << father << endl;
  visited[u] = true;


  int le = adj[u].size();

  if (le==0) {
    ans[u] = 1;
    return;
  }

  vector<long long> l( le, 1 );
  vector<long long> r( le, 1 );
  vector<long long> f( le, 1 );

  for(auto i=0; i<le; i++) {
    auto v = adj[u][i];
    if (visited[v]) adj_count[u][i] = father+1;
    // cout << "ac " << adj_count[u][i] << endl;

    if (i>0) 
      l[i] = (l[i-1] * adj_count[u][i] ) % M; 
    else
      l[i] = adj_count[u][0] % M;
  }

  r[le-1] = adj_count[u][le-1] % M;
  if (le > 1) f[le-1] = l[le-2]; else f[le-1]= 1;

  for(auto i=le-2; i >=0; i--) {
    auto v = adj[u][i];
    r[i] = (r[i+1] * adj_count[u][i] ) % M;
    if (i > 0) f[i] = (l[i-1] * r[i+1] ) % M;
    else f[i] = r[i+1] % M;
  }


  assert(r[0] == l[le-1]);
  ans[u] = r[0];

  for(auto i=0; i<le; i++) {
    // cout << "fi" << i << " " << f[i] << endl;
    auto v = adj[u][i];
    if (!visited[v])  dfs2(v,  f[i]);
  }
}

int main() {
  int N;
  cin >> N >> M;

  adj.assign(N, {});
  adj_count.assign(N, {});
  ans.assign(N, 0);
  visited.assign(N, false);

  for(int i=0; i < N-1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj_count[u].push_back(0);
    adj[v].push_back(u);
    adj_count[v].push_back(0);
  }

  dfs1(0);
  visited.assign(N, false);
  dfs2(0, 0);
  for(auto i=0; i<N; i++) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 26368