akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  vector<long> A(N);
  vector<long> B(N);
  rep (i, N) cin >> A[i] >> B[i];

  long ans = 0;
  for (long i = N-1; i >= 0; i--) {
    long tmp = A[i];
    tmp += ans;
    if (tmp % B[i] == 0) continue;
    else ans += B[i] - (tmp % B[i]);
  }

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int s,w;
    cin >> s >> w;
    cout << (w>=s?"unsafe":"safe") << endl;
    return 0;
}

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

int main(void)
{
    using namespace std;
    int H, W;
    int cnt = 0;
    while (true) {
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0) {
            break;
        }
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if ((i + j )% 2 == 0) {
                    printf("#");
                    cnt++;
                } else {
                    printf(".");
                    cnt++;
                }
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
	int n,k;
	cin>>n>>k;
	int a[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n-k;i++){
		if(a[i+k]>a[i]){
			cout<<"Yes";
		}
		else{
			cout<<"No";
		}
		cout<<endl;
	}

	return 0;
}


Measured memory_bytes: 5108
program AGC40
  character(500000)::S
  integer(8),allocatable::A(:)
  read(*,*)S
  N=len_trim(S)+1
  allocate(A(N))
  A=500000
  if(S(1:1)=='<') A(1)=0
  if(S(N-1:N-1)=='>') A(N)=0
  do i=1,N-1
     if(S(i:i)=='>' .and. S(i+1:i+1)=='<') A(i+1)=0
  end do
  do i=1,N-1
     if(S(i:i)=='<') A(i+1)=A(i)+1
  end do
  do i=N,2,-1
     if(S(i-1:i-1)=='>' .and. (A(i-1)==500000 .or. A(i-1)<=A(i))) A(i-1)=A(i)+1        
  end do
  write(*,*)sum(A)
end program AGC40

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

using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long

int32_t  main()
{
    IOS;
    string s;
    cin>>s;
    cout<<s.substr(0,3);
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;


long long digitSum( long long b, long long n )
{
    if( n < b ) return n;
    return digitSum(b, n/b) + n%b;
}


int main()
{
    long long n, s;
    cin >> n >> s;

    long long ans = -1;
    if( n == s ) ans = n+1;
    else{
        // 2 <= b <= sqrt(n) までを探索
        for( long long b = 2; b*b <= n; ++b ){
            if( digitSum(b, n) == s ){
                ans = b;
                break;
            }
        }
        // sqrt(n) < b <= n を全探索
        if( ans == -1 ){
            for( long long p = sqrt(n); p > 0; --p ){
                long long b = (n - s)/(long long)p + 1;
                if( b > p and b > s-p ){
                    if( digitSum(b, n) == s ){
                        ans = b;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>

using namespace std;

const int MD = 1000000007;

int main() {
	long long n, k; cin >> n >> k;
	long long x = n - (k - 1) + 1;
	cout << x * (3 * n * x + 6 * k * n - 3 * n - 6 * k * k + 12 * k - 2 * x * x + 6 * x - 6 * k * x + 2) / 6 % MD << '\n';
	return 0;
}


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

using namespace std;

const int max_n = 1e7 + 5, mod = 998244353;

long long silnia[max_n];

long long pot(int x, int y){
    int wynik = 1;
    while (y){
        if (y % 2)
            wynik = (long long)wynik * x % mod;
        x = (long long) x * x % mod;
        y /= 2;
    }
    return wynik;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    silnia[0] = 1;
    for (int i = 1; i <= n; i++)
        silnia[i] = (long long)silnia[i - 1] * i % mod;
    long long wynik = pot(3, n);
    for (int i = n / 2 + 1; i <= n; i++)
        wynik = (wynik -(pot(2, n - i) * 2 * silnia[n] % mod) * pot(silnia[i] * silnia[n - i] % mod, mod - 2) % mod) % mod;
    if (wynik < 0)
        wynik += mod;
    cout << wynik << "\n";
    return 0;
}

Measured memory_bytes: 81672
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
//typedef pair<int, int> P;
struct P {
	int x, y;
	P(int x, int y):x(x), y(y){}
	P(){}
};


/** Problem1102 : Calculation of Expression **/
typedef complex<long long int> C;
string s;
int pos;
bool overflow;
const int MAX = 10000;

// <expression> := <term> [+ or -] <term> ...
// <term> := <complex> * <complex> ...
// <factor> := (<expression>) | <complex>
// <complex> := <num> + <num> * i

C factor();

void check(C c)
{
	if (abs(c.real())>MAX || abs(c.imag())>MAX)
		overflow = true;
}

C comp()
{
	int c=0;
	
	if (s[pos]=='i') {
		pos++;
		return C(0, 1);
	}
	
	while (isdigit(s[pos])) {
		c*=10;
		c+=s[pos++]-'0';
		check(C(c, 0));
	}
	
	if (s[pos]=='*' && s[pos+1]=='i') {
		pos+=2;
		return C(0, c);
	} else {
		return C(c, 0);
	}
}

C term()
{
	C ret = factor();
	check(ret);
	while (s[pos]=='*') {
		pos++;
		ret *= factor();
		check(ret);
	}
	return ret;
}

C expression()
{
	C ret = term();
	check(ret);
	while (s[pos] == '+' || s[pos] == '-') {
		if (s[pos] == '+') {
			pos++;
			ret += term();
		} else {
			pos++;
			ret -= term();
		}
		check(ret);
	}
	return ret;
}

C factor()
{
	C ret;
	if (s[pos]=='(') {
		pos++;
		ret = expression();
		pos++;
	} else {
		ret = comp();
	}
	
	check(ret);
	return ret;
}

void print(C ret)
{
	if (ret.real()==0 && ret.imag()==0) {
		cout << 0 << endl;
		return;
	}
	
	if (ret.real()!=0)
		cout << ret.real();
	if (ret.imag()>0) {
		if (ret.real()!=0)
			cout << "+";
		cout << ret.imag() << "i";
	} else if (ret.imag()<0)
		cout << ret.imag() << "i";
	cout << endl;
}

int main()
{
	while (cin>>s) {
		pos=0; overflow=false;
		C ret = expression();
		
		if (overflow)
			cout << "overflow" << endl;
		else
			print(ret);
	}
}

Measured memory_bytes: 1204
K, A, B = map(int, input().split())

# 交換する意味がない
if B - A < 2:
    print(1 + K)

else:
    ans = B
    K -= (A + 1)

    ans += (K // 2) * (B - A)
    ans += (K % 2)
    print(ans)


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

int main(){
    int A,B;
    cin >> A >> B;
    if (A==B) {
        cout << "Draw" << endl;
    }else if ((A>B && B!=1) || A==1) {
        cout << "Alice" << endl;
    }else {
        cout << "Bob" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int H = scan.nextInt();
        int W = scan.nextInt();
        int left=0;
        for(int i=0;i<H;++i){
            String s = scan.next();
            int newl=0;
            for(int j=0;j<W;++j){
                if(s.charAt(j)=='#'){
                    newl=j;
                    if(newl < left){
                        System.out.println("Impossible");
                        return;
                    }
                }
            }
            left = newl;
        }
        System.out.println("Possible");
    }
}

Measured memory_bytes: 22736
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;


const int mod=1000000007;
//const int mod=998244353;


int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t,n,m,k,q,x,a,b,c,d,y,l,r;
    cin >> n >> k;
    vi v(n+1);
    ll dp[n+1][k+1];
    memset(dp,0,sizeof(dp));
    for(int i=0; i<=k; i++){
        dp[0][i]=1;
    }
    for(int i=1; i<=n; i++){
        cin >> v[i];
    }
    for(int i=1; i<=n; i++){
        for(int j=0; j<=k; j++){
            if(j<=v[i]){
                dp[i][j]=dp[i-1][j];
                dp[i][j]%=mod;
            }
            else{
                dp[i][j]=dp[i-1][j]-dp[i-1][j-v[i]-1];
                dp[i][j]%=mod;
            }
        }
        for(int j=1; j<=k&&i!=n; j++){
            dp[i][j]+=dp[i][j-1];
            dp[i][j]%=mod;
        }
    }
    cout << (dp[n][k]+mod)%mod << el;
    return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <stack>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int next(int u) {
    for(int v=nt[u]; v<n; v++) {
        nt[u] = v + 1;
        if(M[u][v]) {
            return v;
        }
    }

    return -1;
}

void dfs_visit(int r) {
    for(int i=0; i<n; i++) {
        nt[i] = 0;
    }

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(!S.empty()) {
        int u = S.top();
        int v = next(u);
        if(v!=-1) {
            if(color[v]==WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }
        else {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs() {
    for(int i=0; i<n; i++) {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    for(int u = 0; u<n; u++) {
        if(color[u]==WHITE) {
            dfs_visit(u);
        }
    }
    for(int i=0; i<n; i++) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    int u, k, v;

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

    for(int i=0; i<n; i++) {
        cin >> u >> k;
        u--;
        for(int j=0; j<k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();

    return 0;
}


Measured memory_bytes: 3100
H,W=map(int,input().split())
S=[[-9999 if s == "#" else 0 for s in input()] for _ in range(H)]
for h in range(H):
	for w in range(W):
		if S[h][w] < 0:
			for xh in range(max(0, h-1), min(H, h+2)):
				for xw in range(max(0, w-1), min(W, w+2)):
					if xh != h or xw != w:
						S[xh][xw] += 1
print("\n".join(["".join(["#" if x < 0 else str(x) for x in row]) for row in S]))


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

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

  int N;
  cin >> N;
  vector<int> P(N * N);
  for (int i = 0; i < N * N; i++) {
    cin >> P[i];
    P[i]--;
  }

  vector<vector<int>> dist(N, vector<int>(N, -1));
  vector<vector<int>> state(N, vector<int>(N, -1));
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      dist[i][j] = min({i + 1, j + 1, N - i, N - j});
      state[i][j] = 1;
    }
  }

  vector<int> dx = {1, 0, -1, 0};
  vector<int> dy = {0, 1, 0, -1};

  auto Inside = [&](int x, int y) {
    return 0 <= x && x < N && 0 <= y && y < N;
  };

  int ans = 0;
  for (int i = 0; i < N * N; i++) {
    int x = P[i] / N, y = P[i] % N;
    ans += --dist[x][y];
    state[x][y] = 0;

    deque<pair<pair<int, int>, int>> dq;
    dq.push_back({{x, y}, dist[x][y]});
    while (!dq.empty()) {
      int r = dq.front().first.first;
      int c = dq.front().first.second;
      int dt = dq.front().second;
      dq.pop_front();
      if (dist[r][c] != dt) continue;
      for (int d = 0; d < 4; d++) {
        int nr = r + dx[d];
        int nc = c + dy[d];
        if (!Inside(nr, nc)) continue;
        int w = state[nr][nc];
        if (dist[nr][nc] > dist[r][c] + w) {
          dist[nr][nc] = dist[r][c] + w;
          if (w) {
            dq.push_back({{nr, nc}, dist[nr][nc]});
          } else {
            dq.push_front({{nr, nc}, dist[nr][nc]});
          }
        }
      }
    }
  }

  cout << ans << "\n";
  return 0;
}

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

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

#define     endl               "\n"
#define     fast_io            ios::sync_with_stdio(false); cin.tie(0);
#define     file_io            freopen("input.txt", "r", stdin);   \
                               freopen("output.txt", "w", stdout);
#define     _unique(c)         (c).resize(unique(begin(c), end(c)) - (c).begin());
 
template<typename T, typename TT>
ostream& operator<<(ostream &os, const pair<T, TT> &t) { return os<<"("<<t.first<<", "<<t.second<<")"; }
template<typename T>
ostream& operator<<(ostream& os, const vector<T> &t) { for(auto& i: t) os<<i<<" "; return os; }
 



 
int main(int argc, char** argv) {
    fast_io
#ifdef LOCAL
    file_io
#endif
    
    
    int n;
    cin >> n;
    cout << ((n-1)>>1) << endl;
    


    return 0;
}

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

int main(){
  int X ; 
  cin >> X ; 
  int a , b ;
  cin >> a >> b ;
  int ans = 0 ; 
  
  for(int i = 1 ; i <= X ; i++){
    int j = i ; 
    int cnt = 0 ; 
    for(int k = 0 ; k < 5 ; k++ ){
      cnt += j%10 ; 
      j /= 10 ; 
    }
    
    if( cnt >= a && cnt <= b ){
      ans += i ; 
    }
  }
  
  
 cout << ans << endl ; 
}

Measured memory_bytes: 3608
N = int(input())
x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))
ans = 0
if N == 1:
	print(x_list[0] + y_list[0])
else:
	for i in range(N):
		a = sum(x_list[0:i+1]) + sum(y_list[i:N])
		if ans < a:
			ans = a
	print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <set>
#define MAXV 100000

using namespace std;

vector<int> G[MAXV];
int N;
bool visited[MAXV];
int prenum[MAXV], parent[MAXV], lowest[MAXV], timer;

void dfs(int current, int prev) {
    // Node current ????¨????????????´????????????
    prenum[current] = lowest[current] = timer;
    timer++;

    visited[current] = true;

    int next;

    for (int i = 0; i < G[current].size(); i++) {
        next = G[current][i];
        if (!visited[next]) {
            // Node current ?????? Node next ????¨????????????´????????????
            parent[next] = current;

            dfs(next, current);
            // Node next ?????¢?´¢?????????????????´????????????
            lowest[current] = min(lowest[current], lowest[next]);
        }
        else if(next != prev) {
            // Edge current --> next ??? Back-edge ?????´????????????
            lowest[current] = min(lowest[current], prenum[next]);
        }
    }
}

void art_points() {
    for (int i = 0; i < N; i++) { visited[i] = false; }
    timer = 1;

    // lowest ????¨????
    dfs(0, -1);

    set<int> ap;
    int np = 0;

    for (int i = 1; i < N; i++) {
        int p = parent[i];
        if (p == 0) np++;
        else if (prenum[p] <= lowest[i]) ap.insert(p);
    }
    if (np > 1) ap.insert(0);

    for (set<int>::iterator it = ap.begin(); it != ap.end(); it++) {
        cout << *it << endl;
    }
}

int main() {
    int m;
    cin >> N >> m;

    for (int i = 0; i < m; i++) {
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    art_points();

    return 0;
}

Measured memory_bytes: 6844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "NO";
            if (sS[0][sS[0].Length - 1] == sS[1][0] && sS[1][sS[1].Length - 1] == sS[2][0]) { sOut = "YES"; }

            //出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

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

using namespace std;

int main(){
    int a,b; cin >> a >> b;
    if(a <= 5) {
        cout << 0 << endl;
    } else if (a>=13) {
        cout << b << endl;
    } else {
        cout << b/2 << endl;
    }
}





Measured memory_bytes: 764
N = int(input())
X = str(input())
X10 = int(X,2)

one_num = X.count("1")
X10_pl = X10%(one_num+1)
if one_num>1:
    X10_mi = X10%(one_num-1)
else:
    X10_mi = 0

for i in range(N):
    target = int(X[i])
    
    if target == 0:
        ones = one_num + 1
        plus = pow(2,N-i-1,ones)
        Xnow = (X10_pl + plus)%ones
        
    else:
        if one_num == 1:
            print(0)
            continue
        ones = one_num-1
        plus = -pow(2,N-i-1,ones)
        Xnow = (X10_mi + plus)%ones

    count=1
    
    while Xnow > 0:
        Xnow2 = bin(Xnow)
        ones = Xnow2.count("1")
        Xnow = Xnow%ones
        count+=1
        
    print(count)



Measured memory_bytes: 82280
#coding:utf-8

k = int(input())

now = 1

if(k%2==0)or(k%5==0):
    print("-1")
else:
    past = 0
    for i in range(1,k+1):
        past = (past * 10 + 7) % k
        if past == 0:
            print("{}".format(i))
            break

Measured memory_bytes: 9176
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
const long long mod= 1e9+7;
long long quickpow(long long a, long long b) {
    if (b < 0) return 0;
    long long ret = 1;
    a %= mod;
    while(b) {
        if (b & 1) ret = (ret * a) % mod;
        b >>= 1;
        a = (a * a) % mod;
    }
    return ret;
}
long long inv(long long a) {
    return quickpow(a, mod - 2);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x,y;
    cin>>x>>y;
    if(x>y)
        swap(x,y);
    if((x+y)%3||y>2*x){
        cout<<"0";
        return 0;
    }
    int z=y-x;
    int sum=(y+x)/3;
    int num=(sum+z)/2;
    int num2=sum-num;
    long long ans=1;
    for(int i=sum-num2+1;i<=sum;++i){
        ans*=1ll*i;
        ans%=mod;
    }
    for(int i=2;i<=num2;++i){
        ans*=inv(1ll*i);
        ans%=mod;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin, stdout
from heapq import heappush, heappop
def main():
    RL = stdin.readline
    n = int(RL())
    e = [[] for _ in xrange(n)]
    for _ in xrange(n - 1):
        x, y = map(int, RL().split())
        x -= 1
        y -= 1
        e[x] += [y]
        e[y] += [x]
    m = int(RL())
    f = [None] * n
    q = []
    d = [None] * n
    for _ in xrange(m):
        x, y = map(int, RL().split())
        x -= 1
        f[x] = y
        d[x] = 1
        heappush(q, (y, x))
    while q:
        y, x = heappop(q)
        for z in e[x]:
            if f[z] is None:
                if d[z] is None:
                    f[z] = y + 1
                    d[z] = 1
                    heappush(q, (y + 1, z))
            else:
                if f[z] not in (y + 1, y - 1):
                    print "No"
                    return
                if d[z] is None:
                    d[z] = 1
                    heappush(q, (f[z], z))
    print "Yes"
    stdout.write('\n'.join(map(str, f)))
    print
main()


Measured memory_bytes: 37500
n, m = map(int, input().split())
s_list, c_list = [0] * m, [0] * m
flug = 0
for i in range(m):
  s_list[i], c_list[i] = map(int, input().split())
def hoge(n):
  return len(str(n))
def huga(p, q, r):
  if str(p)[q] == str(r):
    return True
  else:
    return False
if n == 1:
  begin, end = 0, 10
elif n == 2:
  begin, end = 10, 100
else:
  begin, end = 100, 1000
for i in range(begin, end):
  bit = 0
  for j in range(m):
    if hoge(i) != n or huga(i, s_list[j] - 1, c_list[j]) != True:
      bit = 1
  if bit == 0:
    flug = 1
    print(i)
    break
if flug == 0:
  print(-1)

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


void solve(long long A, long long B, long long C){
  long long ab = A*B;
  long long bc = B*C;
  long long ac = A*C;

  if(A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
    cout << 0 << endl;
    return;
  }

  vector<long long> vec({ab, bc, ac});
  cout << *min_element(vec.begin(), vec.end()) << endl;
  return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  long long C;
  scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


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

int main()
{
    int a,p;
    int result = 0;
    
    if(scanf("%d %d", &a, &p) < 2){
        exit(1);
    };
    
    result = (a * 3 + p) / 2;
    
    printf("%d", result);
    
    return 0;
}


Measured memory_bytes: 128
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	int h, w, n;
	cin >> h >> w >> n;
	int m = max(h, w);
	cout << (n + m - 1) / m << endl;
	return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	// debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, left, right)  (a).begin()+(left),(a).begin()+(right)	// left to (right-1)

int main() {
	string s;
	ll k;
	cin >> s >> k;
	int len = s.size();

	int cnt1 = 0;
	string s1 = s;
	int cnt2 = 0;
	string s2 = s;
	int cnt3 = 0;
	string s3 = s;

	FOR(j, 1, len - 1) {
		if (s1[j] == s1[j - 1]) {
			cnt1++;
			s1[j] = '?';
		}
	}

	if (s2[0] == s1[len - 1]) {
		cnt2++;
		s2[0] = '?';
	}
	FOR(j, 1, len - 1) {
		if (s2[j] == s2[j - 1]) {
			cnt2++;
			s2[j] = '?';
		}
	}

	if (s3[0] == s2[len - 1]) {
		cnt3++;
		s3[0] = '?';
	}
	FOR(j, 1, len - 1) {
		if (s3[j] == s3[j - 1]) {
			cnt3++;
			s3[j] = '?';
		}
	}
	
	ll res = cnt1;
	k--;
	ll loop2 = (k + 1) / 2;
	res += loop2 * cnt2;
	ll loop3 = k / 2;
	res += loop3 * cnt3;

	pv(res)

	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int dp[3005][3005];

int main(){
  int n, t;
  cin >> n >> t;
  vector<int> a(n);
  vector<int> b(n);
  vector<P> ab(n);
  rep(i, n){
    cin >> a[i] >> b[i];
    ab[i]=P(a[i], b[i]);
  }
  sort(ab.begin(), ab.end());
  rep(i, n){
    a[i]=ab[i].first;
    b[i]=ab[i].second;
  }
  rep(i, n){
    rep(j, t){
      if(j-a[i]<0){
        dp[i+1][j]=dp[i][j];
      } else {
        dp[i+1][j]=max(dp[i][j], dp[i][j-a[i]]+b[i]);
      }
    }
  }
  int ans=0;
  rep(i, n){
    ans=max(dp[i][t-1]+b[i], ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 38852
package main

import "fmt"

func main() {
	fmt.Scan(&N)
	m := make(map[int]int)
	start(m)
	fmt.Println(solve(m[1], m[2], m[3]))
}

func start(m map[int]int) {
	for i := 0; i < int(N); i++ {
		var a int
		fmt.Scan(&a)
		m[a]++
	}
}

var N float64
var memo [301][301][301]float64

func solve(i, j, k int) float64 {
	f, done := check(i, j, k)
	if done {
		return f
	}
	if i < 0 || j < 0 || k < 0 {
		return 0
	}
	if memo[i][j][k] > 0 {
		return memo[i][j][k]
	}
	ans := resolve(i, j, k)
	return ans
}

func resolve(i int, j int, k int) float64 {
	ans := N
	ans += solve(i-1, j, k) * float64(i)
	ans += solve(i+1, j-1, k) * float64(j)
	ans += solve(i, j+1, k-1) * float64(k)
	ans /= float64(i + j + k)
	memo[i][j][k] = ans
	return ans
}

func check(i int, j int, k int) (float64, bool) {
	if i == 1 && j == 0 && k == 0 {
		return N, true
	}
	return 0, false
}


Measured memory_bytes: 109468
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;
long long int n, k, a[500], b[500], suma = 0, sumb = 0, w;
int main(){
	long long int count = 0;
	cin >> n >> k;
	for(long long int i = 0;i < n;i++){
		cin >> a[i];
		suma += a[i];
	}
	long long int i2;
	long long int s = sqrt(suma);
	for(long long int i = 1;i <= s;i++){
		sumb = 0;
		if((suma % i) == 0){
			i2 = suma / i;
			for(long long int j = 0;j < n;j++){
				b[j] = a[j] % i2;
				sumb += b[j];
			}
			sort(b, b + n);
			w = sumb / i2;
			count = 0;
			for(long long int q = 0;q < w;q++){
				count += (i2 - b[n - q - 1]);
			}
			if(count <= k){
				cout << i2 << endl;
				return 0;
			}
		}
	}
	for(long long int i = s;i > 0;i--){
		sumb = 0;
		if((suma % i) == 0){
			for(long long int j = 0;j < n;j++){
				b[j] = a[j] % i;
				sumb += b[j];
			}
			sort(b, b + n);
			w = sumb / i;
			count = 0;
			for(long long int q = 0;q < w;q++){
				count += (i - b[n - q - 1]);
			}
			if(count <= k){
				cout << i << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
let cs, ps = Array.(make 51 1, make 51 1)
let rec f n k = if k <= 0 then 0 else if n = 0 then 1 else if k <= 1 then 0 else if k >= cs.(n) - 1 then ps.(n) else f (n - 1) (k - 1) + (if k >= cs.(n - 1) + 2 then 1 else 0) + f (n - 1) (k - (cs.(n - 1) + 2))
let _ = for i = 1 to 50 do cs.(i) <- 2 * cs.(i - 1) + 3; ps.(i) <- 2 * ps.(i - 1) + 1 done; Scanf.scanf "%d %d" @@ fun n x -> Printf.printf "%d\n" @@ f n x

Measured memory_bytes: 384
#include<iostream>

int main()
{
	int L;
	while( std::cin >> L, L )
	{
		bool f = false;
		for( int i = 0; i != 12; ++i )
		{
			int M, N;
			std::cin >> M >> N;
			L -= M - N;
			if( L <= 0 && !f )
			{
				std::cout << i + 1 << std::endl;
				f = true;
			}
		}

		if( !f )
			std::cout << "NA" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1160
import sys
import math
import bisect

def main():
    n, m = map(int, input().split())
    if n == 1 or m == 1:
        print(1)
    else:
        ans = ((m + 1) // 2) * ((n + 1) // 2)
        ans += (m // 2) * (n // 2)
        print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main() {
	int N;
	int count = 0;
	cin >> N;
	int* d = new  int[N];
	bool* same = new bool[N];
	for (int i = 0;i < N;i++) {
		cin >> d[i];
		same[i] = false;
	}
	for (int k = 0;k < N;k++) {
		if (same[k] == false) {
			count++;
			for (int j = k + 1;j < N;j++) {
			if (d[k] == d[j])
				same[j] = true;
		}
		}
	}


	cout << count;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string a,b;
    cin>>a>>b;
    ll l=b.size(),x=1,i,s=0;
    for(i=l-2;i>=0;i--)
    {
        x*=10;
        s+=(x*(b[i]-'0'));
    }
    s+=(b[l-1]-'0');
    l=a.size();
    for(i=l-1;i>=0;i--)
    {
        x*=10;
        s+=(x*(a[i]-'0'));
    }
    ll p=sqrt(s);
    if((p*p)==s)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

struct UnionFind{
  vector<int> d;
  UnionFind(int n):d(n,-1){}
  int find(int x){
    if(d[x]<0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x,int  y){
    x = find(x);y = find(y);
    if(x==y) return false;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x,int y) {return find(x) == find(y);}
  int size(int x) {return -d[find(x)];}
};

int main(){
  int n,m;cin >> n >> m;
  vector<P> edge(m);
  rep(i,m){
    int a,b;cin >> a >> b;
    edge[i] = make_pair(a,b);
  }

  vector<ll> ans(m);
  UnionFind unif(100005);

  for(int i = m-1;i >= 0;i--){
    int a = edge[i].first;
    int b = edge[i].second;
    if(unif.find(a) != unif.find(b)){
      ans[i] = unif.size(a)*unif.size(b);
      unif.unite(a,b);
    }
  }

  rep(i,m-1) {
    cout << ans[i] << endl;
    ans[i+1] += ans[i];
  }
  cout << ans[m-1] << endl;



  
  
}

Measured memory_bytes: 5104
import sys

def is_right(edges):
    max_len = max(edges)
    edges.remove(max_len)
    return max_len ** 2 == edges[0] ** 2 + edges[1] ** 2
    
num = int(sys.stdin.readline().strip())

for i in range(num):
    data = sys.stdin.readline().strip().split(' ')
    a = int(data[0])
    b = int(data[1])
    c = int(data[2])
    if is_right([a, b, c]):
        print('YES')
    else:
        print('NO')
        

Measured memory_bytes: 7776
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  ll x;
  ll k;
  ll d;

  cin >> x >> k >> d;

  x = abs(x);

  ll divNum = x / d;

  if (k < divNum) {
    cout << x - (k * d) << endl;
    return 0;
  }

  if (x % d == 0) {
    if ((k - divNum) % 2) {
      cout << d << endl;
      return 0;
    } else {
      cout << 0 << endl;
      return 0;
    }
  } else {
    if ((k - divNum) % 2) {
      cout << abs(x - (divNum * d) - d) << endl;
      return 0;
    } else {
      cout << x - (divNum * d) << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3620
from queue import PriorityQueue
N, M = map(int, input().split())  # N件のアルバイト, M日後までに欲しい

jobs_list = [[] for _ in range(M+1)]

for i in range(N):
    a, b = map(int, input().split())
    if a > M:  # M日後にもらえる仕事ならok
        continue
    jobs_list[a].append(b)

pq = PriorityQueue()

ans = 0

for jobs in jobs_list:
    for job in jobs:
        pq.put(-job)  # min-heapであるから、マイナスにして追加する
    if not pq.empty():  # pqに要素があるなら仕事を一つ行う
        ans += -(pq.get())

print(ans)


Measured memory_bytes: 19348
'use strict';
process.stdin.on('data', function(chunk) {
  var inputs = chunk.toString().trim();
  var S = Number(inputs);
  var h = Math.floor(S / 3600);
//  var m = Math.floor((S - (h * 3600)) / 60);
  var m = Math.floor( S % 3600 / 60);
  var s = S % 60;
  console.log([h,m,s].join(':'));
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15556
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n; cin >> n;
  double t = trunc(sqrt(n));
  cout << fixed << setprecision(0);
  cout << trunc(t * t) << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3748
#include<iostream>
#include<stdio.h>

using namespace std;

typedef struct{
  int x;
  int y;
}Point;

const int MAX = 10;
int data[MAX][MAX];

void make(int in){
  data[in-1][in-1] = in*in;
  if(in == 1) return;
  int write = 0,status = 0,come = 0;
  Point now;
  now.y = now.x = 0;
  while(1){
    write++;
    data[now.y][now.x] = write;
    if(write == in*in-1) return;
    if(now.y == 0 && !come){
      if(now.x == in-1) now.y++;
      else now.x++;
      status = 0;
      come = 1;
      continue;
    }
    if(now.x == 0 && !come){
      if(now.y == in-1) now.x++;
      else now.y++;
      status = 1;
      come = 1;
      continue;
    }
    if(now.x == in-1 && !come){
      now.y++;
      status = 0;
      come = 1;
      continue;
    }
    if(now.y == in-1 && !come){
      now.x++;
      status = 1;
      come = 1;
      continue;
    }

    if(status){
      now.x++;
      now.y--;
    }else{
      now.y++;
      now.x--;
    }
    come = 0;
  }
}

int main(){
  int in,rev = 0;
  while(cin >> in && in){
    make(in);
    rev++;
    cout << "Case " << rev << ":" << endl;
    for(int i = 0; i < in; i++){
      for(int j = 0; j < in; j++){
	printf("%3d",data[i][j]);
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  int x, y; cin >> x >> y;
  int ans = __INT_MAX__;
  if (x <= y)   ans = min(ans, y - x);
  if (-x <= y)  ans = min(ans, y + x + 1);
  if (x <= -y)  ans = min(ans, -y - x + 1);
  if (-x <= -y) ans = min(ans, -y + x + 2);
  outl(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define max(a,b) \
  ({ __typeof__ (a) _a = (a); \
      __typeof__ (b) _b = (b); \
    _a > _b ? _a : _b; })

#define min(a,b) \
  ({ __typeof__ (a) _a = (a); \
      __typeof__ (b) _b = (b); \
    _a < _b ? _a : _b; })

int main(int argc, const char * argv[]) {
    int i = 0;
    int f = 0;
    scanf("%i %i", &i, &f);
    int *h = malloc(sizeof(int) * i);
    int *g = malloc(sizeof(long) * (i + 1));
    for (int j = 0; j < i; j++) {
        scanf("%i", &h[j]);
        g[j] = -1;
    }
    g[0] = 0;
    
    for (int j = 1; j < i; j++) {
        for (int k = 0; k < f; k++) {
            if (j - k - 1 >= 0) {
                if (g[j] == -1) {
                    g[j] = g[j - k - 1] + abs(h[j] - h[j - k - 1]);
                } else {
                    g[j] = min(g[j], g[j - k - 1] + abs(h[j] - h[j - k - 1]));
                }
            }
        }
    }
    printf("%li\n", g[i - 1]);
    
    free(g);
    free(h);
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    string s; cin >> s;
    lint k; cin >> k;
    
    int p = 0;
    char c;
    
    bool allone = true;
    repeat (i, s.length()) {
        if (s[i] != '1') {
            allone = false;
            break;
        }
    }
    if (allone) {
        cout << "1" << endl;
        return 0;
    }
    
    repeat (i, s.length()) {
        if (s[i] == '1') continue;
        else {
            p = i;
            c = s[i];
            break;
        }
    }
    if (p < k) cout << c << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 256
import sys
import math
from fractions import Fraction

a, b, x = map(int, input().split())

y = Fraction(x / (a ** 2))

if y == b:
    print(0)
    sys.exit()

if b - 2 * y > 0:
    a = Fraction(2 * a * y / b)
    teihen = b
else:   
    teihen = 2 * (b - y)
res = Fraction(a / teihen)
print(90 - math.degrees(math.atan(res)))

Measured memory_bytes: 5432
N = int(input())
last = ""
a = set()
for i in range(N):
    if i == 0:
        last = input()
        a.add(last)
        continue
    tmp = input()
    if tmp[0] != last[-1] or tmp in a:
        print("No")
        exit(0)
    a.add(tmp)
    last = tmp
print("Yes")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 1000000007
#define INF -100000000000000
#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
int main()
{
    fast;
    ll int h,m,w;
    cin>>h>>w>>m;
    ll int i,x,y;
    ll int j,val=0,ww;
    ll int mp[h+1]={0};
    ll int mp1[w+1]={0};
    //ll int mpp[h+1][w+1];
   // for(i=0;i<=h;i++)
   // {
     //   for(j=0;j<=w;j++)
     //       mpp[i][j]=0;
    //}
    vector<pair<ll int,ll int>> temp;
    for(i=1;i<=m;i++)
    {
        cin>>x>>y;
        mp[x]++;
        mp1[y]++;
        temp.PB(MP(x,y));
        
    }
    ll int mx=0,val2,val1;
    for(i=1;i<=h;i++)
    {
        mx=max(mp[i],mx);
    }
    val2=mx;
    ll int v[h+1]={0};ll int t1=0,t2=0;
    ll int q[w+1]={0};
    for(i=1;i<=h;i++)
    {
        if(mp[i]==mx)
        {
            v[i]=-1;
            t1++;
        }
    }mx=0;
    for(i=1;i<=w;i++)
    {
        mx=max(mp1[i],mx);
    }val1=mx;
    for(i=1;i<=w;i++)
    {
        if(mp1[i]==mx)
        {
            q[i]=-1;
            t2++;
        }
    }
ll int cnt=0;
    for(i=0;i<m;i++)
    {
        pair<ll int,ll int> p=temp[i];
        if(v[p.F]==-1 && q[p.S]==-1)
            cnt++;
    }
    if(cnt==t1*t2)
    {
        cout<<val1+val2-1;
    }
    else
        cout<<val1+val2<<endl;
   
}


Measured memory_bytes: 17552
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

data_list = [A,B,C,D,E]
last_tmp = 10
last = 0
for data in data_list:
    data_str = str(data)
    if int(data_str[len(data_str)-1]) != 0:
        if last_tmp >= int(data_str[len(data_str)-1]):
            last = data
            last_tmp = int(data_str[len(data_str)-1])

if last != 0:
    data_list.remove(last)
ans = last
for data in data_list:
    ans += data
    data_str = str(data)
    if int(data_str[len(data_str)-1]) != 0:
        ans += 10-int(data_str[len(data_str)-1])

print(ans)

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

int main() {
  int n;
  cin>>n;
  int a[n];
  for (int i=0; i<n; i++) {
    cin>>a[i];
    --a[i];
  }
  set<int> used;
  int cur = 0;
  while (true) {
    if (cur == 1) {
      cout<<used.size()<<endl;
      return 0;
    }
    if (used.find(cur) != used.end()) {
      cout<<-1<<endl;
      return 0;
    }
    used.insert(cur);
    cur = a[cur];
  }
}

Measured memory_bytes: 5376
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		String s = Integer.toString(n);
		
		for(int i = 0; i < s.length(); i++)
		{
			if(s.charAt(i) == '7')
			{
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}

}


Measured memory_bytes: 27032
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
using namespace std;

#define V 10000
#define INF 100000000

typedef pair<int,int> P;

struct edge {
  int to,cap,cost,rev;
  edge(int a,int b,int c,int d){to = a;cap = b,cost = c;rev = d;}
};

int n,m[110],g,a;
int x[110][30],y[110][30],c[110][30];
vector<int> ar[110];
P ans;

vector<edge> G[V];
int h[V];
int dist[V];
int prevv[V], preve[V];

void add_edge(int from,int to,int cap,int cost){
  G[from].push_back(edge(to,cap,cost,G[to].size()));
  G[to].push_back(edge(from,0,-cost,G[from].size() - 1));
}

P min_cost_flow(int s,int t,int f){
  int res = 0;
  fill(h,h+V,0);
  while(f>0){
    priority_queue<P ,vector<P>, greater<P> > q;
    fill(dist,dist+V,INF);
    dist[s] = 0;
    q.push(P(0,s));
    while(!q.empty()){
      P p = q.top(); q.pop();
      int v = p.second;
      if(dist[v] < p.first)continue;
      for(int i=0;i<G[v].size();i++){
	edge &e = G[v][i];
	if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]){
	  dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
	  prevv[e.to] = v;
	  preve[e.to] = i;
	  q.push(P(dist[e.to],e.to));
	}
      }
    }
    if(dist[t] == INF)return P(f,res);

    for(int v=0;v<V;v++)h[v] += dist[v];

    int d = f;
    for(int v=t;v!=s;v = prevv[v]){
      d = min(d,G[prevv[v]][preve[v]].cap);
    }

    f -= d;
    res += d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return P(f,res);
}

int main(){
  while(scanf("%d",&n) != EOF, n){
    m[0] = 1; ar[0].clear(); ar[0].push_back(0);
    x[0][0] = 0; y[0][0] = 0; c[0][0] = 0;
    for(int i=1;i<n;i++){
      scanf("%d",&m[i]);
      ar[i].clear();
      for(int j=0;j<m[i];j++){
	scanf("%d %d %d",&x[i][j],&y[i][j],&c[i][j]);
	ar[i].push_back(y[i][j]);
      }
      sort(ar[i].begin(),ar[i].end());
      ar[i].erase(unique(ar[i].begin(),ar[i].end()),ar[i].end());
    }
    m[n] = 1; ar[n].clear(); ar[n].push_back(INF);
    x[n][0] = INF; y[n][0] = INF; c[n][0] = 0;
    scanf("%d",&g);

    for(int i=0;i<=V;i++)G[i].clear();
    for(int i=0;i<n;i++){
      for(int j=0;j<ar[i].size();j++){
	for(int k=0;k<m[i+1];k++){
	  if(ar[i][j]<=x[i+1][k]){
	    for(int l=0;l<ar[i+1].size();l++){
	      if(y[i+1][k] == ar[i+1][l]){
		a = l;
		break;
	      }
	    }
	    add_edge(i*50 + j*2 + 1, (i+1)*50 + a*2, 1, c[i+1][k]);
	  }
	}
      }
      for(int j=0;j<ar[i+1].size();j++){
	add_edge((i+1)*50 + j*2,(i+1)*50 + j*2 + 1, 1, 0);
      }
    }
    
    ans = min_cost_flow(1,n*50,g);
    cout << g-ans.first << " " << ans.second << endl;
  }
}

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

using namespace std;

bool a[255];
int main()
{
	string c="CODEFESTIVAL2016";
	
	string str;
	cin>>str;
	int l=str.size();
	int ans=0;
	for(int i=0;i<l;i++)
	{
		if(str[i]!=c[i])ans++;
	}
	cout<<ans<<endl;
	return 0;
	
}

Measured memory_bytes: 256
N,M = gets.split.map(&:to_i)
a = Array.new
b = Array.new
for i in 0..M-1
    a[i],b[i] = gets.split.map(&:to_i)
end

for i in 0..N-1
    puts (a.count(i+1)+b.count(i+1))
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<60;

const ll Mod=998244353;


ll modinv(ll a) {
    ll m=Mod;
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(){
  ll i,j;
  ll n;
  cin>>n;
  ll a[n];
  VVI cnt(1000010); 
  VI u(1000010);

  for(i=0;i<n;i++) {
      cin>>a[i];
      cnt[a[i]].pb(i);
      u[1]+=a[i];
      u[1]%=Mod;
  }

  VI mul(1000010,0);

  ll ans=0;

  for(i=1000009;i>=2;i--){
      ll gen=0;
      for(j=1;i*j<1000010;j++){
          for(int l=0;l<cnt[i*j].size();l++){
              mul[i]+=a[cnt[i*j][l]];
              mul[i]%=Mod;
          }
          if(j>=2) gen=(gen+u[i*j])%Mod;
      }
      u[i]=mul[i]*mul[i]%Mod;
      u[i]=(u[i]+Mod-gen)%Mod;
      //if(u[i]>0) cout<<i<<" "<<u[i]<<endl;
  }
  //cout<<u[1]<<endl;
  u[1]=u[1]*u[1]%Mod;
  for(i=2;i<1000010;i++){
      u[1]=u[1]-u[i]+Mod;
      u[1]%=Mod;
  }
  

  for(i=1;i<1000010;i++){
      ans+=u[i]*modinv(i);
      ans%=Mod;
  }
  for(i=0;i<n;i++){
      ans=(ans+Mod-a[i])%Mod;
  }
  ans=ans*modinv(2)%Mod;
  cout<<ans<<endl;

}


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

typedef long long ll;
ll h;
ll ans=0;
ll power=1;

int main(){
	cin>>h;
	
	while(h>=1){
		h/=2;
		ans+=power;
		power*=2;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256