akhauriyash/Code-Regression huggingface dataset:
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

ll mygcd(ll a, ll b)
{
	ll tmp = 0;
	if(a >= b) {
	} else {
		return mygcd(b,a);
	}
	while((tmp = a%b)) {
		a = b;
		b = tmp;
	}
	return b;
}

ll val[201][201] = {0};
ll val2[201][201] = {0};

int main()
{
	ll K = 0, i = 0, j = 0, k = 0, ans = 0;
	scanf("%lld", &K);
	memset(val, 0, sizeof(val));
	memset(val, 0, sizeof(val2));
	for (i = 1; i <= K; i++) {
		for (j = 1; j <= K; j++) {
			for (k = 1; k <= K; k++) {
				ll tmp = 0;
				if (val[i][j] == 0) {
					tmp = mygcd(i, j);
					val[i][j] = tmp;
					val[j][i] = tmp;
				} else {
					tmp = val[i][j];
				}
				if (val2[k][tmp] == 0) {
					ll tmp2 = 0;
					tmp2 = mygcd(k, tmp);
					ans += tmp2;
					val[k][tmp2] = tmp2;
					val[tmp2][k] = tmp2;
				} else {
					ans += val[k][tmp];
				}
			}
		}
	}
	printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2052
a,b,m=map(int,input().split())
*a,=map(int,input().split())
*b,=map(int,input().split())
ans=10**9
for i in range(m):
    x,y,c=map(int,input().split())
    if len(a)>=x and len(b)>=y:
        res=a[x-1]+b[y-1]-c
        ans=min(ans,res)
l=min(a)+min(b)
print(min(ans,l))

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

int main() {
  string S;
  cin >> S;
  
  char tmp;
  bool flag = true;
  
  int i = S.size() -1;
  while (i > 3){
        
	tmp = S.at(i);  // get last point char
        
    // tmp = 'e' or 'm' erase or dream?
    
    if (tmp == 'e'){
      if (S.at(i-4)=='e' && S.at(i-3)=='r' && S.at(i-2)=='a' && S.at(i-1)=='s'){
        i -= 5;
      }
      else
      {
        flag = false;
        break;
      }
    }
    
    if (tmp == 'm'){     
      if (S.at(i-4)=='d' && S.at(i-3)=='r' && S.at(i-2)=='e' && S.at(i-1)=='a'){
        i -= 5;
      }
      else
      {
        flag = false;
        break;
      }
    }

    // tmp = "r" eraser?
    
    if (tmp == 'r'){      
      if (S.at(i-5)=='e' && S.at(i-4)=='r' && S.at(i-3)=='a' && S.at(i-2)=='s' && S.at(i-1)=='e'){
          i -= 6;
      }
      else
      {
      	if (S.at(i-6)=='d' && S.at(i-5)=='r' && S.at(i-4)=='e' && S.at(i-3)=='a' && S.at(i-2)=='m' && S.at(i-1)=='e'){
          i -= 7;
        }
        else
        {
          flag = false;
          break;
        }
      }
    }
  }
  
  if (flag){
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
  while(1){
    int a, b, c;
    char op;
    scanf("%d %c %d", &a, &op, &b);
    if(op == '?')break;
    else if(op == '+')c=a+b;
    else if(op == '-')c=a-b;
    else if(op == '*')c=a*b;
    else c=a/b;
    printf("%d\n", c);
  }
  return 0;
}

Measured memory_bytes: 1796
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write('\n'.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
#from decimal import Decimal
from fractions import Fraction
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7



n,k=mdata()
a=mdata()
for i in range(k,n):
    if a[i]>a[i-k]:
        out("Yes")
    else:
        out("No")



Measured memory_bytes: 98084
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,sum=0;
char x;
cin>>a>>x>>b;
if(x=='+'){
    sum=a+b;
} else if(x=='-'){
    sum=a-b;
}else{
    printf("wrong op");
}
printf("%d",sum);
    return 0;
}


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

long long my_gcd(long long a, long long b) {
	long long c;

	while (true) {
		if (a == 0) {
			return b;
		} else if (a == b) {
			return a;
		} else if (a < b) {
			c = a;
			a = b;
			b = c;
		}
		a = a - (a / b) * b;
	}
}

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

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

	long long T;
	scanf("%lld", &T);
	long long result = T;
	for (long long i = 1; i < N; i++) {
		scanf("%lld", &T);
		result = T / my_gcd(T, result) * result;
		// printf("T  %lld,result = %lld\n", T, result);
	}

	printf("%lld", result);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		if (A >= 2 * B) {
			System.out.println(A - 2 * B);
		} else {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<deque>
#include<cmath>
#include<cstring>
#include<map>
#include<algorithm>
#include<vector>
#include<ios>
#include<sstream>
#include<locale>
using namespace std;
#define ive(cris) int long long 
#define in(out) long double
#define INF 100000007
int main(){
  int a,b;
  cin>>a>>b;
  if(a==b){
    cout<<"Draw"<<'\n';
  }
  if(a!=1 && b!=1){
    if(a>b){
      cout<<"Alice"<<'\n';
    }
    else if(a<b){
      cout<<"Bob"<<'\n';
    }
  }
  else if(a==1 && b!=1){
    cout<<"Alice"<<'\n';
  }
  else if(a!=1 && b==1){
    cout<<"Bob"<<'\n';
  }
  return 0;
}


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

int main() {
  int N, M;
  cin >> N;
  vector<string>brs(N);
  vector<int>bri(N,1);
  for(int i=0;i<N;i++){
    cin >> brs.at(i);
  }
  cin >> M;
  for(int j=N;j<N+M;j++){
    string s;
    cin >> s;
    brs.push_back(s);
  }
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(brs.at(i)==brs.at(j)&&brs.at(i)!=""){
        bri.at(i)++;
        bri.at(j)--;
        brs.at(j)="";
      }
    }
    for(int j=N;j<N+M;j++){
      if(brs.at(i)==brs.at(j))
        bri.at(i)--;
    }
  }
  int maxi=0;
  for(int i=0;i<N;i++){
    maxi=max(bri.at(i),maxi);
  }
  cout << maxi << endl;
}

Measured memory_bytes: 256
n,q,qq=map(int,input().split())

# root番号保持
root = list(range(n))
# 階層保持
rank =  [0] * n
# ノード数
node =  [1] *n
minus_node =  [0] *n


def find_set(x):
    if(x != root[x]):
        root[x] = find_set(root[x])
    return root[x]

def unite(x,y):
    link(find_set(x),find_set(y))

def link(x,y):
    if root[x] == root[y]:return
    if rank[x] > rank[y]:
        root[y] =x
        node[x] += node[y] 
    else:
        root[x] = y
        node[y] += node[x] 
        if rank[x] == rank[y]:
            rank[y] +=1

def same(x,y):
    return find_set(x) == find_set(y)

# print(root)
# print(rank)
# print(node)


for _ in range(q):
    a,b = map(int,input().split())

    unite(a-1,b-1)
    minus_node[a-1] +=1
    minus_node[b-1] +=1
    # print()
    # print(root)
    # print(rank)
    # print(node)

for _ in range(qq):
    a,b = map(int,input().split())

    if same(a-1,b-1):
        minus_node[a-1] +=1
        minus_node[b-1] +=1
# print()
# print(root)
# print(rank)
# print(node)


print(" ".join([str(node[find_set(i)] - minus_node[i] -1) for i in range(n)]))


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

struct node{
    int num;
    struct node *next,*prev;
};

typedef struct node * NodePointer;
NodePointer head;

void init();/*番兵ノード作成*/
NodePointer listSearch(int);/*一致するデータがあるか検索*/
void printList();/*連結リストに含まれるデータの出力*/
void deleteNode(NodePointer);/*ノードを削除*/
void deleteKey(int);/*与えられた値をリスト削除*/
void deleteFirst();/*リストの最初にある値を削除*/
void deleteLast();/*リストの最後にある値を削除*/
void insert(int);/*データを挿入*/
       
int main(){
    int n,key;
    char order[20];
    char ins[] = "insert";
    char del[] = "delete";
    char delF[] = "deleteFirst";
    char delL[] = "deleteLast";

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

    for(int i=0; i<n; i++){
        scanf("%s",order);
        if(strcmp(del,order) == 0 || strcmp(ins,order) == 0)scanf("%d",&key);

        if(strcmp(ins,order) == 0){
            insert(key);
        }
        else if(strcmp(del,order) == 0){
            deleteKey(key);
        }
        else if(strcmp(delF,order) == 0){
            deleteFirst();
        }
        else if(strcmp(delL,order) == 0){
            deleteLast();
        }
    }

    printList();

    return 0;
}


void init(){
    head = (NodePointer)malloc(sizeof(struct node));
    head->next = head;
    head->prev = head;
}

NodePointer listSearch(int key){
    NodePointer check;
    for(check = head->next; check != head; check = check->next){
        if(check->num == key) return check;
    }

    return NULL;
}

void printList(){
    NodePointer now = head->next;
    int dif=0;
    while(1){
        if(now == head) break;
        if(dif != 0) printf(" ");
        printf("%d",now->num);
        now = now->next;
        dif = 1; 
    }

    printf("\n");
}

void deleteNode(NodePointer key){
    if(key == head ) return;
    key->prev->next = key->next;
    key->next->prev = key->prev;
    free(key);
}

void deleteKey(int key){
    NodePointer v;
    v = listSearch(key);
    if(v == NULL) return;
    deleteNode(v);
}

void deleteFirst(){
    deleteNode(head->next);
}

void deleteLast(){
    deleteNode(head->prev);
}

void insert(int key){
    NodePointer x;
    x = (NodePointer )malloc(sizeof(struct node));
    x->num = key;

    x->next = head->next;
    head->next->prev = x;
    head->next = x;
    x->prev = head;
}



Measured memory_bytes: 33824
class UnionFind:
    def __init__(self, max_size):
        self.parent = [i for i in range(max_size+1)]
        self.depth = [0 for _ in range(max_size+1)]
        self.cnt = [1 for i in range(max_size+1)]
    def find(self, x):
        t = x
        while t!=self.parent[t]:
            t = self.parent[t]
        self.parent[x]=t
        return t
    
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        elif self.depth[x]<self.depth[y]:
            self.parent[x] = y
            self.cnt[y] += self.cnt[x]
        else:
            self.parent[y] = x
            self.cnt[x]+=self.cnt[y]
            if self.depth[x]==self.depth[y]:
                self.depth[x]+=1
    def same(self, x, y):
        return self.find(x)==self.find(y)
    def size(self,x):
        return self.cnt[self.find(x)]

n,m = map(int,input().split())
utree = UnionFind(n+10)
for _ in range(m):
    x,y,z = map(int,input().split())
    utree.unite(x,y)
s = {utree.find(i) for i in range(1,n+1)}
print(len(s))

Measured memory_bytes: 57996
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Face Produces Unhappiness
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

char s[MAX_N + 4];
pii ps[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d%s", &n, &k, s);

  int m = 0;
  for (int i = 0; i < n;) {
    int j = i + 1;
    while (j < n && s[i] == s[j]) j++;
    ps[m++] = pii(((s[i] == 'L') ? 0 : 1), j - i);
    i = j;
  }
  //for (int i = 0; i < m; i++) printf("(%d,%d)", ps[i].first, ps[i].second);
  //putchar('\n');

  int st = 0;
  for (; st + 2 < m && k > 0; st += 2, k--)
    ps[st + 2].second += ps[st].second + ps[st + 1].second;

  if (k > 0 && st + 1 < m) {
    ps[st + 1].second += ps[st].second;
    st++;
  }

  int sum = 0;
  for (int i = st; i < m; i++) sum += (ps[i].second - 1);

  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 1152
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
  int N;
  scanf("%d", &N);
  int A[N], ans = 0;
  for (int i = 0; i < N; ++i) scanf("%d", &A[i]);
  for (int i = 0; i < N; ++i) {
   if (A[i] % 2 && i % 2 == 0) ++ans; 
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 1732
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <functional>
#include <queue>
using namespace std;
const int INT_INF = 500000000;
const long long LONG_LONG_INF = (long long)pow(10, 18);
const int MOD = pow(10, 9) + 7;
/* contest template */
vector<pair<int, int>> p(90001);
int H, W, D, Q, l, r;
vector<vector<int>> A(300, vector<int>(300, 0));
int cs[90001];
int ans[100000];

int main()
{
    cin >> H >> W >> D;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> A[i][j];
            p[A[i][j]] = make_pair(i, j);
        }
    }
    //make cumulative sum table
    for (int i = 0; i < D; i++)
    {
        int j = i;
        while (j <= H * W)
        {
            if (j > D)
            {
                pair<int, int> a = p[j - D];
                pair<int, int> b = p[j];
                cs[j] = cs[j - D] + abs(a.first - b.first) + abs(a.second - b.second);
            }
            j += D;
        }
    }

    cin >> Q;
    for (int i = 0; i < Q; i++)
    {
        cin >> l >> r;
        ans[i] = cs[r] - cs[l];
    }
    for (int i = 0; i < Q; i++)
    {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
DEBUG = False

N, M, X = map(int, input().split())
A = []
C = []
for _ in range(N):
    CA = list(map(int, input().split()))
    C.append(CA[0])
    A.append(CA[1::])

if DEBUG:
    print(A)
    print(C)

max_money = 10**5 * N + 1
ans_money = max_money
# ans_algorythm = None
for i in range(2**N):
    bit = bin(i)[2::]
    bit = bit.zfill(N)
    if DEBUG:
        print("i: {}, bit: {}".format(i, bit))
    tmp_money = 0
    tmp_algorythm = [0] * M
    for j, b in enumerate(bit):
        if b == '1':
            tmp_money += C[j]
            for k, c in enumerate(A[j]):
                tmp_algorythm[k] += c
    if DEBUG:
        print("tmp_money: {}, tmp_algorythm: {}".format(tmp_money, tmp_algorythm))
    if len(list(filter(lambda x: x < X, tmp_algorythm))) == 0:
        ans_money = min(tmp_money, ans_money)
        if DEBUG:
            print("ans_money: {}".format(ans_money))
        # break

if ans_money == max_money:
    print(-1)
else:
    print(ans_money)


Measured memory_bytes: 9272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    string A,B,C;
    cin >> A >> B >> C;
    int numa,numb,numc;
    numa = A.size();
    numb = B.size();
    numc = C.size();
    int ca=0,cb=0,cc=0;
    char T = 'a';
    while(1){
        if(T=='a'){
            if(ca==numa){
                cout << "A" << endl;
                return 0;
            }
            T = A[ca];
            ca++;
        }else if(T=='b'){
            if(cb==numb){
                cout << "B" << endl;
                return 0;
            }
            T = B[cb];
            cb++;
        }else{
            if(cc==numc){
                cout << "C" << endl;
                return 0;
            }
            T = C[cc];
            cc++;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5+1;
vector<int> r(N), c(N);
map<pair<int,int>, bool> mp;
int main(){
    //freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int w,h,m;
    cin>>h>>w>>m;
    while(m--)
    {
        int i,j;
        cin>>i>>j;
        r[i]++; c[j]++;
        mp[{i,j}] = 1;
    }
    int mr = 0, mc = 0;
    for(int i=1;i<=h;i++)
        mr = max(mr,r[i]);

    for(int i=1;i<=w;i++)
        mc = max(mc,c[i]);

    set<int> x,y;
    for(int i=1;i<=h;i++)
        if(r[i] == mr)
            x.insert(i);
    for(int i=1;i<=w;i++)
        if(c[i] == mc)
            y.insert(i);
    for(auto i : x)
        for(auto j : y)
            if(mp.find({i,j}) == mp.end())
                {cout<<mr+mc; return 0;}
    cout<<mr+mc-1;
    return 0;
}

Measured memory_bytes: 52568
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;

int main() {
	int A,B;
	cin >> A;
	cin >> B;
	if (A <= 8 && B <= 8) cout << "Yay!";
	else cout << ":(";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int M1 = sc.nextInt();
   int N = sc.nextInt();
   int M2 = sc.nextInt();
   int N2 = sc.nextInt();

   if (M1!= M2)
     System.out.println(1);
   else System.out.println(0);

 
   
 }
}

Measured memory_bytes: 22228
def slove():
    import sys
    input = sys.stdin.readline
    l, r = list(map(int, input().rstrip('\n').split()))
    m = 10 ** 10
    for i in range(l, r + 1):
        for j in range(i + 1, r + 1):
            m = min(m, (i * j) % 2019)
            if m == 0:
                print(m)
                exit()
    print(m)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 40688
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int s = 0, s2 = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        s += x;
        s2 += x * x;
    }

    int x = (s + n / 2) / n;
    int d = s - x * n;
    int r = (s2 * n - s * s + d * d) / n;

    cout << r << endl;

    return 0;
}

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

int main(){
  int n,l;
  cin >> n >> l;
  int count=0;
  int ans=0;
  vector<int> taste(n);
  for(int i=0;i<n;i++){
    taste.at(i)=l+i;
    count += taste.at(i);
    if(taste.at(n-1)<0){
       ans=1;
    }else if(taste.at(i)==0){
       ans=2;
    }}
  if(ans==0){
    cout << count-taste.at(0) << endl;
  }else if(ans==1){
    cout << count-taste.at(n-1) << endl;
  }else{
    cout << count << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    double M=1;
    rep(i,N){
        M*=(i+1);
    }
    double A[N],B[N];
    vi v;
    rep(i,N) cin >> A[i] >> B[i];
    rep(i,N){
        v.push_back(i);
    }
    double sum=0;
    do{
        rep(i,N-1){
            sum+=sqrt((A[v[i+1]]-A[v[i]])*(A[v[i+1]]-A[v[i]])+(B[v[i+1]]-B[v[i]])*(B[v[i+1]]-B[v[i]]));
        }
    } while(next_permutation(all(v)));
    cout << sum/M << endl;

}

Measured memory_bytes: 256
package main

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

var rdr = bufio.NewReader(os.Stdin)

func myReadLine() string {
	buf := make([]byte, 0, bufio.MaxScanTokenSize)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

type lessFunc func(i, j *[]int) bool

type mySorter struct {
	data     [][]int
	lessfunc []lessFunc
}

func (ms mySorter) Len() int {
	return len(ms.data)
}

func (ms mySorter) Swap(i, j int) {
	ms.data[i], ms.data[j] = ms.data[j], ms.data[i]
}

func (ms mySorter) Less(i, j int) bool {
	var k int
	p, q := &ms.data[i], &ms.data[j]
	for k = 0; k < len(ms.lessfunc)-1; k++ {
		less := ms.lessfunc[k]
		switch {
		case less(p, q):
			return true
		case less(q, p):
			return false
		}
	}
	return ms.lessfunc[k](p, q)
}

func calc(n int, v []int) int {
	m1 := map[int]int{}
	m2 := map[int]int{}
	for i := 0; i < n; i += 2 {
		m1[v[i]]++
	}
	for i := 1; i < n; i += 2 {
		m2[v[i]]++
	}

	byCount := func(d1, d2 *[]int) bool {
		return (*d1)[1] > (*d2)[1]
	}
	m1a := [][]int{}
	m2a := [][]int{}
	for key, value := range m1 {
		m1a = append(m1a, []int{key, value})
	}
	sort.Sort(mySorter{data: m1a, lessfunc: []lessFunc{byCount}})
	/*
		sort.Slice(m1a, func(i, j int) bool {
			return m1a[i][1] > m1a[j][1]
		})
	*/
	for key, value := range m2 {
		m2a = append(m2a, []int{key, value})
	}
	sort.Sort(mySorter{data: m2a, lessfunc: []lessFunc{byCount}})

	if len(m1a) == 1 {
		if len(m2a) == 1 {
			if m1a[0][0] == m2a[0][0] {
				return m1a[0][1]
			} else {
				return 0
			}
		} else {
			if m1a[0][0] == m2a[0][0] {
				return n/2 - m2a[1][1]
			} else {
				return n/2 - m2a[0][1]
			}
		}
	} else {
		if len(m2a) == 1 {
			if m1a[0][0] == m2a[0][0] {
				return n/2 - m1a[1][1]
			} else {
				return n/2 - m1a[0][1]
			}
		} else {
			a := m1a[0][1]
			if m1a[0][0] == m2a[0][0] {
				a += m2a[1][1]
			} else {
				a += m2a[0][1]
			}
			b := m2a[0][1]
			if m1a[0][0] == m2a[0][0] {
				b += m1a[1][1]
			} else {
				b += m1a[0][1]
			}
			if a > b {
				return n - a
			} else {
				return n - b
			}
		}
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	v := make([]int, n)
	sv := strings.Split(myReadLine(), " ")
	for i, s := range sv {
		v[i], _ = strconv.Atoi(s)
	}
	fmt.Printf("%v\n", calc(n, v))
}


Measured memory_bytes: 13056
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int r, D, x;
	
	cin>>r>>D>>x;
	
	for(int i = 0; i < 10; i++){
		x = r*x - D;
		cout<<x<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int a, b, c; cin >> a >> b >> c;
	cout << a * b / 2 << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec a(n);
    rep(i, n) cin >> a[i];

    rep(i, n) {
        if (a[i] == 0) {
            cout << 0 << endl;
            exit(0);
        }
    }

    lint res = 1;
    long double check = 0;
    rep(i, n) {
        res *= a[i];
        check += log10(a[i]);
        if (res > 1000000000000000000 || check > 18.01) {
            cout << "-1" << endl;
            exit(0);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4600
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
typedef vector<ll> vcl;
#define mod 1000000007
int main() {
ll a,b,n;
cin>>a>>b>>n;
ll z=min(n,b-1);
ll ans =a*z/b-a*(z/b);
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = 1e9+7;
const ll INF = 1e9+1;

int n, m, r, a, b, c, ans=INF, x;
vector< vector<int> > dist(201, vector<int>(201, INF));
vector<int> towns;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("A.txt", "r", stdin);
    #endif
    cin >> n >> m >> r;
    for(int i=1; i<=n; i++) dist[i][i]=0;
    for(int i=0; i<r; i++)
    {
        cin >> x;
        towns.push_back(x);
    }
    for(int i=0; i<m; i++)
    {
        cin >> a >> b >> c;
        dist[a][b]=c;
        dist[b][a]=c;
    }
    sort(towns.begin(), towns.end());
    for(int k=1; k<=n; k++)
    {
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=n; j++)
            {
                dist[i][j]=min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }
    do
    {
        int cur=0;
        for(int i=0; i<r-1; i++)
        {
            cur += dist[towns[i]][towns[i+1]];
        }
        ans = min(ans, cur);
    }while(next_permutation(towns.begin(), towns.end()));
    cout << ans;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

int main() {
    int n; cin >> n;
    priority_queue<int> que;
    rep(i,(1<<n)) {
        int s; cin >> s;
        que.push(s);
    }
    vi p(1,que.top()); que.pop();
    rep(i,n) {
        vi rest;
        for (int j = 0; j < (1<<i) and !que.empty();) {
            int val = que.top(); que.pop();
            if (val < p[j]) {
                p.push_back(val);
                j++;
            } else {
                rest.push_back(val);
            }
        }
        outa(p,p.size());
        if (p.size() < (2<<i)) {
            cout << "No" << endl;
            return 0;
        }
        sort(p.rbegin(), p.rend());
        for (auto v : rest) que.push(v);
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3384
import collections
import numpy as np
aaa = 10 ** 9 + 7
N = int(input())
S =  [s for s in input()]
c = collections.Counter(S)
num = np.array(list(c.values()))
num = num + 1
count = 1
if N == 1:
    print(1)
else:
    for i in num:
        count *= i 
        count = count % aaa 
    print((count - 1))

Measured memory_bytes: 22776
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

int main() {
  int n;
  cin >> n;
  mint ans = 1;
  rep2(i, 1, n + 1) ans *= i;
  cout << ans << endl;
}

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

int main() {
	int N,a=101,cnt=0;
	cin >> N;
	vector<int> s(N);
	for(int i = 0;i < N;i++)
	{
		cin >> s.at(i);
	}
	sort(s.begin(),s.end());
	for(int i = 0;i < N;i++)
	{
		if(a > s.at(N - i - 1))
		{
			a = s.at(N - i - 1);
			cnt++;
		}
  }
	cout << cnt << endl;
}


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

int main() {
  int n;
  int ans=0;

  cin >> n;

  vector<int> a(n,0);

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

  for(int i=0;i<n;i+=2) {
    if(a[i]%2!=0) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3588
import sys
from bisect import bisect_left,bisect_right,insort
input = sys.stdin.readline
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parent=list(range(n+1))
        self.size=[1]*(n+1)
    def find(self,x):
    #根を探す。
    #別なグループ間をつなげた場合は、つなげた先の根に書き換える。
        if self.parent[x]==x:
            return x
        else:
            self.parent[x]=self.find(self.parent[x])
            return self.parent[x]
    def unite(self,x,y):
    #二つのグループをつなげる
    #大きいほうに小さいほうをつなげる。
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        else:
            if self.size[x]>=self.size[y]:
                self.parent[y]=x
                self.size[x]+=self.size[y]
            else:
                self.parent[x]=y
                self.size[y]+=self.size[x]
    def cnt(self,x):
    #サイズの取得
        return self.size[self.find(x)]

def main():
    n,m,k=map(int,input().split())
    u=UnionFind(n)
    ans=[0]*(n+1)
    for i in range(m):
        a,b=map(int,input().split())
        ans[a]-=1
        ans[b]-=1
        u.unite(a,b)
    for i in range(k):
        a,b=map(int,input().split())
        if u.find(a)==u.find(b):
            ans[a]-=1
            ans[b]-=1
    for i in range(1,n+1):
        ans[i]+=u.cnt(i)-1
    print(" ".join(map(str,ans[1:])))

if __name__ == '__main__':
    main()

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

int main(void){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> money(n+1,0);
    for (int i = 0; i <=n;i++){
        int temp;
        cin >> temp;
        money.at(temp) = 1;
    }
    int sum1 = 0;
    //０に向かう
    for (int i = x; i >= 0;i--){
        sum1 += money.at(i);
    }
    int sum2 = 0;
    for (int i = x; i <= n;i++){
        sum2 += money.at(i);
    }

    cout << min(sum1, sum2) << endl;
    return 0;
    }

Measured memory_bytes: 256
r,g,b,n = map(int,input().split())
rgb = [r,g,b]
rgb.sort()
x = rgb[2]
y = rgb[1]
z = rgb[0]
ans = 0

for i in range(n//x+30):
    for j in range(n//y+30):
        if (n-x*i-y*j)%z ==0:
            if (n-x*i-y*j)//z >=0:
                ans += 1
          
print(ans)

Measured memory_bytes: 40556
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define For(I,N) for(int I=0;I<N;I++)
#define cinone(N) int N;cin>>N;
#define scanfone(N) int N;cin>>N;
#define cinng(N,M) int N[M];for(int yiuytvnm=0;yiuytvnm<M;yiuytvnm++) cin>>N[yiuytvnm];
#define scanfng(N,M) int N[M];for(int qrwuoiq=0;qrwuoiq<M;qrwuoiq++) scanf("%d",&N[qrwuoiq]);
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
string c;

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>c;
	if(c.size()<=6) over("NO");
	for(int i=0;i<=c.size();i++)
	{
		for(int j=0;j<=c.size();j++)
		{
			if(i+j>c.size()) continue;
			if(c.size()-j+1<0) continue;
			string t=c.substr(0,i);
			t+=c.substr(c.size()-j,j);
			if(t=="keyence") over("YES");
		}
	}
	cout<<"NO"<<endl;
	return 0;
}

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

#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 510000;
const long long MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
  int k, q;
  cin >> k >> q;
  vector<long long> d(k);
  rep(i, k) cin >> d[i];
  rep(i, q) {
    long long n, x, m;
    cin >> n >> x >> m;
    vector<long long> d_mod(k);
    x %= m;
    rep(j, k) d_mod[j] = d[j] % m;
    long long t = (n-1) / k;
    long long r = (n-1) % k;
    vector<long long> times(k, t);
    rep(j, k) {
      if(j+1 <= r) times[j]++;
      else break;
    }
    long long last = x;
    long long diff = 0;
    rep(j, k) {
      if(d_mod[j] == 0) diff += times[j];
      last += d_mod[j] * times[j];
    }
    diff += (last / m) - (x / m);
    cout << (n-1) - diff << endl;
  }
}


Measured memory_bytes: 384
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def gcd(a, b):
# 例外処理
    if a == 0:
        return b
    if b == 0:
        return a

    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

def main():
    N = INT()
    A = LIST()
    A.insert(0, 0)
    A.append(0)
    L = [0] * (N + 2)
    R = [0] * (N + 2)
    L[0] = 0
    # R[]
    R[N + 1] = 0
    for i in range(0, N + 1):
        L[i + 1] = gcd(L[i], A[i])
    for i in range(N, -1, -1):
        R[i] = gcd(R[i + 1], A[i])

    # print(L)
    # print(R)
    ans = 0
    for i in range(1, N + 1):
        ans = max(ans, gcd(L[i], R[i+1]))
    print(ans)

if __name__ == "__main__":
    main()




Measured memory_bytes: 16212
import java.util.*;
import java.text.*;

public class Main {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int len = String.valueOf(n).length();
    int[] arr = {3, 5, 7};
    int cnt = 0;

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

    void run() {

        if (n<357) {
            System.out.println(0);
            return;
        }

        dfs("");

        System.out.println(cnt);
    }

    void dfs(String s) {
        if (3 <= s.length() && s.length() <= len) {
//            System.out.println(s);
            if (s.contains("3") && s.contains("5") && s.contains("7") && Integer.parseInt(s) <= n) cnt++;
            if (s.length() != len) {
                for (int i=0; i<arr.length; i++) dfs(s + arr[i]);
            };
        } else {
            for (int i=0; i<arr.length; i++) {
                dfs(s + arr[i]);
            }
        }
    }


}


Measured memory_bytes: 43172
# coding: utf-8
import math as m
N = int(input())

# フラクタルのステップをnとする
# 端点p1, p2を与えてs, t, uを計算
class Point(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
    
def rotateX(s, t, theta):
    return m.cos(theta)*(t.x - s.x) - m.sin(theta)*(t.y - s.y) + s.x

def rotateY(s, t, theta):
    return m.sin(theta)*(t.x - s.x) + m.cos(theta)*(t.y - s.y) + s.y
    
def koch(n, p1, p2):
    if n == 0:
        return
    # p1, p2からs, t, uを求める
    s = Point((2*p1.x + p2.x)/3, (2*p1.y + p2.y)/3)
    t = Point((p1.x + 2*p2.x)/3, (p1.y + 2*p2.y)/3)
    u = Point(rotateX(s, t, m.pi/3), rotateY(s, t, m.pi/3))
    
    # 各辺に対しても同様にs, t, uを求める
    # printの順番に注意
    koch(n-1, p1, s)
    print("{0:.8f} {1:.8f}".format(s.x, s.y))
    koch(n-1, s, u)
    print("{0:.8f} {1:.8f}".format(u.x, u.y))
    koch(n-1, u, t)
    print("{0:.8f} {1:.8f}".format(t.x, t.y))
    koch(n-1, t, p2)

p1 = Point(0, 0)
p2 = Point(100, 0)
print("{0:.8f} {1:.8f}".format(p1.x, p1.y))
koch(N, p1, p2)
print("{0:.8f} {1:.8f}".format(p2.x, p2.y))

Measured memory_bytes: 8040
#include <stdio.h>
#include <math.h>

int main(void)
{
	int step, a, tmp = 0;
	double x = 0.0, y = 0.0;
	
	while(scanf("%d,%d", &step, &a) != EOF && (step != 0 || a != 0)){
		
		x += step * (sin((tmp * 3.14159) / 180.0));
		y += step * (cos((tmp * 3.14159) / 180.0));
		tmp += a;
	}
	
	printf("%d\n", (int)x);
	printf("%d\n", (int)y);
	
	return 0;
}

Measured memory_bytes: 1032
use proconio::input;

fn main(){
    input! {
        n : usize,
        s : String
    };
    let r = s.match_indices("R").count();
    let g = s.match_indices("G").count();
    let b = s.match_indices("B").count();
    let c = s.as_bytes();
    let mut res = r * g * b;
    for i in 0..n {
        for j in 1..n {
            if i + 2 * j >= n { break }
            if c[i] != c[i+j] && c[i+j] != c[i+2*j] && c[i+2*j] != c[i] {
                res -= 1;
            }
        }
    }
    println!("{}", res);
}

Measured memory_bytes: 2172
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ph push
#define ptc putchar
#define enter putchar('\n')
#define mod 1000000007
using namespace std;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long lnt;
inline int read(){
	int x = 0;char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + c - '0' , c = getchar();
	return x;
}
inline void write(int x){
	if (!x){
       ptc('0');
       return;
	}
	int dg[20] , len = 0;
	while (x) dg[len++] = x % 10 , x /= 10;
	while (len--) ptc(dg[len]+'0');
}
inline void writeln(int x){
	write(x);
	ptc('\n');
}
inline int add(int x,int y){
	x += y;if (x >= mod) x -= mod;
	return x;
}
inline int sub(int x,int y){
	x -= y;if (x < 0) x += mod;
	return x;
}
inline int qpow(int x,int y){
	int res = 1;
	while (y){
		if (y & 1) res = 1ll * res * x % mod;
		x = 1ll * x * x % mod;y >>= 1;
	}
	return res;
}

const int N = 1e5 + 10;
int n , a[N] , suminv[N] , presum[N] , sufsum[N] , dis[N] , ans;

int main(){
	scanf("%d",&n);
	for (int i = 1;i <= n + 1;i++){
		suminv[i] = add(suminv[i-1] , qpow(i , mod - 2));
	}
	for (int i = 1;i <= n;i++){
		scanf("%d",&a[i]);
		presum[i] = add(presum[i-1] , a[i]);
	}
	for (int i = n;i >= 1;i--){
		sufsum[i] = add(sufsum[i + 1] , a[i]);
	}
	
	for (int dist = 0;dist <= n - 1;dist++){
		dis[dist] = presum[n - dist];
		if (dist){
			dis[dist] = add(dis[dist] , sufsum[dist + 1]);
		}
//		printf("[%d %d]\n",dist,dis[dist]);
	}
	
//	for (int i = 1;i <= n;i++) ans = add(ans , 1ll * add(suminv[i] - 1 , suminv[n - i + 1]) * a[i] % mod);
	for (int i = 0;i <= n - 1;i++) ans = add(ans , 1ll * qpow(i + 1 , mod - 2) % mod * dis[i] % mod);
	for (int i = 1;i <= n;i++) ans = 1ll * ans * i % mod;
	cout<<ans;
	return 0;
}



Measured memory_bytes: 2176
#include <stdio.h>
int Maxcheck(int *p,int *q,int *r)
{
  int a,b,c;
  a=*p;b=*q;c=*r;
  int Max,m1,m2;
  if (a>b & a>c)
    {
      Max=a;m1=b;m2=c;
    }
  else if (b>c & b>a)
    {
      Max=b;m1=c;m2=a;
    }
  else if (c>a & c>b)
    {
      Max=c;m1=a;m2=b;
    }
  else if (a==b & b==c)
    {
      Max=a;m1=b;m2=c;
    }
  else if (a==b)
    {
      if (a>c)
        {
          Max=a;m1=b;m2=c;
        }
      else
        {
          Max=c;m1=a;m2=b;
        }
    }
  else if(b==c)
    if (a>b)
      {
        Max=a;m1=b;m2=c;
      }
    else
      {
        Max=c;m1=a;m2=b;
      }
  else if(c==a)
    if (a>b)
      {
        Max=a;m1=b;m2=c;
      }
    else
      {
        Max=b;m1=a;m2=b;
      }
  *p=Max;*q=m1;*r=m2;
}

int main(void)
{
  int n,i,p,q,r;
  scanf("%d",&n);
  for(i=0;i!=n;i++)
    {
      scanf("%d %d %d",&p,&q,&r);
      Maxcheck(&p,&q,&r);
      if (p*p==q*q+r*r)
        {
          printf("YES\n");
        }
      else
        {
          printf("NO\n");
        }
    }
  return 0;
}

Measured memory_bytes: 0
n = int(input())
di = {}
for i in range(1,1000000):
    di[i] = 0
for i in range(1, 150):
    for j in range(1, 150):
        for k in range(1, 150):
            di[i**2+j**2+k**2+i*j+j*k+k*i] += 1
for i in range(1, n+1):
    print(di[i])

Measured memory_bytes: 199988
let id x = x
let (h,w) = Scanf.scanf "%d %d" (fun h w -> (h,w))
         
let repeat f n=
    let rec loop acc =function
        | 0->List.rev acc
        | n -> loop (f ():: acc)(n -1) in
    loop [] n

let list' = repeat (fun () -> Scanf.scanf "%s\n" id) (h+1)

let list = List.tl list'         
         
let rec makeshstr w str =
               if w = 0 then str else makeshstr (w-1) ("#" ^ str)  

let shstr = makeshstr w "##"
          
let () =
  let rec pri list =
    match list with
    | [] -> Printf.printf "%s\n" shstr
    | ans :: rest -> (Printf.printf "#%s#\n" ans) ; pri rest
  in Printf.printf "%s\n" shstr; pri list


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  int n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  string s;
  cin >> s;
  for(int i=a; i<c-1; i++) {
    if(s[i]=='#'&&s[i+1]=='#') {
      cout << "No" << endl;
      return 0;
    }
  }
  for(int i=b; i<d-1; i++) {
    if(s[i]=='#'&&s[i+1]=='#') {
      cout << "No" << endl;
      return 0;
    }
  }
  if(c>d) {
    for(int i=b; i<=d; i++) {
      if(s[i-2]=='.'&&s[i-1]=='.'&&s[i]=='.') {
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 640
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include <iostream>

using namespace std;

int main()
{
    char c;
    
    while(cin>>c){
        if(c=='1')cout << '9';
        else cout << '1';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
class Node():
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None
        self.parent = None


class BinarySearchTree():
    def __init__(self):
        self.root = None

    def insert(self, key):
        root_node = self.root
        insert_node = Node(key)
        parent_node = None

        while root_node:
            parent_node = root_node
            if insert_node.key < root_node.key:
                root_node = root_node.left
            else:
                root_node = root_node.right

        insert_node.parent = parent_node

        if parent_node is None:
            self.root = insert_node
        elif insert_node.key < parent_node.key:
            parent_node.left = insert_node
        else:
            parent_node.right = insert_node

    def find(self, key):
        root_node = self.root

        while root_node:
            if root_node.key == key:
                print('yes')
                return 0
            elif root_node.key < key:
                root_node = root_node.right
            else:
                root_node = root_node.left

        print('no')

    def show_preorder(self, node):
        node_list = []

        node_list.append(node.key)
        if node.left is not None:
            node_list.extend(self.show_preorder(node.left))
        if node.right is not None:
            node_list.extend(self.show_preorder(node.right))

        return node_list

    def show_inorder(self, node):
        node_list = []

        if node.left is not None:
            node_list.extend(self.show_inorder(node.left))
        node_list.append(node.key)
        if node.right is not None:
            node_list.extend(self.show_inorder(node.right))

        return node_list

    def print(self):
        print(' ' + ' '.join(map(str, self.show_inorder(self.root))))
        print(' ' + ' '.join(map(str, self.show_preorder(self.root))))


if __name__ == '__main__':
    tree = BinarySearchTree()

    n = int(input())

    for i in range(n):
        command = input().split()

        if command[0] == 'insert':
            tree.insert(int(command[1]))
        elif command[0] == 'find':
            tree.find(int(command[1]))
        elif command[0] == 'print':
            tree.print()

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

int main(){

    string s;
    cin >> s;

    s.pop_back();

    while(s.size()!=0){
        string t,u;
        if(s.size()%2==0){
            t=s.substr(0,s.size()/2);
            u=s.substr(s.size()/2,s.size()/2);
        }else{
            s.pop_back();
            continue;
        }
        if(u==t){
            cout << t.size()*2 <<endl;
            return 0;
        }
        s.pop_back();
    }

    cout << 0  << endl;

    return 0;
}

Measured memory_bytes: 256