akhauriyash/Code-Regression huggingface dataset:
# AOJ 0040: Affine Cipher
# Python3 2018.6.27 bal4u

M = 26
A = ord('a')

re_prime = [1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25]

def F(ch):
	global a, b
	x = ord(ch)-A
	return chr((a*x + b) % M + A)

dic = {}
for a in re_prime:
	for b in range(M):
		dic[F('t')+F('h')+F('i')+F('s')] = (a, b)
		dic[F('t')+F('h')+F('a')+F('t')] = (a, b)

n = int(input())
for i in range(n):
	s = list(input().split())
	for x in s:
		if len(x) == 4 and x in dic:
			a,b = dic[x]
			break
	tr = {}
	for i in range(M): tr[F(chr(i+A))] = chr(i+A)
	ans = []
	for x in s: ans.append(''.join([tr[c] for c in x]))
	print(*ans)



Measured memory_bytes: 5624
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<string>
#include<queue>
#include<deque>
#define INF 0x3f3f3f3f
using namespace std;
int main(){
	int a,b;
	int p[13]={2,3,4,5,6,7,8,9,10,11,12,13,1};
	while(cin>>a>>b){
		int A,B;
		for(int i=0;i<13;i++){
			if(p[i]==a){
				
				A=i;
				break;
			}
		}
		for(int i=0;i<13;i++){
			if(p[i]==b){
				B=i;
				break;
			}
		}
		if(A==B){
			printf("Draw\n");
		}else if(A>B){
			cout<<"Alice"<<endl;
		}else{
			cout<<"Bob"<<endl;
		}
		
	}
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N; cin >> N;

  vector<int> v(N);
  for(int i = 0; i < N; i++){
    cin >> v[i];
  }

  bool flg = true;
  for(int i = 0; i < N; i++){
    int sum = 0;
    for(int j = 0; j < N; j++){
      if(i == j) continue;

      sum += v[j];
    }
    if(v[i] >= sum){
      flg = false;
      break;
    }
    if(!flg) break;
  }
  cout << (flg ? "Yes" : "No") << endl;
  
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

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

int main() {
  int N;
  scanf("%d", &N);

  int r = 0;
  REP(i,N) {
    int a;
    scanf("%d", &a);
    r ^= (a&1);
  }
  printf(r ? "NO\n" : "YES\n");
}


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

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int a = input[0];
            int b = input[1];
            int c = input[2];

            if (a == b && a == c) Console.WriteLine(1);
            else if (a == b && a != c) Console.WriteLine(2);
            else if (a == c && a != b) Console.WriteLine(2);
            else if (b == c && a != b) Console.WriteLine(2);
            else Console.WriteLine(3);

        }
    }
}


Measured memory_bytes: 11348
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    if(a+b < 10){
        cout << a+b;
    }
    else
    {
        cout << "error";
    }
    cout << endl;
}


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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 200111, inf = 1000111222;

int n, k;
ll ans[max_n];

vector<ll> col[max_n];
vector<pair<ll, int>> v;
bool has_ch_left[max_n];
bool np[max_n];
bool has[max_n];

multiset<ll> r1; // that has pair in the left
multiset<ll> r2; // over all
multiset<ll> r3; // over all
multiset<ll> l1; // over all
multiset<ll> l2; // that has no child in the left

ll set_mx(const multiset<ll>& ms) {
    if (ms.empty()) {
        exit(228);
    }
    auto it = ms.end();
    --it;
    return *it;
}

void add2(int k) {
    vector<ll>& c = col[k];
    r2.erase(r2.find(c[0] + c[1]));
    if (c.size() > 2) {
        r3.erase(r3.find(c[0] + c[1] + c[2]));
    }
    for (int i = 2; i < c.size(); ++i) {
        r1.insert(c[i]);
    }
    l2.insert(c[0] + c[1]);
}

void add1(int k, ll val) {
    vector<ll>& c = col[k];
    r1.erase(r1.find(val));
    l1.insert(val);
    if (has_ch_left[k] == 0) {
        has_ch_left[k] = 1;
        l2.erase(l2.find(col[k][0] + col[k][1]));
    }
}

int main()
{
    //freopen("input.txt", "r", stdin);
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        int val, c;
        scanf("%d %d", &c, &val);
        val *= 2;
        --c;
        col[c].PB(val);
    }
    for (int i = 0; i < k; ++i) {
        sort(col[i].begin(), col[i].end(), greater<ll>());
        col[i][0] = col[i][1] = (col[i][0] + col[i][1]) / 2;
        r2.insert(2 * col[i][0]);
        if (col[i].size() > 2) {
            r3.insert(col[i][0] + col[i][1] + col[i][2]);
        }
        for (int val : col[i]) {
            v.emplace_back(val, i);
        }
    }
    sort(v.begin(), v.end(), greater<pair<ll, int>>());
    for (int i = 0; i < v.size(); ++i) {
        if (has[v[i].S] == 0) {
            has[v[i].S] = 1;
            np[i] = true;
        }
    }
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        ans[i] = -inf;
        if (np[i]) {
            if (!r1.empty()) {
                ans[i] = max(ans[i], sum + set_mx(r1));
            }
            if (!l1.empty() && !r2.empty()) {
                ans[i] = max(ans[i], sum - *l1.begin() + set_mx(r2));
            }
            if (!l2.empty() && !r3.empty()) {
                ans[i] = max(ans[i], sum - *l2.begin() + set_mx(r3));
            }
            sum += v[i].first;
            continue;
        }
        sum += v[i].first;
        ans[i] = sum;
        if (i && np[i - 1]) {
            add2(v[i].S);
        } else {
            add1(v[i].S, v[i].F);
        }
    }
    for (int i = 0; i < n; ++i) {
        if (ans[i] == -inf) {
            ans[i] = -2;
        }
        printf("%lld\n", ans[i] / 2);
    }

    return 0;
}




Measured memory_bytes: 24820
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

class Combination
{
public:
	Combination(long long int mod)
		:mod(mod)
	{}
	~Combination()
	{}

	void init(int n)
	{
		fact.resize(n);
		fact[0] = 1;
		for (int i = 1; i < n; ++i)
		{
			//! 階乗
			fact[i] = fact[i - 1] * i;
			fact[i] %= mod;
		}

		//! 階乗の逆元
		revFact.resize(n);
		revFact[n - 1] = powmod(fact[n - 1], mod - 2);
		for (int i = n - 2; i >= 0; --i)
		{
			revFact[i] = revFact[i + 1] * (i + 1);
			revFact[i] %= mod;
		}
	}

	long long int get(int a, int b)
	{
		return (((fact[a] * revFact[b]) % mod)*revFact[a - b]) % mod;
	}

private:

	long long int powmod(long long int a, long long int p)
	{
		long long int ans = 1;
		long long int mul = a;
		for (; p > 0; p >>= 1, mul = (mul*mul) % mod)
		{
			if ((p & 1) == 1) ans = (ans*mul) % mod;
		}
		return ans;
	}
	long long int mod;
	std::vector<long long int> fact;
	std::vector<long long int> revFact;
};

int main()
{
	int H, W;
	cin >> H >> W;
	int A, B;
	cin >> A >> B;

	Combination comb(MOD);
	comb.init(H + W);
	ll sum = 0;
	pii g(A, B);
	while (g.first < H && g.second < W)
	{
		int h = H - 1 - g.first;
		int w = W - 1 - g.second;

		ll first = comb.get(h + g.second, h);
		ll second = comb.get(g.first + w, w);
		sum += (first*second) % MOD;
		sum %= MOD;
		g.first++; g.second++;
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  for(int i=0; i<3; i++){
    string in;
    cin >> in;
    cout << in[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
function main(input){
  const N=input.split('\n')[0].split(' ')[0];
  const X=input.split('\n')[0].split(' ')[1];
  var nums = input.split('\n')[1].split(' ').map((n) => parseInt(n, 10));
  var sum=0;
  var count=1;
  for(var i=0; i<N; i++){
    sum+=nums[i];
    if(sum>X){
      break
    }
    count++;
  }
  console.log(count);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
  int a, b, n = 0;
  cin >> a >> b;
 if(a < b) swap(a, b);//必ずaのほうが大きい
  n = (a + b) / 2;
  if( (a + b) % 2 != 0) cout << "IMPOSSIBLE" << endl;
  else cout << n << endl;
}

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

int main()
{
  int a,b;
  cin>>a>>b;
  
  if(a==1 && b==2 || a==2 && b==1)
  {
    cout<<"3"<<endl;
  }
  
  else if(a==1 && b==3 || a==3 && b==1)
  {
    cout<<"2"<<endl;
  }
  
  else if(a==2 && b==3 || a==3 && b==2)
  {
    cout<<"1"<<endl;
  }
    
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
struct Node {
	int key;
	Node *p, *l, *r;
};
Node *root;
void insert(int key_) {
	Node *x = root, *y = 0, *z;
	z = (Node*)malloc(sizeof(Node));
	z->key = key_, z->l = 0, z->r = 0;
	while (x) y = x, x = (z->key < x->key) ? x->l : x->r;
	z->p = y;
	if (!y) root = z;
	else if (z->key < y->key) y->l = z;
	else y->r = z;
}
bool find(int key_) {
	Node *x = root;
	while (x) {
		if (key_ < x->key) x = x->l;
		else if (key_ > x->key) x = x->r;
		else return true;
	}
	return false;
}
void walk1(Node *x) { if (!x) return; walk1(x->l); printf(" %d", x->key); walk1(x->r); }
void walk2(Node *x) { if (!x) return; printf(" %d", x->key); walk2(x->l); walk2(x->r); }
int n, v; char c[8];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", &c);
		if (c[0] == 'i') scanf("%d", &v), insert(v);
		else if (c[0] == 'f') scanf("%d", &v), printf("%s\n", find(v) ? "yes" : "no");
		else walk1(root), printf("\n"), walk2(root), printf("\n");
	}
}

Measured memory_bytes: 21312
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> snuke(n, 0);
  for(int i = 0; i < k; ++i){
  	int d;
  	cin >> d;
  	for(int j = 0; j < d; ++j){
  		int a;
  		cin >> a;
  		--a;
  		++snuke[a];
  	}
  }

  int cnt = 0;
  for(int i = 0; i < n; ++i){
  	if(snuke[i] == 0)++cnt;
  }

  cout << cnt << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  cout << n << ":";
  for(int i = 2; i <= sqrt(n); i++){
    if(n % i == 0){
      while(n % i == 0){
        n /= i;
        cout << " " << i;
      }
    }
  }
  if(n > 1){
    cout << " " << n;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1168
import fractions
from collections import defaultdict
A, B = map(int, input().split())
C = fractions.gcd(A, B)
c = C

if c == 1:
    print(1)
    exit()


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


print(len(factorization(c))+1)


Measured memory_bytes: 5088
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    Node[] nodes = new Node[N];
    for (int i = 0; i < N; i++) nodes[i] = new Node(i + 1);
    for (int i = 0; i < N + M - 1; i++) {
      int a = scanner.nextInt() - 1;
      int b = scanner.nextInt() - 1;
      nodes[a].to.add(nodes[b]);
      nodes[b].from.add(nodes[a]);
    }

    Node root = findRoot(nodes);
    List<Node> tsort = new ArrayList<>();
    topologySort(root, tsort);
    Collections.reverse(tsort);
    int i = 0;
    for (Node n : tsort) {
      n.position = i;
      i++;
    }
    for (Node n : tsort) {
      if (n.from.size() > 1) {
        Node min = null;
        for (Node p : n.from) {
          if (min == null || min.position < p.position) min = p;
        }
        n.parent = min;
      } else if (n.from.size() == 1) {
        n.parent = n.from.get(0);
      }
    }

    StringBuilder sb = new StringBuilder();
    for (int j = 0; j < N; j++) {
      if (nodes[j].parent == null) sb.append(0).append("\n");
      else sb.append(nodes[j].parent.id).append("\n");
    }
    System.out.println(sb.toString());
  }

  private static Node findRoot(Node[] nodes) {
    Queue<Node> queue = new LinkedList<>();
    queue.add(nodes[0]);
    while (!queue.isEmpty()) {
      Node n = queue.poll();
      if (n.from.isEmpty()) return n;
      queue.addAll(n.from);
    }
    throw new IllegalStateException();
  }

  private static void topologySort(Node n, List<Node> comp) {
    if (n.visited) return;
    for (Node t : n.to) topologySort(t, comp);
    n.visited = true;
    comp.add(n);
  }

  private static class Node {
    final int id;
    final List<Node> to = new ArrayList<>();
    final List<Node> from = new ArrayList<>();
    int position = 0;
    Node parent = null;
    boolean visited = false;

    private Node(int id) {
      this.id = id;
    }
  }
}

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

int main() {
  int N, Q;
  cin >> N;
  vector<int> A(NMAX);
  ll sum = 0;
  for (int i = 0; i < N; i++)
  {
    int x;
    cin >> x;
    A[x]++;
    sum += x;
  }

  cin >> Q;
  while (Q--)
  {
    int B, C;
    cin >> B >> C;
    sum += (C - B) * A[B];
    A[C] += A[B];
    A[B] = 0;
    cout << sum << endl;    
  }
  
  return 0;
}


Measured memory_bytes: 3736
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;

int main() {
	int N,K,max=1,sum=0;
	double ave;
	cin >> N>>K;
	vector<int>P(N, 0);
	for (int i = 0; i<N; i++) {
		cin >> P[i];
	}
	for (int i = 0; i < K; i++)
		sum += P[i];
	max = sum;
	for (int i = 1; i < N - K + 1; i++) {
		sum -= P[i-1];
		sum += P[i + K-1];
		if (sum > max) {
			max = sum;
			//cout << "koushin" << endl;
		}
	}
	ave = max;
	ave += K;
	ave /= 2;
	printf("%.12f\n",ave);
}

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

int main(void){
    int n, a[110], sum=0, min=1000000;
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> a[i];
        sum += a[i];
        if(a[i]%10!=0){
            if(min > a[i]) min = a[i];
        }
    }
    sort(a, a+n);
    if(sum%10!=0){
        cout << sum << endl;
        return 0;
    }
    if(min!=1000000){
        sum -= min;
        cout << sum << endl;
    }else{
        cout << "0" << endl;
    }
}

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

const int N = 55;

int a[N], frq[1 << 18];
long long C[N][N], sum[N][N];

inline int Count(int x) {
	if (x == 0) return 0;
	else return 32 - __builtin_clz(x);
}

int main() {
	
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	for (int i = 0; i < N; i++) {
		C[i][0] = 1, sum[i][0] = 0;
		for (int j = 1; j <= i; j++) {
			C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
		}
		for (int j = 1; j < N; j++) sum[i][j] = sum[i][j - 1] + C[i][j];
	}
	
	int n, k, S, T; cin >> n >> k >> S >> T;
	int an = 0;
	for (int i = 1; i <= n; i++) {
		int u; cin >> u;
		if ((u & S) != S || (u | T) != T) continue;
		int cur = 0;
		for (int j = 0; j < 18; j++) if (((~S) >> j & 1) && (T >> j & 1)) cur = cur << 1 | (u >> j & 1);
		a[++an] = cur;
	}
	n = an;
	long long ans = 0;
	int xx = __builtin_popcount(T) - __builtin_popcount(S);
	for (int s = 0; s < (1 << xx); s++) {
		for (int i = 1; i <= n; i++) {
			frq[a[i] & s]++;
		}
		int sgn = (__builtin_popcount(s) % 2 ? -1 : 1);
		for (int i = 1; i <= n; i++) if (frq[a[i] & s]) {
			ans += sgn * sum[frq[a[i] & s]][k];
			frq[a[i] & s] = 0;
		}
	}
	
	cout << ans << "\n";
	
	return 0;
}


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

int main(){
    char buff1[2*10*10*10*10*10+1];
    char buff2[2*10*10*10*10*10+1];

    scanf("%s", buff1);
    scanf("%s", buff2);
    int cnt = 0;
    for (int i = 0;i<=strlen(buff1);i++){
        if (buff1[i] != buff2[i]){
            cnt ++;
        }
    }
    
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 2116
#include <iostream>

int main() {
	int n;
	char s[103];
	scanf("%d %s", &n, s);
	
	int max = -1;
	for (int i = 0; i < n; ++i) {
		int mask1 = 0;
		int mask2 = 0;
		for (int j = 0; j < i; ++j) mask1 |= (1 << (s[j] - 'a'));
		for (int j = i; j < n; ++j) mask2 |= (1 << (s[j] - 'a'));
		int mask3 = mask1 & mask2;
		
		if (__builtin_popcount(mask3) > max) max = __builtin_popcount(mask3);
	}
	
	printf("%d\n", max);
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)

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

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> ln(1, 1);
    rep(i, 1, n) {
        if (s[i] == s[i - 1]) {
            ln[ln.size() - 1]++;
        } else {
            ln.push_back(1);
        }
    }

    int sum = -1;
    if (2 * k + 1 >= ln.size()) {
        sum = accumulate(ln.begin(), ln.end(), 0) - 1;
    } else {
        rep(i, 0, 2 * k + 1) {
            sum += ln[i];
        }
        rep(i, 2 * k + 1, ln.size()) sum += ln[i] - 1;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long hxtype;
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
const ll p=998244353ll;
const int N=1000005;
struct duck{
	int b,c,h,u;
	inline duck(){}
	inline duck(int b,int c,int h):b(b),c(c),h(h),u(!(b&&c)){}
}x[N];
char s[N];
int a[N],b[N];
int main(){
	int n=0,m,i,c[3]={0,0,0},he=3,t=0,c1=0,c2=0,ans,B,C,H;
	int x1=0,x2=0,u1=0,u2=0;
	scanf("%s",s+1);
	m=strlen(s+1);
	rep(i,1,m)if(s[i]!=s[i-1])++c[a[++n]=s[i]-65];
	if(!(c[0]&&c[1]&&c[2]))return 0;
	m=0;
	if(c[m]>c[1])m=1;
	if(c[m]>c[2])m=2;
	ans=c[m];
	if(m)rep(i,1,n){
		if(a[i]){
			if(a[i]==m)a[i]=0;
		}else a[i]=m;
	}
//	rep(i,1,n)printf("%d ",a[i]);printf("\n");
	rep(i,1,n){
		if(a[i]){
			if(he==3)he=a[i]-1;
			if(a[i]==1)++c1;else ++c2;
		}else{
			x[++t]=duck(c1,c2,he);
			c1=c2=0;he=3;
		}
	}
	x[++t]=duck(c1,c2,he);
	x[1].u=x[t].u=0;
//	rep(i,1,t)printf("(b=%d,c=%d,h=%d,u=%d)\n",x[i].b,x[i].c,x[i].h,x[i].u);
	rep(i,1,t){
		if(x[i].b){
			++x1;
			if(x[i].u)++u1;
		}
		if(x[i].c){
			++x2;
			if(x[i].u)++u2;
		}
	}
//	printf("x1=%d x2=%d u1=%d u2=%d\n",x1,x2,u1,u2);
	rep(i,1,t)if(u1>x2&&x[i].h!=2&&x[i].b&&x[i].u){
		--ans;
		--u1;
		--x1;
		x[i].h=2;
	}
	rep(i,1,t)if(u2>x1&&x[i].h!=2&&x[i].c&&x[i].u){
		--ans;
		--u2;
		--x2;
		x[i].h=2;
	}
//	rep(i,1,t)printf("(b=%d,c=%d,h=%d,u=%d)\n",x[i].b,x[i].c,x[i].h,x[i].u);
	u1=u2=0;
	rep(i,1,t)if(x[i].h!=2){
		u1+=x[i].b;
		u2+=x[i].c;
	}
//	printf("t=%d ans=%d u1=%d u2=%d\n",t,ans,u1,u2);
	rep(i,1,t)if(x[i].h!=2){
		if(u1>u2&&!x[i].u&&x[i].b> x[i].c){--x[i].b;--u1;if(!x[i].c)x[i].h=3;}
		if(u1>u2&& x[i].c&&x[i].b==x[i].c){--x[i].b;--u1;           x[i].h=1;}
	}
	rep(i,1,t)if(x[i].h!=2){
		if(u2>u1&&!x[i].u&&x[i].c> x[i].b){--x[i].c;--u2;if(!x[i].b)x[i].h=3;}
		if(u2>u1&& x[i].b&&x[i].c==x[i].b){--x[i].c;--u2;           x[i].h=0;}
	}
//	printf("t=%d u1=%d u2=%d\n",t,u1,u2);
//	rep(i,1,t)printf("(b=%d,c=%d,h=%d,u=%d)\n",x[i].b,x[i].c,x[i].h,x[i].u);
	c1=c2=0;
	rep(i,1,t)if(x[i].h!=2){
		if(c2)b[++c1]=0;else c2=1;
		if((H=x[i].h)!=3){
			B=x[i].b;
			C=x[i].c;
			while(B&&C&&u1>ans){
				--u1;--B;--C;
				if(!(B||C)&&i!=1&&i!=t){++u1;B=C=1;break;}
			}
			while(B||C){
				if(H){
					--C;
					b[++c1]=2;
					H=0;
				}else{
					--B;
					b[++c1]=1;
					H=1;
				}
			}
		}
	}
	if(m)rep(i,1,c1){
		if(b[i]){
			if(b[i]==m)b[i]=0;
		}else b[i]=m;
	}
	rep(i,1,c1)putchar(b[i]+65);
	return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MAX 1000010
#define MOD 1000000007
  
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  int N; cin>>N;
  string S,T; cin>>S;
  cin>>T;
  vector<ll> dp(N);
  if(N==1){
    cout<<3<<endl;
    return 0;
  }else if(N==2){
    cout<<6<<endl;
    return 0;
  }

  if(S.at(0)==T.at(0))dp.at(0) = 3;
  else dp.at(0) = 6;
  rep1(i,N){
    if(S.at(i)==T.at(i)){
      if(S.at(i-1)==T.at(i-1))dp.at(i)=dp.at(i-1)*2;
      else dp.at(i)=dp.at(i-1);
    }else if(S.at(i)==S.at(i-1)){
      dp.at(i)=dp.at(i-1);
    }else if(S.at(i-1)!=T.at(i-1)){
      dp.at(i)=dp.at(i-1)*3;
    }else dp.at(i)=dp.at(i-1)*2;
    
  }
  //rep(i,N)cout<<dp.at(i)<<endl;
  cout<<dp.at(N-1)%MOD<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
 
class Main{
   public static void main(String[] args) {
      FastScanner sc = new FastScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      int n = sc.nextInt();
      int k=sc.nextInt();
      int[] arr=new int[n];
      for(int i=0;i<n;i++) {
        arr[i] = sc.nextInt();
      }
      Arrays.sort(arr);
      int sum=0;
      for(int i=0;i<k;i++) {
        sum+=arr[i];
      }
      out.println(sum);
      out.close();
   }
   
   public static boolean isUpperCase(String s)
   {
       for (int i=0; i<s.length(); i++)
       {
           if (!Character.isUpperCase(s.charAt(i)))
           {
               return false;
           }
       }
       return true;
   }

     

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;
      
   //-----------MyScanner class for faster input----------
   public static class FastScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public FastScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
      try {
         str = br.readLine();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return str;
      }

   }
}


Measured memory_bytes: 26024
def floyd(P,m):
    for k in range(m):
        for i in range(m):
            for j in range(m):
                P[i][j]=min(P[i][j],P[i][k]+P[k][j])

n=input()
m=input()
INF=1e10
C=[[INF]*n for i in range(n)]
for i in range(n):
    C[i][i]=0
for i in range(m):
    a1,b1,c1,d1=map(int,raw_input().split(","))
    C[a1-1][b1-1]=c1
    C[b1-1][a1-1]=d1
floyd(C,n)
x1,x2,y1,y2=map(int,raw_input().split(","))
print y1-y2-C[x1-1][x2-1]-C[x2-1][x1-1]

Measured memory_bytes: 4288
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(10 ** 9)



INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


class BIT:
    def __init__(self, size):
        self.bit = [0] * size
        self.size = size

    def add(self, i, w):
        x = i + 1
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return

    def sum(self, i):
        res = 0
        x = i + 1
        while x:
            res += self.bit[x - 1]
            x -= x & -x
        return res


n = I()
X = []
Y = []
XY = []
for x, y in LIR(n):
    Y += [y]
    X += [x]

co_to_ind = {e: i for i, e in enumerate(sorted(Y))}
Y = [co_to_ind[k] for k in Y]
Y = [Y[i] for i in sorted(range(n), key=lambda j:X[j])]
pow2 = [1]
for i in range(n):
    pow2 += [pow2[-1] * 2 % mod]


ans = pow2[n - 1] * n % mod
bit = BIT(n)
for i, y in enumerate(Y):
    bit.add(y, 1)
    ld = bit.sum(y - 1)
    lu = i - ld
    rd = y - ld
    ru = n - y - 1 - lu
    ans = ans + (pow2[ld] - 1) * (pow2[ru] - 1) * pow2[lu] % mod * pow2[rd] % mod
    ans = ans + (pow2[lu] - 1) * (pow2[rd] - 1) * pow2[ld] * pow2[ru] % mod
    ans = ans - (pow2[ld] - 1) * (pow2[ru] - 1) * (pow2[rd] - 1) * (pow2[lu] - 1) % mod


print(ans % mod)








Measured memory_bytes: 119948
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>

typedef long long ll;
using namespace std;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;

const double EPS = 1e-8;

int main()
{
	ll X=0;

	cin >> X;

	cout << (X<1200 ? "ABC":"ARC");
	
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std; 
long long MOD = 998244353; 
int main(){
	string S; int K; cin >> S >> K; 
	int N = S.size(); 
	long long dp[310][310][310] = {};
	vector<int> A;
	int cons = 0; 
	for(int i = 0; i < (int) S.size(); i++){
		if(S.at(i) == '0'){
			A.push_back(cons); cons = 0; 
		}else{
			cons ++; 
		}
	}
	A.push_back(cons); 
	int L = A.size();
	int a = L - 1; int b = N - L + 1; // 0の個数と1の個数
	dp[0][0][0] = 1; 
	for(int i = 0; i < L; i++){
		for(int j = 0; j <= b; j++){
			for(int k = 0; k <= j; k++){
				if(dp[i][j][k] == 0) continue; 
				for(int l = 0; l <= k; l++){
					dp[i+1][j][k-l] += dp[i][j][k]; 
					if(dp[i+1][j][k-l] >= MOD) dp[i+1][j][k-l] -= MOD; 
				}
				for(int l = 1; l <= A[L - i - 1]; l++){
					dp[i+1][j+l][k+l] += dp[i][j][k]; 
					if(dp[i+1][j+l][k+l] >= MOD) dp[i+1][j+l][k+l] -= MOD; 
				}
			}
		}
	}
	long long ans = 0; 
	for(int i = 0; i <= min(300, K); i++){
		ans += dp[L][i][0]; 
	}
	ans %= MOD; 
	cout << ans << "\n";
}

Measured memory_bytes: 236364
#include<iostream>
using namespace std;
int mp[2][31][31]={};
int sai[6][4]={{3,5,4,2},{1,4,6,3},{1,2,6,5},{5,6,2,1},{3,6,4,1},{2,4,5,3}};

void die(int t,int f,int x,int y){
  int i,j,x2,y2,mx=3,f2,dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
  mp[1][y][x]++;
  for(i=0;i<4;i++){
    if(sai[t-1][i]==f){
      for(j=0;j<4;j++){
	int m=(j+i)%4,x1=x+dx[j],y1=y+dy[j];
	if(mp[1][y][x]-1>mp[1][y1][x1]&&sai[t-1][m]>mx){
	  mx=sai[t-1][m],x2=x1,y2=y1;
	  if(j==2)f2=7-t;
	  else if(j==0)f2=t;
	  else f2=f;
	}
      }
      break;
    }
  }
  if(mx!=3)mp[1][y][x]--,die(7-mx,f2,x2,y2);
  else mp[0][y][x]=t;
}

int main(){
  while(1){
    int n;cin>>n;if(n==0)break;
    int i,j,t,f,c[7]={};
    for(i=0;i<n;i++){
      cin>>t>>f;
      die(t,f,15,15);
    }
    for(i=0;i<31;i++)
      for(j=0;j<31;j++){
	c[mp[0][i][j]]++;
	mp[0][i][j]=mp[1][i][j]=0;
      }
    for(i=1;i<6;i++)cout<<c[i]<<" ";cout<<c[6]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define fi first
#define se second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define pi pair<ll,ll>
#define mp make_pair
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
//freopen("explicit.in", "r", stdin);
//freopen("explicit.out", "w", stdout);
 
void SieveOfEratosthenes() 
{ 
    bool prime[10000001];
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=10000000; p++) 
    { 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=10000000; i += p) {
                prime[i] = false; 
            }
        } 
    }  
} 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
ll nCrModpDP(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C));   
    C[0] = 1;
    for (ll i = 1; i <= n; i++) 
    {
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll nCrModp(ll n, ll r, ll p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
  
   return (nCrModp(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p; 
} 
int32_t main() 
{
    fio
	ll j,i,n,t,l,r,c,h,k,m,maxi,s,d,x;
	cin>>d>>t>>s;
	c=s*t;
	if(c>=d)
		cout<<"Yes";
	else
		cout<<"No";
}



	

		

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n, m, p;
	string s;
	cin >> n >> m;

	vector<int> problems(n, -1);

	int ans_ac = 0;
	int ans_wa = 0;

	for(int i = 0; i < m; ++i)
	{
		cin >> p >> s;
		p--;
		if (problems[p] <= 0)
		{
			if (s == "WA")
			{
				problems[p]--;
			}
			else if(s == "AC")
			{
				problems[p] *= -1;
				++ans_ac;
				ans_wa += problems[p] - 1;
			}
		}
	}
	cout << ans_ac << " " << ans_wa;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    char N[3];
    int ans=0;
  
  for(int i=0; i<3; i++){
	cin >> N[i];
    if(N[i]=='7'){
    	ans = 1;
    }
  }
 
  if(ans==1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
    
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;
#define P 1000003
#define N_MAX 2000000
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
    return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}

void init(){
    fac[0] = finv[0] = inv[0] = fac[1] = finv[1] = inv[1] = 1;
    for(int i = 2; i <= N_MAX; i++){
        fac[i] = (fac[i-1]*i)%P;
        inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
        finv[i] = (finv[i-1]*inv[i])%P;
    }
}

int main(int argc, char const *argv[]) {
  init();
  ll Q;
  std::cin >> Q;
  ll x, d, n, ans;
  for(int i=0;i<Q;i++){
    ans = 0;
    std::cin >> x >> d >> n;
    // exception
    if(d==0){
      ans = 1;
      ll reg = x;
      while(n>=1){
        if(n%2!=0) ans = (ans * reg)%P;
        reg = (reg * reg)%P;
        n = n >> 1;
      }
      std::cout << ans << '\n';
      continue;
    }
    if(x%P==0 || (x*inv[d])%P + n - 1 >= 1000003){
      std::cout << 0 << '\n';
      continue;
    }
    ll xn = (x * inv[d])%P;
    ans = (fac[xn + n - 1] * finv[xn-1])%P;
    ll reg = d;
    while(n>=1){
      if(n%2!=0) ans = (ans * reg)%P;
      reg = (reg * reg)%P;
      n = n >> 1;
    }
    std::cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 47744
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r; cin >> r;
    cout << (r < 1200 ? "ABC" : r < 2800 ? "ARC" : "AGC") << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
int main()
{
    std::string s;
    std::cin >> s;

    int mlen = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') {
            int l = 1;
            for (int j = i+1; j < s.size(); j++) {
                if (s[j] == 'A' || s[j] == 'T' || s[j] == 'G' || s[j] == 'C') {
                    l++;
                }
                else {
                    i = j-1;
                    break;
                }
            }
            mlen = std::max(mlen, l);
        }
    }

    std::cout << mlen << std::endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))

    ans = INF
    for i in range(N - 1):
        ans = min(ans, K - (A[i + 1] - A[i]))

    ans = min(ans, K - (K - A[-1] + A[0]))
    return ans


def main():
    print(solve())


if __name__ == '__main__':
    main()


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

char c[4]={'E','W','N','S'};

int main(){
	int t=0,n;
	string s;
	//cin>>t;
	vector<pair<int,bool>> v;
	//int n;
	cin>>n;
	while(n){
		int x=n%10;
		n=n/10;
		if(x==7) t++;
	}
	if(t) cout<<"Yes";
	else cout<<"No";
	cout<<endl;

}


Measured memory_bytes: 3596
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for(ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

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

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {
    ll N, A, B;
    in >> N >> A >> B;
    ll ans = 0;

    ans = A * (N / (A+B)) + min(A,  N % (A+B));

    out << ans << endl;
    return 0;
}

int run2(istream& in, ostream& out) {
    ll N, M, R;
    in >> N >> M >> R;
    vector<ll> r{};
    REP(i, R) {
        ll x;
        in >> x;
        r.emplace_back(x);
    }
    vector<tuple<ll,ll,ll>> v{};
    REP(i, M) {
        ll a,b,c;
        in >> a >> b >> c;
        v.emplace_back(make_tuple(a,b,c));
    }

    ll ans = 0;

    // solution here

    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


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

#define MAXLEN 51

int main(void) {
    char O[MAXLEN], E[MAXLEN];
    int len, i;
    scanf("%s %s", O, E);
    len = (int)strlen(E);
    for (i = 0; i < len; i++) {
        printf("%c%c", O[i], E[i]);
    }
    if (strlen(O) != strlen(E)) {
        printf("%c", O[strlen(O) - 1]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
s = input()

c = [0 for i in range(2019)]
c[0] = 1
mod = 2019
d = 1
x = 0
for i,j in enumerate(s[::-1]):
	x = (x + int(j)*pow(10,i,mod))%mod
	c[x] += 1

ans = 0
for i in range(2019):
	ans += (c[i]*(c[i]-1))//2
print (ans)


Measured memory_bytes: 9328
n = int(input())
h = list(map(int, input().split()))

ans = 0

while any((i > 0 for i in h)):
    counted = False
    for i in range(n):
        if h[i] > 0:
            h[i] -= 1
            if not counted:
                ans += 1
                counted = True
        else:
            counted = False

print(ans)



Measured memory_bytes: 3060
/*
我的心脏怦怦跳，监管者就在附近
name:
Algorithm:
writer:Lxs(cdx)
place:
nothing is impossible
*/
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
bool prime(int x){
	 int i;
	 if(x<2) return 0;
	 for(i=2;i*i<=x;i++){
		if(x%i==0){return 0;}
	 }
	 return 1;
}
int a[110100];
bool f[101010];
int main()
{
	int n,m;
	cin>>n>>m;
	int i;
	long double s=0;
	for(i=0;i<n;i++){
		cin>>a[i];
		s+=a[i];
	}
	int g=0;
	for(i=0;i<n;i++){
		if(a[i]>=double(s/(4*m))){
			g++;
		}
	}
	if(g>=m){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import heapq
from collections import defaultdict

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


work = defaultdict(list)

for i in range(N):
    a,b = map(int, input().split())
    work[a-1].append(-b)



# 終了日から１日前、２日前、...の順で仕事を選ぶ
current_work = []
ans = 0
for i in range(M):
    if i in work.keys():
        for j in work[i]:
            #元が空っぽなので、heapifyしなくてもheapを保てる
            heapq.heappush(current_work, j)

    if current_work:
        #heapq.heapify(current_work)
        ans += -1 * heapq.heappop(current_work)

print(ans)

Measured memory_bytes: 27652
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{  
    long long a,b,s;
    while( cin>>a>>b )
    {
           long long dem=0;
           s=a+b;
           while(s>0)
           {
                     s=s/10;
                     dem++;
           }
           cout<<dem<<endl;
    }
}

Measured memory_bytes: 1156
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
using ll = long long;
#define rep0(i,n) for(int i=0;i<(int)n;i++)
constexpr ll linf=2*1e18;

int main(){
    int k,n;
    cin>>n>>k;
    double p[n];
    double e[n];
    rep0(i,n){
        cin>>p[i];
        e[i] = (p[i] + 1.0) / 2.0;
    }
    double accum[n+1];
    accum[0]=0;
    rep0(i,n){
        accum[i+1]=accum[i]+e[i];
    }
    double ans=0;
    rep0(i,n-k+1){
        ans=max(accum[k+i]-accum[i],ans);
    }
    cout<<setprecision(10)<<ans<<endl;
    return 0;
}

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

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

using namespace std;

int main(){
	int n;
	
	cin >> n;
	
	vector<int> d(n);
	
	for(int i=0; i<n; i++)	cin >> d[i];
	
	sort(all(d));
	
	cout << d[n/2]-d[n/2-1] << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N, K;
vector<pair<int, int>> v, vv;
vector<pair<int, int>> G[100010];
vector<int> d(100010, INT_MAX);
priority_queue<pair<int, int>> que;
int main () {
    cin >> N;
    for (int i = 0; i < N-1; i++) {
        int A, B;
        cin >> A >> B;
        vv.push_back(make_pair(A, B));
        G[A].push_back(make_pair(B, 1));
        G[B].push_back(make_pair(A, 1));
    }
    cin >> K;
    for (int i = 0; i < K; i++) {
        int V, P;
        cin >> V >> P;
        v.push_back(make_pair(V, P));
        G[0].push_back(make_pair(V, P));
    }
    d[0] = 0;
    que.push(make_pair(-d[0], 0));
    while (que.size()) {
        int dd = -que.top().first;
        int a = que.top().second;
        que.pop();
        if (d[a] < dd) continue;
        for (auto t: G[a]) {
            if (d[t.first] > dd+t.second) {
                d[t.first] = dd+t.second;
                que.push(make_pair(-d[t.first], t.first));
            }
        }
    }
    for (auto x: v) {
        if (d[x.first] != x.second) {
            puts("No");
            return 0;
        }
    }
    for (auto x: vv) {
        if (abs(d[x.first]-d[x.second]) != 1) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    for (int i = 1; i <= N; i++) {
        cout << d[i] << endl;
    }
}

Measured memory_bytes: 10984
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
int f(int x){
	int sum=0;
	while(x){
		sum+=x%10;
		x=x/10;
	}
	return sum;
}
int main(){
	int n;
	cin >> n;
	if(n%f(n)==0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# import itertools
# from operator import attrgetter, itemgetter
# import math

# from numba import jit

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    ans = 0

    for i in range(1, n + 1):
        if i % 3 == 0 or i % 5 == 0:
            continue
        ans += i

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 67264
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>


using namespace std;


int main() {
	
	int a;
	int cnt = 0;
	cin >> a;
	
	for (int i = a; i > 0; i--) {
		cnt += a;
		a--;
	}
	cout << cnt << endl;
	
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  string S;
  cin >> S;
  for(int i = 0; i < 3; i++){
    if(S[i] == S[i+1]){
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python


while True :
	S = input()
	if len(S) == 4 and S.isupper() :
		break
	else :
		continue


char_list = list(S)

judge = 0


for i in range(3) :
	for j in range(3-i) : 
		if char_list[i] == char_list[i+j+1] :
			judge = judge + 1

if judge == 2 :
	print('Yes')
else :
	print('No')


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

#define FRE(i,a,b)  for(i = a; i <= b; i++)
#define FRL(i,a,b)  for(i = a; i < b; i++)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define all(x)      x.begin(),x.end()
#define un(x)       x.erase(unique(all(x)), x.end())
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sl(n)       scanf("%lld", &n)
#define sll(a,b)    scanf("%lld %lld", &a, &b)
#define slll(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define D(x)        cerr << #x " = " << (x) << '\n'
#define DBG         cerr << "Hi" << '\n'
#define pb          push_back
#define PI          acos(-1.00)
#define xx          first
#define yy          second
#define eps         1e-9

typedef unsigned long long int ULL;
typedef long long int LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


inline int setBit(int N, int pos) { return N=N | (1<<pos); }
inline int resetBit(int N, int pos) { return N= N & ~(1<<pos); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1<<pos)); }

//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    string s = "UURDDLLUUURRDRDDDLLU";
    D(s.size());
    int i, j, cs, t;
    pii src, dest;
    sff(src.xx,src.yy);
    sff(dest.xx,dest.yy);
    int dx = dest.xx - src.xx;
    int dy = dest.yy - src.yy;
    for(int i = 1; i<=dx; i++)
        printf("R");
    for(int i = 1; i<=dy; i++)
        printf("U");

    for(int i = 1; i<=dx; i++)
        printf("L");
    for(int i = 1; i<=dy; i++)
        printf("D");

    printf("D");
    for(int i = 1; i<=dx; i++)
        printf("R");
    printf("RU");
    for(int i = 1; i<=dy; i++)
        printf("U");
    printf("L");

    printf("U");
    for(int i = 1; i<=dx; i++)
        printf("L");
    printf("LD");
    for(int i = 1; i<=dy; i++)
        printf("D");
    printf("R");
    return 0;
}




Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		int b[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=sc.nextInt();
			for(int i=0;i<n;i++)
			b[i]=sc.nextInt();
		int c=0,s=0;
		for(int i=0;i<n;i++){
			if(a[i]>b[i]){
				c=c+a[i];
				s=s+b[i];
			}	
		}
		System.out.println(c-s);
	}
}

Measured memory_bytes: 21972
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

X, K, D =  na()
if X < 0:
    X = -X
if K % 2 == 0:
    ans = X
    t = min(K//2, X//(2*D))
    ans = min(ans, abs(X - 2*D*t))
    if t + 1 <= K//2:
        ans = min(ans, abs(X - 2*D*(t+1)))
    print(ans)
else:
    if D >= X:
        ans = D-X
        print(ans)
    else:
        X -= D
        ans = X
        t = min(K//2, X//(2*D))
        ans = min(ans, abs(X - 2*D*t))
        if t + 1 <= K//2:
            ans = min(ans, abs(X - 2*D*(t+1)))
        print(ans)


Measured memory_bytes: 61836