akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>

#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(int i = 0; i < n; i += k)


int main() {
    string s;
    int x, y;
    
    cin >> s;
    scanf("%d %d", &x, &y);
    
    int xx = 0, yy = 0, d[8005] = {}, p = 0;
    bool yoko = true;
    REP(i, s.size()){
        if(s[i] == 'F'){
            d[p]++;
            if(yoko){
                xx++;
            }
            else{
                yy++;
            }
        }
        else{
            yoko = !yoko;
            p++;
        }
    }
    
    unordered_map<int, bool> dp1, dp2, dp3;
    dp1[d[0]] = true;dp2[0] = true;
    for(int i = 1; i <= p; i++){
        if(i % 2 == 0){
            if(d[i]){
                for(int j = -xx; j <= xx; j++){
                    if(dp1[j - d[i]] || dp1[j + d[i]]){
                        dp3[j] = true;
                    }
                }
                
                for(int j = min(-xx, -yy); j <= max(xx, yy); j++){
                    if(dp3[j]){
                        dp1[j] = true;
                    }
                    else{
                        dp1[j] = false;
                    }
                    dp3[j] = false;
                }
            }
        }
        else{
            if(d[i]){
                for(int j = -yy; j <= yy; j++){
                    if(dp2[j - d[i]] || dp2[j + d[i]]){
                        dp3[j] = true;
                    }
                }
                
                for(int j = min(-xx, -yy); j <= max(xx, yy); j++){
                    if(dp3[j]){
                        dp2[j] = true;
                    }
                    else{
                        dp2[j] = false;
                    }
                    dp3[j] = false;
                }
            }
        }
    }
    
    /*
    for(int i = -xx; i <= xx; i++){
        cout << dp1[i] << ' ';
    }
    cout << endl;
    for(int i = -yy; i <= yy; i++){
        cout << dp2[i] << ' ';
    }
    cout << endl;
    */
    
    if(dp1[x] & dp2[y]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 2572
import sys
input = sys.stdin.readline

N = int(input())

heights = list(map(int, input().split()))


cnt_height_plus_ind = {}
cnt_height_minus_ind = {}
cnt_ind_minus_height = {}
cnt_minus_height_minus_ind = {}

for ind in range(N):
    height = heights[ind]

    if ind - height not in cnt_ind_minus_height:
        cnt_ind_minus_height[ind - height] = 0
    cnt_ind_minus_height[ind - height] += 1

    if ind + height not in cnt_height_plus_ind:
        cnt_height_plus_ind[ind + height] = 0
    cnt_height_plus_ind[ind + height] += 1

    if height - ind not in cnt_height_minus_ind:
        cnt_height_minus_ind[height - ind] = 0
    cnt_height_minus_ind[height - ind] += 1

    if - ind - height not in cnt_minus_height_minus_ind:
        cnt_minus_height_minus_ind[-ind-height] = 0
    cnt_minus_height_minus_ind[-ind-height] += 1
    

ans = 0
#for val in cnt_height_minus_ind:
#    if val in cnt_minus_height_minus_ind:
#        ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val]

for val in cnt_height_plus_ind:
    if val in cnt_ind_minus_height:
        ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val]

print(ans)

Measured memory_bytes: 87488
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int i = 1;
		while (true) {
			int temp = sc.nextInt();
			if (temp==0) {break;}
			System.out.println("Case "+i+":"+" "+temp);
			i++;
		}
	}
}



Measured memory_bytes: 41196
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		long[][] dp=new long[s.length()+1][2];
		dp[s.length()][1]=11;
		for(int i=s.length()-1; i>=0; i--){
			
				dp[i][0]=Math.min(dp[i+1][0]+(s.charAt(i)-'0'),dp[i+1][1]+(s.charAt(i)-'0'));
				dp[i][1]=Math.min(dp[i+1][0]+11-(s.charAt(i)-'0'),dp[i+1][1]+9-(s.charAt(i)-'0'));
			
		}
		System.out.println(Math.min(dp[0][0],dp[0][1]));
	}
}


Measured memory_bytes: 72180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define traverse(container,it)  for(auto it = container.begin();it != container.end(); it++)
int main()
{
    //freopen("in.txt","r",stdin);
    int n,m;
    ll sum = 0;
    multiset< int >  number;
    priority_queue< pair< int,int > > spare;

    cin >> n >> m;

    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        number.insert(x);
    }

    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        spare.push(make_pair(b,a));
    }

    multiset< int >::iterator it = number.begin();

    while(!spare.empty() && it != number.end()){
        pair< int,int > curr = spare.top();

        while((curr.first> *it) && curr.second>0 && (it != number.end())){
            curr.second--;
            sum += curr.first;
            it++;
        }

        if(curr.first <= *it) break;

        spare.pop();
    }

    while(it != number.end()){
        sum += *it;
        it++;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 6136
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef long long Int;

#define KIND 26
//#define KIND 2
Int D;
Int c[KIND];
Int s[400][KIND];
Int last[KIND];

Int range(Int l, Int r)
{
    Int len = r - l - 1;
    return -len * (len + 1) / 2;
}

struct ContestInfo {
    set<Int> held[KIND];
    vector<Int> t;
    int D;
    Int score = 0;
    ContestInfo(int D) : D(D)
    {
        t.resize(D, -1);
        for (int i = 0; i < KIND; i++) {
            held[i].insert(-1);
            held[i].insert(D);
            score += c[i] * range(-1, D);
        }
    }

    void add(int d, int q)
    {
        if (t[d] != -1) {
            cout << "Add failed" << endl;
            exit(1);
        }
        t[d] = q;
        score += s[d][q];
        held[q].insert(d);
        auto it = held[q].find(d);
        auto rit = next(it);
        auto lit = prev(it);
        score -= c[q] * range(*lit, *rit);
        score += c[q] * range(*it, *rit);
        score += c[q] * range(*lit, *it);
    }

    void erase(int d)
    {
        if (t[d] == -1) {
            cout << "erase failed" << endl;
            exit(1);
        }
        int q = t[d];
        t[d] = -1;
        score -= s[d][q];
        auto it = held[q].find(d);
        auto rit = next(it);
        auto lit = prev(it);
        score += c[q] * range(*lit, *rit);
        score -= c[q] * range(*it, *rit);
        score -= c[q] * range(*lit, *it);
        held[q].erase(it);
    }

    void change(int d, int q)
    {
        erase(d);
        add(d, q);
    }
};

Int calc_score(vector<Int> t)
{
    Int score = 0;
    fill(last, last + 26, -1);
    for (int d = 0; d < D; d++) {
        score += s[d][t[d]];
        last[t[d]] = d;
        for (int i = 0; i < KIND; i++) {
            score -= c[i] * (d - last[i]);
        }
        // cout << score << endl;
    }
    return score;
}

int main()
{
    cin >> D;
    for (Int i = 0; i < KIND; i++) {
        cin >> c[i];
    }
    for (Int d = 0; d < D; d++) {
        for (Int i = 0; i < KIND; i++) {
            cin >> s[d][i];
        }
    }

    ContestInfo ci(D);

    for (int d = 0; d < D; d++) {
        Int t;
        cin >> t;
        t--;
        ci.add(d, t);
    }
    Int current_score = ci.score;
    Int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
        Int d, q;
        cin >> d >> q;
        d--;
        q--;
        int old = ci.t[d];
        ci.change(d, q);
        Int new_score = ci.score;
        cout << new_score << endl;
        /*if (new_score < current_score) {
            ci.change(d, old);
        }
        else {
            current_score = new_score;
            }*/
        current_score = new_score;
    }

    return 0;
}

Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int ans = 0;
  vector<int> d;
  for (int i = 0; i < N; i++)
  {
    int a;
    cin >> a;
    d.push_back(a);
  }
  for (int i = 0; i < N; i++)
  {
    for (int j = i + 1; j < N; j++)
    {
      ans += d.at(i) * d.at(j);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
int main() {
	int A, B;
	cin >> A >> B;
	if (A == B) {
		cout << 2 * A;
	}
	else if (A > B) {
		cout << 2 * A - 1;
	}
	else {
		cout << 2 * B - 1;
	}
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 1e18+1
const ll mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll n,m,q;
    cin>>n>>m>>q;
    ll arr[q][4];
    fr(i,0,q)
    {
        cin>>arr[i][0];
        cin>>arr[i][1];
        cin>>arr[i][2];
        cin>>arr[i][3];
    }
    ll ans=0;
    ll a[n+1]={};
    fr(i,0,(1<<(n+m-1)))
    {
        ll v=1,c=1;
        if(__builtin_popcountll(i)==n)
        {
            fr(j,0,(n+m-1))
            {
                if(i&(1<<j))
                {
                    a[c]=v;
                    c++;
                }
                else
                    v++;
            }

            ll ct=0;
            fr(i,0,q)
            {
                if(a[arr[i][1]]-a[arr[i][0]]==arr[i][2])
                    ct+=arr[i][3];
            }
            ans=max(ans,ct);
        }
    }
    cout<<ans<<endl;
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3632
/**
 *  author: mahfuzz
 *  created: 17.12.2019
**/
 
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << ':' << x << "\n";
//~ const double pi = 2*acos(0.0);
//~ const long long mod = 1e9+7;
//~ const int max_n = 1e6+5;
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    string s; cin >> s;
    int sz = s.length() - 1;
    
    int cnt = 0;
    for(int i = 0; i < sz; i++, sz--){
        if(s[i] != s[sz])
            cnt++;
    }
    
    cout << cnt << "\n";
        
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int X, Y;
  cin >> X >> Y;
  cout << X + Y / 2 << "\n";
}

Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
using namespace std;
int main(){
    int n, l;
    cin >> n >> l;
    int res = 200;
    int reso = 0;
    int sum = 0;
    rep(i,n){
        sum += (l+i);
        if(abs(i+l) < res){
            // show(i)
            res = abs(i+l);
            reso = i;
            // show(l+i)
        }
    }
    cout << sum - (l+reso) << endl;

    

}

Measured memory_bytes: 256
data Group = G0 | G1 | G2 deriving Eq

grouping :: [[Int]]
grouping = [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11], [2]]

main :: IO ()
main = do
  [x, y] <- (map read . words) <$> getLine :: IO [Int]
  putStrLn $ if findGroup x == findGroup y then "Yes" else "No"

findGroup :: Int -> Group
findGroup x
  | x `elem` grouping!!0 = G0
  | x `elem` grouping!!1 = G1
  | x `elem` grouping!!2 = G2
  | otherwise = error "ここに来ることはない"



Measured memory_bytes: 508
#include <cstdio>

using namespace std;

int main() {
    int n, a, c = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a);
        if (a % 2) ++c;
    }
    printf("%s\n", (c % 2 ? "NO" : "YES"));
    return 0;
}


Measured memory_bytes: 128
q = []
lst = {}

def checker(letter, st):
  for i in xrange(len(st)):
    if letter != st[i]:
      return False
  return True

while True:
  q = []
  lst = {}
  st = raw_input()
  deep = 0
  if st == "0":
    break
  while True:
    # checked
    if st in lst:
      if len(q) == 0:
        print "NA"
        break
      st = q[0][0]
      deep = q[0][1]
      q = q[1:]
      continue
    # add checked list
    lst[st] = deep
    # check completed
    if checker(st[0], st):
      print deep
      break
    # que next pattern
    for i in xrange(len(st)-1):
      if st[i] == st[i+1]:
        continue
      if (st[i] == 'r' and st[i+1] == 'g') or (st[i] == 'g' and st[i+1] == 'r'):
        q.append([st[:i] + "bb" + st[i+2:], deep+1])
      elif (st[i] == 'r' and st[i+1] == 'b') or (st[i] == 'b' and st[i+1] == 'r'):
        q.append([st[:i] + "gg" + st[i+2:], deep+1])
      elif (st[i] == 'b' and st[i+1] == 'g') or (st[i] == 'g' and st[i+1] == 'b'):
        q.append([st[:i] + "rr" + st[i+2:], deep+1])
    # print NA if has no pattern in queue
    if len(q) == 0:
      print "NA"
      break
    # get next pattern from queue
    st = q[0][0]
    deep = q[0][1]
    q = q[1:]

Measured memory_bytes: 10016
n = int(raw_input())



FORMAT = ('node {0.id}: parent = {0.parent}, sibling = {0.sibling}, degree = {0.degree}, depth = {0.depth}, height = {0.height}, {0.type}').format

class Node:
    def __init__(self):
        self.id = -1
        self.parent = -1
        self.left = -1
        self.right = -1
        self.sibling = -1
        self.degree = 0
        self.depth = 0
        self.height = 0
        self.type = 'leaf' if self.height == 0 else 'internal node'
        
    def setType(self):
        if self.height == 0 and self.parent != -1:
            self.type = 'leaf'
        elif self.parent == -1:
            self.type = 'root'
        else:
            self.type = 'internal node'

    def __str__(self):
        return FORMAT(self)

def preParse(u):
    if u == -1:
        return
    print u,
    preParse(T[u].left)
    preParse(T[u].right)

def inParse(u):
    if u == -1:
        return
    inParse(T[u].left)
    print u,
    inParse(T[u].right)

def postParse(u):
    if u == -1:
        return
    postParse(T[u].left)
    postParse(T[u].right)
    print u,


T = [Node() for _ in xrange(n)]

for i in xrange(n):
    a = map(int, raw_input().split())
    u = a[0]
    l = a[1]
    r = a[2]
    T[u].id = u
    T[u].left = l  #set child
    T[u].right = r  #set child
    if l != -1 and r != -1:
        T[l].parent = u  #set parent
        T[r].parent = u  #set parent
    elif l != -1 and r == -1:
        T[l].parent = u  #set parent
    elif l == -1 and r != -1:
        T[r].parent = u  #set parent

    if l != -1 and r != -1:
        T[u].degree = 2
        T[l].sibling = r
        T[r].sibling = l
    elif l != -1 and r == -1:
        T[u].degree = 1
    elif  l == -1 and r != -1:
        T[u].degree = 1

N = 0
for i in xrange(n):
    if T[i].parent == -1:
        N = T[i].id

print 'Preorder'
print '',
preParse(N)
print 
print 'Inorder'
print '',
inParse(N)
print 
print 'Postorder'
print '',
postParse(N)
print 

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

int main() {
  string N;
  cin >> N;
  if (N[0]==N[1]&&N[1]==N[2]) {
    cout << "Yes" << endl;
  }
  else if (N[1]==N[2]&&N[2]==N[3]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int 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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
typedef tuple<string, int, int> mytuple;
int main() {
    int N;
    cin >> N;
    vector<mytuple> dict(N);
    REP(i, N) {
        string s;
        int p;
        cin >> s >> p;
        dict[i] = make_tuple(s, -p, i + 1);
    }
    sort(dict.begin(), dict.end());
    REP(i, N) { cout << get<2>(dict[i]) << endl; }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    new Main().solve();
  }

  private void solve() {
    try(InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out)) {

      final int A = in.nextInt();
      final int B = in.nextInt();
      final int Q = in.nextInt();

      long[] s = new long[A+1];
      for (int i = 0; i < A; i++) {
        s[i] = in.nextLong();
      }
      s[A] = 1L << 40;

      long[] t = new long[B+1];
      for (int i = 0; i < B; i++) {
        t[i] = in.nextLong();
      }
      t[B] = 1L << 40;

      for (int q = 0; q < Q; q++) {
        long x = in.nextLong();
        long dist = 1L << 50;

        for (int c = 0; c < 2; c++) {
          long[] af = c == 0 ? s : t;
          long[] as = c == 0 ? t : s;

          for (int i = 0; i < 2; i++) {
            int posF = binarySearch(af, x) + i;
            long df = af[posF];

            for (int j = 0; j < 2; j++) {
              int posS = binarySearch(as, x) + j;
              long ds = as[posS];
              
              long d = Math.abs(x - df);
              d += Math.abs(df - ds);
              dist = Math.min(dist, d);
            }
          }
        }

        out.println(dist);
      }
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  private int binarySearch(long[] arr, long x) {
    int left = 0;
    int right = arr.length;

    return loop(arr, x, left, right);
  }

  private int loop(long[] arr, long x, int left, int right) {
    if(right - left < 2) return left;
    else {
      int mid = (left + right) / 2;
      if(arr[mid] <= x) return loop(arr, x, mid, right);
      else return loop(arr, x, left, mid);
    }
  }

  static class InputReader implements AutoCloseable {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

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

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

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

    @Override
    public void close() throws IOException {
      reader.close();
    }
  }
}

Measured memory_bytes: 50444
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

#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<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

using mint = modint998244353;
const int N = 200010;
mint ten[N];

struct S {
    mint a;
    int size;
};

struct F {
    int x;
};

S op(S l, S r) { return S{l.a * ten[r.size] + r.a, l.size + r.size}; }

S e() { return S{0, 0}; }

S mapping(F l, S r) { return l.x == -1 ? r : S{(ten[r.size] - 1) / 9 * l.x, r.size}; }

F composition(F l, F r) { return (l.x != -1 ? F{l.x} : F{r.x}); }

F id() { return F{-1}; }

int main(void){
    int n, q;
    cin >> n >> q;
    ten[0] = 1;
    REP(i,N-1) ten[i + 1] = 10 * ten[i];
    vector<S> a(n, S{1, 1});
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
    REP(i,q){
        int l = in() - 1, r = in(), x = in();
        seg.apply(l, r, F{x});
        S s = seg.all_prod();
        ll ans = s.a.val();
        printf("%lld\n", ans);
    }

    return 0;
}


Measured memory_bytes: 10640
n = gets.to_i

count = 0
max = 0
n.times do
  d1, d2 = gets.split.map(&:to_i)
  if d1 == d2
    count += 1
  else
    max = [max, count].max
    count = 0
  end
end
max = [max, count].max

puts max >= 3 ? "Yes" : "No"

Measured memory_bytes: 14408
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>
using namespace std;
int n,m,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n,w;
	cin>>n>>w;
	vector<pii> arr;
	for(int i=0;i<n;i++){
		int w,v;
		cin>>w>>v;
		arr.pb({w,v});
	}
	sort(all(arr));
	int dp[n][w+1] = {};
	for(int i=1;i<=w;i++){
		if(i>=arr[0]._1)
			dp[0][i] = arr[0]._2;
		else dp[0][i] = 0;
	}
	for(int i=1;i<=w;i++){
		for(int j=1;j<n;j++){
			int ans = dp[j-1][i];
			if((i-arr[j]._1)>=0){
				ans = max(ans,dp[j-1][i-arr[j]._1]+arr[j]._2);
			}
			dp[j][i] = ans;
		}
	}
	cout<<dp[n-1][w];
	return 0;
}
//.........

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

const int maxn=110;
int n;
int cx,cy,H;
struct node{int x,y,h;}a[maxn];

bool check(int x,int y)
{
	int tmp;
	for(int i=1;i<=n;i++) if(a[i].h!=0)
	{tmp=a[i].h+abs(a[i].x-x)+abs(a[i].y-y);break;}
	int flag=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i].h!=max(tmp-abs(a[i].x-x)-abs(a[i].y-y),0))
		{
			flag=1;
			break;
		}
	}
	if(flag) return false;
	cx=x,cy=y,H=tmp;
	return true;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].h);
	for(int i=0;i<=100;i++)
	{
		for(int j=0;j<=100;j++)
		{
			if(check(i,j))
			{
				printf("%d %d %d\n",cx,cy,H);
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")

N,Y=map(int, input().split())
p(N,Y)

NAmax=min(N,Y//10000)
NBmax=min(N,Y//5000)
NCmax=min(N,Y//1000)
p(NAmax, NBmax, NCmax)

NA=NAmax
for a in range(NA,-1,-1):
  NB=min(NBmax,N-a)

  for b in range(NB,-1,-1):
    c = N-a-b
    y = (a*10000)+(b*5000)+(c*1000)
    if y==Y:
      print(a,b,c,sep=" ")
      exit()
      
i=-1
print(i,i,i, sep=" ")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const int mod = 998244353;
const ll INF = MOD * MOD;
const int inf = (1<<29);


// mod. m での a の逆元 a^{-1} を計算する
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 210000;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理O(n)
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

// 二項係数計算O(1)
ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main() {

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

    int res = 0;

    COMinit();

    for(int i = 0; i <= k; i++) {
        res += ((m*COM(n-1, i)%mod) * modpow(m-1, n-1-i, mod))% mod; 
        res %= mod;
    }

    cout << res << endl;

return 0;
}

Measured memory_bytes: 8536
def main(input = $stdin)
  count = 1
  while (w = input.gets.to_i) != 0
    n = input.gets.to_i
    goods = []
    n.times do
      goods << input.gets.split(",").map(&:to_i)
    end
    values = Array.new(w + 1)
    values[0] = 0
    goods.each{|good|
      (-good[1] - 1).downto(-w - 1){|idx|
        if values[idx] and (!values[idx + good[1]] or values[idx] + good[0] > values[idx + good[1]])
          values[idx + good[1]] = values[idx] + good[0]
        end
      }
      
    }
    puts "Case #{count}:"
    puts values.max_by{|i|i.to_i}
    puts values.index(values.max_by{|i|i.to_i})
    count += 1
  end
end
main

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

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

char input[70][70];
string dp[70][70];

int comp(string s,string t) {
  if(s.length() != t.length()) return (s.length() - t.length());
  rep(i,s.length()) if(s[i] != t[i]) return (s[i] - t[i]);
  return 0;
}

int main() {
  int w,h,n;
  while(cin>>w>>h, w|h) {
    string s,above,left;
    rep(i,h) {
      cin>>s;
      rep(j,w) {
	dp[i][j] = "";
	input[i][j] = s[j];
      }
    }

    rep(i,h) rep(j,w) {
      char c = input[i][j];
      if(!(c <= '9' && c >= '0')) continue;
      above = ((i > 0 && dp[i-1][j] != "0") ? dp[i-1][j] : "") + string(1,c);
      left = ((j > 0 && dp[i][j-1] != "0") ? dp[i][j-1] : "") + string(1,c);
      dp[i][j] = (comp(above,left) <= 0) ? left : above;
    }

    string ans = "";
    rep(i,h) rep(j,w) if(comp(ans,dp[i][j]) < 0) ans = dp[i][j];
    cout<<ans<<endl;
  }
}

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

int t[110000], x[110000], y[110000];
int main() {
	int N;
	
	cin >> N;
	t[0] = x[0] = y[0] = 0;
	for (int i = 0; i < N; ++i) {
		cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
	}

	bool can = true;
	for (int i = 0; i < N; ++i) {
		int dt = t[i + 1] - t[i];
		int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
		if (dt < dist) can = false;
		if (dist % 2 != dt % 2) can = false;
	}

	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = 10000;

int w, h;

bool isOK(int y, int x){
    if(y >= 0 && x >= 0 && y < h && x < w) return true;
    return false;
}

P move(int y, int x, int my, int mx, vector< vector<int> > &v){
    if(isOK(y + my, x + mx) && v[y + my][x + mx] == 1) return P(-1, -1);
    while(isOK(y, x)){
        if(v[y][x] == 3) return P(y, x);
        if(v[y][x] == 1) return P(y - my, x - mx);
        y += my;
        x += mx;
    }
    return P(-1, -1);
}

int dfs(int y, int x, int step, vector< vector<int> > &v){
    //cout <<"now " <<y <<", " <<x <<", " <<step <<", " <<v[y][x] <<endl;
    if(step > 10) return INF;
    if(v[y][x] == 3) return step;
    int ret = INF;
    int my[] = {1, -1, 0, 0};
    int mx[] = {0, 0, 1, -1};
    REP(i, 4){
        P next = move(y, x, my[i], mx[i], v);
        if(next.first != -1){
            int ny = next.first, nx = next.second;
            //cout <<"ret " <<ny <<", " <<nx <<endl;
            if(v[ny][nx] != 3) v[ny + my[i]][nx + mx[i]] = 0;
            ret = min(ret, dfs(ny, nx, step + 1, v));
            if(v[ny][nx] != 3) v[ny + my[i]][nx + mx[i]] = 1;
        }
        //cout <<ret <<endl;
    }
    return ret;
}

int main(){
    while(cin >>w >>h && w){
        //cout <<"s " <<w <<", " <<h <<endl;
        vector< vector<int> > v(h, vector<int>(w));
        REP(i, h) REP(j, w) cin >>v[i][j];
        //cout <<"----" <<endl;
        //REP(i, h){
        //    REP(j, w) cout <<v[i][j] <<" ";
        //    cout <<endl;
        //}
        //cout <<"----" <<endl;
        REP(i, h){
            REP(j, w){
                if(v[i][j] == 2){
                    int tmp = dfs(i, j, 0, v);
                    cout <<(tmp == INF? -1 : tmp) <<endl;
                }
            }
        }
        //cout <<"end" <<endl;
    }
    return 0;
}

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

#define ll long long

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    ll a, b, c;
    cin >> a >> b >> c;

    if(a==b && a!=c && b!=c) cout << "Yes\n";
    else if(b==c && a!=b && a!=c) cout << "Yes\n";
    else if(c==a && a!=b && b!=c) cout << "Yes\n";
    else cout << "No\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

struct edge {
	int a, b, w;
	edge(int a, int b, int w) {
		this->a = a;
		this->b = b;
		this->w = w;
	}
};

void dfs(int node, bool reverse, vi &vis, vector<edge> &e) {
	vis[node] = 1;
	for(edge ed : e) {
		if(!reverse) {
			if(ed.a == node && !vis[ed.b]) {
				dfs(ed.b, reverse, vis, e);
			}
		} else {
			if(ed.b == node && !vis[ed.a]) {
				dfs(ed.a, reverse, vis, e);
			}
		}
	}
}

void solve() {
	int n, m, p;
	cin >> n >> m >> p;
	
	vector<edge> e;
	for(int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		e.pub(edge(a, b, -c + p));
	}
	
	vi vis1(n, 0), visn(n, 0); 
	dfs(0, 0, vis1, e);
	dfs(n - 1, 1, visn, e);
	
	vector<edge> newe;
	for(int i = 0; i < m; i++) {
		if(vis1[e[i].a] && visn[e[i].a]) newe.pub(e[i]);
	}
	
	vi dist(n, inf);
	dist[0] = 0;
	bool neg = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < newe.size(); j++) {
			if(dist[newe[j].a] + newe[j].w < dist[newe[j].b]) {
				dist[newe[j].b] = dist[newe[j].a] + newe[j].w;
				if(i == n - 1) neg = 1;
			}
		}
	}
	
	if(neg) {
		cout << -1 << endl;
		return;
	}
	
	cout << max(0, -dist[n - 1]) << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 3920
#include<iostream>
#include<set>
using namespace std;
int main()
{
    set<int> div;
    int n, m;
    cin >> n >> m;
    for(int i = 1; i * i <= m; i++)
    {
        if(m/i*i == m)
        {
            div.insert(i);
            div.insert(m/i);
        }
    }
    int lb = *div.lower_bound(n);
    cout << m/lb << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static final MyScanner in = new MyScanner();
 
	public static void main(String[] args) {
 
		char[] n = in.next().toCharArray();
 
 
		System.out.println(n[0] == '7' || n[1] == '7' || n[2] == '7' ? "Yes" : "No");
 
	}
 
	public static class MyScanner {
		Scanner sc = new Scanner(System.in);
		String next() { return sc.next();}
		int nextInt() { return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next()); }
	}
}

Measured memory_bytes: 35708
#include<bits/stdc++.h>
#define maxn 223456

using namespace std;
typedef long long ll;
ll a[maxn],s[maxn],l,r,mid,n,ans,d[4];

int main(){
    cin >> n; ans=1e18;
    for (int i=1;i<=n;i++) cin >> a[i],s[i]=s[i-1]+a[i];
    for (int i=2;i<n-1;i++){
        l=0; r=i;
        while (r-l>1){
            mid=(l+r)>>1;
            if (s[mid]>s[i]-s[mid]) r=mid; else l=mid;
        }
        if (s[l]>s[i]-s[r]) d[0]=s[l],d[1]=s[i]-s[l]; else d[0]=s[r],d[1]=s[i]-s[r];
        l=i; r=n;
        while (r-l>1){
            mid=(l+r)>>1;
            if (s[mid]-s[i]>s[n]-s[mid]) r=mid; else l=mid;
        }
        if (s[l]-s[i]>s[n]-s[r]) d[2]=s[l]-s[i],d[3]=s[n]-s[l]; else d[2]=s[r]-s[i],d[3]=s[n]-s[r];
        sort(d,d+4); ans=min(ans,d[3]-d[0]);
    }
    cout << ans << endl;
}


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

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


template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

const int INF = INT_MAX / 2;

int main() {
  int N,K; cin>>N>>K;
  vector<int> h(N);
  REP(i,N) cin>>h[i];
  vector<int> dp(N,INF);
  dp[0] = 0;
  REP(i,N-1) {
    for(int k = 1; k <= K; k++) {
      if(i + k < N)
	chmin(dp[i+k], dp[i] + abs(h[i+k]-h[i]));
    }
  }
  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <regex>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end());
#define rSORT(a) sort((a).rbegin(),(a).rend());
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end());
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Say(a) cout <<(a);
#define Sal(a) cout <<(a)<<endl;

const ll MOD = 1e9+7;
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

//sankou
//vvi = vector<vector<int>>(20, vector<int>(10, 0));

//seiki
//#include <regex>
/*bubun*/
//regex_search("u32", regex("[0-9]"));      // true
/*kanzen*/
//regex_match("u32", regex("(i|u)\\d+"));   // true

int isP(int n) {
    if(n<=1) return 0;
    FOR(i,2,(int)sqrt(n)) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {

    string s;
    ll K,tmp;
    cin >>s>>K;
    FOR(i,0,s.size()-1){
        FOR(al,0,25){
            if(alp[al]==s[i]){
                tmp=al;
                break;
            }
        }
        if(i==s.size()-1) {
            s[i]=alp[(tmp+K)%26];
            K=0;
        }
        if((tmp==0)&&(i!=s.size()-1)) continue;
        if(tmp>0) {
            if((26-tmp)>K) continue;
            if((26-tmp)<=K) {
                K-=(26-tmp);
                s[i]='a';
                tmp=0;
            }
        }
        if(K==0) break;
    }
    Sal(s);
    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
using namespace std;
 
const long long INF = 1e7;
const long long N = 1e5+ 7;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;
 
long double a, n, b, c = 1, d , cnt , m , ans;
string s , s1 , s2;
set<char>st;
ll used[N];
vector<int>v;
int main()
{
   /// freopen("symposium.in" ,"r" ,stdin);
///freopen("symposium.out" , "w" ,  stdout);
    ios_base::sync_with_stdio(0);
cin >> s;
for( int i = 0;i < s.size();i ++ )
    cout << 'x' ;
}

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

using namespace std;


int main(void){
    int K;
    string S;

    cin>>K;
    cin>>S;

    if(S.size() <= K){
        cout<<S<<endl;
    }else{
        string ans=S.substr(0,K);
        ans=ans+"...";
        cout<<ans<<endl;
    }


    return 0;
}



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

int main() {
	int s, w;
	cin >> s >> w;
	if (s > w)puts("safe");
	else cout << "unsafe" << endl;
	return 0;
}






Measured memory_bytes: 3648
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str,order;
    int q,a,b;
    cin >> str >> q;
    for(int i = 1; i <= q; i++){
        string rev;
        cin >> order;
        if(order == "print"){
            cin >> a >> b;
            for (int j = a; j <= b; j++){
                cout << str[j];
            }
            cout << endl;
        }
        else if(order == "reverse"){
            cin >> a>> b;
            for (int j = b; j >= a; j--){
                rev += str[j];
            }
            str = str.replace(a,b-a+1,rev);
        }
        if(order == "replace"){
            cin >> a >> b >> rev;
            str = str.replace(a,b-a+1,rev);
        }
    }
    return 0;
    
}


Measured memory_bytes: 3216
#include<iostream>
#include<set>
#include<map>
using namespace std;

typedef pair<int,int> P;

int dir(char a){
  if(a=='E')return 0;
  if(a=='N')return 1;
  if(a=='W')return 2;
  if(a=='S')return 3;
  return -1;
}

char inv_dir(int a){
  if(a==0)return 'E';
  if(a==1)return 'N';
  if(a==2)return 'W';
  return 'S';
}

int main(){
  int h,w;
  string grid[30];
  bool use[30][30];
  int dx[] = {1,0,-1,0},dy[] = {0,-1,0,1};

  while(cin >> w >> h && (w||h)){
    for(int i=0;i<h;i++)cin >> grid[i];

    int ans = 0;
    while(ans<=180){

      int num = 0;
      for(int i=0;i<h;i++){
	for(int j=0;j<w;j++){
	  int d = dir(grid[i][j]);
	  if(0<=d){
	    num++;
	    for(int k=-1;k<3;k++){
	      int dd = (d+k+4)%4;
	      int sy = i+dy[dd], sx = j+dx[dd];
	      if(sy<0 || sx<0 || h<=sy || w<=sx)continue;
	      if(grid[sy][sx] == '.' || grid[sy][sx] == 'X'){
		grid[i][j] = inv_dir(dd);
		break;
	      }
	    }
	  }
	}
      }
      if(!num)break;
      for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)use[i][j] = false;

      for(int i=0;i<h;i++){
	for(int j=0;j<w;j++){
	  if(!use[i][j] && (grid[i][j] == '.' || grid[i][j] == 'X')){
	    for(int k=0;k<4;k++){
	      int sy = i+dy[k], sx = j+dx[k];
	      if(sy<0 || sx<0 || h<=sy || w<=sx || use[sy][sx])continue;
	      int d = dir(grid[sy][sx]);
	      if(d<0)continue;
	      int dd = (k+2)%4;
	      if(d==dd){
		grid[sy][sx] = '.';
		if(grid[i][j]!='X')grid[i][j] = inv_dir(d);
		use[i][j] = true;
		use[sy][sx] = true;
		break;
	      }
	    }
	  }
	}
      }
      ans++;
      /*
      if(ans<10){
	cout << ans << endl;
	for(int i=0;i<h;i++)cout << grid[i] << endl;
	cout << endl;
      }
      */
    }
    if(ans>180)cout << "NA\n";
    else cout << ans << endl;
  }
}

Measured memory_bytes: 0
def main():
    h, w = map(int, input().split())
    mp = [input() for _ in range(h)]
    
    i_cnt = [[0] * w for _ in range(h)]
    o_cnt = [[0] * w for _ in range(h)]
    
    for x in range(w):
        if mp[h - 1][x] == "I":
            i_cnt[h - 1][x] = 1
    
    for y in range(h):
        if mp[y][w - 1] == "O":
            o_cnt[y][w - 1] = 1
    
    ans = 0
    for y in range(h - 2, -1, -1):
        for x in range(w - 2, -1, -1):
            if mp[y][x] == "I":
                i_cnt[y][x] = i_cnt[y + 1][x] + 1
                o_cnt[y][x] = o_cnt[y][x + 1]
            elif mp[y][x] == "O":
                i_cnt[y][x] = i_cnt[y + 1][x]
                o_cnt[y][x] = o_cnt[y][x + 1] + 1
            else:
                i_cnt[y][x] = i_cnt[y + 1][x]
                o_cnt[y][x] = o_cnt[y][x + 1]
                ans += i_cnt[y][x] * o_cnt[y][x]
    
    print(ans)

main()


Measured memory_bytes: 365440
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll N;
ll ans = 0;

int main() {
	cin >> N;
	for (ll i = 1; i*i <= N; i++) {
		if (N%i == 0) {
			if (N / i - 1 > i)ans += N / i - 1;
			if (i - 1 > N / i)ans += i - 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
modl = [0]*2019
modl[0] = 1
mstack = 0
digit = 1
ans = 0

for i in range(1, len(s) + 1):
    mstack += int(s[-i]) * digit
    mstack %= 2019
    modl[mstack] += 1
    digit = digit*10%2019

for i in modl:
    ans += i*(i - 1)//2

print(ans)

Measured memory_bytes: 9212
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))

import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n = onem()

l = l()

print(lcm_list(l))


Measured memory_bytes: 6996
n = int(input())
nums = list(map(int, input().split()))

acc = [nums[0]]
for i in range(1, n):
    acc.append(acc[i - 1] + nums[i])

index = 0
value = acc[n - 1] - acc[0]
for i in range(n):
    a = acc[i]
    b = acc[n - 1] - a
    if abs(b - a) < value:
        index = i
        value = abs(b - a)
    else:
        break
print(value)

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

#define debug(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;

typedef unordered_map<ll, unordered_map<ll, ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

class xor_set{
private:
    v1 w;
public:
    xor_set () {}
    void insert(ll x){
        for(ll v : w) if(v & -v & x) x ^= v;
        if(x == 0) return;
        for(ll& v : w) if(x & -x & v) v ^= x;
        w.push_back(x);
    }

    ll count(ll x){
        for(ll v : w) if(v & -v & x) x ^= v;
        if(x == 0) return 1;
        else return 0;
    }
};

ll t;

bool solve(ll n, v1& a, string& s){
    xor_set xs;
    for(ll i = n-1;i >= 0;i--){
        if(s[i] == '0'){
            xs.insert(a[i]);
        }else{
            if(xs.count(a[i])) continue;
            else{
                return true;
            }
        }
    }
    return false;
}

int main(){
    cin >> t;
    for(ll i = 0;i < t;i++){
        ll n;
        cin >> n;
        v1 a(n);
        for(ll i = 0;i < n;i++){
            cin >> a[i];
        }
        string s;
        cin >> s;
        if(solve(n, a, s)){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 3644