akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
typedef long long ll;

int main(void) {
  ll i, j, k, l, ans = 1e18, now;
  char s[110];
  scanf("%s", s);
  for(i = 0; i < 26; ++i) {
    char t[110];
    strcpy(t, s);
    now = 0;
    bool ne = true, flg;
    for(j = 0; j < strlen(s); ++j) if(s[j] == i + 'a') ne = false;
    if(ne) continue;
    while( 1 ) {
      flg = true;
      for(j = 0; j < strlen(t); ++j) if(t[j] != i + 'a') flg = false;
      if(flg) break;
      for(j = 0; j < strlen(t) - 1; ++j) if(t[j + 1] == i + 'a') t[j] = t[j + 1];
      t[strlen(t) - 1] = 0;
      now++;
    }
    if(now < ans) ans = now;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 128
import sys
def input(): return sys.stdin.readline().rstrip()
def prime_list(n):
    primes = set(range(2, n+1))
    for i in range(2, int(n**0.5+1)):
        primes-=set(range(i*2, n+1, i))
    return list(primes)
def main():
    x=int(input())
    primes = prime_list(100010)
    for p in primes:
        if p >= x:
            print(p)
            break
if __name__=='__main__':
    main()

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

namespace AOJ
{
    class Program
    {
        private static IEnumerable<bool> Check()
        {
            string line;
            while((line = Console.ReadLine()) != null)
                yield return line == new string(line.Reverse().ToArray());
        }

        static void Main(string[] args)
        {
            Console.WriteLine(Check().Count(x => x));
        }
    }
}

Measured memory_bytes: 5884
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

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

	cout << min(A, B) + min(C, D);

	return 0;
}

Measured memory_bytes: 3604
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i<n; i++) {
			list.add(sc.nextInt());
		}
		sc.close();
		Collections.reverse(list);
		StringBuilder sb = new StringBuilder();
		for (int i : list) {
			sb.append(i);
			sb.append(" ");
		}
		System.out.println(sb.toString().trim());
	}
}

Measured memory_bytes: 26300
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main(){
  string s;cin>>s;
  int n = stoi(s.substr(5,2));
  if(n<=4){
    cout << "Heisei" << endl;
  }else{
    cout << "TBD" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//制約をよく見る。この場合 型をlong long にしないと通らない。
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int n, W;
//型はlong long、　少し大きめに取っておく
long long weight[110], value[110];

long long dp[110][100010];

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

  for (int w = 0; w <= W; w++) dp[0][w] = 0;

  for (int i = 0; i < n; i++) {
  for (int w = 0; w <= W; w++) {
      // a[i]を選択するか否か
    if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
    else dp[i+1][w] = dp[i][w];

  }
  }

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

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

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx-sx;
    int dy = ty-sy;
    rep(i,dy) cout << 'U';
    rep(i,dx) cout << 'R';
    cout << 'U';
    rep(i,dx+1) cout << 'L';
    rep(i,dy+1) cout << 'D';
    cout << 'R';
    rep(i,dx) cout << 'R';
    rep(i,dy) cout << 'U';
    cout << 'R';
    rep(i,dy+1) cout << 'D';
    rep(i,dx+1) cout << 'L';
    cout << 'U';
    cout << endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
ds = [[] for _ in range(n)] # ネタの種類t(<=n)別においしさdのリスト
for _ in range(n):
    t, d = map(int, input().split())
    t -= 1
    ds[t].append(d)

y0, y1 = [], []
for i in range(n):
    if len(ds[i]) == 0:
        continue
    ds[i].sort()    # 各ネタでおいしさのsort
    y1.append(ds[i][-1])    # 各ネタで最大のおいしさをpopしy1に追加
    ds[i].pop()
    y0.extend(ds[i])        # 各ネタで2番目以降のおいしさのリストをy0に追加
y0.sort(reverse=True)   # ネタの種類が増えないおいしさのリスト（各ネタで2番目以降）を降順sort
y1.sort(reverse=True)   # ネタの種類が増えるおいしさ（各ネタで最大）のリストを降順sort

ans = 0
# Y = max(0, k-len(y0))   # Y: ネタの種類の最小値（kまで増やしながら貪欲するため）
Y = min(k, len(y1))   # Y: ネタの種類の最大値（減らしながら貪欲するため）
X = 0
for i in range(Y):
    X += y1[i]      # Y個 ネタの種類が増えるおいしさ（各ネタで最大）を大きい順に加算
for i in range(k-Y):
    X += y0[i]      # k-Y個 ネタの種類が増えないおいしさを大きい順に加算

while True:
    ans = max(ans, X+Y*Y)
    # if (Y>=k or Y>=len(y1)):   # Yをkまで増やしながら貪欲
    #     break
    # X += y1[Y]      # ネタの種類が増えるおいしさ（各ネタで最大）を大きい順に1つ追加
    # X -= y0[k-Y-1]  # ネタの種類が増えない大きさを小さい順に1つ除外
    # Y += 1
    if (Y<=0 or k-Y>=len(y0)):   # Yを減らしながら貪欲
        break
    X -= y1[Y-1]      # ネタの種類が増えるおいしさ（各ネタで最大）を小さい順に1つ除外
    X += y0[k-Y]  # ネタの種類が増えない大きさを大きい順に1つ追加
    Y -= 1
print(ans)


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

ans = []

for i in range(k*2):
  x = input().split()
  if 1 == i % 2:
    for j in range(len(x)):
      if int(x[j]) not in ans:
        ans.append(int(x[j]))

print(n - len(ans))


Measured memory_bytes: 9148
#include <stdio.h>
#include <stdlib.h>

int main(void){
    char S[100];
    scanf("%s",S);
    if(S[0]=='S')printf("Cloudy\n");
    else if(S[0]=='C')printf("Rainy\n");
    else if(S[0]=='R')printf("Sunny\n");
    return 0;
}


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

int main(){
	int price = 700;
	char buf[3];
	for (auto i = 0; i < 3; i++){
		cin >> buf[i];
		if (buf[i] == 'o'){
			price += 100;
		}
	}
	cout << price;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    cin>>n;
    bool ok=false;
    while(n>0){
        if(n%10==7) ok=true;
        n/=10;
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3624
def m():
    N, M = map(int, input().split())
    K = [list(map(int, input().split())) for _ in range(M)]
    P = list(map(int, input().split()))
    ans = 0
    for b in range(1 << N):
        mask = bin(b)[2:].zfill(N)
        light = [False] * M
        for j in range(M):
            on = 0
            for k in range(1, K[j][0] + 1):
                if mask[K[j][k] - 1] == '1':
                    on += 1
            if (on % 2) == P[j]:
                light[j] = True
        if all(light):
            ans += 1
    return ans


print(m())


Measured memory_bytes: 44012
#include<stdio.h>

int func(int, int, int);

int A[20];

int main()
{
  int i, n, q;
  int Q[200];

  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      scanf("%d", &A[i]);
    }
  scanf("%d", &q);
  for(i=0; i<q; i++)
    {
      scanf("%d", &Q[i]);
    }

  for(i=0; i<q; i++)
    {
      if(func(Q[i], n, 0))
	{
	  printf("yes\n");
	}
      else
	{
	  printf("no\n");
	}
    }
  
  return 0;
}

int func(int mi, int n, int i)
{
  if(mi == 0) return 1;
  else if(i == n || mi < 0) return 0;
  else if(func(mi, n, i+1) || func(mi-A[i], n, i+1)) return 1;
  else return 0;
}

Measured memory_bytes: 580
def is_odd(num):
    return num % 2 != 0

def odd_in_list(num_list):
    for num in num_list:
        if is_odd(num):
            return True
    
    return False

def half(num):
    return num / 2

def shift_only(num_list, counter):
    if odd_in_list(num_list):
        print('its over')
        return counter
    else:
        new_list = list(map(half, num_list))
        counter += 1
        print('continue', num_list, counter)
        return shift_only(new_list, counter)


n = int(input())

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


counter = 0
flag = True

while flag:
    for i in range(n):
        # print(a_list[i])
        if a_list[i] % 2 != 0:
            # print('is odd')
            flag = False
            break
        else:
            continue
    
    if not flag:
        break
    
    for i in range(n):
        a_list[i] /= 2
    counter += 1

    # print('-----loop------')
    # print(a_list, counter)

print(counter)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>

using namespace std;

int move(int move_num, int original_num) 
{
	if (move_num > original_num) move_num = original_num;
	return move_num;
}

int main(void)
{
	long long a[5];
	long long N;

	cin >> N;
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

	long long X = min({ a[0], a[1], a[2], a[3], a[4] });

	cout << (long long)(ceil((double)N/X) + 4) << endl;

	return 0;
}

Measured memory_bytes: 256
#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)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

char S[21],T[21];

int main() {

	scanf("%s%s", S,T);

	int a = 0;
	rep(i, 3) {
		if (S[i] == T[i]) ++a;
	}

	printf("%d\n", a);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll mod=1e9+7;
 
using namespace std;


int main(){
	int q=1;
	//cin>>q;

	while(q--){
		string s;
		cin>>s;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define speedrap ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int be(int a,int b,int mod) {if(b == 0) return 1; if(b%2 == 1) return (a*be(a,b-1,mod))%mod; else return (be(a,b/2,mod)*be(a,b/2,mod))%mod;}
const int mod = 1e9+7;
#define PI 3.14159265359
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
#define mkp(x,y) make_pair(x,y)
const int siz = 5*(1e5 + 1);
const int logi = 21;
const double epsilon = 1e-6;
int prime[siz];
bool cmp(const int &a,const int &b)
{
  return (abs(a-b)>1);
}




signed main()
{
 	
	speedrap
	int t;
	t = 1;
	//cin>>t;
	while(t--)
	{
		string s;
		cin>>s;

		int flag = 0;

		for(int i = 0 ; i < s.length() ; i++)
		{
			if(s[i]-'0' == 7)
			{
				flag = 1;
			}
		}

		if(flag == 1)
		{
			cout<<"Yes";
		}
		else
		{
			cout<<"No";
		}
	}
}

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

int main(){
  string s; cin >> s;
  int n = s.size();
  long long ans = stoll(s);
  for(int i = 1; i < (1<<(n-1)); i++){
    int l = 0;
    for(int r = 0; r < n-1; r++){
      if(1 & (i>>(n-r-2))){
        ans += stoll(s.substr(l, r-l+1));
        l = r+1;
      }
    }
    ans += stoll(s.substr(l));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def main():
    N, K = inpl()
    A = inpl()

    nn = 1
    n = 1
    i = 0
    while True:
        nn = A[nn - 1]
        nn = A[nn - 1]
        n = A[n - 1]

        if nn == n:
            break

    roop = set()
    roop.add(n)
    root = n
    while True:
        n = A[n - 1]
        roop.add(n)
        if root == n:
            break

    n = 1
    rest = []
    while n not in roop:
        n = A[n - 1]
        rest.append(n)

    # print(roop)
    # print(rest)
    if K <= len(rest):
        print(rest[K - 1])
    else:
        for i in range((K - len(rest)) % len(roop)):
            n = A[n - 1]
        print(n)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 108824
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,s=0,ans=0;cin>>n;
  lvector A(n,0), S(n+1,0);
  rep(i,n) cin>>A[i];
  for(ll i=1;i<=n;++i) S[i]=S[i-1]+A[i-1];
  map<ll,ll> mp;
  rep(i,n+1) mp[S[i]]+=1;
  for(auto i:mp) {
    ll x=i.second;
    if(x>1) ans+=x*(x-1)/2;
  }
  print(ans);
  return 0;
}

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

N, M = map(int, input().split())
is_AC = [False]*N
pena = [0]*N

for _ in range(M):
    pi, si = input().split()
    pi = int(pi)
    
    if si=='AC':
        is_AC[pi-1] = True
    else:
        if is_AC[pi-1]:
            continue
        else:
            pena[pi-1] += 1

ans0 = is_AC.count(True)
ans1 = 0

for i in range(N):
    if is_AC[i]:
        ans1 += pena[i]

print(ans0, ans1)

Measured memory_bytes: 43988
#include <iostream>
#include <string>

using namespace std;

int main() {
	long long n, k, q, line;
	long long *a, *b;
	cin >> n;
	cin >> k;
	cin >> q;
	line = q - k + 1;
	a = new long long[q];
	b = new long long[n];
	for (int i = 0; i < n; i++) {
		b[i] = 0;
	}
	for (int i = 0; i < q; i++) {
		cin >> a[i];
		b[a[i] - 1] ++;
	}
	for (int i = 0; i < n; i++) {
		if (b[i] >= line) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 2176
import java.util.Scanner;


public class Main{
	static int dfs(int n) {
		if(n<=9) {
			return n;
		}
		return dfs(n/10)+n%10;
	}
    public  static void main(String[] args) {
    	try (Scanner sc = new Scanner(System.in)) {
    		int N=sc.nextInt();
    		int A=sc.nextInt();
    		int B=sc.nextInt();
    		int sum=0;
    		for(int i=1; i<=N; i++) {
    			if(A<=dfs(i) && dfs(i)<=B) {
    				sum+=i;
    			}
    		}
    		System.out.println(sum);
    	}
    }
}

Measured memory_bytes: 21844
import copy
h,w,k=map(int,input().split())
c=[list(input()) for i in range(h)]
ans=0
for bit1 in range(1<<h):
    for bit2 in range(1<<w):
        count=0
        map=copy.deepcopy(c)
        for i in range(h):
            if bit1 & (1<<i):
                for j in range(w):
                    if map[i][j]=="." or map[i][j]=="#":
                        map[i][j]="!"
        for i in range(w):
            if bit2 & (1 << i):
                for j in range(h):
                    if map[j][i] == "." or map[j][i] == "#":
                        map[j][i] = "!"

        for i in range(h):
            for j in range(w):
                if map[i][j]=="#":
                    count+=1
        if count==k:
            ans+=1
print(ans)


Measured memory_bytes: 76760
#include <cstdio>
#include <algorithm>
#include <tuple>
#include <utility>
#include <vector>

int main() {
  size_t n, m;
  scanf("%zu %zu", &n, &m);

  std::vector<std::pair<int, int>> ba(m);
  for (auto& p: ba)
    scanf("%d %d", &p.second, &p.first);

  std::sort(ba.begin(), ba.end());

  int max = 0;
  int res = 0;
  for (auto const& p: ba) {
    int a, b;
    std::tie(b, a) = p;
    if (max <= a) {
      max = b;
      ++res;
    }
  }

  printf("%d\n", res);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	string S; cin >> S;

	if (S == "Sunny"){
		cout << "Cloudy" << endl;
	}
	else if (S == "Cloudy"){
		cout << "Rainy" << endl;
	}
	else{
		cout << "Sunny" << endl;
	}
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long int
int main()
{
   double a,b;
   vector<int>v;
   cin>>a>>b;
   v.pb(a+b);
   v.pb(a-b);
   v.pb(a*b);
   sort(v.begin(),v.end());
   cout<<v[v.size()-1]<<endl;

    return 0;
}


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

using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
const ll MOD=1e9+7;
int main()
{
    ll n,x,sum=0,ans=0;
    cin>>n;
    for(ll i=0;i<n;i++){
        cin>>x;
        ans+=x*sum%MOD;
        ans%=MOD;
        sum+=x;
        sum%=MOD;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3632
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef long long ll;

#define f first
#define s second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int md = 1e9+7;
const ll inf = 1e18;
const int maxn = 3e3+5;

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

int r, c, k;

int arr[maxn][maxn];

bool vis[maxn][maxn][4];

ll dp[maxn][maxn][4];

ll solve(int x, int y, int rem)
{
	if(x> r || y> c || rem< 0) return -4e18;
	if(x == r && y == c) return (rem?max(arr[x][y], 0):0);
	if(vis[x][y][rem]) return dp[x][y][rem];

	ll best = solve(x+1, y, 3);
	ckmax(best, solve(x, y+1, rem));
	if(rem)
	{
		ckmax(best, arr[x][y]+solve(x+1, y, 3));
		ckmax(best, arr[x][y]+solve(x, y+1, rem-1));
	}
	vis[x][y][rem] = true;
	dp[x][y][rem] = best;
	return best;
}

int main()
{
	scanf("%d %d %d", &r, &c, &k);
	for(int i = 1; i<= k; i++)
	{
		int x, y, v; scanf("%d %d %d", &x, &y, &v);
		arr[x][y] = v;
	}
	printf("%lld\n", solve(1, 1, 3));
}

Measured memory_bytes: 356404
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
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++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

ll gcd(ll x, ll y) {
	x = abs(x), y = abs(y);
	if (x < y)swap(x, y);
	while (y) {
		ll r = x % y; x = y; y = r;
	}
	return x;
}

//0/0だけ気を付けて！
struct ratio {
	ll a, b;
	ratio(ll x) { a = x; b = 1; };
	ratio(ll x, ll y) { 
		a = x; b = y; 
		ll g = gcd(x, y); 
		if (g > 0) {
			a /= g, b /= g;
			if (b < 0)a = -a, b = -b;
		}
	};
	
};

void normalize(ratio &r) {
	ll g = gcd(r.a, r.b);
	r.a /= g; r.b /= g;
	if (r.b < 0)r.b = -r.b, r.a = -r.a;
}
bool operator<(const ratio &x,const ratio &y) {
	return x.a*y.b < x.b*y.a;
}
bool operator==(const ratio &x,const ratio &y) {
	return x.a*y.b == x.b*y.a;
}

typedef pair<ratio, int> speP;

char mp[600][600];
void solve(){
	int h, w; cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			cin >> mp[i][j];
		}
	}
	vector<speP> v;
	rep(i, h) {
		rep(j, w) {
			if (mp[i][j] != '#')continue;
			//左下
			int x = h - 1 - i, y = j;

			if (j==w-1||(j < w - 1&&mp[i][j+1]=='.')) {
				v.push_back({ ratio(x+1,y+1),1 });
				v.push_back({ ratio(x,y + 1),0 });
			}
			if (j==0||(j > 0 && mp[i][j - 1] == '.')) {
				v.push_back({ ratio(x+1,y),1 });
				v.push_back({ ratio(x,y),0 });
			}
			if (i==0||(i > 0 && mp[i - 1][j] == '.')) {
				v.push_back({ ratio(x+1,y),1 });
				v.push_back({ ratio(x+1,y + 1),0 });
			}
			if (i==h-1||(i < h - 1 && mp[i + 1][j] == '.')) {
				v.push_back({ ratio(x,y),1 });
				v.push_back({ ratio(x,y + 1),0 });
			}
		}
	}
	int len = v.size();
	for (int i = len-1; i >= 0;i--) {
		//cout << v[i].first.a << " " << v[i].first.b << endl;
		if (v[i].first.a==0&&v[i].first.b==0) {
			//cout << "Hello" << " " << i << endl;
			v.erase(v.begin() + i);
		}
	}
	len = v.size();
	//cout << len << endl;
	int ans = 0;
	sort(v.begin(), v.end());
	/*rep(i, len) {
		cout << v[i].first.a << " " << v[i].first.b << endl;
	}*/
	int cur = 0;
	rep(i, len) {
		int le = i;
		while (i + 1 < len&&v[i].first == v[i + 1].first)i++;
		Rep1(j, le, i) {
			if (v[j].second)cur--;
			else cur++;
		}
		ans = max(ans, cur);
		//cout << cur << " "<<v[i].first.a << " " << v[i].first.b << endl;
	}
	cout << ans / 2+1 << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
		return 0;
}


Measured memory_bytes: 27828
import java.util.Scanner;

public class Main {
	int parent(int i) {
		return i / 2;
	}

	int left(int i) {
		return 2 * i;
	}

	int right(int i) {
		return 2 * i + 1;
	}

	public static void main(String[] args) {
		new Main().run();

	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] A = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			A[i] = scanner.nextInt();
		}
		for (int i = 1; i <= n; i++) {
			System.out.printf("node %d: key = %d, ", i, A[i]);
			if (parent(i) >= 1)
				System.out.printf("parent key = %d, ", A[parent(i)]);
			if (left(i) <= n)
				System.out.printf("left key = %d, ", A[left(i)]);
			if (right(i) <= n)
				System.out.printf("right key = %d, ", A[right(i)]);
			System.out.println();
		}

	}

}

Measured memory_bytes: 23440
//ΔATCODER QUALC B
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
int main()
{
	int n,i,x,s,p;
	s=1,p=1;
	cin>>n;
	while(n--){
		cin>>x;
		if(x%2==0)
			s*=2;
		p*=3;
	}
	cout<<p-s<<endl;
	return 0;
}

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

typedef long long ll;
ll N,K;

ll merge_count(vector<ll> &a){
	int n = a.size();
	if(n<=1) return 0;
	ll cnt = 0;
	vector<ll> b(a.begin(),a.begin() + n/2);
	vector<ll> c(a.begin() + n/2, a.end());
	cnt += merge_count(b);
	cnt += merge_count(c);
	int ai = 0,bi = 0,ci = 0;
	while(ai<n){
		if(bi<b.size() && (ci == c.size() || b[bi] <= c[ci])){
			a[ai++] = b[bi++];
		}else{
			cnt += n/2 - bi;
			a[ai++] = c[ci++];
		}
	}
	return cnt;
}

int main(){
	cin >> N >> K;
	vector<ll> A(N+1);
	A[0] = 0;
	for(int i=1;i<=N;i++){
		cin >> A[i];
		A[i] -= K;
		A[i] += A[i-1];
	}
	cout << N*(N+1)/2 - merge_count(A) << endl;
}



Measured memory_bytes: 5368
def Otoshidama(n , y):

    for i in range(n + 1):
        for w in range(n - i + 1):
            if (10000*i) + (5000*w) + (1000*(n - (i + w))) == y:
                return str(i) + " " + str(w) + " " + str(n - (i + w))

    return "-1 -1 -1"

def main():
    n , y = map(int , input().split())
    print(Otoshidama(n , y))

if __name__ == '__main__':
    main()

Measured memory_bytes: 38768
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define pi acos(-1.0)
#define lowbit(x) ((x)&(-(x)))
#define debug(x) cout<<x<<'\n'
#define pii pair<ll,pair<ll,ll> >
using namespace std;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
//const ll mod = 1e9+7;
ll mod;
const double eps = 1e-6;
ll gcd(ll a, ll b) {return b==0?a:gcd(b, a%b);}
ll lcm(ll a, ll b) {return a/gcd(a, b)*b;}
ll mul(ll a,ll b){ll ans=0;a%=mod,b%=mod;while(b) { if(b&1) ans = (ans+a)%mod; a = (a*2)%mod; b >>= 1; }return ans;}
ll powmod(ll a,ll b){ ll ans = 1, pow = a; while(b) { if(b&1) ans = (ans*pow)%mod; pow = (pow*pow)%mod; b >>= 1; } return ans;}
//(b/a)%p=b*a^(p-2)%p
int pr(ll num){//判素
     if(num == 1) return 0;
     if(num ==2|| num==3 ) return 1 ;
     if(num %6!= 1&&num %6!= 5) return 0 ;
     int tmp =sqrt( num);
     for(int i= 5;i <=tmp; i+=6 )
          if(num %i== 0||num %(i+ 2)==0 )return 0 ;
     return 1 ;
}
int Day(int y,int m, int d){if(m==1||m==2) { m+=12; y--; }int w=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;return w+1;}
int pri[1000005];
void getpri(){
    memset(pri,true,sizeof(pri));
    pri[0]=pri[1]=0;
    for(int i=2;i<=1000000;i++){
        if(pri[i]){
            for(int j=2*i;j<=1000000;j+=i)pri[j]=0;
        }
    }
}
inline int read() {
    int c = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        c = c * 10 + ch - '0';
        ch = getchar();
    }
    return c * f;
}
//int pre[100005];
//void init(){
//    for(int i=1; i<=100005;++i) pre[i]=i;
//}
//int getf(int x){
//    if(pre[x] == x) return x;
//    else return pre[x] = getf(pre[x]);
//}
//void join(int x,int y){
//    int a = getf(x);
//    int b = getf(y);
//    if(a!=b) pre[b]=a;
//}
//大小写转换
//String s;
//Form(s.begin(),s.end(),s.begin(),::toupper);
//Form(s.begin(),s.end(),s.begin(),::tolower);
//(char)toupper('a')
//(char)tolower('B')
//#pragma comment(linker, "/STACK:1024000000,1024000000")//外挂开栈
//stable_sort 排序不处理相同元素
//map<int,int>::reverse_iterator rit;
//for(rit=mp.rbegin();rit!=mp.rend();rit++)
//vec动态二维数组
//vector<vector<int>> g(26,vector<int>(100005));
//初始化vec里面套了n个vec
//lower_bound(begin,end,num) 有序数列中返回第一个>=num的数字的地址
//upper_bound( begin,end,num) 返回第一个>num的数字的地址
const int maxn=3e5+5;
int main(){
    IO;
    ll x;
    cin>>x;
    ll ans=0;
    map<ll,ll> mp;
    for(ll j=2; j*j<=x;++j) {
        while(x%j == 0) {
            mp[j]++;
            x/=j;
        }
    }
    if(x>1) mp[x]++;
    if(mp.empty()){
        cout<<0<<endl;
    }
    else{
        for(auto i:mp){
            for(ll j=1;j<=10000;++j){
                if((1+j)*j/2>i.second){
                    ans+=j-1;
                    break;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

using namespace std;

char ch[2010][2010];

int n;

bitset <2010> B[2010], C[2010];

bitset <2010> Ans[2010];

int main() {
	scanf("%d", &n);
	for(int i = 2; i <= n; i++) scanf("%s", ch[i] + 1);
	for(int i = 2; i <= n; i++)
		for(int j = 1; j < i; j++)
			(B[i][j] = ch[i][j] - '0'), B[j][i] = !B[i][j];
	for(int i = 1; i <= n; i++) Ans[i][i] = 1;
	for(int i = 1; i < n; i++) {
		C[i][i + 1] = B[i][i + 1];
		C[i + 1][i] = B[i + 1][i];
		if(B[i][i + 1]) Ans[i + 1][i] = 1; else Ans[i][i + 1] = 1;
	}
	for(int i = 2; i <= n; i++)
		for(int j = 1; i + j <= n; j++) {
			int l = j, r = i + j;
			C[l][r] = B[l][r];
			C[r][l] = B[r][l];
			bitset <2010> tmp = C[l] & Ans[l + 1] & Ans[r];
			Ans[r][l] = !!tmp.count();
			tmp = C[r] & Ans[l] & Ans[r - 1];
			Ans[l][r] = !!tmp.count();
		}
	int tot = 0;
	for(int i = 1; i <= n; i++) tot += Ans[1][i] && Ans[n][i];
	printf("%d\n", tot);
	return 0;
}

Measured memory_bytes: 5632
N,M=map(int,input().split())
data=[]
for i in range(N):
    data.append([int(j) for j in input().split()])

data.sort(key=lambda x: x[0])

i=0
sum_num=0
for j in range(len(data)):
    sum_num=sum_num+data[j][1]
    if M<=sum_num:
        break
    i=i+1
num=sum_num-M
ans=0
for k in range(i):
    ans=data[k][0]*data[k][1]+ans
ans=data[i][0]*(data[i][1]-num)+ans
print(ans)

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

int main(){
    string s; cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

string s[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};

int main(){
    string t; cin>>t;
    int day=-1;
    rep(i,0,7)if(s[i]==t)day=i;
    printf("%d\n",7-day);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>

using namespace std;


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



int main() {
	
	ll n;

	cin >> n;

	vector<ll>b(n);

	rep(i, n - 1)cin >> b[i];

	ll ans = 0;

	ans += b[0];

	for (ll i = 0; i < n - 1; i++) {

		if (b[i] >= b[i + 1])ans += b[i + 1];
		else ans += b[i];
	}

	ans += b[n - 2];

	cout << ans;

	return 0;
}


Measured memory_bytes: 256
A, B, C, D, E, F = list(map(int, input().split()))
 
water = [1]
for i in range(30):
	water.append(0)
 
for i in range(31):
	if water[i] == 1:
		if (i + A) * 100 <= F:
			water[i + A] = 1
 
		if (i + B) * 100 <= F:
			water[i + B] = 1
 
K = []
 
for i in range(1, 31):
	if water[i] == 1:
		sugar = [1]
		X = min(i * E, F - 100 * i)
		for j in range(X):
			sugar.append(0)
 
		for j in range(X + 1):
			if sugar[j] == 1:
				if j + C <= X:
					sugar[j + C] = 1
 
				if j + D <= X:
					sugar[j + D] = 1
		sugar.reverse()
		s = sugar.index(1)
		WS = ((100 * (X - s) / (100 * i + X - s)), 100 * i + X - s, X - s)
		K.append(WS)
 
K = sorted(K)
print(K[-1][1], K[-1][2])

Measured memory_bytes: 3064
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
 
sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
A = list(map(int, input().split()))

dp = [{} for _ in range(N + 1)]
dp[0] = {0: 0}
dp[1] = {0: 0, 1: A[0]}

for i in range(2, N + 1):
    for j in range(max(0, i // 2 - 2), min(N, i // 2 + 2) + 1):
        candidates = []
        if j - 1 in dp[i - 2]:
            candidates.append(dp[i - 2][j - 1] + A[i - 1])
        if j in dp[i - 1]:
            candidates.append(dp[i - 1][j])
        if len(candidates) > 0:
            dp[i][j] = max(candidates)

print(dp[N][N // 2])

Measured memory_bytes: 123364
#include <bits/stdc++.h>
#define ll long long
#define BUF 1e5
#define INF 1 << 30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

int main() {
    ll s;
    cin >> s;
    ll a, b, c, d;
    N = sqrt(s);
    if (N * N == s) {
        a = N;
        d = N;
        b = 0;
        c = 0;
    } else {
        N++;
        ll tmp = N * N - s;
        if (tmp > N) {
            a = N;
            d = N - 1;
            b = 1;
            c = (tmp - N);
        } else {
            a = N;
            d = N;
            b = 1;
            c = tmp;
        }
    }
    cout << 0 << " " << 0 << " " << a << " " << b << " " << c << " " << d << endl;
}

Measured memory_bytes: 256
def ascan; gets.split.map(&:to_i); end

dic = {}
last = nil
gets.to_i.times do
    str = gets.chomp
    if dic[str]
        puts "No"; exit
    end
    if last && last[-1] != str[0]
        puts "No"; exit
    end
    last = str
    dic[str] = true
end

puts "Yes"

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int n, a[N];

void solve()
{
    cin >> n;
    for (int i=1; i<=2*n; i++) cin >> a[i];
    sort(a+1,a+2*n+1);
    int ans=0;
    for (int i=1;i<=2*n;i+=2)ans+=a[i];
    nout(ans);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n,m;

ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}

map<ll,char> mp;

int main(void){
	string s,t;
	scanf("%lld%lld",&n,&m);
	cin >> s;
	cin >> t;
	ll g=n*m/gcd(n,m);
	bool flag=true;
	for(int i=0;i<n;i++){
		mp[g/n*i]=s[i];
	}
	for(int j=0;j<m;j++){
		if(mp.find(g/m*j)==mp.end()){
			continue;
		}else{
			if(mp[g/m*j]!=t[j]){
				flag=false;
			}
		}
	}
	if(flag){
		printf("%lld\n",g);
	}else{
		printf("-1\n");
	}
	return 0;
} 

Measured memory_bytes: 6144
import itertools

def calc(n):
    for op in itertools.product(operators, repeat=3):
        for form in forms:
            formula = form.format(op[0], op[1], op[2], n[0], n[1], n[2], n[3])
            if eval(formula) == 10:
                print(formula)
                return True
    return False

operators = ("+", "-", "*")

forms = (
  "(({3}{0}{4}){1}{5}){2}{6}",
  "({3}{0}{4}){1}({5}{2}{6})",
  "({3}{0}({4}{1}{5})){2}{6}",
  "{3}{0}(({4}{1}{5}){2}{6})",
  "{3}{0}({4}{1}({5}{2}{6}))",
)

while (True):
    nums = tuple(map(int, input().split()))
    if nums == (0,0,0,0):
        break
    for n in itertools.permutations(nums):
        if calc(n):
            break
    else:
        print(0)

Measured memory_bytes: 7796
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }


int main(){
    long long a, b, c, d;
    cin >>a >> b >> c >> d;

    long long ans = 0;
   ans = max(max(max(a*c,b*c),d*a),b*d);

    cout << ans << endl;


}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())

using namespace std;

// 最大公約数
int64_t gcd(int64_t a, int64_t b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
int64_t lcm(int64_t a, int64_t b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
  int64_t n;
  cin >> n;
  int64_t h;
  int64_t mx= 0;
  int t = 0;
  REP(i,n){
    cin >> h;
    if (h >= mx){
      t++;
      mx = h;
    }
  }
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 256
// B - Resale
#include <bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<(n);i++)

int in(){int x;cin>>x;return x;}

int main(){
	int N; cin>>N;
	vector<int> V(N); rp(i,N) cin>>V[i];
	int ans = 0; rp(i,N) ans += max(0, V[i]-in());
	cout<< ans <<endl;
}

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

using namespace std;

long long N;
long long sum = 0;

int main()
{
	scanf("%lld", &N);
	long long X = N;
	while(X) {
		sum += X % 10;
		X /= 10;
	}
	// cerr << sum << " ";
	if(N % sum == 0) {
		// cerr << N << " " << sum << " ";
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    int a,b;
    cin>>a>>b;
    if(a>b){
        rep(i,a) printf("%c", '0'+b);
        printf("\n");
    }
    else{
        rep(i,b) printf("%c",'0'+a);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		x--;
		p[x] = i;
	}
	vector<long long> a(n), b(n);
	for (int i = 0; i < n; i++) {
		a[i] = b[n - 1 - i] = (i + 1) * 30000;
	}
	for (int i = 0; i < n; i++) {
		b[i] += p[i];
	}
	for (int i = 0; i < n; i++) {
		if (i > 0) cout << " ";
		cout << a[i];
	}
	cout << '\n';
	for (int i = 0; i < n; i++) {
		if (i > 0) cout << " ";
		cout << b[i];
	}
	cout << '\n';
	return 0;		
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

int main()
{
	int a, b; cin >> a >> b;
	reps(i, 3)if (i != a && i != b)co(i);
	return 0;
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;
using PP = pair<double, P>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N, M;
	vector<P> ab;

	cin >> N >> M;
	ab.resize(N);
	for(int i = 0; i < N; i++)
		cin >> ab[i].first >> ab[i].second;

	sort(BE(ab));
	llong ans = 0;
	for(int i = 0; i < N && M; i++){
		ans += min(ab[i].second, M)*ab[i].first;
		M -= min(ab[i].second, M);
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
    //
    //  リーダーより左にいる人は東 (W) になる
    //  リーダーより右にいる人は西 (E) を向く
    //
    //  つまり、Sをループし、その人がリーダーで
    //  あった場合に、以下の人数を数え、その最小値
    //  を求めればよい
    //
    //  * リーダーの左の人が E の人
    //  * リーダーの右の人が W の人
    //
    //  上記それぞれの値は、EとWの数の累積和を使う
    //  ことで求めることが出来る
    //

    int N;
    string S;
    cin >> N >> S;

    vector<int> warr;
    vector<int> earr;

    int esum = 0;
    int wsum = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'E') {
            esum++;
        } 
        if (S[i] == 'W') {
            wsum++;
        } 
        warr.push_back(wsum);
        earr.push_back(esum);
    }

    int64_t ans = INT_MAX;
    for (int j = 0; j < N; j++) {
        //
        //  s[j] がリーダー
        //

        //  自分より左でWの人
        int w = warr[j];
        if (S[j] == 'W') {
            w--;
        }
        //  自分より右でEの人
        int e = earr[earr.size() - 1] - earr[j];

        int64_t tmp_ans = w + e;
        if (tmp_ans < ans) {
            ans = tmp_ans;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3960
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#ifdef _DEBUG
#define dd(x) cout << #x << " : " << x << endl
#else
#define dd(x)
#endif
using namespace std;
using ll = int64_t;

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

    ll ans = 0;
    for(ll i = 1; i <= n; i++) {
        ll tmp = n/i;
        ans += i*tmp*(tmp+1)/2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	K, S := nextInt(), nextLine()
	if len(S) > K {
		fmt.Println(S[:K] + "...")
	} else {
		fmt.Println(S)
	}
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


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

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MOD 1000000007
#define INF 100100100

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

int n, m;
vector<int> state;

void init(){
  state = vector<int>(n, -1);
  state[0] = 1;
}

bool give(int from){
  if(state[from] == 1){
    state[from] = 0;
    return true;
  }else if(state[from] >= 2){
    state[from]--;
    return true;
  }else{
    state[from]++;
    return false;
  }
  // if(state == 3)
}

void given(int to, int is_red){
  if(is_red){
    if(state[to] == 0) state[to] = 1;
    else state[to] = abs(state[to]) + 1;
    // else state[to] = 2;
  }else{
    if(state[to] == 1) state[to] = 2;
    else if(state[to] > 1) state[to]++;
    else state[to]--;
  }
}


int main(){
  cin >> n >> m;
  vector<p> v(m);
  init();

  int res = 0;
  for (int i = 0; i < m; i++) {
    cin >> v[i].first >> v[i].second;
    v[i].first--; v[i].second--;
    int from = v[i].first;
    int to = v[i].second;
    bool is_red = give(from);
    // print(state);
    // if(state[from] == 0 && is_red) res--;
    given(to, is_red);
    // print(state);
  }

  for(auto a : state){
    if(a >= 1) res++;
  }
  cout << res << endl;
}


Measured memory_bytes: 1408
#include <stdio.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}else if(a>b){
		printf("a > b\n");
	}else{
		printf("a == b\n");
	}

	
	
	return 0;
} 


Measured memory_bytes: 2052
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let K: usize = sc.get();
    if K > (N-1)*(N-2)/2 {
        println!("-1");
        return;
    }
    let mut e = Vec::new();
    for i in 2..=N {
        e.push((1, i));
    }
    let mut x = (N-1)*(N-2)/2;
    if x == K {
        println!("{}", e.len());
        for &(i, j) in &e {
            println!("{} {}", i, j);
        }
        return;
    }
    for i in 2..=N-1 {
        for j in i+1..=N {
            e.push((i, j));
            x -= 1;
            if x == K {
                println!("{}", e.len());
                for &(i, j) in &e {
                    println!("{} {}", i, j);
                }
                return;
            }
        }
    }
}


Measured memory_bytes: 2172