akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

bool warshall_floyd(const int n,
                    vector<vector<int64_t>>& cost,
                    vector<vector<int64_t>>& updated) {
    for (auto i = 0; i < n; i++) cost[i][i] = 0;

    for (auto k = 0; k < n; k++) {
        for (auto i = 0; i < n; i++) {
            for (auto j = 0; j < n; j++) {
                if(i == k or j == k) continue;
                if(cost[i][j] == cost[i][k] + cost[k][j]) {
                    updated[i][j] = (1LL << 60);
                }
                if(cost[i][j] > cost[i][k] + cost[k][j]) {
                    return false;
                }
            }
        }
    }
    return true;
}

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

    vector<vector<int64_t>> a(n, vector<int64_t>(n, (1LL << 60)));
    for (auto i = 0; i < n; i++) {
        for (auto j = 0; j < n; j++) cin >> a[i][j];
    }

    vector<vector<int64_t>> b = a;
    bool flg = warshall_floyd(n, a, b);
    if(not flg) {
        cout << -1 << endl; return 0;
    }

    int64_t ans = 0;
    for (auto i = 0; i < n; i++) {
        for (auto j = 0; j < n; j++) {
            if(j < i and b[i][j] != (1LL << 60)) ans += b[i][j];
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    cin >> n;
    int A[n];
    REP(i,n) cin >> A[i];
    int rui[n+1];
    rui[0] = 0;
    REP(i,n) rui[i+1] = rui[i] + A[i];
    int l,r,mid;
    l = 0;
    mid = 0;
    r = 1;
    int ans = INF;
    int hoge[4];
    while(1){
        mid ++;
        if(mid >= n-2) break;
        while(2 * rui[l+1] < rui[mid + 1]) l ++;
        if(l >= 1 and  rui[l + 1] - (rui[mid + 1] - rui[l+1] ) >= rui[mid+1] - rui[l] - (rui[l])) l --;

        while( 2 * (rui[r+1] - rui[mid+1]) < rui[n] - rui[mid+1]) r ++;
        if(r >= mid + 2 and (rui[r+1] - rui[mid + 1]) - (rui[n] - rui[r+1]) >= (rui[n] - rui[r]) - (rui[r] -rui[mid+1])   ) r--;
        
        hoge[0] = rui[l + 1];
        hoge[1] = rui[mid+1] - rui[l+1];
        hoge[2] = rui[r+1] - rui[mid+1];
        hoge[3] = rui[n] - rui[r+1];
        sort(hoge,hoge+4);
        chmin(ans,hoge[3] - hoge[0]); 
    }
    cout << ans << endl;
}

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

using ll = long long;

const int mod = 1000000007;
const int INF = 1000000000;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    string U;
    cin >> U;
    if (S == U) --A;
    else --B;
    cout << A << " " << B << endl;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

bool flags[300000];
int cnt[300000];
int main()
{
	int N; ll K;
	cin >> N >> K;
	vec(A);
	fx(N) {
		vecp(A);
	}

	int count = 0;
	int start = 1;
	int end = 0;
	while (true) {
		if (flags[start]) {
			break;
		}
		flags[start] = true;
		cnt[start] = count++;
		end = start;
		start = A[start - 1];
	}

	if (K<= cnt[start]) {
		int ans = 1;
		fx (K) {
			ans = A[ans - 1];
		}
		ce(ans)
		return 0;
	}

	int zure = (K - cnt[start]) % (cnt[end] - cnt[start] + 1);
	int ans = start;
	fx(zure) {
		ans = A[ans - 1];
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s, t;
	int c=0;
	cin >> s >> t;
	for(int i=0; i < s.length(); ++i){
		if(s[i] != t[i]){
			c++;	
		}
	}
	cout << c;
}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
int main()
{
    
    int N,K;cin >> N >> K;
    string S; cin >> S;
    S += '.';
    int ans = 0;
    char a = S[0];
    for (int i = 1; i < N+1; i++) if(a != S[i]) a = S[i], ans++;
    if(N-ans+2*K >= N) cout << N-1 << endl;
    else cout << N-ans+2*K << endl;
    
    return 0;
}



Measured memory_bytes: 512
import copy
s = list(input())

anslst = []
lst = copy.deepcopy(s)

for x in lst:
    ss = copy.deepcopy(s)
    n = len(ss)
    cnt = 0
    while True:
        tmp = ss[0]
        flg = 0
        for moji in ss:
            if moji != tmp:
                flg = 1
        if flg == 0:
            anslst.append(cnt)
            break

        for i in range(1, n):
            if ss[i - 1] == x or ss[i] == x:
                ss[i - 1] = x
        ss.pop()
        n = len(ss)
        cnt += 1
print(min(anslst))

Measured memory_bytes: 9256
#include <iostream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long LL;

using namespace std;
using namespace __gnu_pbds;

typedef
tree<
pair<LL,LL>,
    null_type,
    greater<pair<LL,LL> >,
    rb_tree_tag,
    tree_order_statistics_node_update>map_t;

LL point[114514];

int main()
{
    map_t TREE;
    int n,c;
    cin >> n >> c;
    for(int i = 1;i <= n;++i)
        TREE.insert(make_pair(0,-i));
    for(int j = 0;j < c;++j)
    {
        int com;
        cin >> com;
        if(com == 0)
        {
            LL t,p;
            cin >> t >> p;
            TREE.erase(make_pair(point[t-1],-t));
            point[t-1]+=p;
            TREE.insert(make_pair(point[t-1],-t));
        }
        else
        {
            int m;
            cin >> m;
            --m;
            //cout << m << endl;
            cout << -TREE.find_by_order(m)->second << " " << TREE.find_by_order(m)->first << endl;
        }
    }
}

Measured memory_bytes: 10148
N = int(input())

x = []
y = []
h = []

for _ in range(N):
    t_x, t_y, t_h = map(int, input().split())
    x.append(t_x)
    y.append(t_y)
    h.append(t_h)

for i in range(101):
    for j in range(101):

        H = 1
        # 初期化
        for index, t_h in enumerate(h):
            if t_h != 0:
                H = abs(i - x[index]) + abs(j - y[index]) + t_h
                break

        for t_x, t_y, t_h in zip(x, y, h):
            if t_h == 0:
                if H > abs(i - t_x) + abs(j - t_y):
                    break
            elif H != abs(i - t_x) + abs(j - t_y) + t_h:
                break
        else:
            print(i, j, H)
            break

        continue
    else:
        continue

    break


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

int main() {

  int H, W;
  cin >> H >> W;
  
  vector<string> s(H);
  for (int i = 0; i < H; i++) {
    cin >> s[i];
  }

  vector<int> p = {-1, 1};

  int count = 0;

  for (int i = 0; i < H; i++) {

    for (int j = 0; j < W; j++) {

      if (s[i][j] == '#') {
      
        string result = "No";
      
        for (int k = 0; k < 2; k++) {
          if (0 <= j + p[k] && j + p[k] < W) {
            if (s[i][j + p[k]] == '#') {
              result = "Yes";
            }
          }
          if (0 <= i + p[k] && i + p[k] < H) {
            if (s[i + p[k]][j] == '#') {
              result = "Yes";
            }
          }
        }

        if (result == "No") {
          count++;
          break;
        }

      } 

    }

    if (count != 0) {
      break;
    }
    
  } 

  if (count == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format, std.datetime;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long K, T;
    scan(K, T);
    auto A = aryread();
    long ans = 0;
    foreach (i; 0 .. T)
        ans = ans.max(A[i] - 1 - (K - A[i]));
    writeln(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	char a, b;
	cin >> a >> b;
	
	if(a=='H')
	{
		cout << b;
		exit(0);
	}
	else
	{
		if(b=='H')
			cout << 'D';
		else
			cout << 'H';
	}
	
	return 0;
}



Measured memory_bytes: 3596
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	string s, t;
	cin >> n >> s;
	t=s;
	int cnt=0;
	for(int i=0; i<n; i++){
		if(s[i]=='(') cnt++;
		else{
			cnt--;
			if(cnt<0){
				t='('+t;
				cnt++;
			}
		}
	}
	if(cnt>0){
		for(int i=0; i<cnt; i++) t=t+')';
	}else{
		for(int i=0; i<-cnt; i++) t='('+t;
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    s = list(input())
    for t0,t1 in [('S','S'),('S','W'),('W','S'),('W','W')]:
        T = ['S'] * (N + 1)

        T[0] = t0
        T[1] = t1

        for i in range(1,N):
            if s[i] == 'o':
                if T[i] == 'S':
                    T[i+1] = T[i-1]
                else:
                    if T[i-1] == 'W':
                        T[i+1] = 'S'
                    else:
                        T[i+1] = 'W'
            else:
                if T[i] == 'W':
                    T[i+1] = T[i-1]
                else:
                    if T[i-1] == 'W':
                        T[i+1] = 'S'
                    else:
                        T[i+1] = 'W'

        if T[-1] == T[0]:
            if T[0] == 'S':
                if s[0] == 'o' and T[-2] == T[1]:
                    T.pop(-1)
                    print(''.join(T))
                    exit()
                elif s[0] == 'x' and T[-2] != T[1]:
                    T.pop(-1)
                    print(''.join(T))
                    exit()
            else:
                if s[0] == 'x' and T[-2] == T[1]:
                    T.pop(-1)
                    print(''.join(T))
                    exit()
                elif s[0] == 'o' and T[-2] != T[1]:
                    T.pop(-1)
                    print(''.join(T))
                    exit()


    print(-1)



if __name__ == "__main__":
    main()

Measured memory_bytes: 11300
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
 
 
using namespace std;
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("tst.txt", "r", stdin);
	#endif	
}
int tc;
const int N=3e5+5,M=3e5+5,MOD=1e9+7,OO=1e9;

int a,b;
int main()
{	
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	//file();

 	scanf("%d %d",&a,&b);
 	if(a>9 || b>9)printf("-1\n");
 	else	printf("%d\n",a*b );
}



Measured memory_bytes: 256
def main():
    MOD = 10 ** 9 + 7

    s = input()
    n = len(s)

    dp = [[0] * 4 for _ in range(n + 1)]
    dp[0][0] = 1

    for i, c in enumerate(s, start=1):
        for j in range(4):
            dp[i][j] = dp[i - 1][j]
        if c == 'A':
            dp[i][1] += dp[i - 1][0]
        elif c == 'B':
            dp[i][2] += dp[i - 1][1]
        elif c == 'C':
            dp[i][3] += dp[i - 1][2]
        else:
            for j in range(1, 4):
                dp[i][j] += dp[i - 1][j - 1]
            for j in range(4):
                dp[i][j] += dp[i - 1][j] * 2
        for j in range(4):
            dp[i][j] %= MOD

    print(dp[n][3])


if __name__ == '__main__':
    main()


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

char S[100005];
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int N; cin >> N >> S + 1;
	int ans = 0;
	for (int i = 1; i <= N; ++i) {
		if (S[i] != S[i - 1]) ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 384
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  val INF = 1 << 24
  val Array(n, m, r) = in.readLine.split(" ").map(_.toInt)
  val t = in.readLine.split(" ").map(_.toInt - 1)

  val graph = Array.fill(n, n)(INF)
  Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    .foreach { e =>
      val v1 = e(0) - 1
      val v2 = e(1) - 1
      graph(v1)(v2) = e(2)
      graph(v2)(v1) = e(2)
    }

  def warshallFloyd():Unit = {
    for{
      k <- 0 until n
      i <- 0 until n
      j <- 0 until n
    } graph(i)(j) = math.min(graph(i)(j), graph(i)(k) + graph(k)(j))
  }
  warshallFloyd()

  val ans = t.permutations.map {a => a.tail./:(0, a.head) { (acc, i) =>
      val v1 = acc._2
      val v2 = i
      (acc._1 + graph(v1)(v2), v2)
    }._1
  }.min
  // val ans = t.tail./:(0, t.head) { (acc, i) =>
  //   val v1 = acc._2
  //   val v2 = i
  //   (acc._1 + graph(v1)(v2), v2)
  // }._1
  println(ans)
}

Measured memory_bytes: 44848
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k, x;
    cin >> k >> x;
    for(int i = x - k + 1; i < x + k; i++)
    {
        cout << i << ' ';
    }

    return 0;
}


Measured memory_bytes: 256
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
B=Counter(A)
#print(B)      
C=list(B.items())
C.sort(reverse=True)
#print(C)

H=0
W=0
for i in range(len(C)):
    if H==0:
        if C[i][1]>=4:
            print(C[i][0]**2)
            exit()
        elif C[i][1]>=2:
            H=C[i][0]
    else:
        if C[i][1]>=2:
            print(H*C[i][0])
            exit()
print(0)

Measured memory_bytes: 21412
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define Rep(i,x) for(int i=head[x];i+1;i=nxt[i])
#define rep2(i,a,b) for(int i=(a);i<(b);i++)
#define ff first
#define ss second
using namespace std;
const int N=305;
const int M=1e9+7;
typedef long long ll;
inline void read(int &x){x=0; char ch=getchar();while(ch<'0') ch=getchar();while(ch>='0'){x=x*10+ch-48; ch=getchar();}}
//------------------------------------------head---------------------------------------------------//
inline void Upd(int &x,int y){x+=y;x%=M;}
vector<pair<int,int> >vec[333];
int f[2][3][N][N];
inline int chk(int i,int j,int k,int l)
{
	for(int kk=0;kk<vec[i].size();kk++)
	{
		int tt=vec[i][kk].first,d=vec[i][kk].second;
		if((int)(k>=tt)+(int)(l>=tt)+1!=d) return 0;
	}
	return 1;
}
int main()
{
	int n,m;read(n);read(m);
	rep(i,1,m)
	{
		int l,r,k;read(l);read(r);read(k);
		if((r==1)&&(k!=1)) {puts("0");return 0;}
		vec[r].push_back(make_pair(l,k));
	}
	f[1][0][0][0]=f[1][1][0][0]=f[1][2][0][0]=1;
	rep2(i,1,n)
	{
		memset(f[!(i&1)],0,sizeof(f[!(i&1)]));
		rep(j,0,2)rep(k,0,i-1)rep(l,0,i-1)if(f[i&1][j][k][l])
		{	
			int j1=(j==2)?0:(j+1),j2=(!j)?2:(j-1);	
			Upd(f[!(i&1)][j][k][l],f[i&1][j][k][l]);
			Upd(f[!(i&1)][j1][l][i],f[i&1][j][k][l]);
			Upd(f[!(i&1)][j2][i][k],f[i&1][j][k][l]);
		}
		rep(j,0,2)rep(k,0,i)rep(l,0,i)if(!chk(i+1,j,k,l)) f[!(i&1)][j][k][l]=0;
	}
	int ans=0;
	rep(j,0,2)rep(k,0,n-1)rep(l,0,n-1)Upd(ans,f[n&1][j][k][l]);
	printf("%d\n",ans);
	return 0;
}
		

Measured memory_bytes: 2560
#include <iostream>

int linear_search(int A[], int n, int key);

int main()
{
	using namespace std;
	int n, A[10000 + 1], q, key, sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> A[i];
	}
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		cin >> key;
		if (linear_search(A, n, key))
		{
			sum++;
		}
	}
	cout << sum << endl;
}

int linear_search(int A[], int n, int key)
{
	int i = 0;
	A[n] = key;
	while (A[i] != key)
	{
		i++;
	}
	return i != n;
}


Measured memory_bytes: 3112
from collections import Counter
s = list(input())
ans = Counter(s)
flag = False
if 'S' in ans:
    if 'E' in ans:
        if 'N' in ans:
            if 'W' in ans:
                flag = True
    else:
        if 'W' not in ans:
            if 'N' in ans:
                flag = True
else:
    if 'N' not in ans:
        if 'E' in ans:
            if 'W' in ans:
                flag = True
print('Yes' if flag==True else 'No')

Measured memory_bytes: 38256
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

double dp[3005][3005];

int main(int, const char**)
{
    int n;
    cin >> n;
    dp[0][0] = 1;
    rep(i, n)
    {
        double r;
        cin >> r;

        auto c = i + 1;
        auto nr = 1 - r;
        rep(j, c + 1)
        {
            if(j == 0)
            {
                dp[c][j] = dp[c - 1][j] * nr;
                continue;
            }
            dp[c][j] = (dp[c - 1][j] * nr) + dp[c - 1][j - 1] * r;
        }
    }
    double ans = 0;
    rep(i, (n + 1) / 2)
    {
        ans += dp[n][i];
    }
    printf("%.10f\n", 1 - ans);
    return 0;
}


Measured memory_bytes: 49808
let solve h w c =
  let v0 = Array.make w 0 in
  let v1 = Array.make w 0 in
  let r = ref 0 in
  for i = 0 to h - 1 do if c.(i).(0) = 0 then r := 1 done;
  for j = 0 to w - 1 do if c.(0).(j) = 0 then begin v0.(j) <- 1; r := 1 end done;
  for i = 1 to h - 1 do
    if c.(i).(0) = 0 then v1.(0) <- 1;
    for j = 1 to w - 1 do
      if c.(i).(j) = 1 then v1.(j) <- 0
      else begin
        let t = if v0.(j) < v1.(j-1) then v0.(j) else v1.(j-1) in
        v1.(j) <- if v0.(j-1) < t then v0.(j-1) + 1 else t + 1;
        r := if v1.(j) > !r then v1.(j) else !r;
      end
    done;
    Array.iteri (fun i e -> v0.(i) <- e) v1
  done;
  !r * !r

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let read () = List.map int_of_string (split_on_char ' ' (read_line ()))

let () =
  match read () with
  | [h; w] ->
    let c = Array.make_matrix h w 0 in
    for i = 0 to h - 1 do
      let rec doit j = function
        | [] -> ()
        | x::xs ->
          c.(i).(j) <- x;
          doit (j + 1) xs in
      doit 0 (read ())
    done;
    Printf.printf "%d\n" (solve h w c)
  | _ -> ()

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

int main() {
    int n;
    scanf("%d", &n);

    char c[n];
    scanf("%s", c);

    int left[26], right[26];    // 左右それぞれの各文字の個数
    for (int i = 0; i < 26; i++) {
        left[i] = right[i] = 0;
    }

    for (int i = 0; i < n; i++) {
        int index = c[i] - 'a';
        right[index]++;
    }

    int numCommon = 0, ans = 0;
    for (int i = 0; i < n; i++) {   // 切断位置をiとi+1の間とする
        int index = c[i] - 'a';
        right[index]--;
        if (left[index] == 0 && right[index] > 0) { // 左が0→1, 右がk+1→k(k>0)のとき共通の文字が増加
            numCommon++;
            ans = max(ans, numCommon);
        } else if (left[index] > 0 && right[index] == 0) {  // 左がk→k+1(k>0), 右が1→0のとき減少
            numCommon--;
        }
        left[index]++;
    }

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

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<long double> x(n);
    vector<string> u(n);
    long double cnt  = 0;
    rep(i,n)
    {
        cin >> x[i] >> u[i];
        if (u[i] == "JPY")
        {
            cnt += x[i];
        }
        else
        {
            cnt += x[i] * 380000;
        }
    }
    
    cout << cnt  << endl;
    
    return 0;
}

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

namespace AtCoder.Contests.ABC160
{
    /// <summary>
    /// 
    /// </summary>
    static class D
    {
        static void Main(string[] args)
        {
            var n = NextInt();
            var x = NextInt();
            var y = NextInt();

            var result = new int[n];

            for (int i = 1; i < n; i++)
            {
                for (int j = i+1; j <= n; j++)
                {
                    var dist = Math.Min(j - i, Math.Abs(i - x) + Math.Abs(j - y) + 1);
                    result[dist]++;
                }
            }

            for (int k = 1; k < n; k++)
            {
                Console.WriteLine(result[k]);
            }
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


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

int main() {
    int i, l, n, b;
    char a;
    char c[4][15] = {};
    char m[4] = {'S','H','C','D'};

    cin >> n;
    for(i = 0;i < n; i++) {
        cin >> a >> b;
        switch (a) {
            case 'S' : a = 0; break;
            case 'H' : a = 1; break;
            case 'C' : a = 2; break;
            case 'D' : a = 3; break;
        }
        c[a][b] = 'T';
    }
    for(i = 0; i < 4; i++){
        for(l = 1; l <= 13; l++){
            if (c[i][l] != 'T') {
                cout << m[i] << " " << l << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3056
<?php
class Security {
    var $S;
    function __construct() {
        fscanf(STDIN, "%s", $this->S);
    }
    function __invoke() {
        $arrS = str_split($this->S);
        $bool = false;
        for ($i = 0; $i < count($arrS) - 1; $i++) {
            if ($arrS[$i] === $arrS[$i + 1]) {
                $bool = true;
            }
        }
        return $bool ? "Bad" : "Good";
    }
}
$Security = new Security();
echo $Security();


Measured memory_bytes: 4604
if __name__ == "__main__":
    A, B, C = map(int, input().split())
    
    max_v = max(A, B, C)
    min_v = min(A, B, C)
    
    num_list = [A, B, C]
    num_list.remove(max_v)
    if len(num_list) == 2:
        num_list.remove(min_v)
        if len(num_list) == 1:
            mid_v = num_list[0]
        else:
            mid_v = min_v
    else:
        mid_v = max_v
    
    ans = 0
    while True:
        if mid_v < max_v:
            ans += max_v - mid_v
            min_v += max_v - mid_v
            mid_v = max_v
            #print("aaa", min_v, mid_v, max_v)
        else:#mid_v = max_v
            if min_v < max_v:
                if (max_v - min_v) % 2 == 0:
                    #min_v = max_v
                    ans += (max_v - min_v) / 2
                    #print("bbb", min_v, mid_v, max_v)
                    break
                else:
                    #min_v = max_v
                    #max_v += 1
                    #mid_v += 1
                    ans += (max_v + 1 - min_v) / 2
                    ans += 1
                    #print("ccc", min_v, mid_v, max_v)
                    break
            else:
                break
    
    print(int(ans))

Measured memory_bytes: 3064
#include <stdio.h>

long long sum = 0;

int main()
{

    int n;
    scanf("%d",&n);
    for(int i = 1; i<=n; i++){
        if(i % 3 == 0 || i % 5 == 0)
            continue;
        else
            sum += i;
    }
    printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 1728
n = int(raw_input())

d = [0 for i in range(n)]
f = [0 for i in range(n)]
a = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
time = [0]
G = [0 for i in range(n)]


def dfs_visit(s):
    st[s] = 1
    time[0] += 1
    d[s] = time[0]
    
    for k in range(n):  
      if a[s][k] == 1 and st[k] == 0:
          dfs_visit(k)
    st[s] ==2
    time[0] += 1
    f[s] = time[0]

def main():
    for s in range(n):
        if st[s] == 0:
            dfs_visit(s)
    for s in range(n):
        print'{0} {1} {2}'.format(s+1, d[s], f[s])

for i in range(n):
    G = map(int, raw_input().split())
    for j in range(G[1]):
        a[G[0]-1][G[2+j]-1] = 1

main()
   


       

Measured memory_bytes: 6412
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int m = scan.nextInt();
		int q = scan.nextInt();
		int[] a = new int[q];
		int[] b = new int[q];
		int[] c = new int[q];
		int[] d = new int[q];
		for(int i = 0; i < q; i++) {
			a[i] = scan.nextInt();
			b[i] = scan.nextInt();
			c[i] = scan.nextInt();
			d[i] = scan.nextInt();
		}
		scan.close();
		
		System.out.println(dfs(a,b,c,d,new int[n],m,0,0));
	}
	
	public static int dfs(int[] a, int[] b, int[] c, int[] d, int[] num, int m, int i, int prev) {
		if(i == num.length) {
			return Ans(a,b,c,d,num);
		}
		
		int[] candidate = new int[m-prev+1];
		for(int j = 0; j < m-prev; j++) {
			num[i] = prev+j;
			candidate[j] = dfs(a,b,c,d,num,m,i+1,prev+j);
		}
		
		return max(candidate);
	}
	

	
	public static int Ans(int[] a, int[] b, int[] c, int[] d, int[] num) {
		int ans = 0;
		for(int i = 0; i < a.length; i++) {
			if(num[b[i]-1] - num[a[i]-1] == c[i]) {
				ans += d[i];
			}
		}
		return ans;
	}
	
	public static int max(int[] candidate) {
		int max = candidate[0];
		for(int i = 1; i < candidate.length; i++) {
			if(candidate[i] > max) max = candidate[i];
		}
		return max;
	}
}


Measured memory_bytes: 41084
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var n,m int
    fmt.Scan(&n,&m)
    ans := make([]int, n)
    a := make([]int, n)
    b := make([]int, n)
    c := make([]int, m)
    d := make([]int, m)
    for i:=0;i<n;i++{
        fmt.Scan(&a[i],&b[i])
    }
    for i:=0;i<m;i++{
        fmt.Scan(&c[i],&d[i])
    }
    for i:=0;i<n;i++{
        ma := 1000000000
        for j:=0;j<m;j++{
            if abs32(a[i]-c[j])+abs32(b[i]-d[j])<ma{
                ma = abs32(a[i]-c[j])+abs32(b[i]-d[j])
                ans[i] = j+1
            }
        }
    }
    for i:=0;i<n;i++{
        fmt.Println(ans[i])
    }
}





// Pairsort
type Pair struct {
    first,second int64
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end



func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func makeTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func sortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}

func reverseString(s string) string{
    t := []rune(s)
    for i,j := 0, len(s)-1 ; i < j ; i, j = i+1, j-1 {
        t[i], t[j] = t[j], t[i]
    }
    return string(t)
}

func inside(h,w,H,W int) bool{
    if h>=0 && h<H && w>=0 && w<W{
        return true
    }
    return false
}


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

int main() {
    int N;
    cin >> N;
    ll cnt = 0;
    ll res = 0;
    ll min_num = INF;
    ll sum = 0;
    rep(i, N) {
        ll a;
        cin >> a;
        if (a < 0) {
            cnt++;
        }

        min_num = min(min_num, abs(a));
        sum += abs(a);
    }

    if (cnt % 2 == 0)
        res = sum;
    else {
        res = sum - 2 * min_num;
    }

    cout << res << endl;
}

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

from collections import deque

N = int(input())
A = [deque(map(int, input().split())) for _ in range(N)]
q = []
def check(x):
    if len(A[x]) == 0: return
    tmp = A[x][0]-1
    if A[tmp][0]-1 == x:
        if tmp < x: x,tmp=tmp,x
        q.append((x,tmp))
        return

for i in range(N):
    check(i)
day = 0
while len(q) > 0:
    day+=1
    q = list(set(q))
    prevQ=[]
    prevQ,q=q,prevQ
    for i in range(len(prevQ)):
        x,y=prevQ[i]
        A[x].popleft()
        A[y].popleft()
    for i in range(len(prevQ)):
        x,y=prevQ[i]
        check(x)
        check(y)
    
for i in range(N):
    if len(A[i]) != 0:
        print(-1)
        sys.exit()
print(day)


Measured memory_bytes: 36168
#include <iostream>
#include <vector>
#include <algorithm>

struct VectorItem
{
  uint64_t value, count;
  VectorItem(uint64_t value, uint64_t count) 
    : value(value), count(count) {}
  bool operator<(const VectorItem &item) const
    { return value < item.value; }
};

int main()
{
  uint64_t N, K;
  std::cin >> N >> K;
  --K;
  
  std::vector<VectorItem> array;
  
  for (uint64_t n = 0; n < N; ++n) {
    uint64_t a, b;
    std::cin >> a >> b;
    
    array.emplace_back(a, b);
  }
  
  std::sort(array.begin(), array.end());
  
  uint64_t k = 0, ans = array[N - 1].value;
  for (uint64_t n = 0; n < N; ++n) {
    if (k <= K && K < k + array[n].count) {
      ans = array[n].value;
    }
    k += array[n].count;
  }
  std::cout << ans << std::endl;
  
  return 0;
}

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

using namespace std;

static const  unsigned long long MOD = 1000000007LL;
string S;

int main() {
	unsigned long long dp[13] = { 0 }, dp_next[13];

	dp[0] = 1;
	cin >> S;

	for (const char& s : S) {
		for (int i = 0; i < 13; i++) dp_next[i] = 0;

		if (s == '?') {
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 13; j++) {
					dp_next[((j * 10 + i) % 13)] += dp[j];
				}
			}
		}
		else {
			for (int i = 0; i < 13; i++) {
				dp_next[(i * 10 + s-'0') % 13] += dp[i];
			}
		}

		for (int i = 0; i < 13; i++) {
			dp[i] = dp_next[i] % MOD;
		}
	}

	cout << dp[5] << endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ara(A,N) sort(A,A+N)
#define rev(A,N) sort(A,A+N,greater<long long>())
using namespace std;
int main()
{   speed_up;
    ll mod = 1e9 + 7;
    //cout<<mod<<endl;
    ll power = 1;
    ll n;
    cin>>n;
    for(int i = 1; i<=n; i++)
    {
        power = (power*i)%mod;
    }
    cout<<power<<endl;

    return 0;

}







Measured memory_bytes: 3600
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

func nextInt() uint64 {
	sc.Scan()
	i, e := strconv.ParseUint(sc.Text(),10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n := nextInt()
	a := make([]uint64, n, n)
	var ans uint64 = 1

	for i := range a {
		a[i] = nextInt()
		if a[i] == 0 {
			fmt.Println(0)
			return
		}
	}

	for i := range a {
		if uint64(math.Pow(10, 18.0)) / ans < a[i] {
			fmt.Println(-1)
			return
		}
		ans *= a[i]
	}

	fmt.Println(ans)
	return
}


Measured memory_bytes: 6144
N,M=map(int,input().split())
edges = [input().split() for x in range(M)]
path = []
for i in range(M):
  if '1' == edges[i][0]:
    path.append('1' + edges[i][1])

while 0 < len(path):
  if len(path[0]) == N:
    break 
  work = path.pop(0)
  for j in range(M):
    if (work[-1] == edges[j][0]) and edges[j][1] not in work:
      path.append(work + edges[j][1])
    elif (work[-1] == edges[j][1]) and edges[j][0] not in work:
      path.append(work + edges[j][0])

print(len(path))

Measured memory_bytes: 3316
A = [list(map(int, input().split())) for i in range(3)]

for i in range(int(input())):
    b = int(input())
    for j in range(3):
        if b in A[j]: A[j][A[j].index(b)] = -1

ans = False
for k in range(2):
    for i in range(3):
        c = 0
        for j in range(3):
            if k == 0: 
                if A[i][j] == -1: c += 1
            else:
                if A[j][i] == -1: c += 1
        if c == 3: ans = True
c = 0
for i in range(3):
    if A[i][i] == -1: c += 1
if c == 3: ans = True

c = 0
for i in range(3):
    if A[i][2-i] == -1: c += 1
if c == 3: ans = True

if ans: print('Yes')
else: print('No')

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

int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  if(s.size() <= k) cout << s << endl;
  else cout << s.substr(0,k) << "..." << endl;
  return 0;
}


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

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
            cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
            const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

#define ll long long int
int arr[200][200];

int colour[100005];

int main() {
    int n,m;
    int  sz;
    cin >> n >> m;
    cin >> sz;
    for (int i = 1; i <= sz; i++) {
        cin >> colour[i];
    }
    int row = 1,col = 1;
    for (int i = 1; i <= sz; i++) {
        int lim = colour[i];
        while (lim--) {
            if (row <= n && col <= m) {
                arr[row][col] = i;
            }
            if (col + 1 <= m && !arr[row][col+1]) {
                col++;
            }else if (col-1 >= 1 && !arr[row][col-1]) {
                col--;
            }else {
                row++;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cout << arr[i][j] <<" ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
vector<int> dp(100000,-1);
int back(vector<int> & heights, int index){
    if(index>heights.size()) return INT_MAX;
    if(dp[index]!=-1) return dp[index];
    
    int step1=INT_MAX,step2=INT_MAX;
    
    if(index+1<heights.size()) step1= abs(heights[index+1]-heights[index])+back(heights,index+1);
    if(index+2<heights.size()) step2= abs(heights[index+2]-heights[index])+back(heights,index+2);
       dp[index]= min(step1,step2);
        return dp[index];
    
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<int> heights(n);
	for(int i=0;i<n;i++) cin>>heights[i];
	dp[heights.size()-1]=0;
	int ans= back(heights,0);
	cout<< ans<<endl;
	return 0;
}

Measured memory_bytes: 5760
n = int(input())
s,d = map(int,input().split())

c = 0
for i in range(s,d+1):
  if i % n == 0:
  	c = c + 1
  else:
    c = c
    
if c != 0:
 	print("OK")
else:
  	print("NG")

Measured memory_bytes: 9092
import java.util.Scanner;
public class Main {
    public static void main(String[] defargs) {
        Scanner scanner = new Scanner(System.in);
        int H,W,i,j;
        while(true){
           H = scanner.nextInt();
           W = scanner.nextInt();
           if ( H == 0 && W == 0 ){
               break;
            }
           for ( i = 1; i <= H; i++ ){
             for ( j = 1; j <= W; j++ ){
                if( i==1 || i==H || j==1|| j==W ){
                    System.out.print("#");
                } else {
                    System.out.print(".");
                }
              }
            System.out.println();
            }
           
            System.out.println();
        }    
    }
}


Measured memory_bytes: 32508
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main() {
  ll r, D, x;
  cin >> r >> D >> x;
  for(int i = 0; i < 10; i++) {
    x = r * x - D;
    cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
string s,t;
int len,p;

void rec(){
  int cnt=0;
  while(p<len&&s[p]!=']'){
    if(s[p]=='+'){
      cnt++;
    }else if(s[p]=='-'){
      cnt+=25;
    }else if(s[p]=='['){
      p++;
      int l=t.size();
      rec();
      int r=t.size()-1;
      while(l<r){swap(t[l],t[r]);l++;r--;}
    }else if(s[p]=='?'){
      t.push_back('A');
      cnt=0;
    }else{
      int ch=(s[p]-'A'+cnt)%26;
      t.push_back((char)(ch+'A'));
      cnt=0;
    }
    p++;
  }
}

int main(){
  while(1){
    cin>>s;
    if(s==".")break;
    t="";
    p=0;
    len=s.size();
    rec();
    cout<<t<<endl;
  }
  return 0;
}

Measured memory_bytes: 1188
import collections
from functools import lru_cache
import bisect

INF = float("inf")
ZERO = 0
ONE = 1


def read():
    return input().strip()


def readInt():
    return int(input().strip())


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


def solve(N, arr):
    ans = 0
    MOD = 10**9 + 7
    totalSum = sum(arr) % MOD
    currSum = 0

    for num in arr:
        currSum += num
        ans = (ans + num * (totalSum - currSum)) % MOD

    return ans % MOD


N = readInt()
arr = readList()

print(solve(N, arr))


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




int main(){
	int N,M;
	cin>>N>>M;
	map<long long,long long> mp;
	for(int i=0;i<N;i++){
		long long a;
		cin>>a;
		mp[a]++;
	}
	
	for(int i=0;i<M;i++){
		long long a,b;
		cin>>a>>b;
		mp[b]+=a;
	}
	
	long long ans = 0;
	 std::map<long long,long long>::reverse_iterator i = mp.rbegin();
	for(true;true;++i){
		if(i->second<=N){
			ans+=i->second*i->first;
			N-=i->second;
			
		}
		else{
			ans+=N*i->first;
			break;
		}
	}
	cout<<ans<<endl;
		
	
	
	
	return 0;
}

Measured memory_bytes: 12800
import java.util.*;
class Main {


public static void main(String[] args) {
  Scanner reader =new Scanner (System.in);
  String a=reader.nextLine();
  String b=reader.nextLine();

  if(a.length()+1==b.length()&&a.equals(b.substring(0,b.length()-1)))
  {
    System.out.println("Yes");
  }
  else
  {System.out.println("No");
}
}}

Measured memory_bytes: 35732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  ll n;
  cin >> n;
  ll k;
  cin >> k;
  ll arr[n];
  for(ll i=0;i<n;i++)
    cin >> arr[i];
  sort(arr,arr+n);
  ll ans=0;
  for(ll i=n-1;i>=n-k;i--)
  {
    ans+=arr[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=2e5+10;
map <ll ,ll>m;
ll f(ll x) {
    if(x==0) return 0;
    return 2*f(x/2)+1;
}
int main() {
   // freopen("test.txt","r",stdin);
    ll h;
    cin>>h;
    cout<<f(h)<<endl;
    return 0;
}

/*
1.变量范围经常搞错，也就是临界情况不清晰
  1.1 加上一点，诸如下标从0~n-1的情况，对于某个其中的值，经常搞错个数和下标
2.经常性读错题目，尤其是看英文题面的情况下
3.结合上一点，如果是英文题面，一定要英文，只准翻译单个单词，逼着自己看英文题面
4.for循环中的i爆LL可能很难注意到
5.千万不要忽视轻视简单的问题
*/





Measured memory_bytes: 256
N, M = map(int, input().split())
L = []
for i in range(N):
  L.append(list(map(int, input().split())))

S = [0]*M

for j in range (N):
  for k in range(1, L[j][0]+1):
    S[L[j][k]-1] += 1
    
print(S.count(N))

Measured memory_bytes: 3060
import java.util.*;

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

    char[][] mozi = new char[1][6];

    for(int i = 0;i<1;i++){
      mozi[i] = scan.next().toCharArray();
    }
    int x = 0;
    if(mozi[0][2] == mozi[0][3]){
      if(mozi[0][4] == mozi[0][5]){
        x = 1;
      }
    }
    if(x == 1){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 21844
#include<cstdio>
#include<cctype>
int main(){
    char ch;
    while(1){
        scanf("%c", &ch);
        
        if(islower(ch)){
            printf("%c",toupper(ch));
            
        }else if(isupper(ch)){
            printf("%c",tolower(ch));
       
        }else{
            printf("%c",ch );
        }
        if(ch == '\n')break;
    }return 0;
    
}


Measured memory_bytes: 2528