akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			String trump = sc.next();
			
			if(trump.equals("#")) break;
			else calc(trump);
		}
	}
	public void calc(String trump){
		String[][] cards = new String[4][13];
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 13; j++){
				cards[i][j] = sc.next();
			}
		}
		
		int led = 0;
		int nsPoint = 0;
		int ewPoint = 0;
		for(int i = 0; i < 13; i++){
			String[] turn = new String[]{cards[0][i], cards[1][i], cards[2][i], cards[3][i]};			
			String ledSuit = turn[led].substring(1, 2);
			
			int winner = win(turn, ledSuit, trump);
			
			if(winner == 0 || winner == 2) nsPoint++;
			else ewPoint++;
			
			led = winner;
		}
		
		if(nsPoint > ewPoint){
			int point = nsPoint - 6;
			System.out.println("NS " + point);
		}
		else{
			int point = ewPoint - 6;
			System.out.println("EW " + point);
		}
	}

	public int win(String[] turn, String ledSuit, String trump){
		int winner = 0;
		int winNum = getNum(turn[0].substring(0, 1));
		String winSuit = turn[0].substring(1,2);
		
		for(int i = 1; i < 4; i++){
			int turnNum = getNum(turn[i].substring(0, 1));
			String turnSuit = turn[i].substring(1, 2);
			
			if(turnSuit.equals(trump)){
				if(!winSuit.equals(trump)){
					winner = i;
					winNum = turnNum;
					winSuit = turnSuit;
				}
				else if(turnNum > winNum){
					winner = i;
					winNum = turnNum;
					winSuit = turnSuit;
				}
			}
			else if(turnSuit.equals(ledSuit)){
				if(!winSuit.equals(trump)){
					if(!winSuit.equals(ledSuit)){
						winner = i;
						winNum = turnNum;
						winSuit = turnSuit;
					}
					else if(turnNum > winNum){
						winner = i;
						winNum = turnNum;
						winSuit = turnSuit;
					}
				}
			}
		}
		return winner;
	}
	
	public int getNum(String card){
		if(card.equals("T")) return 10;
		else if(card.equals("J")) return 11;
		else if(card.equals("Q")) return 12;
		else if(card.equals("K")) return 13;
		else if(card.equals("A")) return 14;
		else return Integer.valueOf(card);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

const int H_max = 50;
const int W_max = 50;
char map[H_max][W_max];
//bool arrived[H_max][W_max];

struct pos{
  int x;
  int y;
  int d;
};

queue<pos> que;

void debug_maps(int h, int w, int x, int y, int l) {
  cout << "pos:: x, " << x << " y, " << y << endl;
  cout << "depth " << l << endl;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << map[i][j];
    }
    cout << endl;
  }
}

int bfs(int h, int w) {
  pos start = {0, 0, 1};
  que.push(start);
  //map[0][0] = '#';
  while (!que.empty()) {
    pos p = que.front();
    que.pop();
    int x = p.x;
    int y = p.y;
    int d = p.d;
    map[x][y] = '#';
    //debug_maps(h, w, x, y, d);
    for (int k = 0; k <= 1; k++) {
      for (int i = -1; i <= 1; i++) {
	int next_x = x;
	int next_y = y;
	if (k == 0) {
	  next_x += i;
	}
	else {
	  next_y += i;
	}
	if (next_x == h-1 && next_y == w-1) {
	  return d+1;
	}
	if ((next_x < 0) ||
	    (next_x >= h) ||
	    (next_y < 0) ||
	    (next_y >= w) ||
	    (map[next_x][next_y] == '#'))
	  {
	    continue;
	  }
	else {
	  //cout << "pushed! (" << next_x << ", " << next_y << ") " << endl;
	  pos next_pos = {next_x, next_y, d+1};
	  que.push(next_pos);
	  map[next_x][next_y] = '#';
	}
      }
    }
  }
  return -1;
}

int main() {
  int h, w;
  cin >> h >> w;
  int sharps = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> map[i][j];
      if (map[i][j] == '#') {
	sharps++;
      }
    }
  }
  int length = bfs(h, w);
  //cout << "path length: " << length << endl;
  int ans = (length == -1 ? -1:(h*w - length - sharps));
  cout << ans << endl;
}

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

def bfs(x, y):
    s = [[False for i in range(W)] for j in range(H)]
        
    q = [(x, y, 0)]

    while q:
        a, b, c = q.pop(0)
        if S[a][b] == '#' or s[a][b]: continue
        s[a][b] = True
        
        if a+1 < H and S[a+1][b] == '.': q.append((a+1, b, c+1))
        if 0 <= a-1 and S[a-1][b] == '.': q.append((a-1, b, c+1))
        if b+1 < W and S[a][b+1] == '.': q.append((a, b+1, c+1))
        if 0 <= b-1 and S[a][b-1] == '.': q.append((a, b-1, c+1))
        
    return max(0, c-1)
    

if __name__ == '__main__':
    H, W = map(int, input().split())
    S = [input() for i in range(H)]
    ans = 0
    
    for i in range(H):
        for j in range(W):
            ans = max(ans, bfs(i, j))
            
    print(ans)
    

Measured memory_bytes: 3188
//=template==================================================================//
// include
#include <vector>
#include <list>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

// namespace
using namespace std;

// define
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(i,n) FOR(i,0,n)

// typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long LL;

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

//=function prototype========================================================//

//===========================================================================//

//=variables=================================================================//

//===========================================================================//
int main(void)
{
  // Scan begin.
  int i, j, k, idx;
  int n, m;
  LL x, y, z;
  LL ans = 0;

  vector<LL> xv;
  vector<LL> yv;
  vector<LL> zv;

  vector<vector<LL>> xyzvv(8);

  cin >> n >> m;
  FOR (i, 0, n) {
    cin >> x >> y >> z;
    xv.push_back(x);
    yv.push_back(y);
    zv.push_back(z);
  }
  // Scan done.

  // Code begin.
  FOR (i, 0, 2) {
    FOR (j, 0, 2) {
      FOR (k, 0, 2) {
        int mode = i*4 + j*2 + k;
        FOR (idx, 0, n) {
          LL eval = 0;
          eval += (i==0 ? xv.at(idx) : -1 * xv.at(idx));
          eval += (j==0 ? yv.at(idx) : -1 * yv.at(idx));
          eval += (k==0 ? zv.at(idx) : -1 * zv.at(idx));
          xyzvv.at(mode).push_back(eval);
        }
      }
    }
  }

  FOR (i, 0, 8) {
    sort(xyzvv.at(i).begin(), xyzvv.at(i).end(), greater<LL>());

    LL temp = 0;
    FOR (j, 0, m) {
      temp += xyzvv.at(i).at(j);
    }
    if (ans < temp) {
      ans = temp;
    }
  }

  cout << ans << endl;
  // Code done.

  return 0;
}

//=functions=================================================================//

//===========================================================================//

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

const long INF = LLONG_MAX / 3;

int main(){
  int n,W;
  cin>>n>>W;
  vector<int> w(n), v(n);
  rep(i,n) cin>>w[i]>>v[i];

  int mv = accumulate(all(v), 0);

  vector<long> dp(mv+1, INF);
  dp[0] = 0;
  rep(i,n){
    vector<long> nxt(dp);

    rep(j,mv) if(j + v[i] <= mv) {
      nxt[j + v[i]] = min(nxt[j+v[i]], dp[j] + w[i]);
    }

    swap(nxt, dp);
  }

  int ans = 0;
  rep(i,mv+1) if(dp[i] <= W) ans = max(ans, i);

  cout << ans << endl;

  return 0;
}


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


int h, w;
vector<string> field;

void dfs(int y, int x) {
  int dy[4] = { -1, 0, 1, 0 };
  int dx[4] = { 0, 1, 0, -1 };

  char c = field[y][x];
  field[y][x] = '.';
  for (int i = 0; i < 4; i++) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    if (ny < 0 || ny >= h) {
      continue;
    }
    if (nx < 0 || nx >= w) {
      continue;
    }
    if (field[ny][nx] == '.') {
      continue;
    }
    if (field[ny][nx] == c) {
      dfs(ny, nx);
    }
  }
}


int main() {
  while (true) {
    cin >> h >> w;
    if (h + w == 0) {
      break;
    }
    field.resize(h);
    for (int i = 0; i < h; i++) {
      cin >> field[i];
    }

    int ans = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (field[i][j] != '.') {
          ans++;
          dfs(i, j);
        }
      }
    }

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

Measured memory_bytes: 4228
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
t, a = na()
hhh = na()
tmp = 100000000
for i, h in enumerate(hhh):
    dif = abs(t - h * 0.006 - a)
    if dif < tmp:
        ans = i + 1
        tmp = dif
print(ans)

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using ll = long long;
using v_int = std::vector<int>;
using v2_int = std::vector<v_int>;
using v_ll = std::vector<ll>;
using v2_ll = std::vector<v_ll>;
using v_string = std::vector<std::string>;
using v_bool = std::vector<bool>;
using v2_bool = std::vector<v_bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using mii = std::map<int, int>;
using mll = std::map<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = 2*(int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = 1000000007;
//const int dc[4] = {1, -1, 0,  0};
//const int dr[4] = {0,  0, 1, -1};
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

using namespace std; 

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T, typename U, typename V> inline
ostream& operator<<(ostream &o, tuple<T,U,V> &p)
{
    return o << "{" << get<0>(p) << "," << get<1>(p) << "," << get<2>(p) << "}";
}

template<typename T> inline
istream& operator>>(istream &is, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) {
        is >> v[i]; 
    }
    return is;
}

template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) { 
        os << v[i];
        if(i != len-1) { os << ","; } 
    } 
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }

template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n;
    cin >> n;
    v_int a(n);
    cin >> a;

    sort(a.begin(), a.end());

    v_int cnt(n);
    ll ans = a[n-1];
    
    int idx = n-2;
    n-=2;

    while(n) {
        ans += a[idx];
        
        cnt[idx]++; n--;
        if(cnt[idx]==2) {
            idx--;
        }
    }
    cout << ans << endl;
    return 0;
}

/*atcoder*/


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

int main() {
  int N;
  cin >> N;
  #define size N
  char S[size];
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  int count_Y = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'Y') {
      count_Y++;
    }
  }
  if (count_Y == 0) {
    cout << "Three" << endl;
  } else {
    cout << "Four" << endl;
  }
}


Measured memory_bytes: 256
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    qi = q[0]
    i = 0
    for s in S:
        if s==qi:
            if i==2:
                ans += 1
                break
            else:
                i+=1
                qi = q[i]
print (ans)
            


Measured memory_bytes: 3444
from itertools import combinations_with_replacement
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split())) for _ in range(q)]
s=0
for p in combinations_with_replacement(range(1,m+1),n):
    t=0
    for a,b,c,d in abcd:
        t+=d*(p[b-1]-p[a-1]==c)
    s=max(s,t)
print(s)

Measured memory_bytes: 9120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	cin.tie(0);
        ios::sync_with_stdio(false);	
	int ans = 0;
	vector<char> vec;
	int n;
	cin >> n;
	for(int i = 0;i<n;++i){
		char temp;
		cin >> temp;
		vec.push_back(temp);
	}
	for(int i = 1;i<n;++i){
		vector<char> fir;
		vector<char> sec;
		copy(vec.begin(),vec.begin()+i,back_inserter(fir));
		copy(vec.begin()+i,vec.end(),back_inserter(sec));
		sort(fir.begin(),fir.end());
		sort(sec.begin(),sec.end());
		fir.erase(unique(fir.begin(),fir.end()),fir.end());
		sec.erase(unique(sec.begin(),sec.end()),sec.end());
		vector<char> list_inter;
		set_intersection(fir.begin(),fir.end(),sec.begin(),sec.end(),back_inserter(list_inter));
		if(ans<list_inter.size())ans=list_inter.size();
	}
	cout << ans<<endl;
	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   // ifstream cin("input.in");
   // ofstream cout("output.out");
    ios::sync_with_stdio(0);cin.tie(0);
    long long N,A[200009],S=0;
    cin>>N;
    for(long i=0;i<N;i++)
    {
        cin>>A[i];
        S+=A[i];
    }
    long long D=0,M=2e18;
    for(long i=0;i<N-1;i++){
        if(abs(S-2*(D+A[i]))<M)
            M=abs(S-2*(D+A[i]));
        D+=A[i];
    }
    cout<<M;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std ;
///CHECKING @Tanvir
#define ft first
#define sd second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<int, pii>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair


#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

const int mod = 1e9 + 7;

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

int MUL(int a, int b, int m = mod) {
    return (1LL * a * b % m);
}

int power(int a, int b, int m = mod) {
    int res = 1;
    while( b ) {
        if( b & 1 ) {
            res = 1LL * res * a % m;
        }
        a = 1LL * a * a % m;
        b /= 2;
    }
    return res;
}


const int maxn = 1e9 + 1;

bool cnt[maxn];


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cout.tie(0);
    bool hobe = true;

    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        int val;
        cin>>val;
        if(cnt[val]) hobe= false;

        cnt[val]= true;

    }
    if(hobe) cout<<"YES\n";
    else cout<<"NO\n";


    return 0;
}

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

6
4 1 3 1 6 2

5
2 6 1 4 5



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


Measured memory_bytes: 975360
# import itertools
import math
from functools import reduce
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

# if gcd_list(A) > 1:
#     print("not coprime")
#     exit()

# 高速素因数分解準備
#MAXN = 10**6+10
#sieve = [i for i in range(MAXN+1)]
#p = 2
#while p*p <= MAXN:
#    if sieve[p] == p:
#        for q in range(2*p, MAXN+1, p):
#            if sieve[q] == q:
#                sieve[q] = p
#    p += 1

A.sort()
MAXN = A[-1]
sieve = [1] * (MAXN + 1)
st = set()
for a in A:
    if a in st:
        sieve[a] = 0
    if sieve[a] == 1:
        for q in range(2*a, MAXN+1, a):
            if sieve[q] == 1:
                sieve[q] = 0
    st.add(a)

ans = 0
for a in A:
    ans += sieve[a]
print(ans)

Measured memory_bytes: 40164
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

using pii = pair<int, int>;
using i64 = long long;

vector<int> dig;

int sdig(i64 x) {
	int s(0);
	while (x > 0) {
		s+= x % 10;
		x/= 10; }
	return s; }

int main() {
#ifdef HOME
	freopen("agc.in", "r", stdin);
	freopen("agc.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int ant(0), s(0);
	i64 n;

	cin >> n;
	ant = sdig(n);
	while (n > 0) {
		dig.push_back(n % 10);
		n/= 10; }
	reverse(begin(dig), end(dig));

	s+= dig[0] - 1;
	for (int i = 1; i < dig.size(); ++i)
		s+= 9;

	ant = max(ant, s);
	cout << ant << endl;

	return 0; }


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

typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<int> vec;
typedef vector<vec> mat;
const ll INF = 100001LL;

int main() {
    ll a, b, d;
    while(cin >> a >> b >> d, a || b || d) {
        vector<P> v;

        for (ll i = 0LL; i <= 100000LL; i++) {
            ll X = a * i + d;
            if (X >= b && X % b == 0LL) v.push_back(P(i, X / b));
            ll Y = b * i + d;
            if (Y >= a && Y % a == 0LL) v.push_back(P(Y / a, i));
            ll Z = a * i;
            if (d > Z && (d - Z) % b == 0LL) v.push_back(P(i, (d - Z) / b));
            ll W = b * i;
            if (d > W && (d - W) % a == 0LL) v.push_back(P((d - W) / a, i));
        }

        ll ansX = INF, ansY = INF;
        for (int i = 0, len = v.size(); i < len; i++) {
            ll X = v[i].first;
            ll Y = v[i].second;
            if ((ansX + ansY) >= (X + Y) && (ansX * a + ansY * b) >= (X * a + Y * b)) {
                ansX = X;
                ansY = Y;
            }
        }

        cout << ansX << " " << ansY << endl;
    }

    return 0;
}

Measured memory_bytes: 6916
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;



void solve()
{
    int n,m;
    scanf("%d%d", &n, &m);
    vector<int> z(n,-1);
    int i,j;
    int bad=0;
    for(i=0; i<m; i++) {
        int s,c;
        scanf("%d%d", &s, &c); s--;
        if(z[s]<0) z[s]=c;
        else if(z[s]!=c) bad=1;
    }
    if(bad) {
        printf("-1\n"); return;
    }
    vector<int> ans;
    for(j=0; j<n; j++) {
        if(z[j]>=0) {
            if(j==0 && n!=1 && z[j]==0) bad=1;
            ans.push_back(z[j]);
        }
        else {
            if(j==0 && n!=1) ans.push_back(1);
            else ans.push_back(0);
        }
    }
    if(bad) {
        printf("-1\n"); return;
    }
    for(j=0; j<n; j++) {
        printf("%d", ans[j]);
    }
    printf("\n");

    return;
}


int main(int argc, char* argv[])
{
#if 1
	solve();
#else
	int T; scanf("%d", &T);
	while (T--) {
		solve();
	}
#endif
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
INF = 1<<21
WHITE, GRAY, BLACK = 0, 1, 2
n = int(stdin.readline())
M = [[INF] * n for _ in range(n)]
for i in range(0, n):
    for j, e in enumerate(list(map(int, stdin.readline().split()))):
        if e != -1: M[i][j] = e
d = [INF] * n
d[0] = 0
color = [0] * n
def prim():
    while True:
        minv = INF
        u = -1
        for i in range(0, n):
            if minv > d[i] and color[i] != BLACK:
                u = i
                minv = d[i]
        if u == -1: break
        color[u] = BLACK
        for v in range(0, n):
            if color[v] != BLACK and d[v] > M[u][v]:
                d[v] = M[u][v]
    return sum(d)
print(prim())

Measured memory_bytes: 7988
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


vector<vector<pair<int,int> > >adj;
int vis[100005];
vector<pair<int,int> >ans;
int mm[100005];
int deg[100005];
void dfs(int ver)
{
    vis[ver]=1;
    int cnt=0;
    vector<pair<int,int> >temp1,temp2;
    for(auto i:adj[ver])
    {
        if(!vis[i.first])
        {
            dfs(i.first);
        }
    }

    for(auto i:adj[ver])
    {
        if(!mm[i.second])
        {
            if(vis[i.first]==1)
                temp1.push_back({i.second,i.first});
            else
                temp2.push_back({i.second,i.first});
        }
    }

    int sz=temp1.size()+temp2.size();
    if(sz&1)
    {
        if(temp1.size()>0)
        temp1.pop_back();
    }

        for(auto i:temp1)
        {
            mm[i.first]=1;
            ans.push_back({ver,i.second});
        }

        for(auto i:temp2)
        {
            mm[i.first]=1;
            ans.push_back({ver,i.second});
        }
    vis[ver]=2;
}


signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,m;
    cin>>n>>m;
    adj.resize(n+1);
    int x,y;
    vector<pair<int,int> >pp;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        pp.push_back({x,y});
        adj[x].push_back({y,i+1});
        adj[y].push_back({x,i+1});
    }

    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
            dfs(i);
    }
    int sum=0;
    for(auto i:ans)
            deg[i.first]++;
    for(int i=1;i<=n;i++)
    {
        sum+=deg[i];
        if(deg[i]&1)
        {
            cout<<-1;
            return 0;
        }
    }
    if(sum!=m)
    {
        cout<<-1;
        return 0;
    }

    for(auto i:ans)
            cout<<i.first<<" "<<i.second<<"\n";
} 


Measured memory_bytes: 26480
/// Kazuki Hoshino


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple

ll n, a[202020], ans , t;

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

cin >> n >> t;

rep(i, 1, n){
cin >> a[i];

}
a[n+1]=1000000000000000;
rep(i, 1, n){
ans+= min(t, a[i+1]-a[i] );
}

cout << ans << endl;





return 0;}
///....


Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys

def f(n):
    if n%2==0:
        return int(n/2)
    else:
        return 3*n+1

def solve(s: int):
    a = [s]
    a_prev = s
    for i in range(100000):
        a_i = f(a_prev)
        a_prev = a_i
        if a_i in a:
            break
        else:
            a.append(a_i)
        
    print(i+2)
        
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = int(next(tokens))  # type: int
    solve(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)

int main() {
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n){
    cin>>a[i];
  }
  sort(a,a+n);
  reverse(a,a+n);
  int ans=0;
  rep(i,0,n){
    if(i%2==0){
      ans+=a[i];
    }
    else{
      ans-=a[i];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import math
a,b,c = map(int,input().split())
sin = math.sin(math.radians(c))
area = a * b * sin / 2
if c == 90:
   h = float(b)
   hypotenuse = math.sqrt(a ** 2 + b ** 2)
elif c > 90:
  h = b * sin
  a_sub = math.sqrt(b ** 2 - h ** 2)
  hypotenuse = math.sqrt((a + a_sub) ** 2 + h ** 2)
elif c < 90:
  h = b * sin
  a_sub = math.sqrt(b ** 2 - h ** 2)
  hypotenuse = math.sqrt((a_sub - a) ** 2 + h ** 2)
around = a + b + hypotenuse
print(f"{area:.8f}")
print(f"{around:.8f}")
print(f"{h:.8f}")


Measured memory_bytes: 5712
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int A[] = new int[N];
		for (int i=0;i<N;i++) {
			A[i] = sc.nextInt();
		}
		Arrays.parallelSort(A);
		int sum =0;
		for (int i=0;i<K;i++) {
			sum +=A[i];
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 39180
// AOJ 1251: Pathological Paths
// 2017.10.19 bal4u@uu

#include <stdio.h>
#include <string.h>

#define HASHSIZ 10007
typedef struct { char *s; int k; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash + HASHSIZ;			// Hash table

void insert(char *s, int w, int k)
{
	int i = (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	HASH *tp = hash + i;

	while (tp->s != NULL) {
		if (!memcmp(tp->s, s, w)) return;
		if (++tp == hashend) tp = hash;
	}
	tp->s = s, tp->k = k;
}

int lookup(char *s, int w)
{
	int i = (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	HASH *tp = hash + i;

	while (tp->s != NULL) {
		if (!memcmp(tp->s, s, w)) return tp->k;
		if (++tp == hashend) tp = hash;
	}
	return -2;
}

char path[102][102];
char s[2][102];
char t[2][120];

int main()
{
	int n, m, i, k, found[2];
	char *p, *q;

	while (scanf("%d%d", &n, &m) && n > 0) {
		memset(hash, 0, sizeof(hash));
		for (i = 0; i < n; i++) {
			scanf("%s", path[i]);
			p = path[i];
			while (*p) {
				p++;
				while (*p && *p != '/') p++;
				k = (*p == 0) ? i : -1;
				insert(path[i], p-path[i], k);
			}
		}

		while (m-- > 0) {
			memset(s, 0, sizeof(s)), memset(t, 0, sizeof(t));
			for (i = 0; i < 2; i++) scanf("%s", s[i]);
			for (i = 0; i < 2; i++) {
				p = s[i], q = t[i];
				if (*p++ != '/') goto notfound;
				*q++ = '/';
				while (*p) {
					if (*p == '/') {
						if (lookup(t[i], q-t[i]) != -1) goto notfound;
						*q++ = *p++;
					} else if (*p == '.' && *(p-1) == '/' &&
						(*(p+1) == '.' || *(p+1) == '/' || *(p+1) == 0)) {
						p++;
						if (*p == '.') {		// for /../
							if (*(p+1) != '/' && *(p+1) != 0) goto notfound;
							if (--q == t[i]) goto notfound;
							if (--q == t[i]) goto notfound;
							while (*q != '/') q--;
							p++, q++;
						}
						p++;
					} else *q++ = *p++;
				}

				*q = 0;
				if ((found[i] = lookup(t[i], q-t[i])) >= 0) goto next;
				if (*(q-1) == '/') {
					strcpy(q, "index.html");
					if ((found[i] = lookup(t[i], q-t[i]+10)) >= 0) goto next;
				} else {
					strcpy(q, "/index.html");
					if ((found[i] = lookup(t[i], q-t[i]+11)) >= 0) goto next;
				}
				goto notfound;
next:;
			}
			puts(found[0] == found[1] ? "yes" : "no");
			continue;
notfound:	puts("not found");
		}
	}
 	return 0;
}

Measured memory_bytes: 1804
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();

            string[] strs = line.Split(' ');

            long N = long.Parse(strs[0]);
            long A = long.Parse(strs[1]);
            long B = long.Parse(strs[2]);
            long count = (N / (A + B)) * A;
            if ((N % (A + B)) < A)
                count += (N % (A + B));
            else
                count += A;

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int vecmin(vector<int> v) {
    sort(v.begin(), v.end());
    return v[0];
}
int main()
{
    int A, B, m;
    cin >> A >> B >> m;
    vector<int> a(A), b(B);
    for(int i = 0; i < A; i++)
        cin >> a[i];
    for(int i = 0; i < B; i++)
        cin >> b[i];
    vector<tuple<int, int, int>> discnt(m);
    for(int i = 0; i < m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        discnt[i] = make_tuple(x, y, z);
    }
    int abmin = vecmin(a) + vecmin(b);
    for(int i = 0; i < m; i++) {
        if (abmin > a[get<0>(discnt[i]) - 1 ] + b[get<1>(discnt[i]) - 1] - get<2>(discnt[i]))
            abmin = a[get<0>(discnt[i]) - 1] + b[get<1>(discnt[i]) - 1] - get<2>(discnt[i]);
        // cout << a[get<0>(discnt[i]) -1 ] << " " << b[get<1>(discnt[i]) -1 ] << " " << get<2>(discnt[i]) << '\n';
    }
    cout << abmin << '\n';
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())

using namespace std;

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
typedef vector<ll> vecll;
const ll inf =1000000007;

//二項係数

const ll MAX = 510000;
const ll MOD = 998244353;

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

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

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

ll cal(ll x, ll n) {  // (x)^N　　
    int p = n;
    x %= MOD;
    ll res = 1;
    while (p > 0) {
        if (p & 1) res = (x * res) % MOD; //pが奇数ならresはx倍される
        x = x * x % MOD; //ここはxを二乗している
        p >>= 1; //pを二で割って、あまり切り捨てか。
    }
    return res;
}


void solve(){
    COMinit();
    ll n,m,k;
    cin >> n >> m >>k;
    ll ans=0;
    for(ll i=0;i<=k;i++){
        ll score=m;
        score*=COM(n-1,i);
        score%=MOD;
        score*=cal(m-1,n-1-i);
        score%=MOD;
        ans+=score;
        ans%=MOD;
    }
    kaku((ans+MOD)%MOD);
}

int main(){
    solve();
}

Measured memory_bytes: 15600
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())
#define maxIndex(v) max_element(v.begin(), v.end()) - v.begin()
#define maxElement(v) *max_element(v.begin(), v.end())
#define minIndex(v) min_element(v.begin(), v.end()) - v.begin()
#define minElement(v) *min_element(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;

int main()
{
  ll N, zero = 0; cin >> N;
  if (N % 2) cout << 0 << endl;
  else {
    zero += N / 10;
    N /= 10;
  	while (N >= 5) {
    	zero += N / 5;
      	N /= 5;
    }
    cout << zero << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
#define MAX 100000


int main(){
    string s,t;
    cin>>s>>t;
    if(s.size()<t.size())cout<<"UNRESTORABLE";
    else{ 
        int size=s.size()-t.size();
        int index;
        for(int i=size;i>=0;i--){
            bool flag=false;
            rep(j,t.size()){
                if(s[j+i]!=t[j]&&s[i+j]!='?'){
                    flag=true;
                  	index=-1;
                    break;
                }
            }
            if(!flag){
                index=i;
                break;
            }
        }
        if(index==-1)cout<<"UNRESTORABLE";
        else{
            rep(i,s.size()){
                if(index<=i&&i<index+t.size()){
                    cout<<t[i-index];
                }
                else {
                    if(s[i]=='?')cout<<'a';
                    else cout<<s[i];
                } 
            }
        }
    }
    return 0;
}
    



Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <unordered_map>
#include <map>
#include <limits.h>
#include <unordered_set>
#include <stack>
#include <string.h>
#include <math.h>
#define fo(i,l,r) for(int i=l;i<=r;++i)
#define fi(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define po pop_back
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long int ll;
typedef unsigned long long int ulli;
using namespace std;
void debugGraph(vector<vector<int> >& graph){
  for(int i=0;i<graph.size();++i){
			cout<<i<<" :";
			for(int j=0;j<graph[i].size();++j){
				cout<<graph[i][j]<<" ";
			}
			cout<<endl;
		}
}
void swap(int *a,int *b){
    int tmp = *a;
    *a = *b;
    *b = tmp;
}
void swap(ll *a,ll *b){
    ll tmp = *a;
    *a = *b;
    *b = tmp;
}
void input(vector<int>& arr,int n){
    fo(i,0,n-1){
        cin>>arr[i];
    }
}
void input(vector<ll>& arr,int n){
  fo(i,0,n-1){
    cin>>arr[i];
  }
}
void input(vector<ulli>& arr,int n){
    fo(i,0,n-1){
        cin>>arr[i];
    }
}
ll max(ll a,ll b){
    return a>b?a:b;
}
ulli max(ulli a,ulli b){
    return a>b?a:b;
}
int max(int a,int b){
    return a>b?a:b;
}
void print(vector<int>& ans,int n){
    fo(i,0,n-1){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
}
void print(vector<ll>& ans,int n){
    fo(i,0,n-1){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
}
void solve(){
    ll n,m;
    cin>>n>>m;
    cout<<n*m<<endl;
}
int main(){
    speed;
    #ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    #endif // !ONLINE_JUDGE
    solve();
}


Measured memory_bytes: 3188
// Getting TlE
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#define ll long long 
#define dd double
using namespace std;
const ll MOD = 1e9 + 7; 
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin>>n;
  ll a[n];
  ll i,j;
  ll s=0;
  ll max=0;
  for(i=0;i<n;i++){
  	cin>>a[i];
  	if(a[i]>max){
  		max=a[i];
	}
	
	if(max>a[i]){
		ll sub=max-a[i];
		s=s+sub;
	}
	
  }
  cout<<s<<endl;
  
  return 0;
}

Measured memory_bytes: 5168
N = int(input())
res = [[0 for _ in range(9)] for _ in range(9)]
for i in range(1, N + 1):
    if i % 10:  res[int(str(i)[0]) - 1][i % 10 - 1] += 1
ans = 0
for i in range(1, N + 1):
    if i % 10:  ans += res[i % 10 - 1][int(str(i)[0]) - 1]
print(ans)

Measured memory_bytes: 73492
#pragma region Macros

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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;
}
template <class T>
ostream &operator<<(ostream &out, vector<T> const &v) {
    for (auto &&a : v) out << a << " ";
    out << endl;
    return out;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int X;
    cin >> X;

    int ureshisa = 0;
    ureshisa += X / 500 * 1000;
    ureshisa += (X % 500) / 5 * 5;
    cout << ureshisa;
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 3584
/*====================================
Auther:    Shyam Makwana
Problem:   abc175_d.cpp
====================================*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
	long long int n,m;
	cin>>n>>m;
	vector<ll> per(n+1);
	vector<ll> point(n+1);

	for(int i=1;i<=n;i++)
		cin>>per[i];

	for(int i=1;i<=n;i++)
		cin>>point[i];

	ll max1=INT_MIN;
	for(int i=1;i<=n;i++)
	{
		int j=i;
		ll c1=0,csum=0;
		while(true)
		{
			c1++;
			csum+=point[j];						
			j=per[j];
			if(j==i)
				break;
		}		
		
		ll cur=0;		
		if(csum<=0)
		{		
			j=i;
			while(true)
			{
				cur+=point[j];
				max1=max(max1,cur);
				j=per[j];
				if(j==i)
					break;
			}			
		}
		else
		{
			ll k=m;
			ll num=k/c1;
			num--;
			cur=num*csum;
			k-=(num*c1);
			max1=max(max1,cur);
			j=i;
			while(k--)
			{
				cur+=point[j];				
				max1=max(max1,cur);
				j=per[j];
				if(j==i)
					break;
			}
			while(k--)
			{
				cur+=point[j];				
				max1=max(max1,cur);
				j=per[j];
				if(j==i)
					break;
			}
		}
	}
	cout<<max1;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    vector<vector<int>> G(H, vector<int> (W));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> G[i][j];
        }
    }
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            int a;
            cin >> a;
            G[i][j] = abs(G[i][j]-a);
        }
    }
    const int zero = 80*160 + 10;
    bitset<zero*2> dp[90][90];
    dp[0][0][zero-G[0][0]] = 1;
    dp[0][0][zero+G[0][0]] = 1;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(i){
                dp[i][j] |= dp[i-1][j] << G[i][j];
                dp[i][j] |= dp[i-1][j] >> G[i][j];
            }
            if(j){
                dp[i][j] |= dp[i][j-1] << G[i][j];
                dp[i][j] |= dp[i][j-1] >> G[i][j];
            }
        }
    }
    int ans = inf;
    for(int i=0; i<zero*2; i++){
        if(dp[H-1][W-1][i]){
            chmin(ans,abs(zero-i));
        }
    }
    cout << ans << enld;
    return 0;
}

Measured memory_bytes: 25728
h,w,a,b=map(int,input().split())

for i in range(b):
    for j in range(a):
        print(1,end='')
    for j in range(w-a):
        print(0,end='')
    print('',sep='\n')
for i in range(h-b):
    for j in range(a):
        print(0,end='')
    for j in range(w-a):
        print(1,end='')
    print('',sep='\n')

Measured memory_bytes: 5360
import java.util.Scanner;

class Main{
	public static void main(String[] args) 	{
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		StringBuffer sb = new StringBuffer(str);
		for(int i = 0 ; i < str.length() ; i++ ) {
			if(Character.isLowerCase(str.charAt(i))) sb.setCharAt(i,Character.toUpperCase(str.charAt(i)));
			else sb.setCharAt(i,Character.toLowerCase(str.charAt(i)));
		}
		System.out.println(sb);
		sc.close();
	}
}


Measured memory_bytes: 26312
#include <bits/stdc++.h>
using namespace std;
    
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, a, b) for (int i = a;i<=b;i++)
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mem(x) memset(x, 0, sizeof(x))
#define ritr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define pai pair < int, int> 
#define pal pair < ll, ll> 
#define vi vector <int> 
#define vl vector < ll > 
#define vpai vector < pii > 

const int mod = 1e9+7;
const int INF = INT_MAX;
const int sze = 3005;

void solve() {
    string str1,str2;
    cin>>str1>>str2;
    int c=0;
    rep(i,str1.length()){
        if(str1[i]!=str2[i]) c++;
    }
    cout<<c<<endl;
}

int main() {
    IOS;

    int t = 1;
    // cin >> t;
    while (t--) {
       solve();
    }

  return 0;
}

Measured memory_bytes: 3804
#include<iostream>
#include<cstdio>

#define rep(i, n, m) for(int i=n;i<m;i++)

using namespace std;

const int num[5] = {5,7,5,7,7};

int main() {
    int n;
    while(scanf("%d", &n) && n){
        int a[n+1];
        rep(i, 0, n){
            string s;
            cin >> s;
            a[i+1] = s.length();
        }

        int ans = -1;
        rep(i, 1, n+1){
            int num_i = 0, cnt = 0;
            rep(j, i, n+1){
                cnt += a[j];
                if(num[num_i] == cnt){
                    num_i++;
                    cnt = 0;
                    if(num_i == 5){
                        ans = i;
                        break;
                    }
                }else if(cnt > num[num_i]){
                    break;
                }
            }
            if(ans != -1) break;
        }

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


Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int main(void) {
	// in
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	for(int i = 0; i < n; ++i) std::cin >> a[i];

	// calc mean
	double mu = 0.0;
	for(int i = 0; i < n; ++i) {
		mu += double(a[i]) / double(n);
	}
	int a_mu = std::floor(mu + 0.5);
	
	// cost
	int cost = 0;
	for(int i = 0; i < n; ++i) {
		cost += (a[i] - a_mu) * (a[i] - a_mu);
	}

	std::cout << cost << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N  int(pow(10.0,6.0))

using namespace std;
int calc(int x){
    return int(x*(x+1)*(x+2)/6);
}


int main(){
    int n;

    int dp[MAX_N];
    int dp_odd[MAX_N];
    int L[200]; //200くらいで正四面体数は10**6を超える
    for(int i=0;i<MAX_N;i++){
        dp[i]=MAX_N;
        dp_odd[i]=MAX_N;
    }
    dp[0]=0;//dp[n]はnを作るのに必要な正四面体数の、最小の個数
    dp_odd[0]=0;//奇数version

    for(int i=0;i<200;i++){
        L[i]=calc(i);
    }

    int new_val;
    for(int x=0;x<MAX_N;x++){
        for(int y=0;y<200;y++){
            new_val= x-L[y];
            if (new_val>=0){
                dp[x] = min(dp[x],dp[new_val]+1);
                if (L[y]%2==1){
                    dp_odd[x] = min(dp_odd[x],dp_odd[new_val]+1); 
                }
            }
        }
    }

    while(true){
        cin >> n;
        if(n==0){
            break;
        }
        printf("%d %d\n",dp[n],dp_odd[n]);
    }
    return 0;
}







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

int a, b, c, d;
std::string s;

int main() {
    std::cin >> s;
    int a = std::stoi(s.substr(0, 1));
    int b = std::stoi(s.substr(1, 1));
    int c = std::stoi(s.substr(2, 1));
    int d = std::stoi(s.substr(3, 1));
    
    for (int i = 0; i <=1; i++) {
        for (int j = 0; j<=1; j++) {
            for (int k = 0; k <= 1; k++) {
                int cb = b;
                int cc = c;
                int cd = d;
                if (i == 1) {
                    cb *= -1;
                }
                if (j == 1) {
                    cc *= -1;
                }
                if (k == 1) {
                    cd *= -1;
                }
                if (a+cb+cc+cd == 7) {
                    std::cout << std::noshowpos << a;
                    std::cout << std::showpos << cb;
                    std::cout << std::showpos << cc;
                    std::cout << std::showpos << cd;
                    std::cout << "=7" << std::endl;
                    return 0;
                }
            }
        }
    }
}


Measured memory_bytes: 256