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

#define int long long
#define pii pair<int,int>
#define X first
#define Y second

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

using namespace std;

const int N=1e5+5;
int arr[N];

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n,m;
	cin>>n>>m;
	map<int,int> mp;
	mp[0]=1;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
		arr[i]+=arr[i-1];
		ans+=mp[arr[i]%m];
		mp[arr[i]%m]++;
	}
	cout<<ans<<"\n";
	return 0;
} 


Measured memory_bytes: 4992
#include <stdio.h>

int main(){
  long long  n, q, s[10001], t, c = 0, i;
  scanf("%lld", &n);
  for(i = 0; i < n; ++i) scanf("%lld", s + i);

  scanf("%lld", &q);
  while(q--){
    scanf("%lld", &t);
    for(i = 0; i < n; ++i)
      if(t == s[i]){
        c++;
        break;
      }
  }

  printf("%lld\n", c);
  return 0;
}

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

class Program
{
    public static void Main()
    {
        string[] temp = Console.ReadLine().Split();
        int[] A = new int[3];
        for(int i = 0; i < 3; i++)
        {
            A[i] = int.Parse(temp[i]);
        }
        Array.Sort(A);
        if ((A[0] == A[1] || A[1] == A[2]) && A[0] != A[2]) { Console.WriteLine("Yes"); }
        else { Console.WriteLine("No"); }
    }
}

Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();

        int n = sc.nextInt();
        string s = sc.next();

        if (n % 2 == 1) Console.WriteLine("No");
        else if (s.Substring(0, n / 2) == s.Substring(n / 2, n / 2)) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
char d[10];
long long n,k,i,j;
int main(){
	cin>>n>>k;
	for(i=1;i<=k;i++){
		char f;
		cin>>f;
		d[f-'0']=1;
	}
	for(i=n;i<=1000000;i++){
		long long x=i;
		string s;
		stringstream ss;
		ss<<i;
		s=ss.str();
		for(j=0;j<s.size();j++){
			//cout<<s;
			if(d[(s[j]-'0')]==1)break;
		}
		if(j==s.size()){
			cout<<x<<'\n';
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
b=list(map(int,input().split()))

A=[]
for i in range(n):
    if i==0:
        A.append(b[0])
    elif i==n-1:
        A.append(b[-1])
    else:
        A.append(min(b[i],b[i-1]))
print(sum(A))

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

int main()
{
    int n,m,sum=0;
    cin>>n>>m;
    
    int a[m];
    
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    
    if(sum<n)
    {
        cout<<"No"<<endl;
    }
    
    else
    {
        cout<<"Yes"<<endl;
    }
}

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

int main(){
	int r=0,c=0;
	int i=0,j=0,k=0;

	cin >> r >> c;
	int A[r+2][c+2];
	// ?????????
	for(i=0;i<r+2;i++){
		for(j=0;j<c+2;j++){
			A[i][j]=0;
		}
	}

	// ????????????
	for(i=1;i<=r;i++){
		for(j=1;j<=c;j++){
			cin >> A[i][j];
		}
	}

	// ????????????
	for(i=1;i<=r+1;i++){
		for(j=1;j<=c;j++){
			A[i][c+1] += A[i][j];
		}
	}
	
	for(j=1;j<=c+1;j++){
		for(i=1;i<=r;i++){
			A[r+1][j] += A[i][j];
		}
	}


	for(i=1;i<=r+1;i++){
		for(j=1;j<=c+1;j++){
			if(j==c+1){
				cout << A[i][j];
			}else{
			cout << A[i][j] << " ";
			}
		}
		cout << endl;
	}

return 0;
}

Measured memory_bytes: 1196
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int M = sc.nextInt();
    
    int sumA = 0;
    
    for(int i=0; i<M; i++){
      sumA += sc.nextInt();
    }
    
    if(sumA > N){
      System.out.print("-1");
    }else if(sumA == N){
      System.out.print("0");
    }else{
      System.out.print(N - sumA);
    }
    
  }
}

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

int main(){
    int N, A, B;
    long long int C[100000], ans = 0;

    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A >> B;
        ans += A;
        ans -= B;
        C[i] = A + B;
    }

    sort(C, C + N);
    reverse(C, C + N);
    for (int j = 0; j < N; j++){
        if(j % 2 == 0)
            ans += C[j];
        else
            ans -= C[j];  
    }
    cout << ans / 2 << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
string s;cin>>s;
int ans=siz(s),scnt=0;

for(int i=0;i < siz(s);i++)
{
    if(s[i]=='S')scnt++;
    else {
        if(scnt>0)ans-=2;
        scnt=max(scnt-1,0);
    }
}

cout<<ans<<endl;
}



Measured memory_bytes: 640
#include <iostream>
using namespace std;
char a[101][101];
int n,m;

void changecol(int pos){
    for (int i=0;i<m;i++)
        a[pos][i]=' ';
}
bool checkcol(){
    for (int i=0;i<n;i++){
        int count=0;
        for (int j=0;j<m;j++){
            if (a[i][j]=='.' || a[i][j]==' ')
                count++;
            if (count==m){
                changecol(i);
            }
        }
        
    }
}
void changerow(int pos){
    for (int i=0;i<n;i++)
        a[i][pos]=' ';
}
void checkrow(){
    for (int i=0;i<m;i++){
        int count=0;
        for (int j=0;j<n;j++){
            if (a[j][i]=='.' || a[j][i]==' ')
                count++;
            if (count==n){
                changerow(i);
            }
        }
    }
}
int main(){
    cin>>n>>m;
    for (int i=0;i<n;i++)
        for (int j=0;j<m;j++)
            cin>>a[i][j];
    checkcol();
    checkrow();
    // for (int i=0;i<n;i++){
    //     for (int j=0;j<m;j++)
    //         cout<<a[i][j];
    //     cout<<endl;
    // }
    for (int i=0;i<n;i++){
        for (int j=0;j<m;j++){
            if (a[i][j]==' ')   continue;
            cout<<a[i][j];
        }
        int count=0;
        for (int j=0;j<m;j++)   if (a[i][j]==' ')   count++;
        if (count<m)   cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) \
    do           \
    {            \
    } while (0)
#define dump(x) \
    do          \
    {           \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template <class T>
inline T sqr(T x) { return x * x; }

void solve()
{
    int n, m;
    cin >> n >> m;
    VI cnt(n);
    int a, b;
    REP(i, 0, m)
    {
        cin >> a >> b;
        ++cnt[a - 1];
        ++cnt[b - 1];
    }
    REP(i, 0, n)
        cout << cnt[i] << endl;
}

int main()
{
    solve();

    return 0;
}

Measured memory_bytes: 256
type Scanner() = class
    let mutable hold = [||]
    let mutable index = 0
    member public this.Next() =
        if hold.Length > index
        then 
            index <- index + 1
            hold.[index - 1]
        else
            let mutable st = stdin.ReadLine()
            while st = "" do st <- stdin.ReadLine()
            hold <- st.Split(' ')
            if hold.Length = 0
            then
                this.Next()
            else
                index <- 1
                hold.[index - 1]
            
    member public this.NextI32() =
        this.Next() |> int

    member public this.ArrayI32(n: int) =
        [for _ in 0 .. n - 1 -> this.NextI32()]

    member public this.NextI64() =
        this.Next() |> int64
    
    member public this.ArrayI64(n: int) =
        [for _ in 0 .. n - 1 -> this.NextI64()]

    member public this.NextF32() =
        this.Next() |> float32
    
    member public this.ArrayF32(n: int) =
        [for _ in 0 .. n - 1 -> this.NextF32()]

    member public this.NextF64() =
        this.Next() |> double
    
    member public this.ArrayF64(n: int) =
        [for _ in 0 .. n - 1 -> this.NextF64()]

    member public __.Tuple2List n (f : int -> 'a list) =
        [for _ in 0 .. n - 1 -> f 2 |> fun x -> x.[0], x.[1]]
    
    member public __.Tuple3List n (f : int -> 'a list) =
        [for _ in 0 .. n - 1 -> f 3 |> fun x -> x.[0], x.[1], x.[2]]

end

let lexiperm a =
    let len = Array.length a
    let rec getPivot ind =
        let scoap = len - ind - 1
        if scoap < 0 then -1
        else if a.[scoap + 1] > a.[scoap] then scoap
        else getPivot (ind + 1)
    let pivot = getPivot 1
    if pivot < 0 then a
    else
    let before = a.[0..pivot]
    let originsuf = a.[pivot+1..]
    let suffix = 
        originsuf
        |> Array.filter(fun x -> x > a.[pivot])
    let suffixmin = suffix |> Array.min
    let minindex = originsuf |> Array.findIndex(fun x -> x = suffixmin)
    let hold = originsuf.[minindex]
    originsuf.[minindex] <- before.[pivot]
    before.[pivot] <- hold
    originsuf
    |> Array.sort
    |> Array.append before

[<EntryPoint>]
let main _ =
    let scanner = Scanner()
    let n = scanner.NextI32()
    let p = scanner.ArrayI32(n) |> List.toArray
    let q = scanner.ArrayI32(n) |> List.toArray
    let mutable pind = 0
    let mutable qind = 0
    let mutable t = Array.sort p
    let kai = Array.fold ( * ) 1 [|1..n|]

    for i in 1..kai do
        if t = p then pind <- i
        if t = q then qind <- i
        t <- lexiperm t
    
    pind - qind
    |> abs
    |> printfn "%i" 
    0


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

int main () {
  int N;
  cin >> N;
  
  int count = 0;
  for(int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    count += r - l + 1;
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<bitset> 
#include<algorithm>
using namespace std;
#define rep(x,y) for(x=0;x<(y);++x) 
#define aryclr(array,sign) memset((array),(sign),sizeof(array)) 
#define MAX(x,y) (((x)>(y))?(x):(y)) 
#define MIN(x,y) (((x)<(y))?(x):(y))
const int MAX_N=3500;
void in();
void solve();
int R,C;
bitset<10000> cc[10];//r,c
int main()
{
	while(cin>>R>>C&&R>0)
	{
		in();
		solve();
	}
	return 0;
}
void in()
{
	//scanf("%d%d",&R,&C);
	//cin>>R>>C; 
	int r,c;
	bool u;
	rep(r,R)
	{
		rep(c,C)
		{
		//	scanf("%d",&u);
			cin>>u;
			cc[r][c]=u;
		}
	}
}
void solve()
{
	int r,c,i,j;
	int mincc=0;
	int sumcc; 
	int ccc;
	rep(r,1<<R)
	{
		sumcc=0;
		rep(i,R)
		{
			if((r>>i)&1)//判断翻面 
			{
				cc[i].flip();
			}
		}
		rep(j,C)
		{
			ccc=0;
			rep(i,R)
			{
				if(cc[i][j])
				++ccc;
			}
			sumcc+=MAX(ccc,R-ccc);
		}
		mincc=MAX(mincc,sumcc);
		rep(i,R)//&#22797;原 
		{
			if((r>>i)&1)
			{
				cc[i].flip();
			}
		}
		
	}
	//printf("%d\n",mincc);
	cout<<mincc<<endl;
}

Measured memory_bytes: 1172
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
using namespace std;

int		main(void)
{
	long long	N, A, B, cnt;
	cin >> N >> A >> B;
	cnt = A * (N / (A + B));
	if ((N - (A + B) * (N / (A + B))) < A)
		cnt += (N - (A + B) * (N / (A + B)));
	else
		cnt += A;
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n;cin >> n;
  vector<int> a(n);
  rep(i,n){
    int k;cin >> k;
    a[k-1] = i+1;
  }
  for(auto &i:a) cout << i << " ";
  cout << endl;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e5+205;
void solve(){
	int a,b; 
	cin>>a>>b; 
	int st = 1;
	int ans = 0;
	for(int i=1;i<=20;i++){
		if(st>=b)break;
		st--;
		st+=a;
		ans++;
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;
 
public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int n = stdIn.nextInt();
        long d = stdIn.nextLong();

        long[] x = new long[n];
        long[] y = new long[n];
        for(int i=0; i<n; i++){
            x[i] = stdIn.nextLong();
            y[i] = stdIn.nextLong();
        }

        int cnt = 0;
        long d2 = d * d;
        long dist2 = 0;
        for(int i=0; i<n; i++){
            dist2 = x[i] * x[i] + y[i] * y[i];
            if(dist2 <= d2){
                cnt++;
            }
        }

        System.out.println(cnt);
    }
}

Measured memory_bytes: 63908
// Time-stamp: <2012-06-26 20:15:18 naga>

#include<iostream>
#include<cstdio>
using namespace std;
int maps[52][52];
int w,h;
void init(){
  for(int i = 0; i < 52; i++){
    for(int j = 0; j < 52; j++){
      maps[i][j] = 0;
    }
  }
  return;
}

void search(int x, int y){
  maps[y][x] = 0;
  if(maps[y - 1][x] && y > 0){
    search(x, y -1);
  }
  if(maps[y - 1][x - 1] && x > 0 && y > 0){
    search(x - 1, y - 1);
  }
  if(maps[y][x - 1] && x > 0){
    search(x - 1, y);
  }
  if(maps[y + 1][x - 1] && y < h && x > 0){
    search(x - 1, y + 1);
  }
  if(maps[y + 1][x] && y < h){
    search(x, y + 1);
  }
  if(maps[y + 1][x + 1] && y < h && x < w){
    search(x + 1, y + 1);
  }
  if(maps[y][x + 1] && x < w){
    search(x + 1, y);
  }
  if(maps[y - 1][x + 1] && y > 0 && x < w){
    search(x + 1, y - 1);
  }
  return;
}


int main(){
  int count;
  while(true){
    cin >> w >> h;
    if( !w && !h){
      break;
    }
    count = 0;
    init();
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	cin >> maps[i][j];
      }
    }
    
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(maps[i][j]){
	  count++;
	  search(j,i);
	}
      }
    }

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

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int ctoi(char c) {
  return c - '0';
}

template <class C>
void printContainer(C &container, const char *delim=",") {
  for(const auto &e : container) {
    std::cout << e << delim;
  }
  std::cout << "\n";
}

// Greatest common divisor
template<class T>
T gcd(T x, T y) {
  if(x < y) {
    std::swap(x, y);
  }
  T r = x % y;
  while(r != 0) {
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

// Least common multiple
template<class T>
T lcm(T x, T y) {
  return (x*y)/gcd(x,y);
}

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  string ans;
  if(a >= b) {
    ans = "delicious";
  }
  else if(a+x >= b) {
    ans = "safe";
  }
  else {
    ans = "dangerous";
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる
//時間を意識しろ
//コードテストちゃんとして
//画面とにらめっこするな書け
//WA出すたびにABCは五億円払え
//わからない問題はとばせ
//躊躇なくぐぐれ

//ここから
int main(){
    ll N;
    cin>>N;
    vl vec(N);
    rep(i,N){
       cin>>vec.at(i);
    }
    map<ll,ll> mj;
    rep(i,N){
        mj[i-vec.at(i)]++;
    }
    ll Ans=0;
    rep(i,N){
        Ans+=mj[i+vec.at(i)];
    }
    cout<<Ans<<endl;
}



Measured memory_bytes: 27436
N = int(input())
dist_from_1 = [0 for i in range(N+1)]

paths = [dict() for i in range(N+1)]
for i in range(N-1):
    a, b, dist = map(int, input().split())
    paths[a][b] = dist
    paths[b][a] = dist

queue = [(0, 1, 0)]
while len(queue) != 0:
    prev, now, dist = queue.pop()
    dist_from_1[now] = dist
    for next in paths[now]:
        if next == prev:
            continue
        queue.append((now, next, dist + paths[now][next]))

for i in range(1, N+1):
    if dist_from_1[i] % 2 == 0:
        print(0)
    else:
        print(1)


Measured memory_bytes: 48864
using System.Text;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var q = int.Parse(line[1]);
        var pos = 1;
        var sb = new StringBuilder();
        for (int i = 0; i < q; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var c = int.Parse(line[0]);
            var k = int.Parse(line[1]);
            if (c == 0)
            {
                var w = pos + k - 1;
                if (w > n) w -= n;
                sb.Append(string.Format("{0}\n", w));
            }
            else
            {
                pos += k;
                if (pos > n) pos -= n;
            }
        }
        Console.Write(sb);
    }
}



Measured memory_bytes: 22980
h, w = [int(i) for i in input().split()]
k = []
wl = []
  
for i in range(0, 10):
  k.append([int(i) for i in input().split()])
for i in range(0, h):
  wl.append([int(i) for i in input().split()])
 
 
n = {1:0}
 
while len(n) < 10:
  c = 1000
  mn = 10
  for a in n.keys():
    a2 = int(a)
    for b in range(0, 10):
      if not b in n:
        if k[b][a2] + n[a] <= c:
          c = k[b][a2] + n[a]
          mn = b
  n[mn] = c
 
ans = 0
for a in range(0, h):
  for b in range(0, w):
    if wl[a][b] != -1:
      ans += n[wl[a][b]]
 
print(ans)
      

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


// type {{{
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
// }}}


// macro {{{
#define rep(i,n) for (ll i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i,n) for (ll i=1, i##_len=(n); i<=i##_len; ++i)

#define SZ(x) ((ll)(x).size())

#define all(x) begin(x),end(x)
// }}}


// Debug {{{
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    rep (i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "(" << p.first << " " << p.second << ")";
}
// }}}


// chmax, chmin {{{
template<class T>
bool chmax(T& a, const T& b) {
    if (a < b) { a = b; return true; }
    return false;
}
template<class T>
bool chmin(T& a, const T& b) {
    if (b < a) { a = b; return true; }
    return false;
}
// }}}



// constants {{{
#define inf(T) numeric_limits<T>::max()

const ll MOD = 1e9+7;
const ld EPS = 1e-9;
// }}}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    for (;;) {
        int e; cin >> e;
        if (e == 0) break;
        int m = inf(int);
        for (int z = 0; z*z*z <= e; ++z) {
            for (int y = 0; z*z*z + y*y <= e; ++y) {
                int x = e - (z*z*z + y*y);
                chmin(m, x + y + z);
            }
        }
        cout << m << endl;
    }

    return 0;
}



Measured memory_bytes: 3048
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

int N;

int main() {
    cin >> N;
    cout << (N + 1) / 2 << endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>


using namespace std;


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

    if(A + B == 3){
        cout << "3" << endl;
    }
    else if(A + B == 4){
        cout << "2" << endl;
    }else if(A + B == 5){
        cout << "1" << endl;
        
    }
    
  
    


}


Measured memory_bytes: 256
/*

    author : s@if

*/

#include<bits/stdc++.h>
using namespace std;
#define NIL -1
#define fi first
#define sec second
#define MAX INT_MAX
#define INF 99999999
#define ll long long
#define PI acos(-1.0)
#define MOD 1000000007
#define PLL pair<ll,ll>
#define PII pair<int,int>
#define ull unsigned long long
#define triplell pair<pair<ll,ll> , ll>
#define triple pair<pair<int,int> , int>
#define For(i,n) for(int i=0;i<(int)n;i++)
#define Forn(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define forba(i,a,b) for(int i=(int)b;i>=(int)a;i--)

int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};

const int MAXN = (int)1e5+9;

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */
    
    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;
    
    cin>>m>>n;
    
    int res = 0;
    
    if(m>=n)
    {
    	res+=m;
    	m--;
	}
	else
	{
		res+=n;
		n--;
	}
	if(m>=n)
    {
    	res+=m;
    	m--;
	}
	else
	{
		res+=n;
		n--;
	}
	
	cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAXSIZE 110
#define INFTY 2100

int G[MAXSIZE][MAXSIZE];

int d[MAXSIZE];
int way[MAXSIZE];
int prev[MAXSIZE];
int color[MAXSIZE] = { 0 };


int main() {
	int n;
	int ans;
	int presentNode, minWeight;

	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			scanf("%d", &G[i][j]);
		}
	}
	for (int i = 0; i < MAXSIZE; i++) {
		way[i] = INFTY;
	}
	presentNode = 1;
	d[1] = 0;
	way[1] = 0;
	color[presentNode] = 1;
	prev[presentNode] = -1;
	while (1) {
		minWeight = INFTY;
		for (int i = 1; i <= n; i++) {
			if (G[presentNode][i] != -1 && G[presentNode][i] < way[i]&&color[i]==0) {
				way[i] = G[presentNode][i];
				prev[i] = presentNode;
			}
		}
		for (int i = 1; i <= n; i++) {
			if (way[i] < minWeight&&color[i] == 0) {
				minWeight = way[i];
				presentNode = i;
			}
		}
		if (minWeight == INFTY)break;
		color[presentNode] = 1;
	}
	ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += way[i];
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if((a == b && a != c)||(b == c && b != a)||(c == a && c != b)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var hs = new HashSet<string>();
        string[] a = Console.ReadLine().Trim().Split(' ');
        for (int i = 0; i < n; i++) hs.Add(a[i]);
        Console.WriteLine(hs.Count() == 3 ? "Three":"Four");
    }
}


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

using namespace std;

int main() {
    unsigned long long n;
    cin >> n;
    vector<vector<unsigned long long>> a = {vector<unsigned long long>(n + 1), vector<unsigned long long>(n + 1)};
    a[0][0] = 0;
    a[1][0] = 0;
    for (size_t i = 0; i < 2; ++i) {
        for (unsigned long long j = 1; j < n + 1; ++j) {
            cin >> a[i][j];
            a[i][j] += a[i][j - 1];
        }
    }
    unsigned long long max_value = 0;
    for (unsigned long long i = 0; i < n; ++i) {
        unsigned long long v = a[0][i + 1] + a[1][n] - a[1][i];
        if (v > max_value) max_value = v;
    }
    cout << max_value << endl;
    return EXIT_SUCCESS;
}

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

using namespace std;

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

void solve() {
    string k;
    cin >> k;
    int n = k.size();
    int d;
    cin >> d;

    const int mod = 1e9 + 7;

    vector<vector<int>> dp(n + 1, vector<int>(d));
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < d; j++) {
            for (int x = 0; x < 10; x++) {
                dp[i][j] = (dp[i][j] + dp[i - 1][(j - x % d + d) % d]) % mod;
            }
        }
    }

    int ans = mod - 1;
    int now = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < k[i] - '0'; j++, now = (now + 1) % d) {
            ans = (ans + dp[n - i - 1][(d - now) % d]) % mod;
        }
    }

    cout << ans + (now == 0);
}

int main() {
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}


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

#define int long long
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)

int N;
vector<int> G[100010];
bool act[100010];
int nxt[100010];
int stop[100010];
bool vis[100010];
int dist[100010];
int dfs(int n) {
    vis[n] = true;
    if (act[n]) {
        stop[n] = -1;
        return -1;
    }
    act[n] = true;
    int res = n;
    if (nxt[n] == n) {
        res = stop[n] = n;
    } else {
        res = dfs(nxt[n]);
    }
    act[n] = false;
    return stop[n] = res;
}
void init() {
    REP(i, N) {
        vis[i] = false;
        dist[i] = 1e9;
    }
    dist[0] = 0;
}
using arr2 = array<int, 2>;
bool solve() {
    cin >> N;

    init();
    REP(i, N) {
        cin >> nxt[i];
        nxt[i] = i + nxt[i];
    }
    REP(i, N) {
        if (!vis[i]) dfs(i);
    }
    priority_queue<arr2, vector<arr2>, greater<arr2>> que;
    que.push({0, 0});
    while (!que.empty()) {
        arr2 ar = que.top();
        que.pop();
        int res = ar[0], n = ar[1];
        if (res > dist[n]) continue;
        FOR(i, 1, 7) {
            if (n + i >= N || stop[n + i] == -1) continue;
            int nxt = stop[n + i];
            if (res + 1 < dist[nxt]) {
                dist[nxt] = res + 1;
                que.push({res + 1, nxt});
            }
        }
    }
    cout << dist[N - 1] << endl;
    return true;
}
signed main() { solve(); }


Measured memory_bytes: 9268
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>

using namespace std;

#define ll long long int
#define ti4 tuple<int,int,int,int>
#define pii pair<ll,ll>

static const int MOD = 1e9 + 7;

int main()
{
    map<char, int> m;
    string s;
    cin >> s;
    for(auto& r: s)
    {
        m[r]++;
    }
    for(auto& e : m)
    {
        if(e.second % 2 != 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<ll, string> PLS;

int m;
int table[5][5];


int main(){
	cin >> m;
	REP(i, m){
		int ans = 0;
		REP(j, 5)REP(k, 5)cin >> table[j][k];
		REP(j, 5){
			REP(k, 5){
				FOR(l, j, 5){
					FOR(x, k, 5){
						//cout << j << " " << k << " " << l << " " << x << endl;
						//cout << (l - j + 1)*(x - k + 1) << endl;
						bool f = 1;
						for (int y = j; y <= l; y++){
							for (int z = k; z <= x; z++){
								//cout << "!" << y << " " << z << endl;
								//cout << table[y][z] << endl;
								if (table[y][z] == 0){
									f = 0;
									break;
								}
							}
							if (f == 0)break;
						}
						if (f)ans = max((ll)ans, (l - j + 1)*(x - k + 1));
					}
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
const int maxn=3e5+7;
struct Seg{
	int l,r;
	bool operator<(const Seg& a)const{
		return r-l>a.r-a.l;
	}
};
int ans[maxn];
int cf[maxn];
int tree[maxn];
void add(int x,int v)
{
	while(x<maxn)
	{
		tree[x]+=v;
		x+=x&-x;
	}
}
int query(int x)
{
	int ret=0;
	while(x)
	{
		ret+=tree[x];
		x-=x&-x;
	}
	return ret;
}
int main()
{
	int n,m;
	cin>>n>>m;
	vc<Seg> seg(n);
	for(int i=0;i<n;i++)
	{
		cin>>seg[i].l>>seg[i].r;
		int len=seg[i].r-seg[i].l+1;
		cf[1]++;
		cf[len+1]--;
	}
	int cur=0;
	for(int i=1;i<=m;i++)
	{
		cur+=cf[i];
		ans[i]=cur;
	}
	sort(seg.begin(),seg.end());
	for(int i=1;i<=m;i++)
	{
	//	dbg(i,ans[i]);
		while(seg.size()&&seg.back().r-seg.back().l+1<i)
		{
			add(seg.back().l,1);
			add(seg.back().r+1,-1);
			seg.pop_back();
		}
		for(int j=i;j<=m;j+=i)
			ans[i]+=query(j);
	}
	for(int i=1;i<=m;i++)
		cout<<ans[i]<<'\n';

}


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

using ll = long long;
using P = pair<int, int>;

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int p[55];

bool check() {
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      if (p[i] > p[j]) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> p[i];

  if (check()) {
    cout << "YES" << endl;
    return 0;
  }

  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      swap(p[i], p[j]);
      if (check()) {
        cout << "YES" << endl;
        return 0;
      }
      swap(p[i], p[j]);
    }
  }

  cout << "NO" << endl;

  return 0;
}


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

ll n, a, b;

ll pow_mod(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res *= a;
    a = a*a;
    a %= mod;
    n >>= 1;
    res %= mod;
  }
  return res;
  /*
  if (n == 1) res = a;
  else if (n % 2 == 1) res = a * pow_mod(a, n-1, mod);
  else res = pow_mod(a, n/2, mod) * pow_mod(a, n/2, mod);
  res %= mod;
  return res;
  */
}

ll inv(ll x, ll mod) {
  ll res = pow_mod(x, mod - 2, mod);
  return res;
}

ll comb_mod(ll n, ll r, ll mod) {
  ll res;
  ll x = 1, y = 1;
  for (ll i = 0; i < r; i++) {
    x *= n-i;
    x %= mod;
    y *= r-i;
    y %= mod;
  }
  res = x * inv(y, mod);
  res %= mod;
  return res;
}

int main() {
  cin >> n >> a >> b;
  ll ans;
  ans = pow_mod(2, n, 1000000007) - 1;
  if (ans < 0) ans += 1000000007;
  ans -= comb_mod(n, a, 1000000007);
  if (ans < 0) ans += 1000000007;
  ans -= comb_mod(n, b, 1000000007);
  if (ans < 0) ans += 1000000007;
  ans %= 1000000007;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define A 100
#define ARIA 1<<21
int N[A][A],p,B[A],C[A],D[A];

int mini(int x, int y){
  return (x>=y) ?y:x;
}


void kas(int s){
  int i;
  for(i=0;i<p;i++){
    C[i]=ARIA;
    B[i]=0;
  }
  C[s]=0;
  while(1){
    int u,v=-1;
    for(u=0;u<p;u++){
      if(B[u]==0 && (v==-1||C[u]<C[v]))v=u;
    }
    if(v==-1)break;
    B[v]=1;
    for(u=0;u<p;u++){
      if(B[u]!=1)C[u]=mini(C[u],C[v]+N[v][u]);
    }
  }
}

int main(){
  int i,j,k,v,c,u;
  scanf("%d",&p);

  for(i=0;i<p;i++){
    for(j=0;j<p;j++){
    N[i][j]=ARIA;
  }
}

for(i=0;i<p;i++){
  scanf("%d %d",&u, &k);
  for(j=0;j<k;j++){
    scanf("%d %d",&v, &c);
	    N[u][v]=c;
  }
 }

kas(0);
for(i=0;i<p;i++){
  printf("%d %d\n",i, C[i]);
    }

return 0;
}	   
    



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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const int mod=1e9+7;

struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  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 c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

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

    return true;
}

map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}

void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}

int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );

  int a,b,c;
  cin>>a>>b>>c;
  int ans=a*b/2;
  
  cout(ans);

  return 0;
}

Measured memory_bytes: 125568
n,m = map(int, input().split())
P,S=[],[]
A = {}# {num: (fixed, WA)}
ac,wa = 0,0
for i in range(m):
  p,s=input().split()
  P.append(int(p))
  S.append(s)
for i in range(m):
  num = P[i]
  res = A.get(num)[0] if A.get(num)!=None else False
  
  if S[i]=='AC':
    if res==False:
      ac += 1
      A[num] = (True, A.get(num)[1]) if A.get(num)!=None else (True,0)
  else:
    if res==False:
      A[num] = (False,A.get(num)[1]+1) if A.get(num)!=None else (False,1)

for a in A.values():
  if a[0]:
    wa += a[1]
print(ac,wa)

Measured memory_bytes: 22676
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N;
    cin >> N;
    vector<int> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    
    long long ans = 1;
    long long x = 1;
    for ( int i = 0; i < N; i++ ) {
        ans *= 3;
        if ( A[i]%2 == 0 ) { x *= 2; }
    }
    
    ans -= x;
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <cmath>
#include <string>
#include <cstring>
#include <iomanip>
#include <random>
#include <ctime>
#include <algorithm>
#include <functional>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <climits>
#include <utility>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << setprecision(10) << fixed;
	/////////////////////////////////////////////////////////////
	string s, t, temp;
	cin >> s >> t;
	for (int i = 0; i < s.length(); ++i) {
		temp = s[s.length() - 1];
		s.erase(s.length() - 1, 1);
		temp += s;
		s = temp;
		if (s == t) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	/////////////////////////////////////////////////////////////
	cout << "\n";
	return 0;
}


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

int H, W;
queue<pair<int,int>> Check;
 
void search(int x, int y, vector<string> &M) {
  if (x>0 && M.at(x-1).at(y) == '.') {
    M.at(x-1).at(y) = 's';
    Check.push(make_pair(x-1, y));
    search(x-1,y,M);
  }
  if (x<H-1 && M.at(x+1).at(y) == '.') {
    M.at(x+1).at(y) = 's';
    Check.push(make_pair(x+1, y));
    search(x+1,y,M);
  }
  if (y>0 && M.at(x).at(y-1) == '.') {
    M.at(x).at(y-1) = 's';
    Check.push(make_pair(x, y-1));
    search(x,y-1,M);
  }
  if (y<W-1 && M.at(x).at(y+1) == '.') {
    M.at(x).at(y+1) = 's';
    Check.push(make_pair(x, y+1));
    search(x,y+1,M);
  }
  
  M.at(x).at(y) = 'S';
  
  return;
}
 
int main() {
  int Ch, Cw, Dh, Dw;
  cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
  
  vector<string> S(H);
  
  for (int i = 0; i < H; i++) {
    cin >> S.at(i);
  }
   
  S.at(Ch-1).at(Cw-1) = 's';
  int magic=0;

  queue<pair<int,int>> Start;
  Start.push(make_pair(Ch-1, Cw-1));
  
  pair<int,int> X;
  
  while (true) {
    
    Check = Start;
    
    if (Start.empty()) {
      cout << -1 << endl;
      break;
    }
  
    while (!Start.empty()) {
      X = Start.front();
      search(X.first,X.second,S);
      Start.pop();
    }
  
    if (S.at(Dh-1).at(Dw-1) == 'S') {
      cout << magic << endl;
      break;
    }
  
    while (!Check.empty()) {
      X = Check.front();
      for (int i = max(X.first-2,0); i < min(X.first+3,H); i++) {
        for (int j = max(X.second-2,0); j < min(X.second+3,W); j++) {
          if (S.at(i).at(j) == '.') {
            S.at(i).at(j) = 's';
            Start.push(make_pair(i, j));
          }
        }
      }
      Check.pop();
    }
  
    magic++;
    
  }
  
  return 0;
}

Measured memory_bytes: 5572
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n;cin>>n;
  vi a(n);
  rep(i,n) cin>>a[i];
  vi dp(n, -1);
  rep(i,n) {
    auto it = lower_bound(dp.begin(), dp.end(), a[i]);
    int idx = it - dp.begin();
    dp[idx-1] = a[i];
  }
  int ans = 0;
  rep(i,n) {
    if (dp[i] != -1) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

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

    vector<int> p(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
    }

    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (p[i] == i) {
            ans++;
            if (i + 1 <= n and p[i + 1] == i + 1) i++;
        }
    }

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[101];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    a[n] = 101;

    int s = 0, sol = 0;
    for (int i = 1; i <= n; ++i)
    {
        ++s;
        if (a[i] != a[i-1])
        {
            sol += s / 2;
            s = 0;
        }
    }
    cout << sol;
}


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

void write(int x0, int y0, int x1, int y1, int x2, int y2)
{
  cout << x0 << ' ' << y0 << ' ' << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
}

int main()
{
  long long s;
  cin >> s;
  long long k = (long long)(sqrt(s));
  while (k * k < s)
    k++;

  if (k * k == s) write(0, 0, 0, k, k, 0);
  else if (k * k - s < k) write(0, 0, k * k - s, k, k, 1);
  else write(0, 0, k * (k - 1) - s, k - 1, k, 1);
}


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

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

int main()
{
    int n, k;
    cin >> n >> k;
    int x, cnt = 0;
    rep(i, n)
    {
        cin >> x;
        cnt += min(2 * x, 2 * abs(x - k));
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
def elongation(n):
    NG=["AAGC","GAGC","TAGC","CAGC","AGAC","GGAC","CGAC","TGAC","AACG","GACG","CACG","TACG","AGGC","ATGC","AGTC"]
    trinucleotide={"TTT":1}
    new_trinucleotide={}
    MOD=10**9+7
    for k in range(n):
        for i in trinucleotide:
            for j in "AGCT":
                new=i+j
                if new in NG:
                    pass
                else:
                    if new[1:] in new_trinucleotide:
                         new_trinucleotide[new[1:]]=(new_trinucleotide[new[1:]]+trinucleotide[i])
                    else:
                         new_trinucleotide[new[1:]]=trinucleotide[i]
        trinucleotide=new_trinucleotide
        new_trinucleotide={}
    return(sum(trinucleotide.values())%MOD)

print(elongation(int(input())))

Measured memory_bytes: 3064