akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, m;
    cin >> n >> m;
    vector<string> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    for (int i = 0; i + m <= n; i++)
    {
        for (int j = 0; j + m <= n; j++)
        {
            bool f = true;
            for (int k = i; k < i + m; k++)
            {
                for (int l = j; l < j + m; l++)
                {
                    if (a[k][l] != b[k - i][l - j])
                        f = false;
                }
            }
            if (f)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
from collections import OrderedDict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    od = OrderedDict()
    a = list(map(int, input().split()))
    for i in range(len(a)):
        od[a[i]] = i+1

    p = OrderedDict(
        sorted(od.items(), key=lambda x: x[0])
    )

    print(*[v for k, v in p.items()])


if __name__ == '__main__':
    main()


Measured memory_bytes: 80100
#include <cstdio>
using namespace std;

int main(){
	
	int n,q,m,da,res;
	int i;
	int date[100] = {0};
	while(true){
		
		res = 0;
		for(i=0;i<sizeof(date)/sizeof(int);i++){
			date[i] = 0;
		}
		
		scanf(" %d %d", &n, &q);
		if(n == 0 & q == 0){
			break;
		}
		
		for(i=0;i<n;i++){
			scanf(" %d", &m);
			for(int j=0;j<m;j++){
				scanf(" %d", &da);
				date[da] ++;
			}
		}
		for(i=0;i<100;i++){
			if(date[res] < date[i]){
				res = i;
			}
		}
		if(date[res] >= q){
			printf("%d\n", res);
		}else{
			printf("0\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 1036
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;
using ll = long long;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    ll left = 0;
    for (int i = 1; i < n; ++i) {
        left += a[i];
    }
    ll right = a[0];
    ll ans = abs(left - right);
    for (int i = 1; i < n - 1; ++i) {
        left -= a[i];
        right += a[i];
        ans = min(ans, abs(left - right));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;
int mgcd(int a,int b);
int mgcd(int a,int b){
        if(a%b==0){
            return b;
        }
        else{
            return mgcd(b,a%b);
        }
    }

int main(){
    long long int n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++){
            for(int k=1;k<=j;k++){
            	if(i==j&&j==k&&i==k){
            		ans+=mgcd(k,mgcd(i,j));
            	}
            	else if(i==j||j==k||i==k){
            		ans+=3*mgcd(k,mgcd(i,j));
            	}
            	else{
            		ans+=6*mgcd(k,mgcd(i,j));
            	}
            }
        }
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3580
N, M = list(map(int, input().split(' ')))
a = []
for _ in range(M):
  a.append(int(input()))

mod = 10**9+7 #出力の制限
Nmax = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

for i in range( 2, Nmax + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def f(a, b):
  a -= 1
  b += 1
  n = abs(a-b)
  r = int(n/2)
  if r == 0: return 1
  n = r if n % 2 == 0 else r + 1
  ret = 0
  while r > 0:
    ret += cmb(n, r, mod)
    r -= 1
    n += 1

  ret += 1
  return ret

result = 0
if M == 0:
  result = f(N+1, -1) % mod
else:
  a0 = -1
  a1 = a.pop(0)
  while len(a) > 0:
    if a1 - a0 <= 1 and a0 != -1:
      result = 0
      break

    if result == 0:
      result += f(a1, a0)
    else:
      result *= f(a1, a0)
      result %= mod
    a0 = a1
    a1 = a.pop(0)

  if a1 - a0 <= 1 and a0 != -1:
    result = 0
  else:
    if result == 0:
      result += f(a1, a0)
    else:
      result *= f(a1, a0)
      result %= mod
    a0 = a1
    a1 = N+1
    result *= f(a1, a0)
    result %= mod

print(result)

Measured memory_bytes: 19016
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



string str;

int main() {
    while (getline(cin, str)) {
        set<string> se;
        for (int i = 0; i < str.size(); ++i) if (str[i] == '.' || str[i] == ',') str[i] = ' ';
        istringstream sin(str);
        string res = "";
        string tmp;
        while (sin >> tmp) if (tmp.size() >= 3 && tmp.size() <= 6) res += tmp + " ";
        res.erase(res.end() - 1);
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1204
#include<stdio.h>
#include<stdlib.h>
int n,i,A[1000000],tmp,k,cnt=0,j,m=0,h=1;

// InsersionSort
void insersionSort(int A[], int n, int g){
  for(i=g;i<=n-1;i++){
    tmp=A[i];
    k=i-g;
    while(k>=0&&A[k]>tmp){
      A[k+g]=A[k];
      k=k-g;
      cnt++;
    }
    A[k+g]=tmp;
  }
}

// ShellSort
void shellSort(int A[], int n){
  int *T=(int *)malloc(sizeof(int)*n);
  while(h<=n){
    T[m] = h;
    h = h*3+1;
    m++;
  }
  int *G=(int *)malloc(sizeof(int)*m);
  for(i=0;i<=m-1;i++){
    G[i] = T[i];
  }
  for(j=m-1;j>=0;j--){
    insersionSort(A, n, G[j]);
  }
  printf("%d\n",m);
  for(i=m-1;i>=0;i--){
    if(i<m-1)printf(" ");
    printf("%d",G[i]);
  }
  free(T);
  free(G);
}

int main(){
  scanf("%d", &n);
  for(i=0;i<=n-1;i++)scanf("%d",&A[i]);
  shellSort(A, n);
  printf("\n");
  printf("%d\n",cnt);
  for(i=0;i<=n-1;i++)printf("%d\n",A[i]);
  return 0;
}

Measured memory_bytes: 4508
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty;
	ll x = tx-sx;
	ll y = ty-sy;
	rep(i,y) cout << 'U';
	rep(i,x) cout << 'R';
	rep(i,y) cout << 'D';
	rep(i,x+1) cout << 'L';
	rep(i,y+1) cout << 'U';
	rep(i,x+1) cout << 'R';
	cout << 'D';
	cout << 'R';
	rep(i,y+1) cout << 'D';
	rep(i,x+1) cout << 'L';
	cout << 'U' << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	char buf[3][128];
	while (cin.getline(*buf, sizeof(*buf)), **buf != '0')
	{
		cin.getline(buf[1], sizeof(*buf));
		cin.getline(buf[2], sizeof(*buf));

		int a[3], b[3];
		for (int i = 0; i < 3; ++i)
		{
			a[i] = b[i] = 0;
			for (int j = 1; buf[i][j] != '\0'; ++j)
				if (buf[i][j] == 'A')
					++a[i];
				else
					++b[i];
			if (i < 2)
				if (buf[i+1][0] == 'A')
					++a[i];
				else
					++b[i];
		}
		if (a[2] > b[2])
			++a[2];
		else
			++b[2];
		for (int i = 0; i < 3; ++i)
			printf("%d %d\n", a[i], b[i]);
	}

	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#define MAX 1000001
int parent(int);
int left(int);
int right(int);
void maxheapify(int *,int);
void buildmaxheap(int*);
void swap(int *,int *);
int H;
int main(){
  int n,A[MAX],i;
  scanf("%d",&n);
  H=n;
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  buildmaxheap(A);
  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}
void swap(int *p1,int *p2){
  int temp;
  temp=*p1;
  *p1=*p2;
  *p2=temp;
}
int parent(int i){
return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}
void maxheapify(int A[],int i){
  int l,r,largest;
  l=left(i);
  r=right(i);
  if(l<=H &&A[l]>A[i])largest=l;
  else largest=i;
  if(r<=H&&A[r]>A[largest])largest=r;

  if(largest!=i){
    swap(&A[i],&A[largest]);
    maxheapify(A,largest);
  }
}
void buildmaxheap(int A[]){
  int i;
  for(i=H/2;i>=1;i--){
    maxheapify(A,i);
  }
}
    
    
    
  



Measured memory_bytes: 3676
//Gathering Children

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "

using p = pair<ll,string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    string s;
    cin>>s;
    s.pb('R');
    rep(i,0,s.size()-1){
        int a = i;
        int l = 0,r = 0;
        bool flag = false;
        while(true){
            if(flag&&s[a+l+r]=='R'){
                i--;
                break;
            }
            if(s[a+l+r]=='R')r++;
            else{
                l++;
                flag=true;
            }
            i++;
        }
        rep(j,0,r-1)cout<<0<<spa;
        if((l+r)%2==0)cout<<(l+r)/2<<spa<<(l+r)/2<<spa;
        else if(r%2==0)cout<<(l+r)/2<<spa<<(l+r)/2+1<<spa;
        else cout<<(l+r)/2+1<<spa<<(l+r)/2<<spa;
        rep(j,0,l-1)cout<<0<<spa;
    }
    cout<<nnn;
    return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    pair<int,int> p[m];
    rep(i,m){
        int a,b;
        cin >> a >> b;
        p[i]=make_pair(b-1,a-1);
    }

    sort(p,p+m);

    int save=-1;
    int ans=0;
    rep(i,m){
        if(save>=p[i].second && save<p[i].first) continue;
        else{
            save=p[i].first-1;
            ans++;
        }
    }

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

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;



int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c)
        cout<<1;
    else if(a!=b &&b!=c && c!=a)
        cout<<3;
    else
        cout<<2;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define ll long long
int main()
{
    int ans;
    string s;
 
    cin >> s;
 
    int cnt0 = 0;
    int cnt1 = 0;
    rep(i, s.size()) {
        if (s[i] == '0')
            ++cnt0;
        else
            ++cnt1;
    }
    ans = min(cnt0, cnt1) * 2;
    cout << ans << endl;
    return(0);
}

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

int main(void){
    int i;
    char N[5];
    scanf("%s", N);
    for(i=0; i<3; i++){
        if(N[i]=='1') printf("9");
        else if(N[i]=='9') printf("1");
        else printf("%c", N[i]);
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#define MAX_NUM 500000
#define INFTY 1000000001
int count = 0;

void merge(int a[],int left,int mid,int right){
    int n1 = mid-left;
    int n2 = right-mid;
    int l[n1+1];
    int r[n2+1];
    for(int i=0;i<n1;i++){
        l[i] = a[left+i];
    }
    for(int i=0;i<n2;i++){
        r[i] = a[mid+i];
    }
    l[n1] = INFTY;
    r[n2] = INFTY;
    int i=0,j=0;
    for(int k=left;k<right;k++){
        count++;
        if(l[i] < r[j]){
            a[k] = l[i];
            i++;
        }else{
            a[k] = r[j];
            j++;
        }
    }
}

void mergeSort(int a[],int left,int right){
    if(left+1<right){
        int mid = (left+right)/2;
        mergeSort(a,left,mid);
        mergeSort(a,mid,right);
        merge(a,left,mid,right);
    }
}

int main(){
    int a[MAX_NUM] = {};
    int n;
    std::cin >> n;
    for(int i=0;i<n;i++){
        std::cin >> a[i];
    }
    
    mergeSort(a,0,n);
    
    std::cout << a[0] ;
    for(int i=1;i<n;i++){
        std::cout << ' ' << a[i];
    }
    std::cout << '\n' << count << '\n';
    return 0;
}



Measured memory_bytes: 6896
N=int(input())
a = [int(i) for i in input().split()] 
sorted_a=sorted(a)
sum_A=0
sum_B=0
while sorted_a != []:
    sum_A+= sorted_a[-1]
    if len(sorted_a)!=1:
        sum_B+= sorted_a[-2]
    del sorted_a[-1]
    if sorted_a!=[]:
        del sorted_a[-1]

print(sum_A-sum_B)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=40000;
int n,m,u,v,zt[20],f[N],pw[N];
void up(int &x,int y){x=x-mod+y; x=(x<0)?x+mod:x;}
bool check(int s)
{
	return (s&1)&&((s>>1)&1)||!(s&1)&&!((s>>1)&1);
}
int count(int s)
{
	int cnt=0;
	while (s) cnt++,s-=(s&(-s));
	return cnt;
}
int main()
{
	scanf("%d%d",&n,&m);
	pw[0]=1;
	for (int i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		zt[u]|=(1<<(v-1));//保存出边状态 
		pw[i]=(ll)pw[i-1]*2%mod;
	}
	int Max=1<<n;
	f[0]=1;
	for (int i=0;i<Max;i++)
	if (f[i])
	{
		int _i=(Max-1)^i;
		for (int j=_i;j;j=((j-1)&_i))
		if (check(j)) 
		{
			int del=1;
			for (int k=1;k<=n;k++)
			{
				if ((i>>(k-1))&1) 
				  del=(ll)del*(pw[count(zt[k]&j)]-1+mod)%mod;
			    if ((j>>(k-1))&1)
			      del=(ll)del*pw[count(zt[k]&i)]%mod;
			}
			up(f[i|j],(ll)del*f[i]%mod);
		}
	}
	printf("%d\n",((ll)pw[m]-f[Max-1]+mod)%mod);
	return 0;
} 

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

int main(){
    ll n;
    cin >> n;
    vector<ll> p(n);
    ll cnt = 0;
    ll mi = n+1;
    rep(i, 0, n){
        cin >> p[i];
        mi = min(p[i], mi);
        if(mi == p[i]) cnt ++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;
string a;

int main(){
	IOS
	cin >> a;
	for(int i=1;i<a.size();i++){
		if(a[i]!=a[i-1]){
			cout << "Yes" << endl; return 0;
		}
	}
	cout << "No" << endl;
}

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

const int dx[2] = {0, 1};
const int dy[2] = {1, 0};
int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (auto i = 0; i < h; i++) cin >> s[i];
    vector<vector<int>> c(h, vector<int>(w, 1 << 20));
    queue<pair<int, int>> q;
    q.emplace(0, 0);
    c[0][0] = (s[0][0] == '#');
    while (not q.empty()) {
        auto p = q.front();
        q.pop();
        for (auto i = 0; i < 2; i++) {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            int cost = c[p.first][p.second];
            if (nx >= h or ny >= w) continue;
            if (s[p.first][p.second] == '.' and
                s[nx][ny] == '#')
                cost++;
            if (c[nx][ny] > cost) {
                c[nx][ny] = cost;
                q.emplace(nx, ny);
            }
        }
    }
    cout << c[h - 1][w - 1] << endl;
    return 0;
}

Measured memory_bytes: 3672
n=int(input())
a=[int(input())for _ in range(n)]+[10**9]
b=[int(input())for _ in range(n)]+[10**9]
a.sort(reverse=1)
b.sort(reverse=1)
aa=0
bb=0
if a[-1]>b[-1]:
  bb=1
  b.pop()
else:
  aa=1
  a.pop()
ans=1
while len(a)!=1 or len(b)!=1:
  if a[-1]>b[-1]:
    bb+=1
    b.pop()
  else:
    aa+=1
    a.pop()
  if aa*bb:
    ans*=max(aa,bb)
    ans%=10**9+7
    aa-=1
    bb-=1
print(ans)

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

#define rep( i, n ) for( int i = 0; i < ( n ); i++ )
#define PI 3.14159265
typedef long long ll;

int main( void ) {
    int n, m;
    cin >> n >> m;

    int a[ n ][ m ]={};
    int b[ m ]={};
    int c[ n ]     = {}; // cはa*bの値

    rep( i, n ) {
        for( int j = 0; j < m; j++ ) {
            cin >> a[ i ][ j ];
        }
    }
    for( int j = 0; j < m; j++ ) {
        cin >> b[ j ];
    }
    rep( i, n ) {
        for( int j = 0; j < m; j++ ) {
            c[ i ] += a[ i ][ j ] * b[ j ];
        }
        cout << c[ i ] << endl;
    }

    return 0;
}



Measured memory_bytes: 3136
def main():
    n, threshould = [int(x) for x in input().split()]
    count = 0
    for _ in range(n):
        dist = sum(int(x) ** 2 for x in input().split())
        # 真偽値は 1 か 0 として足せる。
        count += dist <= threshould ** 2
    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9064
def ini(): return int(input())
def inli(): return list(map(int, input().split()))
def inf(): return float(input())
def inlf(): return list(map(float, input().split()))
def inl(): return list(input())
def pli(): return "".join(list(map(str, ans)))

n= ini()
k= ini()
x = ini()
y = ini()
if k<n:
    print(k*x+(n-k)*y)
else:
    print(n*x)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n, h, w;
    cin >> n >> h >> w;

    vector<int> a(n);
    vector<int> b(n);
    int cnt = 0;

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

    for(int j = 0; j < n; j++){
        if(a[j] >= h && b[j] >= w){
            cnt = cnt + 1;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e10

using namespace std;
typedef long long int ll;

int main()
{
    ll N,M;
    while(cin >> N >> M)
    {
        if(N == 0 && M == 0) break;
        vector<ll>C(M),X(N);
        for(int i = 0; i < M; i++) cin >> C[i];
        for(int i = 0; i < N; i++) cin >> X[i];
        sort(C.begin(),C.end());
        vector<vector<ll>>dp(N+1,vector<ll>(256,INF));
        vector<vector<bool>>f(N+1,vector<bool>(256,false));
        dp[0][128] = 0;
        f[0][128] = true;
        for(int i = 0; i < N; i++)
        {
            for(int j = 0; j <= 255; j++)
            {
                if(f[i][j] == false) continue;
                for(int k = 0; k < M; k++)
                {
                    if(j+C[k] > 255) dp[i+1][255] = min(dp[i+1][255],dp[i][j] + (X[i]-255)*(X[i]-255)),f[i+1][255] = true;
                    if(j+C[k] < 0) dp[i+1][0] = min(dp[i+1][0], dp[i][j] + X[i]*X[i]),f[i+1][0] = true;
                    if(j+C[k] >= 0 && j+C[k] <= 255) dp[i+1][j+C[k]] =min(dp[i+1][j+C[k]],dp[i][j] + (X[i]-(j+C[k]))*(X[i]-(j+C[k]))),f[i+1][j+C[k]] = true;
                }
            }
        }
        ll S = INF;
        for(int i = 0; i <= 255; i++) if(f[N][i]) S = min(S,dp[N][i]); 
        cout << S << endl;
    }
}


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

int main()
{
    long long n, k, q;
    std::cin >> n >> k >> q;
    std::vector<long long> a(n, 0);
    for (int i = 0; i < q; i++) {
        long long tmp;
        std::cin >> tmp;
        a[tmp - 1]++;
    }

    long long lim = q - k ;
    for (int i = 0; i < n; i++) {
        std::string ans = "Yes";
        if (lim >= a[i])
            ans = "No";
        std::cout << ans << std::endl;
    }


    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	int n, t_score = 0, h_score = 0;
	string t, h;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		cin >> t >> h;
		if (t == h) {
			t_score++;
			h_score++;
		}
		else if (t > h)t_score += 3;
		else h_score += 3;
	}
	printf("%d %d\n", t_score, h_score);
}


Measured memory_bytes: 3336
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd
#define bod 100000007
/****************************/
int n,k;
int a[200010];
inline double expect(int x)
{
	double ans;
	int ans1=0;
	rep(i,x)
	{
		ans1+=i+1;
	}
	ans=(double)(ans1*1.000000000000)/(x*1.0000000000);
	return ans;
}
double f[200010];
int main()
{
	cin>>n>>k;
	rep(i,n)
	{
		cin>>a[i];
	}
	rep(i,n)
	{
		f[i]=expect(a[i]);
		//cout<<f[i]<<" ";
	}
	double ans=0.000000000000;
	double ret=0.000000000000;
	rep(i,k)
	{
		ret+=f[i];
	}
	ans=max(ans,ret);
	rep3(i,k,n)
	{
		ret+=f[i];
		ret-=f[i-k];
		ans=max(ans,ret);
	}
	printf("%.12f",ans);
	return 0;
}

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

int gcb(int x, int y)
{
  if(y == 0)return x;
  return gcb(y, x % y);
}

int main()
{
  int a, b;
  while(cin >> a >> b){
    cout << gcb(a, b) << " " << a / gcb(a, b) * b<< endl;    
  }
}

Measured memory_bytes: 1156
line = input().split()
H = int(line[0])
W = int(line[1])
S =[input().split() for i in range(H)]

a = ord("A")

for i in range(H):
    for j in range(W):
        if S[i][j]=="snuke":
            y = i+1
            x = chr(a+j)
            print("{0}{1}".format(x,y))
            break


Measured memory_bytes: 38256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream &operator << (ostream& out,const pair<S,T>& o){
    out << "(" << o.first << "," << o.second << ")"; return out;
}

/*
<url:https://arc070.contest.atcoder.jp/tasks/arc070_b>
問題文============================================================
 シカのAtCoDeerくんは正整数が書かれたカードを N 枚持っています。i(1≦i≦N) 枚目に書かれている数は ai です。
 AtCoDeerくんは大きい数が好きなので、
 カードに書かれた数の総和が K 以上になるようなカードの部分集合をよい集合と呼びます。
 
 そして、各カード i に対して、そのカードが不必要かどうかを次のように判定します。
 
 「カード i を含む任意のよい集合に対して、その集合からカード i を除いたものもよい集合」ならカード i は不必要
 それ以外の場合は、不必要でない
 
 不必要なカードの枚数を求めてください。
 ただし、それぞれの判定は独立に行われ、不必要だからと言ってカードが途中で捨てられたりすることはありません。

 入力は全て整数
 1≦N≦5000
 1≦K≦5000
 1≦ai≦10^9(1≦i≦N)
=================================================================

解説=============================================================

 不必要なカードは昇順(降順）に並べた時、右から（左から）連続するものであるとわかる。
 ここで、
 Kを超えない、集合を作り、そこにa[i]を加えた時、
 全体の総和が Kを超えるかどうかの境目で必要、不必要の判断ができる
 
 さて、Kを超えない最適な集合を作るには
 まず、要素の大きい順から考えて、それぞれの要素を含むべきかどうかを判断しなければならない
 
 よって、降順に要素を並べ
 各i[0..N-1] から　集合を作って言った際に a[i]を含めて Kを超えるギリギリの要素jまで加算して行く、
 K以上となった時、i...j までが必要なカードだとわかる
 さらにjを加算せずにインクリメントして言って、 その　K以上、K未満である境を判断して行く
 
================================================================
*/
ll N,K;
vector<ll> a;
ll solve(){
    ll res = 0;
    cin >> N >> K;
    a.resize(N); for(auto &in:a) cin >> in;
    sort(a.begin(),a.end()); reverse(a.begin(),a.end());
    ll ans = -1;
    for(int i = 0; i < N;i++){
        ll sum = 0;
        for(ll j = i; j < N;j++){
            if(sum + a[j] < K){ sum += a[j]; continue; }
            ans = max(ans,j);
        }
    }
    return res = N - ans - 1;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

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

    int f = 1;
    for (int i = 0; i < n; i++)
    {
        ll p;
        cin >> p;
        if (p % 2 == 0)
        {
            f &= (p % 3 == 0 or p % 5 == 0);
        }
    }
    cout << (f ? "APPROVED" : "DENIED") << endl;
}

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

#define ff              first
#define fo(i,n)         for(i=0;i<n;i++)
#define Fo(i,k,n)       for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x, y)      cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());


const int N = 3e5, M = N;
//=======================


void solve() {
  int i, j, n, m;
  cin>>n;
  vector<int> prime(1000,0);
 

  int count=0;
  for(i=1;i<=n-1;i++){
    int ans=n-i;
    int temp=1;
    for(j=2;j*j<=ans;j++){
        int cnt=0;
        while(ans%j==0){
            ans/=j;
            cnt++;
        }
        temp*= (cnt+1);
    }
    if(ans>1) temp*=2;
    count+=temp;
  }
  cout<<count;
}

int32_t main()
{
  FIO;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  
  solve();
  return 0;
}


Measured memory_bytes: 3656
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	string N;
	cin >> N;
	int d = 0;
	for (int i = 0; i < N.size(); i++) {
		d += (int)N[i] - 48;
	}
	int D;
	D = stoi(N);
	if (D % d == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

using namespace std;

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

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

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

struct Data {
    ll C;
    vector<ll> v;
};

Data D[15];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M, X;
    cin >> N >> M >> X;
    REP(i, N) {
        cin >> D[i].C;
        REP(j, M) {
            ll a;
            cin >> a;
            D[i].v.push_back(a);
        }
    }

    ll ans = INF;
    REP(b, pow(2, N)) {
        vector<ll> v(M, 0);
        ll cost = 0;
        REP(j, N) {
            if (((b >> j) & 1) == 0)
                continue;
            cost += D[j].C;
            REP(i, M) {
                v[i] += D[j].v[i];
            }
        }

        bool e = true;
        REP(j, M) {
            if (v[j] < X)
                e = false;
        }
        if (e)
            ans = std::min(ans, cost);
    }

    if (ans == INF)
        ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define _overload1(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload1(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _overload2(_1, _2, _3, name, ...) name
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (ll i = (ll)(a - 1); i >= (ll)(b); --i)
#define rrep(...) _overload2(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define tr(it, c) for (iter(c) it = (c).begin(); it != (c).end(); it++)
#define all(x) (x).begin(), (x).end()

const double EPS = 1e-15, PI = acos(-1);
const ll INF = 1'010'000'000'000'000'017LL;

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

void Main() {
  ll n;
  cin >> n;
  ll a[n];
  ll sum = 0;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  ll ave = sum / n;
  ll total1 = 0, total2 = 0;
  rep(i, n) {
    total1 += pow(a[i] - ave, 2);
    total2 += pow(a[i] - (ave + 1), 2);
  }
  cout << min(total1, total2) << endl;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
# 全種類
st = set(s) | set(t)

d1 = defaultdict(int)
d2 = defaultdict(int)

for key in s:
    d1[key] += 1
for key in t:
    d2[key] -= 1

answer = 0
for key in st:
    answer = max(answer, d1[key]+d2[key])
print(answer)

Measured memory_bytes: 3316
def main():
    import sys
    from copy import deepcopy
    input = sys.stdin.readline
    R, C, K = [int(x) for x in input().strip().split()]
    G = [[0] * (C+1) for r in range(R+1)]
    for k in range(K):
        r, c, v = [int(x) for x in input().strip().split()]
        G[r][c] = v
    # for r in range(R+1):
    #     print(G[r])
    ans = [[[0] * 4 for _ in range(C+1)] for _ in range(2)]
    for r in range(1, R+1):
        for c in range(1, C+1):
            ans[r%2][c][0] = max(ans[(r-1)%2][c][-1], ans[r%2][c-1][0])
            for i in range(1, 4):
                ans[r%2][c][i] = max(ans[(r-1)%2][c][3], ans[r%2][c-1][i], ans[(r-1)%2][c][3]+G[r][c], ans[r%2][c-1][i-1]+G[r][c])

    print(max(ans[R%2][-1]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 147136
/* 
 * Project: AtCoder Beginners Contest 172 B - Minor Change
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/27
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;

string s;
string t;

void solve() {

    int cnt = 0;

    for (int i=0;i<s.length();i++) {
        if (s[i] != t[i]) {
            cnt++;
        }
    }
    printf("%d\n", cnt);
}

int main() {

    cin >> s >> t;

    solve();

}

Measured memory_bytes: 3472
s = input()
i, j = 0, len(s)-1
ans = 0
while i < j:
    if s[i] == s[j]:
        i += 1
        j -= 1
    elif s[i] == "x":
        ans += 1
        i += 1
    elif s[j] == "x":
        ans += 1
        j -= 1
    else:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 3316
STATE = {
    "NOTHING": ".",
    "LOOP": "E"
}

DIRECT = {
    ">": [0, 1],
    "<": [0, -1],
    "^": [-1, 0],
    "v": [1, 0]
}

output = []

while True:

    width, height = [int(item) for item in input().split(" ")]

    if width == 0 and height == 0:
        break

    tiles = []
    for lp in range(width):
        splits = [item for item in input()]
        tiles.append(splits)

    row, col = 0, 0
    while True:

        if tiles[row][col] == STATE["NOTHING"]:
            output.append(str(col) + " " + str(row))
            break
        elif tiles[row][col] == STATE["LOOP"]:
            output.append("LOOP")
            break

        for key in DIRECT:
            if tiles[row][col] == key:
                tiles[row][col] = STATE["LOOP"]
                row += DIRECT[key][0]
                col += DIRECT[key][1]
                break


print("\n".join(output))



Measured memory_bytes: 5688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, first, second, fourth, fifth, count = 0;
  cin >> A >> B;
  // cout << A << endl;
  
  for (int i = 0; (A + i) <= B; i++) {
    first = (A + i) / 10000 % 10;
    second = (A + i) / 1000 % 10;
    fourth = (A + i) / 10 % 10;
    fifth = (A + i) / 1 % 10;
    if (first == fifth && second == fourth) {
      count++;
      // cout << (A + i) << endl;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;


//
int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);
	int dice[6][4] = {
		{5,3,2,4},	//表が1
		{1,3,6,4},	//表が2
		{1,6,2,5},	//表が3
		{5,1,2,6},	//表が4
		{6,3,1,4},	//表が5
		{2,3,5,4}	//表が6
	};

	while(1){
		int top = 1;
		int tmp = 0;
		int ans = 1;
		int n = 0;
		int fr = 2,ri = 3;
		string dir;
		cin >> n;

		
		if(n == 0) break;
		

		for(int i = 0; i < n; i++) {
			cin >> dir;
			if(dir == "North") {
				tmp = top;
				top = fr;
				fr = 7 - tmp;
			} else if(dir == "East") {
				tmp = ri;
				ri = top;
				top = 7 - tmp;
			} else if(dir == "South") {
				tmp = top;
				top = 7 - fr;
				fr = tmp;
			} else if(dir == "West") {
				tmp = ri;
				ri = 7 - top;
				top = tmp;
			} else if(dir == "Right") {
				tmp = fr;
				fr = ri;
				ri = 7 - tmp;
			} else if(dir == "Left") {
				tmp = fr;
				fr = 7 - ri;
				ri = tmp;
			}
			ans += top;
		}
		cout << ans << endl;

	}

	//while(1){}
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <cstdlib>
#include <cctype>
using namespace std;

char mcxi[5] = "mcxi";

void showMCXI(int m[]){
    for(int i = 0; i < 4; i++){
        switch (m[i]) {
            case 0: break;
            case 1: cout << mcxi[i]; break;
            default: cout << m[i] << mcxi[i]; break;
        }
    }
    cout << endl;
}

void addMCXI(int ans[], int m1[], int m2[]){
    for(int i = 3; i >= 0; i--){
        ans[i] += m1[i] + m2[i];
        if(ans[i] > 9){
            ans[i-1]++; ans[i] %= 10;
        }
    }
}

void putArray(int digit[], string str){
    for(int i = 0; i < 4; i++){
        int idx = str.find(mcxi[i]);
        if(idx == -1){
            digit[i] = 0;
        } else if(idx == 0 || !isdigit(str[idx-1])){
            digit[i] = 1;
        } else {
            digit[i] = atoi(&str.c_str()[idx-1]);
        }
    }
}

int main(int argc, const char * argv[]) {
    int n; cin >> n;
    while(n--){
        string input1, input2;
        cin >> input1 >> input2;
        
        int d1[4] = {0}, d2[4] = {0}, ans[4] = {0};
        putArray(d1, input1);
        putArray(d2, input2);
        addMCXI(ans, d1, d2);
        showMCXI(ans);
    }
}

Measured memory_bytes: 1220
#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;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
constexpr ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> t(n);
    rep(i, n) cin >> t[i];
    ll tmp = t[0];
    rep1(i, n-1) {
        tmp = lcm(tmp, t[i]);
    }
    cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<stack>
#include<list>
#include<set>
#define mod 1000000007

using namespace std;

#define DEBUG_FLAG

#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#ifdef DEBUG_FLAG
    #define dbgout(fmt, ...) fprintf(stderr, "\033[1;33mDEBUG(%s:%d):\t\033[0m" fmt, __func__, __LINE__, ##__VA_ARGS__)
#else
    #define dbgout(fmt, ...) 
#endif

int main(void)
{
    string s;
    cin >> s;
    int Q, r = 1;
    cin >> Q;
    queue<string> tB;
    stack<string> tF;
    while (Q--)
    {
        int c, m; string d;
        cin >> c;
        if (c == 1) r *= -1;
        else {
            cin >> m >> d;
            if (m == 1 && r == 1 || m == 2 && r == -1) tF.push(d);
            else tB.push(d);
        }
    }
    string ss;
    while (!tF.empty())
    {
        ss += tF.top();
        tF.pop();
    }
    ss += s;
    while (!tB.empty())
    {
        ss += tB.front();
        tB.pop();
    }
    if (r == -1) reverse(ss.begin(), ss.end());
    cout << ss << endl;
    return 0;
}

Measured memory_bytes: 12132
n, k = map(int, input().split())
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
ans = Base_10_to_n(n, k)
print(len(str(ans)))

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
//////////////

void solve() {
	string S;
	cin >> S;
	int N = S.size();
	int A = 0;
	int B = 0;
	for (int i = 0; i < N; ++i) {
		if (S[i] == '0') {
			A++;
		}
		else {
			B++;
		}
	}
	cout << 2*min(A, B) << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 512
import sys
from collections import defaultdict
from queue import Queue


def main():
    input = sys.stdin.buffer.readline
    n, m, r = map(int, input().split())
    graph = defaultdict(list)
    for _ in range(m):
        s, t, d = map(int, input().split())
        graph[s].append((t, d))
    que = Queue()
    que.put(r)
    dist = [-1] * n
    dist[r] = 0
    while not que.empty():
        e = que.get()
        dist_now = dist[e]
        for nxt, cost in graph[e]:
            dist_nxt = dist[nxt]
            if dist_nxt == -1 or dist_nxt > dist_now + cost:
                dist[nxt] = dist_now + cost
                que.put(nxt)
    for d in dist:
        print(d if d != -1 else "INF")


if __name__ == "__main__":
    main()



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

map<string, int> mp;

int main()
{
	string str;
	string maxi;
	string maxl;
	
	while (!cin.eof()){
		cin >> str;
		mp[str]++;
		if (mp[maxi] < mp[str]){
			maxi = str;
		}
		if (maxl.size() < str.size()){
			maxl = str;
		}
	}
	
	cout << maxi << " " << maxl << endl;
	
	return 0;
}

Measured memory_bytes: 1192
n=int(input())
a=list(map(int,input().split()))
k=0
b={}
for i in range(n):
    if a[i]+i in b:
        b[a[i]+i]+=1
    else:
        b[a[i]+i]=1
    if i-a[i] in b:
        k+=b[i-a[i]]
print(k)

Measured memory_bytes: 111496
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF = 1LL << 60;

int main() {
 string s;
 cin>>s;
 for(int i=0;i<s.size();i++){
   for(int j=i;j<s.size();j++){
     for(int k=j;k<s.size();k++){
       if(s.substr(i,j)+s.substr(k)=="keyence"){
         cout<<"YES"<<endl;return 0;
       }
     }
   }
 }
 cout<<"NO"<<endl;
return 0;
} 

Measured memory_bytes: 256
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for i in range(N + 1)]


def ok(last4):
    for i in range(4):
        # tの初期化
        t = list(last4)

        if i >= 1:
            # 文字の入れ替え
            t[i - 1], t[i] = t[i], t[i - 1]

        if "".join(t).count("AGC") >= 1:
            return False

    return True


def dfs(cur, last3):
    # 深いところから戻っていく過程で
    # 今までのlast3 のパターンと同様なら再利用
    if last3 in memo[cur]:
        return memo[cur][last3]

    if cur == N:
        return 1
    ret = 0

    for c in "ACGT":
        if ok(last3 + c):
            # ok の場合count を増やす
            # 1個ずらして curを増やす
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret

    return ret


print(dfs(0, "TTT"))


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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    //I don't care about anybody, and fuck ratings! I'll go to google!
    int a, b; cin>>a>>b;
    if(a>9 || b>9) return cout<<"-1\n", 0;
    else cout<<a*b<<"\n";
    return 0;
}


Measured memory_bytes: 256