akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int p = 1000000007;
int log2_p_MAX = 32;
long long felmer(long long a)
{
  // a^(2^i) mod p
  long long rem[log2_p_MAX];
  rem[0] = a%p;
  for(int i=1;i<log2_p_MAX;i++)
    rem[i] = (rem[i-1]*rem[i-1])%p;
  long long res = 1;
  long long expo = p-2;
  for(int i=0;i<log2_p_MAX;i++){
	if(expo%2==1){
      res *= rem[i];
      res = res%p;
    }
  	expo /= 2;
  }
  return res;
}
int main()
{
  long long n,k,i,t=1,u,res=1;
  cin >> n >> k;
  if(k>=n-1){
    for(i=0;i<n;i++){
      res*=2*n-i-1;
      res%=p;
      res*=felmer(i+1);
      res%=p;
    }
  }else{
    for(i=0;i<k;i++){
      t*=n-i;
      t%=p;
      t*=n-i-1;
      t%=p;
      u=felmer(i+1);
      t*=u;
      t%=p;
      t*=u;
      t%=p;
      res+=t;
      res%=p;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue> 
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
//#define int LL
#define db double
using namespace std;
//const int N   = ;
//const int mod = ;
const int INF =numeric_limits<int >::max();
#define For(n) for (int i=1;i<=n;++i)
#define rep(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
	x=0;
	char ch=getchar();
	int f=1;
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
}

int bo[233],a[233],n;
char s[233],ans[233],t1,tmp[233],t2;

void cmp()
{
	int ok=0,i;
	for ( i=1;i<=t1&&i<=t2&&ans[i]==tmp[i];++i) ;
	if (i==min(t1,t2)+1) ok=t1>t2;
	else ok=ans[i]>tmp[i];
	if (ok)
	{
		t1=t2;
		rep(i,1,t1) ans[i]=tmp[i];
		
	}
}
string ss=" zyxwvutsrqponmlkjihgfedcba";

int check()
{
	rep(i,1,26) if (s[i]!=ss[i]) return 1;
	return 0;
}
int sz,pos;
signed main()
{
	scanf("%s",s+1);n=strlen(s+1);
	if (n==26&&check()==0)  return printf("-1"),0;
	memset(a,-1,sizeof(a));
	rep(i,1,n)
	{
		bo[s[i]-'a']=1;
		rep(j,s[i]-'a',25)
		  if (bo[j]==0)
		  {
		  	a[i]=j;
		  	break;
		  }
	}
	rep(i,0,25) if (bo[i]==0)
	{
		pos=i;
		break;
	}else sz++;
	if (sz!=26)
	{
		rep(i,1,n) putchar(s[i]);putchar('a'+pos);
		return 0;
	}
	t1=26;rep(i,1,26) ans[i]=ss[i];
	rep(i,1,n)if (a[i]=='z')
	{
		t2=i-1;
		rep(j,1,t2) tmp[j]=s[j];
		tmp[t2]++;
		cmp();
	}
	rep(i,1,n) if (a[i]!=-1) 
	{
		if (i==22)
		{
			i=22;
		}
		t2=i;
		rep(j,1,i) tmp[j]=s[j];
		tmp[t2]=a[i]+'a';
		cmp();
	}

	rep(i,1,t1) putchar(ans[i]);
	return 0;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N
        self.count = 0
        self._size = [1]*N
    def root(self,a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    def is_sama(self,a,b):
        return self.root(a) == self.root(b)
    def unite(self,a,b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return
        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
            self._size[rb] += self._size[ra]
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]:
                self.rank[ra] += 1
            self._size[ra] += self._size[rb]
        self.count += 1
    def print_info(self):
        print("parent", self.parent)
        print("rank", self.rank)
        print("count", self.count)
        print("size", self._size)
    def size(self,a):
        return self._size[self.root(a)]

N, M = map(int,input().split())
uf = UnionFind(N)
for i in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    uf.unite(a,b)
ans = 0
for i in range(N):
    ans = max(ans,uf.size(i))
print(ans)

Measured memory_bytes: 20124
#include <iostream>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

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

int main() {
	long long int a, b, c;
	vector<long long int> v;
	cin >> a >> b >> c;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	sort(v.begin(), v.end());
	set<Q> st;
	st.insert(Q(v[0], P(v[1], v[2])));
	long long int count = 0;
	while (true) {
		if ((v[0] % 2 == 1) || (v[1] % 2 == 1) || (v[2] % 2 == 1)) {
			break;
		}
		count++;
		long long int a2, b2, c2;
		a2 = (v[0] / 2) + (v[1] / 2);
		b2 = (v[1] / 2) + (v[2] / 2);
		c2 = (v[2] / 2) + (v[0] / 2);
		v.clear();
		v.push_back(a2);
		v.push_back(b2);
		v.push_back(c2);
		sort(v.begin(), v.end());
		Q q = Q(v[0], P(v[1], v[2]));
		if (st.find(q) != st.end()) {
			count = -1;
			break;
		}
	}
	cout << count << endl;
	return 0;
}

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

int main (){
    int N;cin>>N;
    vector<int>D1(110);
    vector<int>D2(110); 
    bool s = true;
    for(int i=0; i<N; i++)cin >> D1.at(i) >> D2.at(i);
    for(int i=0; i<N-2; i++){
        if(D1.at(i) != D2.at(i))continue;
        if(D1.at(i+1)!= D2.at(i+1))continue;
        if(D1.at(i+2)!= D2.at(i+2))continue;
        cout << "Yes" << endl;
        s = false;
        break;

    }
    if(s)cout << "No" << endl;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
const int N=102,M=10010,mod=998244353;
ll n,m,T,k,cnt,x,y,z,indx,t,ans,a[N];
string s;
int main()
{
	scanf("%lld",&n);
	while (n--)
	{
		cin>>s;
		if (s=="AC") a[1]++;
		if (s=="WA") a[2]++;
		if (s=="TLE") a[3]++;
		if (s=="RE") a[4]++;
	}
	printf("AC x %lld\n",a[1]);
	printf("WA x %lld\n",a[2]);
	printf("TLE x %lld\n",a[3]);
	printf("RE x %lld\n",a[4]);
}

Measured memory_bytes: 3796
#include "bits/stdc++.h"

#define ll long long
#define ull unsigned long long
#define ld long double

#define tiii tuple < int, int, int >
#define pii pair < int, int >
#define pll pair < ll, ll >
#define pci pair < char, int >
#define psi pair < string, int >
#define pis pair < int, string >

#define vi vector < int >
#define vd vector < double >
#define vld vector < ld >
#define vll vector < ll >
#define vs vector < string >
#define vc vector < char >
#define vpi vector < pii >
#define vpll vector < pll >
#define vpis vector < pis >

#define pb push_back
#define mt make_tuple
#define gt0 get < 0 >
#define gt1 get < 1 >
#define gt2 get < 2 >

#define pi acos(-1)

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

const int maxn = 1e5 + 5;
const int mod = 1e9 + 9;

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

    fast;

    int n;

    cin >> n;

    int a[n + 5], b[n + 5];

    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];

    for(int i = 0; i < n - 2; i++){
        if(a[i] == b[i] && a[i + 1] == b[i + 1] && a[i + 2] == b[i + 2]){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define N 1000005
#define oo 999999999

using namespace std;

int n,m;
int a[N],b[N];
int l=oo,r;
int ans;

bool check(int);

int main(){
	scanf("%d",&n);m=2*n-1;
	for(int i=1;i<=m;i++)
		scanf("%d",&a[i]),l=min(l,a[i]),r=max(r,a[i]);	
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid)) l=mid+1,ans=mid;
		else r=mid-1;
	}
	cout<<l-1<<endl;
	return 0;
}
bool check(int x){
	memset(b,0,sizeof(b));	
	int z=oo,sum=0,y;
	for(int i=1;i<=m;i++)
		if(a[i]>=x)
			b[i]=1,sum++;
	for(int i=n;i>1;i--)
		if(b[i]==b[i-1]&&z>n-i){	
			z=n-i;
			y=b[i];
		}
	for(int i=n;i<m;i++)
		if(b[i]==b[i+1]&&z>i-n){
			z=i-n+1;
			y=b[i];
		}
	if(z==oo)
		return sum<m-sum?false:true;
	return y?true:false;
}


Measured memory_bytes: 6400
n = int(input())

D = {}

for i in range(26):
    D[chr(i+ord('a'))] = float('inf')

for _ in range(n):
    S = list(input())

    for i in range(26):
        count = S.count(chr(i+ord('a')))
        if count < D[chr(i+ord('a'))]:
            D[chr(i+ord('a'))] = count

ans = []

for i in range(26):
    if D[chr(i+ord('a'))] < float('inf'):
        for j in range(D[chr(i+ord('a'))]):
            ans.append(chr(i+ord('a')))
ans.sort()

print(*ans,sep="")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  string S;
  cin >> S;

  if(S[0] != 'A'){
    cout << "WA" << endl;
    return 0;
  }
  S[0] = 'a';

  int C = 0;
  REP(i,2,S.size()-1){
    if(S[i]=='C'){
      C++;
      S[i] = 'c';
    }
  }

  if(C!=1){
    cout << "WA" << endl;
    return 0;
  }

  rep(i,S.size()){
    if('a' <= S[i] && S[i] <= 'z'){
      ;
    }else{
      cout << "WA" << endl;
      return 0;
    }
  }
  cout << "AC" << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
# define    all(a)              a.begin(), a.end()
#define forn(i, a, b) for (int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define MOD int(1e9+7)
using namespace std;

typedef long long int ll;

bool cmp(int a, int b) {
    return a < b;
}

void printV(vector<int> nums) {
    for (int i: nums) {
        printf("%d ", i);// << " ";
    }
    printf("\n");
}

// void printV(vector<ll> nums) {
//     for (ll i: nums) {
//         printf("%lld ", i);// << " ";
//     }
//     printf("\n");
// }



int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

bool valid(int i, int j, int n, int m) {
    if (i >= 0 && i < n && j >=0 && j < m)
        return true;
    else 
        return false;
}

int cnt = 0;
void visit(int src, vector<vector<int>> graph, vector<bool> visited) {
    visited[src] = true;
    bool f = true;
    for (bool flag: visited) {
        f = f&flag;
    }
    if (f)
        cnt++;
    for (int i: graph[src]) {
        if (!visited[i]) {
            visit(i, graph, visited);
        }
    }
    visited[src] = false;
}


int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    // ios_base::sync_with_stdio(false);
    // cin.tie(0);cout.tie(0);
    // time_t start, end;
    // time(&start);
    int n, m;
    cin >> n >> m;
    vector<bool> visited(n+1);
    vector<vector<int>> graph(n+1);
    for (int i=0; i<m; i++) {
        int a, b;
        cin >> a >> b;
        graph[a].pb(b);
        graph[b].pb(a);
    }
    visited[0] = visited[1] = true;
    visit(1, graph, visited);
    cout << cnt << endl;
    // printV(res);
    // time(&end); 
    // double time_taken = double(end - start);
    // cout << "Time Taken: " << fixed << time_taken << setprecision(5);
    // cout << " sec" << endl;
    return 0;
}      

Measured memory_bytes: 3644
def base10toN(num, base):
    converted_string, modstring = "", ""
    currentnum = num
    if not num:
        return '0'
    while currentnum:
        mod = currentnum % base
        currentnum = currentnum // base
        converted_string = chr(48 + mod + 7*(mod > 10)) + converted_string
    return converted_string
n=int(input())
pop=[0]*(2*10**5+1)
for i in range(1,2*10**5+1):
  temp=base10toN(i,2)
  ans=0
  for j in range(len(temp)):
    if temp[j]=='1':
      ans+=1
  r=i%ans
  pop[i]=pop[r]+1
x=input()
ones=0
ans1=[]
for i in range(n):
  if x[i]=='1':
    ones+=1
dividemore=0
divideless=0
for i in range(n):
  if x[i]=='1':
    dividemore=(pow(2,n-1-i,ones+1)+dividemore)%(ones+1)
    if ones>=2:
      divideless=(pow(2,n-1-i,ones-1)+divideless)%(ones-1)
for i in range(n):
  counter=0
  if x[i]=='0':
    temp=(dividemore+pow(2,n-1-i,ones+1))%(ones+1)
  else:
    if ones==1:
      ans1.append('0')
      continue
    else:
      temp=(divideless-pow(2,n-1-i,ones-1))%(ones-1)
  ans1.append(str(pop[temp]+1))
print(' '.join(ans1))
    

Measured memory_bytes: 85300
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    
    // Nを取り出す
    int N = Integer.parseInt(line);
    
    // L1... を取り出す
    line = sc.nextLine();
    String[] l1l2 = line.split(" ");
    List<Integer> kusi = new ArrayList<>();
    
    for(int i = 0; i < l1l2.length; i++ ) {
      kusi.add(Integer.parseInt(l1l2[i]));
    }
    
    Collections.sort(kusi);
    
    calc(kusi);
  }
  
  // 計算する
  public static void calc(List<Integer> list) {
    int total = 0;
    for(int i = 0; i < list.size(); i=i+2) {
      total += list.get(i);
    }
    
    System.out.println(total);
  }
}

Measured memory_bytes: 25044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   while (true) {
      int n;
      cin >> n;
      if (n == 0) break;
      vector<int> s(n);
      rep(i, n) cin >> s[i];
      double m = 0.0;
      rep(i, n) m += s[i];
      m /= n;
      double alpha2 = 0.0;
      rep(i, n) { alpha2 += (s[i] - m) * (s[i] - m) / n; }
      double ans = sqrt(alpha2);
      printf("%0.5f\n", ans);
   }
   return 0;
}


Measured memory_bytes: 3220
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  char c; cin >> c;
  int x='z'-c;
  if(x<=25){
    cout << 'a' << endl;
  }
  else{
    cout << 'A' << endl;
  }
  
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <cassert>

#define rep(i,x) for(int i = 0; i < x; i++)
#define rrep(i,x) for(int i = 1; i <= x; i++)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using ll = long long;
using namespace std;
const int INF = 1001001001;
const ll LINF = 1002003004005006007;

const int mod = (int)1e9 + 7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    ll n, k;
    cin >> n >> k;
    vector<mint> d(k + 1, 0);
    rrep(i, k) {
        d[i] = mint(k / i).pow(n);
    }
    for (int i = k; i > 0; --i){
        for (int j = 2 * i; j <= k; j += i){
            d[i] -= d[j];
        }
    }
    mint ans = 0;
    rrep(i, k) ans += (d[i] * i);
    cout << ans << endl;
}


Measured memory_bytes: 3616
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
            var x = line[0];
            var y = line[1];

            for(var i = 0; i <= x; i++)
            {
                if (i * 2 + (x - i) * 4 == y)
                {
                    WriteLine("Yes");
                    return;
                }
            }

            WriteLine("No");
        }
    }
}


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

typedef long long int int64;
int main()
{
	int64 n,a,b;
	scanf("%lld%lld%lld",&n,&a,&b);
	if(n > a * b || n + 1 < a + b) {
		printf("-1\n");
	} else {
		for(int i = b;i >= 1;--i) {
			printf("%d ",i);
		}
		if(a == 1) {
			printf("\n");
			return 0;
		}
		int bk = (n - b) / (a - 1);
		int c1 = (n - b) % (a - 1);
		for(int i = 0;i < c1;++i) {
			for(int j = bk;j >= 0;--j) {
				printf("%lld ",i*(bk+1)+j+b+1);
			}
		}
		for(int i = c1;i < (a - 1);++i) {
			for(int j = bk - 1;j >= 0;--j) {
				printf("%lld ",i*bk+c1+j+b+1);
			}
		}
		printf("\n");
	}
}


Measured memory_bytes: 2176
#include<iostream>
#include<string>
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)

using namespace std;

int main(){
  int N;
  cin >> N;
  string s, t;
  cin >> s >> t;
  int ans = 2 * N;
  REP(i, 0, N) {
    if (s.substr(i) == t.substr(0, N - i)) {
      ans = N + i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int H, W;

	while (true) {
		cin >> H >> W;

		if (H + W == 0)break;

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

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

int main() {
    int n;
    int s = 0;
    vector<int> v;
    cin >> n;

    int A[n];
    
    for(int i=0; i<n; i++) {
        cin >> s;
        v.push_back(s);
        A[i] = s;
    }

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

    for(int i=0; i<n; i++) {
        int a = v[n / 2 - 1];
        int b = v[n / 2 ];
        if(A[i]<=a) {
            cout << b << endl;
        }
        else {
            cout << a << endl;
        }
    }

    return 0;
}

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

typedef long long ll;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int a[maxn];
int n;

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<ll> sum(n + 1);
    for (int i = 1; i <= n; i++) sum[i] = (sum[i - 1] + a[i - 1]);
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans = (ans + a[i] * ((sum[n] - sum[i + 1]) % mod) % mod) % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5556
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let r = read::<i32>();
    let g = read::<i32>();
    println!("{}", 2 * g - r);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a[3][3];
  	for (int i=0 ; i < 3; i++){
      for(int j = 0; j < 3 ; j++){
        cin >> a[i][j];
      }
    }
  int N;
  cin >> N;
  
  bool b[3][3];
  for(int i = 0; i < 3; i++)
    for(int j = 0; j < 3; j++)
      b[i][j] = false;
  
  int x;
  int count;
  while(count< N){
    cin >> x;
  for (int i=0 ; i < 3; i++){
      for(int j = 0; j < 3 ; j++){
        if(a[i][j]==x)
          b[i][j] = true;
      }
    }
    count++;
  }
  
  string answer = "No";
  for (int i = 0; i < 3; i++){
    if((b[i][0] && b[i][1] && b[i][2]) == true)
    	answer = "Yes";
  }
  
  for (int i = 0; i < 3; i++){
    if((b[0][i] && b[1][i] && b[2][i]) == true )
    	answer = "Yes";
  }
   
  if((b[0][0] && b[1][1] && b[2][2]) == true)
    answer = "Yes";
  
  if((b[0][2] && b[1][1] && b[2][0]) == true)
    answer  = "Yes";
  cout << answer << endl;
}

Measured memory_bytes: 256
import sys

n = int(sys.stdin.readline())
p_list = [int(x) for x in sys.stdin.readline().split()]
p_list_sort = sorted(p_list)
if p_list == p_list_sort:
    print("YES")
    sys.exit(0)
for i in range(len(p_list)):
    for j in range(len(p_list)):
        if i == j:
            break
        p_list[i], p_list[j] = p_list[j], p_list[i]
        if p_list == p_list_sort:
            print("YES")
            sys.exit(0)
        else:
            p_list[i], p_list[j] = p_list[j], p_list[i]
else:
    print("NO")


Measured memory_bytes: 3064
N, M = map(int, input().split())
d = {}
for _ in range(M):
    a, b = map(int, input().split())
    if a not in d:
        d[a] = [b]
    else:
        d[a].append(b)
if 1 not in d:
    print('IMPOSSIBLE')
else:
    for i in d[1]:
        if i in d:
            if N in d[i]:
                print('POSSIBLE')
                break
    else:
        print('IMPOSSIBLE')

Measured memory_bytes: 30684
X = list(map(int, input().split()))

if X[0] == 0:
  print(1)
elif X[1] == 0:
  print(2)
elif X[2] == 0:
  print(3)
elif X[3] == 0:
  print(4)
elif X[4] == 0:
  print(5)

Measured memory_bytes: 9124
Scanf.scanf "%d" (fun n ->
    let module M = Map.Make (struct type t = int let compare = compare end) in
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort (fun a b -> compare b a) a;

    let rec loop_2 t i p c =
        if i = n then 0 else
            if a.(i) <> p then loop_2 t (i + 1) a.(i) c else
                t * a.(i)
    in

    let rec loop_1 i p c =
        if i = n then 0 else
            if a.(i) <> p then (
                if c >= 2 then loop_2 p (i + 1) a.(i) 1
                          else loop_1 (i + 1) a.(i) 1
            ) else (
                let c = c + 1 in
                if c = 4 then p * p else
                    loop_1 (i + 1) p c
            )
    in
    loop_1 1 a.(0) 1 |> Printf.printf "%d\n"
)

Measured memory_bytes: 6688
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N; cin >> N;
	VI A(N);
	REP(i, N)cin >> A[i];
	int ans = 0;
	int sum = 0;
	REP(i, N)sum += A[i];

	REP(i, N) {
		int tmp = ((sum - A[i]) % mod)*A[i];
		ans += tmp;
		ans %= mod;
		sum -= A[i];
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 4780
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h,w,k;
    cin>>h>>w>>k;
    char mat[h+2][w+2];
    rep(i,0,h){
        rep(j,0,w){
            cin>>mat[i][j];
        }
    }
    ll ans=0;
    rep(i,0,1<<(h+w)){
        // cout<<i<<'\n';
        ll total=0;
        rep(j,0,h){
            if(i&(1<<j))continue;
            rep(f,0,w){
                if(i&(1<<(f+h)))continue;
                total+=(mat[j][f]=='#');
            }
        }
        if(total==k)ans++;
    }
    cout<<ans<<"\n";
    return 0;  
}

Measured memory_bytes: 3592
//ID:computerbox --> Hajiyev Huseyn
#include <bits/stdc++.h>
#define FAST_READ ios_base::sync_with_stdio(0);/*cin.tie(0); cout.tie(0);*/
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 200010

using namespace std;

string cislo;

ll sum=0;
vector<char>zn;
vector<char>ans;
int main(){
FAST_READ;
cin>>cislo;
ll cnt=0;

for(ll i=1;i<=3;i++)
{
	zn.pb('+');
}
for(ll i=1;i<=3;i++)
{
	zn.pb('-');
}
ll zns=4;
while(1)
{
  ans.clear();
  ll sum=cislo[0]-'0';
  for(ll i=0;i<3;i++)
  {

  	if(zn[i]=='+')
  	{
  		//eb(1);
  		sum=sum+(cislo[i+1]-'0');
  		ans.pb('+');
  	}
  	else
  	{
  		sum=sum-(cislo[i+1]-'0');
  		ans.pb('-');
  	}
   
  }
 // deb(sum);
  if(sum==7)
  {
  	break;
  }
  next_permutation(all(zn));
  //vecc(zn,zn.size());
}
for(ll i=0;i<cislo.size();i++)
{
	cout<<cislo[i];
	if(i!=cislo.size()-1)cout<<ans[i];
}
cout<<"=7";
cout<<endl;
//cout<<sum<<endl;




return 0;
} 

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

// 最小公倍数を求めるただそれだけ

int main() {
    ll a, b, r, x, tmp;
    cin >> a >> b;

    x = a*b;

    //　自然数a>bを確認・入れ替え

    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    //ユークリッドの互除法
    r = a % b;
    while (r!=0) {
        a = b;
        b = r;
        r = a % b;
    }

    // 最小公倍数を出力
    cout << x/b << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3


n = int(input())

renzoku = 0
renzoku3 = 0

for i in range(n):
    numbers = input().split(" ")
    d1 = int(numbers[0])
    d2 = int(numbers[1])

    if d1 == d2:
        renzoku += 1
    else:
        renzoku = 0

    if renzoku == 3:
        renzoku3 = 1


if renzoku3 == 1:
    print("Yes")
else:
    print("No")


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

double getDistance(pair<int, int> a, pair<int, int> b)
{
    return sqrt((double)(a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}

int main()
{
    int n;
    pair<int, int> points[10];

    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>points[i].first>>points[i].second;
    }

    double sol = 0;
    for(int i = 0 ; i < n ; i++){
        for(int j = i + 1 ; j < n ; j++){
            sol += getDistance(points[i], points[j]);
        }
    }

    cout << fixed << setprecision(10) <<  sol * 2 / n;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,i,c=0;
    string s;
    cin>>s;
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')
        c=3;
    else if(s[0]=='R'&&s[1]=='R')
        c=2;
    else if(s[1]=='R'&&s[2]=='R')
        c=2;
        else if(s[0]=='R'||s[1]=='R'||s[2]=='R')
            c=1;
    cout<<c;
}


Measured memory_bytes: 3608
import java.util.*;
public class Main{
  public static void main(String[] augs){
    Scanner sc = new Scanner(System.in);
    int count = 0;
    int max_hight = 0;
    int n = sc.nextInt();
    
    for (int i=1; i<=n; i++){
      int h = sc.nextInt();
      if (h >= max_hight){
        max_hight = h;
        count++;
      }
    }
    
    System.out.println(count);
  }
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include<string.h>
const int N=110;
using namespace std;
int n,m,ans;
vector<int>a[N];
int p[N],q[N];
bool vis[N];
 
void dfs(int x){
    if(x==n+1){
        memset(q,0,sizeof(q));
        for(int i=1;i<=n;i++){
            if(!vis[i]) continue;
            for(int j=0;j<a[i].size();j++){
                int b=a[i][j];
                q[b]++;
            }
        }
        for(int i=1;i<=m;i++) if(q[i]%2!=p[i]) return ;
        ans++;
        return ;
    }
    dfs(x+1);vis[x]=true;
    dfs(x+1);vis[x]=false;
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int k;
        cin>>k;
        for(int j=0;j<k;j++){
            int t;cin>>t;
            a[t].push_back(i);
        }
    }
    for(int i=1;i<=m;i++) scanf("%d",&p[i]);
    dfs(1);
    cout<<ans<<endl;
    return 0;
}
 


Measured memory_bytes: 256
from collections import Counter
import sys

h, w = map(int, input().split())
arr = [list(map(str, input().rstrip())) for _ in range(h)]

arr = sum(arr, [])

c = Counter(arr)
c = list(c.values())

if h % 2 == 0 and w % 2 == 0:
    ans = all([x % 4 == 0 for x in c])  # 全て4個セットならOK

elif h % 2 == 1 and w % 2 == 1:
    even = (h + w) // 2 - 1  # 2個セットを許容できる個数
    odd_cnt = len([x for x in c if x % 2 == 1])
    if odd_cnt != 1:
        print("No")
        sys.exit()
    odd = sum([x for x in c if x % 2 == 1])
    if odd % 4 == 3:
        even -= 1
    c.remove(odd)
    # 2個セットが許容数以下か
    ans = True if sum([x % 4 == 2 for x in c]) <= even else False
    ans &= all([x % 4 == 0 for x in c if x % 4 != 2])  # 残り全て4個セットか

else:
    even = h // 2 if h % 2 == 0 else w // 2  # 2個セットを許容できる個数
    # 2個セットが許容数以下か
    ans = True if sum([x % 4 == 2 for x in c]) <= even else False
    ans &= all([x % 4 == 0 for x in c if x % 4 != 2])  # 残り全て4個セットか

print("Yes" if ans else "No")

Measured memory_bytes: 9516
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <functional>

using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> v(n);
  for (int i=0;i<n;i++){
    cin >> v[i];
  }
  
  int ans1, ans2, ans3;
  vector<int> ansv(n);
  
  for (int i=0;i<n;i++){
    ans1 = std::accumulate(v.begin(), v.begin()+i, 0);
    ans2 = std::accumulate(v.begin()+i, v.end(), 0);
    ansv[i] = abs(ans1 - ans2);
    //cout << ansv[i] << endl;
  }
  int min = *std::min_element(ansv.begin(), ansv.end());
  cout << min << endl;  
  return 0;
}

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

int main(){
	int n;
	scanf("%d", &n);
	int min = INT_MAX, max = 0;
	for (int i = 0, x; i < n; ++ i){
		scanf("%d", &x);
		min = std::min(min, x);
		max = std::max(max, x);
	}
	return printf("%d\n", max - min), 0;
}

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

int main(){ 
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> b(n+1,0);
  for (int i = 0; i < n; i++) {
    b[a[i]]++;
  }
  vector<ll> cnt(n+1,0);
  map<int,ll> mp3;
  ll sum = 0;
  for (int i = 0; i <= n; i++) {
    if (b[i] == 0) continue;
    ll d = b[i];
    cnt[i] = (d * (d - 1)) / 2;
    sum += cnt[i];
    d--;
    mp3[i] = max(0LL, (d * (d - 1)) / 2);
  }

  for (int i = 0; i < n; i++) {
    cout << sum + mp3[a[i]] - ((ll)b[a[i]] * (b[a[i]] - 1) / 2) << endl;
  }
  return 0;
} 

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

int main(){
    int n;
    cin>>n;
    vector<int>x(n);
    int mi=100;
    int ma=0;
    for(int i=0; i<n; i++){
        cin>>x.at(i);
        mi=min(mi,x.at(i));
        ma=max(ma,x.at(i));
    }
    int ans=1000000;
    for(int j=mi; j<=ma; j++){
        int sum=0;
        for(int i=0; i<n; i++){
            sum+=pow((j-x.at(i)),2);
        }
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int a[110000];
    REP(i, N) cin >> a[i];
    int dir = 0;
    int ans = 1;
    REP(i, N-1){
        //初期判定
        if (dir == 0){
            if (a[i] - a[i+1] == 0){
                continue;
            } else if (a[i] - a[i+1] < 0){
                dir = 1;
            } else {
                dir = 2;
            }
        }
        //増加の場合
        if(dir == 1){
            if (a[i] - a[i+1] > 0){
                dir = 0;
                ans += 1;
            }
        }
        //減少の場合
        if(dir == 2){
            if (a[i] - a[i+1] < 0){
                dir = 0;
                ans += 1;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>      
#define pb push_back 
#define fr first 
#define sc second
#define MOD 1000000007
#define len(s) s.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define f(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef map<int,int> mii; 

int main() {

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;

    //int t; cin>>t; while(t--) { 
    string s,t;
    cin>>s>>t;
    if(len(s)+1!=len(t)) cout<<"No";
    else {
        f(i,0,len(s)) if(s[i]!=t[i]) {
            cout<<"No";
            return 0;
        }
        cout<<"Yes"; 
    }
    return 0 ;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){

	int l,a,b,c,d,k,j;
	cin>>l>>a>>b>>c>>d;

	k=a/c;
	if(a%c>0){k=k+1;}
	j=b/d;
	if(b%d>0){j=j+1;}

	if(k==j){cout<<l-k<<endl;}
	else if(k>j){cout<<l-k<<endl;}
	else{cout<<l-j<<endl;}

	return 0;
	}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define INF 1e+18
#define ll long long
using namespace std;

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

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

int main() {
    int p[4];
    for (int i = 0; i < 4; i++) {
        std::cin >> p[i];
        if (i % 2 == 1) p[i - 1] *= p[i];
    }
    p[0] = std::max(p[0], p[2]);
    std::cout << p[0] << std::endl;

    return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC044_A_Tak_and_Hotels
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			int k = int.Parse(Console.ReadLine());
			int x = int.Parse(Console.ReadLine());
			int y = int.Parse(Console.ReadLine());

			int result = 0;
			
			if (n <= k)
			{
				result = x * n;
			}
			else
			{
				result = x * k;
				result += y * (n - k);
			}
			
			Console.WriteLine(result);
		}
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;
int N[3], even = 0, mx = 0, ans = 0;
int main(){
  cin >> N[0] >> N[1] >> N[2];
  rep(i, 3) if(N[i]%2 == 0) ++even;
  if(even == 2){
    rep(i, 3) if(N[i]%2 == 0) ++N[i];
    ++ans;
  }else if(even == 1){
    rep(i, 3) if(N[i]%2 != 0) ++N[i];
    ++ans;
  }
  rep(i, 3) mx = max(mx, N[i]);
  rep(i, 3) if(N[i] < mx) ans += (mx-N[i])/2;
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
	{
        int table[11][11]={0};
        if(n==0)
			break;
        for(int i=0,in;i<n;++i)
		{
            for(int j=0;j<n;++j)
			{
                cin>>in;
                table[i][j]=in;
                table[n][j]+=in;
                table[i][n]+=in;
            }
        }
        for(int i=0;i<n;++i)table[n][n]+=table[n][i];
        for(int i=0;i<n+1;++i)
		{
            for(int j=0;j<n+1;++j)printf("%5d",table[i][j]);
            cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
const int N = (int)1e5 + 123;
 
int p[N];
string s[N];
int d[N];
int pen[N];
int n, m;

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();   
	cin >> n >> m;
	int cnt1 = 0, cnt2 = 0;
	for(int i = 1; i <= m; i++)
	{
		cin >> p[i] >> s[i];
		if(!d[p[i]] && s[i] == "WA") pen[p[i]]++;
		if(!d[p[i]] && s[i] == "AC") cnt1++, d[p[i]] = 1;
	}
	cout << cnt1 << ' ';
	for(int i = 1; i <= n; i++) if(d[i]) cnt2 += pen[i];
	cout << cnt2 << endl;
}                                

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

int main()
{
	int n,m;
	cin>>n>>m;
	
	int a[m+1],s=0,ans;
	for(int i=1;i<=m;i++)
	{
		cin>>a[i];
		s+=a[i];
	}
	ans=n-s;
	if(ans<0) 
	cout<<"-1";
	else
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;

int main() {
	int n, max = 0, tmp, pos = 0;
	cin >> n;
	int A[2][100];
	for (int i = 0; i < 2; ++i) {
		for (int k = 0; k < n; ++k) {
			A[i][k] = 0;
		}
	}
	for (int i = 0; i < 2; ++i) {
		for (int k = 0; k < n; ++k) {
			cin >> A[i][k];
		}
	}

	for (int i = 0; i < n; ++i) {
		tmp = 0;
		pos = 0;
		for (int k = 0; k < n; ++k) {
			if (i == k) {
				tmp += A[pos][k];
				pos = 1;
			}
			tmp += A[pos][k];
		}
		if (max < tmp) max = tmp;
	}
	cout << max << endl;
	return 0;
	
}

Measured memory_bytes: 256
N,M = map(int, input().split())

ans = set([0])
cnt = [1] * N
for _ in range(M):
    x,y = [int(i) - 1 for i in input().split()]
    cnt[x] -= 1; cnt[y] += 1
 
    if x in ans:
        ans.add(y)
        if cnt[x] == 0: # 絶対に赤いボールがyに移される
            ans.remove(x)
 
print(len(ans))

Measured memory_bytes: 12652
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-7
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

class AccumulSum {
public:
	AccumulSum(int h,int w,vector<vector<ll> >& a) {
		_h=h;
		_w=w;
		_sum.resize(_h+1);
		for(int i=0; i<_h+1; ++i) {
			_sum[i].resize(_w+1);
			for(int j=0; j<_w+1; ++j) {
				if(i==0||j==0) _sum[i][j]=0;
				else _sum[i][j]=a[i-1][j-1];
			}
		}
		for(int i=0; i<_h+1; ++i) {
			for(int j=1; j<_w+1; ++j) _sum[i][j]+=_sum[i][j-1];
		}
		for(int i=0; i<_w+1; ++i) {
			for(int j=1; j<_h+1; ++j) _sum[j][i]+=_sum[j-1][i];
		}
	}
	// the coordinates of ul and dr should be 0-indexed
	long long query(pair<int,int> ul,pair<int,int> dr) {
		ll ret=0;
		ret+=_sum[dr.first+1][dr.second+1];
		ret-=_sum[dr.first+1][ul.second];
		ret-=_sum[ul.first][dr.second+1];
		ret+=_sum[ul.first][ul.second];
		return ret;
	}
private:
	int _h;
	int _w;
	vector<vector<ll> > _sum;
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,m,q;
	cin>>n>>m>>q;
	vector<vector<ll>> s(n,vector<ll>(m));
	REP(i,n) REP(j,m) {
		char g;
		cin>>g;
		s[i][j]=(g-'0');
	}
	AccumulSum acm1(n,m,s);
	vector<vector<ll>> a1(n,vector<ll>(m-1,0));
	vector<vector<ll>> a2(n-1,vector<ll>(m,0));
	REP(i,n) REP(j,m-1) if(s[i][j]==1&&s[i][j+1]==1) a1[i][j]=1;
	REP(i,n-1) REP(j,m) if(s[i][j]==1&&s[i+1][j]==1) a2[i][j]=1;
	AccumulSum acm2(n,m-1,a1);
	AccumulSum acm3(n-1,m,a2);
	REP(i,q) {
		P z1,z2;
		cin>>z1.first>>z1.second>>z2.first>>z2.second;
		z1.first--; z1.second--;
		z2.first--; z2.second--;
		ll v=acm1.query(z1,z2);
		ll e=0;
		if(z1.second<m-1) e+=acm2.query(z1,P(z2.first,z2.second-1));
		if(z1.first<n-1) e+=acm3.query(z1,P(z2.first-1,z2.second));
		cout<<v-e<<endl;
	}
}


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

using namespace std;

const int N = 1e5+100;

int n, a[N];

bool solve() {
    if(n == 1) {
        return a[0] & 1;
    }
    int hav1 = 0, odd = 0, even = 0, sum = 0;
    for(int i = 0 ; i < n ; i++ ) {
        if(a[i] & 1) odd++;
        else even++;
        if(a[i] == 1)hav1++;
        sum = (sum + a[i]) % 2;
    }
    if(hav1) {
        return !((sum - n) & 1);
    }
    if(odd == n) return 1;
    if(even == 1) return 0;
    if(odd > 1) return !(even & 1);
    if(even & 1) return 0;
    for(int i = 0 ; i < n ; i++ ) {
        if(a[i] & 1) if(a[i] > 1)a[i]--;
    }
    int gc = a[0];
    for(int i = 0 ; i < n ; i++ ) {
        gc = __gcd(a[i], gc);
    }
    for(int i = 0 ; i < n ; i++ ) {
        a[i] /= gc;
    }
    return !solve();
}

int main () {
    cin >> n;
    for(int i = 0 ; i < n ; i++ ) {
        cin >> a[i];
    }
    cout << ((!solve()) ? "First" : "Second") << '\n';
}


Measured memory_bytes: 4020
A, B, C, X, Y = [int(_) for _ in input().split()]
ans = A * X + B * Y
for i in range(max(X, Y) + 1):
    cost = 2 * C * i
    if X > i:
        cost += A * (X - i)
    if Y > i:
        cost += B * (Y - i)
    ans = min(ans, cost)
print(ans)

Measured memory_bytes: 3064
#B
s=input()
n=len(s)

def kai(l,r):
    ss=s[l:r+1]
    nn=len(ss)
    #print(ss)
    if nn==1:
        return 'Yes'
    else:
        for i in range(int((nn-1)/2)):
            if ss[i]==ss[nn-i-1]:
                if i==int((nn-1)/2)-1:
                    return 'Yes'
            else:
                return 'No'
                break

if kai(0,n-1)=='Yes':
    if kai(0,int((n-1)/2)-1)=='Yes':
        if kai(int((n+3)/2)-1,n-1)=='Yes':
           print('Yes')
    else:
        print('No')
else:
    print('No')
    

Measured memory_bytes: 3064
N, M = map(int, input().split())
import math

ans = 0

if N == 0 or N == 1:
  ans += 0
else:
  ans += N*(N-1)/2
  
if M == 0 or M == 1:
  ans += 0
else:
  ans += M*(M-1)/2  

print(math.floor(ans))

Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>
int abs(int n){
    if(n > 0){
        return n;
    } else {
        return -n;
    }
}


int main(){
   int n;
   int max = 0;
   scanf("%d", &n);
   int w[n];
   for(int i = 0; i < n; i++){
       scanf("%d", &w[i]);
       max += w[i];
   }

   int min=max;
   int a, b = 0;
   for(int i = 0; i < n; i++){
       a = 0;
       b = 0;
       for(int j = 0; j <= i; j++){
           a += w[j];
       }
       for(int j = i+1; j < n; j++){
           b += w[j];
       }
       
      // printf("%d %d\n", a, b);
       if(abs(a-b)< min){
           min = abs(a-b);
       }
   }
   printf("%d", min);
   return 0;
}

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

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
    int X,Y;
    cin >> X >> Y;
    int A,B,C;
        A = 300000;
        B = 200000;
        C = 100000;
    if(X == 1 && Y == 1) cout << 1000000 <<endl;
    else if(X < 4 && Y < 4){
        if(X == 1 && Y == 2) cout << A + B <<endl;
        if(X == 1 && Y == 3) cout << A + C <<endl;
        if(X == 2 && Y == 1) cout << A + B <<endl;
        if(X == 2 && Y == 2) cout << B + B <<endl;
        if(X == 2 && Y == 3) cout << C + B <<endl;
        if(X == 3 && Y == 1) cout << A + C <<endl;
        if(X == 3 && Y == 2) cout << C + B <<endl;
        if(X == 3 && Y == 3) cout << C + C <<endl;
    }
    else if(X < 4 && Y > 3){
        if(X == 1) cout << A <<endl;
        if(X == 2) cout << B <<endl;
        if(X == 3) cout << C <<endl;
    }
    else if(Y < 4 && X > 3){
        if(Y == 1) cout << A <<endl;
        if(Y == 2) cout << B <<endl;
        if(Y == 3) cout << C <<endl;
    }
    else cout << 0 <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"



signed main()
{
    FAST;
    int t;
    t=1;
    
    while(t--)
    {
        int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
        int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
        int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
        int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
        int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
        
        cin>>x;
        temp = __gcd((int)360,x);
        
        ans = 360/temp;
        cout<<ans<<endl;
        
        
    }
        
    
    
    
    
}

Measured memory_bytes: 3632