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

int main() {
  string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int N;
  string S;
  cin >> N >> S;
  for (int i = 0; i < S.size(); i++) {
    char item = S[i];
    int index;
  	for (int j = 0; j < alpha.size(); j++) {
      if (item == alpha[j]) {
        index = j;
        goto BREAK_LABEL;
      }
    }
    BREAK_LABEL:
    index = index + N < alpha.size() ? index + N : (index + N) - alpha.size();
    cout << alpha[index];
  }
  cout << endl;
}

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

int main() {
  int n, d, ans = 0;
  cin >> n >> d;
  int a[n][d];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int s = 0;
      for (int k = 0; k < d; k++) {
        int t = a[j][k] - a[i][k];
        s += t * t;
      }
      bool f = false;
      for (int k = 0; k <= sqrt(s); k++) {
        if (k * k == s) f = true;
      }
      if (f) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

  int a, b;
  cin >> a >> b;

  int ans = a;
  if(b < a) --ans;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from itertools import accumulate
from collections import Counter


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    S = accumulate(A)
    C = Counter(S)
    ans = 0
    k = 0
    for a in A:
        ans += C[k]
        k += a
        C[k] -= 1
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 41980
import java.util.Arrays;

public class Main {
  private static void solve() {
    int n = ni();
    String[][] p = new String[n][3];
    for (int i = 0; i < n; i++) {
      p[i][0] = next();
      p[i][1] = next();
      p[i][2] = i + 1 + "";
    }

    Arrays.sort(p,
        (o1, o2) -> o1[0].equals(o2[0]) ? Integer.parseInt(o2[1]) - Integer.parseInt(o1[1])
            : o1[0].compareTo(o2[0]));
    
    for (String[] v : p) {
      out.println(v[2]);
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

int main() {
int xa,xb,xc,xd,ya,yb,yc,yd;
int x,y;
cin >> xa >> ya >> xb >> yb;
x = xa - xb;
y = ya - yb;

  xc = xb + y;
  yc = yb - x;
  xd = xa + y;
  yd = ya - x;
  cout << xc << " " << yc << " " << xd << " " << yd; 

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]){cout<<"NO"<<endl;return 0;}
    }
    cout<<"YES";return 0;
}

Measured memory_bytes: 1024
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int ans[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	string str;
	cin >> n;
	cin >> str;
	for (int o1 = 0; o1 < 2; o1++)
	{
		for (int o2 = 0; o2 < 2; o2++)
		{
			ans[0] = o1;
			ans[1] = o2;
			for (int i = 1; i < n; i++)
			{
				if (ans[i] == 0)
				{
					if (str[i] == 'o') ans[(i + 1) % n] = ans[i - 1];
					else ans[(i + 1) % n] = ans[i - 1] ^ 1;
				}
				else
				{
					if (str[i] == 'o') ans[(i + 1) % n] = ans[i - 1] ^ 1;
					else ans[(i + 1) % n] = ans[i - 1];
				}
			}
			if (ans[0] != o1) continue;
			if ((ans[n - 1] == ans[1]) ^ (str[0] == 'o') ^ (ans[0] != 0)) continue;
			for (int i = 0; i < n; i++) putchar("SW"[ans[i]]);
			puts("");
			return 0;
		}
	}
	puts("-1");
	return 0;
}

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

struct UnionFind {
    vector<int> p;
    UnionFind(int n) : p(n, -1) {}
    void merge(int a, int b) {
        a = root(a), b = root(b);
        if (a == b) return;
        if (p[a] < p[b]) swap(a, b);
        p[b] += p[a];
        p[a] = b;
    }
    int root(int x) {
        if (p[x] < 0) return x;
        return p[x] = root(p[x]);
    }
    int size(int x) {
        return -p[root(x)];
    }
};

signed main() {
    int N, W, H;
    cin >> N >> W >> H;
    vector<bitset<4>> flag(N);
    vector<vector<pair<int, int>>> row(H), col(W);
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        flag[i][0] = (x == 0);
        flag[i][1] = (x == W - 1);
        flag[i][2] = (y == 0);
        flag[i][3] = (y == H - 1);
        row[y].push_back({x, i});
        col[x].push_back({y, i});
    }

    UnionFind uf(N);
    for (int i = 0; i < H; i++) {
        sort(begin(row[i]), end(row[i]));
        for (int j = 0; j < (int)row[i].size() - 1; j++)
            uf.merge(row[i][j].second, row[i][j + 1].second);
    }
    for (int i = 0; i < W; i++) {
        sort(begin(col[i]), end(col[i]));
        for (int j = 0; j < (int)col[i].size() - 1; j++)
            uf.merge(col[i][j].second, col[i][j + 1].second);
    }
    
    int ans = 0;
    set<int> s;
    for (int i = 0; i < N; i++) {
        int r = uf.root(i);
        s.insert(r);
        flag[r] |= flag[i];
    }
    for (int r : s) {
        ans += uf.size(r) - 1;
    }
    if (s.size() > 1) {
        int mx = 0;
        for (int dir = 0; dir < 4; dir++) {
            int cnt = 0;
            for (int r : s) {
                cnt += flag[r][dir];
            }
            mx = max(mx, cnt);
        }
        ans += s.size() - mx;
        ans += s.size() - 1;
    }

    cout << ans << endl;
}



Measured memory_bytes: 11544
using System;

namespace OJcsharp
{
    class Program
    {
        static string yn(string[] str)
        {
            int xmax = 0, ymax = 0;
            for (int n = 0; n < 10; n++)
            {
                if (xmax > ymax)
                {
                    if (xmax < int.Parse(str[n]))
                        xmax = int.Parse(str[n]);
                    else
                    {
                        if (ymax < int.Parse(str[n]))
                            ymax = int.Parse(str[n]);
                        else
                            return "NO";
                    }
                }
                else
                {
                    if (ymax < int.Parse(str[n]))
                        ymax = int.Parse(str[n]);
                    else
                    {
                        if (xmax < int.Parse(str[n]))
                            xmax = int.Parse(str[n]);
                        else
                            return "NO";
                    }
                }
            }
            return "YES";
        }
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] ans = new string[N];
            for (int n = 0; n < N; n++)
            {
                ans[n] = yn(Console.ReadLine().Split(' '));
            }
            for (int n = 0; n < N; n++)
            {
                Console.WriteLine(ans[n]);
            }
        }
    }
}

Measured memory_bytes: 5292
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)

int main(){
  ll x,y;
  cin>>x>>y;
  ll cnt=1;
  while(x<=y){
    x*=2;
    if(x>y)break;
    cnt++;
  }

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


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

int main(){
    using namespace std;
    size_t N;
    cin >> N;
    vector<size_t> A(N);
    for(auto& i : A)cin >> i;
    vector<size_t> B(N), C(N);
    partial_sum(A.cbegin(), A.cend() - 1, B.begin() + 1, __gcd<size_t>);
    partial_sum(A.crbegin(), A.crend() - 1, C.begin() + 1, __gcd<size_t>);
    vector<size_t> ans(N);
    transform(B.cbegin(), B.cend(), C.crbegin(), ans.begin(), __gcd<size_t>);
    cout << *max_element(ans.begin(), ans.end()) << endl;
    return 0;
}

Measured memory_bytes: 3328
S = input()
Max = 0
t = 0
for i in range(len(S)):
    if(S[i] == 'A')or(S[i]=='C')or(S[i]=='G')or(S[i]=='T'):
        k=i
        while k<len(S):
            if(S[k] not in ['A','C','G','T']):
                ans = k-i
                if(ans > Max):
                    Max = ans
                break
            elif(k==len(S)-1):
                ans = k-i+1
                if(ans>Max):
                    Max = ans
            k+=1
print(Max)

Measured memory_bytes: 38256
/*
======================
[     ___T_          ]
[    | 6=6 | =>HI :-)] 
[    |__o__|         ]
[ >===]__o[===<      ]
[     [o__]          ]
[      .".           ]
[      |_|           ]
[                    ]
======================
 */

#include<bits/stdc++.h>
using namespace std;
using lli = int64_t;
const int maxN = 2e5 * 2 + 10;
vector<int> adj[maxN];
bool visited[maxN];
int cnt = 0;
void dfs(int node){
	visited[node] = true;
	cnt += 1;
	for(auto child : adj[node]){
		if(!visited[child]){
			dfs(child);
		}
	}
}
int main(){
	 ios::sync_with_stdio(false);
	 cin.tie(nullptr);
	 cout.tie(nullptr);
	 int T = 1;
	 for(int t = 1; t <= T; t++){
		 int n,m;
		 cin >> n >> m;
		 for(int i = 1; i <= m; i++){
			 int u,v;
			 cin >> u >> v;
			 adj[u].push_back(v),adj[v].push_back(u);
		 }
		 int max_count = 0;
		 for(int i = 1; i <= n; i++){
			 if(!visited[i]){
				 cnt = 0;
				 dfs(i);
			 }
			 max_count = max(max_count,cnt);
		 }
		 cout << max_count << "\n";
	 }
}


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

int main() {
  
  int N;
  int K;
  cin >> N >> K;
  
  int num = 0;
  
  vector<int> h(N);
  
  for(int i = 0;i < N;++i){
    cin >> h[i];
  }
  
  for(int i = 0;i < N;++i){
    if(h[i] >= K){
      ++num;
    }
  }
  
  cout << num << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<bitset>
#include<algorithm>
using namespace std;
int C, R;
bitset<10000> cookie[10];

int main()
{
	
	while (cin >> R >> C&& R || C)
	{

		for (int i = 0; i<R; i++)
			for (int j = 0; j<C; j++)
			{
				bool upwd;
				cin >> upwd;
				cookie[i][j] = upwd;
			}


		int permute = 1 << R;
		int res = 0;

		for (int i = 0; i< permute; i++)
		{
			for (int j = 0; j<R; j++)
				if (i & (1 << j))
					cookie[j].flip();

			int pos_res = 0;
			for (int j = 0; j<C; j++)
			{
				int up = 0;
				for (int k = 0; k<R; k++)
					if (cookie[k][j])
						up++;
				pos_res += max(up, R - up);
			}
			res = max(res, pos_res);

			for (int j = 0; j<R; j++)
				if (i & (1 << j))
					cookie[j].flip();
		}

		cout << res << endl;
	}
}

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

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//constant
const int MOD = 1000000009;
const int INF = INT_MAX / 3;

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
	int n;
	cin >> n;
	vi a(n);
	REP(i, n)
		cin >> a[i];
	long long int sum = 0;
	sum += a[0] - 1;
	a[0] = 1;
	int wari = 2;
	REP(i, n) {
		if (a[i] == wari) {
			sum += a[i] / wari - 1;
			wari++;
		}
		else if (a[i] % wari == 0) {
			sum += a[i] / wari - 1;
		}
		else
			sum += a[i] / wari;
			

	}
	cout << sum << endl;


}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main()
{

    string str;
    int N,ACcount=0,WAcount=0,TLEcount=0,REcount=0;
    cin>>N;
    while(N--)
    {
        cin>>str;

        if(str=="AC")
            ACcount++;
        else if(str=="WA")
            WAcount++;
        else if(str=="TLE")
            TLEcount++;
        else if(str=="RE")
            REcount++;
    }
    cout<<"AC "<<"x "<<ACcount<<endl;
    cout<<"WA "<<"x "<<WAcount<<endl;
    cout<<"TLE "<<"x "<<TLEcount<<endl;
    cout<<"RE "<<"x "<<REcount<<endl;

    return 0;
}


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

int main(){
    int X;
    cin >> X;
    if(X >= 1800){
        cout << "1" << endl;
    }else if(X >= 1600){
        cout << "2" << endl;
    }else if(X >= 1400){
        cout << "3" << endl;
    }else if(X >= 1200){
        cout << "4" << endl;
    }else if(X >= 1000){
        cout << "5" << endl;
    }else if(X >= 800){
        cout << "6" << endl;
    }else if(X >= 600){
        cout << "7" << endl;
    }else if(X >= 400){
        cout << "8" << endl;
    }
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
template<typename T> bool chmax(T &a, T b) {if(a <= b){a = b; return true;}return false;}
template<typename T> bool chmin(T &a, T b) {if(a >= b){a = b; return true;}return false;}


int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    int count = 0;
    while(0 <= (b - a) && count < c){
        b -= a;
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,m;
	cin >> n >> m;
	vector<int> x(m),y(m);
	for(int i = 0; i < m; i++){
		cin >> x[i] >> y[i];
	}

	vector<int> num(n+1),red(n+1);
	red.assign(red.size(),0);
	num.assign(num.size(),1);
	red[1] = 1;

	for(int i = 0; i < m; i++){
		num[x[i]]--;
		num[y[i]]++;
		if(red[x[i]] == 1){
			red[y[i]] = 1;
			if(num[x[i]] == 0) red[x[i]] = 0;
		}
	}

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

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main()
{
    int A,B,C,Div;
    scanf("%d%d%d",&A,&B,&C);
    if(A>B)
    {
        printf("0\n");
    }
    else if(A<=B)
    {
        Div=B/A;
        if(Div>=C)
        {
            printf("%d\n",Div-(Div-C));
        }
        else
        {
            printf("%d\n",Div);
        }
    }
    return 0;
}


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

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

    int N;
    cin >> N;

    vector<int> p(N);

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

    int ans = 0;

    for(int i = 0; i < N - 1; i++) {
        if(i == p[i]) {
            swap(p[i], p[i + 1]);
            ans++;
        }
    }

    if(p[N - 1] == N - 1) {
        swap(p[N - 1], p[N - 2]);
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextLong()
    var number = n
    val div = mutableListOf<Long>()
    var divisor = 1L
    while (divisor * divisor <= number) {
        if (number % divisor == 0L) {
            div.add(divisor)
            if (divisor * divisor != number) {
                div.add(number / divisor)
            }
        }
        divisor++
    }
    var sum = 0L
    for (d in div) {
        if (d == 1L) continue
        val q = n / d
        if (q < d - 1) {
            sum += d - 1
        }
    }
    println(sum)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

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

int main(){
    set<int> s;
    for(int i=0;i<5;i++){s.insert(i+1);}
    for(int i=0;i<5;i++){
        int t;cin >> t;
        s.erase(t);
    }
    auto it = s.begin();
    cout << *it <<"\n";
    return 0;
}


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

#define IO          ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int         long long
#define double      long double
#define vi          vector <int>
#define vvi         vector <vi>
#define pii         pair <int,int>
#define vii         vector <pii>
#define nl          '\n'
#define yy          "YES\n"
#define nn          "NO\n"
#define pb          emplace_back
#define all(v)      (v).begin(), (v).end()
#define rall(v)     (v).rbegin(), (v).rend()
#define mod         1000000007
#define PI          3.1415926535897932

signed main()
{
        IO;
        int n;
        cin >> n;
        vi a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        sort(rall(a));
        vi store;
        for (int i = 0; i < n; i++) {
            store.pb(a[i]);
            if (i) {
                store.pb(a[i]);
            }
        }
        int ans = 0;
        for (int i = 0; i < n - 1; i++) {
            ans += store[i];
        }
        cout << ans;
}



Measured memory_bytes: 8992
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    h,w = map(int, input().split())
    if h == 1 or w == 1:
        print(1)
        return
    if h*w % 2 == 0:
        print(h*w//2)
    else:
        print(h*w//2 + 1)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 64108
#include <bits/stdc++.h>
using namespace std;
long long n,a,b,ans=0,cnt=0;
string s,t;
int main(){
  cin >> s >> n;
  for(int i=0;i<s.size();i++){
    if(i%n==0){
      cout << s[i];
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=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;

VI e[200000];

int main(void){
    int n, m;
    cin >> n >> m;
    REP(i,m){
        int a, b;
        scanf("%d %d", &a, &b);
        a--;
        b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }

    VI dist(n,1000);
    queue<int> que;
    dist[0] = 0;
    que.push(0);
    while (!que.empty()){
        int x = que.front();
        que.pop();
        for (int next : e[x]){
            if (dist[next] <= dist[x] + 1) continue;
            dist[next] = dist[x] + 1;
            que.push(next);
        }
    }
    cout << (dist[n-1] <= 2 ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    return 0;
}


Measured memory_bytes: 13168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    const ll MOD = 1e9+7;
    vector<ll> last(m);
    last[0] = 1;
    rep(i,0,n) {
        vector<ll> dp(m);
        string s;
        cin >> s;
        rep(i,0,m) {
            if(s[i]!='#') {
                if(i>0) dp[i] = dp[i-1];
                dp[i] = (dp[i]+last[i])%MOD;
            }
        }
        swap(last,dp);
    }
    cout << last[m-1]<<"\n";
}


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

using namespace std;

template<typename T>
class SegTree {
public:
    explicit SegTree(int n, T def) : N(calcN_(n)), def(def), mVal(2*calcN_(n)-1, def) {}
    void update(int idx, T value){
        int i = N + idx - 1;
        update_(mVal[i], value);
        while(i > 0){
            i = (i-1)/2;
            mVal[i] = operate(mVal[2*i+1], mVal[2*i+2]);
        }
    }
    T get(int l, int r){
        return getImpl_(l, r, 0, 0, N);
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    T getImpl_(int l, int r, int idx, int rangeL, int rangeR){
        if(r <= rangeL || rangeR <= l) return def;
        if(l <= rangeL && rangeR <= r) return mVal[idx];
        int rangeM = (rangeL+rangeR)/2;
        T a = getImpl_(l, r, 2*idx+1, rangeL, rangeM);
        T b = getImpl_(l, r, 2*idx+2, rangeM, rangeR);
        return operate(a, b);
    }
    T update_(T& data, T val) { data = val; }
    T operate(T a, T b) { return min(a, b); }
    const int N;
    const T def;
    vector<T> mVal; 
};

class UnionFind {
public:
    explicit UnionFind(int N) : root(N, -1), size(N, 1) {}
    int getRoot(int u){ return root[u] == -1 ? u : root[u] = getRoot(root[u]); }
    int getSize(int u){ return size[getRoot(u)]; }
    int same(int a, int b){
        return getRoot(a) == getRoot(b);
    }
    int merge(int a, int b){
        int u = getRoot(a);
        int v = getRoot(b);
        if(u != v){
            root[u] = v;
            size[v] += size[u];
        }
    }
private:
    vector<int> root;
    vector<int> size;
};

int main(){
    int N; long long D;
    while(cin >> N >> D){
        vector<long long> A(N);
        for(auto& t : A) cin >> t;
        vector<pair<long long, int>> key;
        for(int i=0;i<N;i++) key.emplace_back(A[i], i);
        sort(key.begin(), key.end());
        SegTree<pair<long long, int>> left(N, make_pair(1LL << 60, -1));
        SegTree<pair<long long, int>> right(N, make_pair(1LL << 60, -1));
        vector<pair<long long, pair<int, int>>> edge;
        for(auto& p : key){
            int idx = p.second;
            int idxL = left.get(0, idx).second;
            int idxR = right.get(idx+1, N).second;
            if(idxL != -1){
                edge.emplace_back((idx-idxL)*D + p.first + A[idxL], make_pair(idxL, idx));
            }
            if(idxR != -1){
                edge.emplace_back((idxR-idx)*D + p.first + A[idxR], make_pair(idxR, idx));
            }
            left.update(idx, make_pair((N-idx)*D + A[idx], idx));
            right.update(idx, make_pair(idx*D + A[idx], idx));
        }
        long long res = 0;
        UnionFind uf(N);
        sort(edge.begin(), edge.end());
        for(auto & e : edge){
            int u = uf.getRoot(e.second.first);
            int v = uf.getRoot(e.second.second);
            if(u != v){
                uf.merge(u, v);
                res += e.first;
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 32436
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
 
#if DEBUG
    #include "debug.h"
#else
    #define debug(args...)
#endif    

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;


#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = INT_MAX;
const int mod = 1e9+7;

const int N = 3e5 + 10;
inline int add(int x,int y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline int mul(int x,int y){
  x = (1LL * x * y) % mod;
  return x;
}
inline int pow_(ll x, ll y, int p = mod){
  ll r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
clock_t time_p=clock();

ll A[N];
int ct[64][2];


int32_t main(){
  fast;

  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);

  int n;
  cin >> n;
  FOR(i,1,n)cin >> A[i];

  for(int i = 0; i < 61; i++) {
    FOR(j,1,n) {
      if(A[j]&(1LL << i))ct[i][1]++;
      else ct[i][0]++;
    }
  }

  int ans = 0;
  for(int i = 0; i < 61; i++) {
    ans = add(ans , mul(mul(ct[i][0], ct[i][1]) , (pow_(2,i))));
  }
  cout << ans << "\n";
  time_p=clock()-time_p;
  cerr<<"\nTime Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";

  return 0;
}

Measured memory_bytes: 2560
S = list(map(int, input()))
ans = 0
l = len(S)
i = 0
while len(S)-1 > i:
    if S[i] != S[i+1]:
        S.pop(i)
        S.pop(i)
        ans += 2
        if i == 0:
            i -= 1
        else:
            i -= 2
    i += 1


print(ans)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007

ll dat[1010][3];
ll arms[41];
short B[41];
string F[1010];

int main() {
	arms[0] = arms[1] = 1;
	for (int i = 2;i < 35;i++) {
		arms[i] = arms[i - 1] * 2;
	}
	ll S = (1LL << 34);
	int N;
	cin >> N;
	ll x, y;
	short z = 2;
	for (int i = 0;i < N;i++) {
		cin >> x >> y;
		dat[i][0] = x;
		dat[i][1] = y;
		if ((x + y) & 1) {
			if (z == 0)
				z = 5;
			if (z == 2)
				z = 1;
		}
		else {
			if (z == 1)
				z = 5;
			if (z == 2)
				z = 0;
		}
	}
	if (z == 5) {
		cout << -1 << endl;
		return 0;
	}

	if (z == 1)
		arms[0] = 0, S--;

	bool xc, yc;
	string ans;
	for (int i = 0;i < N;i++) {
		x = dat[i][0];
		if (x < 0)xc = 1, x = -x;
		else xc = 0;

		y = dat[i][1];
		if (y < 0)yc = 1, y = -y;
		else yc = 0;

		ll bt = (S - x - y) / 2;
		int bc = 1;

		B[0] = 6;
		for (int j = 1;j < 35;j++) {
			if (bt & 1)B[j] = 1;
			else B[j] = 0;
			bt /= 2;
		}

		for (int j = 0;j < 35;j++) {
			if (x & (1LL << j)) {
				if (B[j + 1]) {
					B[j + 1] = 5;
					x += (1LL << j);
				}
				else {
					B[j + 1] = 4;
					x -= (1LL << j);
				}
			}
			else {
				B[j + 1] += 6;
			}
		}

		ans = "";
		for (int j = 0;j < 35;j++) {
			if (arms[j] == 0)continue;
			if (B[j] == 4) {
				if (xc)ans += 'L';
				else ans += 'R';
			}
			else if (B[j] == 5) {
				if (xc)ans += 'R';
				else ans += 'L';
			}
			else if (B[j] == 6) {
				if (yc)ans += 'D';
				else ans += 'U';
			}
			else if (B[j] == 7) {
				if (yc)ans += 'U';
				else ans += 'D';
			}
			else
				ans += 'X';
		}
		F[i] = ans;
	}

	if (arms[0] == 0) {
		cout << 34 << endl;
		for (int i = 1;i < 35;i++) {
			cout << arms[i];
			if (i == 34)cout << endl;
			else cout << " ";
		}
		for (int j = 0;j < N;j++) {
			cout << F[j] << endl;
		}

		//VERIFY

		for (int i = 0;i < N;i++) {
			ans = F[i];
			x = 0, y = 0;
			for (int j = 0;j < 34;j++) {
				if (ans[j] == 'L')x -= arms[j + 1];
				if (ans[j] == 'R')x += arms[j + 1];
				if (ans[j] == 'U')y += arms[j + 1];
				if (ans[j] == 'D')y -= arms[j + 1];
			}
			if (x != dat[i][0] || y != dat[i][1]) {
				cout << "WA" << endl;
				cout << x << " " << y << endl;
				assert(0);
			}
		}
		
	}
	else {
		cout << 35 << endl;
		for (int i = 0;i < 35;i++) {
			cout << arms[i];
			if (i == 34)cout << endl;
			else cout << " ";
		}
		for (int j = 0;j < N;j++) {
			cout << F[j] << endl;
		}

		for (int i = 0;i < N;i++) {
			ans = F[i];
			x = 0, y = 0;
			for (int j = 0;j < 35;j++) {
				if (ans[j] == 'L')x -= arms[j];
				if (ans[j] == 'R')x += arms[j];
				if (ans[j] == 'U')y += arms[j];
				if (ans[j] == 'D')y -= arms[j];
			}
			if (x != dat[i][0] || y != dat[i][1]) {
				cout << x << " " << y << endl;
				cout << "WA" << endl;
				assert(0);
			}
		}
	}
}

Measured memory_bytes: 384
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=(int)f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=(int)f; i>(int)t; i--)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define pb push_back
#define SYNC ios_base::sync_with_stdio(false)
#define inf 2248012
#define mp make_pair
#define F first
#define S second
#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d %d",&x,&y)
#define riii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> ii;

const int MAXN = 5e5+3; //AREGLAAAAAAAAR!!!!
ll mod=1e9+7;
int main(){
	ll n,m;
	lrii(n,m);
	if(n<m) swap(n,m);
	ll ans=0;
	ll a=n,b=m;
	if(n==m || n==m+1){
		ans=1;
		FOR(i,0,a+b){
			if(!(i%2)){ ans=(ans%mod*n%mod)%mod; n--; }
			else{ ans=(ans%mod*m%mod)%mod; m--;  }
		}
		if(a==b){ ans=(ans%mod+ans%mod)%mod;} 
	}
	printf("%lld\n",ans%mod);

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long

int main () {
  ll n;
  cin >> n;
  ll a[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];  
  }    
  ll left = 0;
  ll right =0;
  ll now = 0;
  for (ll i = 0; i < n; i++) {
    if (i == 0) {
      if (a[i] <= 0) {
        now = 1;
        left= 1 - a[i];  
      }  
      else {
        now = a[i];
        left = 0;  
      }
    }    
    else {
      if (now > 0) {
        if (now + a[i] < 0) {
          now = now + a[i];  
        }    
        else {
          left += now + a[i] + 1;
          now = -1;  
        }
      }  
      else {
        if (now + a[i] > 0) {
          now = now + a[i];  
        }  
        else {
          left += -a[i] - now + 1;  
          now = 1;
        }
      }
    }
  }
  now = 0;
  for (ll i = 0; i < n; i++) {
    if (i == 0) {
      if (a[i] >= 0) {
        now = -1;
        right= 1 + a[i];  
      }  
      else {
        now = a[i];
        right = 0;  
      }
    }    
    else {
      if (now > 0) {
        if (now + a[i] < 0) {
          now = now + a[i];  
        }    
        else {
          right += now + a[i] + 1;  
          now = -1;
        }
      }  
      else {
        if (now + a[i] > 0) {
          now = now + a[i];  
        }  
        else {
          right += -a[i] - now + 1;  
          now = 1;
        }
      }
    }
  }
  cout << ((left > right) ? right : left) << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, G = 0;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {cin >> H.at(i);}
  for (int i = 0; i < N; i++) {G += H.at(i);}
  vector<int> Z(N - 2);
  int A = H.at(0);
  for (int i = 1; i < N - 1; i++) {
    A += H.at(i);
    if (A - G + A < 0) {Z.at(i - 1) = (A - G + A) * -1;}
    else {Z.at(i - 1) = A - G + A;}
  }
  sort(Z.begin(), Z.end());
  cout << Z.at(0) << endl;
}

Measured memory_bytes: 3532
import sys
n, m = map(int, input().split())
G = [[] for _ in range(n)]
cnt = [0]*n
for _ in range(m):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
    cnt[a-1]+=1
    cnt[b-1]+=1
if any(cnt[i]%2 == 1 for i in range(n)):
    print('No')
    sys.exit()
c = cnt.count(4)
if any(cnt[i]>=6 for i in range(n)) or c>=3:
    print('Yes')
    sys.exit()
if c<=1:
    print('No')
    sys.exit()
v = cnt.index(4)
for v0 in G[v]:
    now = v0
    p = v
    while True:
        for nv in G[now]:
            if nv == p:
                continue
            p = now
            now = nv
            break
        if now == v:
            print('Yes')
            sys.exit()
        if cnt[now] == 4:
            break
print('No')
        


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

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

    vector<int> p(n);

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

    int count =0;

    for(int i=0 ; i<n-2;i++){
        if(p[i]>p[i+1] && p[i+1]>p[i+2]){
            count++;
        }

        else if (p[i]<p[i+1] && p[i+1]<p[i+2]){
            count++;
        }
    }

    cout << count << endl;
}



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

int main(void){
  char step[1000010];

  while(1) {
    cin >> step;
    if(step[0] == '#') break;
    int counter = 0;
    int state;

    if(step[0] == '1' || step[0] == '4' || step[0] == '7') state = 6;
    else if(step[0] == '2' || step[0] == '8') state = 7;
    else state = 8;
    
    int i;
    
    for(i = 1; step[i] != '\0'; i++){

      if(state == 6){
        if(step[i] == '1' || step[i] == '4' || step[i] == '7'){
          continue;
        }else if(step[i] == '8' || step[i] == '2'){
          state = 3;
          continue;
        }else{
          state = 5;
          continue;
        }
      }

      if(state == 7){
        if(step[i] == '2' || step[i] == '8'){
          continue;
        }else if(step[i] == '1' || step[i] == '4' || step[i] == '7'){
          state = 0;
          continue;
        }else{
          state = 5;
          continue;
        }
      }

      if(state == 8){
        if(step[i] == '9' || step[i] == '6' || step[i] == '3'){
          continue;
        }else if(step[i] == '8' || step[i] == '2'){
          state = 2;
          continue;
        }else{
          state = 0;
          continue;
        }
      }
      

      if(state == 0){
        if(step[i] == '3' || step[i] == '6' || step[i] == '9'){
          state = 5;
          continue;
        }else if(step[i] == '8' || step[i] == '2'){
          state = 3;
          continue;
        }else{
          state = 1;
          continue;
        }
      }

      if(state == 1){
        if(step[i] == '4' || step[i] == '7'|| step[i] == '1'){
          state = 0;
          continue;
        }else if(step[i] == '8' || step[i] == '2'){
          counter++;
          state = 3;
          continue;
        }else{
          counter++;
          state = 5;
          continue;
        }
      }

      if(state == 2){
        if(step[i] == '3' || step[i] == '6' || step[i] == '9'){
          state = 5;
          continue;
        }else if(step[i] == '2' || step[i] == '8'){
          state = 3;
          continue;
        }else{
          counter++;
          state = 0;
          continue;
        }
      }

      if(state == 3){
        if(step[i] == '1' || step[i] == '4' || step[i] == '7'){
          state = 0;
          continue;
        }else if(step[i] == '2' || step[i] == '8'){
          state = 2;
          continue;
        }else{
          counter++;
          state = 5;
          continue;
        }
      }

      if(state == 4){
        if(step[i] == '3' || step[i] == '6' || step[i] == '9'){
          state = 5;
          continue;
        }else if(step[i] == '8' || step[i] == '2'){
          counter++;
          state = 2;
          continue;
        }else{
          counter++;
          state = 0;
          continue;
        }
      }

      if(state == 5){
        if(step[i] == '6' || step[i] == '3' || step[i] == '9'){
          state = 4;
          continue;
        }else if(step[i] == '8' || step[i] == '2'){
          state = 2;
          continue;
        }else{
          state = 0;
          continue;
        }
      }
    }

    cout << counter << endl;
  }
  return 0;
}

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

using namespace std;
int N;
string s[4] = {"SS","SW","WW","WS"};
string tmp;

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

  for(int i = 0; i < 4; i++) {
    string ans = s[i];
    for(int j = 1; j <= N;j++) {
      if(tmp[j%N] == 'o') {
	if(ans[j] == 'S') {
	  if(ans[j-1] == 'S') ans.push_back('S');
	  else ans.push_back('W');
	}
	else {
	  if(ans[j-1] == 'S') ans.push_back('W');
	  else ans.push_back('S');
	}
      }
      else {
	if(ans[j] == 'S') {
	  if(ans[j-1] == 'S')ans.push_back('W');
	  else ans.push_back('S');
	}
	else {
	  if(ans[j-1] == 'S')ans.push_back('S');
	  else ans.push_back('W');
	}
      }
    }
    bool is = false;

    if(ans[0] == ans[ans.length()-2] && ans[1] == ans[ans.length()-1])
      is = true;
    
    if(is) {
     
      cout << ans.substr(0,ans.length()-2) <<endl;
      return 0;
    }
  

  }
    
    cout <<"-1"<<endl;
}
  


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

int main(void)
{
	std::string a, b;

	std::cin >> a >> b;

	long long num = std::stoi(a + b);

	for(int i = 0; i * i <= num; i++) {
		if (i * i == num) {
			std::cout << "Yes" << std::endl;
			return 0;
		}
	}
	std::cout << "No" << std::endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

//https://doc.rust-jp.rs/book/second-edition/ch08-03-hash-maps.html
fn main() {
    let w: String = read();
    let mut map = HashMap::new();
    let mut ans = "Yes";

    for s in w.chars() {
        let count = map.entry(s).or_insert(0);
        *count += 1;
    }

    for i in map.iter() {
        if i.1 % 2 != 0 {
            ans = "No";
            break;
        }
    }

    println!("{}", ans);

}


Measured memory_bytes: 4352
N,K=list(map(int,input().split()))
s = []
for i in range(N):
  s.append(1)
a=[]
for k in range(K):
  o = int(input())
  if 1<o:
    p = list(map(int,input().split()))
    for g in p:
      a.append(g)
  else:
    p = int(input())
    a.append(p)
for i in a:
  s[i-1] = 0
ans = 0
for w in s:
  if w==1:
    ans += 1
print(ans)

Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
  int n;
  cin >> n;
  int cnt = 1;
  rep(i, n){
    int a;
    cin >> a;
    if(cnt == a){
      cnt++;
    }
  }
  if(cnt == 1) cnt = n+2;
  cout << n - cnt + 1 << endl;
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int num[10];
int n, m, q;
vector<int> a, b, c, d;

int calc()
{
    int ret = 0;
    rep(i, q)
    {
        if (num[b[i]] - num[a[i]] == c[i])
        {
          //  cout << i << endl;
            ret += d[i];
        }
    }
    return ret;
}

int dfs(int index)
{
    int ret = 0;

    if (index == n)
    {
        ret = calc();
       // rep(i, 10) cout << num[i];
       // cout << "\t" << ret << endl;
        return ret;
    }
    else
    {
        REP(i, num[index - 1] , m + 1)
        {
            num[index] = i;
            ret = max(ret, dfs(index + 1));
            num[index] = 0;
        }
    }
    return ret;
}

int main()
{
    cin >> n >> m >> q;
    rep(i, q)
    {
        int a_i, b_i, c_i, d_i;
        cin >> a_i >> b_i >> c_i >> d_i;
        a.push_back(a_i - 1);
        b.push_back(b_i - 1);
        c.push_back(c_i);
        d.push_back(d_i);
    }
    int ans = 0;
    REP(i, 1, m + 1)
    {
        rep(j, 10) num[j] = 0;
        num[0] = i;
        ans = max(ans, dfs(1));
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int H, W, i, j;
	H = 0;
	W = 0;
	while (cin >> H >> W){
		if (H != 0 || W != 0){
			for (i = 0; i < H; i++){
				for (j = 0; j < W; j++){
					cout << "#";
				}
				cout << "\n";
			}
			cout << "\n";
		}
		else {
			break;
		}
	}
	return 0;
}

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

using namespace std;
using lint = long long;
#define MOD 1000000007

int main(void)
{
    int N, M;
    //lint mod = 1000000007;
    cin >> N >> M;
    vector<int> a(M);
    for(int  i = 0; i < M; i++){
        cin >> a[i];
    }
    /*
    for(int i = 1; i < M; i++){
        if(a[i] - a[i-1] == 1){
            cout << 0 << endl;
            return 0;
        }
    }
    */
    
    vector<lint> dp(N+1);
    int cnt = 0;
    for(int i = 0; i <= N; i++){
        if(cnt < M && a[cnt] == i){
            dp[i] = 0;
            cnt++;
        }
        else if(i == 0 || i == 1){
            dp[i] = 1;
        }
        else{
            dp[i] = (dp[i-1] % MOD + dp[i-2] % MOD) % MOD;
        }
        //cout << cnt << " " << dp[i] << endl;
    }

    cout << dp[N] << endl;


    return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> a(N),b(N);
	
	for(int i=0;i<N;i++){
		cin >> a.at(i);
	}  //input 
	
	for(int i=0;i<N;i++){
		int amax=0;
		for(int j=0;j<N;j++){
			amax=max(a.at(j),amax);
		}
		b.at(i)=amax;
		for(int j=0;j<N;j++){
			if(a.at(j)==b.at(i)){
				a.at(j)=0;
				break;
			}
		}
	}  //�傫�����ɕ��ёւ�
	
	int i=0;
	int ans=0;
	while(i<N){
		ans+=b.at(i);
		i+=2;
	}
	
	i=1;
	while(i<N){
		ans-=b.at(i);
		i+=2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define re(i,a,n) for(i=a;i<=n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second


ll binpow(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
   while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return binpow(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll m,n,i,f=0,j,ans=0,k,x,r,l,t;
    cin >> n ;
    vector<ll> a(n);
    ll sum=0;
    rep(i,n) 
    {
          cin >> a[i];
          sum+=a[i];
          sum%=P;
    }
    
    ll t1;
    rep(i,n)
    {
         sum=(sum-a[i]+P)%P;
         t1=(a[i]*sum)%P;
         ans=(ans+t1)%P;
    }
    cout << ans << endl ;
    return 0;
}

Measured memory_bytes: 4780
import copy

H, W, K = map(int, input().split())
ll = [[0 for w in range(W)] for h in range(H)]
ans = 0

for h in range(H):
  row = input()
  for w in range(W):
    if (row[w] == '.'):#白
      ll[h][w] = 0
    else:
      ll[h][w] = 1

for h in range(2 ** H):
  hstr = format(h, f'0{H}b')
  for w in range(2 ** W):
    wstr = format(w, f'0{W}b')
    l = copy.deepcopy(ll)
    count = 0
    for h1 in range(H):
      for w1 in range(W):
        if (hstr[h1] == '1' or wstr[w1] == '1'):
          l[h1][w1] = 0
        count += l[h1][w1]
    if (count == K):
      ans += 1

print(ans)

Measured memory_bytes: 9352
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int H, W;
int counter;
vector< vector<bool> > field;


void solve();
void setup();

int main()
{
  setup();
  solve();
  return 0;
}

void setup() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  field = vector<vector<bool>>(H, vector<bool>(W, false));
  counter = 0;
  REP(i, H) {
    string s;
    cin >> s;
    REP(j, W) {
      if (s[j] == '#') {
        counter++;
        field[i][j] = true;
      } else {
        field[i][j] = false;
      }
    }
  }
}

bool search(int row, int col) {
  if (row == H || col == W) { return false; }
  if (row == H - 1 && col == W - 1) { return true; }
  if (field[row][col] == false) { return false; }
  return search(row + 1, col) || search(row, col + 1);
}

void solve() {
  if (counter != (H + W - 1)) {
    cout << "Impossible" << endl;
    return;
  }
  bool result = search(0, 0);
  if (result) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

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

int main(void)
{
	bool judge = false;
	int n;
	cin >> n;
	for (int i = 1; i <= 9; i++)
	{
		for (int j = 1; j <= 9; j++)
		{
			if (i * j == n) { judge = true; }
		}
	}
	if (judge) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	return 0;
}

Measured memory_bytes: 256
def generate_arr(a):
    if len(a) == N:
        arr.append(a)
        return
    for i in range(1,N+1):
        if i not in a:
            generate_arr(a+[i])
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
arr = []
generate_arr([])
arr.sort()
ans_p = 0
ans_q = 0
for i in range(len(arr)):
    if arr[i] == P:
        ans_p = i+1
    if arr[i] == Q:
        ans_q = i+1
print(abs(ans_p-ans_q))

Measured memory_bytes: 82452