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

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}


void solve(){
     int ok1 = 0;
     int ok2 = 0;
     string s;cin >> s;
     REP(i,s.size()){
      if(s[i] == '1')ok1++;
      else ok2++;
     }
     cout << min(ok1,ok2)*2;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;//cin >> t;
  WL(t)solve();
  return 0;
}

Measured memory_bytes: 512
#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 K; cin >> K;
	int A = 7;

	REP(i, K * 10) {
		if (A%K == 0) {
			cout << i + 1 << endl;
			return 0;
		}
		A *= 10;
		A += 7;
		A %= K;
	}



	cout << -1 << endl;

	return 0;
}



Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using static Prog;
using NX = System.Int64;

public class Solver
{
    public void Solve()
    {
        int N = NextInt();
        Console.WriteLine(N / 2 + N % 2);
    }
}

public class Prog
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    public struct Pair { public int x, y; public Pair(int a, int b) { x = a; y = b; } }
    static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        new Solver().Solve();
        Console.Out.Flush();
        return;
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}


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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;
typedef vector<ll> VL;

const int N = 20000;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int x, y;
    cin >> s >> x >> y;
    int n = s.size();

    bool is_x = true;
    VI dx(1, 0), dy(1, 0);
    REP(i, s.size()) {
        if(s[i] == 'T') {
            is_x = !is_x;
            if(dx.back() > 0) dx.push_back(0);
            if(dy.back() > 0) dy.push_back(0);
        } else {  // F
            if(is_x) dx.back()++;
            else dy.back()++;
        }
    }
    if(dx.back() == 0) dx.pop_back();
    if(dy.back() == 0) dy.pop_back();

    vector<vector<bool>> dpx(dx.size() + 1, vector<bool>(N * 2 + 1, false));
    if(dx.size() == 0) {
        dpx[0][N + 0] = true;
    } else {
        if(s[0] == 'F') {
            dpx[1][N + dx[0]] = true;
        } else {
            dpx[1][N + dx[0]] = true;
            dpx[1][N - dx[0]] = true;
        }
    }
    FOR(i, 1, dx.size() - 1)FOR(j, -n, n)
        dpx[i + 1][N + j] = dpx[i][N + j - dx[i]] or dpx[i][N + j + dx[i]];

    vector<vector<bool>> dpy(dy.size() + 1, vector<bool>(N * 2 + 1, false));
    dpy[0][N + 0] = true;
    FOR(i, 0, dy.size() - 1)FOR(j, -n, n)
        dpy[i + 1][N + j] = dpy[i][N + j - dy[i]] or dpy[i][N + j + dy[i]];

    cout << (dpx[dx.size()][N + x] and dpy[dy.size()][N + y] ? "Yes" : "No") << ln;

    return 0;
}


Measured memory_bytes: 20096
import sys
sys.setrecursionlimit(10**7)

MOD = 1000000007
N, K = map(int, input().split())
edges = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    edges[a].append(b)
    edges[b].append(a)

colors = [K] + [0 for _ in range(N-1)]


def dfs(parent, edge, n):
    for child in edges[edge]:
        if child != parent:
            colors[child] = max(0, n)
            n -= 1
            dfs(edge, child, K-2)


def solve():
    dfs(0, 0, K-1)
    
    ans = K
    for color in colors[1:]:
        ans *= color
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    solve()


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

typedef pair<int, int> P;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int N; cin >> N;
    int sum = 0;
    bool ok = true;
    REP( i, N ){
        string s; cin >> s;
        if( s == "A" ){
            sum++;
        }else if( s == "Un" ){
            sum--;
        }
        if( sum < 0 ) ok = false;
    }
    if( sum > 0 ) ok = false;
    cout << ( ok ? "YES" : "NO" ) << endl;
}



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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b) cout << c << endl;
    else if (b == c) cout << a << endl;
    else cout << b << endl;

    return 0;
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

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

  vector<vector<bool>> Ss(1000, (vector<bool> (1000, false)));

  rep(i, (int)(T.size()-S.size()+1)){
    //cout << 22 << endl;
    rep(k, (int)S.size()) if(S[k] == T[i]){
      rep(j, (int)S.size()){
        if(S[j]==T[i+j]){
          Ss.at(i).at(j) = true;
        }
        //cout << Ss.at(i).at(j)<<endl;
      }
    }
  }

  int max=0;
  int max_val;
  rep(i, 1000){
    int now = count(Ss.at(i).begin(), Ss.at(i).end(), true);
    if(now > max) max=now;
  }

  max_val=(int)S.size() - (int)max;
  cout << max_val <<endl;
}


Measured memory_bytes: 3800
x,y = map(int,input().split())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


  
if (x+y)%3 !=0 :
  print(0)
else:  
  mod = 10**9+7 #出力の制限
  N = 10**6
  g1 = [1, 1] # 元テーブル
  g2 = [1, 1] #逆元テーブル
  inverse = [0, 1] #逆元テーブル計算用テーブル    

  for i in range( 2, N + 1 ):
      g1.append( ( g1[-1] * i ) % mod )
      inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
      g2.append( (g2[-1] * inverse[-1]) % mod )

  move = (x+y)//3
  lx = x-move
  n = cmb(move,lx,mod)  
        
  print(n%(10**9+7))  

Measured memory_bytes: 122016
#include<cstdio>

int main()
{
	int h,n,s=0;
	scanf("%d%d",&h,&n);
	while(n--)
	{
		int x;
		scanf("%d",&x);
		s+=x;
	}
	printf("%s\n",h<=s?"Yes":"No");
	return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]

MOD = 10**9+7

def dot(A, B):
    N = len(A)
    K = len(A[0])
    assert len(B) == K
    M = len(B[0])
    C = [[0] * M for _ in range(N)]
    for i in range(N):
        for j in range(M):
            for k in range(K):
                C[i][j] += A[i][k] * B[k][j]
            C[i][j] %= MOD
    return C



def mp(A, n):
    assert len(A) == len(A[0])
    B = [[0] * len(A) for _ in range(len(A))]
    for i in range(len(A)):
        B[i][i] = 1

    while n:
        n, i = divmod(n, 2)
        if i:
            B = dot(A, B)
        A = dot(A, A)

    return B


ans = sum([sum(r) % MOD for r in mp(A, K)]) % MOD
print(ans)


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

vector<int> g[200005];
vector<int> ans;
bool vis[200005];
void dfs(int s,int& cnt){
	if(vis[s]) return;
	vis[s] = true;
	cnt++;
	for(int i=0;i<g[s].size();i++){
		if(vis[g[s][i]]) continue;
		dfs(g[s][i],cnt);
	}
}
int main(int argc, char * argv[]) 
{
	int n,m,a,b;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	memset(vis,0,sizeof(vis));
	for(int i=0;i<n;i++){
		if(!vis[i]){
			int cnt = 0;
			dfs(i,cnt);
			ans.push_back(cnt);
			//printf("i=%d,cnt=%d\n",i,cnt);
		}
	}
	int realAns = ans[0];
	for(int i=0;i<ans.size();i++)
		realAns = max(realAns,ans[i]);
	cout<<realAns<<endl;
    return 0;
}

Measured memory_bytes: 24020
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c;
  int cnt1=0,cnt2=0;
  while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
    if((a*a+b*b)==c*c) cnt1++;
    if(a==b) cnt2++;
  }
  cout << cnt1<<endl;
  cout << cnt2<<endl;
  return 0;
}

Measured memory_bytes: 1208
package main

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

func main() {
	mod := int64(math.Pow10(9) + 7)
	N := nextInt64()
	K := nextInt64()
	M := N - K

	for i := int64(1); i <= K; i++ {
		fmt.Println(combi(M+1, i, mod) * combi(K-1, i-1, mod) % mod)
	}
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}

var combiMemo = map[int64]map[int64]int64{}

func combi(n, r, mod int64) int64 {
	if n < r {
		return 0
	}

	m, ok1 := combiMemo[n]

	if !ok1 {
		m = map[int64]int64{}
		combiMemo[n] = m
	}

	var c int64 = 1

	for i := n; i >= (n - r + 1); i-- {
		c = mulm(c, i, mod)
	}
	for i := r; i >= 1; i-- {
		c = divm(c, i, mod)
	}
	combiMemo[n][r] = c
	return c % mod
}

func addm(a, b, mod int64) int64 {
	return (a + b) % mod
}

func subm(a, b, mod int64) int64 {
	return (a - b + mod) % mod
}

func mulm(a, b, mod int64) int64 {
	return (a * b) % mod
}

func divm(a, b, mod int64) int64 {
	return mulm(a, invm(b, mod), mod)
}

func invm(a, mod int64) int64 {
	b := mod
	u := int64(1)
	v := int64(0)

	for b > 0 {
		t := a / b

		a -= t * b
		a, b = b, a

		u -= t * v
		u, v = v, u
	}

	return (u + mod) % mod
}


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

typedef long long ll;
 
int main(){
    int N;
    cin >> N;
    vector<ll> a(N);
    vector<ll> b(N);

    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    b = a;
    sort(a.begin(),a.end());
    ll small = a[N/2];ll big = a[N/2-1];
    for(int i=0;i<N;i++){
        if(b[i]<=big){
            cout << small << endl;
        }else{
            cout << big << endl;
        }
    }
}

Measured memory_bytes: 5376
N,X=map(int,input().split())
L = list(map(int,input().split()))

CUMSUM = []
c = 0
for i in L:
    if c <= X:
        CUMSUM.append(c)
        c += i
if c <= X:
    CUMSUM.append(c)

print(len(CUMSUM[:X]))

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
ll f(ll b, ll n){
	if(n<b) return n;
	else return f(b,n/b)+n%b;
}
int main(){
	ll n,s;
	scan(n);scan(s);
	/*for(ll b=2;b<=n;b++){
		printf("b:%lld wa:%lld keta:%d 2:%d 1:%d\n",b,f(b,n),(int)(log(n)/log(b))+1,n/b,n%b);
	}*/
	if(s>n) prin(-1);
	else if(s==n) prin(n+1);
	else{
		ll b;
		int flag=0;
		for(b=2;b<=min((ll)1000000,n+1);b++){
			if(f(b,n)==s){
				flag=1;
				break;
			}
		}
		if(flag) prin(b);
		else if(n>1000000){
			for(ll A=n/b;A>=1;A--){
				if(!((double)(n+1)/(A+1)<=n/A&&n/A<=(double)n/A)) continue;
				ll minb=(n+1)/(A+1)+((n+1)%(A+1)!=0);
				ll smax=A+n%minb,smod=smax%A;
				if(s>=A&&s<=smax&&(s-A)%A==smod){
					ll ans=minb+(n%minb-(s-A))/A;
					prin(ans);
					//prin(f(ans,n));
					return 0;
				}
			}
			prin(-1);
		}
		else prin(-1);
	}
	return 0;
}


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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef pair<ll, ll> pint;


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

class Dice
{
public:
  vint num;


  Dice(vint num);
  void roll(char d);
  ll top();
  ll front();
  ll left(){return num[3];}
  ll right(){return num[2];}
  ll right(ll top, ll front);
  bool check(const Dice &obj){
    rep(i,6){
      if(this->num[i] != obj.num[i]) return false;
    }
    return true;
  }

  void rotate(){
    this->roll('E');
    this->roll('N');
    this->roll('W'); // rotate clockwise
  }

  bool operator ==(Dice obj){

    rep(i,4){
      rep(j,4){
        if(obj.check(*this)) return true;
        obj.rotate();
      }
      obj.roll('E');   
    }

    obj.roll('S');
    rep(j,4){
      if(obj.check(*this)) return true;
      obj.rotate();
    }

    obj.roll('N');
    obj.roll('N');

    rep(j,4){
      if(obj.check(*this)) return true;
      obj.rotate();
    }


    return false;
  }




};

Dice::Dice(vint num){
  this->num = num;
}

void Dice::roll(char d){
  vint tmp_num = num;
  if(d == 'E'){
    num[2] = tmp_num[0];
    num[0] = tmp_num[3];
    num[3] = tmp_num[5];
    num[5] = tmp_num[2];
  }else if(d == 'N'){
    num[0] = tmp_num[1];
    num[1] = tmp_num[5];
    num[5] = tmp_num[4];
    num[4] = tmp_num[0];
  }else if(d == 'S'){
    num[0] = tmp_num[4];
    num[4] = tmp_num[5];
    num[5] = tmp_num[1];
    num[1] = tmp_num[0];
  }else if(d == 'W'){
    num[0] = tmp_num[2];
    num[2] = tmp_num[5];
    num[5] = tmp_num[3];
    num[3] = tmp_num[0];
  }else{
    assert(false);
  }
  // cout<<d<<endl;

}

ll Dice::top(){
  return num[0];
}

ll Dice::front(){
  return num[1];
}

ll Dice::right(ll top, ll front){
  
  ll cnt = 0;
  while(this->top() != top && cnt < 4){
    this->roll('E');
    cnt++;
  }
  cnt = 0;
  while(this->top() != top && cnt < 4){
    this->roll('N');
    cnt++;
  }

  cnt = 0;
  while(this->front() != front && cnt < 4){
    this->rotate();
    cnt++;
  }

  assert(this->top() == top && this->front() == front);

  return this->right();
}


void print(const vint& v)
{
  std::for_each(v.begin(), v.end(), [](int x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}

int main() {


  cout<<fixed<<setprecision(10);

  vint v1(6), v2(6);
  rep(i,6)cin>>v1[i];
  rep(i,6)cin>>v2[i];


  Dice d1 = Dice(v1);
  Dice d2 = Dice(v2);

  if(d1 == d2)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}





//




Measured memory_bytes: 3160
#include<iostream>
#include<string>
#include<map>
int main(){
        std::map<std::string,int> weekday{
                {"SUN",0},
                {"MON",1},
                {"TUE",2},
                {"WED",3},
                {"THU",4},
                {"FRI",5},
                {"SAT",6}};
        std::string S;
        std::cin >> S;
        std::cout << 7 - weekday[S];
}

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

vector<int> switches, p;
vector<vector<int>> s;
int cnt = 0;

void check(){
    rep(i, s.size()){
        int on_num = 0;
        rep(j, s[i].size()){
            if(switches[s[i][j]] == 1){
                on_num ++;
            }
        }
        if(on_num % 2 != p[i])
            return;
    }
    cnt++;
}

int cluc(int id){
    switches[id] = 0;
    if(id + 1 != switches.size())
        cluc(id + 1);
    else{
        check();
    }

    switches[id] = 1;
    if(id + 1 != switches.size())
        cluc(id + 1);
    else{
        check();
    }
}

int main(void){
    int n, m;
    cin >> n >> m;

    int k[m], tmp;

    rep(i, m){
        cin >> k[i];
        s.emplace_back();
        rep(j, k[i]){
            cin >> tmp;
            tmp--;
            s[i].push_back(tmp);
        }
    }

    rep(i, m){
        cin >> tmp;
        p.push_back(tmp);
    }

    rep(i, n)
        switches.push_back(0);

    cluc(0);

    cout << cnt << endl;
    return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1001001001;

int main() {
    int n;
    cin >> n;
    int count = 0;
    for (int i = 0; i < n; i++) {
        int c;
        cin >> c;
        if (c != i + 1) {
            count++;
        }
    }

    if (count == 0 || count == 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n);
    map<lint, lint> cnt;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    lint tot = 0;
    for (auto &p : cnt) {
        tot += p.second * (p.second - 1) / 2;
    }
    for (int i = 0; i < n; ++i) {
        lint ret = tot;
        ret -= cnt[a[i]] * (cnt[a[i]] - 1) / 2;
        ret += (cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2;
        cout << ret << "\n";
    }
    return 0;
}

Measured memory_bytes: 13144
#include<bits/stdc++.h>
//#include"atcoder/all"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
//using namespace atcoder;
typedef long long ll;
const ll mod = 1000000007;
int main(){
  ll N,i,a,ans = 1;scanf("%lld",&N);
  ll C[3] = {};
  for(i=0;i<N;i++){
    scanf("%lld",&a);
    ans = ans*(ll(C[0]==a)+(C[1]==a)+(C[2]==a))%mod;
    if(C[0] == a) C[0]++;
    else if(C[1] == a) C[1]++;
    else if(C[2] == a) C[2]++;
    else{
      printf("0\n");return 0;
    }
  }
  printf("%lld\n",ans);
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

//ａをbで割る
long long mod_div(long long a,long long b){
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}

#define MAX_K 2222222
vector<long long> fact(MAX_K);
long long combination(long long n, long long r){
    if(n < r || n < 0 || r < 0)
        return 0;
	if(fact[0] != 1){
		fact[0] = 1;
		for(long long i = 1;i < MAX_K;i++)fact[i] = (fact[i-1] * i) % MOD;
	}
    long long ret = fact[n];
	long long tmp = (fact[r] * fact[n-r]) % MOD;
    return mod_div(ret,tmp);
}

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

	ll x, y;cin >> x >> y;

	for(ll i = 0;i <= 1000000;i++){
		ll a = x - i;
		ll b = y - 2 * i;
		if(a == b*2){
			cout << combination(i + b, i) << endl;
			return 0;
		}
	}

	cout << 0 << endl;

	return 0;
}


Measured memory_bytes: 17664
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include<random>
#include<iostream>
using namespace std;

int main() {
	int N;
	cin >> N;
	for(int i=0;i<50000;i++){
		if(N*100 <= i*108 && i*108 < (N+1)*100){
			cout << i << "\n";
			return 0;
		}
	}
	cout << ":(\n";
}

Measured memory_bytes: 256
from math import factorial
from itertools import permutations


def dist(t1, t2):
    return ((t1[0] - t2[0])**2+(t1[1] - t2[1])**2)**0.5


N = int(input())
l_cities = [None] * N

for i in range(N):
    l_cities[i] = tuple(map(int, input().split()))

perm_l = permutations(list(range(N)))

summ = 0

for l_p in perm_l:
    for i in range(1, N):
        summ += dist(l_cities[l_p[i-1]], l_cities[l_p[i]])
    
avg_mean = summ / factorial(N)
print(avg_mean)


Measured memory_bytes: 40940
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int a,b,c;
    cin >> a >> b >> c;
    cout << (b)/c - (a-1)/c << endl;
}

Measured memory_bytes: 3624
s=input()
ss=[]
if(s[0]=='A'):
    if('C' in s[2:-1]):
        a=s.find('A')
        b=s.find('C')
        if(s[a+1:b].islower() and s[b+1:].islower()):
            print('AC')
        else:
            print('WA')
    else:
        print('WA')
else:
    print('WA')

Measured memory_bytes: 3060
n, m = map(int, input().split())

a_li =[]
for i in range(n):
    li = input().split()
    del li[0]
    a_li += li

count_li =[]
for o in range(m+1):
    x = a_li.count(str(o))
    count_li.append(int(x))
    
print(count_li.count(n))

Measured memory_bytes: 3060
#include <stdio.h>
#define N 500000

void merge(int *, int, int, int);
void mergeSort(int *, int, int);

int cnt=0;

int main()
{
  int n,A[N],i;

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

  mergeSort(A, 0, n);

  for(i=0;i<n;i++){    
    if(i != 0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",cnt);

  return 0;

}

void merge(int A[],int left,int mid,int right)
{
  int n1,n2,i,j,k;
  int L[N],R[N];

  n1 = mid -left;
  n2 = right -mid;

  for(i=0;i<n1;i++){
    L[i] = A[left + i];
  }
  for(i=0;i<n2;i++){
    R[i] = A[mid + i];
  }
  L[n1] = 1000000005;
  R[n2] = 1000000005;
  i = 0;
  j = 0;

  for(k=left;k<right;k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else{
      A[k] = R[j];
      j = j + 1;
    }
    cnt++;
  }
}

void mergeSort(int A[],int left,int right)
{
  int mid;
  if((left+1) < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

Measured memory_bytes: 5584
#include <bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;


int main(){
	

	int r; std::cin >> r;
	std::cout << 3 * r * r;


	return 0;
}

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

using namespace std;

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

	int n, k;
	string s;
	cin >> n >> k >> s;
	s[k - 1] = tolower(s[k - 1]);
	cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

			boolean aflg = "H".equals(a);
			boolean bflg = "H".equals(b);


			if(aflg){
				System.out.println(bflg?"H":"D");
			} else {
				System.out.println(!bflg?"H":"D");
			}
		}
	}
}

Measured memory_bytes: 19924
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#include <assert.h>
#define FOR(i,a,n) for(i=(a);i<(n);i++)
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define MOD 1000000007
#define SIZE 100005
#define LOCAL
#ifdef LOCAL
    #define DEBUG(...) printf(" "__VA_ARGS__)
#else
    #define DEBUG(...)
#endif /* LOCAL */
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
int dist[10][10];
int main(void)
{
	int h,w,t,res=0,i,j,k;
	scanf("%d%d",&h,&w);
	FOR(i,0,10){
		FOR(j,0,10){
			scanf("%d",&dist[i][j]);
		}
	}
	FOR(k,0,10){
		FOR(i,0,10){
			FOR(j,0,10){
				dist[i][j]=MIN(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	FOR(i,0,h){
		FOR(j,0,w){
			scanf("%d",&t);
			if(t<0) continue;
			res+=dist[t][1];
		}
	}
	printf("%d\n",res);
	return 0;
}
    
    


Measured memory_bytes: 128
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

//Huge Family
public class Main{

	int n, MOD = 10007;
	int[][] e, f;
	boolean[] v;
	
	int bfs(int s){
		v[s] = true;
		int max = -1, c = 0;
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(s);
		while(!q.isEmpty()){
			int p = q.poll();
			for(int i=0;i<2;i++){
				if(max<f[p][i]){
					max = f[p][i]; c = 1;
				}
				else if(max==f[p][i])c++;
				if(!v[e[p][i]]){
					v[e[p][i]] = true; q.add(e[p][i]);
				}
			}
		}
		return (c/2)%MOD;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			n = sc.nextInt();
			if(n==0)break;
			e = new int[n][2]; f = new int[n][2];
			for(int i=0;i<n;i++)for(int j=0;j<2;j++){
				e[i][j] = sc.nextInt(); f[i][j] = sc.nextInt();
			}
			v = new boolean[n];
			int res = 1;
			for(int i=0;i<n;i++)if(!v[i])res=(res*bfs(i))%MOD;
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

#define int long long int

constexpr int INF = std::numeric_limits<int>::max();

int cnt[100001];

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K; cin >> N >> K;

    vector<pair<int, int>> V;
    while (N--) {
        int t, d; cin >> t >> d;
        V.emplace_back(d, t);
    }

    sort(V.begin(), V.end(), greater<pair<int, int>>());

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> queue;
    int base = 0;
    int x = 0;
    for (int i = 0; i < K; i++) {
        int d = V[i].first;
        int t = V[i].second;
        queue.emplace(V[i]);

        base += d;
        if (cnt[t]++ == 0) {
            x++;
        }
    }

    int ans = base + x * x;

    int idx = K;
    int lim = queue.size();
    for (int i = 0; i < lim && idx < V.size(); i++) {
        int qd = queue.top().first;
        int qt = queue.top().second;
        queue.pop();

        if (cnt[qt] == 1) {
            continue;
        }
        cnt[qt]--;

        while (idx < V.size() && cnt[V[idx].second] > 0) {
            idx++;
        }
        if (idx == V.size()) {
            break;
        }

        int vd = V[idx].first;
        int vt = V[idx].second;
        idx++;

        cnt[vt] = 1;
        x++;

        base = base - qd + vd;
        ans = max(ans, base + x * x);
    }

    cout << ans << endl;
}

Measured memory_bytes: 5744
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ldouble = long double;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;


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

	string res = "APPROVED";
	for (ll i = 0; i < n; i++)
	{
		ll a;
		cin >> a;

		if (a % 2 == 0)
		{
			if (!(a % 3 == 0 || a % 5 == 0))
			{
				res = "DENIED";
			}
		}
	}

	println(res);
}

Measured memory_bytes: 3576
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}



int main() {
	ll A, B,an=0;
	cin >> A >> B;
	for (ll i = A; i <= B; i++) {
		if (i % 10 == i / 10000 && (i / 1000) % 10 == (i % 100) / 10) {
			an++;
		}
	}
	cout << an << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
#include <fstream>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

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

void chmin(ll& x, ll y) {
	x = min(x, y);
}

void chmax(ll& x, ll y) {
	x = max(x, y);
}

ll pow_long(ll x, ll y) {
	ll res = 1;
	while (y > 0) {
		if (y % 2 == 1) res *= x;
		x *= x;
		y /= 2;
	}
	return res;
}

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 1000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

ll n, ans;

void solve() {
	cin >> n;
	for (ll i = 1; i <= n; i++) {
		if (i % 3 == 0 || i % 5 == 0) continue;
		ans += i;
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T = 1;
	//cin >> T;
	rep(i, T) solve();
}


Measured memory_bytes: 3200
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


class BinaryNode:
    def __init__(self, node, left, right):
        self.node = node
        self.left = left
        self.right = right


class BinaryTree:
    def __init__(self, N):
        self.tree = [-1] * N
        self.parent = [-1] * N

    def insert_node(self, N, node):
        self.tree[N] = node
        if node.left is not None:
            self.parent[node.left] = N
        if node.right is not None:
            self.parent[node.right] = N

    def get_root(self):
        for n in range(len(self.parent)):
            if self.parent[n] == -1:
                return n

    def preorder(self, N):
        ret = [N]
        if self.tree[N].left is not None:
            ret.extend(self.preorder(self.tree[N].left))
        if self.tree[N].right is not None:
            ret.extend(self.preorder(self.tree[N].right))
        return ret

    def inorder(self, N):
        ret = []
        if self.tree[N].left is not None:
            ret.extend(self.inorder(self.tree[N].left))
        ret.append(N)
        if self.tree[N].right is not None:
            ret.extend(self.inorder(self.tree[N].right))
        return ret

    def postorder(self, N):
        ret = []
        if self.tree[N].left is not None:
            ret.extend(self.postorder(self.tree[N].left))
        if self.tree[N].right is not None:
            ret.extend(self.postorder(self.tree[N].right))
        ret.append(N)
        return ret


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    tree = BinaryTree(N)
    for n in range(N):
        n, left, right = il()
        if left == -1: left = None
        if right == -1: right = None
        tree.insert_node(n, BinaryNode(n, left, right))
    print('Preorder')
    print('', *tree.preorder(tree.get_root()))
    print('Inorder')
    print('', *tree.inorder(tree.get_root()))
    print('Postorder')
    print('', *tree.postorder(tree.get_root()))


if __name__ == '__main__':
    main()



Measured memory_bytes: 7140
#include<bits/stdc++.h>
using namespace std;
#define pb  push_back
#define mod 1000000007
#define INF 1e18
typedef  long long ll;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t;
	cin >> t;
	string s="";
	while (t--)
	{
		s+="ACL";
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        System.out.println(s.next().substring(0,1).toUpperCase()+s.next().substring(0,1).toUpperCase()+s.next().substring(0,1).toUpperCase());


    }


}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

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

int fanc(vector<vector<int>> &v, int a, int b, int n){
	v.at(a).at(b) = 0;
	v.at(b).at(a) = 0;
	vector<bool> c(n, false);
	queue<int> q;
	q.push(0);
	c.at(0) = true;
	while(!q.empty()){
		int q_t = q.front(); q.pop();
		rep(i, n){
			if(v.at(q_t).at(i) == 1 && c.at(i) == false){
				c.at(i) = true;
				q.push(i);
			}
		}
	}
	
	int ans = 0;
	rep(i, n){
		if(c.at(i) == false){
			ans = 1;
			break;
		}
	}
	
	v.at(a).at(b) = 1;
	v.at(b).at(a) = 1;
	
	return ans;
}

int main(){
	int n, m, a, b, ans = 0;
	cin >> n >> m;
	vector<vector<int>> v(n, vector<int>(n, 0));
	rep(i, m){
		cin >> a >> b;
		a--;
		b--;
		v.at(a).at(b) = 1;
		v.at(b).at(a) = 1;
	}
	
	rep(i, n){
		for(int j = i+1; j < n; j++){
			if(v.at(i).at(j) == 1){
				ans += fanc(v, i, j, n);
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define Max 200000
#define Min -2000000000;

int main(){
	int i;
	long R[Max];
	long n;
	long max, min;
	scanf("%ld", &n);

	for(i = 0; i < n; i++)
		scanf("%ld", &R[i]);
	max = Min;
	min = R[0];
	for(i = 1; i < n; i++) {
		max = max > R[i] - min ? max : R[i] - min;
		min = min < R[i] ? min : R[i]; 
	}

	printf("%ld\n", max);
    return 0;
}

Measured memory_bytes: 2160
#include<stdio.h>

int main(void){
  int a, b, cal, i;
 
  while(scanf("%d", &a) != EOF)
    {
      cal=0;
 
      for(i = 0; i * a <= (600 - a); i++)
    {
      cal = cal + (i * a) * (i * a) * a;
    }
      printf("%d\n", cal);
    }
  return 0;
}


Measured memory_bytes: 2040
n,m = map(int,input().split())
h = tuple(map(int,input().split()))
u = []
for i in range(m):
    u.append(list(map(int,input().split())))

z = [0 for i in range(n)]

for i in range(m):
    if h[u[i][0]-1] > h[u[i][1]-1]:
        z[u[i][1]-1] += 1
    if h[u[i][0]-1] < h[u[i][1]-1]:
        z[u[i][0]-1] += 1
    if h[u[i][0]-1] == h[u[i][1]-1]:
        z[u[i][1]-1] += 1
        z[u[i][0]-1] += 1

t = []
for i in range(n):
    if z[i] == 0:
        t.append(z[i])

print(len(t))

Measured memory_bytes: 32676
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	h := make([]int, n)
	for i:=range h {
		fmt.Scan(&h[i])
	}
	g := make([]int, n-1)
	if n == 1 {
		fmt.Println(h[0])
		return
	}

	for i:=1;i<n;i++ {
		if h[i-1] <= h[i] {
			g[i-1] = 1
		} else {
			g[i-1] = -1
		}
	}
	var ans int
	if g[0] == -1 {
		ans = h[0]
	} else {
		ans = 0
	}
	for i:=1;i<n-1;i++ {
		if g[i-1] == -1 && g[i] == 1 {
			ans -=  h[i]
		} else if g[i-1] == 1 && g[i] == -1 {
			ans += h[i]
		}
	}
	if g[n-2] == 1 {
		ans += h[n-1]
	}

	fmt.Println(ans)
}

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, k;
	cin >> n >> k;

	vector<int> all;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		all.push_back(x);
	}
	vector<int> dp(k + 1);

	for (int i = 0; i <= k; i++)
	{
		if (dp[i] == 0)
		{
			for (int j = 0; j < n; j++)
			{
				if (i + all[j] <= k)
					dp[i + all[j]] = 1;
			}
		}
	}
	cout << (dp[k] == 1 ? "First\n" : "Second\n");
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[10001],dp[100][100];

int main(){
  int x,y;
  bool a[200001],b[200001];
  clr(a,0);
  clr(b,0);
  cin >> n >> m;
  rep(i,0,m){
    cin >> x >> y;
    if(!(x == 1 && y == n)){
      if(x == 1)a[y] = true;
      else if(y == n)b[x] = true;
    }
  }
  bool f = false;
  rep(i,1,200001){
    if(a[i]&& b[i])f = true;
  }
  if(f)puts("POSSIBLE");
  else puts("IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdtr1c++.h>
#define stat akjcjalsjcjalscj
#define hash ajkscjlsjclajsc
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using namespace std;
#define TASK "solve"

const int N = 3e5 + 100;
const int module = 1e6 + 3;
const long long Base = 500000004;
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());

long long rand(long long l, long long r){
    return 1LL * (1LL * rnd() * RAND_MAX + rnd()) % (r - l + 1) + l;
}
void doc() {
}

int GCD(int a,int b) {
    return b == 0 ? a : GCD(b,a % b);
}
void solve() {
    int n;
    cin >> n;
    int a[n];
    long long F[n][2];
    for (int i = 0; i < n; i++) cin >> a[i];
    F[0][0] = a[0];
    F[0][1] = 0 - a[0];
    for (int i = 1; i < n; i++) {
        F[i][0] = max(F[i - 1][1] - a[i],F[i - 1][0] + a[i]);
        F[i][1] = max(F[i - 1][1] + a[i],F[i - 1][0] - a[i]);
    }
    cout << F[n - 1][0];
}

int main() {
    srand(time(nullptr));
    ios_base::sync_with_stdio(1); cin.tie(nullptr); cout.tie(nullptr);
    doc();
    solve();
}



Measured memory_bytes: 2176
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))

mat = [[0] * w for _ in range(h)]

i = 0
j = 0
num = 1
while True:
    mat[j][i] = num
    a[num-1] -= 1
    if a[num-1] == 0:
        num += 1
    if i <= w-2:
        i += 1
    elif i == w-1:
        if j == h-1:
            break
        i = 0
        j += 1

for i in range(h):
    if i % 2 == 1:
        tmp = mat[i]
        tmp.reverse()
        mat[i] = tmp

for i in range(h):
    for j in range(w-1):
        print(mat[i][j], end = ' ')
    print(mat[i][-1])

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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = Convert.ToInt32(Console.ReadLine());
            int[] A = new int[N];
            int max = 0;
            int nextMax = 0;
            int pos = 0;
            for (var i = 0; i < N; i++)
            {
                A[i] = Convert.ToInt32(Console.ReadLine());
                if (max < A[i])
                {
                    nextMax = max;
                    max = A[i];
                    pos = i;
                } else if (nextMax < A[i])
                {
                    nextMax = A[i];
                }
            }
            for (var i = 0; i < N; i++)
            {
                if (i == pos)
                {
                    Console.WriteLine(nextMax);
                } else
                {
                    Console.WriteLine(max);
                }
            }

        }
    }
}


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

int main() {
  string S; 
  cin>>S;
  bool flag=true;
  
  if(S[0]!='A') flag=false;

  int count;
  int x;
  for(int i=2;i<=S.size()-2;i++){
    if(S[i]=='C'){
      count++;
      x=i;
    }
  }
  if(count!=1) flag=false;

  string T = S;
  rep(i,S.size()) {
    T[i]=tolower(T[i]);
  }
  
  rep(i,S.size()){
    if(i!=x&&i!=0&&S[i]!=T[i])flag=false;
  }
  if(flag)puts("AC");
  else puts("WA");
  return 0;
}

Measured memory_bytes: 256