akhauriyash/Code-Regression huggingface dataset:
# 2K * 2Kの正方形で一周するので、
# (X,Y) -> (X % 2K, Y % 2K)に言い換えることが出来る
# Wの表とBの表を別々で持つ
# それぞれの表で二次元累積和を持ち、範囲に対する得点を求められるようにする
# K * Kの正方形の左下隅を1000 * 1000通り全探索して最大値を求める
# 効率化のため、上記K * Kの正方形が黒である場合と白である場合を同時に計算する
# その領域で見つけた白の個数は、黒を計算するときは「白の総数 - 見つけた白の個数」とすることで白の得点として加算できるえ

import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())
white = [[0] * (2 * K + 1) for i in range(2 * K + 1)]
black = [[0] * (2 * K + 1) for i in range(2 * K + 1)]
# 黒を数えるときは、同時に白を数えて、白全体の数から引く
white_all = 0
black_all = 0
for i in range(N):
  x,y,c = readline().split()
  x,y = int(x) % (2 * K),int(y) % (2 * K)
  if c == "W":
    white[x + 1][y + 1] += 1
    white_all += 1
  else:
    black[x + 1][y + 1] += 1
    black_all += 1
  
for i in range(1, len(white)):
  for j in range(1, len(white[i])):
    white[i][j] += white[i][j - 1]
    
for j in range(1, len(white)):
  for i in range(1, len(white[j])):
    white[i][j] += white[i - 1][j]

for i in range(1, len(black)):
  for j in range(1, len(black[i])):
    black[i][j] += black[i][j - 1]
    
for j in range(1, len(black)):
  for i in range(1, len(black[j])):
    black[i][j] += black[i - 1][j]

cases = ((0,0),(K,K),(-K,-K),(K,-K),(-K,K))
ans = 0
  
for i in range(1, K + 1):
  for j in range(1, K + 1):
    # 基本となる正方形の左下隅・右上は以下の通り
    # (i,j),(i + K - 1, j + K - 1)
    # これに対して、
    # i,jともに +Kしたもの
    # i,jともに -Kしたもの
    # iは+K,jは-Kしたもの
    # iは-K,jは+Kしたもの
    # が考えられる範囲となる
    # なお、最小値は1,1、最大値は2 * K,2 * Kとなる
    # iだけ+Kした正方形は、その正方形の白黒を反転させると計上済みとなる
    black_cnt = 0
    white_cnt = 0
    for c in cases:
      x1 = i + c[0]
      y1 = j + c[1]
      x2 = x1 + K - 1
      y2 = y1 + K - 1
        
      x1 = max(1, x1)
      y1 = max(1, y1)
      x2 = min(2 * K, x2)
      y2 = min(2 * K, y2)
      if x1 > x2 or y1 > y2:
        continue
        
      # その領域の黒と白の数を数える
      black_cnt += black[x2][y2] - black[x2][y1 - 1] - black[x1 - 1][y2] + black[x1 - 1][y1 - 1]
      white_cnt += white[x2][y2] - white[x2][y1 - 1] - white[x1 - 1][y2] + white[x1 - 1][y1 - 1]
      
    # その正方形が黒の場合と白の場合を両方算出し、比較する
    point = max(black_cnt + (white_all - white_cnt),white_cnt + (black_all - black_cnt))
    if ans < point:
      ans = point
    
print(ans)

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

int main() {
  int n, di;
  cin >> n;
  int d[n];
  for (int i = 0; i < n; i++) {
    cin >> di;
    d[i] = di;
  }

  sort(d, d + n);
  int cnt = 1;
  for (int i = 1; i < n; i++) {
    if (d[i - 1] != d[i]) cnt++;
  }
  cout << cnt << endl;
}

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


int main(){
    int a, b;
     char op;
    
    while(1){
   
    cin >> a >> op >> b ;
   
        
    if ( op == '+') cout << a + b << endl;
    else if ( op == '-') cout << a - b << endl;
    else if (op == '*') cout << a*b << endl;
    else if ( op  == '/' ) cout << a/b << endl;
    else if ( op  == '?' ) break;
        }
    
    return 0;
    
}

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    long long r, d, x;
    cin >> r >> d >> x;
    REP(i, 10){
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
X=int(input())

x=X//100

if x<6:
  print(8)
elif x<8:
  print(7)
elif x<10:
  print(6)
elif x<12:
  print(5)
elif x<14:
  print(4)
elif x<16:
  print(3)
elif x<18:
  print(2)
else:
  print(1)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <stack>
 
using namespace std;
 
#define f(i,a,b) for(int i=a;i<b;i++)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int>>
#define ss second
#define ff first
#define ll long long
#define lld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pq priority_queue< int >
#define pqll priority_queue< ll >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define INF 1000000000
#define NINF -1000000000
 
ll maxll(ll a , ll b ){
    return a > b ? a : b;
}
 
ll minll(ll a , ll b){
    return a > b ? b : a;
}

// bool check(ll z){
//     ll temp = k;
//     // cout << z << endl;
//     f(i , 0 , n){
//         ll sub = (ll)z * a[i];
//         if (sub > b[i])
//         temp -= (sub -b[i]);
//         if (temp < 0){
//             return 0;
//         }
//     }
//         // cout << z << endl;
//     sol = z;
//         return 1;
// }

// int gcd (int a , int b){
//     return __gcd(a,b);
// }

// void print_vi(vi a){
//     for (int i: a){
//         cout << i << " " ;
//     }
//     cout << endl;
// }

// Best algo to find maximum sum subarray (contiguous)
// ll kadane (vl a){
//     ll curr = 0 , maxi = 0;
//     f(i , 0 , a.size()){
//         curr = max(a[i] , curr + a[i]);
//         maxi = max(maxi , curr);
//     }
//     return maxi;
// }

// Method to get the factors of a big number here a[j] = factors of number j
// ll x;
// cin >> x;
// vl a(x+1 , 0);
// f( i , 1 , x+1){
//     for (int j = i ; j < x+1 ; j+= i){
//         a[j]++;
//     }
// }

void solve(){
    
    int n , k;
    cin >> n >> k;
    vi a (n);
    f( i , 0 , n){
        cin >> a[i];
    }
    sort(a.begin() , a.end());
    int sum = 0;
    f( i , 0 , k){
        sum += a[i];
    }
    cout << sum << endl;
}

 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
 
 
    
    int t = 1;
    // cin >> t;
    
    while(t--){
        
        solve();
    }
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main(void)
{
  long n, k, x, tmp = 0;
  cin >> n >> k;
  vector<P> ab(n);
  for(int i = 0; i != n; i++){
    int a, b;
    cin >> a >> b;
    ab[i] = make_pair(a, b);
  }
  sort(ab.begin(), ab.end());
  for(x = 0;; x++){
    tmp += ab[x].second;
    if(tmp >= k){
      cout << ab[x].first << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main()
{
    int n,i,m,x;
    int c=0;
    cin>>n;
    for(i=0;i!=n;i++)
    {
        cin>>x;
        if(i==0)
        {
            m = x;
            c++;
        }
        else
        {
            if(x>=m)
            {
                m = x;
                c++;
            }
        }
    }

    cout<<c;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[m];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0; i < m; i++){
            b[i] = sc.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);
        int a_r = a[n-1];
        int b_l = b[0];

        String ans = "War";

        for(int i = a_r + 1; i <= b_l; i++){
            if(i > x && i <= y) ans = "No War";
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22868
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())

    que = queue.Queue()
    que.put('3')
    que.put('5')
    que.put('7')

    res = 0
    while not que.empty():
        i = que.get()
        if int(i) <= N:
            if ('3' in i) and ('5' in i) and ('7' in i):
                res += 1
            que.put(i + '3')
            que.put(i + '5')
            que.put(i + '7')
        else:
            break

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 54100
import sys
sys.setrecursionlimit(10**9)
n,m = map(int, input().split())

rel = [[] for _ in range(n)]
for i in range(m):
  x,y,z = map(int, input().split())
  rel[x-1].append(y-1)
  rel[y-1].append(x-1)

ans = [-1]*n
def hoge(parent, pos):
  for i in rel[pos]:
    if ans[i] >= 0:
      continue
    ans[i] = pos
    hoge(pos, i)
  return

cnt = 0
for i in range(n):
  if ans[i] < 0:
    hoge(0, i)
    cnt += 1

print(cnt)

Measured memory_bytes: 109700
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

int main() {
  int n; cin >> n;
  vector<ll> A(n);
  loop(i,0,n) cin >> A[i];
  map<ll, int> M;
  ll ans = 0;
  loop(i,1,n+1) {
    ll v = i+A[i-1];
    if (i==1) {
      M[v]++;
      continue;
    }
    ll val = i - A[i-1];
    if (val >= 0) {
      ans += M[val];
    }
    M[v]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 18400
#include<stdio.h>
#include<string.h>
main(){
  int j,s,len;
  int a[105];
  char r[105];
  while(scanf("%s",r)!=EOF){
    for(j=0;j<103;j++){
      a[j]=0;
    }
    len=strlen(r);
    s=0;
    for(j=0;j<len;j++){
      if(r[j]=='I'){
	a[j]=1;
      }
      else if(r[j]=='V'){
	a[j]=5;
      }
      else if(r[j]=='X'){
	a[j]=10;
      }
      else if(r[j]=='L'){
	a[j]=50;
      }
      else if(r[j]=='C'){
	a[j]=100;
      }
      else if(r[j]=='D'){
	a[j]=500;
      }
      else{
	a[j]=1000;
      }
    }
    for(j=0;j<len;j++){
      if(a[j]<a[j+1]){
	s+=(a[j+1]-a[j]);
	j++;
      }
      else{
	s+=a[j];
      }
    }
    printf("%d\n",s);
  }
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);

    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
    int nxt=1, ans=0;
    for(int i=0;i<n;i++){
        if(a.at(i)==nxt){
            nxt++;
        }else{
            ans++;
        }
    }
    if(ans==n){
        cout << "-1" << endl;
        return 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n; cin >> n;
    int h[101]; INITA(h, 0, 100, 0);
    int mx = 0;
    REP(i, n) {
        cin >> h[i];
        mx = max(mx, h[i]);
    }
    int res = 0;
    FORD(i, mx, 1) {
        int prev = 0;
        REP(j, n) {
            if (h[j] == i) {
                if (prev != i) {
                    res += 1;
                }
                prev = h[j];
                h[j] -= 1;
            } else {
                prev = h[j];
            }
        }
    }
    cout << res << endl;
    return 0;
}

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

int main(){
  int n,a,ma=0;
  cin >> n;
  map<int,int> mp;
  r(i,n){
    cin >> a;
    mp[a]++;
    mp[a-1]++;
    mp[a+1]++;
  }
  for(auto it=mp.begin();it!=mp.end();it++){
    ma=max(ma,(*it).second);
  }
  cout << ma << endl;
}


Measured memory_bytes: 4736
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
vector<int> adj[N];
bool vis[N];
int dis[N];
void dfs(int s)
{
	int p;
	vis[s]=true;
	for(int i=0;i<adj[s].size();i++)
	{
		p=adj[s][i];
		if(vis[p]==0)
		{
			dfs(p);
		}
	}
	for(int i=0;i<adj[s].size();i++)
	{
		p=adj[s][i];
		dis[s]=max(dis[s],1+dis[p]);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<=n;i++)
	{
		vis[i]=0;
		dis[i]=0;
	}
	int x,y;
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		adj[x].push_back(y);
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i]==0)
		{
			dfs(i);
		}
	}
	int ans=0;
	for(int i=0;i<=n;i++)
	{
		if(dis[i]>ans)
		{
			ans=dis[i];
		}
	}
	cout<<ans;
}

Measured memory_bytes: 11524
#include <stdio.h>

int main()
{
  int n;
  int h[100000];
  int i;
  int maxmove=0;
  int move=0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &h[i]);
  }
  for (i = 1; i < n; i++) {
    if(h[i]<=h[i-1]){
      move++;
      if(move>maxmove) maxmove=move;
    }else{
      move=0;
    }
  }
  printf("%d\n",maxmove);
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
using namespace std;

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
 
  if (a <= b) {
    if (b<=c) {
      printf("%d %d %d\n", a, b, c);
    } 
    else if (a<=c&&c<=b) {
      printf("%d %d %d\n", a, c, b);
    }
    else {
      printf("%d %d %d\n", c, a, b);
    }
  }
  else {
    if (a <= c) {
      printf("%d %d %d\n", b, a, c);
    } 
    else if (b <= c && c <= a) {
      printf("%d %d %d\n", b, c, a);
    }
    else {
      printf("%d %d %d\n", c, b, a);
    }
  }
  return 0;
}

Measured memory_bytes: 1028
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine();
        var nk = s.Split(' ');
        var n = int.Parse(nk[0]);
        var k = int.Parse(nk[1]);
        List<long> hlist = new List<long>();
        for (int i = 0; i < n; i++)
        {
            hlist.Add(int.Parse(Console.ReadLine()));
        }

        hlist.Sort();

        long dmin = long.MaxValue;
        for (int i = 0; i < hlist.Count - (k - 1); i++)
        {
            long d = hlist[i + k - 1] - hlist[i];
            if (d < dmin)
            {
                dmin = d;
            }
        }

        Console.WriteLine(dmin);
    }
}


Measured memory_bytes: 16988
#include <stdio.h>
#include <string.h>
int main()
{
    long long int a,c;
    char b;
    scanf("%lld %c %lld",&a,&b,&c);
    if(b=='+')
    {
        printf("%lld\n",a+c);
    }
    else
    {
        if(c>a)
        {
            printf("-%lld\n",c-a);
        }
        else
        {
            printf("%lld\n",a-c);
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORD(i, a, b) for(int i = (a); i > (b); --i)
#define REPD(i, a, b) for(int i = (a); i >=(b); --i)
#define TR(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define unmap unordered_map
#define lb lower_bound //first pos >= val
#define ub upper_bound // first pos > val
#define debug(a) cout << a << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <ll> vll;

const ll maxN = 1e18;
const ll minN = -1e18;
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int bignumlen = 2200;
const int Blen = 8;
const ll base = 100000000;
const int baseHash = 31;
const ld PI = acos(-1);

//Remember limit for IT, etc...
const ll limit = 2e5 + 5;
const ll limit1 = 1e6 + 5;

string s;

void solveProblem() {
    if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

void fastInput() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void readInput() {
    cin >> s;
}

int main() {
    fastInput();
    readInput();
    solveProblem();
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << x << endl;

int main()
{
    long long N, D, A;
    cin >> N >> D >> A;
    D = 2 * D;
    vector<pair<long long, long long>> monster(N);
    rep(i, N)
    {
        int X, H;
        cin >> X >> H;
        monster[i] = make_pair(X, H);
    }
    sort(monster.begin(), monster.end());

    long long ans = 0;
    vector<long long> kill_bomb(N + 1, 0);
    kill_bomb[0] = 0;
    int r = 1;
    rep(i, N)
    {
        kill_bomb[i + 1] += kill_bomb[i];
        long long HP = monster[i].second - kill_bomb[i + 1] * A;
        if (HP <= 0)
            continue;
        int count = HP / A;
        if (HP % A != 0)
            count++;
        ans += count;
        kill_bomb[i + 1] += count;

        while (r < N)
        {
            if (monster[r].first > monster[i].first + D)
                break;
            r++;
        }
        if (r == N)
            continue;
        kill_bomb[r + 1] -= count;
    }

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

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 1e5 + 7;
int arr[MAXN];
int main()
{
    string s;
    cin>>s;
    int len = s.size();
    int r, l;
    memset(arr, 0, sizeof arr);
    for(int i = 0; i < len; i++)
    {
        l = 0, r = 0;
        if(s[i] == 'R')
        {
            r++;
            int x, y;
            for(int j = i+1; j < len; j++)
            {
                if(s[j] == 'R')
                    r++;
                else
                {
                    x = j;
                    break;
                }
            }
            for(int j = x; j < len; j++)
            {
                if(s[j] == 'L')
                    l++;
                if(s[j] == 'R' || j == len - 1)
                {
                    //cout<<r<<'\t'<<l<<endl;
                    arr[x] = arr[x-1] = (r+l)/2;
                    if(r>l && (r-l)%2 == 1)
                    {
                        if(l%2 == 1)
                            arr[x]++;
                        else arr[x-1]++;
                    }
                    else if(l>r && (l-r)%2 == 1)
                    {
                        if(r%2 == 1)
                            arr[x-1]++;
                        else arr[x]++;
                    }
                    y = j;
                    break;
                }
            }
            i = y-1;
            if(y == len - 1) i++;
        }
    }
    for(int i = 0; i < len; i++)
    {
        cout<<arr[i];
        if(i < len-1) cout<<' ';
        else cout<<endl;
    }
 
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  int n;
  cin>>n;
  vector<long long> a(n);
  map<long long,long long> maps;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    if(maps.count(a[i]))
      maps[a[i]]+=1;
    else
      maps[a[i]]=1;
  }
  
  sort(a.begin(),a.end());
  
  int q;
  cin>>q;
  vector<long long> b(q);
  vector<long long> c(q);
  for(int i=0;i<q;i++)
    cin>>b[i]>>c[i];
   
  long long sum=0;
  for(int j=0;j<n;j++)
  {
    sum+=a[j];
  }
      

  for(int i=0;i<q;i++)
  {
    long long change=0;
    change+=maps[b[i]]*(c[i]-b[i]);
    maps[c[i]]+=maps[b[i]];
    maps[b[i]]=0;
    sum+=change;
	cout<<sum<<endl;
    
  }
}
  
  

Measured memory_bytes: 11292
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	if (N <= 999) {
		out << "ABC"
			<< endl;
	}
	else{
		out << "ABD" << endl;
	}

	return 0;
}
#endif


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	int n;
	for (cin >> n; n--;)
	{
		vector<int> a(10);
		for (int i = 0; i < 10; i++)
		{
			cin >> a.at(i);
		}
		
		int idb = 0, idc = 0;
		bool b = true;
		for (int i = 0; i < a.size(); i++)
		{
			if (idb < a.at(i))
			{
				idb = a.at(i);
			}
			else if (idc < a.at(i))
			{
				idc = a.at(i);
			}
			else
			{
				b = false;
				break;
			}
		}


		cout << (b ? "YES" : "NO") << endl;
	}
}


Measured memory_bytes: 3012
#include<stdio.h>
int main()
{
	char s[1200];
	scanf("%[^\n]", s);
	for(int i = 0; s[i] != '\0'; i++)
	{
		if('A' <= s[i] && s[i] <= 'Z')s[i] += 32;
		else if('a' <= s[i] && s[i] <= 'z')s[i] -= 32;
		printf("%c", s[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2044
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

class Program {
    static void Main(string[] args) {
        int H, W, N;
        Input(out H);
        Input(out W);
        Input(out N);
        if(N % Math.Max(H, W) == 0) {
            Console.WriteLine(N / Math.Max(H, W));
        } else {
            Console.WriteLine(N / Math.Max(H, W) + 1);
        }
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
}

Measured memory_bytes: 11092
unit = ['', 'Man', 'Oku', 'Cho', 'Kei', 'Gai', 'Jo', 'Jou', 'Ko', 'Kan', 'Sei', 'Sai', 'Gok', 'Ggs', 'Asg', 'Nyt', 'Fks', 'Mts']
while 1
  a,b = gets.split()
  if a=='0' then break end
  p = a.to_i**b.to_i
  s = ''
  for i in 0..17
    rem = p%10000
    if rem!=0 then s = rem.to_s + unit[i] + s end
    p /= 10000
    if p==0 then break end
  end
  puts s
end

Measured memory_bytes: 6140
#include<stdio.h>

int main(void){

  double c1,c2,c3;
  double px,py;
  double x1,y1,x2,y2,x3,y3;

  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&px,&py) != EOF){
    
    c1 = (x3 - x2) * (py - y2) - (y3 - y2) * (px - x2);
    c2 = (x1 - x3) * (py - y3) - (y1 - y3) * (px - x3);
    c3 = (x2 - x1) * (py - y1) - (y2 - y1) * (px - x1);

    if((c1 > 0  && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0)){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
  }

    return 0;
  }

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[1000005];
int main()
{
	ll n,ans=0;
	scanf("%lld%s",&n,s+1);
	char jk='#';
	for(int i=1;i<=n;i++)
	if(s[i]!=jk)
	ans++,jk=s[i];
	cout<<ans;
}

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

int main(void){
    char s[101]; 

    scanf("%s", s);

    printf("%c", s[0]);

    printf("%d", strlen(s) - 2);

    printf("%c\n", s[strlen(s) - 1]);
    return 0;

} 


Measured memory_bytes: 384
N, C = map(int, input().split())

tv = [[0]*C for _ in range(100000)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s-1, t): tv[i][c-1] = 1
    
print(max([sum(tv[i]) for i in range(100000)]))


Measured memory_bytes: 41768
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String[] c = s.split("");
        int countA = 0;
        int countB = 0;
        for (int i = 0; i < s.length(); i += 2) {
            if (c[i].equals("0"))
                countA++;
        }
        for (int i = 1; i < s.length(); i += 2) {
            if (c[i].equals("1"))
                countA++;
        }
        for (int i = 0; i < s.length(); i += 2) {
            if (c[i].equals("1"))
                countB++;
        }
        for (int i = 1; i < s.length(); i += 2) {
            if (c[i].equals("0"))
                countB++;
        }
        System.out.println(Math.min(countA, countB));
    }
}


Measured memory_bytes: 32684
#include <stdio.h>

int main(void) {
	int i, w, n, vline[30], swap[2], tmp;
	scanf ("%d %d", &w, &n);
	for (i=0; i<w; i++) vline[i] = i+1;
	for (i=0; i<n; i++){
		scanf ("%d,%d", &swap[0], &swap[1]);
		tmp = vline[swap[0]-1];
		vline[swap[0]-1] = vline[swap[1]-1];
		vline[swap[1]-1] = tmp;
	}
	for (i=0; i<w; i++) printf ("%d\n", vline[i]);
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>

using namespace std;
typedef long long ll;

ll a[1000000];
ll ans,mx,mn=1e8,sum,cnt;
int main(){
	ll n;
	cin>>n;
	for(int i =0; i<n; i++){
		ll b;
		cin>>b;
		a[b]++;
		mx = max(mx,b);
		mn = min(mn,b);
	}
	for(int i=mn; i<=mx; i++){
		sum = a[i]+a[i+1]+a[i+2];
		ans = max(ans,sum);
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))

A.sort()

B = [0] * (N+1)
for i in range(N):
    B[i+1] = B[i] + A[i]

ans = 0
for i in range(N):
    if B[i] * 2 < A[i]:
        ans = 0
    else:
        ans += 1

print(ans+1)

Measured memory_bytes: 14320
/*
* じょえチャンネル
* 高評価・チャンネル登録よろしくおねがいします！
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/

#include <bits/stdc++.h>


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


#define inf (int)(3e18)
#define int long long
#define mod (int)(1000000007)

#define intt long long
#define P pair<int,int>

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

using namespace std;

//Library
//モッドパウ
int modpow(int x, int y, int m = mod) {
    int res = 1;
    while (y) {
        if (y % 2) {
            res *= x;
            res %= m;
        }
        x = x * x % mod;
        y /= 2;
    }
    return res;
}

int mypow(int x, int y) {
    int res = 1;
    while (y) {
        if (y % 2) {
            res *= x;
        }
        x = x * x;
        y /= 2;
    }
    return res;
}
//is the number (x) a prime number?
bool prime(int x) {
    for (int i = 2; i * i <= x; i++) {
        if (!(x % i)) {
            return false;
        }
    }
    return true;
}


//saidai-kouyakusuu
inline int gcd(int x, int y) {
    if (!y) {
        return x;
    }
    return gcd(y, x % y);
}


//number of keta
int keta(int x) {
    int ans = 0;
    while (x) {
        x /= 10;
        ans++;
    }
    return ans;
}

//sum of keta
int ketasum(int x) {
    int ans = 0;
    while (x) {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

inline int lcm(int x, int y) {
    int ans = x / gcd(x, y) * y;
    return ans;
}
int twobeki(int x) {
    int ans = 0;
    while (1) {
        if (!(x & 1)) {
            ans++;
            x /= 2;
        }
        else {
            break;
        }
    }
    return ans;
}


template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
    if (lhs < rhs) {
        lhs = rhs;
        return 1;
    }
    return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
    if (lhs > rhs) {
        lhs = rhs;
        return 1;
    }
    return 0;
}
void Yes(){
    cout<<"Yes"<<endl;
}
void No(){
    cout<<"No"<<endl;
}
void YES(){
    cout<<"YES"<<endl;
}
void NO(){
    cout<<"NO"<<endl;
}


#define fin(i) scanf("%lld",&i)
#define fout(i) printf("%lld",i)
#define fendl printf("\n")
//Library-End

int n,m,ans,x[104],y[104],h[104];
pair<int, pair<int, int>> g;
signed main() {
    cin>>n;
    rep(i,n){
        fin(x[i]);fin(y[i]);fin(h[i]);
        if (h[i]) {
            g={x[i],{y[i],h[i]}};
        }
    }
    rep(i,101){
        rep(j,101){
            bool ok=1;
            int taka=abs(i-g.first)+abs(j-g.second.first)+g.second.second;
            rep(k,n){
                if (h[k]!=max(taka-abs(i-x[k])-abs(j-y[k]),0ll)) {
                    ok=0;
                    break;
                }
            }
            if (ok) {
                cout<<i<<' '<<j<<' '<<taka<<endl;
            }
        }
    }
}


Measured memory_bytes: 256
function parseInt(x) parse(Int, x) end
parseMap(x::Array{SubString{String}, 1}) = map(parseInt, x)

function istrip(t,tt, x, xx, y, yy)
	if abs(xx-x)+abs(yy-y) <= tt-t && (abs(xx-x)+abs(yy-y)-tt+t)%2 == 0
		return(1)
	else
		return(0)
	end
end

function main()
	n = parseInt(readline())
	flg = 0
	x = Array{Int}(3,n+1)
	x[:,1] = [0,0,0]
	for i in 1:n
		x[:,i+1] = parseMap(split(readline()))
	end
	x = sortcols(x, by = x ->x[1])
	flg = 0
	for i in 2:n+1
		if istrip(x[1,i-1],x[1,i],x[2,i-1],x[2,i],x[3,i-1],x[3,i]) == 0
			print("No")
			flg = 1
			break
		end
	end
	if flg == 0
		print("Yes")
	end
end

main()

Measured memory_bytes: 182076
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#include "atcoder/all"

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }

    friend std::istream &operator>>(std::istream &in, mint &o) {
        ll a;
        in >> a;
        o = a;
        return in;
    }

    friend std::ostream &operator<<(std::ostream &out, const mint &o) {
        out << o.x;
        return out;
    }

};


int main() {
    int n, s;
    cin >> n >> s;
    vector<int> v(n);
    rep(i, n) cin >> v[i];

    vector<vector<mint>> dp(n + 1, vector<mint>(s + 1, 0));
    dp[0][0] = 1;

    auto get = [&](int i, int j) -> mint {
        return dp[i][j];
    };

    auto set = [&](int i, int j, mint v) {
        if (j > s) return;
        dp[i][j] += v;
    };

    rep(i, n) {
        rep(j, s + 1) {
            mint prev = get(i, j);
            set(i + 1, j, prev);
            set(i + 1, j + v[i], prev);
        }
        if (i != 0) {
            set(i + 1, 0, 1);
            set(i + 1, v[i], 1);
        }
    }

    mint ans = 0;
    rep(i, n) {
        ans += dp[i + 1][s];
    }
    cout << ans << endl;
}


Measured memory_bytes: 73708
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[3][n+1];
	int i,j;
	for(i=1;i<=2;i++)
	{
		for(j=1;j<=n;j++)
		{
			cin>>a[i][j];
		}
	}
	for(j=n-1;j>=1;j--)
	{
		a[2][j]+=a[2][j+1];
	}
	a[1][n]+=a[2][n];
	for(j=n-1;j>=1;j--)
	{
		if(a[1][j+1]>a[2][j])
		{
			a[1][j]+=a[1][j+1];
		}
		else
		{
			a[1][j]+=a[2][j];
		}
	}
	cout<<a[1][1];
	return 0;
}

Measured memory_bytes: 256
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
d = 2 ** (H - 1)
mcut = 1008
for i in range(d):
  L = [0 for _ in range(H)]
  for j in range(1, H):
    L[j] = L[j-1] + i % 2
    i //= 2
  C = [0 for _ in range(L[H-1]+1)]
  cutp, cutq = True, True
  cut = L[H-1]
  for m in range(W):
    for l in range(H):
      C[L[l]] += int(S[l][m])
    if cutq:
      cutq = False
      if max(C) > K:
        cutp = False
        break
    else:
      if max(C) > K:
        cut += 1
        C = [0 for _ in range(L[H-1]+1)]
        for l in range(H):
          C[L[l]] += int(S[l][m])
    if cutp == False:
      break
  if cutp:
    if cut < mcut:
      mcut = cut
print(mcut)

Measured memory_bytes: 74616
#include<bits/stdc++.h>
using namespace std;
int main()
{
    #ifdef TarekHasan
        freopen("input.txt","r",stdin);
    #endif // TarekHasan

    long long int x; cin >> x;
    long long int answer = 0;

    long long int y=(x/500);
    answer+=(y*1000);
    x%=500;
    y=(x/5);
    answer+=(y*5);
    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 3620
N=int(input())
*A,=map(int,input().split())
D=[[1]for _ in range(N+1)]
for i in range(2,N+1):
    j=1
    while i*j<=N:
        D[i*j].append(i)
        j+=1

D=D[1:]
B=[0]*N
ans=[]
i=1
while i<=N:
    B[-i]%=2
    if B[-i]==A[-i]:
        i+=1
        continue
    else:
        ans.append(N-i+1)
        for d in D[-i]:
            B[d-1]+=1
        B[-i]%=2
    i+=1
        
M=len(ans)
ans.sort()
print(M)
print(*ans)

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

const int MAX_N = 100001;
int dp[MAX_N];
int main()
{
    int n;
    cin >> n;
    dp[0] = 0;
    for(int i=1;i<MAX_N;++i) dp[i] = 1 << 30; 
    
    for(int i=0;i<MAX_N;++i)
    {
        int tmp = 1;
        int pow6 = 0;
        int pow9 = 0;
        do
        {
            pow6 = pow(6, tmp);
            pow9 = pow(9, tmp);

            if(i + pow6 < MAX_N)
            {
                dp[i + pow6] = min(dp[i + pow6], dp[i] + 1);
            }

            if(i + pow9 < MAX_N)
            {
                dp[i + pow9] = min(dp[i + pow9], dp[i] + 1);
            }
            tmp++;
        }while(i + pow6 < MAX_N);
        dp[i + 1] = min(dp[i + 1], dp[i] + 1);
    }

    cout << dp[n] << endl;
}

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

#define int long long int



signed main()
{
   int a,b,c,d,mx=-1e18;
   cin>>a>>b>>c>>d;
   mx=max(a*c,mx);mx=max(mx,b*d);mx=max(mx,b*c);mx=max(mx,a*d);
   cout<<mx;
}


Measured memory_bytes: 3608
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        long[] A = new long[N];
        long[] B = new long[N];
        long[] C = new long[N];
        for(int i = 0;i < N;i++)    A[i] = sc.nextLong();
        for(int i = 0;i < N;i++)    B[i] = sc.nextLong();
        for(int i = 0;i < N;i++)    C[i] = sc.nextLong();
        Arrays.sort(A);
        Arrays.sort(B);
        Arrays.sort(C);
        long[] BC = new long[N];
        long[] AB = new long[N];
        int cid = N-1;
        for(int i = N-1;i >= 0;i--){
            while(cid >= 0 && B[i] < C[cid]) cid--;
            if(i == N-1)    BC[i] = (long)(N-1-cid);
            else    BC[i] = (long)(N-1-cid)+BC[i+1];
        }
        int bid = N-1;
        for(int i = N-1;i >= 0;i--){
            while(bid >= 0 && A[i] < B[bid])    bid--;
            if(i == N-1){
                if(A[i] >= B[N-1])    AB[i] = 0;
                else    AB[i] = BC[bid+1];
            }else{
                if(A[i] >= B[N-1])  AB[i] = AB[i+1];
                else    AB[i] = BC[bid+1]+AB[i+1];
            }
        }
        System.out.println(AB[0]);
    }
}

Measured memory_bytes: 100632
#include <bits/stdc++.h>
#include<unordered_map>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;
int main() {
	cin >> A >> B;
	if (B%A == 0)cout << A + B << endl;
	else cout << B - A << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
#include <iomanip>
#include <sstream>
#include <unordered_map>

using namespace std;
typedef long long ll;


ll ans, mx, mn, flag, sum, cnt;


int main(){
	ll a,b;
	cin>>a>>b;
	ll d[3];
	d[0]=a+b;
	d[1]=a-b;
	d[2]=a*b;
	sort(d,d+3);
	cout<<d[2];
			
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include<string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int A, B;
    cin >> A >> B;
    if (A + B >= 10) {
        cout << "error" << endl;
    } else {
        cout << A + B << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def read_int_list():
    return list(int(i) for i in input().split())
n = int(input())
player = dict()
for i in range(n):
    k, p = read_int_list()
    player[k] = p

max_p = max(player)
min_p = min(player)
high = min_p - 1
low = player[max_p]
b = max_p-min_p+1
print(high+b+low)

Measured memory_bytes: 17912
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 33; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

long long Div(long long a, long long b, long long m) {
	return (a * modpow(b, m - 2, m)) % m;
}

long long mod = 1000000007;
long long N, C[1 << 18], fact[1 << 18], inv[1 << 18];

void init() {
	fact[0] = 1;
	for (int i = 1; i <= 200000; i++) fact[i] = (1LL * fact[i - 1] * i) % mod;
	for (int i = 0; i <= 200000; i++) inv[i] = Div(1, fact[i], mod);
}

long long ncr(long long n, long long r) {
	return (fact[n] * inv[r] % mod) * inv[n - r] % mod;
}

int main() {
	cin >> N; init();
	for (int i = 0; i < N; i++) cin >> C[i];
	sort(C, C + N);

	long long t1 = 0, t2 = 0;
	for (int i = 0; i < N; i++) {
		t1 += C[i]; t1 %= mod;
		t2 += 1LL * (N - i - 1LL) * C[i]; t2 %= mod;
	}
	t1 = Div(t1, N, mod);
	t2 = Div(t2, N, mod);
	t2 = Div(t2, N - 1, mod);

	long long ret = 0;
	for (int i = 0; i <= N; i++) {
		long long V1 = ncr(N, i);
		long long V2 = (t1 + 1LL * (i - 1LL) * t2); V2 %= mod;
		long long V3 = i;
		ret += ((V1 * V2 % mod) * V3 % mod);
		ret %= mod;
	}
	long long ret2 = modpow(2, N, mod);
	cout << (ret * ret2 % mod) << endl;
	return 0;
}

Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    ll N, M, K; cin >> N >> M >> K;
    vector<ll> a(N), b(M);
    rep(i, N) cin >> a[i];
    rep(i, M) cin >> b[i];
    
    vector<ll> sumA(N + 1, 0), sumB(M + 1, 0);
    for(int i = 1; i <= N; i++){
        sumA[i] = sumA[i - 1] + a[i - 1];
    }
    for(int i = 1; i <= M; i++){
        sumB[i] = sumB[i - 1] + b[i - 1];
    }    
    ll ans = 0;
    rep(i, N + 1){
        if(sumA[i] > K) break;
        int last = K - sumA[i];
        auto itr = upper_bound(all(sumB), last);
        ans = max(ans, (ll)(i + itr - sumB.begin() - 1));
    }

    cout << ans << endl;
}

Measured memory_bytes: 9600
#include<stdio.h>
#include<math.h>
int main()
{
    int a,b,sum=0;
    scanf("%d%d",&a,&b);
	if(b<10){
		sum = a*10+b;
	}
	else if(b>=10 && b<100){
		sum = a*100 + b;
	}
	else if(b==100){
		sum = a*1000+b;
	}
    if(sqrt(sum) == (int)sqrt(sum)){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000000 + 7
#define PI 3.14159265359

const long long INF = 100000;
typedef pair<int,int> P;
typedef long long ll;

using Graph = vector<vector<int>>;


vector<int> connect;// 各点の連結成分が入る
vector<int> connect2;// 各点の連結成分が入る
vector<int> num(100000 + 1);// num[i]はiの自分を除く連結成分の数
vector<int> numb(100000 + 1);// numb[i]はiの連結成分のうち、iとブロック関係にある人の数
vector<bool> seen(100000 + 1, false);

//vの連結成分を格納していくdfs
void dfs(const Graph &G, int v) {
	if (seen[v] == true) return;
	
	if (seen[v] == false) {
		seen[v] = true;
		connect.push_back(v);
	}

	for (auto next_v : G[v]) {
		if (seen[next_v] == true) continue;
		dfs(G, next_v);
	}
}

int main() {
    int N, M, K;
	cin >> N >> M >> K;
	
	Graph Friend(N + 1);
	Graph Block(N + 1);

	for (int i = 1; i <= M; i++) {
		int A, B;
		cin >> A >> B;
		Friend[A].push_back(B);
		Friend[B].push_back(A);
	}
	for (int i = 1; i <= K; i++) {
		int C, D;
		cin >> C >> D;
		Block[C].push_back(D);
		Block[D].push_back(C);
	}

	for (int v = 1; v <= N; v++) {
		//if (seen[v] == true) continue;
      
		//各頂点vの連結成分をconnectに格納
		dfs(Friend, v);
		
      	for (int i = 0; i < connect.size(); i++) {
			//cout << connect[i] << " ";
		}
		//cout << endl;
      	
		//各連結成分のnumを計算
		for (int i = 0; i < connect.size(); i++) {
			num[connect[i]] = connect.size() - 1;
			//cout << num[connect[i]] << " ";
        }
		//cout << endl;
      
		//各連結成分をsetに格納
		set<int> S;
		for (int i = 0; i < connect.size(); i++) {
			S.insert(connect[i]);
		}

		//各連結成分のnumbを求める
		for (int i = 0; i < connect.size(); i++) {
			int V = connect[i];
			int count = 0;

			for (auto block : Block[V]) {
				if (S.count(block)) count++;
			}
			numb[V] = count;
		}
		connect = connect2;

	}

	vector<int> ans(N + 1);
	for (int i = 1; i <= N; i++) {
		ans[i] = num[i] - numb[i] - Friend[i].size();
	}

	for (int i = 1; i <= N; i++) {
		if (i == N) cout << ans[i];
		else cout << ans[i] << " ";
	}

}

Measured memory_bytes: 17656
def main():
    N, Q = map(int, input().split())
    V = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        V[a - 1].append(b - 1)
        V[b - 1].append(a - 1)
    C = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        C[p - 1] += x
    cur = [(0, 0, -1)]
    while cur:
        n, x, f = cur.pop()
        C[n] = x = C[n] + x
        for c in V[n]:
            if c != f:
                cur.append((c, x, n))
    print(' '.join(str(c) for c in C))

main()


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

using namespace std;

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

    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(s[i] == '1')
            ans++;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define mod 1000000007
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define pii pair<ll,ll>
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

/**********************************************************************************************************************/



signed main()/*question galat mat padhna yr*/
{
    fast;   
    ll n,m,x;
    cin>>n>>m>>x;
    ll c[n];
    ll a[n][m+1];
    For(i,n)
    {
        // cin>>c[i];
        For(j,m+1)cin>>a[i][j];
    }
    set<vector<ll>>v;
    vector<ll>nul;
    For(i,m+1)nul.pb(0);
    v.insert(nul);
    For(i,n)
    {
        set<vector<ll>>temp;
        for(auto z:v)
        {
            vector<ll>p;
            For(j,m+1)
            {
                p.pb(z[j]+a[i][j]);
            }
            temp.insert(p);
        }
        for(auto z:temp)v.insert(z);
    }
    
    ll cost=mod;
    for(auto z:v)
    {
        bool check=0;
        For(i,m)
        {
            if(z[i+1]<x)check=1;
        }
        if(check==0)
        {
            cost=z[0];
            cout<<z[0]<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}   

Measured memory_bytes: 4724
#include <iostream>
#include <cmath>
#include <algorithm> 
#include <vector>
#include <limits>

using namespace std;

const long long INF = 100000000000000000;

int main () {
    const int MAX_SUM_V = 100000;
    long long N,W;
    cin >> N >> W;
    vector <long long>w(N);
    vector <long long>v(N);
    for (int i = 0 ; i < N ; i++)
    {
        cin >> w[i] >> v[i];
    }
    vector <vector <long long> >dp(N + 1, vector<long long>(MAX_SUM_V + 1, INF));
    dp[0][0] = 0;
    long long ans = MAX_SUM_V;
    for (int i = 0 ; i < N ; i++)
    {
        for (int j = 0 ; j <= MAX_SUM_V ; j++) {
            dp[i + 1][j] = j - v[i] >= 0 ? min(dp[i][j - v[i]] + w[i], dp[i][j]) : dp[i][j];
        }
    }

    for (int i = 0 ; i <= MAX_SUM_V ; i++) {
        ans = (dp[N][i] <= W) ? i : ans;
    }

    cout << ans <<endl;
}


Measured memory_bytes: 80256