akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    int n,m,k;
    cin>>n>>m>>k;
    vector<vector<int>> G1(n),G2(n);
    UnionFind uf(n);

    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        G1[a].push_back(b);
        G1[b].push_back(a);
        uf.merge(a,b);
    }

    rep(i,k){
        int c,d;
        cin>>c>>d;
        c--,d--;
        G2[c].push_back(d);
        G2[d].push_back(c);
    }

    rep(i,n){
        int ans=uf.size(i);
        ans--;
        ans-=G1[i].size();
        rep(j,G2[i].size()){
            if(uf.issame(i,G2[i][j])) ans--;
        }
        cout<<ans<<" ";
    }
    cout<<endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    A.at(0) = 0;
    for (int i=1; i<N; i++) cin >> A.at(i);
    vector<int> B(N);
    for (int i=0; i<N; i++) B.at(i) = 0;
    for (int i=1; i<N; i++) {
        B.at(A.at(i)-1)++;
    }
    for (int i=0; i<N; i++) cout <<B.at(i) << "\n";
}

Measured memory_bytes: 4792
function Main(input) {
    var result = 0;

    if (input.match("RRR")) {
        result = 3;
        
    } else if (input.match("RR")) {
        result = 2;
    } else if (input.match("R")) {
        result = 1;
    } else {
        result = 0;
    }
    console.log(result);
    
    
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29688
r=0
while r==0:
        L=""
        l="#"
        i=map(int,raw_input().split())
        if i[0]==i[1]==0:
                break
        a=i[1]
        b=i[1]-2
        c=i[0]-2
        while 0 < a:
                L=L+"#"
                a=a-1
        while 0 < b:
                l=l+"."
                b=b-1
        l=l+"#"
        print L
        while 0 < c:
                print l
                c=c-1
        print L
        print

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

int main(){
	ll H;
	cin >> H;
	ll ans = 0;
	ll Nm = 1;
	while (H>1) {
		ans += Nm;
		H /= 2;
		Nm *= 2;
	}
	ans += Nm;
	cout << ans << endl;

	return 0;
}


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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int n, k, m;
    while (cin >> n >> k >> m, n|k|m) {
        vi stones(n);
        REP(i, n) {
            stones[i] = i+1;
        }
        int idx = m-1;
        stones.erase(stones.begin()+idx);
        REP(i, n-1) {
            idx = (idx + k-1) % stones.size();
            stones.erase(stones.begin()+idx);
        }
        cout << stones[0] << endl;
    }
}

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <queue>
#include <cassert>
#include <set>
using namespace std; typedef long long ll; const int MINF=-1e9; typedef pair<int,int> P;

int main() {
  int n; cin>>n;
  string s[n]; for(int i=0;i<n;i++) cin>>s[i];
  int an=0; int u[3]={0,0,0}; // xA, BA, Bx
  for(int i=0;i<n;i++) {
    for(int j=0;j<s[i].size()-1;j++) {
      if (s[i][j]=='A'&&s[i][j+1]=='B') an++;
    }
    if (s[i].back()=='A') {
      if (s[i].front()=='B') u[1]++;
      else u[0]++;
    } else if (s[i].front()=='B') u[2]++;
  }
  if (u[1]>0){
    an+=u[1]-1; u[1]=0;
    if (u[0]>0) an++, u[0]--;
    if (u[2]>0) an++, u[2]--;
  }
  an+=min(u[0],u[2]);
  cout<<an<<endl;
}

Measured memory_bytes: 768
import Data.List
main=do
    s<-getLine
    print $ sum $ f 0 s
f n s
    | null s = []
    | null ss = []
    | null sss = []
    | otherwise =  ((n+ns) * length ws) : f (n+ns) r
    where
    ss = dropWhile (=='W') s
    (bs,sss) = span (=='B') ss
    (ws,r) = span (=='W') sss
    ns = length bs

Measured memory_bytes: 13820
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)

def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, M, X = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=10**7
    for i in range(2**12):
        count=0
        und=[0]*M
        for n in range(N):
            if i >>n &1:
                s=S[n]
                count+=s[0]
                for j in range(M):
                    und[j]+=s[j+1]
        flag=True
        for j in range(M):
            if und[j]<X: 
                flag=False
                break
        if flag:
            ans=min(ans,count)
            
    if ans ==10**7:
        print(-1)
    else:
        print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 69592
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
ll mod = 1000000007;
vector<ll> dp(2005);

ll sumdp(int p)
{   
    ll sum=0;
    for(int i=0;i<p;i++)
    {
        sum += dp[i];
        sum = sum%mod;
    }

    return sum;
}

int main(void)
{
    
    
    dp[0]=1;
    int s;
    cin>>s;

    for(int i=1;i<=s;i++)
    {
        if(i<3) dp[i]=0;

        dp[i] = sumdp(i-2);

    }

    cout<<dp[s]%mod<<endl;
}

Measured memory_bytes: 3196
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    
    if (a < b)
    {
        for (int i = 0; i < b; i++)
        {
            cout<<a;
        }
        cout<<"\n";
    }
    else
    {
        for (int i = 0; i < a; i++)
        {
            cout<<b;
        }
        cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		int n = sc1.nextInt();

		if ( n % 2 == 0) {
			System.out.println(n);
		}
		else {
			System.out.println(n * 2);
		}

		sc1.close();

	}

}

Measured memory_bytes: 22736
#include<iostream>
#include<map>
#include<string>

using namespace std;
int main(){
  string s;
  cin>>s;
  map<char,int> a;
  for(int i=0;i<s.size();++i){
    ++a[s[i]];
    if(a[s[i]]>1){
      cout<<"no"<<endl;
      return 0;
    }
  }
  cout<<"yes"<<endl;
  return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int x[] = new int [3];
        for(int i = 0;i < 3;i++){
            x[i] = scanner.nextInt();
        }
        int k = scanner.nextInt();
        int max = 0;
        int n = 0;
        for(int i = 0;i < 3;i++){
            if(max < x[i]){
                max = x[i];
                n = i;
            }
        }
        for(int i = 0;i < k;i++){
            x[n] *= 2;
        }
        int sum = 0;
        for(int i = 0;i < 3;i++){
            sum += x[i];
        }

        System.out.println(sum);
    }
}

Measured memory_bytes: 21076
#include <iostream>

using namespace std;
typedef long long ll;

void swap(ll &x, ll &y){
    ll tmp = x;
    x = y;
    y = tmp;
}

int main(){
    ll n, m;
    cin >> n >> m;
    if(n > m){ swap(n, m); }

    ll ans = 0;
    if(m == 1){
        ans = 1;
    }else if(n == 1 && m > 2){
        ans = m - 2;
    }else if(n > 2 && m > 2){
        ans = (n - 2) * (m - 2);
    }

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


Measured memory_bytes: 256
import sys


def main():
    n = int(sys.stdin.readline().strip())
    a = [int(s) for s in sys.stdin.readline().strip().split(' ')]
    b = []

    maxlen = -1
    for i in range(n):
        ai = a[i]
        bi = format(ai, 'b')
        b.append(bi)
        if maxlen < len(bi):
            maxlen = len(bi)

    ans = 0
    for i in range(maxlen):
        ones = 0
        zeros = 0
        for j in range(n):
            if len(b[j]) < i + 1:
                zeros += 1
            else:
                target = b[j][-1-i]
                if target == '1':
                    ones += 1
                else:
                    zeros += 1
        ans += (2 ** i) * (ones * zeros)
        ans = ans % (10 ** 9 + 7)
    print(ans)


main()


Measured memory_bytes: 130016
#include<bits/stdc++.h>
using namespace std;
int N;
int s[100];
char t[100][10];
int u[100],v[100],w[100];

int num[1000];

int s2i(string str){
  stringstream ss;
  ss<<str;
  int res;
  ss>>res;
  return res;
}

int change(int x){
  if(0<=x){
    return x;
  }else{
    return num[-x];
  }
}

void setvalue(int x,int y){
  assert( x<0 );
  num[-x]=y;
}

int main(){

  set<char> st;
  map<int,int> lp;  
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&s[i]);
    assert( lp.count(s[i]) == 0 );
    lp[ s[i] ] = i;
    
    scanf("%s",t[i]);
    char a[20],b[20],c[20];
    
    if(t[i][0]=='A'){
      scanf("%s %s %s",a,b,c);
      if('a'<=a[0]&&a[0]<='z')u[i]=-1*(int)a[0],st.insert(a[0]);
      else assert(0);
      
      if('a'<=b[0]&&b[0]<='z')v[i]=-1*(int)b[0],st.insert(b[0]);
      else v[i]=s2i(b);

      if('a'<=c[0]&&c[0]<='z')w[i]=-1*(int)c[0],st.insert(c[0]);
      else w[i]=s2i(c);

    }else if(t[i][0]=='S'&&t[i][1]=='U'){
      scanf("%s %s %s",a,b,c);
      if('a'<=a[0]&&a[0]<='z')u[i]=-1*(int)a[0],st.insert(a[0]);
      else assert(0);
      
      if('a'<=b[0]&&b[0]<='z')v[i]=-1*(int)b[0],st.insert(b[0]);
      else v[i]=s2i(b);

      if('a'<=c[0]&&c[0]<='z')w[i]=-1*(int)c[0],st.insert(c[0]);
      else w[i]=s2i(c);

      
    }else if(t[i][0]=='S'&&t[i][1]=='E'){
      scanf("%s %s",a,b);
      if('a'<=a[0]&&a[0]<='z')u[i]=-1*(int)a[0],st.insert(a[0]);
      else assert(0);

      if('a'<=b[0]&&b[0]<='z')v[i]=-1*(int)b[0],st.insert(b[0]);
      else v[i]=s2i(b);
      
    }else if(t[i][0]=='I'){
      scanf("%s %s",a,b);
      if('a'<=a[0]&&a[0]<='z')u[i]=-1*(int)a[0],st.insert(a[0]);
      else assert(0);

      if('a'<=b[0]&&b[0]<='z')assert(0);
      else v[i]=s2i(b);

      
    }else if(t[i][0]=='H'){
      
    }else assert(0);
  }

  int mx=50000000;
  int p=0,cc=0;
  while(cc < mx){
    
    if(t[p][0]=='A'){
      int value=change(v[p])+change(w[p]);
      if(value<0 || 16<=value)break;
      setvalue(u[p],value);
      p++;
    }else if(t[p][0]=='S'&&t[p][1]=='U'){
      int value=change(v[p])-change(w[p]);
      if(value<0 || 16<=value)break;
      setvalue(u[p],value);
      p++;
    }else if(t[p][0]=='S'&&t[p][1]=='E'){
      int value=change(v[p]);
      if(value<0 || 16<=value)break;
      setvalue(u[p],value);
      p++;
    }else if(t[p][0]=='I'){
      int value=change(u[p]);
      if(value > 0 ){
        int next=change(v[p]);
        if( lp.count( next ) == 0 )break;
        p=lp[next];
      }else{
        p++;
      }


    }else if(t[p][0]=='H'){
      break;
    }else assert(0);

    
    cc++;
    if(p==N)break;
  }
  
  if(cc<mx){
    set<char> :: iterator it;
    for(it=st.begin();it!=st.end();it++){
      int f=*it;
      printf("%c=%d\n", *it, change(-f) );
    }
  }else{
    printf("inf\n");
  }
  
  return 0;
}

Measured memory_bytes: 3324
#include <cstdio>

using namespace std;

int main()
{
	int N;
	scanf("%d", &N);
	int T[N];
	for (int i = 0; i < N; i++) {
		scanf("%d", &T[i]);
	}
	int M;
	scanf("%d", &M);
	int P[M], X[M];
	for (int i = 0;i < M; i++){
		scanf("%d", &P[i]);
		scanf("%d", &X[i]);
	}
	int sum;
	for(int j = 0; j < M;j++){
		sum = 0;
		for(int i = 0; i < N;i++){
			sum += T[i];
		}
		sum = sum - T[P[j]-1] + X[j];
		printf("%d\n", sum);
	}
	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> ii;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=1000000007;
const long double PI=3.1415926535898;
const long double EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}

int n,m;
vector<int> adj[100005];

int main(){
	scanf("%d%d",&n,&m);
	int a,b;
	for(int i=0;i<m;i++){
		scanf("%d%d",&a,&b);
		adj[a].pb(b);adj[b].pb(a);
	}
	int par[100005],dist[100005];
	memset(dist,-1,sizeof(dist));memset(par,0,sizeof(par));
	queue<int> q;
	dist[1]=0;q.push(1);
	while(!q.empty()){
		int cur=q.front();q.pop();
		for(int i=0;i<SZ(adj[cur]);i++){
			if(dist[adj[cur][i]]>dist[cur]+1||dist[adj[cur][i]]==-1){
				dist[adj[cur][i]]=dist[cur]+1;
				par[adj[cur][i]]=cur;
				q.push(adj[cur][i]);
			}
		}
	}
	for(int i=2;i<=n;i++){
		if(par[i]==0){printf("No");return 0;}
	}
	printf("Yes\n");
	for(int i=2;i<=n;i++){
		printf("%d\n",par[i]);
	}
}


Measured memory_bytes: 10988
#include"bits/stdc++.h"
using namespace std;

int main()
{
    int a,b;cin>>a>>b;long long sum=0;
    while(b--)
    {
        int c;cin>>c;
        sum+=c;
    }
    if(a<=sum) cout<<"Yes"<<endl;
    else cout<<"No";
}


Measured memory_bytes: 256
a1=gets.chomp.split(" ").map(&:to_i)
a2=gets.chomp.split(" ").map(&:to_i)
a3=gets.chomp.split(" ").map(&:to_i)

n = gets.to_i

n.times do |i|
  b = gets.to_i
  for i in 0..2
    if a1[i] == b
      a1[i] = 0
    end
    if a2[i] == b
      a2[i] = 0
    end
    if a3[i] == b
      a3[i] = 0
    end
  end
end

isbingo = false
if a1[0] == 0 && a1[1] == 0 && a1[2] == 0
  isbingo = true
end
if a2[0] == 0 && a2[1] == 0 && a2[2] == 0
  isbingo = true
end
if a3[0] == 0 && a3[1] == 0 && a3[2] == 0
  isbingo = true
end
if a1[0] == 0 && a2[0] == 0 && a3[0] == 0
  isbingo = true
end
if a1[1] == 0 && a2[1] == 0 && a3[1] == 0
  isbingo = true
end
if a1[2] == 0 && a2[2] == 0 && a3[2] == 0
  isbingo = true
end
if a1[0] == 0 && a2[1] == 0 && a3[2] == 0
  isbingo = true
end
if a1[2] == 0 && a2[1] == 0 && a3[0] == 0
  isbingo = true
end

if isbingo
  puts "Yes"
else
  puts "No"
end

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

def f(x):
    if int(x) > N:
        return 0
    else:
        if all(x.count(j) >= 1 for j in ["3", "5", "7"]):
            ans = 1
        else:
            ans = 0
        for i in ["3", "5", "7"]:
            ans += f(x+i)    
        return ans        

print(f("0"))

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

int main(){
  int a;
  cin >> a;
  int count = 0;
  for (int i = 0; i < 3; i++){
    if (a % 10 == 1) count++;
    a /= 10;
  }
  cout << count << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn=1e4+100;
ll a[maxn];
ll go(ll l,ll r){
    ll pos=1;
    for(int i=0;i<l;i++){
        pos*=(r-i);
        pos/=(i+1);
    }
    return pos;
}
int main(){
    ll n,p;
    while(~scanf("%lld%lld",&n,&p)){
        for(int i=0;i<n;i++)
            scanf("%lld",&a[i]);
        ll cnt1=0,cnt2=0;
        for(int i=0;i<n;i++){
            if(a[i]&1) cnt1++;
            else cnt2++;
        }
        ll ans=0;
        if(p==0){
            ll s=0,d=0;
            ans=1;
            for(int i=1;i<=cnt2;i++)
                s+=go(i,cnt2);
            for(int i=2;i<=cnt1;i+=2)
                d+=go(i,cnt1);
            ans+=(s+d+s*d);
        }
        else{
            ll s=0,d=0;
            for(int i=1;i<=cnt2;i++)
                s+=go(i,cnt2);
            for(int i=1;i<=cnt1;i+=2)
                d+=go(i,cnt1);
            ans+=(d+(d*s));
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

#define int long long

signed main() {
    int k;
    cin >> k;
    int a[1000001];
    a[1] = 7 % k;

    for(int i = 2; i <= k; i++) {
        a[i] = (a[i - 1] * 10 + 7) % k;
    }

    for(int i = 1; i <= k; i++) {
        if(a[i] == 0) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 11384
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

const double PI = 3.14159265358979323846;

int map[16][16];
int w,h;

int f(int x, int y) {
    if ((map[x][y] == -1) || (x < 0) || (y < 0) || (w <= x) || (h <= y)) {
        return 0;
    }
    if ((x == 0) && (y == 0)) {
        return 1;
    }

    if (map[x][y] != 0) {
        return map[x][y];
    }
    return f(x - 1, y) + f(x, y - 1);
}

int main() {
    while (true) {
        int n;
        cin >> w >> h >> n;
        if ((w == 0) && (h == 0)) return 0;
        for (int i = 0; i < w; ++i) {
            for (int j = 0; j < h; ++j) {
                map[i][j] = 0;
            }
        }
        for (int i = 0; i < n; ++i) {
            int x, y;
            cin >> x >> y;
            map[x - 1][y - 1] = -1;
        }

        cout << f(w - 1, h - 1) << endl;
    }
}

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

using namespace std;

bool check(vector<int> &hei) {
    for (int x : hei) {
        if (x > 0) return true;
    }
    return false;
}

int main () {
    int n = 0, k = 0;
    cin >> n >> k;
    vector<long long> h(n);
    for (int i=0; i<n; i++) {
        cin >> h.at(i);
    }
    sort(h.begin(), h.end());
    long long min = 1000000001;
    for (int i=0; i<n-k+1; i++) {
        long long buf = h.at(i+k-1) - h.at(i);
        if (buf < min) min = buf;
    }
    cout << min << endl;
    return 0;
}


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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;

int main() {
    lli n;
    cin1(n);
    string s;
    cin1(s);

    lli r_cnt = 0;
    lli l_cnt = 0;
    lli status = 0;//1でr継続中、-1でl継続中、0は無
    REP(i, 0, s.length()) {
        if (status == 0) {
            if (s[i] == ')'){
                r_cnt++;
                status = 1;
            }
            else {
                l_cnt++;
                status = -1;
            }
        }
        else if (status == 1) {
            if (s[i] == ')') {
                r_cnt++;
            }
            else {
                status = -1;
                l_cnt++;
            }
        }
        else if (status == -1) {
            if (s[i] == ')') {
                l_cnt--;
                if (l_cnt == 0) {
                    status = 0;
                }
            }
            else {
                l_cnt++;
            }
        }
    }
    //cout << l_cnt << endl;
    REP(i, 0, r_cnt) {
        cout << '(';
    }
    cout << s;
    REP(i, 0, l_cnt) {
        cout << ')';
    }
    cout << endl;
}


Measured memory_bytes: 256
#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 n,k,r,s,p;
  string t;
  cin>>n>>k>>r>>s>>p>>t;
  int ans=0;
  rep(i,t.size()){
    if(i>k-1&&t[i-k]==t[i]){
      t[i]='x';
      continue;
    }
    if(t[i]=='p') ans+=s;
    else if(t[i]=='r') ans+=p;
    else ans+=r;
  }	
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 512
local mod = 1000000007
local mfl = math.floor

local function bmul(x, y)
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  local x0, y0 = x - x1 * 31623, y - y1 * 31623
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local fact = {1}
local invs = {1}
local invfact = {1}

for i = 2, 500000 do
  fact[i] = bmul(fact[i - 1], i)
  invs[i] = bmul(mfl(mod / i), mod - invs[mod % i])
  invfact[i] = bmul(invfact[i - 1], invs[i])
end

local function getPerm(n, k)
  if n == 0 or k == 0 then return 1 end
  local ret = fact[n]
  if k < n then
    ret = bmul(ret, invfact[n - k])
  end
  return ret
end

local function getComb(n, k)
  if k == 0 or k == n then return 1 end
  return bmul(fact[n], bmul(invfact[k], invfact[n - k]))
end

local n, m = io.read("*n", "*n")
if m < n then
  print(0) os.exit()
end
local p_mn = getPerm(m, n)
local matched = 0
for i = 1, n do
  local comb = getComb(n, i)
  local remPerm = getPerm(m - i, n - i)
  local z = bmul(comb, remPerm)
  if i % 2 == 1 then
    matched = badd(matched, z)
  else
    matched = badd(matched, mod - z)
  end
end
local not_matched = badd(p_mn, mod - matched)
print(bmul(p_mn, not_matched))


Measured memory_bytes: 15112
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            Dictionary<int, int> players = new Dictionary<int, int>();
            int[] rank = new int[31];
            bool[] isSame = new bool[31];

            while (true)
            {
                string[] input1 = Console.ReadLine().Split(',');
                int p = int.Parse(input1[0]);
                int s = int.Parse(input1[1]);

                if (p == 0 && s == 0) break;

                players.Add(p, s);

                if (!isSame[s])
                {
                    for (int i = 0; i <= s; i++) rank[i]++;
                    isSame[s] = true;
                }
            }

            string input2;

            while (!string.IsNullOrEmpty(input2 = Console.ReadLine()))
            {
                int q = int.Parse(input2);

                sb.AppendLine(rank[players[q]].ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9508
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;

int main() {
    int N, M;
    cin>>N>>M;
    ll H[N];
    ll HH[N];
    for(int i=0;i<N;++i){
        cin>>H[i];
        HH[i] = H[i];
    }
    int A, B;
    for(int i=0;i<M;++i){
        cin>>A>>B;
        A--;
        B--;
        if(H[A]>H[B]){
            HH[B] = -1;
        }
        else if(H[B]>H[A]){
            HH[A] = -1;
        }
        else{
            HH[A] = -1;
            HH[B] = -1;
        }
    }
    int ans = 0;
    for(int i=0;i<N;++i){
        if(H[i]==HH[i]) ans++;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 5188
import sys
import numpy as np
sys.setrecursionlimit(10 ** 9)

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

M1, D1 = rl()
M2, D2 = rl()
print(1 if M1 != M2 else 0)

Measured memory_bytes: 21504
using System;

namespace id_0000
{
    class Program
    {
        static void Main(string[] args)
        {
            for(int i=1; i<=9 ;i++)
            {
                for(int j=1;j<=9;j++)
                {
                    Console.WriteLine(i + "x" + j  + "=" + (i * j));
                }
            }
        }
    }
}

Measured memory_bytes: 5528
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <string.h>
#include <math.h>
#include <map>

using namespace std;

int main(){
	int N, A, B;
	cin >> N;
	if (N == 1)
		cout << "Hello World" << endl;
	else{
		cin >> A >> B;
		cout << A + B << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<stack>
#include<vector>
#include<map> 
#define maxn 100005
#define INF 1000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;



int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	printf("%d %d %d\n",c,a,b);
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static Scanner sc = new Scanner(System.in);

	static class FastScanner {
		private final InputStream in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		public FastScanner(InputStream source) {
			in = source;
		}

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte()) return buffer[ptr++];
			else return -1;
		}

		private static boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args){

		solve_abc160_c();
	}
  
  	public static void solve_abc160_c(){

		FastScanner sc = new FastScanner(System.in);
		
		int K = sc.nextInt();
		int N = sc.nextInt();
		int[] a = new int[N];
		int sum = 0;
		int max = 0;
		
		a[0] = sc.nextInt();
		
		for(int i=1;i<N;i++){
			a[i] = sc.nextInt();
			sum += a[i] - a[i-1];
			if((a[i] - a[i-1])> max) max = a[i] - a[i-1];
		}
		
		sum += a[0] + K - a[N-1];
		
		if((a[0] + (K - a[N-1])) > max) max = a[0] + (K - a[N-1]);
		
		sum -= max;
		
		System.out.println(sum);
	}
}

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

int main() {
  int N,ans=1;
  string S;
  cin >> N >> S;
  for(int i=0; i<N-1; i++){
    if(S[i] != S[i+1]){
      ans++;
    }
  }
  cout << ans << endl;
}


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

int main(){
    int N;
    cin >> N;
    double ans = 0;
    for(int i= 0; i < N; i++){
        int a;
        cin >> a;
        ans += (double)1/(double)a;
    }
    ans = (double)1/ans;
    cout << fixed << setprecision(6) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i,n) for(int i=0; i<n; i++)
#define M0D 1000000007
using namespace std;

int main(){

  const int inf=100000000;
  int N,M;
  cin >> N >> M;
  int ans=M;

  int a[1000],b[1000],c[1000], dist[100][100];

  For(i,M){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--,b[i]--;
  }

  For(i,N) For(j,N){
    if(i==j) dist[i][j]=0;
    else dist[i][j]=inf;
  }

  For(i,M){
    dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);
    dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
  }

  For(k,N) For(i,N) For(j,N) dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);

  For(i,M){
    bool shortest=false;
    For(j,N) if(dist[j][a[i]]+c[i]==dist[j][b[i]]) shortest=true;
    if(shortest) ans--;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
const int N=20;
int n,a[N],b[N];
struct node
{
    int x,p;
    node(int x=0,int p=0):x(x),p(p){}
}c[N];
int d[N];
int solve(int x)
{
    for(int i=0;i<n;i++)
        if(x>>i&1)
            c[i+1]=node(b[i+1],1),d[i+1]=b[i+1];
        else
            c[i+1]=node(a[i+1],0),d[i+1]=a[i+1];
    sort(d+1,d+1+n);
    int ans=0;
    for(int i=n;i>=1;i--)
    {
        bool flag=false;
        for(int j=i;j>=1;j--)
            if(c[j].x==d[i]&&c[j].p==(i-j&1))
        {
            flag=true;
            ans+=i-j;
            for(int k=j;k<i;k++)
            {
                c[k+1].p^=1;
                swap(c[k],c[k+1]);
            }
            break;
        }
        if(!flag) return inf;
    }
    return ans;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++) scanf("%d",&b[i]);
    int ans=inf;
    for(int i=0;i<1<<n;i++)
        ans=min(ans,solve(i));
    if(ans==inf) ans=-1;
    printf("%d\n",ans);
}



Measured memory_bytes: 3800
//解説あり
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

void Zalgorithm(vector<int> &Z, string S) {
	int n = S.size();
	Z.push_back(n);
	int i = 1, j = 0;
	while(i < n) {
		while (i + j < n && S[j] == S[i+j]) j++;
		Z.push_back(j);

		if (j == 0) {
			i++;
			continue;
		}

		int k = 1;
		while (k < j && k + Z[k] < j) {
			Z.push_back(Z[k]);
			k++;
		}
		i += k;
		j -= k;
	}
    return;
}

int main(void) {
  string s;
  int n;
  cin >> n >> s;

  int ans = 0;
  rep(i, 0, n) {
      vector<int> Z;
      Zalgorithm(Z, s.substr(i, n-i));
      rep(j, 0, Z.size()) {
          ans = max(ans, min(Z[j], j));
      }
  }

    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <iostream>
using namespace std;
static const int MAX = 100;


int main(){
  int n, A[MAX];
  cin >> n;
  for(int i = 0;i < n;i++) cin >> A[i];
  int v,j;
  for(int i = 0;i < n;i++){
       if(i > 0) printf(" ");
       printf("%d", A[i]);      
       } 
       printf("\n");
  for(int i = 1; i < n; i++){
     /* for(int k = 0;k < n;k++){
       if(k > 0) printf(" ");
       printf("%d", A[k]);      
       } 
       printf("\n"); */
      v = A[i];
      j = i-1;
    while((j >= 0) && (A[j] > v)){
       A[j+1] = A[j];
       j--;
    }
    A[j+1] = v;
   for(int i = 0;i < n;i++){
      if(i > 0) printf(" ");
      printf("%d", A[i]);      
   } 
    printf("\n"); 
  }  
  return 0;
}


Measured memory_bytes: 3216
//                             ¯\_(ツ)_/¯   
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mma,ava,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define ll long long
 
 
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
 
const int N=2e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;

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

	int a,b,c,k;

	scanf("%d %d %d %d",&a,&b,&c,&k);
	
	while(k--){
		if(c<=max(b,a))c*=2;
		else if(b<=a)b*=2;
	}
	if(c>max(b,a) && a<min(b,c))printf("Yes\n");
	else printf("No\n");	
	
}

//CBA

Measured memory_bytes: 3708
N = int(input())
H = list(map(int, input().split()))
count = 0
ans = 0
for i in range(N - 1):
    if H[i] >= H[i + 1]:
        count += 1
    else:
        ans = max(count,ans)
        count = 0
ans = max(count,ans)
print(ans)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define int long long
using namespace std;

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

int ans = 0;
if( N % 10 == 0 ){
cout << 10 << endl;
return 0;
}else{
while( N > 0 ){
ans += N % 10;
N /= 10;
}
}
cout << ans << endl;
}


Measured memory_bytes: 256
N,M = [int(s) for s in input().split()]
dist = [N*-10**9]*N
E = []
flag = 0
change = 0
N_flag = 0
for i in range(M):
    a,b,c = [int(s) for s in input().split()]
    E.append((a,b,c))
dist[0] = 0
for i in range(N):
    for (a,b,c) in E:
        if a == N or b == N:
            N_flag = 1
        newLen = dist[a-1] + c
        if newLen > dist[b-1]:
            change = 1
            dist[b-1] = newLen
            if i == N-1 and change == 1 and N_flag == 1:
                flag = 1
        change = 0
        N_flag = 0
if flag == 1:
    print('inf')
else:
    print(dist[N-1])

Measured memory_bytes: 3316
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  
  string s;
  cin >> s;
  
  ll k;
  cin >> k;

  vector<string> ss;
  for (ll i = 0; i < k; i++){
    for (ll j = 0; j < s.size()-i; j++){
      ss.emplace_back(s.substr(j, i+1));
    }
  }
  sort(ss.begin(), ss.end());
  ss.erase(unique(ss.begin(), ss.end()), ss.end());
  cout << ss[k-1] << endl;


  return 0;
}


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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll a, b, n; gi(a), gi(b), gi(n);
	if(n >= b) {
		print((a*(b-1))/b - (a*((b-1)/b)));
		return 0;
	}
	print((a*n)/b - (a*(n/b)));
}


Measured memory_bytes: 3576
package main

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

var A []int

// パーティション
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	A = make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		A[i], _ = strconv.Atoi(sc.Text())
	}

	q := partition(0, n-1)

	for i := 0; i < n; i++ {
		if i != 0 {
			fmt.Print(" ")
		}
		if i == q {
			fmt.Print("[")
		}
		fmt.Printf("%d", A[i])
		if i == q {
			fmt.Print("]")
		}
		if i == n-1 {
			fmt.Println("")
		}
	}
}

func partition(p, r int) int {
	var x, i, t int
	x = A[r]
	i = p - 1
	for j := p; j < r; j++ {
		if A[j] <= x {
			i++
			t = A[i]
			A[i] = A[j]
			A[j] = t
		}
	}
	t = A[i+1]
	A[i+1] = A[r]
	A[r] = t
	return i + 1
}



Measured memory_bytes: 3124
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s=sc.next();
        int ans=0;
        for(int i=1;i<s.length();i++){
            if(s.charAt(i-1)!=s.charAt(i)){
                ans++;
            }
        }
        System.out.println(ans);
    }
    
 
}

Measured memory_bytes: 23524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;

int H, W;
vector<string> S;
bool flag = false;

int dfs(int h, int w){
    //cout << h << " " << w << " " << flag << endl;
    S[h][w] = '.';
    if(flag) return 0;
    if(h == H-1 && w == W-1){
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if(S[i][j] == '#'){
                    flag = true;
                    break;
                    return 0;
                }
            }
        }
        return 0;
    }

    if(h+1 < H && w+1 < W){
        if(S[h][w+1] == S[h+1][w]){
            flag = true;
            return 0;
        }
        if(S[h+1][w] == '#') dfs(h+1, w);
        if(S[h][w+1] == '#') dfs(h, w+1);
    }

    else if(h == H-1 && w+1 < W){
        if(S[h][w+1] == '#') dfs(h, w+1);
        else { flag = true; return 0;}

    }
    else if(w == W-1 && h+1 < H){
        if(S[h+1][w] == '#') dfs(h+1, w);
        else { flag = true; return 0;}
    }
    return 0;

}


int main(){
    cin >> H >> W;
    S.resize(H);
    for(int i = 0; i < H; i++) cin >> S[i];
    if(S[0][0] != '#' || S[H-1][W-1] != '#'){
        cout << "Impossible" << endl;
        return 0;
    }
    //cout << flag << endl;
    dfs(0, 0);
    //cout << flag << endl;
    if(flag) cout << "Impossible" << endl;
    else cout << "Possible" << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) = println(run {
    fun List<Int>.accumulated(): List<Int> { var sum = 0; return this.map { sum += it; sum } }
    val n = readLine()!!.toInt()
    val w = readLine()!!.split(" ").map { it.toInt() }

    val total = w.sum()
    w.accumulated().map { Math.abs(total-2*it) }.min()!!

})



Measured memory_bytes: 37856
N = int(input())
SP = []

for i in range(N):
    s, p = input().split()
    SP.append({'name':s, 'point':int(p), 'num':int(i+1)})

SP.sort(key=lambda x: x['point'], reverse=True)
SP.sort(key=lambda x: x['name'])

for v in SP:
    print(v['num'])

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

int n, k;
long long T[100000];

int check(long long P) {
	int i = 0;
	for (int j = 0; j < k; j++) {
		long long s = 0;
		while (s + T[i] <= P) {
			s += T[i];
			i++;
			if (i == n)return n;
		}
	}
	return i;
}

int solve() {
	long long left = 0;
	long long right = 1000000000;
	long long mid;
	while(right - left > 1) {
		mid = (left + right) / 2;
		int v = check(mid);
		if (v >= n)right = mid;
		else left = mid;
	}
	return right;
}

int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> T[i];
	}
	long long ans = solve();
	cout << ans<<endl;
	
}


Measured memory_bytes: 3900
#include <stdio.h>
int main(void){
    int n, x, s;
    int i, j, k;
    for(;;){
        scanf("%d %d",&n, &x);
        s = 0;
        if(n == 0 && x == 0){
            break;
        }
        int i, j, k;
        for(i = 1; i < n-1; i++){
            for(j = i+1; j < n; j++){
                for(k = j+1; k <= n; k++){
                    if(i + j + k == x){
                        s++;
                    }
                }
            }
        }
        printf("%d\n",s);
    }
    return 0;
}




Measured memory_bytes: 2048
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007
ll fac[1000000];
ll finv[1000000];
ll inv[1000000];

void comb_init(){
  fac[0] = 1;
  fac[1] = 1;
  for(int i=2;i<1000000;i++){
    fac[i] = i*fac[i-1];
    fac[i] %= MOD;
  }
  inv[1] = 1;
  for(int i=2;i<1000000;i++){
    inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
  }
  finv[0] = 1;
  finv[1] = 1;
  for(int i=2;i<1000000;i++){
    finv[i] = inv[i]*finv[i-1];
    finv[i] %= MOD;
  }
}

ll comb(ll n,ll k){
  ll c;
  c = fac[n];
  c *= finv[k];
  c %= MOD;
  c *= finv[n-k];
  c %= MOD;
  return c;
}

int main(){
  ll n;
  cin >> n;
  ll x[n],y[n];
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i];
  }
  double c = 1.0/n;
  double ans = 0;
  double z;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      z = sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]));
      ans += z;
    }
  }
  ans *= c;
  cout << std::setprecision(12) << ans << endl;; // "3.1"


  return 0;
}


Measured memory_bytes: 256
def c_2d_plane_2n_points_bipartite_graph():
    import networkx as nx
    from networkx.algorithms.flow import dinitz
    N = int(input())
    A, B, C, D = [], [], [], []
    for _ in range(N):
        a, b = [int(i) for i in input().split()]
        A.append(a)
        B.append(b)
    for _ in range(N):
        c, d = [int(i) for i in input().split()]
        C.append(c)
        D.append(d)

    # 赤い点の番号は 1~N とし，青い点の番号は N+1~2N とする
    # ソースを 0 番とし，シンクを 2N+1 番とする
    graph = nx.DiGraph()
    graph.add_nodes_from(range(2 * N + 2))
    for i in range(N):
        for j in range(N):
            if A[i] < C[j] and B[i] < D[j]:
                graph.add_edge(i + 1, j + N + 1, capacity=1)
    for i in range(1, N + 1):
        graph.add_edge(0, i, capacity=1)
    for j in range(N + 1, 2 * N + 1):
        graph.add_edge(j, 2 * N + 1, capacity=1)

    return dinitz(graph, 0, 2 * N + 1).graph['flow_value']

print(c_2d_plane_2n_points_bipartite_graph())

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

using namespace std;

const int N = 10000;
//const int N = 3;
//int dp[N][N][N];
map<tuple<int, int, int>, bool> m;

int subsolve (int & a, int & b, int & c) {
    tuple<int, int, int> key = make_tuple(a, b, c);
    if (m.count (key) != 0) {
        return -1;
    } else {
        m.insert (make_pair (key, true));
    }

    int ta = (b + c) / 2;
    int tb = (a + c) / 2;
    int tc = (a + b) / 2;
    int na = tb + tc, nb = ta + tc, nc = ta + tb;

    if ( a % 2 || b % 2 || c % 2) {
        a = na, b = nb, c = nc;
        return 1;
    } else {
        a = na, b = nb, c = nc;
        return 0;
    }
}

int solve (int a, int b, int c) {
    //memset(dp, -1, sizeof(dp));
    int i = 0;
    for (;; ++i) {
        //cout << "i = " << i << endl;
        int ret = subsolve (a, b, c);
        //cout << "ret =" << ret << endl;
        if (ret == -1) return -1;
        if (ret != 0) break;
    }
    return i;
}

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

    cout << solve (a, b, c) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y;
	cin>>n>>x>>y;
	int output[n];
	memset(output,0,sizeof(output));
	for(int i=1;i<=n;i++)
	for(int j=i+1;j<=n;j++)
	{
		if(i<=x)
		{
			if(j<=x)
				output[j-i]++;
			else if(j>x and j<=y)
				output[min(j-i,x-i+1+y-j)]++;
			else 
				output[min(j-i,x-i+1+j-y)]++;
		}
		else if(j>=y)
		{
			if(i>=y)
				output[j-i]++;
			else if(i<y and i>=x)
				output[min(j-i,j-y+1+i-x)]++;
			else
				output[min(j-i,j-y+1+x-i)]++;
		}
		else
			output[min(j-i,i-x+1+y-j)]++;
	}
	for(int i=1;i<n;i++)
		cout<<output[i]<<endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> del(n);
  for (int i = 0; i < n; i++) cin >> del.at(i);
  long long sum = 0;
  for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
      sum += del.at(i) * del.at(j);
  cout << sum << endl;
}

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

using namespace std;
using ll = long long;

int n, m;
vector<int> s, c;

bool ok(string str) {
    if (str.length() != n) return false;
    for (int i = 0; i < m; ++i) if (str.at(s.at(i)) != to_string(c.at(i)).at(0)) return false;
    return true;
}

string solve() {
    for (int i = 0; i <= 999; ++i) {
        stringstream iss; iss << i;
        string str = iss.str();
        if (ok(str)) return str;
    }
    return "-1";
}

int main() {
    cin >> n >> m;
    s.resize(m); c.resize(m);
    for (int i = 0; i < m; ++i) cin >> s.at(i) >> c.at(i), --s.at(i);
    cout << solve() << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val a, op, b = sc.next()
    val ans = op match {
      case "+" => a.toInt + b.toInt
      case "-" => a.toInt - b.toInt
    }
    println(ans)
  }
}


Measured memory_bytes: 25644