akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
int A[3];
int L[8];
int b[3];
int main(){
  int i, j, k, mask, res, tmp;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<3;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  {
    int KL2GvlyY;
    for(KL2GvlyY=0;KL2GvlyY<N;KL2GvlyY++){
      rd(L[KL2GvlyY]);
    }
  }
  res = 1073709056;
  for(mask=0;mask<1<<(2*N);mask++){
    b[0] = b[1] = b[2] = 0;
    k = mask;
    tmp = 0;
    for(i=0;i<N;i++){
      j = k%4;
      k /= 4;
      if(j!=3){
        b[j] += L[i];
        tmp++;
      }
    }
    if(!b[0] || !b[1] || !b[2]){
      continue;
    }
    chmin(res, 10*(tmp-3) + abs(A[0]-b[0]) + abs(A[1]-b[1]) + abs(A[2]-b[2]));
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190715-1

// --- original code ---
// int N, A[3], L[8];
// int b[3];
// {
//   int i, j, k, mask;
//   int res, tmp;
//   rd(N,A(3),L(N));
// 
//   res = int_inf;
//   rep(mask,1<<(2N)){
//     b[0] = b[1] = b[2] = 0;
//     k = mask;
//     tmp = 0;
//     rep(i,N){
//       j = k%4;
//       k /= 4;
//       if(j!=3) b[j] += L[i], tmp++;
//     }
//     if(!b[0] || !b[1] || !b[2]) continue;
//     res <?= 10(tmp-3) + abs(A[0]-b[0]) + abs(A[1]-b[1]) + abs(A[2]-b[2]);
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const int MOD = 1000000007;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
template<class T>
int dp2csv(const vector<vector<T>>& dp, const string fname);
int range_check(int val, int min, int max) {
	if (val < min) {
		return min;
	}
	if (val > max) {
		return max;
	}
	return val;
}
int main() {
	string str;
	cin >> str;
	if (str == "SUN")
		cout << 7 << endl;
	else if (str == "MON")
		cout << 6 << endl;
	else if (str == "TUE")
		cout << 5 << endl;
	else if (str == "WED")
		cout << 4 << endl;
	else if (str == "THU")
		cout << 3 << endl;
	else if (str == "FRI")
		cout << 2 << endl;
	else if (str == "SAT")
		cout << 1 << endl;
	return 0;
}
template<class T>
int dp2csv(const vector<vector<T>>& dp, const string fname) {
	ofstream ofs(fname);
	if (ofs.fail()) { cerr << "cannot open file. :" + fname << endl; return -1; }
	for (auto dp_row : dp) {
		for (auto dp_cell : dp_row) {
			ofs << dp_cell << ",";
		}
		ofs << endl;
	}
	ofs.close();
	return 0;
}


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


counter = {}
for number in A:
    if number not in counter:
        counter[number] = 1
    else:
        counter[number] += 1

tmp = 0
for c in counter.values():
    tmp += c * (c-1) // 2

answer = [0] * N

for i, number in enumerate(A):
    v = counter[number]
    answer[i] = str(tmp - v * (v-1) // 2 + (v-1) * (v-2) // 2)

print('\n'.join(answer))


Measured memory_bytes: 127052
#include <bits/stdc++.h>
using namespace std;
 
long long gcd(long x,long y){
    if(y==0)return x;

    return gcd(y,x%y);
}
long long lcm(long x,long y){
    return x*y/gcd(x,y);
}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main()
{
    long long K,N,a,b;
    map<long long,long long> mp;
    cin>>N>>K;

    for(long long i=1;i<=N;i++){
        cin>>a>>b;

        mp[a]+=b;
    }

    long long sum=0;

    for(auto itr = mp.begin(); itr!=mp.end();itr++){

        sum+=itr->second;

        if(sum>=K){
            cout<<itr->first<<endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,i;
  cin >> n;
  vector<int> a(n);
  for(i=0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  int cnt = 0;
  int cnt2 = 0;
  for(i=0;i<n-1;i++){
    if(a[i]==a[i+1]) cnt++;
    else{
      if(cnt%2==0) cnt2++;
      cnt = 0;
    }
  }
  if(cnt%2==0) cnt2++;
  cout << cnt2 << "\n";
  return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1) 

const ll INF = 10010001010;
const int inf = 2000000000;


typedef tuple<string, int, int> TUP;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int N, L;
    cin >> N >> L;
    ll sum = 0;
    int big = -13245;
    vector<int> A(N);
    int ans = 2345678;
    for (int i = 0; i < N; i++)
    {
        A[i] = i + L;
        sum += A[i];
        ans = min(ans, abs(A[i]));
        big = max(big,abs(A[i]));
    }
    if(A[N-1] < 0){
        cout << sum + ans << endl;
    }
    else{
        cout << sum - ans << endl;
    }
}


Measured memory_bytes: 256
from collections import deque, defaultdict
from itertools import chain, combinations
import json


def main():
    # N = int(input())
    H, W = [int(a) for a in input().split()]
    S = [
        input()
        for _ in range(H)
    ]

    def saitan(start, end):
        mem = {start}

        def get_rinsetsu(ii, jj):
            d = [
                (1, 0),
                (-1, 0),
                (0, 1),
                (0, -1),
            ]
            res = []
            for di, dj in d:
                ni = ii + di
                nj = jj + dj
                if ni < 0 or nj < 0:
                    continue
                if ni >= H or nj >= W:
                    continue
                if S[ni][nj] == '.':
                    if (ni, nj) not in mem:
                        res.append((ni, nj))
            return res

        q = [(start, 0)]
        while len(q) != 0:
            (i, j), distance = q.pop(0)
            rinsetsu = get_rinsetsu(i, j)
            for r in rinsetsu:
                if r == end:
                    return distance + 1, mem
                q.append((r, distance + 1))
                mem.add(r)
        return -1, mem

    res = -1
    for a in range(H * W):
        start = a // W, a % W
        mm = set()
        if S[start[0]][start[1]] == '#':
            continue
        for b in range(a + 1, H * W):
            end = b // W, b % W
            if S[end[0]][end[1]] == '#':
                continue
            if end in mm:
                continue
            ddd, m = saitan(start, end)
            mm |= m
            res = max(res, ddd)
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 75612
#include <iostream>

int main(int argc, char *argv[])
{
  using namespace std;
  int a, b, c, tmp;
  cin >> a >> b >> c;
  if (a > b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  if (b > c) {
    tmp = b;
    b = c;
    c = tmp;
  }
  if (a > b) {
    tmp = a;
    a = b;
    b = tmp;
  }

  cout << a << " " << b << " " << c << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;

int main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    vector<int> nums;
    int now = 1; // 今見ている数
    int cnt = 0; // いくつ並んでいるか
    rep(i, n) {
        if (s[i] == (char)('0' + now)) cnt ++;
        else {
            nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if (cnt != 0) nums.push_back(cnt);
    if (nums.size()%2==0) nums.push_back(0);

    int add = 2 * k + 1;
    int ans = 0;
    for (int i=0; i<nums.size(); i+=2) {
        int tmp = 0;
        int left = i;
        int right = min(i+add, (int)nums.size());
        for (int j=left; j<right; ++j) {
            tmp += nums[j];
        }
        ans = max(tmp, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
  vector<pair<int,int> > v;
  int a, b;
  while(cin >> a >> b && (a || b)){
    v.push_back(make_pair(a, b));
  }
  for(int i=0;i<(int)v.size();i++){
    for(int j=0;j<v[i].first;j++){
      for(int k=0;k<v[i].second;k++){
        if((j+k) % 2 == 0){
          cout << "#";
        }else{
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1188
class BinTree
  attr_accessor :node
  def initialize(n)
    @node = Array.new(n){Node.new()}
  end
  def preorder(n=root())
    str = ""
    return str if n < 0
    #root
    str << sprintf(" %s", n)
    #left
    str << preorder(node[n].left)
    #right
    str << preorder(node[n].right)
    return str
  end
  def inorder(n=root())
    str = ""
    return str if n < 0
    #left
    str << inorder(node[n].left)
    #root
    str << sprintf(" %s", n)
    #right
    str << inorder(node[n].right)
    return str
  end
  def postorder(n=root())
    str = ""
    return str if n < 0
    #left
    str << postorder(node[n].left)
    #right
    str << postorder(node[n].right)
    str << sprintf(" %s", n)
  end
  def root
    #find root
    r = 0
    node.size.times {|i|
      if node[i].parent == -1 then
        r = i
        break
      end
    }
    return r
  end
  def add(i, l, r)
    node[i].left = l
    node[i].right = r
    node[l].parent = i unless l == -1
    node[r].parent = i unless r == -1
  end
end

class Node
  attr_accessor :parent, :left, :right
  def initialize
    @parent = -1
    @left = -1
    @right = -1
  end
end



n = gets.to_i
tree = BinTree.new(n)

n.times{
  i, l, r = gets.split.map(&:to_i)
  tree.add(i, l, r)
}

puts "Preorder"
puts tree.preorder()
puts "Inorder"
puts tree.inorder()
puts "Postorder"
puts tree.postorder()

Measured memory_bytes: 8732
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int n, m;
bool ok(int i, int j) {
    return i >= 0 && i < n && j >= 0 && j < m;
}
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int a, b;
    string s;
    cin >> a >> b >> s;
    bool ok = 1;
    if (s[a] != '-') ok = 0;
    forn(i, sz(s)) {
        if (i != a && (s[i] < '0' || s[i] > '9')) {
            ok = 0;
            break;
        }
    }
    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

using namespace std;

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define FORR(i,a,b) for (int i = a; i <= b; i++)
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;

const int MX = 100005;
int n;
string s;
vi a;
bitset<MX> ex;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> s;
	n = s.size();

	if (s.back() == '1' || s[0] == '0' || s[s.size()-2] == '0') {
		cout << -1 << endl;
		return 0;
	}

	for (int i = 0, j = s.size() - 2; i <= j; i++, j--) {
		if (s[i] != s[j]) {
			cout << -1 << endl;
			return 0;
		}
		if (s[i] == '1') {
			ex[i+1] = 1;
			a.pb(i+1);
		}
	}

	int cn = 1;

	for (int i = 1; i < a.size(); i++) {
		cout << a[i] << " " << a[i-1] << endl;
		for (int j = 1; j < a[i] - a[i-1]; j++) {
			while (ex[cn]) cn++;
			cout << a[i] << " " << cn << endl;
			cn++;
		}
	}

	cout << a.back() << " " << n << endl;
	while (ex[cn]) cn++;
	while (cn < n) {
		cout << n << " " << cn << endl;
		cn++;
		while (ex[cn]) cn++;
	} 

	return 0;
}

Measured memory_bytes: 1868
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const long long inf=1e17;
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pii;
int main(){
	int n,m;
	cin>>n>>m;
	vvi cost(n,vi(n,inf));
	rep(i,n)cost[i][i]=0;	
	while(m--){
		int a,b,c;
		cin>>a>>b>>c;
		cost[a][b]=c;
	}
	rep(k,n)rep(i,n)rep(j,n)if(cost[i][k]!=inf&&cost[k][j]!=inf)
		cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
	int h=true;
	rep(i,n)if(cost[i][i]<0)h=false;
	if(!h){
		cout<<"NEGATIVE CYCLE"<<endl;
	}else{
		rep(i,n){
			rep(j,n){
				if(j)cout<<" ";
				if(cost[i][j]==inf)cout<<"INF";
				else cout<<cost[i][j];
			}
			cout<<endl;
		}
	}
}

Measured memory_bytes: 1296
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args){
	int a, b, m = 0, l = 0;

//	try{
		Scanner scan = new Scanner(System.in);
		
		a = Integer.parseInt(scan.next());
		b = Integer.parseInt(scan.next());
		
		if(a >= 1 || b<= 100){
			m = a * b;
			l = (a + b) * 2;
		}else{
			//a = null;
			//b = null;
		}
		
		System.out.println(m + " " + l);

//	}catch(IOException e){
	
//	}


	}

}

Measured memory_bytes: 26236
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-
# arc058_a

# input
N, K = map(int, input().split())
D = input().split()
# getans
def is_in_d(s):
	for d in D:
		if d in s:
			return True
	return False
for i in range(100000):
	ans = str(N+i)
	if not is_in_d(ans):
		break
# output
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define pint pair<int,int>
using namespace std;

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

ll fun(ll a, ll b){
	if(a==0 || b==0)	return 0;
	if(a<b){
		ll temp=a;	a=b;	b=temp;
	}
	if(a%b==0){
		ll temp=a/b;
		return (2*temp-1)*b;
	}

	ll temp=a/b;

	return 2*temp*b+fun(a%b,b);
}

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

	cout<<n+fun(n-x,x)<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MOD=2019;
int main()
{
    int l,r;
    cin>>l>>r;
    if(r-l+1>=2020)
    {
        cout<<0<<endl;
        return 0;
    }
    int ans=2020;
    for(int i=l;i<=r;i++)
    {
        for(int j=i+1;j<=r;j++)
        {
            int n1=i%MOD, n2=j%MOD;
            ans=min(ans,n1*n2%MOD);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    n,X = LI()
    x = LI()
    for i in range(n-1):
        x[i+1] += x[i]
    x.insert(0,0)
    ans = float("inf")
    f = [5]*(n+1)
    for i in range(1,n):
        f[i+1] = f[i]+2
    for k in range(1,n+1):
        i = 0
        a = n
        d = (k+n)*X
        while a > 0:
            d += f[i]*(x[a]-x[max(0,a-k)])
            a -= k
            i += 1
        ans = min(ans,d)
    print(ans)
#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 79824
//*******bharath*************/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
void RUN()
{
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
 
}
int a[100005][4];
int rem[100005][4];
int n;

int ans(int i,int prev)
{
    if(i==n)
        return 0;
    if(rem[i][prev]!=-1)
        return rem[i][prev];
        
    int k = 0;
	if (prev == 0) 
	{
		k=max(k, a[i][1] + ans(i + 1, 1));
		k=max(k, a[i][2] + ans(i + 1, 2));
		k=max(k, a[i][3] + ans(i + 1, 3));
	}
	else if (prev == 1)
	{
		k = max(k, a[i][2] + ans(i+ 1, 2));
		k = max(k, a[i][3] + ans(i + 1, 3));
	}
	else if (prev == 2) 
	{
		k = max(k, a[i][1] + ans(i + 1, 1));
	    k = max(k, a[i][3] + ans(i + 1, 3));
	}
	else
	{
		k=max(k,a[i][1]+ans(i + 1, 1));
		k=max(k,a[i][2]+ans(i + 1, 2));
	}
 
	return rem[i][prev] = k;
        
}

void solve()
{
	cin>>n;
	for(int i=0;i<n;i++)
	    for(int j=1;j<=3;j++)
	        cin>>a[i][j];
	for(int i=0;i<n+2;i++)
	    for(int j=0;j<4;j++)
	        rem[i][j]=-1;
	cout<<ans(0,0)<<endl;
	
}

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

Measured memory_bytes: 14532
import sys
import itertools

input = sys.stdin.readline


def main():
    N = int(input())
    A1 = [int(x) for x in input().split()]
    A2 = [int(x) for x in input().split()]

    dp = list(itertools.accumulate(A1))
    ans = A1[0] + A2[0]
    for i in range(1, N):
        ans = max(ans, dp[i]) + A2[i]

    print(ans)




if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
package main

import (
	"fmt"
)

func main() {
	var A, B, K int
	fmt.Scan(&A)
	fmt.Scan(&B)
	fmt.Scan(&K)
	// var A, B, K = 8, 12, 2

	var count int
	for i := 100; i >= 1; i-- {
		if A%i == 0 && B%i == 0 {
			count += 1
			if count == K {
				fmt.Println(i)
				break
			}
		}
	}
}


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

using namespace std;

const int mod = 1000000007;
const int N = 205;

const int SZ = 100005;

int inv[N];
int s[SZ];
int dp[N][SZ];

int mul(int a, int b) {
    return (1LL * a * b) % mod;
}

int add(int a, int b) {
    a += b;
    if (a >= mod) a -= mod;
    return a;
}


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

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

    sort(s, s + n);

    for (int i = 0; i <= x; i++) {
        dp[0][i] = i % s[0];
    }

    for (int i = 1; i < n; i++) {
        for (int j = 0; j <= x; j++) {
            dp[i][j] = add(dp[i - 1][j % s[i]], mul(dp[i - 1][j], i));
        }
    }

    cout << dp[n - 1][x];
    //dp[i][j] = dp[i - 1][j % s[i]] + dp[i - 1][j] * i;
}

Measured memory_bytes: 80128
#include<iostream>
#include<vector>
#include<map>

using namespace std;

int main(){
  int n; cin >> n;
  map<vector<int>, long long> a;
  string s;
  long long ans = 0;
  for(int i = 0; i < n; i++){
    cin >> s;
    vector<int> t(26, 0);
    for(int j = 0; j < 10; j++){
      t[s[j]-'a']++;
    }
    a[t]++;
  }
  for(auto i:a){
    ans += i.second * (i.second - 1) / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 18944
use std::io::Read;

const U32_LARGE: u32 = 1 << 30;

fn read<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();
    let m = read();
    let mut a = vec![0; m];
    let mut b = vec![0; m];
    let mut c = vec![Vec::new(); m];
    for i in 0..m {
        a[i] = read();
        b[i] = read();
        c[i].resize(b[i], 0);
        for j in 0..b[i] {
            c[i][j] = read();
        }
    }

    // 宝箱の部分集合 k を開けるのに必要な最小コスト
    let mut dp = vec![U32_LARGE; 1 << n];

    dp[0] = 0;
    for k in 0..(1 << n) {
        for i in 0..m {
            let mut nk = k;
            for j in 0..b[i] {
                nk |= 1 << (c[i][j] - 1);
            }
            if dp[k] + a[i] < dp[nk] {
                dp[nk] = dp[k] + a[i];
            }
        }
    }

    if dp[(1 << n) - 1] == U32_LARGE {
        println!("{}", -1);
    } else {
        println!("{}", dp[(1 << n) - 1]);
    }
}


Measured memory_bytes: 4352
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
r = 0
for i in range(N):
  r += B[A[i]-1]
for i in range(N-1):
  if (A[i] +1)== A[i+1]:
    r += C[A[i]-1]
print(r)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

#define _GLIBCXX_DEBAC
using namespace std;
	

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int x = 0;
	for (int i = 0; i < n-1; i++) {
		if (s[i] == s[i + 1]) {
			x += 1;
		}
	}
	cout << n-x;
		return 0;
}









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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  int n;
  cin >> n;
  vi h(n);
  rep(i,n) cin >> h[i];
  vi dp(n);
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);
  for(int i = 2; i < n; i++) {
    dp[i] = min((dp[i-1] + abs(h[i]-h[i-1])), (dp[i-2] + abs(h[i]-h[i-2])));
  }
  cout << dp[n-1] << endl;
}

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

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    int N, R;
    cin >> N >> R;

    if (N >= 10) {
        cout << R << "\n";
    } else {
        cout << R + 100 * (10 - N) << "\n";
    }

    return 0;
}


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

int main(){
    char a;
    cin>>a;
    if(a=='A') cout<<'T'<<endl;
    if(a=='T') cout<<'A'<<endl;
    if(a=='G') cout<<'C'<<endl;
    if(a=='C') cout<<'G'<<endl;
}

Measured memory_bytes: 256
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect
from random import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

def cost(A, x):
  return sum((a-x)**2 for a in A)

N = read()
A = reads()
m = sum(A) // N
print(min(cost(A, m), cost(A, m+1)))

Measured memory_bytes: 38640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL;

const int MAX = 1100000;
const int 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;
}

int main()
{ 
    // 前処理
    COMinit();

    int n,k;
    cin>>n>>k;
    LL a[n];
    for(int i=0;i<n;i++){cin>>a[i];}
    sort(a,a+n);
    if(k==1){cout<<0<<endl;return 0;}
    //累積和
    LL sum[n];
    for(int i=0;i<n;i++){
        if(i==0){sum[i]=a[i];}
        else{sum[i]=sum[i-1]+a[i];}
    }
    LL ans=0;
    for(int i=k-2;i<=n-2;i++){
        LL x=sum[n-1]-sum[i]-sum[n-i-2];
        x=x%MOD;
        ans=ans+x*COM(i,k-2);
        ans=ans%MOD;
    }

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

Measured memory_bytes: 27648
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		long x = ir.nextLong();
		long ret = (x / 11) * 2;
		x %= 11;
		if (x > 0) {
			if (x <= 6)
				ret++;
			else
				ret += 2;
		}
		out.println(ret);
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 21076
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

const p = 1000000007

func Solve() {
  var N, A, B int
  NextInt(&N, &A, &B)
  if A > B { A, B = B, A }
  S := make([]int, N + 1)
  S[0] = -int(1e18)
  DP := make([]int, N + 2)
  DP[0] = 1
  s, t := 0, -1
  for i := 1; i <= N; i++ {
    NextInt(&S[i])
    if i > 1 && S[i] - S[i - 2] < A { Write(0); return }
    for S[i] - S[t + 1] >= B {
      t++
      DP[i] = (DP[i] + DP[t]) % p
    }
    DP[i + 1] = DP[i]
    if S[i] - S[i - 1] < A {
      for s < i - 1 {
        if s <= t { DP[i + 1] = (DP[i + 1] - DP[s] + p) % p }
        DP[s] = 0
        s++
      }
    }
  }
  Write(SumInt(DP[:N + 1]...) % p)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func Max(a, b int) int {
  if a < b { return b }
  return a
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}
func Ceil(x, y int) int {
  a := x / y
  if x % y > 0 { a++ }
  return a
}

Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int n, a[1000];
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    scanf("%d", &n);
    if(!n)break;
    rep(i, n)scanf("%d", a+i);
    sort(a, a + n);
    int res = 12345123;
    rep1(i, n)res = min(res, a[i] - a[i - 1]);
    pri(res);
  }
  return 0;
}

Measured memory_bytes: 3220
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	vector<vector<int>> d(c, vector<int>(c));
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			cin >> d[i][j];
		}
	}

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

	vector<vector<int>> cost(3, vector<int>(c));
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				cost[(j+k) % 3][i] += d[a[j][k]][i];
			}
		}
	}

	int res = INF;
	for (int c1 = 0; c1 < c; c1++) {
		for (int c2 = 0; c2 < c; c2++) {
			if (c1 == c2)continue;

			for (int c3 = 0; c3 < c; c3++) {
				if (c3 == c1 || c3 == c2)continue;
				int cnt = 0;

				cnt += cost[0][c1];
				cnt += cost[1][c2];
				cnt += cost[2][c3];

				res = min(res, cnt);
			}

		}

	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define LL long long
using namespace std ;
void Read ( int &x, char c = getchar(), bool f = 0 ) {
	for ( x = 0 ; !isdigit(c) ; c = getchar() ) if (c == '-') f = 1 ;
	for ( ; isdigit(c) ; c = getchar() ) x = 10*x + c - '0' ;
	if (f) x = -x ;
}
int pos[3] ;
int main() {
	int n ;
	Read(n) ; Read(pos[0]) ; Read(pos[1]) ;
	bool first = 0, now ;
	if (pos[0] > pos[1]) first = 1 ;
	now = first ;
	while (pos[1] - pos[0] > 1) {
		if (now) -- pos[1] ;
		else ++ pos[0] ;
		now ^= 1 ;
	}
	while (1) {
		if (now) {
			if (pos[1] - pos[0] > 1) -- pos[1] ;
			else {
				if (pos[1] ^ n) ++ pos[1] ;
				else {
					puts("Alice") ;
					return 0 ;
				}
			}
		} else {
			if (pos[1] - pos[0] > 1) ++ pos[0] ;
			else {
				if (pos[0] ^ 1) -- pos[0] ;
				else {
					puts("Borys") ;
					return 0 ;
				}
			}
		}
		now ^= 1 ;
	}
	puts("Draw") ;
	return 0 ;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 8)

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1; b-= 1
    g[a].append(b)
    g[b].append(a)
friends = [0 for _ in range(n)]

def dfs(v):
    global n
    friends[v] = n
    n += 1
    for next_v in g[v]:
        if friends[next_v] == 0:
            dfs(next_v)
    
for i in range(n):
    if friends[i] == 0:
        n = 1
        dfs(i)
print(max(friends))

Measured memory_bytes: 217204
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <numeric>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

int main(void){
  double t,x;
  cin >> t >> x;
  cout << t/x;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

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

    vector<bool> a(x+1, false);
    a[0] = true;

    for (int i = 1; i <= x; ++i) {
        for (int j = 100; j <= 105; j++) {
            if (i-j < 0) continue;
            if (a[i-j]) a[i] = true;
        }
    } 

    cout << (a[x] ? 1 : 0) << endl;

    return 0;
}


Measured memory_bytes: 256
X,Y,A,B,C = [int(i.strip()) for i in input().split(' ')]
p = [int(i.strip()) for i in input().split(' ')]
q = [int(i.strip()) for i in input().split(' ')]
r = [int(i.strip()) for i in input().split(' ')]

pd = sorted(p, reverse=True)
RED = pd[:X]
qd = sorted(q,reverse=True)
GREEN = qd[:Y]

ALL = r + RED +GREEN

ad = sorted(ALL,reverse=True)
print(sum(ad[:X+Y]))

Measured memory_bytes: 24880
#include<iostream>
#include<stdio.h>//printf("%.9f\n",*********);
#include<vector>//文字列.erase(n)
#include<algorithm>//next_permutation
#include<set>
#include<string>//char(小文字-32=大文字) to_string
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drrep(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define str string
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {

	int n, a, b;
	cin >> n >> a >> b;

	int sum = 0;

	rrep(i, n) {
		if (a <= keta(i) && keta(i) <= b) {
			sum += i;
		}
	}
	cout << sum << rt;

	please AC;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  vl cum(200001, 0LL);
  vl c(n);
  vl dp(n + 1);
  REP(i, n) { cin >> c[i]; }

  c.erase(unique(c.begin(), c.end()), c.end());

  dp[0] = 1LL;
  FOR(i, 1, c.size() + 1) {
    dp[i] = (dp[i - 1] + cum[c[i - 1]]) % MOD;
    cum[c[i - 1]] = (cum[c[i - 1]] + dp[i - 1]) % MOD;
  }
  cout << dp[c.size()] << endl;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <stdio.h>
using namespace std;
#define pb push_back
#define pf push_fron
#define INF 1000000000
typedef long long ll;

int a, b, c, d;

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

	int st, en;

	if (a > c) st = a;
	else st = c;

	if (b < d)en = b;
	else en = d;

	cout << ((b<c||d<a)?0:(en - st)) << endl;

	return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline T GCD(T a, T b) {
    return b ? GCD(b, a % b) : a;
}
template<class T>
inline T LCM(T a, T b) {
    return (a + (b - 1)) / b;
}

int round_int(int a, int b) {
    return (a + (b - 1)) / b;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int dp[101][76];

bool isp(int a)
{
	for(int i=2;i*i<=a;i++)if(a%i==0)return 0;
	return 1;
}

int main() {
	int n;
	cin >> n;
	dp[0][1] = 1;
	int p = 0;
	for (int i = 2; i <= n; i++)
	{
		if (!isp(i))continue;
		int cnt = 0;
		for (int j = 1; j <= n; j++)
		{
			int a = j;
			while (a % i == 0)cnt++, a /= i;
		}
		for (int j = 0; j <= cnt; j++)
		{
			for (int k = 1; k * (j + 1) <= 75; k++)
			{
				dp[i][k * (j + 1)] += dp[p][k];
			}
		}
		p = i;
	}
	cout << dp[p][75] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[30] , b[30] , c[30];
int main()
{
    int n;
    cin>>n;
    for(int i =1 ; i <= n ; i++ ) cin>>a[i];
    for(int i =1 ; i <= n ; i++ ) cin>>b[i];
    for(int i =1 ; i <= n-1 ; i++ ) cin>>c[i];
    
    int tot = 0;
    int last = -1;
    for(int i = 1 ; i<=n ; i++ ) {
        
        tot += b[a[i]];
        if(last == a[i] -1) tot += c[last];
        last = a[i];
    }
    cout<<tot<<endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define ces(d) cout<<" "<<endl;

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

ce((A-1)*(B-1));
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int i,j,n,count=0,v,c,c1,v1;
  int G[101][101],color[101],d[101],pi[101],mincost,ii;
  for(i=0;i<101;i++){
    for(j=0;j<101;j++)G[i][j]=-1;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&c);
    for(j=0;j<c;j++){
      scanf("%d%d",&v1,&c1);
      G[v][v1]=c1;
    }
  }

  for(i=0;i<n;i++){
    color[i]=0;
    pi[i]=-1;
    d[i]=10000001;
  }
  d[0]=0;

  while(1){
    mincost=10000001;
    for(i=0;i<n;i++){
      if(color[i]!=2 && d[i]<mincost){
        mincost=d[i];
        ii=i;
      }
    }
    if(mincost==10000001)break;
    color[ii]=2;
    for(i=0;i<n;i++){
      if(G[ii][i]!=-1 && color[i]!=2 && (G[ii][i]+d[ii])<d[i]){
	pi[i]=ii;
	d[i]=G[ii][i]+d[ii];
	color[i]=1;
      }
    }
  }
  for(i=0;i<n;i++)printf("%d %d\n",i,d[i]);
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
int n,m;
int vis[105][105];
char a[105][105];
void find_row()
{
  for(int i=0;i<n;i++){
        int t=0;
    for(int j=0;j<m;j++){
        if(a[i][j]=='.')
            t++;
    }
    if(t==m){
        for(int k=0;k<m;k++)
            vis[i][k]=1;
    }
  }
}
void find_col()
{
    for(int i=0;i<m;i++){
            int t=0;
        for(int j=0;j<n;j++){
            if(a[j][i]=='.')
                t++;
        }
        if(t==n){
            for(int k=0;k<n;k++)
                vis[k][i]=1;
        }
    }
}
void print_ans()
{
    for(int i=0;i<n;i++){
            int t=0;
        for(int j=0;j<m;j++){
            if(!vis[i][j])
                printf("%c",a[i][j]),t++;
        }
    if(t)
        printf("\n");
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%s",a[i]);
    find_col();
    find_row();
    print_ans();
    return 0;
}


Measured memory_bytes: 256
S = input()
flag = True

for i in range(len(S) // 2):
    if S[i] != S[len(S) - 1 - i]:
        flag = False

for i in range((len(S) - 1) // 2 //2):
    if S[i] != S[(len(S) - 1) // 2 -1 - i]:
        flag = False

for i in range((len(S) - (len(S) + 3 // 2)) // 2):
    if S[(len(S) + 3) // 2 -1 + i] != S[len(S) - 1 - i]:
        flag = False
        
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064