akhauriyash/Code-Regression huggingface dataset:
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {
	std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define FORE(i,c) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void mxze(T &x, U y) { if(x < y) x = y; }

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

const int MAXN = 15;

int n, m, c[MAXN][MAXN], con[MAXN][1<<MAXN], cli[1<<MAXN];

int dp[MAXN][1<<MAXN];

int f(int v, int msk){
	// debug(v,msk);
	if(v==n-1) return con[n-1][msk] + cli[msk];
	int &ret = dp[v][msk];
	if(ret != -1) return ret;
	ret = -5e8;
	if(c[v][n-1]) mxze(ret, f(n-1, msk) + c[v][n-1]);
	FOR(u,0,n) if((msk & (1<<u)) && c[v][u]) 
		mxze(ret, f(u, msk^(1<<u)) + c[v][u]); 
	for(int sub = msk ; sub; sub = (sub-1) & msk )  {
		mxze(ret, f(v, msk ^ sub) + con[v][sub] + cli[sub]);	
	}
	return ret;
}

int main(){
	scan(n, m);
	int CC=0;
	FOR(i,0,m){
		int a, b, cc; scan(a,b,cc); a--; b--;
		c[a][b] = c[b][a] = cc;
		CC+=cc;
	}
	ms(dp,-1);
	FOR(msk,0,1<<n){
		FOR(i,0,n) if(msk&(1<<i)){
			FOR(j,i+1,n) if(msk&(1<<j)){
				cli[msk] += c[i][j];
			}
		}
		FOR(i,0,n){
			FOR(j,0,n) if(msk&(1<<j)){
				con[i][msk] += c[i][j];
			}
		}
	}
	ms(dp,-1);
	debug(CC, f(0,(1<<(n-1))-2));
	printf("%d\n",CC-f(0,(1<<(n-1))-2));
}

Measured memory_bytes: 4224
#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char *argv[])
{
	string S;

	cin >> S;

    int a = S[0] - '0';
    int b = S[1] - '0';
    int c = S[2] - '0';
    int d = S[3] - '0';


    if (a + b + c + d == 7) {
        cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if (a + b + c - d == 7) {
        cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
        return 0;
    }
    if (a + b - c + d == 7) {
        cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if (a + b - c - d == 7) {
        cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
        return 0;
    }
    if (a - b + c + d == 7) {
        cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if (a - b + c - d == 7) {
        cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
        return 0;
    }
    if (a - b - c + d == 7) {
        cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if (a - b - c - d == 7) {
        cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
        return 0;
    }

	return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d %d", $N, $K, $Q);
$sum = array_pad(array(), $N, 0);
for ($i = 0; $i < $Q; $i++) {
    fscanf(STDIN, "%d", $A);
    $sum[$A - 1]++;
}
$KQ = $K - $Q;
for ($i = 0; $i < $N; $i++) {
    echo $KQ > -$sum[$i] ? "Yes\n" : "No\n";
}


Measured memory_bytes: 9080
#include <iostream>
#include <queue>
#include <string>
using namespace  std;

typedef pair<string, int> PAIR;

void fnInput(int &rnMaxProc, int &rnQtm, queue<PAIR> &rqPPrc)
{
  cin >> rnMaxProc >> rnQtm;
  
  for (int i = 0; i < rnMaxProc; i++)
  {
    string sPrcNam;
    int nPrcTim;
    cin >> sPrcNam >> nPrcTim;
    rqPPrc.push(PAIR(sPrcNam, nPrcTim));
  }
}

void fnSchedule(int nQtm, queue<PAIR> &rqPPrc)
{
  int nTtlTim = 0;
  while (rqPPrc.size())
  {
    PAIR PProcess = rqPPrc.front(); rqPPrc.pop(); 
    if (PProcess.second > nQtm)
    {
      PProcess.second -= nQtm;
      rqPPrc.push(PProcess);
      nTtlTim += nQtm;
    }
    else
    {
      nTtlTim += PProcess.second;
      cout << PProcess.first << " " << nTtlTim << endl;
    }
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int nMaxPrc, nQtm;
  queue<PAIR> qPPrc;
  
  fnInput(nMaxPrc, nQtm, qPPrc);
  fnSchedule(nQtm, qPPrc);

  return 0;
}

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

using namespace std;
long long a,b,c;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>a>>b>>c;
	for(long long i=a;i<=a*1000;i+=a)
	 	if(i%b==c) 
	 	{
	 		cout<<"YES";
	 		return 0;
	 	}
	cout<<"NO";
	
	 
 	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N;
	cin >> N;
	vector<ll> A(N);
	FOR(i,0,N)cin >> A[i];
	SORT(A);
	vector<ll> ans,ans2;
	ll x = N/2;
	ll y = N-1;
	ll z = 0;
	ans.push_back(A[x]);
	FOR(i,0,N-1){
		if(i%2==0){
			ans.push_back(A[y]);
			y--;
		}else{
			ans.push_back(A[z]);
			z++;
		}
	}
	ll S=0,S2=0;
	FOR(i,0,N-1){
		S += abs(ans[i]-ans[i+1]);
	}



	ans2.push_back(A[x]);
	y = N-1;
	z = 0;
	FOR(i,0,N-1){
		if(i%2==1){
			ans2.push_back(A[y]);
			y--;
		}else{
			ans2.push_back(A[z]);
			z++;
		}
	}

	FOR(i,0,N-1){
		S2 += abs(ans2[i]-ans2[i+1]);
	}




	pri(max(S,S2));
}

Measured memory_bytes: 3316
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  heapq import heappop,heapify,heappush
from bisect import bisect_left

def main():
    s = input()
    l = len(s) - 1
    ans = 0
    for bit in range(1 << l):
        op = []
        for i in range(l):
            if (bit>>i)&1:
                op.append('+')
            else:
                op.append('')
        
        formula = s[0]
        for i in range(l):
            formula += op[i]
            formula += s[i + 1]
        
        ans += eval(formula)
    
    print(ans)
if __name__ == '__main__':
    main()


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

int main(){
  int n, k; cin >> n >> k;
  string s; cin >> s;
  for(int i=0; i<s.size(); ++i){
    if(i+1 == k) cout << (char)((int)s[i] + 32);
    else cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define _              ios_base::sync_with_stdio(0);cin.tie(0);
#define pb             emplace_back
#define mp             make_pair
#define F              first
#define S              second
#define rep(i, x)      for (__typeof(x) i = 0; i < x; i++)
#define repp(i, x, y)  for (__typeof(x) i = x; i < y; i++)
#define all(a)         (a).begin(),(a).end()
#define sz(x)          (int)x.size()
#define endl           '\n'
#define DB(x)          cerr << #x << " is " << x << endl;
#define TEST(T)        int T; cin >> T; rep(i, T)
#define MOD            1000000007
typedef long long          ll;
typedef vector<int>        vi;
typedef pair<int, int>     ii;
typedef vector<ii>        vii;
#define MAX 1000+10

bitset<MAX> b;
void seive(){
    b.set();
    for(int i=2;i<MAX;i++){
        if (b[i]){
            for(int j=2*i;j<MAX;j+=i) b.reset(j);
        }
    }
}

vi p(MAX, 0);

int main(){ _
    seive();
    int n; cin >> n;
    ll ways =1, k;
    for(int j=2;j<=n;j++){
        int k = j;
        for(int i=2;i<=n;i++){
            if (k != 0 && b[i]){
                while (k%i==0) k/=i, p[i]++;
            }
        }
    }
    for(auto i: p) ways = (ways*(i+1))%MOD;
    cout << ways << endl;
}

Measured memory_bytes: 256
n=int(input())
v=list(map(int,input().split()))
a=n//2
dp=[[0,0]for i in range(10**5+1)]
bp=[[0,0]for i in range(10**5+1)]
for i in range(n):
  if i%2==0:
    dp[v[i]][0]+=1
    dp[v[i]][1]=v[i]
  else:
    bp[v[i]][0]+=1
    bp[v[i]][1]=v[i]
dp.sort(reverse=True)
bp.sort(reverse=True)
if bp[0][1]==dp[0][1]:
  if dp[1][0]>=bp[1][0]:
    dp[0][0]=dp[1][0]
  else:
    bp[0][0]=bp[1][0]
print(a-dp[0][0]+a-bp[0][0])

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

int main()
 {
	
	string s,t;
	cin>>s>>t;
	int ma=0,flag=0,fin=0;
	for(int i=0;i<s.length()-t.length()+1;i++)
	{
	    int count=0,ma=0;
	    for(int j=0;j<t.length();j++)
	    {
	        if(s[i+j]==t[j])
	        {
	            count++;
	        }
	       // else
	       //   count=0;
	        ma=max(count,ma);
	    }
	    fin=max(fin,ma);
	}
	cout<<t.length()-fin<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
typedef long long ll;
using namespace std;

int main(){
  ll i,j,k,r,g,b,n;
  cin >> r >> g >> b >> n;
  ll ret=0;
  for(i=0;i<=n;i++){
    for(j=0;j<=n;j++){
      if(n-i*r-j*g>=0 && (n-i*r-j*g)%b==0)ret++;
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
#include<set>
#pragma warning(disable:4996)
set<int> s;
void zaichangnei() {
	int N = 0;
	while (scanf("%d", &N) != EOF) {
		s.clear();
		for (int i = 0; i < N; i++) {
			int tmp = 0;
			scanf("%d", &tmp);
			if (s.find(tmp) == s.end())s.insert(tmp);
			else s.erase(tmp);
		}
		printf("%d\n", s.size());
	}
}
int main() {
	//baixianguo();
	//diancai();
	zaichangnei();
	return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pi;
 
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i=a;i<=b;i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void solve()
{
    ll n;
    cin >> n;

    map<ll, ll> a;

    FOR(i, 0, n-2){
        ll x;
        cin >> x;
        a[x]++;
    }

    FOR(i, 1, n){
        if(a.find(i)!=a.end()){
            cout << a[i] << endl;
        }else{
            cout << 0 << endl;
        }
    }

    return;
}

int main() 
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastio

    ll t = 1;
    // cin >> t;

    FOR(i, 1, t){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 16124
# N, A, B, C, D = map(int, input().split())
S = input()

preS = ''

a_cnt = 0
bc_cnt = 0
ans = 0

for i, v in enumerate(S):
  if preS == 'A':
    if v == 'C':
      ans += a_cnt * bc_cnt
      a_cnt = 0
      bc_cnt = 0
  elif preS == 'B':
    if v == 'C':
      bc_cnt += 1
    else:
      ans += a_cnt * bc_cnt
      a_cnt = 0
      bc_cnt = 0      
  elif preS == 'C':
    if v == 'A' and a_cnt > 0 and bc_cnt > 0:
      ans += a_cnt * bc_cnt
      bc_cnt = 0      
    elif v != 'B':
      ans += a_cnt * bc_cnt
      a_cnt = 0
      bc_cnt = 0
  if v == 'A':
    a_cnt += 1

  preS = v
#  print(v, preS,a_cnt,bc_cnt,ans)
else:
  ans += a_cnt * bc_cnt
#  print(v, preS,a_cnt,bc_cnt,ans)
print(ans)

Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,n) for(int i=0;i<n;i++)
/*int N, heights[100005], k;
int dp[100005];
int main()
{
    fill(dp, dp + 100004, 1000000000);
    cin >> N >> k;
    loop(i, N)
    {
        cin >> heights[i];
    }
    if (N == 1)
    { 
        cout << 0;
        return 0; 
    }
    //dp[1] += abs(heights[0] - heights[1]);
    dp[0] = 0;
    for (int i=1;i<N;i++)
    {
        loop(j, min(k,i)) 
        {
            dp[i] = min(dp[i], dp[i - j - 1] + abs(heights[i] - heights[i - j - 1]));
        }
    }
    //cout << dp[1] << " ";
    cout << dp[N - 1];
}*/
int N, A[100005][3], dp[100005][3];
int main()
{
    cin >> N;
    loop(i, N)
        loop(j, 3)
            cin >> A[i][j];
    dp[1][0] = A[0][0];
    dp[1][1] = A[0][1];
    dp[1][2] = A[0][2];
    for(int i=2;i<=N;i++)
    {
        dp[i][0] = A[i - 1][0] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = A[i - 1][1] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = A[i - 1][2] + max(dp[i - 1][0], dp[i - 1][1]);
    }
    cout << max(dp[N][0], max(dp[N][1], dp[N][2]));
}



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

int main(){
    string s;
    cin >> s;
    int a = 0,b = 0;
    rep(i,s.size()){
        if(s[i] == '1')a++;
        else b++;
    }
    cout << min(a,b)*2 << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n,a[100010],b[100010];
long long ans;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n+1;i++) scanf("%d",&a[i]),ans+=a[i];
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	for(int i=1;i<=n;i++) {
		if(b[i]<=a[i]) a[i]-=b[i],b[i]=0;
		else {
			b[i]-=a[i];a[i]=0;
			if(b[i]<=a[i+1]) a[i+1]-=b[i],b[i]=0;
			else b[i]-=a[i+1],a[i+1]=0;
		}
	}
	for(int i=1;i<=n+1;i++) ans-=a[i];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1024
A,B,C,X,Y = map(int,raw_input().split())
if C * 2 > A + B:
	print A * X + B * Y
else:
	x = C * 2 * min(X,Y)
	if X < Y:
		if C * 2 < B:
			print Y * 2 * C
		else:
			y = (Y - X) * B
			print x+y
	else:
		if C * 2 < A:
			print X * 2 * C
		else:
			y = (X - Y) * A
			print x+y

Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    int n;
    cin>>n;
    if(n==1)
    cout<<"Hello World"<<endl;
    else
    {
        int a,b;
        cin>>a>>b;
        cout<<a+b<<endl;   
    }
    
    return 0;
}

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

ab = [list(map(int, input().split())) for i in range(n)]

ab.sort()

payment = 0

for i in ab:
  price = i[0]
  amount = i[1]
  if amount > m:
    amount = m
  m -= amount
  payment += amount*price
  if m == 0:
    break

print(payment) 

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

LL gcd(LL a, LL b) {
  return b ? gcd(b, a % b) : a;
}

int main() {
  LL a, b; cin >> a >> b;

  LL x = gcd(a, b);
  LL res = 1;
  for (LL i = 2; i * i <= x; i ++) {
    if (x % i == 0) {
      res ++;
      while (x % i == 0) {
        x /= i;
      }
    }
  }
  if (x > 1) res ++;

  cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int b[30];
int main(void){
    int n,m,c,res=0;
    scanf("%d%d%d",&n,&m,&c);
    for(int i=0;i<m;i++) scanf("%d",b+i);
    for(int i=0;i<n;i++){
        int a,sum=c;
        for(int j=0;j<m;j++){
            scanf("%d",&a);
            sum+=a*b[j];
        }
        if(sum>0) res++;
    }
    printf("%d\n",res);
}

Measured memory_bytes: 128
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  rep(i, n-1){
    repLRE(j, i+1, n-1){
      rep(k, 32) {
        ll ik = (i >> k) & 1;
        ll jk = (j >> k) & 1;
        if(ik != jk) {
          cout << (k + 1) << " ";
          break;
        }
      } // k
    } // j
    cout << endl;
  } // i

  return 0;
}


Measured memory_bytes: 3636
#pragma GCC optimize("O3")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>ll(b);i--)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
#define INF 1000000000000 
#define MOD 1000000007 
#define MAXR 100000 
#define PB push_back 
#define MP make_pair 
#define F first 
#define S second 
#define Umap unordered_map
#define Uset unordered_set


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

    ll K;
    cin >> K;

    if (K%2 == 0 || K%5==0) {
        cout << -1 << endl;
        return 0;
    }

    ll cnt = 1;
    ll warareru = 7;
    while (true) {
        ll amari = warareru % K;
        if (amari == 0) break;

        warareru = (amari * 10 + 7);
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
 
int main() {
    int n;
    scanf("%d", &n);
    int x[n];
    
    for(int i = 0; i < n; ++i)
        scanf("%d", &x[i]);
    
    int mini = x[0], maxi = x[0];
    
    for(int i = 1; i < n; ++i) {
        if (x[i] > maxi) 
            maxi = x[i];
            
        if (x[i] < mini) 
            mini = x[i];
    }
    
    int melhorTotal;
    
    for(int p = mini; p <= maxi; ++p) {
        int total = 0;
        for(int i = 0; i < n; ++i)
            total += (x[i] - p)*(x[i] - p);
        if (p == mini || total < melhorTotal)
            melhorTotal = total;
    }
    
    printf("%d\n", melhorTotal);
    
    
 
    return 0;
}

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

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	string c;
	cin >> c;
	int d = 0;
	int e = 0;
	for(int i = 0; i < c.size(); i++){
		if(c[i] == 'c'){
			printf("No\n");
			continue;
		}
		if(d + e >= a + b){
			printf("No\n");
			continue;
		}
		if(c[i] == 'a'){
			d++;
			printf("Yes\n");
		} else if(c[i] == 'b' && e < b){
			e++;
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	}
}


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

using namespace std;

int main(){
  long long a,b,c,k;
  cin >> a >> b >> c >> k;
  
  long long sum;
  if(a>=k){
    sum=k;
    cout << sum << endl;
    return 0;
  }else{
    sum=a;
    k-=a;
    if(b>=k){
      cout << sum << endl;
      return 0;
    }else{
      k-=b;
      cout << sum-k << endl;
    }
  }
}


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


int main()
{
  
  int r = 0 , c = 0 , list[101][101] , tate[101] , yoko[101] , s = 0;
  
  cin >> r >> c;
  
  for( int i = 0; i < 101; i++ )
    {
      tate[i] = 0;
      yoko[i] = 0;
      for( int j = 0; j < 101; j++ )
	{
	  list[i][j] = 0;
	}
    }
  
      for( int i = 0; i < r; i++ )
	{
	  for( int j = 0; j < c; j++ )
	    {
	      cin >> list[i][j];
	      yoko[i] += list[i][j];
	      tate[j] += list[i][j];
	    }
	}   
      
      for( int i = 0; i < r; i++ )
	{
	  for( int j = 0; j < c; j++ )
	    {
	      cout << list[i][j] << " ";
	    }
	  cout << yoko[i] << "\n";
	}
      
      for( int j = 0; j < c; j++ )
	{
	  s += tate[j];
	  cout << tate[j] << " ";
	}
   
      cout << s << "\n";   
      return 0;
}   

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

using namespace std;

tuple<int, int, int> t[1111];
long d[1111][11111];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> get<0>(t[i]) >> get<1>(t[i]) >> get<2>(t[i]);
	sort(t, t + n, [](auto a, auto b) {return get<0>(a) + get<1>(a) < get<0>(b) + get<1>(b); });
	for (int i = 0; i < n; i++) {
		for (int j = 1; j < 10002; j++) {
			int s = min(j > 10000 ? 10000 : j - get<0>(t[i]), get<1>(t[i]));
			d[i + 1][j] = max(d[i][j], (s < 0 ? 0 : d[i][s] + get<2>(t[i])));
		}
	}
	cout << d[n][10001] << endl;
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n,m;cin>>n>>m;
    cout<<(n*3+m)/2<<endl;
}

Measured memory_bytes: 256
from collections import deque
import sys
sys.setrecursionlimit(10**7)

N,M = map(int,input().split())
Graph =[[] for i in range(N)]
for i in range(M):
    L,R,D = map(int,input().split())
    Graph[L-1].append((R-1,D))
    Graph[R-1].append((L-1 ,-D))
visit=[False]*N
dist=[0]*N
for i in range(N):
    if not visit[i]:
        visit[i]=True
        A = deque()
        A.append(i)
        while A:
            x = A.pop()
            for y,d in Graph[x]:
                if visit[y] and (dist[y]!=d+dist[x]):
                    print('No')
                    sys.exit()
                elif not visit[y] :
                    visit[y]=True
                    A.append(y)
                    dist[y]=d+dist[x] 
    
print('Yes')

Measured memory_bytes: 67092
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
int MOD = 1000000007; //10^9 + 7

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


int main(int argc, char *argv[]){
  int n;
  cin >> n;
  vi h(n);
  rep (i, n) cin >> h[i];

  // 無限大の値
  const long long INF = 1LL << 60;

  // DP テーブル
  long long dp[100010];

  // DP テーブル全体を初期化 (最小化問題:INF else:0)
  for (int i = 0; i < 100010; ++i) dp[i] = INF;

  // 初期条件
  dp[0] = 0;

  // ループ
  for (int i = 1; i < n; ++i) {
      chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
      if(i>1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
  }

  // 解を得て出力
  cout << dp[n-1] << endl;

  return 0;
}

Measured memory_bytes: 4408
use std::io::*;
use std::str::FromStr;

//portable utility
#[allow(dead_code)]
fn switch<T>(flag: bool, true_value: T, false_value: T) -> T {
    if flag {
        true_value
    } else {
        false_value
    }
}

#[allow(dead_code)]
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")
}

#[allow(dead_code)]
fn read_string() -> Vec<char> {
    read::<String>().chars().collect()
}

#[allow(dead_code)]
fn read_vector<T: FromStr>(number: usize) -> Vec<T> {
    (0..number).map(|_| read()).collect()
}

fn main() {
    let (n, m): (usize, usize) = (read(), read());
    let hs: Vec<i32> = read_vector(n);
    let mut route: Vec<Vec<usize>> = vec![vec![]; n + 1];
    for _ in 0..m {
        let (a, b): (usize, usize) = (read(), read());
        route[a].push(b);
        route[b].push(a);
    }

    let mut count = 0;
    for i in 1..=n {
        if route[i].iter().all(|&j| hs[j - 1] < hs[i - 1]) {
            count += 1;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 8380
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<ld> vld;
#define SS(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t){cin >> t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First& first, Rest&...rest){cin >> first;MACRO_VAR_Scan(rest...);}
#define _overload3(_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(...) _overload3(__VA_ARGS__,REPI,_REP,)(__VA_ARGS__)
#define ln '\n'

using Weight = ld;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) {}
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
void add_edge(Graph &g,int a,int b,Weight w=1){g[a].emplace_back(a,b,w);g[b].emplace_back(b,a,w);}
vector<Weight> Dijkstra(const Graph &g,int s) {
    const Weight INF = numeric_limits<Weight>::max()/8;
    using state = tuple<Weight,int>;
    priority_queue<state> q;
    vector<Weight> dist(g.size(),INF);
    dist[s] = 0;
    q.emplace(0,s);
    while (q.size()) {
        Weight d;
        int v;
        tie(d,v) = q.top(); q.pop();
        d *= -1;
        /* if(v == t) return d; */
        if (dist[v]<d) continue;
        for (auto &e : g[v]) {
            if (dist[e.dst] > dist[v] + e.weight) {
                dist[e.dst] = dist[v] + e.weight;
                q.emplace(-dist[e.dst], e.dst);
            }
        }
    }
    return dist;
}

//---------------8<---------------8<---------------8<---------------8<---------------//

int barrier[1010][3];

ld dis(int a, int b) {
  ld res = 0.0;
  res += sqrt(pow(barrier[a][0]-barrier[b][0],2)
            + pow(barrier[a][1]-barrier[b][1],2));
  res -= barrier[a][2] + barrier[b][2];
  if (res < 0) return 0;
  return res;
}

signed main() {

  int start = 0, goal = 1;
  REP(i,2) {
    SS(int,x,y);
    barrier[i][0] = x;
    barrier[i][1] = y;
    barrier[i][2] = 0;
  }

  SS(int,N);
  REP(i,2,N+2) {
    SS(int,x,y,r);
    barrier[i][0] = x;
    barrier[i][1] = y;
    barrier[i][2] = r;
  }

  Graph g(N+2);
  REP(i,N+1) REP(j,i+1,N+2) add_edge(g,i,j,dis(i,j));
  vld v = Dijkstra(g,start);
  cout << setprecision(20) << v[goal] << ln;
}


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

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

  double ans = 0;
  for(int i=1;i<=n;i++){
    int i_tmp = i;
    int count = 0;
    if(i_tmp < k){
      while(i_tmp < k){
        i_tmp *= 2;
        count++;
      }
    }
    ans += pow(0.5, count);
    // cout << count << endl;
  }
  ans /= n;
  cout << setprecision(12) << ans << endl;
}


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

#スター型がマックス

if k>((n-1)*(n-2))//2:
    print(-1)
    exit()

ans=set([])

cnt=((n-1)*(n-2))//2
for i in range(2,n+1):
    ans.add((1,i))

for i in range(2,n):
    for j in range(i+1,n+1):
        if cnt>k:
            ans.add((i,j))
            cnt-=1
        else:
            break

print(len(ans))

for item in ans:
    print(item[0],item[1])







Measured memory_bytes: 43248
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-11
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007
const int N = 500031;

string st;

int main(){
	//freopen("tree.in","r",stdin);
	//freopen("tree.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	int a,b,c,d;
	cin>>a>>b>>c>>d;

	int l=max(a,c);
	int r=min(b,d);
	if (r<l)
		r=l;
	cout<<r-l<<endl;

	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 256
#include<vector>
#include"iostream"
#include"algorithm"
#include<random>
#include<string>
#include<map>
using namespace std;
#define int long long
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
int kj[300005], kji[300005];
const long long mod = 998244353;

int modpow(int x, int n, int md) {
	if (!n)return 1;
	int res = modpow(x*x%md, n / 2, md);
	if (n & 1)res = res*x%mod;
	return res;
}

int comb(int n, int r) {
	int ans = kj[n];
	ans = ans*kji[r] % mod;
	ans = ans*kji[n - r] % mod;
	return ans%mod;
}

signed main() {
	int n, a, b, k; cin >> n >> a >> b >> k;
	kj[0] = 1;
	rep(i, n+3) {
		kj[i + 1] = kj[i] * (i + 1);
		kj[i + 1] %= mod;
	}
	rep(i, n+3)kji[i] = modpow(kj[i], mod - 2, mod);

	int ans = 0;
	for (int i = 0; i <= n; i++) {//useA
		int ub = k - a*i;
		if (ub<0||ub%b)continue;
		ub /= b;
		if (ub > n)continue;
		int res = comb(n, i)*comb(n, ub) % mod;
		ans += res;
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4992
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();
        int n = sc.nextInt();
        long ans = 0;
        for (int i = 0; i <= n / r ; i++) {
            for (int j = 0; j <= n / g; j++) {
                if(n < r * i + g * j) break;
                if((n - (r * i + g * j)) % b == 0) ans++;
            }
        }
        System.out.println(ans);
        sc.close();
    }

}


Measured memory_bytes: 23636
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<int> b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];
  ll t = 0;
  rep(i,m) t += b[i];
  int j = m;
  int ans = 0;
  rep(i, n+1) {
    while (j > 0 && t > k) {
      --j;
      t -= b[j];
    }
    if (t > k) break;
    ans = max(ans, i+j);
    if (i == n) break;
    t += a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4436
#include<stdio.h>
#include<ctype.h>

int main(void) {
	char str[10000];
	int i = 0;
	gets(str);
		for (i = 0; str[i] != '\0';i++) {
			str[i] = toupper(str[i]);
		}
	printf("%s\n", str);
	return 0;
}

Measured memory_bytes: 520
H,W,N,*A = map(int,open(0).read().split())
h,w = 0,0
D = [[0]*W for i in range(H)]
for i in range(N):
    c=0
    while c<A[i]:
        D[h][w] = i+1
        if h%2==0:w+=1
        else:w-=1
        if w<0 or w>=W:
            h+=1
            w = 0 if h%2==0 else W-1
        c+=1
for d in D:print(*d)

Measured memory_bytes: 3828
#include "bits/stdc++.h"
using namespace std;
const int N=20;
int n,d,a[N][N],ans;
int main()
{
	scanf("%d%d",&n,&d);
	for(int i=0;i<n;i++)
		for(int j=0;j<d;j++)
			scanf("%d",&a[i][j]);

	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			int dist=0;
			for(int k=0;k<d;k++)
				dist+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			int r=sqrt(dist);
			if(r*r==dist) ans++;
		}
	}

	cout<<ans;
}

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

int main() {
  int N;
  cin >> N;
  
  if ((N / 1000 ==  N % 1000 / 100 && N % 1000 / 100 == N % 100 /10) || ( N % 1000 / 100 == N % 100 /10 &&  N % 100 /10 == N % 10) ) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5+10;
int num[maxn];
int vis[maxn];
int fa[maxn];
bool check(string a,string b)
{
    int len = a.size();
    for(int i = 0;i<len;++i)
    {
        if(a[i]!=b[i])
            return false;
    }
    return true;
}
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    LL a,b ,c,k;
    cin >> a >> b >> c >> k;
    LL sum = 0;
    sum = min(k,a)-max(k-a-b,0LL);
    cout << sum << "\n";
    return 0;
}


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

typedef long long ll;

using namespace std;

int main(void) {
	// For fast IO
	// cin.tie(NULL);
	// ios_base::sync_with_stdio(false);


	ll n;
	ll cnt = 0;
	int arr[100000 + 1] = {0};
	vector<ll> pnums;

	cin >> n;
	
	// 소수 찾기
	for(ll i = 2; i <= 100000 + 1; i++) {
		if(arr[i] != 0) continue;
		if(n % i == 0) pnums.push_back(i);
		for(ll j = 2; i * j <= 100000 + 1; j++) {
			arr[i * j] = 1;
		}
	}

	for(int i = 0; i < pnums.size(); i++) {
		ll p = pnums[i];
		ll cur = p;
		while(n % cur == 0) {
			n /= cur;
			cur *= p;
			cnt++;
		}
		while(n % p == 0) {
			n /= p;
		}
	}

	if(1 < n) {
		// 100000 + 1 보다 크거나 같은 값으로 곱해져 있음.
		for(ll i = 100000 + 1; i < 1000000 + 1 && 1 < n; i++) {
			while(n % i == 0) {
				n /= i;
				cnt++;
			}
		}
		if(1 < n) cnt++;	// n은 소수
	}

	cout << cnt;

	return 0;
}

Measured memory_bytes: 4024
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  double x1,x2,x3,x4,y1,y2,y3,y4;
  while(cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4){
    double dx1,dx2,dy1,dy2;
    dx1 = x1 - x2;
    dy1 = y1 - y2;
    dx2 = x3 - x4;
    dy2 = y3 - y4;
    if(abs(dx1*dx2 + dy1*dy2) < EPS)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
//1 6 2 5 3 2 5 3 2 5 3
#include <algorithm>
#include <map>
#include <iostream>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <iterator>
#include <array>
#include <iomanip>
typedef long long int ll;
using namespace std;
#define maxN 200005
#define mod 1000000007
#define pi 3.14159265358979323846264338327950

ll all[maxN] = {};
bool vis[maxN] = {};

void solve()
{
    ll n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> all[i];
    }
    vis[1] = true;
    int now = 1;
    while (1)
    {
        now = all[now];
        if (vis[now])
        {
            break;
        }
        vis[now] = true;
    }
    //cout<<"start: "<<now<<endl;
    int start = now;
    for (int i = 0; i <= n; i++)
    {
        vis[i] = 0;
    }
    vector<int> path;
    while (1)
    {
        path.push_back(start);
        vis[start] = true;
        start = all[start];
        if (vis[start])
        {
            break;
        }
    }
//    for(auto i:path){
//    	cout<<i<<" ";
//	}
//	cout<<endl;
    //cout <<path.size() << endl;
    for (int i = 0; i <= n; i++)
    {
        vis[i] = 0;
    }
    int temp = 1;
    while (1)
    {
    	if (temp == now)
        {
            break;
        }
    	temp = all[temp];
    	if(k==1){
    		cout<<temp<<endl;
    		return;
		}
        k--;
    }
    //cout<<"k: "<<k<<endl;
    cout << path[k % path.size()] << endl;
}

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

Measured memory_bytes: 6036
#include <stdio.h>

int main(){

  int vec[100][100];
  int sub[100];
  int ans[100]={0};
  int n,m,i,j,k,num,sum;

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

  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      scanf("%d",&vec[i][j]);
    }
  }
  for(j=0;j<m;j++){
    scanf("%d",&sub[j]);
  }
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      ans[i]+=vec[i][j]*sub[j];
    }
    printf("%d\n",ans[i]);
  }
  return 0;
}


Measured memory_bytes: 636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int gcd(int m,int n){
  int r,tmp;
  if(m<n){
    tmp = m;
    m = n;
    n = tmp;
  }

  r = m%n;
  while(r!=0){
    m=n;
    n=r;
    r=m%n;
  }
  return n;
}

int main(){
  int N,X;
  cin >> N >> X;
  int x[N];
  for(int i=0;i<N;i++){
    cin >> x[i];
  }
  int sub[N];
  for(int i=0;i<N;i++){
    if(x[i] - X >= 0){
      sub[i] = x[i] - X;
    }else{
      sub[i] = X - x[i];
    }
  }
  sort(sub,sub+N);
  int ans = sub[N-1];
  for(int i=0;i<N-1;i++){
    ans = gcd(sub[i],ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
using P = pair<string, int>;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;


int main(){
    int n; cin >> n;
    map<string, int> m{};
    rep(i,n){
        string s;
        cin >> s;
        if(m.count(s)){
            m[s] += 1;
        }else{
            m[s];
        }
    }
    int maxCount = 0;
    map<string, int>::iterator it;
    for(it = m.begin(); it != m.end(); it++){
        maxCount = max(maxCount, it->second);
    }
    vector<string> ans;
    for(pair<string, int> e : m){
        if(e.second == maxCount) ans.push_back(e.first);
    }
    sort(ans.begin(), ans.end());
    rep(i,ans.size()) cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 23920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * 課題C1
 *
 * @author ken2
 */
public class Main {

	/** 天気：晴れ */
	private static final String WATHER_SUNNY = "Sunny";
	/** 天気：曇り */
	private static final String WATHER_CLOUDY = "Cloudy";
	/** 天気：飴 */
	private static final String WATHER_RAINY = "Rainy";

	/**
	 * メイン処理

	 * @param args 起動引数
	 */
	public static void main(String[] args) {

		// 標準入力から今日の天気を取得
		String weather = scanTodayWeather(System.in);

		// 標準出力へ明日の天気を出力
		if (weather.equals(WATHER_SUNNY)) {
			System.out.println(WATHER_CLOUDY); // Sunny→Cloudy
		}
		if (weather.equals(WATHER_CLOUDY)) {
			System.out.println(WATHER_RAINY); // Cloudy→Rainy
		}
		if (weather.equals(WATHER_RAINY)) {
			System.out.println(WATHER_SUNNY); // Rainy→Sunny
		}
	}

	/**
	 * 今日の天気を取得
	 *
	 * @param in 入力ストリーム
	 * @return 今日の天気
	 */
	private static String scanTodayWeather(InputStream in) {
		InputStreamReader isr = new InputStreamReader(in);
		BufferedReader br = new BufferedReader(isr);
		String weather = null;
		try {
			weather = br.readLine();
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return weather;
	}
}


Measured memory_bytes: 21460
// Aizu 1209: Square Coins
// 2017.9.22 bal4u@uu

#include <stdio.h>

#define N 17

int tbl[20];
int dp[20][303];

int main()
{
	int n, i, j;

	for (i = 1; i <= N; i++) tbl[i] = i*i;
	dp[0][0] = 1;
	for (i = 1; i <= N; i++) for (n = 0; n <= 300; n++)	{
		dp[i][n] += dp[i-1][n];
		for (j = tbl[i]; n+j <= 300; j += tbl[i]) dp[i][n+j] += dp[i-1][n];
	}
	while (scanf("%d", &n) && n) printf("%d\n", dp[N][n]);
	return 0;
}

Measured memory_bytes: 1736
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

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


const long long int mod = 998244353;
const long long int INF = 1e18;




long long int H,W,res=0;
string a[100];
int main()
{
    cout << fixed << setprecision(18);
    cin>>H>>W;
    for(long long int i = 0; i < H; i++){
        cin>>a[i];
    }
    for(long long int i = 0; i < H; i++){
        for(long long int j = 0; j < W; j++){
            if(a[i][j]=='#'){
                res++;
            }
        }
    }
    if(res==H+W-1){
    cout<<"Possible"<<endl;
    }else{
        cout<<"Impossible"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

vector<ll> v;

// n自身はvectorに入らないので注意！
void enum_div(ll n)//nの約数を列挙
{
	for(ll i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			v.push_back(i);
			if(i!=1 && i*i!=n)
			{
				v.push_back(n/i);
			}
		}
	}
}

int main(void){
  ll x; cin >> x;
  enum_div(x);
  ll ans = 1001001001001001;

  for(auto y: v){
    chmin(ans,y + x/y - 2);
  }

  cout << ans << endl;



}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        int tmp = i;
        int ketasuu = 0;
        while(tmp) {
            ketasuu++;
            tmp /= 10;
        }
        if(ketasuu % 2 == 1) ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int ans = -1;
		int num = 7;
 
		for (int i = 1; i <= k; i++) {
			if (num % k == 0) {
				ans = i;
				break;
			}
 
			num = (((10 % k) * (num % k)) % k + 7 % k) % k;
		}
 
		System.out.println(ans);
 
		sc.close();
	}
 
}

Measured memory_bytes: 35720
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long 
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define pw(x) (1<<(x))
#define inf 1000000005
#define MOD 1000000007 
#define N 2005
#define M 1000003
#define LOG 19
#define KOK 250
#define EPS 0.0000001
using namespace std;

int n;
char s[N]; 
bitset<2005> okb[N],oks[N];
bitset<2005> v[N];

int main() {

	scanf("%d",&n);

	for(int i=1;i<=n;i++) v[i][i]=1;

	for(int i=2;i<=n;i++) {

		scanf("%s",s+1);

		for(int j=1;j<=i-1;j++) {

			if(s[j]=='1') {

				v[i][j]=1;

			}
			else {

				v[j][i]=1;

			}

		}

	}

	int ans=0;

	for(int i=1;i<=n;i++) oks[i][i]=okb[i][i]=1;

	for(int i=1;i<n;i++) {

		if(v[i][i+1]) {

			okb[i+1][i]=1;

		}
		else {

			oks[i][i+1]=1;

		}

	}

	for(int l=3;l<=n;l++) {

		for(int s=l;s<=n;s++) {

			bitset<2005> res=v[s]&oks[s-l+1]&okb[s-1];

			if(res.count()) oks[s-l+1][s]=1;

		}

		for(int b=1;b+l-1<=n;b++) {

			bitset<2005> res=v[b]&oks[b+1]&okb[b+l-1];

			if(res.count()) okb[b+l-1][b]=1;

		}

	}

/*	for(int i=1;i<=n;i++) {

		for(int j=i;j<=n;j++) {

			printf("%d %d bas %d son %d\n",i,j,(int)okb[j][i],(int)oks[i][j]);	

		}

	}*/

	for(int i=1;i<=n;i++) {

		if(okb[n][i] && oks[1][i]) ans++;

	}

	printf("%d",ans);

}

Measured memory_bytes: 1792