akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
lint N, M, Q, ans = 0;
lint a[100], b[100], c[100], d[100], A[100];

void dfs(lint num, lint depth){
  if(depth == N){
    lint ans1 = 0;
    for(lint i = 0; i < Q; i++){
      if(A[b[i]] - A[a[i]] == c[i]) ans1 += d[i];
    }
    ans = max(ans, ans1);
    return;
  }
  for(lint i = num; i <= M; i++){
    A[depth] = i, dfs(i, depth + 1);
  }
}

signed main(){
  cin >> N >> M >> Q;
  for(int i = 0; i < Q; i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i]; --a[i]; --b[i];
  }
  dfs(1, 0);
  cout << ans << endl;
}

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

public class Main {
  private static String solve(int d, int n) {
    StringBuffer sb = new StringBuffer();
    if (n == 100) {
      sb.append(n + 1);
    } else {
      sb.append(n);
    }
    for (int i = 0; i < d; i++) {
      sb.append("00");
    }
    return sb.toString();
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int d = reader.nextInt();
    int n = reader.nextInt();
    out.println(solve(d, n));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int main()
{
 int N;
 cin >> N;
 vector<int> a(N);
 for(int i=0;i<N;i++){
     cin >> a.at(i);
 }
 int count,max;
 count =1;
 max = a.at(0);
 for(int j=1;j<N;j++){
     if(a.at(j)>=max){
         count++;
         max = a.at(j);
     }
 }
 cout << count <<endl;
}

Measured memory_bytes: 256
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 0
cur_sum = 0  # 0が入るまでのsum
for i in range(n):
    if a[i] == 0:
        ans += cur_sum // 2
        cur_sum = 0
    else:
        cur_sum += a[i]
ans += cur_sum // 2
print(ans)


Measured memory_bytes: 7072
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int n, k;
    cin >> n >> k;
    int p[n];
    rep(i, n) cin >> p[i];
    double sm[1000];
    sm[0] = 1;
    rep(i, 1000) sm[i+1] = sm[i] + (i + 2);
    // rep(i, n) cout << sm[i] << " ";
    // cout << endl;
    double e[n+1];
    e[0] = 0;
    rep(i, n) e[i+1] = e[i] + sm[p[i]-1] / (double)p[i];
    // rep(i, n + 1) cout << e[i] << " ";
    // cout << endl;
    double ans = 0;
    for (int i = 0; i <= n - k; i++){
        ans = max(ans, e[i+k] - e[i]);
    }
    printf("%.10f\n", ans);
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using P = pair<int,int>;
using Graph =vector<string>;
Graph field;
queue<P> q;

int main() {
  ll ans,d,t,s;
  cin>>ans;
  if(ans==1){
    cout<<0<<endl;
  }else{
    cout<<1<<endl;
  }
}



Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
using namespace std;
int main(){
int a[3];
bitset<11> cards;
while(cin>>a[0]>>a[1]>>a[2]){
cards.reset();
int sum=a[0]+a[1];
int ans=0;
cards[a[0]]=1;
cards[a[1]]=1;
cards[a[2]]=1;
for(int i=1;i<11;i++){
//cout<<cards[i];
if(sum+i<=20&&cards[i]==0){
ans++;
}
}
//cout<<endl;
//cout<<ans<<endl;
if(ans*2>7){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
}

Measured memory_bytes: 1152
def bmi(a):
	return int(a[0]), abs(22-int(a[2])/((int(a[1])/100.0)**2))
	
while 1:
	n=input()
	if n==0:break
	data=[bmi(raw_input().split()) for i in range(n)]
	print sorted(sorted(data),key=lambda x:x[1])[0][0]

Measured memory_bytes: 4512
#include<iostream>
using namespace std;
int main(){
	int x,y,x1y,x2y,x3y,max;
	cin>>x>>y;
	x1y=x+y;
	x2y=x-y;
	x3y=x*y;
	max=x1y;
	if(x2y>max)
		max=x2y;
	if(x3y>max)
		max=x3y;
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100

void swap(int,int);
void sort(int *,int);
int main() {
  int i,n;
  int array[N];
  scanf("%d",&n);
  for (i = 0; i < n; i++) {
    scanf("%d",&array[i]);
  }

  sort(array,n);
  return 0;
}

void sort(int *A,int n){
  int i,j,minj=0,cnt=0,temp;
  for (i = 0; i < n; i++) {
    minj = i;
    for (j = i; j <= n-1; j++) {
      if (A[j] < A[minj]) {
        minj = j;
      }
    }
    if(i!=minj){
    temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;
    cnt++;
    }
  }
  for (i = 0; i < n; i++) {
    if (i > 0)printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d\n",cnt);
}



Measured memory_bytes: 2052
#include<stdio.h>
#include<math.h>

int main(void){
    double x[200000], y[200000], t[200000];
    int i, p=0, n, d;

    scanf("%d%d", &n, &d);
    for(i=0; i<n; i++){
        scanf("%lf%lf", &x[i], &y[i]);
    }
    for(i=0; i<n; i++){
        t[i] = sqrt(x[i]*x[i] + y[i]*y[i]);
        if(t[i] <= d){
            p++;
        }
    }
    printf("%d\n", p);
    return 0;
}

Measured memory_bytes: 5324
//    .------------------------------------------------------------.
//    |   _  __   ___    ___    ___   _  _    ___     _     _  _   |
//    |  | |/ /  / _ \  |   \  |_ _| | \| |  / __|   /_\   | \| |  |
//    |  | ' <  | (_) | | |) |  | |  | .` | | (_ |  / _ \  | .` |  |
//    |  |_|\_\  \___/  |___/  |___| |_|\_|  \___| /_/ \_\ |_|\_|  |
//    |             ___    ___     _     _  _    ___               |
//    |            / _ \  | _ \   /_\   | \| |  / __|              |
//    |           | (_) | |   /  / _ \  | .` | | (_ |              |
//    |            \___/  |_|_\ /_/ \_\ |_|\_|  \___|              |
//    |                 ___   ___    ___    ___                    |
//    |                | _ ) | __|  / __|  / _ \                   |
//    |                | _ \ | _|  | (_ | | (_) |                  |
//    |                |___/ |___|  \___|  \___/                   |
//    |                                                            |
//    |------------------------------------------------------------|
//    |                      .------------.                        |
//    |                      | KerakTelor |                        |
//    |                      |------------|                        |
//    |                      | 2019-10-08 |                        |
//    |                      '------------'                        |
//    '------------------------------------------------------------'

#include <bits/stdc++.h>

#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("tune=native")

#define vec vector
#define prq priority_queue
#define fi first
#define se second

using namespace std;

using ll=long long;
using ld=long double;

//    .-----------------------------------------.
//    |        ___   _   _    ___   ___         | 
//    |       | _ ) | | | |  / __| / __|        | 
//    |       | _ \ | |_| | | (_ | \__ \        | 
//    |       |___/  \___/   \___| |___/        | 
//    |  ___   ___    ___    ___    _  _   ___  | 
//    | | _ ) | __|  / __|  / _ \  | \| | | __| |
//    | | _ \ | _|  | (_ | | (_) | | .` | | _|  | 
//    | |___/ |___|  \___|  \___/  |_|\_| |___| |
//    |                                         | 
//    '-----------------------------------------'

int main()
{
    int n,w;
    scanf("%d%d",&n,&w);
    vec<ll> dp(w+1);
    while(n--)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        for(int i=w;i>=a;--i)
            dp[i]=max(dp[i],dp[i-a]+b);
    }
    printf("%lld\n",dp[w]);
}



Measured memory_bytes: 1024
#! /usr/bin/python3
# 文字列大好きいろはちゃんイージー / Iroha Loves Strings (ABC Edition)

"""
    1≦N,L≦100
    全ての i(1≦i≦N) に対し、Si の長さは L に等しい。
    各 i について, Si は全て半角英小文字のみから成る文字列である。
"""

test_mode = False

N, L = map(int, input().split())
S = []
for i in range(N):
    S.append(input())

if test_mode:
    print(S)
S.sort()
if test_mode:
    print(S)

for i in range(N):
    print(S[i], end='')


Measured memory_bytes: 3060
from fractions import gcd

N = int(input())
AAA = list(map(int, input().split()))

# +1 shifted
dp_l = [0] * (N + 1)
dp_r = [0] * (N + 1)

dp_l[0] = 0
dp_r[0] = 0

for i in range(1, N):
    dp_l[i] = gcd(dp_l[i - 1], AAA[i - 1])
    dp_r[i] = gcd(dp_r[i - 1], AAA[-i])

max_gcd = 0
for i in range(N + 1):
    gcd_cand = gcd(dp_l[i], dp_r[N - i - 1])
    max_gcd = max(gcd_cand, max_gcd)

print(max_gcd)


Measured memory_bytes: 16124
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>
#include<unordered_set>
#include<unordered_map>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

template<typename T>
T modinv(T a, T m) {
	T b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(max(a * c, a * d), max(b * c, b * d)) << endl;

	return 0;
}


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

int main()
{
    ll N, D;
    cin >> N >> D;
    cout << (N + 2 * D) / (2 * D + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;


#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;
using Graph = vector<vector<int>>;

int main() {
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  REP(i,n) cin >> a.at(i);

  ll s1=0;
  ll s2=0;
  for(int i=0; i<n-1;i++){
    for(int j=i+1;j<n;j++){
      if(a[i]>a[j]){
        s1++;
      }else if(a[i]<a[j]){
        s2++;
      }
    }
  }

  ll ans;
  ans = k*(k+1)/2%MOD*s1%MOD+(k-1)*(k)/2%MOD*s2%MOD;
  cout << ans%MOD << endl;

}



  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N; cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    long long sum = 0;
    int minus = 0;
    long long mi = 1LL << 30;
    for(int i = 0; i < N; i++){
        if(A[i] < 0)minus++;
        sum += abs(A[i]);
        mi = min(mi, abs(A[i])); 
    }
    if(minus % 2 ==0)cout << sum << endl;
    else cout << sum - mi * 2 << endl;
}


Measured memory_bytes: 4020
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#define INF 100000000000
#define N 200000
#define ll long long
using namespace std;

int main(){
    int n; cin>>n;
    int data[n];
    ll money=1000;
    ll stock=0;
    for(int i=0; i<n; i++) cin>>data[i];
    
    for(int i=0; i<n-1; i++){
        if(data[i]>data[i+1]){
            money+=data[i]*stock;
            stock=0;
        }
        else{
            ll p=money/data[i];
            stock+=p;
            money-=p*data[i];
        }
    }
    money+=data[n-1]*stock;
    
    cout<<money<<endl;
}

Measured memory_bytes: 3636
n = int(input())
 
testimony = [[] for _ in range(n)]
for i in range(n):
    tmp = int(input())
    for j in range(tmp):
        person, state = map(int, input().split())
        testimony[i].append([person-1, state])
#print(testimony)

from itertools import product
s = [0,1]
ptns = sorted(list(product(s, repeat=n)), reverse=1)
#print(ptns)

for i in range(len(ptns)):
    for j in range(n):
        if ptns[i][j] == 1: 
            for k in testimony[j]:
                if ptns[i][k[0]] != k[1]:
                    break
            else:
                continue
            break
    else:
        print(sum(ptns[i]))
        exit()

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

using namespace std;
vector<int> G[200005];
int seen[200005] = {0};
int ans[200005] = {0};

void dfs(int s) {
    seen[s] = 1;
    for (int i = 0; i < G[s].size(); i++) {
        int n = G[s][i];

        if (seen[n] == 1)
            continue;

        ans[n] += ans[s];
        dfs(n);
    }
}

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

    for (int i = 0; i < n-1; i++) {
        int a, b;   cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    for (int i = 0; i < q; i++) {
        int p, x;   cin >> p >> x;
        ans[p-1] += x;
    }

    dfs(0);

    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";

    cout << endl;

    return 0;
}

Measured memory_bytes: 21120
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename T> ll min(ll a, const T&& b) { return a < b ? a : b; }
template<typename T> ll min(const T&& a, ll b) { return a < b ? a : b; }
template<typename T> ll max(ll a, const T&& b) { return a > b ? a : b; }
template<typename T> ll max(const T&& a, ll b) { return a > b ? a : b; }
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n; cin >> n;
  ll K; cin >> K;
  rep(i, K) {
    ll x, y; cin >> x >> y; --x, --y;
    ll center = (n-1)/2;
    if (x <= center) {
      x = center-x;
    }
    else {
      x = x-center-(n%2==0);
    }
    if (y <= center) {
      y = center-y;
    }
    else {
      y = y-center-(n%2==0);
    }
    // cout << x << " " << y << endl;
    ll d = max(x, y);
    ll pos = (center-d) % 3;
    cout << pos+1 << endl;
  }
}



Measured memory_bytes: 3172
#入力
N = int(input())
X = list(map(int,input().split()))
#座標Pは平均値に近いほど良いので平均値を求める
s = sum(X)
l = len(X)
ave = s/l
#実際にPとしてとれるのは整数の座標。本当の平均値に近い整数値座標をP(ここではavei)とする。
if ave - float(int(ave)) <= 0.5:
  avei = int(s/l)
else:
  avei = int(s/l) + 1
#与えられた式に従って消費体力を求める
ans = 0
for i in range(N):
  ans += (X[i] - avei)**2
#結果
print(ans)

Measured memory_bytes: 3064
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)

	for sc.Scan() {
		n, _ := strconv.Atoi(sc.Text())
		if n == 0 {
			break
		}
		sc.Scan()
		s := strings.Split(sc.Text(), " ")
		score := make([]float64, n)
		for i := range score {
			score[i], _ = strconv.ParseFloat(s[i], 64)
		}
		mu := 0.0
		for _, v := range score {
			mu += v
		}
		mu /= float64(n)
		sigma := 0.0
		for _, v := range score {
			sigma += math.Pow((v - mu), 2)

		}
		sigma /= float64(n)
		fmt.Println(math.Sqrt(sigma))
	}
}



Measured memory_bytes: 1188
#define ll long long int
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define maxx(a,b) std::max(a,b)
#define maxxx(a,b,c) std::max(a,std::max(b,c))
#define minn(a,b) std::min(a,b)
#define minnn(a,b,c) std::min(a,std::min(b,c))

#include <bits/stdc++.h>
using namespace std;
int main()
{
   
   string s,t;
  cin>>s>>t;
  bool flag=true;
  for(int i=0;i<s.size();i++)
  {
  	if(s[i]!=t[i]){flag=false;break;}
  }
  if(flag==false)cout<<"No"<<endl;
  else if(flag==true&&(s.size()+1)==t.size())cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i = a;i<n;i++)

int tenPow(int num){
  int ans =1;
  rep(i,0,num){
    ans*=10;
  }
  return ans;
}
int main(){
    map<int,int> Puzzle;
    int pa = 1234567;
    queue<int> q;
    q.push(pa);
    int BFSnum=q.size();
    int nowpos=0;
    while(!q.empty()){
      if(BFSnum==0){
        BFSnum=q.size();
        nowpos++;
      }
      BFSnum--;
      int num=q.front();
      q.pop();
      if(Puzzle[num]!=0){
        continue;
      }
      else{
        Puzzle[num]=nowpos;
      }
      int zeropos;
      int tmp=num;
      for(int i = 0;true;i++){
        if(tmp%10==0){
          zeropos=i;
          break;
        }
        tmp/=10;
      }
      tmp = num;
      if(!(zeropos==7 || zeropos==3)){
        int swapnum=(tmp/tenPow(zeropos+1))%10;
        swapnum =tmp - swapnum*tenPow(zeropos+1)+swapnum*tenPow(zeropos);
        int pushnum;
        pushnum=swapnum;
        q.push(pushnum);
      }
      if(!(zeropos==4 || zeropos==0)){
        int swapnum=(tmp/tenPow(zeropos-1))%10;
        swapnum =tmp - swapnum*tenPow(zeropos-1)+swapnum*tenPow(zeropos);
        int pushnum;
        pushnum=swapnum;
        q.push(pushnum);
      }
      if(zeropos>=4){
        int swapnum=(tmp/tenPow(zeropos-4))%10;
        swapnum =tmp - swapnum*tenPow(zeropos-4)+swapnum*tenPow(zeropos);
        int pushnum;
        pushnum=swapnum;
        q.push(pushnum);
      }
      if(zeropos<=3){
        int swapnum=(tmp/tenPow(zeropos+4))%10;
        swapnum =tmp - swapnum*tenPow(zeropos+4)+swapnum*tenPow(zeropos);
        int pushnum;
        pushnum=swapnum;
        q.push(pushnum);
      }
    }
    while(true){
      int p=0;
      int cnum;
      string c;
      cin >>c;
      stringstream ss;
      ss << c;
      ss >> cnum;
      rep(j,0,7){
        cnum*=10;
      }
      p+=cnum;
      if(cin.eof())break;
      rep(i,1,8){
        cin >>c;
        stringstream ss;
        ss << c;
        ss >> cnum;
        rep(j,0,7-i){
          cnum*=10;
        }
        p+=cnum;
      }
      if(p == 1234567)cout <<0<<endl;
      else cout <<Puzzle[p]<<endl;
    }
  return 0;
}



Measured memory_bytes: 4088
#!/usr/bin/env ruby

# Tic Tac Toe
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0066

def identity?(a, b, c)
  [a, b, c].uniq.one? && a != 's'
end

while line = gets
  field = line.chomp!.split('')
  winner = nil

  # row
  winner = field[0] if identity?(field[0], field[1], field[2])
  winner = field[3] if identity?(field[3], field[4], field[5])
  winner = field[6] if identity?(field[6], field[7], field[8])

  # column
  winner = field[0] if identity?(field[0], field[3], field[6])
  winner = field[1] if identity?(field[1], field[4], field[7])
  winner = field[2] if identity?(field[2], field[5], field[8])

  # diag
  winner = field[0] if identity?(field[0], field[4], field[8])
  winner = field[2] if identity?(field[2], field[4], field[6])

  puts (winner.nil?) ? 'd' : winner
end

Measured memory_bytes: 6864
#include<bits/stdc++.h>
using namespace std;
const int POW[11]={0,1,2,4,8,16,32,64,128,256,512};
int main()
{
	int n;
	cin>>n;
	int f[101][11]={0};
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<11;j++)
		{
			cin>>f[i][j];
			f[i][0]+=f[i][j]*POW[11-j];
		}
	}
	int p[101][11]={0};
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<11;j++)
		{
			cin>>p[i][j];
		}
	}
	int res=INT_MIN; 
	for(int k=1;k<1024;k++)
	{
		int cres=0;
		for(int i=0;i<n;i++)
		{
			int c=(k&f[i][0]);
			string s="";
			for(int a=c;a;a/=2)
			{
				s+=((a%2)?'1':'0');
			}
			//reverse(s.begin(),s.end());
			int cc=0;
			for(int j=0;j<s.length();j++)
			{
				if(s[j]=='1')
					cc++;
			}
			cres+=p[i][cc];
		}
		res=(cres>res?cres:res);
	}
	cout<<res<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>

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

using namespace std;

int main(void){

    int A,B,C,D;

    cin >> A >> B >> C >> D;

    int sq1 = A*B;
    int sq2 = C*D;

    if(sq1 > sq2){
        cout << sq1 << endl;
    }else if(sq1 < sq2){
        cout << sq2 << endl;
    }else{
        cout << sq1 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
vector<vector<long long>> adjmatr;
const long long MOD = 1e9 + 7;
vector<vector<long long>> mult(vector<vector<long long>> a, vector<vector<long long>> b){
    vector<vector<long long>> c;
    for(long long i=0;i<=52;i++){
        vector<long long> temp;
        for(long long j=0;j<=52;j++){
            temp.push_back(0);
        }
        c.push_back(temp);
      
    }
    for(long long i=1;i<=50;i++){
        for(long long j=1;j<=50;j++){
            for(long long k=1;k<=50;k++){
               // cout<<i<<" "<<j<<" "<<k<<endl;
                c[i][j] = c[i][j] +((a[i][k]*b[k][j])+MOD)%MOD;
                c[i][j]%=MOD;
            }
        }
    }
    return c;
}
vector<vector<long long>> modpow(vector<vector<long long>> c,long long k){
    
    if(k==1){
        return c;
    }
    auto a = modpow(c,k/2);
    auto b = mult(a,a);
    
    if(k%2){
        b = mult(b,c);
    }
    return b;
}
int main(){
    long long n,k;
    cin>>n>>k;
    for(long long i=0;i<=52;i++){
        vector<long long> temp;
        for(long long j=0;j<=52;j++){
            temp.push_back(0);
        }
        adjmatr.push_back(temp);
    }
    for(long long i=1;i<=n;i++){
        for(long long j=1;j<=n;j++){
            cin>>adjmatr[i][j];
        }
    }
    auto ans = modpow(adjmatr,k);
    long long res = 0;
    for(long long i=0;i<=50;i++){
        for(long long j=0;j<=50;j++){
            res+=ans[i][j];
            res%=MOD;
        }
    }
    cout<<res<<endl;
}

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

using namespace std;


int main()
{
	unsigned int r, c;
	unsigned int a[101];
	unsigned int s[101];

	cin >> r >> c;
	for (unsigned int j = 0; j <= c; ++j) {
		s[j] = 0;
	}

	for (unsigned int i = 0; i < r; ++i) {
		a[c] = 0;
		for (unsigned int j = 0; j < c; ++j) {
			cin >> a[j];
			a[c] += a[j];
			s[j] += a[j];
		}
		for (unsigned int j = 0; j < c; ++j) {
			cout << a[j] << " ";
		}
		cout << a[c] << endl;
	}
	for (unsigned int j = 0; j < c; ++j) {
		s[c] += s[j];
		cout << s[j] << " ";
	}
	cout << s[c] << endl;
	return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string S;
    cin >> S;
    vector<int> c;
    bool x = 0;
    for(int i = 0; i < S.length(); i++)
    {
        if(S[i] == 'A' || S[i] == 'G' || S[i] == 'C' || S[i] == 'T')
        {
            x = 1;
        }
    }
    if(!x)
    {
        cout << 0;
        return 0;
    }
    for(int i = 0; i < S.length(); i++)
    {
        int count = 1;
        bool x = 0;
        if(S[i] == 'A' || S[i] == 'G' || S[i] == 'C' || S[i] == 'T')
        {
            x = 1;
            while(S[i + 1] == 'A' || S[i + 1] == 'G' || S[i + 1] == 'C' || S[i + 1] == 'T')
            {
                count++;
                i++;
            }
        }
        if(x)
        {
            c.push_back(count);
        }
    }
    for(int i = 1; i < c.size(); i++)
    {
        if(c[0] < c[i])
        {
            c[0] = c[i];
        }
    }
    cout << c[0];

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  int dx = tx-sx,dy = ty-sy;
  cout<<string(dy,'U')<<string(dx,'R');
  cout<<string(dy,'D')<<string(dx,'L');
  cout<<'L'<<string(dy+1,'U')<<string(dx+1,'R')<<'D';
  cout<<'R'<<string(dy+1,'D')<<string(dx+1,'L')<<'U';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0; i<N; i++)

using namespace std;

int main(){
  int X, A; cin >> X >> A;

  if( X < A){
    cout << 0 << endl;
  }else if( X >= A){
    cout << 10 << endl;
  }
}

Measured memory_bytes: 256
import itertools

N = int(input())

A = []
xy = []
for _ in range(N):
    a = int(input())
    A.append(a)
    for _ in range(a):
        xy.append(list(map(int, input().split())))

ans = 0
for hu in list(itertools.product([0,1], repeat=N)):
    xy_idx = 0
    ok_flg = 1
    for i in range(N):
        if hu[i]:
            for _ in range(A[i]):
                x, y = xy[xy_idx]
                x -= 1
                if hu[x] != y:
                    ok_flg = 0
                    break
                xy_idx += 1
        else:
            xy_idx += A[i]
    if ok_flg:
        ans = max(ans, sum(hu))

print(ans)

Measured memory_bytes: 8948
#include<bits/stdc++.h>
const int maxn=1e5+50;
typedef long long ll;
ll n,m;
ll a[maxn];
ll minn;
using namespace std;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]/=2;
	}
	ll lcm=1;
	for(int i=0;i<n;i++){
		lcm=lcm/__gcd(lcm,(ll)a[i])*a[i];
		if(lcm>m){
			puts("0");
			return 0;
		}
	}
	for(int i=0;i<n;i++){
		if(lcm%(a[i]*2)==0){
			puts("0");
			return 0;
		}
	}
	printf("%lld",m/lcm-m/(2*lcm));
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        String S = scanner.nextLine();

        boolean a = true;
        int c = 0;

        if (S.charAt(0)!='A') {
            a = false;
        }

        if (Character.isUpperCase(S.charAt(1))) {
            a = false;
        }
       
        for (int i = 2;i < S.length()-1;i++){
            if (Character.isUpperCase(S.charAt(i))) {
                if (S.charAt(i)=='C') {
                    c++;
                }else{
                    a = false;
                }
            }
        }

        if (Character.isUpperCase(S.charAt(S.length()-1))) {
            a = false;
        }

        if (a && c == 1) {
            System.out.println("AC");
        }else{
            System.out.println("WA");
        }
    }
}

Measured memory_bytes: 21972
#include <stdio.h>

int main(void)
{
  char s[101];
  int i;
  

  scanf("%s", s);
  
  for( i = 0; s[i] != '\0'; i++ ){
    if( s[i] != 'x' ){
      s[i] = 'x';
    }
   printf("%c", s[i]);
  }

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b, c, n;
string s, t;


int main()
{
	int k, q;
	cin >> n >> k >> q;
	vector<int> A(n), b(q);
	rep(i, q)
	{
		cin >> b.at(i);	
	}
	
	rep(i, q)
	{
		A.at(b.at(i)-1)++;
	}
	
	rep(i, n)
	{
		if (k-(q-A.at(i)) > 0)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
}


Measured memory_bytes: 1408
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    N, M = read_int_list()
    A = read_int_list()
    for i in range(M):
      total = sum(A)
    res = N - total
    if res < 0:
      res = -1
    print(res)


main()


Measured memory_bytes: 10624
s = input()
n = len(s)
a = s[:4]
done = False
if s == s[::-1]:
    if s[:(n - 1) //2] == s[:(n - 1) //2][::-1]:
        if s[(n + 1) // 2:] == s[(n + 1) // 2:][::-1]:
            print('Yes')
            done = True
if not done:
    print('No')

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());

        // 主処理
        long min = a * (n - 1) + b;
        long max = a + b * (n - 1);
        long result;

        if (b < a) {
            result = 0;
        } else if (n == 1) {
            result = a == b ? 1 : 0;
        } else {
            result = max - min + 1; // 重複分の数1を補正
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 25172
#include <iostream>
#include<string>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<map>
using namespace std;

int main() {
	int X, a, b,c;
	cin >> X;
	c = X;
	a = c / 500;
	c = c - 500 * a;
	b = c / 5;
	cout << a * 1000 + b * 5 << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List<int> numsH = new List<int>();
        List<int> numsW = new List<int>();
        
        while (true)
        {
            string[] str =  Console.ReadLine().Split(' ');

            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);

            if (a == 0 && b == 0)
                break;
            else
            {
                numsH.Add(a);
                numsW.Add(b);
            }
        } 

        for (int i = 0; i < numsH.Count;i++)
        {
            for ( int i2 = 0; i2<numsH[i];i2++)
            {
                for (int i3 =0;i3<numsW[i];i3++)
                {
                    Console.Write("#");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 8888
N = gets.to_i
Ls = gets.split.map(&:to_i)

ls = Ls.sort
ans = 0
(2 ... N).each do |a|
  b = a - 1
  c = 0
  while c < b
    if ls[a] >= ls[b] + ls[c]
      c += 1
    else
      ans += b - c
      b -= 1
    end
  end
end
puts ans

Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() { 
  int n;
  cin >> n;
  vl a(n);
  ll sa = 0;
  int isOdd = 0;
  rep(i,n){
    cin >> a[i];
    isOdd|=(a[i]%2);
  }
  if(isOdd)
  cout<<"first"<<endl;
  else cout<<"second"<<endl;

  return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
 
typedef long long ll;
 
 
int main() {
    int n, a, b;
    cin >> n >> a >> b;
 
    ll cur = 0, pre = 0;
    int px = 0;
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
 
        cur = pre + min(1LL * (x - px) * a, ll(b));
        if (i == 0) cur = 0;
        pre = cur;
        px = x;
    }
 
    cout << cur << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        v[i] = {a, b};
    }
    v.emplace_back(INF<int>, 0);
    sort(v.begin(),v.end());
    priority_queue<int> Q;
    int ans = 0;
    int cur = 0;
    for (int i = 1; i <= m; ++i) {
        while(v[cur].first <= i) Q.emplace(v[cur++].second);
        if(!Q.empty()){
            ans += Q.top(); Q.pop();
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1904
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int c=1e5;
const ll mod=1e9+7;
/*bool p[1000];
void sieve(){
p[0]=p[1]=1;
for(int i=2;i<=100;i++){
    for(int j=i*i;j<=100;j+=i){
        p[j]=1;
    }
}
}*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x,y;
    cin>>x>>y;
    char z;
    int dp[x+5][y+5]={};
    dp[0][0]=1;
    for(int i=0;i<x;i++){
        for(int j=0;j<y;j++){
            cin>>z;
            if(z=='#')continue;
            if(i>0){
              dp[i][j]+=dp[i-1][j];
            }
            if(j>0){
              dp[i][j]+=dp[i][j-1];
            }
            dp[i][j]%=mod;
        }
    }
    cout<<dp[x-1][y-1];
    return 0;
}


Measured memory_bytes: 4224
//Copyright(c)2018 Mstdream
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=400010;
vector<int>g[N];
int du[N],n,m,flag=0,q[N],top;
char s[N];
void topsort(){
	for(int i=1;i<=2*n;i++)for(auto x:g[i])du[x]++;
	for(int i=1;i<=2*n;i++)if(!du[i])q[++top]=i;
	while(top){
		int v=q[top--];
		for(auto x:g[v]){
			du[x]--;
			if(!du[x])q[++top]=x;
		}
	}
	for(int i=1;i<=2*n;i++)if(du[i])flag=1;
}
int main(){
	scanf("%d%d%s",&n,&m,s+1);
	for(int i=1,u,v;i<=m;i++){
		scanf("%d%d",&u,&v);
		if(s[u]==s[v])g[u+n].push_back(v),g[v+n].push_back(u);
		else g[u].push_back(v+n),g[v].push_back(u+n);
	}
	topsort();
	puts(flag?"Yes":"No");
}


Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define pll pair<ll,ll> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//g++ code.cpp   ./a.out 

int main() {
   ll n,m; cin >> n >> m;
   vector<pll> p;
   rep(i,n){
      ll a,b; cin >> a >> b;
      p.push_back(make_pair(a,b));
   }
   sort(p.begin(),p.end());
   ll ans=0;
   rep(i,n){
      if(p[i].second<m){
         ans+=p[i].first*p[i].second;
         m-=p[i].second;
      }
      else{
         ans+=p[i].first*m;
         cout << ans << endl;
         return 0;
      }
   }
}



Measured memory_bytes: 2420
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;

int main() {
	ll N = 0;
	cin >> N;
	for (int i = 1; i < 10; i++) {
		if (N % i == 0 && N / i < 10) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

int main(void){
    int n;
    scanf("%d", &n);
    int f[n][10];
    for(int i = 0;i < n;i++){
        for(int j = 0;j < 10;j++){
            scanf("%d", &f[i][j]);
        }
    }
    int p[n][11];
    for(int i = 0;i < n;i++){
        for(int j = 0;j < 11;j++){
            scanf("%d", &p[i][j]);
        }
    }
    int c[n];
    for(int i = 0;i < n;i++){
        c[i] = 0;
    }
    ll psum = -mod-10;
    for(int a1 = 0;a1 < 2;a1++){
    for(int a2 = 0;a2 < 2;a2++){
    for(int a3 = 0;a3 < 2;a3++){
    for(int a4 = 0;a4 < 2;a4++){
    for(int a5 = 0;a5 < 2;a5++){
    for(int a6 = 0;a6 < 2;a6++){
    for(int a7 = 0;a7 < 2;a7++){
    for(int a8 = 0;a8 < 2;a8++){
    for(int a9 = 0;a9 < 2;a9++){
    for(int a0 = 0;a0 < 2;a0++){
        for(int i = 0;i < n;i++){
            c[i] = a1 * f[i][0] + a2 * f[i][1] + a3 * f[i][2] + a4 * f[i][3] + a5 * f[i][4] + a6 * f[i][5] + a7 * f[i][6] + a8 * f[i][7] + a9 * f[i][8] + a0 * f[i][9];
        }
        ll ppp = 0;
        for(int i = 0;i < n;i++){
            ppp += p[i][c[i]];
        }
        if(ppp > psum && (a1!=0||a2!=0||a3!=0||a4!=0||a5!=0||a6!=0||a7!=0||a8!=0||a9!=0||a0!=0))psum = ppp;
        
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    printf("%lld\n", psum);
    return 0;
}

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

using namespace std;

#define pb push_back

typedef long long ll;

ll dist[101][101];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            if(i == j){
                dist[i][j] = 0;
            }
            else{
                dist[i][j] = 10e6;
                dist[j][i] = 10e6;
            }
        }
    }
    int a[m], b[m], c[m];
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i] >> c[i];
        dist[a[i]-1][b[i]-1] = c[i];
        dist[b[i]-1][a[i]-1] = c[i];
    }
    for(int k = 0; k < n; k++)
    {
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n; j++)
            {
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < m; i++){
        if(dist[a[i]-1][b[i]-1] < c[i]){
            ans++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_SIZE 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define SIZE 100

int N,E;
vector<int> G[SIZE];
bool can_visit[SIZE][SIZE];

void bfs(int start_node){

	queue<int> Q;

	for(int i = 0; i < G[start_node].size(); i++){
		can_visit[start_node][G[start_node][i]] = true;
		Q.push(G[start_node][i]);
	}

	while(!Q.empty()){

		for(int i = 0; i < G[Q.front()].size(); i++){
			if(can_visit[start_node][G[Q.front()][i]] == false){
				can_visit[start_node][G[Q.front()][i]] = true;
				Q.push(G[Q.front()][i]);
			}
		}
		Q.pop();
	}
}

int main(){

	scanf("%d %d",&N,&E);

	int from,to;
	for(int loop = 0; loop < E; loop++){
		scanf("%d %d",&from,&to);
		G[from].push_back(to);
	}

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++)can_visit[i][k] = false;
	}

	for(int i = 0; i < N; i++)bfs(i);

	for(int i = 0; i < N-1; i++){
		for(int k = i+1; k < N; k++){
			if(can_visit[i][k] == true && can_visit[k][i] == true){
				printf("1\n");
				return 0;
			}
		}
	}

	printf("0\n");

	return 0;
}

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

#define int long long
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; }

signed main(){
	int n, k;
	cin >> n >> k;
	int p[5010];
	int c[5010];
	for(int i = 0;i < n;i++) cin >> p[i];
	for(int i = 0;i < n;i++) p[i]--;
	for(int i = 0;i < n;i++) cin >> c[i];

	int ans = LLONG_MIN;
	for(int x = 0;x < n;x++){
		int sum = 0;
		int i = x;
		int cnt = 0;
		while(cnt < k){
			sum += c[p[i]];
			chmax(ans, sum);
			i = p[i];
			cnt++;
			if(i == x) break;
		}
		if(cnt == k || sum <= 0) continue;
		int ok = k/cnt;
		if(k % cnt == 0) ok--;
		cnt = ok*cnt;
		sum = sum * ok; 
		chmax(ans, sum);

		while(cnt < k){
			sum += c[p[i]];
			chmax(ans, sum);
			i = p[i];
			cnt++;
		}
	}
	cout << ans << endl;



	return 0;
}


Measured memory_bytes: 3716
N = gets.to_i

def solve(balls)
	[true, false].repeated_permutation(10){|flapper|
		b, c = [], []

		for i in 0...10 do
			flapper[i] ? b << balls[i] : c << balls[i]
		end

		return 'YES' if b == b.sort && c == c.sort
	}
	return 'NO'
end

N.times {
balls = gets.split.map &:to_i
puts solve(balls)
}



Measured memory_bytes: 8068
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        int a[][] = new int[n][m];
        int b[] = new int[m];
        int ans[] = new int[n];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i][j] = Integer.valueOf(sc.next());
            }
        }
        for (int i = 0; i < m; i++) {
            b[i] = sc.nextInt();
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                ans[i] += a[i][j] * b[j];
            }
            System.out.println(ans[i]);
        }
        
    }
}

Measured memory_bytes: 38992
import sys,math
try:sys.stdin,sys.stdout=open('input.txt','r'),open('out.txt','w')
except:pass
from time import clock
a=clock()
from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt,log
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
# print('{:.3f}'.format(1),round(1.123456789,4))
# sys.setrecursionlimit(500000)
def lcm(a,b): return (a*b)//gcd(a,b)
def setbits(n):return bin(n).count('1')
def resetbits(n):return bin(n).count('0')
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r):
    num,den=1,1;r=min(n,n-r)
    for i in range(r):num*=(n-i);den*=(i+1)
    return num//den
def ncr_p(n, r, p):
    num,den=1,1;r=min(r,n-r)
    for i in range(r):num = (num * (n - i)) % p ;den = (den * (i + 1)) % p
    return (num * modinv(den,p)) % p
def isPrime(num) :
    if num<=1:return False
    if num==2 or n==3:return True
    if (num % 2 == 0 or num % 3 == 0) :return False
    m = int(num**0.5)+1
    for i in range(5,m,6):
        if (num % i == 0 or num % (i + 2) == 0) :return False
    return True
def bin_search(s, low, high, val):
    while low <= high:
        mid = low + (high - low) // 2;
        if s[mid] == val:return mid
        elif s[mid] < val:low = mid + 1
        else:high = mid - 1
    return -1
def sumofdigit(num):
    count=0;
    while num : count+=num % 10;num //= 10;
    return count;
def inputmatrix():
    r,c=iia();mat=[0]*r;
    for i in range(r):mat[i]=iia();
    return r,c,mat;
def prefix_sum(n,s):
    for i in range(1,n):s[i]+=s[i-1]
    return s;
def binomial(n, k):
    if 0 <= k <= n:
        ntok = 1;ktok = 1
        for t in range(1, min(k, n - k) + 1):ntok *= n;ktok *= t;n -= 1
        return ntok // ktok
    else:return 0
def divisors(n):
    res = [];
    for i in range(1,ceil(sqrt(n))+1):
        if n%i == 0:
            if i==n//i:res.append(i)
            else:res.append(i);res.append(n//i)
    return res;
# code here---
s=is1()
ans=0
for i in s:
    ans+=int(i)
if ans%9==0:print('Yes')
else:print('No')


Measured memory_bytes: 78936
n = int(input())
high = list(map(int, input().split()))
res = 0
tempres = 0
temp = high[0]
for h in high[1:]:
    if temp >= h:
        tempres += 1
    else:
        res = max(res, tempres)
        tempres = 0
    temp = h
res = max(res, tempres)
print(res)

Measured memory_bytes: 14224
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    A = list(map(int,input().split()))
    B = [0] * n
    x = 0
    for a in A:
        x ^= a
    for i in range(n):
        B[i] = x^A[i]
    print(" ".join(map(str,B)))


if __name__=='__main__':
    main()

Measured memory_bytes: 115776