akhauriyash/Code-Regression huggingface dataset:
n = int(input())
S = [str(input()) for _ in range(n)]
from collections import defaultdict
dic = defaultdict(int)

for s in list(S[0]):
    dic[s] += 1
for s in S[1:]:
    tmp = defaultdict(int)
    for i in list(s):
        tmp[i] += 1
    for j in dic.keys():
        dic[j] = min(dic[j], tmp[j])

ans = []
for d in dic.keys():
    num = dic[d]
    ans += [d]*num

ans.sort()
print(''.join(ans))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
        using namespace std;
        #include <ext/pb_ds/assoc_container.hpp>
        #include <ext/pb_ds/tree_policy.hpp>
        using namespace __gnu_pbds;
        #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
        #define ll long long
        #define int long long
        #define lb long double
        #define f(i,a,b) for(int i=(a);i<=(b);i++)
        #define fd(i,a,b) for(int i=a;i>=b;i--)
        #define vi vector<int>
        #define mii map<int,int>
        #define pii pair<int,int>
        #define si set<int>
        #define pb push_back
        #define mk make_pair
        #define fi first
        #define se second
        #define fv(i,v) for(auto i=v.begin();i!=v.end();++i)
        #define fdv(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
        #define print(a,n) f(i,1,n) cout<<a[i]<<" "; cout<<endl;
        #define printv(v) for(auto iv: v) cout<<iv<<" "; cout<<endl;
        #define all(v) v.begin(),v.end()
        #define r(a,n) ll a[n+1]; f(i,1,n) cin>>a[i];
        #define pi 3.141592653589793238
        const int mod=1e9+7;
        const int inf=1e18;
        int parent[26];
        int size[26];
        const int A=26;
        //bool vis[1000+1]={};
        const int MAXN=2*1e6+1;
        int spf[MAXN];
        ll power(ll x, unsigned ll y)
        {
            ll res = 1;
            while (y > 0)
            {
                if (y & 1)
                    res = res*x;
                y = y>>1;
                x = x*x;
            }
            return res;
        }

        bool isPrime(int n)
        {
            if (n <= 1)
                return false;
            if (n <= 3)
                return true;

            if (n % 2 == 0 || n % 3 == 0)
                return false;

            for (int i = 5; i * i <= n; i = i + 6)
                if (n % i == 0 || n % (i + 2) == 0)
                    return false;

            return true;
        }
        void sieve()
        {
            spf[1] = 1;
            for (int i=2; i<MAXN; i++)
                spf[i] = i;
            for (int i=4; i<MAXN; i+=2)
                spf[i] = 2;
            for (int i=3; i*i<MAXN; i++)
            {
                if (spf[i] == i)
                {
                    for (int j=i*i; j<MAXN; j+=i)
                        if (spf[j]==j)
                            spf[j] = i;
                }
            }
        }

        int lcm(int a, int b)
        {
            return (a*b)/__gcd(a,b);
        }

        signed main()
        {
            ios_base::sync_with_stdio(false);
            cin.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            {
                string s,t1;
                cin>>s;
                cin>>t1;
                int c=0;
                f(i,0,s.size()-1)
                {
                    if(s[i]!=t1[i])c++;
                }
                cout<<c<<endl;
            }
        }


Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    string a[3]; rep(i, 3) cin >> a[i];
    int nxt = 0;
    while (1) {
        int tmp = a[nxt][0] - 'a';
        if (SZ(a[nxt]) == 0) { out((char)(nxt + 'A')); return 0; }
        a[nxt] = a[nxt].substr(1, SZ(a[nxt]) - 1);
        nxt = tmp;
    }
}




Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <numeric>
using namespace std;

int main() {
	int a, p;
	cin >> a >> p;
	cout << ((3 * a) + p) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    string S; cin >> S;
    int N = (int)S.size();
    ll ans = 0;
    for(int bit=0;bit<(1<<(N-1));bit++){
        ll tmp = 0;
        for(int i=0;i<N-1;i++){
            tmp = tmp*10+(S[i]-'0');
            /*cout<<"tmp="<<tmp<<endl;
            cout<<"bit="<<bit<<endl; */
            if((bit>>i) & 1){
                ans += tmp;
                tmp = 0;
            }
        }
        tmp = tmp*10+(S[N-1]-'0');
        ans += tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def compress(list01):
    newList=[]
    n=len(list01)
    now=1
    count0=0
    count1=0
    list01.append((list01[-1]+1)%2)
    for i in range(n+1):
        nex=list01[i]
        if now==0:
            if nex==0:
                count0+=1
            if nex==1:
                count1+=1
                newList.append(count0)
                count0=0
        if now==1:
            if nex==0:
                count0+=1
                newList.append(count1)
                count1=0
            if nex==1:
                count1+=1
        now=nex
    if list01[-2]==0:
        newList.append(0)
    return newList

def measure_insect(mixed_list,k):
    n=(len(mixed_list)-1)//2
    now=sum(mixed_list[:2*k+1])
    maximum=now
    for i in range(n-k):
        now-=mixed_list[2*i]
        now-=mixed_list[2*i+1]
        now+=mixed_list[2*i+2*k+1]
        now+=mixed_list[2*i+2*k+2]
        if now>maximum:
            maximum=now
    return maximum

N,K=map(int,input().split())
S=[int(_) for _ in input()]

print(measure_insect(compress(S),K))

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> h(n);
  vector<int> d(n);
  rep(i, n) {
    cin >> h[i].first;
    h[i].second = i;
  }

  sort(h.begin(), h.end());
  int ans = 1e9;
  for (int i = 0; i < n - k + 1; ++i) {
    d[i] = h[i + k - 1].first - h[i].first;
    ans = min(ans, d[i]);
  }

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


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

int main(){
	int n,k;
	cin>>n>>k;
	int next;
	int answer=0;
	while(n-->0){
		cin>>next;
		answer+=min(k-next,next);
	}
	cout<<answer*2;
	return 0;
} 

Measured memory_bytes: 256
#B問題
import math
K = int(input())
A = list(map(int,input().split()))
B = A[::-1]

MIN = 0
MAX = 0
flag = 0
for i in range(K):
    if i == 0:
        if B[i] != 2:
            flag = 1
            break
        else:
            MIN = 2
            MAX = 3
    else:
        if MAX < B[i]:
            flag = 1
            break
        else:
            MAX = (MAX//B[i] + 1)*B[i]-1
            MIN = math.ceil(MIN/B[i])*B[i]
            if MAX < MIN:
                flag = 1
                break
if flag == 1:
    print(-1)
else:
    print(MIN,MAX)

Measured memory_bytes: 15020
#include <iostream>
using namespace std;
int main(){
    int x,y;
    cin >> x >> y;
    string board[x];
    for (int i = 0 ; i < x ; i++){
            cin >> board[i];
    }
    for (int i = 0 ; i < x ; i++){
        for (int j = 0 ; j < y ; j++){
            cout << board[i][j];
        }
        cout << endl;
        for (int j = 0 ; j < y ; j++){
            cout << board[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 1e9 + 5
#define C 998244353
#define pi 3.14159265359
#define loop(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define rloop(i,a,b) for(ll i = ll(a); i >= ll(b); --i)
#define sloop(i,a) for (std::set<ll>::iterator i = a.begin(); i != a.end(); ++i)
#define pb push_back
#define all(v) v.begin(), v.end()
typedef long long int ll;
typedef unsigned long long int ull;

int solve(){
    ll m=0,n,res=0,flag=0,ans=0,ma=-1,mb=-1;
    string s;
    cin >> s;
    if(s[s.length()-1]=='s')
        cout << s + "es" << "\n";
    else
        cout << s + "s" << "\n";
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    loop(f,0,t){    
        solve();
    }   
}

Measured memory_bytes: 3624
A = input()
B = input()
if len(A) > len(B):
    print("GREATER")
elif len(A) < len(B):
    print("LESS")
else:
    for i in range(len(A)):
        if A[i] > B[i]:
            print("GREATER")
            exit()
        elif A[i] < B[i] :
            print("LESS")
            exit()
    print("EQUAL")

Measured memory_bytes: 3064
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let a: isize = sc.input();
    let op: String = sc.input();
    let b: isize = sc.input();

    let ans = if op == "+" {
        a + b
    } else {
        a - b
    };
    println!("{}", ans);
}


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

using namespace std;
using ll = long long;


int main()
{
    string s;
    cin >> s;
    for(auto&i:s)i -= '0';
    int cnt = 0;
    for(auto&i:s)cnt += i;
    cout << (cnt % 9 ? "No" : "Yes") << endl;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    int A,B;
    cin >> A >> B;
    if (A-2*B <= 0) {
        cout << 0 << endl;
    }else{
        cout << A-2*B << endl;
    }
    
    
    
    
    return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=550;
//ここまでテンプレ
int main(){
	vector<tuple<int,int,int,int>> ans;
	int H,W;
	cin>>H>>W;
	int A[SIZE][SIZE]={};
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>A[i][j];
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W-1;j++){
			if(A[i][j]%2){
				A[i][j]--;
				A[i][j+1]++;
				//cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
				ans.eb(i+1,j+1,i+1,j+2);
			}
		}
	}
	for(int i=0;i<H-1;i++){
		if(A[i][W-1]%2){
			A[i][W-1]--;
			A[i+1][W-1]++;
			//cout<<i+1<<" "<<W<<" "<<i+2<<" "<<W<<endl;
			ans.eb(i+1,W,i+2,W);
		}
	}
	cout<<ans.size()<<endl;
	for(tuple<int,int,int,int> T:ans){
		int a,b,c,d;
		tie(a,b,c,d)=T;
		cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
	}
	return 0;
}

Measured memory_bytes: 5360
from collections import defaultdict
N = int(input())
d = defaultdict(int)

for i in range(1, N+1):
  s, t = str(i)[0], str(i)[-1]

  if s != 0 and t != 0:
    if s > t:
      s, t = s, t
    d[(s, t)] += 1

ans = 0
for i in range(1, 11):
  for j in range(1, 11):
    i = str(i)
    j = str(j)
    ans += d[(i, j)]*d[(j, i)]

print(ans)


Measured memory_bytes: 73828
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s[100], co;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> co;
  if (co == "SUN")
    Cout(7);
  else {
    s[0] = "SUN";
    s[1] = "MON";
    s[2] = "TUE";
    s[3] = "WED";
    s[4] = "THU";
    s[5] = "FRI";
    s[6] = "SAT";
    rep(i, 7) {
      if (s[i] == co) tmp = i;
    }
    Cout(7 - tmp);
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
	int n;
	while(cin>>n,n){
		int top=1,south=2,east=3,sum=1;
		for(int i=0;i<n;++i){
			string s;
			cin>>s;
			if(s=="North"){
				int tmp=top;
				top=south;
				south=7-tmp;
			}else if(s=="East"){
				int tmp=east;
				east=top;
				top=7-tmp;
			}else if(s=="West"){
				int tmp=top;
				top=east;
				east=7-tmp;
			}else if(s=="South"){
				int tmp=south;
				south=top;
				top=7-tmp;
			}else if(s=="Right"){
				int tmp=south;
				south=east;
				east=7-tmp;
			}else if(s=="Left"){
				int tmp=east;
				east=south;
				south=7-tmp;
			}
			sum+=top;
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 1212
def read():
    return list(map(int, input().split()))

n = read()[0]

a = read()
p = a[0]
res = 0
num = 0
for i in range(1, n):
    q = a[i]
    if p > q:
        if res == 1:
            num += 1
            res = 0
        elif res == 0:
            res = -1
    elif p < q:
        if res == -1:
            num += 1
            res = 0
        elif res == 0:
            res = 1
    p = q
print(num + 1)

Measured memory_bytes: 14228
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int Q;
  cin >> Q;
  while( Q-- ) {
    string s = "";
    for(int i=0; i<8; i++) {
      char c;
      cin >> c;
      if( c == '0' ) s += "0000";
      if( c == '1' ) s += "0001";
      if( c == '2' ) s += "0010";
      if( c == '3' ) s += "0011";
      if( c == '4' ) s += "0100";
      if( c == '5' ) s += "0101";
      if( c == '6' ) s += "0110";
      if( c == '7' ) s += "0111";
      if( c == '8' ) s += "1000";
      if( c == '9' ) s += "1001";
      if( c == 'a' ) s += "1010";
      if( c == 'b' ) s += "1011";
      if( c == 'c' ) s += "1100";
      if( c == 'd' ) s += "1101";
      if( c == 'e' ) s += "1110";
      if( c == 'f' ) s += "1111";
      // cout << s << endl;
    } 
 
    long long int sum = 0;
    long double sum2 = 0;
    for(int i=24; i>0; i--) {
      if( s[i] == '1' ) {
    sum += pow(2.0, 24-i);
      }
    }
    for(int i=25; i<32; i++) {
      if( s[i] == '1' ) {
    sum2 += pow(0.5, i-25+1);
      }
    }
    
    long long int tmp = (long long int)sum2;
    if( sum2 - (long double)tmp > 0 ) {
      if( s[0] == '1' ) {
    cout << '-';
      }
      string add = "";
      while( 1 ) {
    if( sum2 == 0 ) break;
    sum2 *= 10;
    tmp = (long long int)sum2;
    add += '0' + tmp;
    sum2 -= (long double)tmp;
      }
     
      cout << sum << '.' << add << endl;
    } else {
      if( s[0] == '1' ) {
    cout << '-';
      }
      cout << sum << ".0" << endl; 
    }
  }
   
}

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

int gcd(int a, int b)
{
    int c = (a > b)? a : b;
    int d = (a > b)? b : a;

    if (c%d==0)
        return d;
    return gcd(c%d, d);
}

int main()
{
    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;
    return 0;
}



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

int main() {
  int l, r, d;
  cin >> l >> r >> d;
  int small, big;
  if(l%d==0) small = l;
  else small = (l/d+1)*d;
  if(r/d==0) big = r;
  else big = (r/d)*d;
  if(l==r && l%d==0) {
    cout << 1 << endl;
    return 0;
  }
  cout << (r-l+1)/d << endl;
//  cout << small << endl << big << endl;
  return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
#define N 100000
int main(){
    int n,i,j,x[N],num=0,min=1000000,top=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x[i]);
        if(x[i]>top) top=x[i];
    }
    for(i=0;i<=top;i++){
            num=0;
        for(j=0;j<n;j++){
            num+=(x[j]-i)*(x[j]-i);
        }
        if(min>num) min=num;
    }
    printf("%d\n",min);
    return 0;
}

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

using namespace std;

int main()
{
    unsigned int n = 100000;
    int week;
    
    cin >> week;
    
    for (int i = 0; i < week; i++)
    {
        n *= 1.05;
        if (n % 1000 > 0)
        {
            n = (n / 1000 + 1) * 1000;
        }
    }
    
    cout << n << endl;
    
    return 0;
}



Measured memory_bytes: 2976
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

#define LL long long
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int MAXN = 600010;
const int INF = 2147483600;

int N;

int Node[MAXN<<1],Next[MAXN<<1],Root[MAXN+1],C[MAXN<<1],cnt; 
inline void addedge(int u,int v,int c){
	Node[cnt]=v; Next[cnt]=Root[u]; C[cnt]=c; Root[u]=cnt++;
}
inline void insert(int u,int v,int c){
	addedge(u,v,c); addedge(v,u,0);
}
int S,T; int dis[MAXN+1];
inline bool BFS(){
	for(int i=S;i<=T;i++) dis[i]=0;
	queue<int> que; que.push(S); dis[S]=1;
	while(!que.empty()){
		int k=que.front();
		for(int x=Root[k];x!=-1;x=Next[x]){
			int v=Node[x]; 
			if(C[x]>0&&!dis[v]) dis[v]=dis[k]+1,que.push(v); 
		} que.pop();
	} 
	return (dis[T]?1:0);
}
inline int DFS(int k,int t){
	if(k==T) {return t;} int ret=0;
	for(int x=Root[k];x!=-1;x=Next[x]){
		int v=Node[x]; if(C[x]>0&&dis[v]==dis[k]+1){
			int d=DFS(v,min(t,C[x]));
			C[x]-=d; C[x^1]+=d; ret+=d; t-=d;
			if(!t) return ret;
		}
	} if(!ret) dis[k]=0;
	return ret;
}
int nod;
queue<int> que; int vis[MAXN+1],chs[MAXN+1],root;
vector<int> vec[MAXN+1]; int P[MAXN+1];
inline void Add(int k){
	++nod; for(int i=0,sz=vec[k].size();i<sz;i++){
		int j=vec[k][i];
		if(!vis[j]&&chs[j]!=k) vis[j]=k,que.push(j); 
	}
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	N=read(); T=2*N,S=0;
	memset(Root,-1,sizeof(Root));
	for(int i=1;i<N;i++){
		P[i]=read();
		insert(S,i,1);
		for(int j=1;j<=P[i];j++){
			int x=read();
			vec[x].push_back(i);
			insert(i,x+N-1,1);
		}
	}
	for(int i=1;i<=N;i++) insert(i+N-1,T,1);
	int sum=0; while(BFS()) sum+=DFS(S,INF);
	if(sum!=N-1){ puts("-1"); return 0; }
	int id=1; int now=0;
	for(int i=1;i<N;i++){
		now+=2;
		for(int j=1;j<=P[i];j++){
			if(!C[now]) chs[i]=Node[now]-(N-1);
			now+=2;
		}
	}
	while(now<cnt) {
		if(C[now]) {
			root=id; break;
		} now+=2; ++id;
	} 
	Add(root);
	while(!que.empty()){ int k=que.front();  Add(chs[k]); que.pop(); }
	if(nod!=N){ puts("-1"); return 0; }
	for(int i=1;i<N;i++) printf("%d %d\n",chs[i],vis[i]);
	return 0;
}




Measured memory_bytes: 42512
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
//		int m = scan.nextInt();
//		int a = scan.nextInt();
		
		int[] ww = new int[n];
		int s1 = 0;
		int s2 = 0;
		int ss = 0;
		for(int i=0;i<n;i++) {
			int w = scan.nextInt();
			ww[i] = w;
		}
		for(int i=1; i<n; i++) {
			for(int j=0;j<n;j++) {
				if(j<=i) {
					s1+=ww[j];
				}else {
					s2+=ww[j];
				}
			}
  
			if(i==1) {
			ss = Math.abs(s2-s1);
			}if(ss>Math.abs(s2-s1)) {
				ss = Math.abs(s2-s1);
			}
			s1=0;
			s2=0;
			
		}
		System.out.println(ss);
		
	}

}

Measured memory_bytes: 23892
import itertools

n, m=map(int, input().split())
branch=[]
for i in range(m):
    a, b=map(int, input().split())
    branch.append((a, b))
seq=[]
for i in range(2, n+1):
    seq.append(i)
ans=0
permutation=list(itertools.permutations(seq))
for i in range(len(permutation)):
    number_list=list(map(int, permutation[i]))
    start=1
    flag=1
    for j in range(n-1):
        if not ((start, number_list[j]) in branch or (number_list[j], start) in branch):
            flag=0
            break
        start=number_list[j]
    if flag:
        ans=ans+1
print(ans)


Measured memory_bytes: 43500
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int line[101],n,r,map[101];
char map3[100000];
char map2[100][101];


int c(const void *v1,const void *v2){
    return strcmp((char *)v1,(char *)v2);
}

int main(void){
    int l,i;
    scanf("%d %d",&n,&l);
    for(i=0;i<n;i++)
        scanf("%s",map2[i]);
    qsort(map2,n,sizeof(map2[0]),c);
    for(i=0;i<n;i++)
        strcat(map3,map2[i]);
    printf("%s\n",map3);
    return 0;
}

    


Measured memory_bytes: 252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59


struct UnionFind {
    int n, cnt;
    vector<int> par, rank, sz;

    UnionFind(int n) : n(n), cnt(n), par(n), rank(n), sz(n, 1) {
        iota(par.begin(), par.end(), 0);
    }

    int find(int x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return sz[find(x)];
    }

    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
            sz[y] += sz[x];
        } else {
            par[y] = x;
            sz[x] += sz[y];
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
        cnt--;
    }
};


int main(){
  ll i,j;
  ll n,r;
  cin>>n>>r;
  ll p[n+1];

  for(i=1;i<=n;i++) {
    ll x;
    cin>>x;
    p[i]=x;
  }
  
  ll used[n+1];
  for(i=1;i<=n;i++){
    used[i]=0;
  }


  UnionFind uf(n+1);
  vector<ll> v;

  for(i=1;i<=n;i++){
    if(used[i]==0){
      used[i]=1;
      ll t=i;
      ll si=1;
      while(uf.find(t)!=uf.find(p[t])){
        uf.unite(t,p[t]);
        si++;
        t=p[t];
        used[t]=1;
      }
      v.pb(si);
    } 
  }

  VI cnt(n+1,0);
  for(i=0;i<v.size();i++) cnt[v[i]]++;

  vector<P> u;
  for(i=0;i<=n;i++){
    if(cnt[i]>0) u.pb(P(i,cnt[i]));
  }
  ll z=u.size();

  VI dp(n+1,-1);
  dp[0]=0;

  for(i=0;i<z;i++){
    for(j=0;j<n+1;j++){
      if(dp[j]>=0) {
        dp[j]=u[i].se;
      } else if(j<u[i].fi || dp[j-u[i].fi]<=0 ){
        dp[j]=-1;
      } else{
        dp[j]=dp[j-u[i].fi]-1;
      }
    }
  }

  if(dp[r]>=0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  

  return 0;
}


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

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int x, y, z;
  cin >> x >> y >> z;
  swap(x,y);
  swap(x,z);
  cout << x << " " << y << " " << z << endl;
  return 0;
}

Measured memory_bytes: 384
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var n=arr.shift()-0;
var book=[];
for(var i=0;i<n;i++)book[i]=arr.shift();
var q=arr.shift()-0;
for(var i=0;i<q;i++){
   if(i!=0)console.log("");
   var ans=[];
   var v=arr.shift().split(" ");
   var a=v[0];
   var b=v[1];
   var c=(v[2]!="*")?(new Date(v[2])).getTime():"*";
   var d=(v[3]!="*")?(new Date(v[3])).getTime():"*";
   book.forEach(function(V){
      V=V.split(" ");
      var A=V[0];
      var B=V[1];
      var C=(new Date(V[2])).getTime();
      var flag=true;
      if(a!="*"){
         var regex = new RegExp(a);
         if(regex.test(A)==false)flag=false;
      }
      if(b!="*"){
         var regex = new RegExp(b);
         if(regex.test(B)==false)flag=false;
      }
      if(c!="*"){
         if(c>C)flag=false;
      }
      if(d!="*"){
         if(d<C)flag=false;
      }
      if(flag)ans.push(A);
   });
   ans.forEach(function(value){
       console.log(value);
   });
}

Measured memory_bytes: 17928
use List::Util qw/reduce/;
sub any (&@) {my $p = shift; return reduce { $a || $p->(local $_ = $b) } 0, @_}
my $input = <stdin>;
chomp($input);
my ($a, $b) = split(' ', $input);

print ((any {$_ % 3 == 0 } ($a, $b, $a+$b)) ? 'Possible' : 'Impossible');

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    string s;

    cin >> s;

    int res = 0;

    for (int i = 0; i < s.size() / 2; i++)
    {
        res += s[i] != s[s.size() - 1 - i];
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#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;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
int n, k;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    ll v[n];
    for (int i = 0; i < n; i++)
        cin >> v[i];
    ll ans = -1000000 * 50;
    for (int i = 0; i <= min(n, k); i++) //取る個数
    {
        for (int j = 0; j <= i; j++) //右から取る
        {
            ll sum = 0;
            vector<ll> s;
            for (int l = 0; l < i - j; l++) //和
            {
                s.push_back(v[n - 1 - l]);
            }
            for (int l = 0; l < j; l++) //和
            {
                s.push_back(v[l]);
            }
            sort(ALL(s));
            int drow = max(0, k - i);
            for (int h = 0; h < i; h++)
            {
                if (s[h] < 0 && drow > 0)
                {
                    drow--;
                }
                else
                {
                    sum += s[h];
                }
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
Acount = {}
q = []
 
for a in A:
  if a not in Acount:
    Acount[a] = 0
  
  Acount[a] += 1
    
for key, val in Acount.items():
  if val >= 2:
    q.append(key)
    
  if val >= 4:
    q.append(key)
 
q.sort(reverse=True)
 
if len(q) < 2:
  print(0)
else:
  print(q[0]*q[1])


Measured memory_bytes: 18060
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

ll 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;
    }
}

ll 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(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string L;
    cin >> L;

    ll n = L.size();
    vector<ll> dp1(n), dp2(n);
    dp1[0] = 1; dp2[0] = 2;
    Rep (i, n-1) {
        if (L[i+1] == '0'){
            dp1[i+1] = 3 * dp1[i] % MOD;
            dp2[i+1] = dp2[i];
        } else {
            dp1[i+1] = (3 * dp1[i] % MOD + dp2[i]) % MOD;
            dp2[i+1] = 2 * dp2[i] % MOD;
        }        
    }

    cout << (dp1[n-1] + dp2[n-1]) % MOD << "\n";
}

Measured memory_bytes: 2000
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));

  const x = s[0];
  const a = s[1];
  const b = s[2];

  let ans = '';

  if (a >= b) {
    ans = 'delicious';
  } else if (x >= (b - a)) {
    ans = 'safe';
  } else {
    ans = 'dangerous';
  }

  console.log(ans);
}

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


Measured memory_bytes: 7372
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int
var t float64

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	as := intSliceScanner(n)
	idx := -1
	amx := 0
	for i := 0; i < n; i++ {
		if abs(as[i]) >= amx {
			amx = abs(as[i])
			idx = i
		}
	}
	ans := make([][]int, 0, n*2)
	for i := 0; i < n; i++ {
		if as[idx]*as[i] < 0 {
			ans = append(ans, []int{idx, i})
		}
	}
	if as[idx] > 0 {
		for i := 0; i < n-1; i++ {
			ans = append(ans, []int{i, i + 1})
		}
	} else {
		for i := n - 1; i > 0; i-- {
			ans = append(ans, []int{i, i - 1})
		}
	}
	fmt.Println(len(ans))
	for _, v := range ans {
		fmt.Println(v[0]+1, v[1]+1)
	}
}


Measured memory_bytes: 1784
MOD = 10**9 + 7

N = int(input())
A = [int(x) for x in input().split()]

sum = 0
squaresum = 0
for i in range(N):
    sum = (sum + A[i]) % MOD
    squaresum = (squaresum + A[i]**2) % MOD
ans = ((sum**2) % MOD - squaresum) % MOD
if ans % 2 == 0:
    print(ans//2)
else:
    print((ans + MOD)//2)

Measured memory_bytes: 94120
#include<iostream>
#include <bits/stdc++.h>
 
#define ll long long
#define endl "\n"
#define rep(i,a,b) for(int i=a;i<b;i++)
 
using namespace std;
 
int main(void) {
		ios::sync_with_stdio(0);
		cin.tie(0);
		cout.tie(0);
		int k;
	    cin>>k;
  		string s;
  		cin>> s;
  	if(s.length()>k){
      rep(i,0,k) cout<<s[i];
      cout<<"..."<<endl;
    }
  else
    cout<<s<<endl;	   
}

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void rec(lol& n, int i, lol& result);
int che;

int main()
{
    lol result{0};
    lol n; cin >> n;
    lol m = n;
    if(n == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    int sqr = sqrt(n);
    FOR(i, 2, sqr)
    {
        if(n < i)
            break;
        //n = m;
        lol a{0};
        rec(n, i, a);
        //cout << n << endl;
        if(a > 0)
        {
            for(int j = 1; j*(j + 1) <= 2*a; j++)
            {
                result++;
            }
            //cout << result << endl;
        }
    }
    //cout << che << " " << result << " " << pow(che, 2) << " " << m << endl;
    /*if(result == 1 && pow(che, 2) != m)
        result++;*/
    if(n != 1)
        result++;

    cout << result << endl;
    return 0;
}

void rec(lol& n, int i, lol& result)
{
    if(n%i != 0)
        return;
    if(n%i == 0)
    {
        che = i;
        result++;
        n /= i;
        rec(n, i, result);
    }
}

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

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

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

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    static int mod = 1000000007;
    static long oo = Long.MAX_VALUE;

    public static boolean pow10(int v) {
        while(v > 1 && v % 10 == 0) v /= 10;
        return v == 1;
    }

    public static int digSum(int v) {
        if(v < 10) return v;
        else return (v % 10) + digSum(v / 10);
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out); 
        
        int n = sc.nextInt();
        if(pow10(n)) pw.println(10);
        else pw.println(digSum(n));

        pw.close();
    }

}


Measured memory_bytes: 21716
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define set0(x) memset(x,0,sizeof(x))
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();int f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
int n,a[110],v[110] = {0},tst[110];
int main() {
	read(n);
	for(int i=1;i<=n;i++){
		read(a[i]);
	}
	for(int i=1;i<=n;i++){
		int cord = a[i],diff = i-a[i];
		for(int j=i+1;j<=n;j++){
			if(j-a[j]>diff)cord+=1;
			else diff+=1;
		}
		v[cord] = a[i];
	}
	int ok = 1;
	for(int i=1;i<=n;i++){
		if(v[i]>i)ok = 0;
		for(int j = n;j>=v[i];j--)tst[j+1] = tst[j];
		tst[v[i]] = v[i];
	}
	for(int i=1;i<=n;i++)if(tst[i]!=a[i])ok = 0;
	if(!ok){
		cout<<-1<<endl;
	}else{
		for(int i=1;i<=n;i++)cout<<v[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
from operator import mul#掛け算
n = int(input())
cof = [1 << x for x in range(10)]#1（＝2＾0）～512（＝2＾9）
fs = [sum(map(mul, map(int, input().split()), cof)) for _ in range(n)]
#上記で2進数01を10進数化。但し、桁が逆に並んでいて、1桁目は1の桁。
ps = [list(map(int, input().split())) for _ in range(n)]
ans = float('-inf')
for g in range(1, 1024):
    sum=0#収益の初期値
    for f, p in zip(fs, ps):
        tmp2=bin(f & g).count('1')
        #他店ｆも自店ｇもオープンしてる時間帯数、共にビットが立っている
        sum+=p[tmp2]#オープン時間帯数を基にした収益を加算
    ans = max(ans, sum)#収益が最大なら更新
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    string s;
    cin>>s;
    int n = sz(s);

    map<int, int> mod;
    mod[0]++;
    ll ss = 0;
    ll ten = 1;
    rep(i, n) {
        ss = (ss + (s[n - i - 1] - '0') * ten) % 2019;
        ten = (ten * 10) % 2019;
        mod[ss]++;
    }
    ll ans = 0;
    for (auto i : mod) {
        ans += i.se * (i.se - 1) / 2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3748
def up(m):
    while m>0:
        if m//10>0:
            m=m//10
        else:
            break
    return m


n=int(input())
a=[[0]*9 for x in range(9)]
for c in range(1,n+1):
    i=c%10
    if i==0:
        continue
    j=up(c)
    a[i-1][j-1]+=1
t=0
for i in range(9):
    for j in range(9):
        t+=a[i][j]*a[j][i]
print(t)

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

N, M = map(int, input().split())
xyz = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0

for a in [-1, 1]:
    for b in [-1, 1]:
        for c in [-1, 1]:
            xyz.sort(key=lambda t: a*t[0]+b*t[1]+c*t[2])
            xs, ys, zs = 0, 0, 0
            
            for x, y, z in xyz[:M]:
                xs += x
                ys += y
                zs += z
            
            ans = max(ans, abs(xs)+abs(ys)+abs(zs))

print(ans)

Measured memory_bytes: 74128
def gcd(a,b):
    if a < b:a,b = b,a
    if b == 0:return a
    if a % b == 0:return b
    else:return gcd(b,a % b)

n = int(input())
a = list(map(int,input().split()))
L = [0]*(n+2)
R = [0]*(n+2)
for i in range(n):
    L[i+1] = gcd(L[i],a[i])
    R[n-i] = gcd(a[n-i-1],R[n-i+1])
ans = 0
for i in range(n):
    ans = max(ans,gcd(L[i],R[i+2]))
print(ans) 

Measured memory_bytes: 63984
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
void solve(){
	ll n;
	cin>>n;
	ll cur=100,res=0;
	while(cur<n){
		cur+=(cur/100);
		res++;
	}
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 998244353
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
ll fact[200003];
ll invfact[200003];
ll power(ll x,ll y){
  if(y<=0) return 1;
  ll z=power(x,y/2);
  if(y%2) return ((z*z)%mod)*x%mod;
  return (z*z)%mod;
}
ll Cr(ll x, ll y){
  return (((fact[x]*invfact[x-y])%mod)*invfact[y])%mod;
}
void make_fact(int n){
  fact[0]=1;
  rep(i,1,n+1) fact[i]=(i*fact[i-1])%mod;
  invfact[0]=1;
  rep(i,1,n+1) invfact[i]=(power(i,mod-2)*invfact[i-1])%mod;
}
void solve(){
  int n,m,k;
  cin>>n>>m>>k;

  make_fact(n);

  ll ans=0;
  rep(i,0,k+1) {
    ans+=(((Cr(n-1,i)*m)%mod)*power(m-1,n-1-i))%mod;
    ans%=mod;
  }
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    {
      solve();
    }
}


Measured memory_bytes: 6776
#include<iostream>

using namespace std;

int main(){
  bool ac[100001]={};
  int pc[100001]={};
  int n,m;
  cin>>n>>m;
  int a=0,pe=0;
  while(m--){
    int p;
    char s[9];
    cin>>p>>s;
    if(s[0]=='A'){
      a+=!ac[p];
      ac[p]=true;
    }else{
      pc[p]+=!ac[p];
    }
  }
  int p=0;
  for(int i=1;i<=n;i++){
    if(ac[i]){
      p+=pc[i];
    }
  }
  cout<<a<<' '<<p<<endl;
}


Measured memory_bytes: 4100
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const double pi = 3.14159265358979323846;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
	speed;
    ll n;
  	
  	cin>>n;
  	if(n%1000==0)
      cout<<0;
  
  	else
      cout<<1000-n%1000;
  return 0;
    
}

Measured memory_bytes: 3608
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::cmp;
use std::num::Wrapping; // overflowを回避
use std::f64::consts;


fn main() {
    let n: i32 = read();
    let target: i32 = read();
    let mut ans: String = String::from("-1 -1 -1");

    for man in 0..n+1 {
        for gosen in 0..n-man+1 {
            let mut sen = n - man - gosen;
            if sen < 0 {
                sen = 0;
            }
            let sum = man * 10000 + gosen * 5000 + sen * 1000;

            if sum == target {
                ans = format!("{} {} {}", man, gosen, sen);
            }
        }
    }

    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = 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")
}


Measured memory_bytes: 4352
N = int(input())
points = list(map(int, input().split(' ')))
points.insert(0, 0)
points.insert(len(points), 0)

sum = 0
for i in range(1, len(points)):
    sum += abs(points[i - 1] - points[i])


for i in range(1, len(points) - 1):
    tmp_sum = 0
    if points[i - 1] <= points[i] <= points[i + 1]:
        print(sum)
        continue

    if points[i - 1] <= points[i + 1] <= points[i]:
        print(sum - 2 * abs(points[i] - points[i + 1]))
        continue

    if points[i] <= points[i - 1] <= points[i + 1]:
        print(sum - 2 * abs(points[i] - points[i - 1]))
        continue

    if points[i] <= points[i + 1] <= points[i - 1]:
        print(sum - 2 * abs(points[i] - points[i + 1]))

        continue
    if points[i + 1] <= points[i - 1] <= points[i]:
        print(sum - 2 * abs(points[i] - points[i - 1]))

        continue
    if points[i + 1] <= points[i] <= points[i - 1]:
        print(sum)

        continue

Measured memory_bytes: 13928
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    int N;
    cin >> N;
    
    int mcnt = 0;
    int minabs = INT_MAX;
    ll sumabs = 0;
    //vector<int> As;
    REP(i, N) {
        int a;
        cin >> a;
        //As.push_back(a);
        if (a < 0) mcnt++;
        minabs = min(minabs, abs(a));
        sumabs += abs(a);
    }
    
    if (mcnt%2 == 0) {
        cout << sumabs << endl;
    } else {
        cout << sumabs - 2*minabs << endl;
    }
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <set>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  set<string> s;
  for (int i = 0; i < n; ++i) {
    char t[19];
    scanf("%s", t);
    s.insert(string(t));
  }
  printf("%d\n", (int)s.size());
}


Measured memory_bytes: 18808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e4 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b== c && c == a){
        cout <<"Yes" << endl;
    }
    else{
        cout <<"No" << endl;
    }

    return 0;
}

Measured memory_bytes: 764