akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstdlib>
#include <climits>
#define INF (1<<29)

using namespace std;
int minDis[201][201];
int city[9];
int n,m;
int r;
int a,b,c;
int res=INF;
bool used[9];

/*
int dfs(int x)
{
    int tmp;
    if(x==r){
        tmp = 0;
        for
    }
    return min(tmp,dfs(x+1));
}
*/
void floyd()
{
    /*
    for(int i = 1;i<=n;i++)
        for(int j = 1;j<=n;j++){
            minDis[i][j] = min(edge[i][j],minDis[i][j]);
        }
        */
    for(int k = 1;k<=n;k++)
        for(int i = 1;i<=n;i++)
            for(int j = 1;j<=n;j++)
                if(minDis[i][j]>minDis[i][k]+minDis[k][j])
                    minDis[i][j] = minDis[i][k]+minDis[k][j];
}
/*
void printall()
{
    cout<<"--------"<<endl;
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=n;j++){
            cout<<edge[i][j]<<" ";
        }
        cout<<endl;
    }
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=n;j++){
            cout<<minDis[i][j]<<" ";
        }
        cout<<endl;
    }
}
*/
void dfs(int c,int las,int dist) {
    //cout<<c<<" "<<las<<" "<<dist<<endl;
    if(c==r+1) {
if(res>dist)res=dist; return;
}
for(int i=1;i<=r;i++)if(!used[i]) {
              used[i]=true; if(las==-1)dfs(c+1,i,0);
else dfs(c+1,i,dist+minDis[city[las]][city[i]]); used[i]=false;
        }
  }
int solve()
{
    floyd();
    //printall();
    /*
    sort(city,city+r);
    int R = INF;
    int tmp;
    do{
        tmp = 0; 
        for(int i = 0;i<r-1;i++){
            //cout<<city[i]<<" ";
            tmp+=minDis[city[i]][city[i+1]];
        }
        //cout<<endl;
        R = min(R,tmp);
    }while(next_permutation(city,city+r));
    return R;
    */
    dfs(1,-1,0);
    return res;

}
int main()
{
    for(int i = 0;i<201;i++)
        for(int j = 0;j<201;j++)
            if(i!=j)minDis[i][j] = INF;

    cin>>n>>m>>r;
    for(int i=1;i<=r;i++)cin>>city[i];
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        minDis[a][b] = minDis[b][a] = min(c,minDis[a][b]);
    }
    int res = solve();
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 384
import java.math.BigDecimal;
import java.util.*;

public class Main {

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

    void run() {
        //入力
    	Scanner sc = new Scanner(System.in);
    	int val = sc.nextInt();
    	double sum = 0;
    	for(int i =1; i <= val; i++) {
    		if(i % 3 != 0 && i % 5 !=0) {
    			sum += i;
    		}
    	}
    	System.out.println(BigDecimal.valueOf(sum).setScale(0).toPlainString());
    }
}

Measured memory_bytes: 36240
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

int64_t absi(int64_t a) {
    return (a > 0) ? a : (a * -1);
}

int main()
{
    int64_t N;
    std::cin >> N;

    int64_t S = 0;
    std::vector<int64_t> a;
    for (int64_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        S += t;
        a.push_back(t);
    }

    int64_t minDiff = INT64_MAX;
    int64_t x = a[0];
    int64_t y = S - a[0];
    for (int64_t i = 1; i < N; ++i) {
        minDiff = std::min(minDiff, absi(x - y));
        x += a[i];
        y -= a[i];
    }

    std::cout << minDiff << std::endl;

    return 0;
}


Measured memory_bytes: 2420
import sys


class Paper:
    def __init__(self):
        self.paper = [[0 for x in range(10)] for y in range(10)]

    def white_space(self):
        s = 0
        for x in range(10):
            for y in range(10):
                if self.paper[x][y] == 0:
                    s += 1
        return s

    def most_dark(self):
        s = 0
        for x in range(10):
            for y in range(10):
                if self.paper[x][y] > s:
                    s = self.paper[x][y]
        return s

    def drop(self, x, y, size):
        r = []
        if size == 1:
            r.append((x,y))
            r.append((x-1,y))
            r.append((x+1,y))
            r.append((x,y-1))
            r.append((x,y+1))
        elif size == 2:
            r = [(i,j) for i in range(x-1, x+2) for j in range(y-1, y+2)]
        elif size == 3:
            r = [(i,j) for i in range(x-1, x+2) for j in range(y-1, y+2)]
            r.append((x-2, y))
            r.append((x+2, y))
            r.append((x, y-2))
            r.append((x, y+2))
        else:
            pass
#        print r
        r = filter(self.out_of_paper, r)
#        print r
        try:
            for p in r:
                self.paper[p[0]][p[1]] += 1
        except:
            pass
        return self

    def out_of_paper(self, p):
        if 0 <= p[0] < 10 and 0 <= p[1] < 10:
            return True
        else:
            return False



paper = Paper()
for line in sys.stdin:
    (x, y, size) = tuple(map(int, line.split(',')))
    paper.drop(x, y, size)
print paper.white_space()
print paper.most_dark()

Measured memory_bytes: 4280
import itertools
s = ""
def satisfy(p, q, r):
	global s
	f = s.replace("P", str(p)).replace("Q", str(q)).replace("R", str(r))
	while len(f) > 1:
		f = f.replace("-0", "2").replace("-1", "1").replace("-2", "0")
		for x, y in itertools.product(xrange(3), repeat=2):
			f = f.replace("(%d*%d)" % (x, y), str(min(x, y)))
			f = f.replace("(%d+%d)" % (x, y), str(max(x, y)))
	return f == "2"
while True:
	s = raw_input()
	if s == ".": break
	count = 0
	for p, q, r in itertools.product(xrange(3), repeat=3):
		if satisfy(p, q, r):
			count += 1
	print count

Measured memory_bytes: 5128
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	int a,b;
	cin>>a>>b;
	if(a>b)
	{
		for(int t=b+1;t<a;t++)
		{
			if(a-t==t-b)
			{
				cout<<t;
				return 0;
			}
		}
	}
	if(a<b)
	{
		for(int t=a+1;t<b;t++)
		{
			if(b-t==t-a)
			{
				cout<<t;
				return 0;
			}
		}
	}
	cout<<"IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

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

        int n = sc.nextInt();

        int[] a = new int[n];
        for (int i=0; i<n; ++i) {
            a[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        int counter = 0;
        int m = 0;

        for (int i=0; i<q; ++i) {
            m = sc.nextInt();
            if (Arrays.binarySearch(a, m) >= 0) {
                counter += 1;
            }
        }
        System.out.println(counter);
    }
}


Measured memory_bytes: 81316
#include <cstdio>
#include <algorithm>

#define ll long long
#define MAXN 50

ll d[MAXN+2][MAXN * MAXN + 2];

int main() {
    int n, a, x;
    ll rez = 0;

    scanf("%d%d", &n, &a);
    d[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &x);
        for (int nr = i - 1; nr >= 0; nr--)
            for (int sum = 0; sum <= nr * MAXN; sum++)
                d[nr + 1][sum + x] += d[nr][sum];
    }
    for (int i = 1; i <= n; i++)
        rez += 1LL*d[i][i * a];
    printf("%lld", rez);
    return 0;
}


Measured memory_bytes: 768
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void file(){
#ifndef ONLINE_JUDGE
	freopen("a_input.txt", "r", stdin);
	freopen("a_output.txt", "w", stdout);
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int dx[] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
vector <vector < char >> adj;
vector<vector<bool>>mem;
ll sum2 = 0,sum1=0;
int n, m;
bool valied(int i, int j){
	return i >= 0 && j >= 0 && i < n&&j < m;
}
void dfs(int i, int j, char c){
	if (adj[i][j] != c)return;
	mem[i][j] = 1;
	if (c == '#')c = '.',sum1++;
	else c = '#',sum2++;
	for (int k = 0; k < 4; k++){
		int x = dx[k] + i;
		int y = dy[k] + j;
		if (valied(x, y)&&!mem[x][y])
			dfs(x, y, c);
	}
}
int main(){
	//file();
	fast();
	cin >> n >> m;
	adj = vector<vector<char>>(n, vector<char>(m));
	for (int i = 0; i < n; i++)
	for (int j = 0; j < m; j++)
		cin >> adj[i][j];
	long long sum = 0;
	mem = vector<vector<bool>>(n, vector<bool>(m, 0));
	for (int i = 0; i < n; i++)
	for (int j = 0; j < m; j++)
	if (adj[i][j] == '#'&&!mem[i][j]){
		sum2 = 0;
		sum1 = 0;
		dfs(i, j, '#');
		sum += sum2*sum1;
	}
	cout << sum;
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
 
#define pi 3.1415926535

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

  vector<int> p(n);

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

  sort(p.begin(), p.end());

  ll sum = 0;

  for(int i = 0; i < k; i++){
    sum += p[i];
  }

  cout << sum << endl;

  return 0; 
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;


int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   long int n,m;
   cin>>n>>m;

   vector<long int> val(n);
   for(long int i = 0; i < n; i++)
      cin>>val[i];

   vector<vector<long int>> v(n);

   for(long int i = 0; i < m; i++){
    long int a,b;
    cin>>a>>b;
    v[a-1].push_back(b-1);
    v[b-1].push_back(a-1);
   }

   long int ans = 0;

   for(long int i = 0; i < n; i++){
      long int myHeight = val[i];
      bool done = true;
      for(auto ele : v[i]){
        if(myHeight <= val[ele]){
          done = false;
          break;
        }
      }
      ans += done;
   }

   cout<<ans;

   return 0;
}

Measured memory_bytes: 9800
import sys

n, *p = map(int, sys.stdin.read().split())
p = [None] + p + [None]

def main():
    cnt = 0
    i = 0
    while i <= n:
        if p[i] == i:
            cnt += 1
            if p[i+1] == i + 1:
                i += 1
        i += 1
    
    return cnt

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 14068
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s1, s2;
    cin >> s1 >> s2;
    int ans = 0;
    for (int i = 0; i < 3; i++)
    {
        if(s1[i] == s2[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>
int main(){
    int i;
    char w[1201];
    for( i = 0 ; ; i += 1 ){
        scanf("%c",&w[i]);
        if( w[i] == '\n' ){
            break;
        }
        else{
            if( islower( w[i] ) == 0 ){
                w[i] = tolower( w[i] );
            }
            else if( isupper( w[i] ) == 0 ){
                w[i] = toupper( w[i] );
            }
        }
    }
    for( i = 0 ; ; i += 1 ){
        if( w[i] == '\n' ){
            printf("\n");
            break;
        }
        else{
            printf("%c",w[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair

int main(){
    ios_base::sync_with_stdio(0);
    int n;
    string x;
    cin>>n>>x;
    for(int i=0;i<x.size();i++){
        x[i]+=n;
        if(x[i]>'Z')
            x[i]='A'+(x[i]-'Z'-1);
    }
    cout<<x;
    return 0;
    }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        
        var sc = new Scanner(System.in);
    
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        
        boolean flag = false;
        for(int i = 0; i <= x; i++){
            if(i*2 + (x-i)*4 == y){
                flag = true;
                break;
            }
        }
        System.out.println(flag ? "Yes" : "No");
    }
}

Measured memory_bytes: 35664
l = list(map(int, input()))
mod = 10 ** 9 + 7

ln = len(l)
dp = [0] * 2
dp[1] = 1

for e in l:
    dp_new = [0] * 2
    # exact -> exact
    dp_new[1] += dp[1] * (e + 1)

    # exact -> small
    if e == 1:
        dp_new[0] += dp[1]

    # small -> small
    dp_new[0] += dp[0] * 3

    dp = dp_new
    for i in range(2):
        dp[i] %= mod

ans = sum(dp) % mod

print(ans)


Measured memory_bytes: 3956
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define ll long long
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
int x[1010];
int y[1010];
int len[33];
ll Abs(ll x){if(x < 0) return -x; return x;}
int main() {
	int n = read();
	for(int i = 1; i <= n; i++)
		x[i] = read(), y[i] = read();
	int tmp = Abs(x[1] + y[1]) & 1;
	for(int i = 1; i <= n; i++)
		if((Abs(x[i] + y[i]) & 1) != tmp)
			return puts("-1"), 0;
	printf("%d\n1", 32 - tmp);
	len[1] = 1; int N = 1;
	if(tmp) {
		for(int i = 1; i <= 30; i++) printf(" %d", len[++N] = 1 << i);
		puts("");
	} else {
		for(int i = 0; i <= 30; i++) printf(" %d", len[++N] = 1 << i);
		puts("");
	} char s[40];
	memset(s, 0, sizeof(s));
	for(int i = 1; i <= n; i++) {
		ll nx = 0, ny = 0;
		for(int j = N; j; --j) {
			ll dx = x[i] - nx, dy = y[i] - ny;
			if(Abs(dx) > Abs(dy)) {
				if(dx > 0) nx += len[j], s[j] = 'R';
				else nx -= len[j], s[j] = 'L';
			} else {
				if(dy > 0) ny += len[j], s[j] = 'U';
				else ny -= len[j], s[j] = 'D';
			}
		} printf("%s\n", s + 1);
	}
	return 0;
}

Measured memory_bytes: 256
N, T = map(int, input().split())
t = list(map(int, input().split()))
hotwater = 0
ans = 0

for i in t:
    if hotwater < i:
        ans += T
        hotwater = i + T
    else:
        ans += i - (hotwater - T)
        hotwater = i + T

print(ans)

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

int main() {
  int a,b;
  cin >> a >> b;
  int m =a%2;
  int n =b%2;
  if (m != 0 && n !=0) {
    cout << "Odd" << endl;
  }else{
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#
# abc082 a
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1 3"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """7 4"""
        output = """6"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5 5"""
        output = """5"""
        self.assertIO(input, output)


def resolve():
    a, b = map(int, input().split())
    print((a+b+1)//2)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16196
# https://abc100.contest.atcoder.jp/tasks/abc100_c

n = a=int(input()) #つかわない
li = list(map(int,input().split()))

ans = 0
for num in li:
	while True:
		if num % 2 == 0:
			ans += 1
			num /= 2
		else:
			break

print(ans)


Measured memory_bytes: 4148
S = input()

cnt = 0
max_ans = 0
for s in S:
    if s in 'A' or s in 'C' or s in 'G' or s in 'T':
        cnt += 1
    else:
        if cnt > max_ans:
            max_ans = cnt
            cnt = 0

print(max(cnt, max_ans))


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<cmath>
using ll = long long;
using namespace std;

int main()
{
    ll N, W; cin >> N >> W;
    vector<ll> v(N, 0); vector<ll> w(N, 0);
    for(int i = 0; i < N; i++) cin >> w.at(i) >> v.at(i);

    vector< vector<ll> >dp(N+1, vector<ll>(W+1, 0));
    for(int i = 0; i < N; i++)
    {
        for(int sum_w = 0; sum_w <= W; sum_w++)
        {
            if(sum_w - w.at(i) >= 0)
            {
                dp.at(i+1).at(sum_w) = max(dp.at(i+1).at(sum_w), dp.at(i).at(sum_w - w.at(i)) + v.at(i));
            }
            dp.at(i+1).at(sum_w) = max(dp.at(i+1).at(sum_w), dp.at(i).at(sum_w));
        }
    }
    cout << dp.at(N).at(W) << endl;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>                                                                          
using namespace std;
int main()
{
  string S;
  cin >> S;
  string a="abcdefghijklmnopqrstuvwxyz";
  sort(S.begin(),S.end());
  int count=0;
  int ans=0;
  for(int i=0; i<26; i++){
    for(int j=0; j<S.size(); j++){
      if(a.at(i)==S.at(j))
        count++;
    }
    if(count!=0)
      ans++;
    else if(count==0){
      cout << a.at(i) << endl;
      break;
    }
    count=0;
  }
  if(ans==26)
    cout << "None" << endl;
}

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

int cmp(const void *p,const void *q){
  return *(int *)p - *(int *)q;
}

int main(void){
  int n,k,i,q,j=0,s=0,m=0;
  int a[300000],b[300000],c[300000];

  for(i=0;i<200000;i++){ a[i]=0; b[i]=0;}

  scanf("%d %d",&n,&k);

  for(i=0;i<n;i++){
    scanf("%d",&q);
    if(a[q]==0){
      a[q]++; b[j]=q; j++;
    }
    else{
      a[q]++;
    }
  }

  for(i=0;i<j;i++){
    c[i]=a[b[i]];
  }

  qsort(c,j,sizeof(int),cmp);

  for(i=0;i<j-k;i++)
    s+=c[i];

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

  return 0;
}


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

int main() {
    ios::sync_with_stdio(0);
    int h,n;
    cin>>h>>n;
    int sum=0;  
    while(n--) {
        int x;
        cin>>x;
        sum+=x;
    }
    if(sum>=h) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}




Measured memory_bytes: 256
using System;

namespace E
{
    class E
    {
        static void Main()
        {
            Console.WriteLine(solver());
        }
        static long solver()
        {
            var N = long.Parse(Console.ReadLine());
            if ((N % 2) == 1) return 0;
            var result = 0L;
            var temp2 = 10L;
            result += N / 10;
            for (int i = 1; i <= 36; i++)
            {
                temp2 *= 5;
                result += N / temp2;
            }
            return result;
        }
    }
}


Measured memory_bytes: 13140
#include <algorithm>
#include <cstdio>

using namespace std ;

int main ()
{
	double res=0 ;
	int n , a , i ;
	scanf("%d",&n);
	for ( i=1 ; i<=n ; i++ ) scanf("%d",&a),res+=1.0/(double)(a);
	printf("%.6lf\n",1.0/res);
	return 0 ;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

int k = 0;
using Graph = vector<vector<int>>;
vector<bool> seen;
map<pair<int, int>, int> ans;

void dfs(const Graph &G, int v, int parent_color = 0) {
  seen[v] = true;
  int now_color = 1;
  for (auto next_v : G[v]) {
    if (seen[next_v]) continue;
    if (now_color == parent_color) now_color++;
    ans[make_pair(v, next_v)] = now_color;
    ans[make_pair(next_v, v)] = now_color;
    dfs(G, next_v, now_color);
    now_color++;
  }
}

int main() {
  int n;
  cin >> n;
  int cnt[100005] = {};
  vector<pair<int, int>> nodes;
  Graph G(n + 1);
  REP(i, n - 1) {
    int x, y;
    cin >> x >> y;
    nodes.push_back(make_pair(x - 1, y - 1));
    G[x - 1].push_back(y - 1);
    G[y - 1].push_back(x - 1);
    chmax(k, max(++cnt[x - 1], ++cnt[y - 1]));
  }
  cout << k << endl;
  seen.assign(n + 1, false);
  dfs(G, 0);
  for (auto p : nodes) {
    cout << ans[p] << endl;
  }
}


Measured memory_bytes: 22652
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,Q,a,b,e,ans;
  string S;
  char c,d;
  cin>>N>>S>>Q;
  unordered_map<char,set<int>> mp;
  for(int i=0;i<N;i++){
    mp[S.at(i)].insert(i);
  }
  for(int i=0;i<Q;i++){
    cin>>a;//1か2か
    if(a==1){
      cin>>b>>c;
      d=S.at(b-1);
      S.at(b-1)=c;
      mp[d].erase(b-1);
      mp[c].insert(b-1);
    }
    else{
      cin>>b>>e;
      ans=0;
      for(char j='a';j<='z';j++){
        if(mp[j].size()==0){continue;}
        auto it=mp[j].rbegin();
        if(*it<b-1){continue;}
        auto itr=mp[j].lower_bound(b-1);
        if(*itr<=e-1){ans++;}
      }
      cout<<ans<<endl;
    }
  }
}

Measured memory_bytes: 27240
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iostream>
#define N 100010
using namespace std;
int n, a[N];
int endp[N];

int val(int x, int y){
	if (x >= n) return true;
	if (y >= a[x]) return true;
	return endp[x] ^ ((a[x] - 1 - y) & 1);
}

int main(){
	int i;
	scanf("%d", &n);
	for (i = 0; i < n; ++ i){
		scanf("%d", &a[i]);
	}
	sort(a, a + n, greater<int>());
	endp[n - 1] = 0;
	for (i = n - 2; i >= 0; -- i){
		if (a[i] == a[i + 1]) 
			endp[i] = endp[i + 1] ^ 1;
		else endp[i] = 0;
	}
	int x = 0, y = 0;
	while (x < n - 1 && y + 1 < a[x + 1])
		x++, y++;
	if (!val(x, y + 1) || !val(x + 1, y))
		puts("First");
	else
		puts("Second");

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#define N 1000010
#define ls x << 1
#define rs x << 1 | 1
#define inf 0x3f3f3f3f
#define inc(i) (++ (i))
#define dec(i) (-- (i))
#define mid ((l + r) >> 1)
#define int long long
#define XRZ 1000000007
#define debug() puts("XRZ TXDY");
#define mem(i, x) memset(i, x, sizeof(i));
#define Next(i, u) for(register int i = head[u]; i ; i = e[i].nxt)
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout);
#define Rep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define Dep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))
int dx[10] = {1, -1, 0, 0};
int dy[10] = {0, 0, 1, -1};
using namespace std;
inline int read() {
    register int x = 0, f = 1; register char c = getchar(   );
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
int n, m, A[N], sum[4];
signed main() {
    n = read(), m = read();
    if(n < 2 && m < 2) puts("0");
    else printf("%lld", n * (n - 1) / 2 + m * (m - 1) / 2);
	return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
$a = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
	$a[$i] -= $i + 1;
}
sort($a);
$b = $a[$n/2];
$x = 0;
for ($i = 0; $i < $n; $i++) {
	$x += abs($a[$i] - $b);
}
echo $x;

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

namespace ProblemA
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var A = read[0];
            var B = read[1];

            if (A >= 13)
                Console.WriteLine(B);
            else if (A >= 6)
                Console.WriteLine(B / 2);
            else
                Console.WriteLine(0);
        }
    }
}


Measured memory_bytes: 11348
#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[i];

	long long money=1000;
	for(int i=0; i<n-1; ++i){
		long long stock=0;
		if(a[i]<a[i+1]) stock = money/a[i];
		money += stock*(a[i+1]-a[i]);
	}
	cout << money << endl;
}

Measured memory_bytes: 3560
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

//N以下のごちうさ数
void gotiusa() {
	//i桁目
	//N未満確定か
	//前5
	//前51
	//前51?
	//51?3を含む
	int dp[20][2][2][2][2][2] = {};
	string S; cin >> S;
	dp[0][0][0][0][0][0] = 1;
	rep(i, 0, S.size()) rep(j, 0, 2) rep(k, 0, 2) rep(p, 0, 2)rep(q, 0, 2)rep(r, 0, 2) {
		int lim = j ? 9 : S[i] - '0';
		//dump(i, j, k, p, q, r, dp[i][j][k][p][q][r]);
		rep(d, 0, lim + 1) {
			dp[i + 1][j || d < lim][d == 5][k && d == 1][p][(q&&d == 3) || r] += dp[i][j][k][p][q][r];
			//dump(i + 1, j || d < lim, d == 5, k && d == 1, p, (q&&d == 3) || r);
			//dump(dp[i + 1][j || d < lim][d == 5][k && d == 1][p][(q&&d == 3) || r]);
		}
	}
	int ans = 0;
	rep(j, 0, 2)rep(k, 0, 2)rep(p, 0, 2)rep(q, 0, 2)ans += dp[S.size()][j][k][p][q][1];
	cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	gotiusa();
	return 0;
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;

int main() {
  cpp_int N, A;
  cin >> N >> A;
  cpp_int ans = 1, lcm = A, mod = 1000000007;
  while (cin >> A) {
    auto gcd = __gcd(lcm, A);
    (ans *= A / gcd) %= mod;
    ans += lcm / gcd;
    lcm = lcm / gcd * A;
  }
  cout << ans % mod << "\n";
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n,m;
	scanf("%d%d\n",&n,&m);
	string s;
	while(n--)
	{
		cin>>s;
		cout<<s<<endl;
		cout<<s<<endl;
	}
	return 0;
}

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


typedef long long ll;
typedef unsigned long long ull;

using namespace std;

#define drobucs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main() {
	drobucs;
	
	map < char, int> mp;
	string s;
	cin >> s;

	for (int i = 0; i < 4; ++i) {
		mp[s[i]]++;
	}

	if (mp.size() == 2) {
		int cnt = 0;
		for (auto t : mp) {
			if (t.second == 2)cnt++;
		}
		if (cnt == 2) {
			cout << "Yes";
		}
		else {
			cout << "No";
		}
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
/*
2019/05/26
*/
//再帰呼び出し?
//A
int  main() {
  /* code */
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  REP(i,n){
    cin>>a[i];
  }
  int ans=0;
  REP(l,k+1){//l=0tok
    REP(r,k-l+1){//r=0tok-l
      if(l+r>n)continue;
      int d=k-l-r;//戻す数
      int now=0;
      vector<int> s;//取り出したものの集合
      REP(i,l){
        now+=a[i];
        s.push_back(a[i]);
      }
      FOR(i,n-r,n){
        now+=a[i];
        s.push_back(a[i]);
      }
      sort(s.begin(),s.end());
      REP(i,d){
        if(i>=s.size())break;
        if(s[i]>0)break;
        now-=s[i];
      }
      ans=max(ans,now);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
	int h, w;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int N = 1010;
char a[N][N];
int d[N][N], vis[N][N];
int main() {
	scanf("%d%d", &h, &w);
	for (int i = 1; i <= h; ++i)
		scanf("%s", a[i] + 1);
	queue<pair<int, int> > q;
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j)
			if (a[i][j] == '#') vis[i][j] = 1,q.push(make_pair(i, j));
	int ans = 0;
	while (!q.empty()) {
		int x = q.front().first, y = q.front().second;
		q.pop();
		ans = d[x][y];
		for (int i = 0; i < 4; ++i) {
			int nx = x + dx[i], ny = y + dy[i];
			if (!vis[nx][ny] && a[nx][ny] == '.') {
				vis[nx][ny] = 1;
				d[nx][ny] = d[x][y] + 1;
				q.push(make_pair(nx, ny));
			}
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 15376
import sys
input = sys.stdin.readline
from operator import itemgetter
import heapq

def main():
    n, m = list(map(int, input().strip().split()))
    v = list(map(lambda x: -x, map(int, input().strip().split())))
    q = []
    for item in v:
        heapq.heappush(q, item)
    for _ in range(m):
        p = heapq.heappop(q)
        # print(p)
        heapq.heappush(q, (p+1) // 2)
    print(-sum(q))

if __name__ == '__main__':
    main()


Measured memory_bytes: 63984
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int r, g; cin >> r >> g;
	cout << 2 * g - r << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int v[101][101];
int main(void){
    int n;
    cin >> n;
    int x,y,z;
    for(int i=1;i<=n;i++){
        cin >> x>>y;
        for(int j=1;j<=y;j++){
            cin >> z;
            v[i][z]=1;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(j!=n){
                cout << v[i][j]<<" ";
            }
            else{
                cout << v[i][j];
            }
        } 
        cout << endl;
    }
}



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

using namespace std;

int main() {
    int n;
    cin >> n;
    double sum = 0;
    for(int i=0;i<n;i++) {
        double f;
        string s;
        cin >> f >> s;
        if (s == "JPY") {
            sum += f;
        } else {
            sum += f * 380000;
        }
    }
    printf("%.8lf\n", sum);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }

template <typename T> inline T read(){
    T sum = 0;
    int fl = 1,ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') fl = -1;
    for(; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
    return sum * fl;
}

int a,b;

inline void Solve (){
	if(a >= 1 && a <= 9 && b >= 1 && b <= 9){
		printf("%d\n",a * b);
	}else printf("-1\n");
}

inline void Input (){
	a = read<int>();
	b = read<int>();
}

int main(){
	Input();
	Solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(int argc, const char *argv[]) {
  int N;
  cin >> N;
  string s;
  map<string, int> S;
  for (int i = 0; i < N; i++) {
    cin >> s;
    S[s]++;
  }
  cout << S.size() << endl;
  return 0;
}


Measured memory_bytes: 19120
#include <bits/stdc++.h>
        using namespace std;
         
        int main() {
          int n;
          int i=0;
          long long a;
          long long b=1;
          cin >> n;
          while(i<n){
          	cin >> a;
            if(a == 0){
              b = 0;
              break;
            }
            if(a>1000000000000000000/b || b<0){
              b = -1;
              break;
            }
            b *= a;
            i++;
          }
          while(i<n){
          	cin >> a;
            if(a == 0){
              b = 0;
              break;
            }
            i++;
            }
          cout << b << endl;
          }

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

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

    double ans = 0.0;

    for (auto i = 0; i < n; i++)
    {
        ans += double(1) / a[i];
    }

    cout << setprecision(16) << 1 / ans << endl;
}

Measured memory_bytes: 256
N = gets.to_i
Hi = gets.split.map(&:to_i)
Hi[0] -= 1 if Hi[0] > 1

result = 'Yes'
(N - 1).times do |i|
  current = i
  _next = i + 1

  next Hi[_next] -= 1 if Hi[current] <= Hi[_next] - 1
  next if Hi[current] <= Hi[_next]

  break result = 'No'
end

puts result

Measured memory_bytes: 8580
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

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

    ll h, w, k;
    cin >> h >> w >> k;

    vector<vector<ll>> grid(h, vector<ll>(w));
    for(int i = 0; i < k; ++i){
        ll r, c, v;
        cin >> r >> c >> v;
        --r;
        --c;
        grid[r][c] = v;
    }

    vector<vector<vector<ll>>> dp(h, vector<vector<ll>>(w, vector<ll>(4, 0)));
    dp[0][0][1] = grid[0][0];
    for(int j = 1; j < w; ++j){
        dp[0][j][0] = dp[0][j-1][0];
        dp[0][j][1] = max(dp[0][j-1][1], dp[0][j-1][0] + grid[0][j]);
        dp[0][j][2] = max(dp[0][j-1][2], dp[0][j-1][1] + grid[0][j]);
        dp[0][j][3] = max(dp[0][j-1][3], dp[0][j-1][2] + grid[0][j]);
    }

    for(int i = 1; i < h; ++i){
        ll mx_prev0 = max({dp[i-1][0][0], dp[i-1][0][1], dp[i-1][0][2], dp[i-1][0][3]});
        dp[i][0][0] = mx_prev0;
        dp[i][0][1] = mx_prev0 + grid[i][0];
        for(int j = 1; j < w; ++j){
            ll mx_prev = max({dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3]});
            dp[i][j][0] = max(mx_prev, dp[i][j-1][0]);
            dp[i][j][1] = max({mx_prev + grid[i][j], dp[i][j-1][1], dp[i][j-1][0] + grid[i][j]});
            dp[i][j][2] = max(dp[i][j-1][2], dp[i][j-1][1] + grid[i][j]);
            dp[i][j][3] = max(dp[i][j-1][3], dp[i][j-1][2] + grid[i][j]);
        }
    }

    cout << max({dp[h-1][w-1][0], dp[h-1][w-1][1], dp[h-1][w-1][2], dp[h-1][w-1][3]}) << endl;

    return 0;
}

Measured memory_bytes: 706368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int D=365;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));

ll calc(const vector<int>& t, int d, int q){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d){
      if(t[i]!=-1){
        res += s[i][t[i]];
        lst[t[i]] = i;
      }
    }
    else{
      res += s[i][q];
      lst[q]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  //cerr << res << '\n';
  return res;
}

ll calc2(const vector<int>& t, int d1, int d2){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d1 && i!=d2){
      res += s[i][t[i]];
      lst[t[i]] = i;
    }
    else if(i==d1){
      res += s[i][d2];
      lst[t[d2]]=i;
    }
    else if(i==d2){
      res += s[i][d1];
      lst[t[d1]]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  //cerr << res << '\n';
  return res;
}

int main(){
  /*
  ifstream in("input.in");
  cin.rdbuf(in.rdbuf());
  ofstream ofs("output.txt");
  cout.rdbuf(ofs.rdbuf());
  //*/
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
  mt19937 mt(184);
  cin >> D;
  rep(i,26) cin >> c[i];
  rep(y,D) rep(x,26) cin >> s[y][x];
  vector<int> t(D,-1);
  ll now = calc(t, -1, -1);
  rep(d,D){
    int k=-1;
    ll prenow=-1;
    rep(q,26){
      ll pre = calc(t,d,q);
      if(now < pre){
        if(mt()&1 || mt()&1 || mt()&1) {
          now = pre;
          t[d] = q;
        }
        if(k==-1) {k=q; prenow = pre;}
      }
      if(chmax(now,calc(t,d,q))){
        t[d]=q;
      }
      end = chrono::system_clock::now();
      double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
      if(ela>1900) break;
    }
    if(t[d]==-1) {
      t[d]=k;
      now = prenow;
    }
    // timer
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1900) break;
  }
  while(1){
    int d1=mt()%365, d2=mt()%365;
    if(d1==d2) continue;
    if(chmax(now,calc2(t,d1,d2))){
      int tmp = t[d1];
      t[d1]=t[d2];
      t[d2]=tmp;
    }
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1970) break;
  }
  rep(i,D) cout << t[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, n) for (int i = (a); i < (n); ++i)
using namespace std;
using ll = long long;
using uint = unsigned int;
const ll mod = (ll)1e9 + 7;

int main() {
  int n;
  cin >> n;
  map<int, int> lnum;
  set<int> ls;
  rep(i, n) {
    int l;
    cin >> l;
    lnum[l]++;
    ls.insert(l);
  }
  auto lend = ls.end();
  ll ans = 0;
  for (auto li = ls.begin(); li != lend; ++li)
    for (auto lj = ls.begin(); lj != lend; ++lj)
      for (auto lk = ls.begin(); lk != lend; ++lk) {
        if (!(*li < *lj && *lj < *lk)) continue;
        if (abs(*li - *lj) < *lk && *lk < *li + *lj) ans += lnum[*li] * lnum[*lj] * lnum[*lk];
      }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const auto INF = (ll)1e9;
using v = vector<int>;
using m = map<ll,int>;
using vv = vector<v>;
int main(){
    int n,m;
    cin >> n >> m;
    auto a = v(m,0);
    auto b = v(m,0);
    auto c = v(n,0);
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
        c[--a[i]]++;
        c[--b[i]]++;
    }

    for(auto i:c){
        cout << i <<endl;
    }

    return 0;
}


Measured memory_bytes: 256
from sys import stdin


def floor_sum(n, m, a, b):
    result = 0
    if a >= m:
        result += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        result += n * (b // m)
        b %= m

    yMax = (a * n + b) // m
    xMax = yMax * m - b
    if yMax == 0:
        return result
    result += (n - (xMax + a - 1) // a) * yMax
    result += floor_sum(yMax, a, m, (a - xMax % a) % a)
    return result


readline = stdin.readline

T = int(readline())

result = []
for _ in range(T):
    N, M, A, B = map(int, readline().split())
    result.append(floor_sum(N, M, A, B))
print(*result, sep='\n')


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

#define endl '\n'

int c[29];
int mi[9];

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

    int n, m;
    cin >> n >> m;
    memset(c, 0, sizeof c);
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for(int j = 0; j < m; j++) {
            c[s[j] - 'a']++;
        }
    }
    if(n % 2 == 1 && m % 2 == 1) {
        if(n < m)
            swap(n, m);
        mi[4] = (n / 2) * (m / 2);
        mi[2] = n / 2 + m / 2;
        mi[1] = 1;
    }
    else if(n % 2 == 1 || m % 2 == 1) {
        if(m % 2 == 1)      // n is odd
            swap(n, m);
        mi[4] = (n / 2) * (m / 2);
        mi[2] = m / 2;
        mi[1] = 0;
    }
    else {
        mi[4] = n * m / 4;
        mi[2] = 0;
        mi[1] = 0;
    }

    for(int i = 0; i < 26; i++) {
        if(mi[4] <= 0) break;
        while(c[i] >= 4) {
            if(mi[4] <= 0) break;
            c[i] -= 4;
            mi[4]--;
        }
    }
    if(mi[4] > 0) {
        cout << "No";
        return 0;
    }

    for(int i = 0; i < 26; i++) {
        if(mi[2] <= 0) break;
        while(c[i] >= 2) {
            if(mi[2] <= 0) break;
            c[i] -= 2;
            mi[2]--;
        }
    }
    if(mi[2] > 0) {
        cout << "No";
        return 0;
    }


    for(int i = 0; i < 26; i++) {
        if(mi[1] <= 0) break;
        while(c[i] >= 1) {
            if(mi[1] <= 0) break;
            c[i] -= 1;
            mi[1]--;
        }
    }
    // cout << mi[4] << endl;
    // cout << mi[2] << endl;
    // cout << mi[1] << endl;
    if(mi[1] > 0) {
        cout << "No";
        return 0;
    }
    cout << "Yes";

    return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	ll X,K,D;cin>>X>>K>>D;
	if(X<0)X=-X;
	if(K<=X/D){
		cout<<(X-D*K)<<endl;
		return 0;
	}
	else{
		K-=X/D;
		if(K%2==0)cout<<X%D<<endl;
		else cout<<abs(X%D-D)<<endl;
	}
}

Measured memory_bytes: 3624
/**
 * author:    Ziel
 * created:   15.04.2020 19:51:56
**/

// ~zaletaet~

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>

#define fi first
#define se second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define pb push_back

using namespace std;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const ll N = 1e5 + 123, MOD = 1e9 + 7, oo = 1e9 + 9, INF = 1e18 + 9;
const double EPS = 1e-9, PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	int r;
	cin >> r;
	cout << 2.0 * PI * r;

	return 0;
}




Measured memory_bytes: 3820
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

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

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class CWelcomeToAtCoder {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, m; cin >> n >> m;
      vector<int> wa(n+1);
      vector<int> penalty(n+1);
      vector<bool> ac(n+1);
      rep(i, m) {
        int p; cin >> p;
        string s; cin >> s;
        if (s == "WA") {
          wa[p]++;
        } else if (!ac[p]) {
          ac[p] = true;
          penalty[p] = wa[p];
        }
      }

      ll acsum = 0;
      ll pesum = 0;
      for(int i=1; i<=n; i++) {
        acsum += ac[i];
        pesum += penalty[i];
      }

      cout << acsum << ' ' << pesum << endl;


    }
};

signed main() {
  CWelcomeToAtCoder solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
#define INF 1e18
#define NINF -1e16

#define nax 10

void solve(){
	
	int n;
	cin>>n;
	int ans=0;
	rep(i,0,n){
		ans+= (i+1)*(n-i);
	}
	rep(i,0,n-1){
		int u,v;
		cin>>u>>v;
		u--,v--;
		int maxm = max(u,v);
		int minm=min(u,v);
		ans-=(minm+1)*(n-maxm);
	}
	cout<<ans<<endl;
	

}

signed main(){
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand (static_cast <unsigned> (time(0)));
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}

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

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

  string ans = "No";
  rep(i,1,9) if (N % i == 0 && N / i < 10) ans = "Yes";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256